@@ -267,7 +267,7 @@ def __init__(
267267 preamble_length = 4 ,
268268 encryption_key = None ,
269269 high_power = True ,
270- baudrate = 5000000
270+ baudrate = 1000000
271271 ):
272272 self ._tx_power = 13
273273 self .high_power = high_power
@@ -400,19 +400,6 @@ def _write_from(self, address, buf, length=None):
400400 device .write (self ._BUFFER , end = 1 )
401401 device .write (buf , end = length ) # send data
402402
403- def _write_fifo_from (self , buf , length = None ):
404- # Write a number of bytes to the transmit FIFO and taken from the
405- # provided buffer. If no length is specified (the default) the entire
406- # buffer is written.
407- if length is None :
408- length = len (buf )
409- with self ._device as device :
410- self ._BUFFER [0 ] = (_REG_FIFO | 0x80 ) & 0xFF # Set top bit to 1 to
411- # indicate a write.
412- self ._BUFFER [1 ] = length & 0xFF # Set packt length
413- device .write (self ._BUFFER , end = 2 ) # send address and lenght)
414- device .write (buf , end = length ) # send data
415-
416403 def _write_u8 (self , address , val ):
417404 # Write a byte register to the chip. Specify the 7-bit address and the
418405 # 8-bit value to write to that address.
@@ -754,26 +741,27 @@ def send(
754741 self .idle () # Stop receiving to clear FIFO and keep it clear.
755742 # Fill the FIFO with a packet to send.
756743 # Combine header and data to form payload
757- payload = bytearray (4 )
744+ payload = bytearray (5 )
745+ payload [0 ] = 4 + len (data )
758746 if destination is None : # use attribute
759- payload [0 ] = self .destination
747+ payload [1 ] = self .destination
760748 else : # use kwarg
761- payload [0 ] = destination
749+ payload [1 ] = destination
762750 if node is None : # use attribute
763- payload [1 ] = self .node
751+ payload [2 ] = self .node
764752 else : # use kwarg
765- payload [1 ] = node
753+ payload [2 ] = node
766754 if identifier is None : # use attribute
767- payload [2 ] = self .identifier
755+ payload [3 ] = self .identifier
768756 else : # use kwarg
769- payload [2 ] = identifier
757+ payload [3 ] = identifier
770758 if flags is None : # use attribute
771- payload [3 ] = self .flags
759+ payload [4 ] = self .flags
772760 else : # use kwarg
773- payload [3 ] = flags
761+ payload [4 ] = flags
774762 payload = payload + data
775763 # Write payload to transmit fifo
776- self ._write_fifo_from ( payload )
764+ self ._write_from ( _REG_FIFO , payload )
777765 # Turn on transmit mode to send out the packet.
778766 self .transmit ()
779767 # Wait for packet sent interrupt with explicit polling (not ideal but
@@ -873,7 +861,8 @@ def receive(
873861 # RadioHead header and at least one byte of data --reject this packet and ignore it.
874862 if fifo_length > 0 : # read and clear the FIFO if anything in it
875863 packet = bytearray (fifo_length )
876- self ._read_into (_REG_FIFO , packet )
864+ self ._read_into (_REG_FIFO , packet , fifo_length )
865+
877866 if fifo_length < 5 :
878867 packet = None
879868 else :
0 commit comments