forked from BateauNautilus/DriveSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (31 loc) · 1.35 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
#!/usr/bin/env python3
import time
from Message.CANMessage import MessageToCan
from Message.EnvironmentStatus import EnvironmentStatus
from Message.MotorStatus import MotorStatus
from Message.Parameters.Current import Current
from Message.Parameters.Humidity import Humidity
from Message.Parameters.Vibration import Vibration
from Message.Parameters.Voltage import Voltage
from Message.Parameters.WaterTemperature import WaterTemperature
from config import Config
from lib.pythoncan import can
from Message.Parameters.RPM import Rpm
tasks = {}
def main():
bus = can.interface.Bus(channel=Config.getChannel(), bustype=Config.getBusType())
print('start_transmit()')
sendMotorStatusMessage()
sendEnvironmentStatusMessage()
while True:
time.sleep(20)
def sendMotorStatusMessage():
msg = MotorStatus(rpm=Rpm(5000), voltage=Voltage(12.5), current=Current(2), vibration=Vibration(0.2))
canmsg = MessageToCan(msg, deviceId=Config.getDeviceId())
tasks['motorStatus'] = can.send_periodic(Config.getChannel(), canmsg, msg.period)
def sendEnvironmentStatusMessage():
msg = EnvironmentStatus(waterTemperature=WaterTemperature(5), humidity=Humidity(0.12))
canmsg = MessageToCan(msg, deviceId=Config.getDeviceId())
tasks['EnvironmentStatus'] = can.send_periodic(Config.getChannel(), canmsg, msg.period)
if __name__ == "__main__":
main()