-
Notifications
You must be signed in to change notification settings - Fork 8
/
mockObdGenerator.py
80 lines (57 loc) · 1.61 KB
/
mockObdGenerator.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
import socketio
import random
import time
import json
import obd
import time
obd2CmdListFile = open('obd2CmdsList.json',)
obdCmdList = json.load(obd2CmdListFile)
obd2CmdListFile.close()
sio = socketio.Client()
print(sio)
def generateFaultCodes():
return [
("P0104", "Mass or Volume Air Flow Circuit Intermittent"),
("B0003", ""), # unknown error code, it's probably vehicle-specific
("C0123", "")
]
def generateData():
idleTime = round(random.uniform(10.5, 75.5), 1)
#print(idleTime)
data = {'speed': random.randint(75, 85),
'rpm': random.randint(700, 7500),
'throttle': random.randint(40, 60),
'runTime': random.randint(60, 90),
'idleTime': idleTime}
return json.dumps(data)
def sendData():
sio.emit('data', generateData())
sio.emit('dtcData', generateFaultCodes())
time.sleep(.1)
@sio.on('sensorDumpRequest')
def on_message(data):
obdCmdResponseList = []
for obdCmd in obdCmdList:
#response = connection.query(obdCmd['Name']) # send the command, and parse the response
obdCmdResponseList.append(obdCmd)
sio.emit('sensorDumpData', obdCmdResponseList)
@sio.event
def connect():
print("Connected!")
# while True:
# generateFaultCodes()
# sendData()
# print("asdf")
@sio.event
def connect_error():
print("The connection failed!")
@sio.event
def disconnect():
print("I'm disconnected!")
@sio.event
def message(data):
print('I received a message!')
sio.connect('http://localhost:3000')
while True:
generateFaultCodes()
sendData()