-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (57 loc) · 1.82 KB
/
main.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
from HaltechCANReader import CANBusReader
from GPSReader import GPSReader
from AnalogReader import AnalogReader
from GAReader import GAReader
import os
import signal
import sys
import time
import threading
import logging
# Where the data gets stored
SavePath = "/home/pi/data/"
# The specific directory, based on time
SavePath += str(time.strftime("%Y-%m-%d-%H-%M-%S")) + "/"
# All the filenames
CANFileName = "CAN"
GPSFileName = "GPS"
GAFileName = "GA"
AVIFileName = "AVI"
# Complete the full filenames
CompleteCANFileName = os.path.join(SavePath, CANFileName + ".csv")
CompleteGPSFileName = os.path.join(SavePath, GPSFileName + ".csv")
CompleteGAFileName = os.path.join(SavePath, GAFileName + ".csv")
CompleteAVIFileName = os.path.join(SavePath, AVIFileName + ".csv")
# Check if the path exists (it shouldn't, time should be going forwards)
if not os.path.exists(SavePath):
os.mkdir(SavePath)
# Set as working directory
os.chdir(SavePath)
# Print current working directory
cwd = os.getcwd()
print(cwd)
# Logging for debugging purposes
logging.basicConfig(filename='app.log',
filemode='w',
format='%(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
# CANReader = CANBusReader(CompleteCANFileName)
GPSReader = GPSReader(CompleteGPSFileName)
GAReader = GAReader(CompleteGAFileName)
AVIReader = AnalogReader(CompleteAVIFileName)
def signal_handler(signal, frame):
sys.exit(0)
def main():
# CANReader.start_thread()
GPSReader.start_thread()
GAReader.start_thread()
AVIReader.start_thread()
signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C')
forever = threading.Event()
forever.wait()
if __name__ == "__main__":
try:
main()
except Exception as e:
logging.error("Exception Occurred", exc_info=True)