-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
82 lines (66 loc) · 2.41 KB
/
run.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
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import asyncio
from datetime import datetime
import os
import logging
import broker
from multiprocessing import Process
from multiprocessing.managers import BaseManager
from can_time_sync import send_timesync
from car import Car
from cloud_sender import cloud_sender
from receivers.e2_can import can_receiver
from receivers.gps import gps_receiver
from receivers.serial_data_parser import bms_receiver
from receivers.tpms import tpms_receiver
from send_scheduler import send_scheduler
e = datetime.now()
LOG_PATH = f"/home/pi/LST_Can_Hub/logs/{e.year}-{e.month}-{e.day} {e.hour}:{e.minute}:{e.second} canhub.log"
async def main():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(processName)s] %(message)s",
handlers=[
# logging.FileHandler(LOG_PATH),
logging.StreamHandler()
])
logging.info("Configuring CAN START")
os.system('sudo ifconfig can0 down')
os.system('sudo ip link set can0 type can bitrate 250000')
os.system('sudo ifconfig can0 up')
logging.info("Configuring CAN END")
logging.info("Waiting for broker")
c = await broker.get_connection_async()
await c.close()
logging.info("Broker OK")
BaseManager.register('Car', Car)
manager = BaseManager()
manager.start()
car = manager.Car()
MOCK = False
processes = []
processes.append(Process(target=bms_receiver, args=[car], name="BMS-Receiver"))
processes.append(Process(target=gps_receiver, args=[car], name="GPS-Receiver"))
processes.append(Process(target=can_receiver, args=[car, MOCK], name="CAN-Receiver"))
processes.append(Process(target=tpms_receiver, args=[car], name="TPMS-Receiver"))
processes.append(Process(target=send_scheduler, args=[car], name="Send-Scheduler"))
processes.append(Process(target=cloud_sender, name="Cloud-Sender"))
processes.append(Process(target=send_timesync, name="Can-Time-Sync"))
for p in processes:
p.start()
logging.info(f"Starting {p.name}")
try:
for p in processes:
p.join()
manager.join()
except KeyboardInterrupt:
for p in processes:
logging.info(f"Terminate {p.name}")
p.kill()
logging.info(f"Terminate {manager.name}")
manager.kill()
if __name__ == "__main__":
os.system("mkdir /home/pi/LST_Can_Hub/logs")
asyncio.run(
main()
)