def ExchangeArrivalTimes(self): """ Exchange V2V communications between the Icarous instances """ arrTimes = [] log = [] for ic in self.icInstances: if ic.arrTime is not None: arrTimes.append(ic.arrTime) for arr in arrTimes: fid = arr.intersectionID if fid <= 0: continue avail = False for g in log: if fid == g[0].intersectionID: avail = True g.append(arr) if not avail: log.append([arr]) for lg in log: if len(lg) == 0: continue datalog = LogData() datalog.intersectionID = lg[0].intersectionID datalog.nodeRole = 1 datalog.totalNodes = len(lg) mg = MergerData * MAX_NODES datalog.log = mg(*lg) for ic in self.icInstances: if ic.arrTime is None: continue if ic.arrTime.intersectionID == datalog.intersectionID: ic.InputMergeLogs(datalog, self.commDelay)
def ExchangeV2VData(self): """ Exchange V2V communications between the Icarous instances """ # Transmit all V2V data for ic in self.icInstances: # Do not broadcast if running SBN if "SBN" in ic.apps: continue if not ic.missionStarted or ic.missionComplete: continue # broadcast position data to all other vehicles in the airspace tfdata = V2Vdata("INTRUDER", { "callsign": ic.callsign, "pos": ic.position, "vel": ic.velocity }) ic.transmitter.transmit(self.current_time, ic.position, tfdata) # Gather logs to be exchanged for merging activity log = {} for ic in self.icInstances: if ic.arrTime is not None: intsid = ic.arrTime.intersectionID if intsid in log.keys(): log[intsid].append(ic.arrTime) else: log[intsid] = [ic.arrTime] # Transmit all merger log data for lg in log: datalog = LogData() datalog.intersectionID = log[lg][0].intersectionID datalog.nodeRole = 1 datalog.totalNodes = len(log[lg]) mg = MergerData * MAX_NODES datalog.log = mg(*log[lg]) for ic in self.icInstances: # Do not broadcast if running SBN if "SBN" in ic.apps: continue mergelog = V2Vdata("MERGER", datalog) ic.transmitter.transmit(self.current_time, ic.position, mergelog) # Receive all V2V data for ic in self.icInstances: if not ic.missionStarted or ic.missionComplete: continue received_msgs = ic.receiver.receive(self.current_time, ic.position) data = [m.data for m in received_msgs] ic.InputV2VData(data) self.comm_channel.flush()