Skip to content

Added WizNet w6100 IPv4 Support #119

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 75 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7e80cbf
Renamed read to _read and removed unused buffer parameter.
Apr 2, 2023
76ddb6c
Fixed failing test due to increased buffer length.
Apr 2, 2023
86fc89f
Refactored _read_mr to return an integer. Updated types for _read
Apr 2, 2023
431dcef
Refactored read_sncr to return an integer.
Apr 2, 2023
13a7120
Refactored read_snsr to return an integer.
Apr 2, 2023
fbbf1d4
Refactored read_snir to return an integer.
Apr 2, 2023
15c040b
Removed unused _ip_address_in_use.
Apr 2, 2023
137e366
Refactored rcr and rtr to return ints. Improved error message in rtr.…
Apr 2, 2023
ddd2754
Refactored pretty_ip and unpretty_ip to check that IPv4 is 4 bytes.
Apr 2, 2023
a12a25b
Simplified error checking for mac_address.setter. Added error checkin…
Apr 2, 2023
14872a2
Renamed _read_socket to _read_socket_register and refactored to retur…
Apr 2, 2023
a4b4f83
Refactored socket_status to return an integer. Tidied up some type hi…
Apr 2, 2023
a50351e
Replaced _pbuff[] with an integer for register reads.
Apr 4, 2023
b6f5715
Fixed weird logic in socket_listen causing infinite loop.
Apr 4, 2023
c2dd00f
Refactored two byte register reads.
Apr 4, 2023
f4f0b33
Refactored two byte register writes.
Apr 4, 2023
a49fcd0
Renamed _write_socket to _write_socket_register.
Apr 4, 2023
ea3b506
Fixed a bug that change _pbuff from a bytearray to a bytes object.
Apr 4, 2023
f033e49
Refactored remote_ip to only return 4 bytes. Refactored socket num ra…
Apr 4, 2023
1259c60
Refactored refactored set_dhcp to return None and raise an exception …
Apr 4, 2023
d26ff96
Refactored link_status to return bool and added a _check_link_status …
Apr 4, 2023
3191c36
Refactored remote_port to use _read_two_byte_sock_reg.
Apr 4, 2023
e9045ba
Refactored _read_mr.
Apr 4, 2023
3281502
Refactored socket_open to raise exceptions instead of returning an in…
Apr 4, 2023
0649ac1
Fixed hex formatting bug in pretty_mac.
Apr 4, 2023
1b8ea61
Refactored write_sncr to check for command completion. Deleted unused…
Apr 5, 2023
b68709b
Refactored socket_write removed unused vars, reduced math on timeout,…
Apr 5, 2023
7c26a76
Changed socket_write so TCP sn_ir raises error and UDP sn_ir returns 0.
Apr 5, 2023
b603bd4
Standardised on if w5500 else for chip specific code.
Apr 5, 2023
f58367f
Refactored _SRC_PORTS to self.src_ports_in_use as it is not a CONSTANT.
Apr 6, 2023
76081bb
Fixed a bug in socket.send where WIZNET5K.socket_send could be called…
Apr 6, 2023
9d6299e
Refactored to remove redundant _send_socket_cmd.
Apr 6, 2023
8d3a56e
Refactored socket_read for readability.
Apr 6, 2023
af10233
Refactored read_udp for readability.
Apr 6, 2023
147cbd6
Refactored sw_reset to split chip types.
Apr 7, 2023
82de7c5
Refactored _w5xxx_init to raise exception if no chip detected, init c…
Apr 7, 2023
3c72544
Removed print statements from _w5xxx_init and improved logic.
Apr 7, 2023
7a0b39f
Deleted # pylint: disable=no-member.
Apr 7, 2023
ad48f17
renamed write to _write as it is not used outside WIZNET5K.
Apr 7, 2023
b1c66f2
Refactored _write with explicit to_bytes casting and updated type hints.
Apr 7, 2023
debb8b3
Refactored ifconfig setter to explicitly cast arguments to bytes. Upd…
Apr 7, 2023
cbe8754
Corrected some type hints, added checking socket number range for pub…
Apr 7, 2023
a053793
Refactored socket_available renamed vars for readability.
Apr 7, 2023
81e54b6
Refactored pretty_ip, unpretty_ip, pretty_mac to call helper funcs.
Apr 8, 2023
2c2b0b8
Added type aliases IpAddressRaw and MacAddressRaw.
Apr 8, 2023
062a7bb
Refactored to move chip specific code to seperate methods.
Apr 8, 2023
61e0ce9
Refactored to group methods by general type.
Apr 8, 2023
c353f9a
Refactored to group methods by general type again.
Apr 8, 2023
0948dfb
Tidied up type hints.
Apr 8, 2023
0bc352f
Remove read_sncr from tests.
Apr 8, 2023
ac30705
Merge branch 'main' into refactor_wiznet5k
May 1, 2023
8a9831a
Reinstate fix for w5500 reset.
May 1, 2023
d1521f9
Renamed some constants that are chip specific.
May 1, 2023
efbf3ea
Simplified chip ID logic.
May 1, 2023
57f5957
Simplified chip ID logic.
May 1, 2023
d72abb1
Fixed formatting error with prettyIP
May 1, 2023
99183f5
Added str input for mac_address.
May 1, 2023
80129de
Set the timeout for DNS responses to 5 seconds to allow slow connecti…
May 1, 2023
6ec00d6
Refactored constants and if W5500 else statements to facilitate addin…
May 2, 2023
1a46101
Renamed the IpAddress4Raw type.
May 2, 2023
a39d458
Merge changes to main.
Jun 9, 2023
67c3763
Setup common registers.
Jun 10, 2023
3586526
Setup socket registers.
Jun 10, 2023
d1fa3a1
Update chip specific methods.
Jun 10, 2023
946400a
Add w6100 detection.
Jun 10, 2023
d72a1bf
Refactor soft reset.
Jun 11, 2023
4962a92
Refactor chip reset.
Jun 11, 2023
7404571
Refactor to move UDP header read from socket_available to udp_read
Jun 16, 2023
2900ae1
Refactor DHCP receive as full packet always returned. Add support for…
Jun 16, 2023
58d3400
Refactor read and write socket reg methods to chip specific section.
Jun 16, 2023
8059f49
Minor edits to doc-strings.
Jun 16, 2023
d5db21e
Removed out of date tests.
Jun 16, 2023
142c216
Handle read_udp with no bytes on socket.
Jun 17, 2023
93dd7cd
Better way to handle no bytes on socket.
Jun 17, 2023
884da9d
Fix incorrect offset in WIZNET5K._read_sndipr().
Jun 19, 2023
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
1,436 changes: 720 additions & 716 deletions adafruit_wiznet5k/adafruit_wiznet5k.py

