Marco Zeisler 349a38fa9f vehicle sends daf to orchestrator via rabbitMQ broker
vehicle receives new target velocity from orchestrator as response;
at this point, this velocity is just a random float between 0 and 130;
2021-05-24 17:17:50 +02:00

46 lines
1.4 KiB
Python

import pickle
import sys
from random import randrange
from wrappers import daf
from wrappers.message_broker_wrapper import MBWrapper
sys.modules['daf'] = daf
class Orchestrator:
vins = []
tls = []
_daf_mbs = {}
_velocity_mbs = {}
def __init__(self):
# TODO fetch available car VINs from Entity Ident
self.vins.append('SB164ABN1PE082000')
self.vins.append('SB999ABN1PE082111')
# 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')
def setup_msg_queues(self):
for vin in self.vins:
daf_channel = MBWrapper(exchange_name='vehicle_daf_{}'.format(vin), callback=self.handle_daf_receive)
daf_channel.setup_receiver()
self._daf_mbs[vin] = daf_channel
velocity_channel = MBWrapper(exchange_name='vehicle_velocity_{}'.format(vin))
velocity_channel.setup_sender()
self._velocity_mbs[vin] = velocity_channel
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
response_channel = self._velocity_mbs[received_daf_object.vehicle_identification_number]
response_channel.send(randrange(0, 130))