traffic light sends orchestrator its status on change;
This commit is contained in:
@@ -2,15 +2,16 @@ import pickle
|
||||
import sys
|
||||
from random import randrange
|
||||
|
||||
from wrappers import daf
|
||||
from wrappers.message_broker_wrapper import MBWrapper
|
||||
from shared import daf
|
||||
from shared.TrafficLightColor import Color
|
||||
from shared.message_broker_wrapper import MBWrapper
|
||||
|
||||
sys.modules['daf'] = daf
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
vins = []
|
||||
tls = []
|
||||
tls = {}
|
||||
|
||||
_daf_mbs = {}
|
||||
_velocity_mbs = {}
|
||||
@@ -19,11 +20,14 @@ class Orchestrator:
|
||||
# TODO fetch available car VINs from Entity Ident
|
||||
self.vins.append('SB164ABN1PE082000')
|
||||
self.vins.append('SB999ABN1PE082111')
|
||||
self.vins.append('SB555ABN1PE082555')
|
||||
print('vins', self.vins)
|
||||
|
||||
# TODO fetch available TLs from Entity Ident
|
||||
self.tls.append('traffic-light-1')
|
||||
self.tls.append('traffic-light-2')
|
||||
self.tls.append('traffic-light-3')
|
||||
self.tls['traffic-light-1'] = {'color': Color.RED, 'switching_time': 120}
|
||||
self.tls['traffic-light-2'] = {'color': Color.GREEN, 'switching_time': 240}
|
||||
self.tls['traffic-light-3'] = {'color': Color.RED, 'switching_time': 360}
|
||||
print('tls', self.tls)
|
||||
|
||||
def setup_msg_queues(self):
|
||||
for vin in self.vins:
|
||||
@@ -35,11 +39,20 @@ class Orchestrator:
|
||||
velocity_channel.setup_sender()
|
||||
self._velocity_mbs[vin] = velocity_channel
|
||||
|
||||
for tl in self.tls:
|
||||
tl_channel = MBWrapper(exchange_name='traffic_light_state_{}'.format(tl), callback=self.handle_tl_state_receive)
|
||||
tl_channel.setup_receiver()
|
||||
|
||||
def handle_daf_receive(self, msg):
|
||||
received_daf_object = pickle.loads(msg)
|
||||
print(received_daf_object)
|
||||
|
||||
# TODO use the data from the traffic lights to transmit a new target velocity for this vehicle to achieve
|
||||
# a green wave
|
||||
# TODO use the data from the traffic lights (self.tls)
|
||||
# to transmit a new target velocity for this vehicle to achieve a green wave
|
||||
response_channel = self._velocity_mbs[received_daf_object.vehicle_identification_number]
|
||||
response_channel.send(randrange(0, 130))
|
||||
|
||||
def handle_tl_state_receive(self, msg):
|
||||
tl_state = pickle.loads(msg)
|
||||
self.tls[tl_state['tlid']]['color'] = tl_state['color']
|
||||
print(tl_state)
|
||||
|
||||
Reference in New Issue
Block a user