-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseatbelt.py
158 lines (125 loc) · 4.69 KB
/
seatbelt.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import time
import kafka
import json
producer = kafka.KafkaProducer(bootstrap_servers=['192.168.16.245:9092'], value_serializer=lambda m: json.dumps(m).encode('ascii'))
doors = list("111111")
choices = {
"BeltReminderSensorRL_MS": 0,
"BeltReminderSensorRM_MS": 0,
"BeltReminderSensorRR_MS": 0,
"BeltReminderSensor_MS": 0,
"BeltRmderSensorRow3L_MS": 0,
"BeltRmderSensorRow3R_MS": 0,
"DrivSeatBeltBcklState_MS": 0,
"PassSeatBeltBcklState_MS": 0,
"LowBeamIndication_MS": 0,
"MainBeamIndication_MS": 0
}
payload = {
"vehicle_id": "f-type",
"source": "test",
"signal": None,
"timestamp": int(round(time.time() * 1000)),
"command": "EVENT",
"attributes":{
"value" : None
}
}
def send_reversed(signal, door = None, window = None):
if window != None:
if door == 0:
payload["signal"] = signal
payload["attributes"]["value"] = int(window)
producer.send( 'androidbigdata' , payload)
elif door == 1:
payload["signal"] = signal
payload["attributes"]["value"] = int(window)
producer.send( 'androidbigdata' , payload)
elif door == 2:
payload["signal"] = signal
payload["attributes"]["value"] = int(window)
producer.send( 'androidbigdata' , payload)
elif door == 3:
payload["signal"] = signal
payload["attributes"]["value"] = int(window)
producer.send( 'androidbigdata' , payload)
elif door != None and window == None:
if doors[door] == "1":
doors[door] = "0"
payload["signal"] = signal
payload["attributes"]["value"] = int("".join(doors), 2)
producer.send( 'androidbigdata' , payload)
else:
doors[door] = "1"
payload["signal"] = signal
payload["attributes"]["value"] = int("".join(doors), 2)
producer.send( 'androidbigdata' , payload)
else:
if choices[signal] == 0:
payload["signal"] = signal
payload["attributes"]["value"] = 1
producer.send( 'androidbigdata' , payload)
choices[signal] = 1
else:
payload["signal"] = signal
payload["attributes"]["value"] = 0
producer.send( 'androidbigdata' , payload)
choices[signal] = 0
while True:
print("Driver Seatbelt \t0")
print("Passenger Seatbelt \t1")
print("Belt Reminder Sensor RL \t2")
print("Belt Reminder Sensor RR \t3")
#print("BeltReminderSensorRM_MS \t1")
#print("BeltReminderSensor_MS \t3")
#print("BeltRmderSensorRow3L_MS \t4")
#print("BeltRmderSensorRow3R_MS \t5")
print("Driver Door \t4")
print("Passenger Door \t5")
print("Rear Driver Door \t6")
print("Rear Passenger Door \t7")
print("Trunk \t8")
print("Hood \t9")
print("Driver Window Position \t10")
print("Passenger Window Position \t11")
print("Rear Driver Window Pos \t12")
print("Rear Passenger Window Pos \t13")
print("Low Beams \t14")
print("High Beams \t15")
select = str(input("Please select signal to toggle: "))
if select == "0":
send_reversed("DrivSeatBeltBcklState_MS")
elif select == "1":
send_reversed("PassSeatBeltBcklState_MS")
elif select == "2":
send_reversed("BeltReminderSensorRL_MS")
elif select == "3":
send_reversed("BeltReminderSensorRR_MS")
elif select == "4":
send_reversed("DoorStatusMS_MS", 5)
elif select == "5":
send_reversed("DoorStatusMS_MS", 4)
elif select == "6":
send_reversed("DoorStatusMS_MS", 3)
elif select == "7":
send_reversed("DoorStatusMS_MS", 2)
elif select == "8":
send_reversed("DoorStatusMS_MS", 1)
elif select == "9":
send_reversed("DoorStatusMS_MS", 0)
elif select == "10":
pos = str(input("Please select window pos 1-5: "))
send_reversed("DriverWindowPosition_MS", 0, pos)
elif select == "11":
pos = str(input("Please select window pos 1-5: "))
send_reversed("PassWindowPosition_MS", 1, pos)
elif select == "12":
pos = str(input("Please select window pos 1-5: "))
send_reversed("RearDriverWindowPos_MS", 2, pos)
elif select == "13":
pos = str(input("Please select window pos 1-5: "))
send_reversed("RearPassWindowPos_MS", 3, pos)
elif select == "14":
send_reversed("LowBeamIndication_MS")
elif select == "15":
send_reversed("MainBeamIndication_MS")