@@ -741,31 +741,32 @@ def receive(self, timeout=0.5, keep_listening=True):
741
741
packet = None
742
742
# Enter idle mode to stop receiving other packets.
743
743
self .idle ()
744
- if not timed_out :
745
- # Read the data from the FIFO.
746
- with self ._device as device :
747
- self ._BUFFER [0 ] = _REG_FIFO & 0x7F # Strip out top bit to set 0
748
- # value (read).
749
- device .write (self ._BUFFER , end = 1 )
750
- # Read the length of the FIFO.
751
- device .readinto (self ._BUFFER , end = 1 )
752
- fifo_length = self ._BUFFER [0 ]
753
- # Handle if the received packet is too small to include the 4 byte
754
- # RadioHead header--reject this packet and ignore it.
755
- if fifo_length < 4 :
756
- # Invalid packet, ignore it. However finish reading the FIFO
757
- # to clear the packet.
758
- device .readinto (self ._BUFFER , end = fifo_length )
759
- packet = None
760
- else :
761
- # Read the 4 bytes of the RadioHead header.
762
- device .readinto (self ._BUFFER , end = 4 )
763
- # Ignore validating any of the header bytes.
764
- # Now read the remaining packet payload as the result.
765
- fifo_length -= 4
766
- packet = bytearray (fifo_length )
767
- device .readinto (packet )
768
- # Listen again if necessary and return the result packet.
769
- if keep_listening :
770
- self .listen ()
744
+ if timed_out :
745
+ return None
746
+ # Read the data from the FIFO.
747
+ with self ._device as device :
748
+ self ._BUFFER [0 ] = _REG_FIFO & 0x7F # Strip out top bit to set 0
749
+ # value (read).
750
+ device .write (self ._BUFFER , end = 1 )
751
+ # Read the length of the FIFO.
752
+ device .readinto (self ._BUFFER , end = 1 )
753
+ fifo_length = self ._BUFFER [0 ]
754
+ # Handle if the received packet is too small to include the 4 byte
755
+ # RadioHead header--reject this packet and ignore it.
756
+ if fifo_length < 4 :
757
+ # Invalid packet, ignore it. However finish reading the FIFO
758
+ # to clear the packet.
759
+ device .readinto (self ._BUFFER , end = fifo_length )
760
+ packet = None
761
+ else :
762
+ # Read the 4 bytes of the RadioHead header.
763
+ device .readinto (self ._BUFFER , end = 4 )
764
+ # Ignore validating any of the header bytes.
765
+ # Now read the remaining packet payload as the result.
766
+ fifo_length -= 4
767
+ packet = bytearray (fifo_length )
768
+ device .readinto (packet )
769
+ # Listen again if necessary and return the result packet.
770
+ if keep_listening :
771
+ self .listen ()
771
772
return packet
0 commit comments