-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasestation.py
More file actions
35 lines (30 loc) · 893 Bytes
/
Copy pathbasestation.py
File metadata and controls
35 lines (30 loc) · 893 Bytes
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
import os
import time
import subprocess
import signal
from subprocess import check_call
from signal import pause
from gpiozero import Button, LED
LOG_PATH = "/mnt"
SERIAL_PORT_BAUD_RATE = 460800
proc = None
button = Button(21)
green = LED(20)
def str2str():
global proc
if proc is None:
args = 'str2str -in serial://ttyAMA0:' + '{0}'.format(SERIAL_PORT_BAUD_RATE) + ':8:n:1:off -out ' + os.path.join(LOG_PATH, time.strftime("base-%Y-%m-%d-%H-%M-%S")) + '.ubx'
proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, preexec_fn=os.setsid)
green.blink()
else:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
proc = None
green.on()
def shutdown():
green.off()
check_call(['sudo', 'poweroff'])
if __name__ == "__main__":
button.when_pressed = str2str
button.when_held = shutdown
green.on()
pause()