@@ -166,9 +166,7 @@ def __init__(self, spi_bus, cs, reset=None,
166
166
167
167
# Buffer for reading params from module
168
168
self ._pbuff = bytearray (8 )
169
-
170
-
171
- self ._rbuf = bytearray (1 )
169
+ self ._rxbuf = bytearray (MAX_PACKET )
172
170
173
171
# attempt to initialize the module
174
172
self ._ch_base_msb = 0
@@ -395,22 +393,28 @@ def read(self, addr, callback, length=1, buffer=None):
395
393
return buffer
396
394
397
395
def write (self , addr , callback , data ):
396
+ """Write data to a register address.
397
+ :param int addr: Destination address.
398
+ :param int callback: Callback reference.
399
+ :param int data: Data to write, as an integer.
400
+ :param bytearray data: Data to write, as a bytearray.
401
+
402
+ """
398
403
with self ._device as bus_device :
399
404
bus_device .write (bytes ([addr >> 8 ]))
400
405
bus_device .write (bytes ([addr & 0xFF ]))
401
406
bus_device .write (bytes ([callback ]))
402
407
403
- if hasattr (data ,'from_bytes' ):
408
+ if hasattr (data , 'from_bytes' ):
404
409
bus_device .write (bytes ([data ]))
405
410
else :
406
411
for i , _ in enumerate (data ):
407
412
bus_device .write (bytes ([data [i ]]))
408
- return len
409
-
410
413
411
414
# Socket-Register API
412
-
413
415
def _udp_remaining (self ):
416
+ if self ._debug :
417
+ print ("* UDP Bytes Remaining: " , UDP_SOCK ['bytes_remaining' ])
414
418
return UDP_SOCK ['bytes_remaining' ]
415
419
416
420
def socket_available (self , socket_num , sock_type = SNMR_TCP ):
@@ -425,7 +429,6 @@ def socket_available(self, socket_num, sock_type=SNMR_TCP):
425
429
assert socket_num <= self .max_sockets , "Provided socket exceeds max_sockets."
426
430
427
431
if sock_type == 0x02 :
428
- print ('UDP: ' , UDP_SOCK ['bytes_remaining' ])
429
432
# flush by reading remaining data from previous packet
430
433
while UDP_SOCK ['bytes_remaining' ] > 0 and self .socket_read (socket_num , 1 ):
431
434
if self ._debug :
@@ -435,7 +438,6 @@ def socket_available(self, socket_num, sock_type=SNMR_TCP):
435
438
436
439
res = self ._get_rx_rcv_size (socket_num )
437
440
438
- print ('Res: ' , res )
439
441
res = int .from_bytes (res , 'b' )
440
442
if sock_type == SNMR_TCP :
441
443
return res
@@ -572,8 +574,6 @@ def socket_read_udp(self, socket_num, length):
572
574
UDP_SOCK ['bytes_remaining' ] -= ret
573
575
if self ._debug :
574
576
print ("UDP read {0} bytes: " .format (ret ))
575
- print (UDP_SOCK ['bytes_remaining' ])
576
- print (resp )
577
577
return ret , resp
578
578
# failed to read or no data
579
579
return - 1
@@ -617,7 +617,6 @@ def socket_read(self, socket_num, length):
617
617
# Read data from the starting address of snrx_rd
618
618
ctrl_byte = (0x18 + (socket_num << 5 ))
619
619
620
- print ("Read data, len={}, at: {}" .format (ret , ptr ))
621
620
resp = self .read (ptr , ctrl_byte , ret )
622
621
623
622
# After reading the received data, update Sn_RX_RD to the increased
0 commit comments