-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
855 lines (637 loc) · 27.7 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# SPDX-FileCopyrightText: Copyright (c) 2023 Herwin Bozet
#
# SPDX-License-Identifier: MIT
"""
`ebyte_e32`
====================================================
* Author(s): Herwin Bozet
"""
from collections import namedtuple
from time import sleep
try:
from typing import Union, Optional, Tuple
except ImportError:
pass
from busio import UART
from digitalio import Direction, DigitalInOut
from microcontroller import Pin
from .exceptions import E32GenericError
class Modes:
"""
Refers to the E32 module's operating modes set via the `M0` and `M1` pins.
The constants' values are organized in the following manner:
`list[M0: int, M1_Value: int]`
"""
MODE_NORMAL = (0, 0)
"""
UART and LoRa radio are ready to receive and return packages.
Also known as `Mode 0`.
"""
MODE_WAKE_UP = (1, 0)
"""
Same as normal mode, with a preamble added to sent data to wake up the receiver.
The preamble's code length depends on the [???] set in the module operating configuration.
Also known as `Mode 1`.
"""
MODE_POWER_SAVE = (0, 1)
"""
The UART bus is disabled, and the module waits for incoming messages with the appropriate preambles.
Once received, AUX goes low for ~5ms and the UART bus is re-opened, it sends the message, and AUX goes high again.
Also known as `Mode 2` or `PS Mode`.
"""
MODE_SLEEP = (1, 1)
"""
Puts the module in sleep mode where the LoRa radio is turned off and the UART bus
can be used to set and get the module's parameters, or reset it.
Also known as `Mode 3`.
"""
class SerialParity:
"""
UART bus parity for all communications between the module and the MCU in any non-sleep modes.
This setting isn't related to the LoRa transmission rate and can be different between communicating modules.
"""
PARITY_NONE = 0b00
"Same as 8N1"
PARITY_ODD = 0b01
"Same as 8O1"
PARITY_EVEN = 0b10
"Same as 8E1"
PARITY_DEFAULT = PARITY_NONE
"Default UART parity on E32 devices"
class SerialBaudRate:
"""
UART baud rate for all communications between the module and the MCU in any non-sleep modes.
This setting isn't related to the LoRa transmission rate and can be different between communicating modules.
"""
BAUD_1200 = (0b000, 1200)
"Equal to 1200 bps"
BAUD_2400 = (0b001, 2400)
"Equal to 2400 bps"
BAUD_4800 = (0b010, 4800)
"Equal to 4800 bps"
BAUD_9600 = (0b011, 9600)
"Equal to 9600 bps (Default)"
BAUD_19200 = (0b100, 19200)
"Equal to 19200 bps"
BAUD_38400 = (0b101, 38400)
"Equal to 38400 bps"
BAUD_57600 = (0b110, 57600)
"Equal to 57600 bps"
BAUD_115200 = (0b111, 115200)
"Equal to 115200 bps"
BAUD_DEFAULT = BAUD_9600
"Default baud rate on E32 devices"
class AirDataRate:
"""
Data rate in bps at which LoRa modules communicate between each other.
**This setting directly affects the maximum packet size and communication range !**
**This setting must be the same between all communicating modules.**
"""
RATE_0_3K = 0b000
"Equal to 0.3 kbps"
RATE_1_2K = 0b001
"Equal to 1.2 kbps"
RATE_2_4K = 0b010
"Equal to 2.4 kbps"
RATE_4_8K = 0b011
"Equal to 4.8 kbps"
RATE_9_6K = 0b100
"Equal to 9.6 kbps"
RATE_19_2K = 0b101
"Equal to 19.2 kbps"
RATE_DEFAULT = RATE_2_4K
"Default air data rate on E32 devices"
class TransmissionMode:
"""
Transmission modes available for LoRa communications.
"""
TRANSMISSION_TRANSPARENT = 0b0
"""
In this mode all devices on the same channel and address will communicate between each other.
"""
TRANSMISSION_FIXED = 0b1
"""
In this mode all devices will be able communicate between each other by prepending the target channel and
address to each message.
You can also use the special ``0xFFFF`` address to monitor or broadcast messages on a given channel.
The module will automatically switch channel if required and will return to it's original one.
"""
TRANSMISSION_DEFAULT = TRANSMISSION_TRANSPARENT
"""
Default transmission mode on E32 devices.
This is not explicitly indicated in the E32 datasheets, but this is the case in practice.
"""
class WakeUpTime:
"""
???
[Not on mode 0 !]
This setting isn't related to the LoRa transmission rate and can be different between communicating modules.
"""
WAKE_TIME_250MS = 0b000
"???"
WAKE_TIME_500MS = 0b001
"???"
WAKE_TIME_750MS = 0b010
"???"
WAKE_TIME_1000MS = 0b011
"???"
WAKE_TIME_1250MS = 0b100
"???"
WAKE_TIME_1500MS = 0b101
"???"
WAKE_TIME_1750MS = 0b110
"???"
WAKE_TIME_2000MS = 0b111
"???"
WAKE_TIME_DEFAULT = WAKE_TIME_250MS
"Default wake-up time on E32 devices"
class IODriveMode:
"""
Changes the way the module's internal pull-up resistor works.
Using the ``DRIVE_OPEN`` setting may require you to manually add pull-up resistors.
This setting isn't related to the LoRa transmission rate and can be different between communicating modules.
"""
DRIVE_OPEN = 0b0
"""
Both `TX` and `AUX` pins will be push-pull outputs.
The `RX` pin will be a pull-up input.
"""
DRIVE_PULL = 0b1
"""
Both `TX` and `AUX` pins will be open-collector outputs.
The `RX` pin will be an open-collector input.
"""
DRIVE_DEFAULT = DRIVE_PULL
"Default IO drive mode E32 devices"
class ForwardErrorCorrection:
"""
On/Off statuses available for the module's *Forward Error Correction*
Turning the FEC off will reduce the the transmission time and will decrease the maximum transmission distance.
FIXME: Figure out the ratio since LoRaWAN wants 5/4 !
**This setting must be the same between all communicating modules.**
"""
FEC_DISABLED = False
"Enables forward error correction"
FEC_ENABLE = True
"Disables forward error correction"
FEC_DEFAULT = FEC_ENABLE
"Default FEC status on E32 devices"
CHANNEL_MIN = 0
"""Minimal allowed channel number. (Inclusive)"""
CHANNEL_MAX = 31
"""Maximal allowed channel number. (Inclusive)"""
TX_POWER_MIN = 0b00
"""Minimal allowed TX power value. (Inclusive)"""
TX_POWER_MAX = 0b11
"""Maximal allowed TX power value. (Inclusive)"""
E32DeviceVersion = namedtuple("E32DeviceVersion", (
"model", "version", "features"
))
"""Named tuple returned by the `E32DeviceConfig` when fetching the module's version."""
E32DeviceConfig = namedtuple("E32DeviceConfig", (
"address", "uart_parity", "uart_rate", "data_rate", "channel", "tx_mode", "io_drive_mode", "wake_up_time",
"forward_error_correction", "tx_power"
))
"""Named tuple returned by the `E32DeviceConfig` when fetching the module's current config."""
class E32Device:
"""
Generic class for interacting with E32 modules over UART.
"""
_m0: DigitalInOut
_m1: DigitalInOut
_aux: Optional[DigitalInOut]
_uart: UART
_uart_pin_tx: Pin
_uart_pin_rx: Pin
_uart_buffer_size: int
_address: int
_uart_parity: Union[int, SerialParity]
_uart_rate: Union[tuple[int, int], SerialBaudRate]
_data_rate: Union[int, AirDataRate]
_channel: int
_tx_mode: int
_io_drive_mode: int
_wake_up_time: int
_fec: bool
_tx_power: int
def __init__(self,
pin_m0: Pin,
pin_m1: Pin,
pin_aux: Optional[Pin],
pin_tx: Pin,
pin_rx: Pin,
uart_buffer_size: int = 64,
address: int = 0x0000,
uart_parity: Union[int, SerialParity] = SerialParity.PARITY_NONE,
uart_rate: Union[tuple[int, int], SerialBaudRate] = SerialBaudRate.BAUD_DEFAULT,
data_rate: Union[int, AirDataRate] = AirDataRate.RATE_DEFAULT,
channel: int = 0,
tx_mode: Union[int, TransmissionMode] = TransmissionMode.TRANSMISSION_DEFAULT,
io_drive_mode: Union[int, IODriveMode] = IODriveMode.DRIVE_DEFAULT,
wake_up_time: Union[int, WakeUpTime] = WakeUpTime.WAKE_TIME_DEFAULT,
forward_error_correction: Union[bool, ForwardErrorCorrection] = True,
tx_power: int = 0b11,
):
# Preparing pins
self._m0 = DigitalInOut(pin_m0)
self._m1 = DigitalInOut(pin_m1)
self._aux = None if pin_aux is None else DigitalInOut(pin_aux)
# Preparing UART bus
self._uart_pin_tx = pin_rx
self._uart_pin_rx = pin_tx
self._uart_buffer_size = uart_buffer_size
self._uart = None
self.prepare_uart(9600, None)
# Correcting some pin-related stuff
self._m0.direction = Direction.OUTPUT
self._m1.direction = Direction.OUTPUT
if self._aux is not None:
self._aux.direction = Direction.INPUT
# Saving configuration values
self._address = address
self._uart_parity = uart_parity
self._uart_rate = uart_rate
self._data_rate = data_rate
self._channel = channel
self._tx_mode = tx_mode
self._io_drive_mode = io_drive_mode
self._wake_up_time = wake_up_time
self._fec = forward_error_correction
self._tx_power = tx_power
# Checking if the module works by fetching its version and not getting any data validation errors.
self.mode = Modes.MODE_SLEEP
self.get_version()
# Validating and applying configuration
self.update_config()
def __del__(self):
self.deinit()
def deinit(self):
"""
Deinitializes the E32 module instance and liberates all used pins.
:return: ``None``
"""
self.reset()
self._m0.deinit()
self._m1.deinit()
if self._aux is not None:
self._aux.deinit()
self._uart.deinit()
def prepare_uart(self, baudrate: int, parity: Optional[UART.Parity]):
"""
Prepares the UART bus for further communications.
:param baudrate: Baudrate used by the new UART bus.
:param parity: Parity used by the new UART bus.
:return: ``None``
"""
if self._uart is not None:
self.flush_uart()
self._uart.deinit()
self._uart = UART(
self._uart_pin_tx, self._uart_pin_rx,
parity=parity, baudrate=baudrate,
receiver_buffer_size=self._uart_buffer_size)
def flush_uart(self):
"""
Empties out the UART buffer if possible.
:return: ``None``
"""
self._uart.reset_input_buffer()
def wait_aux(self, max_wait_ms: int = 250):
"""
Wait for the `AUX` pin to go high meaning that the module is ready for communications.
If no `AUX` pin was given, or if it stays low, the waiting period will be 150ms at most.
:type max_wait_ms: Max amount of time in milliseconds to wait for the `AUX` pin to go high. (Default: ``150``)
:return: ``None``
"""
if self._aux is None:
sleep(max_wait_ms / 1000)
return
wait_loop_count = 0
while not self._aux.value and wait_loop_count < (max_wait_ms / 10) - 1:
sleep(0.01)
wait_loop_count += 1
# Waiting just a bit more, this helps fix some timing issues when AUX is high but data wasn't sent yet.
# This shouldn't be happening, but it does, so... yeah...
sleep(0.01)
def send(self, message: bytes, max_packet_size: Optional[int] = None, wait_aux: bool = True):
"""
Sends a message on the UART bus.
:param message: Message to be sent, may get truncated.
:param max_packet_size: Max byte count to send, if `None`, the message's length will be used.
:param wait_aux: Whether the method should wait for AUX pin (Default: ``True``)
:return: The numbers of bytes written.
"""
if max_packet_size is None:
max_packet_size = len(message)
bytes_sent = self._uart.write(message[:max_packet_size])
if wait_aux:
self.wait_aux()
return bytes_sent
def read(self, byte_count: int = -1) -> bytearray | None:
"""
Reads bytes waiting in the UART bus' buffer.
:param byte_count: Tha maximum amount of bytes to read. (Default: ``-1``)
:return: The data as a ``bytearray`` or ``None``.
"""
return self._uart.read(byte_count if byte_count >= 0 else self.in_buffer)
@property
def in_buffer(self) -> int:
"""
Get the amount of bytes waiting in the UART bus' buffer.
:return: Bytes in UART buffer.
"""
return self._uart.in_waiting
def update_config(self, make_permanent: bool = False, verify: bool = True) -> None:
"""
Applies the current config to the module.
**The module will temporarily go into sleep mode and flush the UART buffer.**
:param make_permanent: Whether the config should be saved when the module is powered-down. (Default: ``False``)
:param verify: Whether the config should be fetched and checked afterward. (Default: ``True``)
:return: ``None``
:raises E32GenericError: If the config couldn't be applied.
"""
original_mode = self.mode
if original_mode != Modes.MODE_SLEEP:
self.mode = Modes.MODE_SLEEP
command = bytearray(6)
command[0] = 0xC0 if make_permanent else 0xC2
command[1] = (self._address & 0xFF00) >> 8
command[2] = self._address & 0xFF
command[3] = ((self._uart_parity & 0b11) << 6) | \
((self._uart_rate[0] & 0b111) << 3) | \
(self._data_rate & 0b111)
command[4] = self._channel & 0b00011111
command[5] = ((self._tx_mode & 0b1) << 7) | \
((self._io_drive_mode & 0b1) << 6) | \
((self._wake_up_time & 0b111) << 3) | \
((self._fec & 0b1) << 2) | \
(self._tx_power & 0b11)
# Preparing the UART bus
self.flush_uart()
# Sending config
if self._uart.write(command) != 6:
raise E32GenericError("Failed to send the parameters configuration command !")
# Waiting for module to react
self.wait_aux()
# Flushing data returned by the module.
# The datasheet doesn't mention explicitly that it returns the new config, so I won't take the risk.
self.flush_uart()
if verify:
raw_config = self.get_raw_config()
if raw_config[1:] != command[1:]:
raise E32GenericError("The module didn't return the new config !")
if original_mode != Modes.MODE_SLEEP:
self.mode = original_mode
def get_raw_config(self) -> bytes:
"""
Fetches the raw operating config from the module and returns it.
**The module will temporarily go into sleep mode and flush the UART buffer.**
:return: The raw response as a ``bytes`` object of length 6.
"""
original_mode = self.mode
if original_mode != Modes.MODE_SLEEP:
self.mode = Modes.MODE_SLEEP
self._uart.write(b'\xC1\xC1\xC1')
self.wait_aux()
if self._uart.in_waiting != 6:
raise E32GenericError(
f"The operating parameters request returned {self._uart.in_waiting} byte(s) instead of 6 !"
)
raw_config = self._uart.read(6)
if original_mode != Modes.MODE_SLEEP:
self.mode = original_mode
return raw_config
def get_config(self) -> E32DeviceConfig:
"""
Get a named tuple containing the module's current operating configuration
:return: A ``E32DeviceConfig`` with the module's current operating configuration.
"""
raw_config = self.get_raw_config()
return E32DeviceConfig(
raw_config[1:3], # Address
(raw_config[3] & 0b11000000) >> 6, # UART Parity
(raw_config[3] & 0b111000) >> 3, # UART Rate
raw_config[3] & 0b111, # Air data rate
raw_config[4] & 0b11111, # Channel
(raw_config[5] & 0b10000000) >> 7, # Transmission mode
(raw_config[5] & 0b1000000) >> 6, # IO drive mode
(raw_config[5] & 0b111000) >> 3, # Wake-up time
(raw_config[5] & 0b100) >> 2, # FEC status
raw_config[5] & 0b11, # TX Power
)
def get_raw_version(self) -> bytes:
"""
Fetches the raw version number and returns it.
**The module will temporarily go into sleep mode and flush the UART buffer.**
:return: The raw response as a ``bytes`` object of length 4.
:raises E32GenericError: If the version couldn't be fetched.
"""
original_mode = self.mode
if original_mode != Modes.MODE_SLEEP:
self.mode = Modes.MODE_SLEEP
self._uart.write(b'\xC3\xC3\xC3')
self.wait_aux()
if self._uart.in_waiting != 4:
raise E32GenericError(
f"The operating parameters request returned {self._uart.in_waiting} byte(s) instead of 4 !"
)
raw_version = self._uart.read(4)
if original_mode != Modes.MODE_SLEEP:
self.mode = original_mode
return raw_version
def get_version(self) -> E32DeviceVersion:
"""
Fetches the module's model, version number and its features.
**Ebyte's documentation doesn't explain the content of the second and third values in details.**
:return: A tuple containing the module's model, its version number, ant its features.
:raises E32GenericError: If the version is invalid.
"""
raw_version = self.get_raw_version()
if raw_version[0] != 0xC3:
raise E32GenericError("The version data has a bad response code !")
if raw_version[1] != 0x32:
raise E32GenericError("The version data has an invalid model !")
return E32DeviceVersion(raw_version[1], raw_version[2], raw_version[3])
def reset(self, stay_in_sleep_mode: bool = True):
"""
Sends the `RESET` command to the module and stays in sleep mode waiting for further configuration unless
instructed not to.
The module is left in sleep mode to prevent rogue communications with an undesired operating configuration.
**The module will temporarily go into sleep mode and flush the UART buffer.**
**The module will likely be unresponsive for a couple of seconds !**
:param stay_in_sleep_mode: Whether the module should be left in sleep mode after the reset. (Default: ``True``)
:return: ``None``
"""
original_mode = self.mode
if original_mode != Modes.MODE_SLEEP:
self.mode = Modes.MODE_SLEEP
self._uart.write(b'\xC4\xC4\xC4')
self.wait_aux(1500) # May not be enough, it doesn't respond directly, even if AUX is high...
if not stay_in_sleep_mode and original_mode != Modes.MODE_SLEEP:
self.mode = original_mode
@property
def mode(self) -> Union[tuple[int, int], Modes]:
"""
Module's mode as it is or should be represented on the `M0` and `M1` pins.
**Changing this property will flush the UART buffer.**
"""
return self._m0.value, self._m1.value
@mode.setter
def mode(self, value: Union[tuple[int, int], Modes]):
self._m0.value = value[0]
self._m1.value = value[1]
self.wait_aux()
self.prepare_uart(
baudrate=9600 if self.mode == Modes.MODE_SLEEP else self._uart_rate[1],
parity=(
None if self.mode == Modes.MODE_SLEEP or self.uart_parity == SerialParity.PARITY_NONE else (
UART.Parity.ODD if self.uart_parity == SerialParity.PARITY_ODD else UART.Parity.EVEN
)
)
)
self.flush_uart()
@property
def address(self) -> int:
"""
Module's address used to receive messages. (Must be between ``0x0000`` and ``0xFFFF``)
If the module is in fixed communications mode the address has extra some extra behaviour:
⦁ The ``0xFFFF`` address can be used to monitor or broadcast messages on a given channel.
⦁ The address is ignored when receiving broadcast messages.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._address
@address.setter
def address(self, value: int):
if not 0x0000 <= value <= 0xFFFF:
raise ValueError(f"The 'address' isn't between 0x0000 and 0xFFFF ! (It's {value})")
self._address = value
self.update_config()
@property
def uart_parity(self) -> int:
"""
Module's UART parity used on the `RX` and `TX` lines when in non-sleep modes,
as transmitted via the save parameters command.
Must be between one of the values in ``SerialParity``.
This value is automatically applied to the uart bus when switching modes.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._uart_parity
@uart_parity.setter
def uart_parity(self, value: int):
if not 0b00 <= value <= 0b11:
raise ValueError(f"The 'uart_parity' isn't between 0 and 3 ! (It's {value})")
self._uart_parity = value
self.update_config()
@property
def uart_rate(self) -> tuple[int, int] | SerialBaudRate:
"""
Module's UART rate used on the `RX` and `TX` lines when in non-sleep modes.
Must be between one of the values in ``SerialBaudRate``.
This value is automatically applied to the uart bus when switching modes.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._uart_rate
@uart_rate.setter
def uart_rate(self, value: tuple[int, int] | SerialBaudRate):
if not 0b000 <= value[0] <= 0b111:
raise ValueError(f"The 'uart_rate' isn't between 0 and 7 ! (It's {value[0]})")
self._uart_rate = value
self.update_config()
@property
def data_rate(self) -> int | AirDataRate:
"""
Module's data rate for any LoRa communications in non-sleep modes.
Must be between one of the values in ``AirDataRate``.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._data_rate
@data_rate.setter
def data_rate(self, value: int | AirDataRate):
if not 0b000 <= value <= 0b111:
raise ValueError(f"The 'data_rate' isn't between 0 and 7 ! (It's {value})")
self._data_rate = value
self.update_config()
@property
def channel(self) -> int:
"""
Module's channel used for any LoRa communications in non-sleep modes.
Must be between ``CHANNEL_MIN`` and ``CHANNEL_MAX``. (Both are inclusive limits)
If the module is in fixed communications mode, it may change its channel to the targeted one and will return
to the original one afterward.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._channel
@channel.setter
def channel(self, value: int):
if not CHANNEL_MIN <= value <= CHANNEL_MAX:
raise ValueError(f"The 'channel' isn't between {CHANNEL_MIN} and {CHANNEL_MAX} ! (It's {value})")
self._channel = value
self.update_config()
@property
def tx_mode(self) -> int | TransmissionMode:
"""
Module's transmission mode used for any LoRa communications in non-sleep modes.
Must be between one of the values in ``TransmissionMode``.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._tx_mode
@tx_mode.setter
def tx_mode(self, value: int | TransmissionMode):
if not 0 <= value <= 1:
raise ValueError(f"The 'tx_mode' isn't between 0 and 1 ! (It's {value})")
self._tx_mode = value
self.update_config()
@property
def io_drive_mode(self) -> int | IODriveMode:
"""
Module's IO drive mode for its ``RX``, ``TX`` and ``AUX`` pins.
Must be between one of the values in ``IODriveMode``.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._io_drive_mode
@io_drive_mode.setter
def io_drive_mode(self, value: int | IODriveMode):
if not 0 <= value <= 1:
raise ValueError(f"The 'io_drive_mode' isn't between 0 and 1 ! (It's {value})")
self._io_drive_mode = value
self.update_config()
@property
def wake_up_time(self) -> int | WakeUpTime:
"""
Module's wake-up time when in non-sleep and non-normal modes.
Must be between one of the values in ``WakeUpTime``.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._wake_up_time
@wake_up_time.setter
def wake_up_time(self, value: int | WakeUpTime):
if not 0b000 <= value <= 0b111:
raise ValueError(f"The 'wake_up_time' isn't between 0 and 7 ! (It's {value})")
self._wake_up_time = value
self.update_config()
@property
def forward_error_correction(self) -> bool | ForwardErrorCorrection:
"""
Module's forward error correction toggle for any LoRa communications when in non-sleep modes.
Must be between one of the values in ``ForwardErrorCorrection``.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._fec
@forward_error_correction.setter
def forward_error_correction(self, value: bool | ForwardErrorCorrection):
self._fec = value
self.update_config()
@property
def tx_power(self) -> int:
"""
Module's TX power as transmitted via the save parameters command.
Must be between ``TX_POWER_MIN`` and ``TX_POWER_MAX``, both are inclusive.
**Changing this property will cause the module to temporarily go into sleep mode and flush the UART buffer.**
"""
return self._tx_power
@tx_power.setter
def tx_power(self, value: int):
if not 0b00 <= value <= 0b11:
raise ValueError(f"The 'tx_power' isn't between 0 and 3 ! (It's {value})")
self._tx_power = value
self.update_config()