-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodem.py
executable file
·84 lines (55 loc) · 1.94 KB
/
modem.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
#!/usr/bin/env python3
"""This is a very primitive and dumb front end to get the ball
rolling.
"""
# -*- coding: utf-8 -*-
import argparse
import pdb
import serial
import sys
import time
import tkinter
def main(serial_port='/dev/ttyACM0', baudrate=9600, callsign=None):
if not callsign:
sys.stderr.write('*** no callsign provided ***\n')
sys.exit(1)
modem = serial.Serial(port=serial_port, baudrate=baudrate)
def writeln(s):
modem.write(s.encode('utf-8'))
modem.write(b'\r\n')
modem.flush()
time.sleep(0.1)
# On startup, we'll need to pull the '!BOOT OK' off the
# console. If the modem has already started, there won't
# be anything to read.
modem.read(modem.in_waiting)
writeln('!ID '+callsign)
response = modem.read(modem.in_waiting).decode('utf-8').strip()
print(response)
assert(response == '*ID SET')
root = tkinter.Tk()
frame = tkinter.Frame(root)
frame.pack()
messagelist = tkinter.Text(frame, width=64)
messagelist.pack()
message = tkinter.Text(frame)
message.pack()
transmitter = tkinter.Button(frame)
transmitter["text"] = "Transmit"
transmitter.pack()
def transmit(*args):
m = message.get("1.0", "end-1c")
if not m:
return
writeln('>'+m)
time.sleep(0.1)
response = modem.read(modem.in_waiting).decode('utf-8').strip()
assert(response == '*TX SENT')
transmitter.bind('<Button-1>', transmit)
root.mainloop()
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='lora-modem', description='gui for a lora modem')
parser.add_argument('-p', '--port', default='/dev/ttyACM0', help='serial port')
parser.add_argument('-c', '--callsign', default='', help='callsign')
ap_args = parser.parse_args()
main(serial_port=ap_args.port, baudrate=9600, callsign=ap_args.callsign)