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;
This commit is contained in:
+6
-1
@@ -1,4 +1,7 @@
|
||||
import threading
|
||||
|
||||
from flask import Flask
|
||||
from orchestrator import Orchestrator
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -19,4 +22,6 @@ def api2():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
orc = Orchestrator()
|
||||
threading.Thread(target=orc.setup_msg_queues).start()
|
||||
threading.Thread(target=app.run).start()
|
||||
@@ -0,0 +1,45 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user