Skip to content

Commit 8059f49

Browse files
author
BiffoBear
committed
Minor edits to doc-strings.
1 parent 58d3400 commit 8059f49

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries
66
# SPDX-FileCopyrightText: 2021 Patrick Van Oosterwijck
77
# SPDX-FileCopyrightText: 2021 Adam Cummick
8+
# SPDX-FileCopyrightText: 2023 Martin Stephens
89
#
910
# SPDX-License-Identifier: MIT
1011
"""
@@ -155,7 +156,7 @@
155156
_MR_RST = const(0x80) # Mode Register RST
156157
# Socket mode register
157158
_SNMR_CLOSE = const(0x00)
158-
_SNMR_TCP = const(0x21)
159+
SNMR_TCP = const(0x21)
159160
SNMR_UDP = const(0x02)
160161
_SNMR_IPRAW = const(0x03)
161162
_SNMR_MACRAW = const(0x04)
@@ -377,7 +378,7 @@ def mac_address(self, address: Union[MacAddressRaw, str]) -> None:
377378
"""
378379
Set the WIZnet hardware MAC address.
379380
380-
:param Union[MacAddressRaw, str] address: A 6 byte hardware MAC address.
381+
:param Union[MacAddressRaw, str] address: A hardware MAC address.
381382
382383
:raises ValueError: If the MAC address is invalid
383384
"""
@@ -397,7 +398,7 @@ def mac_address(self, address: Union[MacAddressRaw, str]) -> None:
397398
@staticmethod
398399
def pretty_mac(mac: bytes) -> str:
399400
"""
400-
Convert a byte MAC address to a ':' seperated string for display.
401+
Convert a bytes MAC address to a ':' seperated string for display.
401402
402403
:param bytes mac: The MAC address.
403404
@@ -406,7 +407,7 @@ def pretty_mac(mac: bytes) -> str:
406407
:raises ValueError: If MAC address is not 6 bytes.
407408
"""
408409
if len(mac) != 6:
409-
raise ValueError("Wrong length for MAC address.")
410+
raise ValueError("Incorrect length for MAC address.")
410411
return ":".join(f"{byte:02x}" for byte in mac)
411412

412413
def remote_ip(self, socket_num: int) -> str:
@@ -491,7 +492,7 @@ def ifconfig(
491492

492493
# *** Public Socket Methods ***
493494

494-
def socket_available(self, socket_num: int, sock_type: int = _SNMR_TCP) -> int:
495+
def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
495496
"""
496497
Number of bytes available to be read from the socket.
497498
@@ -502,6 +503,7 @@ def socket_available(self, socket_num: int, sock_type: int = _SNMR_TCP) -> int:
502503
:return int: Number of bytes available to read.
503504
504505
:raises ValueError: If the socket number is out of range.
506+
:raises ValueError: If the number of bytes on a UDP socket is negative.
505507
"""
506508
debug_msg(
507509
"socket_available called on socket {}, protocol {}".format(
@@ -518,22 +520,6 @@ def socket_available(self, socket_num: int, sock_type: int = _SNMR_TCP) -> int:
518520
raise ValueError("Negative number of bytes found on socket.")
519521
return number_of_bytes
520522

521-
# if sock_type == _SNMR_TCP:
522-
# return number_of_bytes
523-
# if number_of_bytes > 0:
524-
# if self.udp_datasize[socket_num]:
525-
# return self.udp_datasize[socket_num]
526-
# # parse the udp rx packet
527-
# # read the first 8 header bytes
528-
# udp_bytes, self._pbuff[:8] = self.socket_read(socket_num, 8)
529-
# if udp_bytes > 0:
530-
# self.udp_from_ip[socket_num] = self._pbuff[:4]
531-
# self.udp_from_port[socket_num] = (self._pbuff[4] << 8) + self._pbuff[5]
532-
# self.udp_datasize[socket_num] = (self._pbuff[6] << 8) + self._pbuff[7]
533-
# udp_bytes = self.udp_datasize[socket_num]
534-
# return udp_bytes
535-
# return 0
536-
537523
def socket_status(self, socket_num: int) -> int:
538524
"""
539525
Socket connection status.
@@ -552,17 +538,17 @@ def socket_status(self, socket_num: int) -> int:
552538
def socket_connect(
553539
self,
554540
socket_num: int,
555-
dest: Union[bytes, IpAddress4Raw],
541+
dest: IpAddress4Raw,
556542
port: int,
557-
conn_mode: int = _SNMR_TCP,
543+
conn_mode: int = SNMR_TCP,
558544
) -> int:
559545
"""
560546
Open and verify a connection from a socket to a destination IPv4 address
561547
or hostname. A TCP connection is made by default. A UDP connection can also
562548
be made.
563549
564550
:param int socket_num: ID of the socket to be connected.
565-
:param Union[bytes, Address4Bytes] dest: The destination as a host name or IP address.
551+
:param IpAddress4Raw dest: The destination as a host name or IP address.
566552
:param int port: Port to connect to (0 - 65,535).
567553
:param int conn_mode: The connection mode. Use SNMR_TCP for TCP or SNMR_UDP for UDP,
568554
defaults to SNMR_TCP.
@@ -585,7 +571,7 @@ def socket_connect(
585571
self.write_sndport(socket_num, port)
586572
self.write_sncr(socket_num, _CMD_SOCK_CONNECT)
587573

588-
if conn_mode == _SNMR_TCP:
574+
if conn_mode == SNMR_TCP:
589575
# wait for tcp connection establishment
590576
while self.socket_status(socket_num) != SNSR_SOCK_ESTABLISHED:
591577
time.sleep(0.001)
@@ -652,7 +638,7 @@ def release_socket(self, socket_number):
652638
WIZNET5K._sockets_reserved[socket_number - 1] = False
653639

654640
def socket_listen(
655-
self, socket_num: int, port: int, conn_mode: int = _SNMR_TCP
641+
self, socket_num: int, port: int, conn_mode: int = SNMR_TCP
656642
) -> None:
657643
"""
658644
Listen on a socket's port.
@@ -717,7 +703,7 @@ def socket_accept(self, socket_num: int) -> Tuple[int, Tuple[str, int]]:
717703
)
718704
return next_socknum, (dest_ip, dest_port)
719705

720-
def socket_open(self, socket_num: int, conn_mode: int = _SNMR_TCP) -> None:
706+
def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> None:
721707
"""
722708
Open an IP socket.
723709

0 commit comments

Comments
 (0)