Skip to content

Commit

Permalink
Merge pull request #119 from BiffoBear/add_w6100
Browse files Browse the repository at this point in the history
Added WizNet w6100 IPv4 Support
  • Loading branch information
brentru authored Jun 20, 2023
2 parents 0fa1ca9 + 884da9d commit 30aa274
Show file tree
Hide file tree
Showing 9 changed files with 738 additions and 2,034 deletions.
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

0 comments on commit 30aa274

Please sign in to comment.