-
Notifications
You must be signed in to change notification settings - Fork 0
/
transceiver.py
57 lines (48 loc) · 1.34 KB
/
transceiver.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
import sys
from time import sleep
sys.path.insert(0, '../../pySX127x')
from SX127x.LoRa import *
from SX127x.LoRaArgumentParser import LoRaArgumentParser
from SX127x.board_config import BOARD
import RPi.GPIO as GPIO
BOARD.setup()
GPIO.setwarnings(False)
class TRANS(LoRa):
tx_counter = 0
def __init__(self, verbose=False):
super(TRANS, self).__init__(verbose)
self.set_mode(MODE.SLEEP)
self.set_dio_mapping([1,0,0,0,0,0])
def start(self):
self.tx_counter = 0
BOARD.led_on()
self.write_payload([0x0f])
self.set_mode(MODE.TX)
while True:
sleep(1)
def on_tx_done(self):
self.set_mode(MODE.STDBY)
self.clear_irq_flags(TxDone=1)
sys.stdout.flush()
self.tx_counter += 1
sys.stdout.write("\rtx #%d" % self.tx_counter)
sleep(0.01)
rawinput = "che khabar?\r\n"
data = [int(hex(ord(c)), 0) for c in rawinput]
self.write_payload(data)
BOARD.led_on()
self.set_mode(MODE.TX)
lora = TRANS(verbose=False)
lora.set_pa_config(pa_select=1)
try:
lora.start()
except KeyboardInterrupt:
sys.stdout.flush()
print("")
sys.stderr.write("KeyboardInterrupt\n")
finally:
sys.stdout.flush()
print("")
lora.set_mode(MODE.SLEEP)
print(lora)
BOARD.teardown()