-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie
executable file
·71 lines (52 loc) · 1.23 KB
/
cookie
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
#!/usr/bin/python2
from fsk import Fsk
import struct
import json
import time
import os
import spidev
from gps import GPS
from ping import Ping
import signal
import sys
from imu import IMU
def readChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data >> 2
def getAnalog(n):
return [readChannel(i) for i in range(n)]
def signal_handler(signal, frame):
gps.stop()
ping.stop()
fsk.stop()
imu.stop()
sys.exit(0)
NUMBER_ANALOG = 8
IMU_ADDRESS = 0x69
IMU_MAG_ADDRESS = 0x0C
spi = spidev.SpiDev()
spi.open(0,0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
with open("conf.json") as fconf, open("dump.txt", "a") as fdump:
conf = json.load(fconf)
fsk = Fsk(conf)
fsk.start()
gps = GPS("/dev/ttyS3", 38400)
gps.start()
ping = Ping(size = .783)
ping.start()
imu = IMU(IMU_ADDRESS, IMU_MAG_ADDRESS)
imu.start()
while True:
vals = []
vals.append(getAnalog(NUMBER_ANALOG))
vals.append(gps.get_data())
vals.append(ping.get_data())
vals.append(imu.get_data())
#sys.stderr.write(str(ping.get_data()[0]) + "\n")
#print("\t".join(map(str, imu.get_data())))
fsk.feed(vals)
fdump.write(",".join(map(str, vals)))
time.sleep(0.1)