30
30
pass
31
31
32
32
try :
33
- from typing import Optional , Any
33
+ from typing import Optional
34
34
except ImportError :
35
35
pass
36
36
@@ -132,7 +132,7 @@ def ticks_diff(ticks1: int, ticks2: int) -> int:
132
132
"""Compute the signed difference between two ticks values
133
133
assuming that they are within 2**28 ticks
134
134
"""
135
- diff : int = (ticks1 - ticks2 ) & _TICKS_MAX
135
+ diff = (ticks1 - ticks2 ) & _TICKS_MAX
136
136
diff = ((diff + _TICKS_HALFPERIOD ) & _TICKS_MAX ) - _TICKS_HALFPERIOD
137
137
return diff
138
138
@@ -207,11 +207,11 @@ def __init__(self, address: int, *, offset: int = 0, bits: int = 1) -> None:
207
207
self ._offset = offset
208
208
209
209
def __get__ (self , obj , objtype ) -> int :
210
- reg_value : int = obj ._read_u8 (self ._address )
210
+ reg_value = obj ._read_u8 (self ._address )
211
211
return (reg_value & self ._mask ) >> self ._offset
212
212
213
213
def __set__ (self , obj , val ) -> None :
214
- reg_value : int = obj ._read_u8 (self ._address )
214
+ reg_value = obj ._read_u8 (self ._address )
215
215
reg_value &= ~ self ._mask
216
216
reg_value |= (val & 0xFF ) << self ._offset
217
217
obj ._write_u8 (self ._address , reg_value )
@@ -262,7 +262,7 @@ def __init__(
262
262
agc : bool = False ,
263
263
crc : bool = True
264
264
) -> None :
265
- self .high_power : bool = high_power
265
+ self .high_power = high_power
266
266
# Device support SPI mode 0 (polarity & phase = 0) up to a max of 10mhz.
267
267
# Set Default Baudrate to 5MHz to avoid problems
268
268
self ._device : spidev .SPIDevice = spidev .SPIDevice (
@@ -276,7 +276,7 @@ def __init__(
276
276
self .reset ()
277
277
# No device type check! Catch an error from the very first request and
278
278
# throw a nicer message to indicate possible wiring problems.
279
- version : int = self ._read_u8 (_RH_RF95_REG_42_VERSION )
279
+ version = self ._read_u8 (_RH_RF95_REG_42_VERSION )
280
280
if version != 18 :
281
281
raise RuntimeError (
282
282
"Failed to find rfm9x with expected version -- check wiring"
@@ -298,78 +298,78 @@ def __init__(
298
298
# Set mode idle
299
299
self .idle ()
300
300
# Set frequency
301
- self .frequency_mhz : float = frequency
301
+ self .frequency_mhz = frequency
302
302
# Set preamble length (default 8 bytes to match radiohead).
303
- self .preamble_length : int = preamble_length
303
+ self .preamble_length = preamble_length
304
304
# Defaults set modem config to RadioHead compatible Bw125Cr45Sf128 mode.
305
- self .signal_bandwidth : int = 125000
306
- self .coding_rate : int = 5
307
- self .spreading_factor : int = 7
305
+ self .signal_bandwidth = 125000
306
+ self .coding_rate = 5
307
+ self .spreading_factor = 7
308
308
# Default to enable CRC checking on incoming packets.
309
- self .enable_crc : bool = crc
309
+ self .enable_crc = crc
310
310
"""CRC Enable state"""
311
311
# set AGC - Default = False
312
312
self .auto_agc = agc
313
313
"""Automatic Gain Control state"""
314
314
# Set transmit power to 13 dBm, a safe value any module supports.
315
- self .tx_power : int = 13
315
+ self .tx_power = 13
316
316
# initialize last RSSI reading
317
- self .last_rssi : float = 0.0
317
+ self .last_rssi = 0.0
318
318
"""The RSSI of the last received packet. Stored when the packet was received.
319
319
The instantaneous RSSI value may not be accurate once the
320
320
operating mode has been changed.
321
321
"""
322
- self .last_snr : float = 0.0
322
+ self .last_snr = 0.0
323
323
"""The SNR of the last received packet. Stored when the packet was received.
324
324
The instantaneous SNR value may not be accurate once the
325
325
operating mode has been changed.
326
326
"""
327
327
# initialize timeouts and delays delays
328
- self .ack_wait : float = 0.5
328
+ self .ack_wait = 0.5
329
329
"""The delay time before attempting a retry after not receiving an ACK"""
330
- self .receive_timeout : float = 0.5
330
+ self .receive_timeout = 0.5
331
331
"""The amount of time to poll for a received packet.
332
332
If no packet is received, the returned packet will be None
333
333
"""
334
- self .xmit_timeout : float = 2.0
334
+ self .xmit_timeout = 2.0
335
335
"""The amount of time to wait for the HW to transmit the packet.
336
336
This is mainly used to prevent a hang due to a HW issue
337
337
"""
338
- self .ack_retries : int = 5
338
+ self .ack_retries = 5
339
339
"""The number of ACK retries before reporting a failure."""
340
- self .ack_delay : Optional [ float ] = None
340
+ self .ack_delay = None
341
341
"""The delay time before attemting to send an ACK.
342
342
If ACKs are being missed try setting this to .1 or .2.
343
343
"""
344
344
# initialize sequence number counter for reliabe datagram mode
345
- self .sequence_number : int = 0
345
+ self .sequence_number = 0
346
346
# create seen Ids list
347
- self .seen_ids : bytearray = bytearray (256 )
347
+ self .seen_ids = bytearray (256 )
348
348
# initialize packet header
349
349
# node address - default is broadcast
350
- self .node : int = _RH_BROADCAST_ADDRESS
350
+ self .node = _RH_BROADCAST_ADDRESS
351
351
"""The default address of this Node. (0-255).
352
352
If not 255 (0xff) then only packets address to this node will be accepted.
353
353
First byte of the RadioHead header.
354
354
"""
355
355
# destination address - default is broadcast
356
- self .destination : int = _RH_BROADCAST_ADDRESS
356
+ self .destination = _RH_BROADCAST_ADDRESS
357
357
"""The default destination address for packet transmissions. (0-255).
358
358
If 255 (0xff) then any receiving node should accept the packet.
359
359
Second byte of the RadioHead header.
360
360
"""
361
361
# ID - contains seq count for reliable datagram mode
362
- self .identifier : int = 0
362
+ self .identifier = 0
363
363
"""Automatically set to the sequence number when send_with_ack() used.
364
364
Third byte of the RadioHead header.
365
365
"""
366
366
# flags - identifies ack/reetry packet for reliable datagram mode
367
- self .flags : int = 0
367
+ self .flags = 0
368
368
"""Upper 4 bits reserved for use by Reliable Datagram Mode.
369
369
Lower 4 bits may be used to pass information.
370
370
Fourth byte of the RadioHead header.
371
371
"""
372
- self .crc_error_count : int = 0
372
+ self .crc_error_count = 0
373
373
374
374
# pylint: disable=no-member
375
375
# Reconsider pylint: disable when this can be tested
@@ -530,7 +530,7 @@ def rssi(self) -> int:
530
530
"""The received strength indicator (in dBm) of the last received message."""
531
531
# Read RSSI register and convert to value using formula in datasheet.
532
532
# Remember in LoRa mode the payload register changes function to RSSI!
533
- raw_rssi : int = self ._read_u8 (_RH_RF95_REG_1A_PKT_RSSI_VALUE )
533
+ raw_rssi = self ._read_u8 (_RH_RF95_REG_1A_PKT_RSSI_VALUE )
534
534
if self .low_frequency_mode :
535
535
raw_rssi -= 157
536
536
else :
@@ -542,7 +542,7 @@ def snr(self) -> float:
542
542
"""The SNR (in dB) of the last received message."""
543
543
# Read SNR 0x19 register and convert to value using formula in datasheet.
544
544
# SNR(dB) = PacketSnr [twos complement] / 4
545
- snr_byte : int = self ._read_u8 (_RH_RF95_REG_19_PKT_SNR_VALUE )
545
+ snr_byte = self ._read_u8 (_RH_RF95_REG_19_PKT_SNR_VALUE )
546
546
if snr_byte > 127 :
547
547
snr_byte = (256 - snr_byte ) * - 1
548
548
return snr_byte / 4
@@ -553,7 +553,7 @@ def signal_bandwidth(self) -> int:
553
553
value to increase throughput or to a lower value to increase the
554
554
likelihood of successfully received payloads). Valid values are
555
555
listed in RFM9x.bw_bins."""
556
- bw_id : int = (self ._read_u8 (_RH_RF95_REG_1D_MODEM_CONFIG1 ) & 0xF0 ) >> 4
556
+ bw_id = (self ._read_u8 (_RH_RF95_REG_1D_MODEM_CONFIG1 ) & 0xF0 ) >> 4
557
557
if bw_id >= len (self .bw_bins ):
558
558
current_bandwidth = 500000
559
559
else :
@@ -563,8 +563,6 @@ def signal_bandwidth(self) -> int:
563
563
@signal_bandwidth .setter
564
564
def signal_bandwidth (self , val : int ) -> None :
565
565
# Set signal bandwidth (set to 125000 to match RadioHead Bw125).
566
- bw_id : int
567
- cutoff : int
568
566
for bw_id , cutoff in enumerate (self .bw_bins ):
569
567
if val <= cutoff :
570
568
break
@@ -603,7 +601,7 @@ def coding_rate(self) -> int:
603
601
correction (try setting to a higher value to increase tolerance of
604
602
short bursts of interference or to a lower value to increase bit
605
603
rate). Valid values are limited to 5, 6, 7, or 8."""
606
- cr_id : int = (self ._read_u8 (_RH_RF95_REG_1D_MODEM_CONFIG1 ) & 0x0E ) >> 1
604
+ cr_id = (self ._read_u8 (_RH_RF95_REG_1D_MODEM_CONFIG1 ) & 0x0E ) >> 1
607
605
denominator = cr_id + 4
608
606
return denominator
609
607
@@ -681,7 +679,7 @@ def crc_error(self) -> int:
681
679
# pylint: disable=too-many-branches
682
680
def send (
683
681
self ,
684
- data : Any ,
682
+ data ,
685
683
* ,
686
684
keep_listening : bool = False ,
687
685
destination = None ,
@@ -760,7 +758,7 @@ def send(
760
758
self ._write_u8 (_RH_RF95_REG_12_IRQ_FLAGS , 0xFF )
761
759
return not timed_out
762
760
763
- def send_with_ack (self , data : Any ) -> bool :
761
+ def send_with_ack (self , data ) -> bool :
764
762
"""Reliable Datagram mode:
765
763
Send a packet with data and wait for an ACK response.
766
764
The packet header is automatically generated.
@@ -770,7 +768,7 @@ def send_with_ack(self, data: Any) -> bool:
770
768
retries_remaining = self .ack_retries
771
769
else :
772
770
retries_remaining = 1
773
- got_ack : bool = False
771
+ got_ack = False
774
772
self .sequence_number = (self .sequence_number + 1 ) & 0xFF
775
773
while not got_ack and retries_remaining :
776
774
self .identifier = self .sequence_number
@@ -804,7 +802,7 @@ def receive(
804
802
with_header : bool = False ,
805
803
with_ack : bool = False ,
806
804
timeout : Optional [float ] = None
807
- ):
805
+ ) -> Optional [ bytearray ] :
808
806
"""Wait to receive a packet from the receiver. If a packet is found the payload bytes
809
807
are returned, otherwise None is returned (which indicates the timeout elapsed with no
810
808
reception).
@@ -841,7 +839,7 @@ def receive(
841
839
if time .monotonic () - start >= timeout :
842
840
timed_out = True
843
841
# Payload ready is set, a packet is in the FIFO.
844
- packet : Optional [ bytearray ] = None
842
+ packet = None
845
843
# save last RSSI reading
846
844
self .last_rssi = self .rssi
847
845
0 commit comments