Skip to content

fix buffer length var in socket_write() #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions adafruit_wiznet5k/adafruit_wiznet5k.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,12 @@ def socket_write(self, socket_num, buffer, timeout=0):
dst_addr = offset + (socket_num * 2048 + 0x8000)

# update sn_tx_wr to the value + data size
ptr = (ptr + len(buffer)) & 0xFFFF
ptr = (ptr + ret) & 0xFFFF
self._write_sntx_wr(socket_num, ptr)

cntl_byte = 0x14 + (socket_num << 5)
self.write(dst_addr, cntl_byte, buffer)
txbuf = buffer[:ret] # <- use ret
self.write(dst_addr, cntl_byte, txbuf)

self._write_sncr(socket_num, CMD_SOCK_SEND)
self._read_sncr(socket_num)
Expand Down Expand Up @@ -863,9 +864,8 @@ def _read_snmr(self, sock):

def _write_socket(self, sock, address, data):
"""Write to a W5k socket register."""
base = self._ch_base_msb << 8
cntl_byte = (sock << 5) + 0x0C
return self.write(base + sock * CH_SIZE + address, cntl_byte, data)
return self.write(address, cntl_byte, data)

def _read_socket(self, sock, address):
"""Read a W5k socket register."""
Expand Down