@@ -287,14 +287,16 @@ def max_sockets(self) -> int:
287
287
288
288
@property
289
289
def chip (self ) -> str :
290
- """Ethernet controller chip type.
290
+ """
291
+ Ethernet controller chip type.
291
292
292
293
:return str: The chip type."""
293
294
return self ._chip_type
294
295
295
296
@property
296
297
def ip_address (self ) -> bytearray :
297
- """Configured IP address.
298
+ """
299
+ Configured IP address.
298
300
299
301
:return bytearray.
300
302
"""
@@ -305,11 +307,12 @@ def pretty_ip(
305
307
# pylint: disable=no-self-use, invalid-name
306
308
ip : bytearray ,
307
309
) -> str :
308
- """Convert a bytearray IP address to a dotted-quad string for printing.
310
+ """
311
+ Convert a bytearray IP address to a dotted-quad string for printing.
309
312
310
313
:param bytearray ip: A four byte IP address.
311
314
312
- :return str: The IP address in 0.0.0.0 format .
315
+ :return str: The IP address (a string of the form '255.255.255.255') .
313
316
"""
314
317
return "%d.%d.%d.%d" % (ip [0 ], ip [1 ], ip [2 ], ip [3 ])
315
318
@@ -318,9 +321,10 @@ def unpretty_ip(
318
321
# pylint: disable=no-self-use, invalid-name
319
322
ip : str ,
320
323
) -> bytes :
321
- """Convert a dotted-quad string to a four byte IP address.
324
+ """
325
+ Convert a dotted-quad string to a four byte IP address.
322
326
323
- :param str ip: The IP address in the form 0.0.0.0 to be converted.
327
+ :param str ip: The IP address (a string of the form '255.255.255.255') to be converted.
324
328
325
329
:return bytes: The IP address in four bytes.
326
330
"""
@@ -329,14 +333,16 @@ def unpretty_ip(
329
333
330
334
@property
331
335
def mac_address (self ) -> bytearray :
332
- """Ethernet hardware's MAC address.
336
+ """
337
+ Ethernet hardware's MAC address.
333
338
334
339
:return bytearray: The six byte MAC address."""
335
340
return self .read (REG_SHAR , 0x00 , 6 )
336
341
337
342
@mac_address .setter
338
343
def mac_address (self , address : Sequence [Union [int , bytes ]]) -> None :
339
- """Sets the hardware MAC address.
344
+ """
345
+ Sets the hardware MAC address.
340
346
341
347
:param tuple address: Hardware MAC address.
342
348
"""
@@ -347,8 +353,12 @@ def pretty_mac(
347
353
# pylint: disable=no-self-use, invalid-name
348
354
mac : bytearray ,
349
355
) -> str :
350
- """Converts a bytearray MAC address to a
351
- dotted-quad string for printing
356
+ """
357
+ Convert a bytearray MAC address to a ':' seperated string for display.
358
+
359
+ :param bytearray mac: The MAC address.
360
+
361
+ :return str: Mac Address in the form 00:00:00:00:00:00
352
362
353
363
"""
354
364
return "%s:%s:%s:%s:%s:%s" % (
@@ -361,7 +371,8 @@ def pretty_mac(
361
371
)
362
372
363
373
def remote_ip (self , socket_num : int ) -> Union [str , bytearray ]:
364
- """IP address of the host which sent the current incoming packet.
374
+ """
375
+ IP address of the host which sent the current incoming packet.
365
376
366
377
:param int socket_num: ID number of the socket to check.
367
378
@@ -388,7 +399,8 @@ def link_status(self) -> int:
388
399
return 0
389
400
390
401
def remote_port (self , socket_num : int ) -> Union [int , bytearray ]:
391
- """Port of the host which sent the current incoming packet.
402
+ """
403
+ Port of the host which sent the current incoming packet.
392
404
393
405
:param int socket_num: ID number of the socket to check.
394
406
@@ -405,7 +417,8 @@ def remote_port(self, socket_num: int) -> Union[int, bytearray]:
405
417
def ifconfig (
406
418
self ,
407
419
) -> Tuple [bytearray , bytearray , bytearray , Tuple [int , int , int , int ]]: # *1
408
- """Network configuration information.
420
+ """
421
+ Network configuration information.
409
422
410
423
:return Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
411
424
The IP address, subnet mask, gateway address and DNS server address."""
@@ -420,7 +433,8 @@ def ifconfig(
420
433
def ifconfig (
421
434
self , params : Tuple [bytearray , bytearray , bytearray , Tuple [int , int , int , int ]]
422
435
) -> None :
423
- """Set network configuration.
436
+ """
437
+ Set network configuration.
424
438
425
439
:params Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
426
440
Configuration settings - (ip_address, subnet_mask, gateway_address, dns_server).
@@ -435,7 +449,8 @@ def ifconfig(
435
449
self ._dns = dns_server
436
450
437
451
def _w5100_init (self ) -> int :
438
- """Detects and initializes a Wiznet5k ethernet module.
452
+ """
453
+ Detect and initialize a Wiznet5k ethernet module.
439
454
440
455
:return int: 1 if the initialization succeeds, 0 if it fails.
441
456
"""
@@ -460,7 +475,8 @@ def _w5100_init(self) -> int:
460
475
return 1
461
476
462
477
def detect_w5500 (self ) -> int :
463
- """Detects W5500 chip.
478
+ """
479
+ Detect W5500 chip.
464
480
465
481
:return int: 1 if a W5500 chip is detected, -1 if not.
466
482
"""
@@ -488,7 +504,8 @@ def detect_w5500(self) -> int:
488
504
return 1
489
505
490
506
def detect_w5100s (self ) -> int :
491
- """Detects W5100S chip.
507
+ """
508
+ Detect W5100S chip.
492
509
493
510
:return int: 1 if a W5100 chip is detected, -1 if not.
494
511
"""
@@ -502,8 +519,9 @@ def detect_w5100s(self) -> int:
502
519
return 1
503
520
504
521
def sw_reset (self ) -> int :
505
- """Perform a soft-reset on the Wiznet chip
506
- by writing to its MR register reset bit.
522
+ """Perform a soft-reset on the Wiznet chip.
523
+
524
+ Perform a soft reset by writing to the chip's MR register reset bit.
507
525
508
526
:return int: 0 if the reset succeeds, -1 if not.
509
527
"""
@@ -518,12 +536,12 @@ def sw_reset(self) -> int:
518
536
return 0
519
537
520
538
def _read_mr (self ) -> bytearray :
521
- """Reads from the Mode Register (MR)."""
539
+ """Read from the Mode Register (MR)."""
522
540
res = self .read (REG_MR , 0x00 )
523
541
return res
524
542
525
543
def _write_mr (self , data : int ) -> None :
526
- """Writes to the mode register (MR)."""
544
+ """Write to the mode register (MR)."""
527
545
self .write (REG_MR , 0x04 , data )
528
546
529
547
def read (
@@ -533,7 +551,8 @@ def read(
533
551
length : int = 1 ,
534
552
buffer : Optional [WriteableBuffer ] = None ,
535
553
) -> Union [WriteableBuffer , bytearray ]:
536
- """Read data from a register address.
554
+ """
555
+ Read data from a register address.
537
556
538
557
:param int addr: Register address to read.
539
558
:param int callback: Callback reference.
@@ -563,7 +582,8 @@ def read(
563
582
def write (
564
583
self , addr : int , callback : int , data : Union [int , Sequence [Union [int , bytes ]]]
565
584
) -> None :
566
- """Write data to a register address.
585
+ """
586
+ Write data to a register address.
567
587
568
588
:param int addr: Destination address.
569
589
:param int callback: Callback reference.
@@ -590,7 +610,8 @@ def write(
590
610
# Socket-Register API
591
611
592
612
def socket_available (self , socket_num : int , sock_type : int = SNMR_TCP ) -> int :
593
- """Return the number of bytes available to be read from the socket.
613
+ """
614
+ Return the number of bytes available to be read from the socket.
594
615
595
616
:param int socket_num: Socket to check for available bytes.
596
617
:param int sock_type: Socket type. Use SNMR_TCP for TCP or SNMR_UDP for UDP, \
@@ -625,7 +646,8 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
625
646
return 0
626
647
627
648
def socket_status (self , socket_num : int ) -> Union [bytearray , None ]:
628
- """Returns the socket connection status.
649
+ """
650
+ Return the socket connection status.
629
651
630
652
Can be: SNSR_SOCK_CLOSED, SNSR_SOCK_INIT, SNSR_SOCK_LISTEN, SNSR_SOCK_SYNSENT,
631
653
SNSR_SOCK_SYNRECV, SNSR_SYN_SOCK_ESTABLISHED, SNSR_SOCK_FIN_WAIT,
@@ -645,7 +667,8 @@ def socket_connect(
645
667
port : int ,
646
668
conn_mode : int = SNMR_TCP ,
647
669
) -> int :
648
- """Open and verify a connection from a socket to a destination IP address
670
+ """
671
+ Open and verify a connection from a socket to a destination IP address
649
672
or hostname. A TCP connection is made by default. A UDP connection can also
650
673
be made.
651
674
@@ -692,8 +715,7 @@ def _send_socket_cmd(self, socket: int, cmd: int) -> None:
692
715
print ("waiting for sncr to clear..." )
693
716
694
717
def get_socket (self ) -> int :
695
- """Requests, allocates and returns a socket from the W5k
696
- chip.
718
+ """Request, allocate and return a socket from the W5k chip.
697
719
698
720
Cycles through the sockets to find the first available one, if any.
699
721
@@ -716,7 +738,8 @@ def get_socket(self) -> int:
716
738
def socket_listen (
717
739
self , socket_num : int , port : int , conn_mode : int = SNMR_TCP
718
740
) -> None :
719
- """Start listening on a socket's port.
741
+ """
742
+ Listen on a socket's port.
720
743
721
744
:param int socket_num: ID of socket to listen on.
722
745
:param int port: Port to listen on (0 - 65,535).
@@ -748,15 +771,16 @@ def socket_listen(
748
771
def socket_accept (
749
772
self , socket_num : int
750
773
) -> Tuple [int , Tuple [Union [str , bytearray ], Union [int , bytearray ]]]:
751
- """Gets the dest IP and port from an incoming connection.
774
+ """
775
+ Destination IP address and port from an incoming connection.
752
776
753
- Returns the next socket number so listening can continue, along with
777
+ Return the next socket number so listening can continue, along with
754
778
the IP address and port of the incoming connection.
755
779
756
780
:param int socket_num: Socket number with connection to check.
757
781
758
782
:return Tuple[int, Tuple[Union[str, bytearray], Union[int, bytearray]]]:
759
- If successful, the next (socket number, (destination IP address, destination port)).
783
+ If successful, the next (socket number, (destination IP address, destination port)).
760
784
761
785
If errors occur, the destination IP address and / or the destination port may be
762
786
returned as bytearrays.
@@ -773,7 +797,8 @@ def socket_accept(
773
797
return next_socknum , (dest_ip , dest_port )
774
798
775
799
def socket_open (self , socket_num : int , conn_mode : int = SNMR_TCP ) -> int :
776
- """Opens a network socket.
800
+ """
801
+ Open an IP socket.
777
802
778
803
The socket may connect via TCP or UDP protocols.
779
804
@@ -823,7 +848,8 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
823
848
return 1
824
849
825
850
def socket_close (self , socket_num : int ) -> None :
826
- """Close a socket.
851
+ """
852
+ Close a socket.
827
853
828
854
:param int socket_num: The socket to close.
829
855
"""
@@ -833,7 +859,8 @@ def socket_close(self, socket_num: int) -> None:
833
859
self ._read_sncr (socket_num )
834
860
835
861
def socket_disconnect (self , socket_num : int ) -> None :
836
- """Disconnect a TCP or UDP connection.
862
+ """
863
+ Disconnect a TCP or UDP connection.
837
864
838
865
:param int socket_num: The socket to close.
839
866
"""
@@ -845,7 +872,8 @@ def socket_disconnect(self, socket_num: int) -> None:
845
872
def socket_read (
846
873
self , socket_num : int , length : int
847
874
) -> Tuple [int , Union [int , bytearray ]]:
848
- """Read data from a TCP socket.
875
+ """
876
+ Read data from a TCP socket.
849
877
850
878
:param int socket_num: The socket to read data from.
851
879
:param int length: The number of bytes to read from the socket.
@@ -915,7 +943,8 @@ def socket_read(
915
943
def read_udp (
916
944
self , socket_num : int , length : int
917
945
) -> Union [int , Tuple [int , Union [int , bytearray ]]]:
918
- """Read UDP socket's current message bytes.
946
+ """
947
+ Read UDP socket's current message bytes.
919
948
920
949
:param int socket_num: The socket to read data from.
921
950
:param int length: The number of bytes to read from the socket.
@@ -938,7 +967,8 @@ def read_udp(
938
967
def socket_write (
939
968
self , socket_num : int , buffer : bytearray , timeout : float = 0
940
969
) -> int :
941
- """Write data to a socket.
970
+ """
971
+ Write data to a socket.
942
972
943
973
:param int socket_num: The socket to write to.
944
974
:param bytearray buffer: The data to write to the socket.
@@ -1020,7 +1050,7 @@ def socket_write(
1020
1050
1021
1051
# Socket-Register Methods
1022
1052
def _get_rx_rcv_size (self , sock : int ) -> int :
1023
- """Get size of received and saved in socket buffer."""
1053
+ """Size of received and saved in socket buffer."""
1024
1054
val = 0
1025
1055
val_1 = self ._read_snrx_rsr (sock )
1026
1056
while val != val_1 :
@@ -1030,7 +1060,7 @@ def _get_rx_rcv_size(self, sock: int) -> int:
1030
1060
return int .from_bytes (val , "big" )
1031
1061
1032
1062
def _get_tx_free_size (self , sock : int ) -> int :
1033
- """Get free size of socket's tx buffer block."""
1063
+ """Free size of socket's tx buffer block."""
1034
1064
val = 0
1035
1065
val_1 = self ._read_sntx_fsr (sock )
1036
1066
while val != val_1 :
@@ -1068,17 +1098,17 @@ def _read_snrx_rsr(self, sock: int) -> Union[bytearray, None]:
1068
1098
return data
1069
1099
1070
1100
def _write_sndipr (self , sock : int , ip_addr : bytearray ) -> None :
1071
- """Writes to socket destination IP Address."""
1101
+ """Write to socket destination IP Address."""
1072
1102
for octet in range (4 ):
1073
1103
self ._write_socket (sock , REG_SNDIPR + octet , ip_addr [octet ])
1074
1104
1075
1105
def _write_sndport (self , sock : int , port : int ) -> None :
1076
- """Writes to socket destination port."""
1106
+ """Write to socket destination port."""
1077
1107
self ._write_socket (sock , REG_SNDPORT , port >> 8 )
1078
1108
self ._write_socket (sock , REG_SNDPORT + 1 , port & 0xFF )
1079
1109
1080
1110
def _read_snsr (self , sock : int ) -> Union [bytearray , None ]:
1081
- """Reads Socket n Status Register."""
1111
+ """Read Socket n Status Register."""
1082
1112
return self ._read_socket (sock , REG_SNSR )
1083
1113
1084
1114
def _write_snmr (self , sock : int , protocol : int ) -> None :
0 commit comments