Large diffs are not rendered by default.

42 changes: 13 additions & 29 deletions adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,7 @@ def _dhcp_connection_setup(self, timeout: float = 5.0) -> None:
self._eth.write_snmr(self._wiz_sock, 0x02) # Set UDP connection
self._eth.write_sock_port(self._wiz_sock, 68) # Set DHCP client port.
self._eth.write_sncr(self._wiz_sock, 0x01) # Open the socket.
while (
self._eth.read_sncr(self._wiz_sock) != b"\x00"
): # Wait for command to complete.
time.sleep(0.001)
if self._eth.read_snsr(self._wiz_sock) == b"\x22":
if self._eth.read_snsr(self._wiz_sock) == 0x22:
self._eth.write_sndport(2, _DHCP_SERVER_PORT)
debug_msg("+ Connection OK, port set.", self._debug)
return
Expand Down Expand Up @@ -299,30 +295,18 @@ def _receive_dhcp_response(self, timeout: float) -> int:
:returns int: The number of bytes stored in the global buffer.
"""
debug_msg("Receiving a DHCP response.", self._debug)
# DHCP returns the query plus additional data. The query length is 236 bytes.
minimum_packet_length = 236
buffer = bytearray(b"")
bytes_read = 0
debug_msg("+ Beginning to receive…", self._debug)
while bytes_read < minimum_packet_length and time.monotonic() < timeout:
if self._eth.socket_available(self._wiz_sock, _SNMR_UDP):
x = self._eth.read_udp(self._wiz_sock, _BUFF_LENGTH - bytes_read)[1]
buffer.extend(x)
bytes_read = len(buffer)
debug_msg("+ Bytes read so far {}".format(bytes_read), self._debug)
debug_msg(x, self._debug)
if bytes_read == _BUFF_LENGTH:
break
debug_msg("Received {} bytes".format(bytes_read), self._debug)
if bytes_read < minimum_packet_length:
bytes_read = 0
else:
_BUFF[:bytes_read] = buffer
_BUFF[bytes_read:] = bytearray(_BUFF_LENGTH - bytes_read)
del buffer
gc.collect()
debug_msg(_BUFF[:bytes_read], self._debug)
return bytes_read
while time.monotonic() < timeout:
# DHCP returns the query plus additional data. The query length is 236 bytes.
if self._eth.socket_available(self._wiz_sock, _SNMR_UDP) > 236:
bytes_count, bytes_read = self._eth.read_udp(
self._wiz_sock, _BUFF_LENGTH
)
_BUFF[:bytes_count] = bytes_read
debug_msg("Received {} bytes".format(bytes_count), self._debug)
del bytes_read
gc.collect()
return bytes_count
raise TimeoutError("No DHCP response received.")

def _process_messaging_states(self, *, message_type: int):
"""
Expand Down
2 changes: 1 addition & 1 deletion adafruit_wiznet5k/adafruit_wiznet5k_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def gethostbyname(self, hostname: bytes) -> Union[int, bytes]:
ipaddress = -1
for _ in range(5):
# wait for a response
socket_timeout = time.monotonic() + 1.0
socket_timeout = time.monotonic() + 5.0
while not self._iface.socket_available(dns_socket, 0x02):
if time.monotonic() > socket_timeout:
_debug_print(
Expand Down
8 changes: 4 additions & 4 deletions adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
wiznet5k.adafruit_wiznet5k.SNIR_TIMEOUT
| wiznet5k.adafruit_wiznet5k.SNIR_DISCON
)
while not _the_interface.read_snir(self._socknum)[0] & mask:
while not _the_interface.read_snir(self._socknum) & mask:
pass
_the_interface.write_snir(
self._socknum, 0xFF
) # Reset socket interrupt register.
_the_interface.socket_close(self._socknum)
while (
_the_interface.socket_status(self._socknum)[0]
_the_interface.socket_status(self._socknum)
!= wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED
):
pass
Expand All @@ -284,7 +284,7 @@ def _status(self) -> int:

:return int: Status of the socket.
"""
return _the_interface.socket_status(self._socknum)[0]
return _the_interface.socket_status(self._socknum)

@property
def _connected(self) -> bool:
Expand All @@ -297,7 +297,7 @@ def _connected(self) -> bool:

if self._socknum >= _the_interface.max_sockets:
return False
status = _the_interface.socket_status(self._socknum)[0]
status = _the_interface.socket_status(self._socknum)
if (
status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT
and self._available() == 0
Expand Down
124 changes: 0 additions & 124 deletions tests/dhcp_dummy_data.py

This file was deleted.

91 changes: 0 additions & 91 deletions tests/extract_unique_dns_responses.py

This file was deleted.

Loading