diff --git a/hydrobot_sensor_sim.py b/hydrobot_sensor_sim.py new file mode 100644 --- /dev/null +++ b/hydrobot_sensor_sim.py @@ -0,0 +1,31 @@ +import time +import random +from canard import can, bus +from canard.hw import socketcan +from canard.file import jsondb + +parser = jsondb.JsonDbParser() +b = parser.parse('hydrobot_can.json') + +dev = socketcan.SocketCanDev("can1") +dev.start() + +temp = 65.5 +humid = 0.90 +press = 100 + +while True: + + temp = max(0x00, min(0xFF, random.randint(-1, 1)/2 + temp)) + humid = max(0x00, min(0xFF, random.randint(-1, 1)/100 + humid)) + press = max(0x00, min(0xFF, random.randint(-1, 1) + press)) + + message = b.get_message("AirTemp") + message.get_signal("Temperature").value = temp + message.get_signal("Humidity").value = humid + message.get_signal("Pressure").value = press + + frame = b.build_frame("AirTemp") + dev.send(frame) + + time.sleep(1)