-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataManagerRx.py
141 lines (106 loc) · 4.82 KB
/
DataManagerRx.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
from Queue import Queue
import Custom_Class
from datetime import datetime, timedelta
from threading import RLock
VALIDITY = timedelta(0, 10)
def update_LocTable(index, time, locTable):
locTable[index].time = time
locTable[index].timestamp = datetime.now()
locTable[index].val = VALIDITY
def rxd_platform(out_multicast_queue, uid,locTable, locTableIds, data_rx_queue, in_multicast_queue, car_event):
print('rxd_platform\n')
while True:
msg = out_multicast_queue.get()
if isinstance(msg, Custom_Class.CAM) or isinstance(msg, Custom_Class.DENM) \
or isinstance(msg, Custom_Class.BEACON) or isinstance(msg, Custom_Class.CAMSEM):
if msg.id == uid:
continue
elif msg.ttl > 0:
msg.ttl = msg.ttl - 1
in_multicast_queue.put(msg)
continue
if isinstance(msg, Custom_Class.CAM) or isinstance(msg, Custom_Class.BEACON) \
or isinstance(msg, Custom_Class.CAMSEM):
# if isinstance(msg, Custom_Class.CAM) or isinstance(msg, Custom_Class.CAMSEM):
# print("####################CAM#####################################")
# print(msg)
# print("####################END_CAM#################################")
lock = RLock()
lock.acquire()
if msg.id in locTableIds:
index = locTableIds.index(msg.id)
time = datetime.strptime(msg.time, '%Y-%m-%d %H:%M:%S.%f')
update_LocTable(index, time, locTable)
else:
time = datetime.strptime(msg.time, '%Y-%m-%d %H:%M:%S.%f')
locM = Custom_Class.LOCM(msg.id, time, datetime.now(), VALIDITY)
locTable.append(locM)
locTableIds.append(locM.id)
lock.release()
if isinstance(msg, Custom_Class.CAMSEM):
if msg.buss == "O" and msg.state == "RED":
car_event.set()
elif msg.buss == "O" and (msg.state == "GREEN" or msg.state == "EMS"):
car_event.clear()
elif isinstance(msg, Custom_Class.DENM):
print("$$$$$$$$$$$$ Received DEM \n\n")
data_rx_queue.put(msg)
print('terminating xd_platform\n')
return
def rxd_platform_RSU(out_multicast_queue, ems_timer1, ems_timer2, ems_timer3, ems_timer4,
uid, locTable, locTableIds, data_rx_queue, in_multicast_queue):
print('rxd_platform\n')
id = -1
while True:
msg = out_multicast_queue.get()
if isinstance(msg, Custom_Class.CAM) or isinstance(msg, Custom_Class.DENM) \
or isinstance(msg, Custom_Class.BEACON) or isinstance(msg, Custom_Class.CAMSEM):
if msg.id == uid:
continue
elif msg.ttl > 0:
msg.ttl = msg.ttl - 1
in_multicast_queue.put(msg)
continue
if isinstance(msg, Custom_Class.CAM) or isinstance(msg, Custom_Class.BEACON) \
or isinstance(msg, Custom_Class.CAMSEM):
# if isinstance(msg, Custom_Class.CAM):
# print("####################CAM#####################################")
# print(msg)
# print("####################END_CAM#################################")
lock = RLock()
lock.acquire()
if msg.id in locTableIds:
index = locTableIds.index(msg.id)
time = datetime.strptime(msg.time, '%Y-%m-%d %H:%M:%S.%f')
update_LocTable(index, time, locTable)
else:
time = datetime.strptime(msg.time, '%Y-%m-%d %H:%M:%S.%f')
locM = Custom_Class.LOCM(msg.id, time, datetime.now(), VALIDITY)
locTable.append(locM)
locTableIds.append(locM.id)
lock.release()
if isinstance(msg, Custom_Class.CAM) and msg.id == id:
check_EMS(msg, ems_timer1, ems_timer2, ems_timer3, ems_timer4)
elif isinstance(msg, Custom_Class.DENM):
if msg.state:
id = int(msg.id)
print("##########################################")
print("ID= ", id)
else:
id = -1
ems_timer1.clear()
ems_timer2.clear()
ems_timer3.clear()
ems_timer4.clear()
data_rx_queue.put(msg)
print('terminating xd_platform\n')
return
def check_EMS(msg, ems_timer1, ems_timer2, ems_timer3, ems_timer4):
if int(msg.x) < 150 and msg.buss == "E":
ems_timer1.set()
elif int(msg.x) > 225 and msg.buss == "O":
ems_timer3.set()
elif int(msg.y) < 150 and msg.buss == "N":
ems_timer2.set()
elif int(msg.y) > 225 and msg.buss == "S":
ems_timer4.set()