Exemple #1
0
 def __init__(self):
     self.ownShip = Aircraft(0, 0, 0, 0, 0, 0, 0, 0)
     self.aircraftQueue = PriorityQueue()
     self.myAction = Action(0, 0)
     self.ads_bInt = ADS_BDriver()
     self.display = Display()
     self.loudSpeaker = LoudSpeaker()
     self.panelBtns = FrontPanelButtons()
 def __init__(self):
     self.ownShip = Aircraft(0, 0, 0, 0, 0, 0, 0, 0)
     self.aircraftQueue = PriorityQueue()
     self.myAction = Action(0, 0)
     self.ads_bInt = ADS_BDriver()
     self.display = Display()
     self.loudSpeaker = LoudSpeaker()
     self.panelBtns = FrontPanelButtons()
Exemple #3
0
class MainClass:
    def __init__(self):
        self.ownShip = Aircraft(0, 0, 0, 0, 0, 0, 0, 0)
        self.aircraftQueue = PriorityQueue()
        self.myAction = Action(0, 0)
        self.ads_bInt = ADS_BDriver()
        self.display = Display()
        self.loudSpeaker = LoudSpeaker()
        self.panelBtns = FrontPanelButtons()

    def refreshAircraftListFromADSB(self):
        adsData = self.ads_bInt.refresh()
        return ADS_BDataProcessor.getAircraftList(adsData)

    def buildAircraftPriorityQueue(self, aircraftList):
        self.aircraftQueue = PriorityQueue()
        for a in aircraftList:
            self.aircraftQueue.put(a)

    def updateDisplay(self, aircraftList, alertLevel, action):
        self.display.updateAircraftList(aircraftList)
        self.display.updateCurAlertLevel(alertLevel)
        self.display.updateCurAction(action)

    def updateLoudSpeaker(self, action):
        self.loudSpeaker.annunciate(action)

    def loopIter(self):
        aircraftList = self.refreshAircraftListFromADSB()

        if len(aircraftList) > 0:
            self.buildAircraftPriorityQueue(aircraftList)

            curAlertLevel = self.aircraftQueue.queue[0].getAlertLevel()
            curAction = self.determineAction

            self.updateDisplay(aircraftList, curAlertLevel, curAction)
            self.updateLoudSpeaker(curAction)

    def eventLoop(self):
        while True:
            self.loopIter()

    @property
    def determineAction(self):
        myAircraft = self.aircraftQueue.get()
        if (myAircraft.getAlertLevel() == AlertLevel.AL_PrevAdvisory):
            return Action(0, 1)
        elif (myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryLow):
            if (myAircraft.getZInFeet() > self.ownShip.getZInFeet()):
                return Action(-1, -1)
            elif (myAircraft.getZInFeet() < self.ownShip.getZInFeet()):
                return Action(1, -1)
            elif (myAircraft.getYInFeet > self.ownShip.getYInFeet()):
                return Action(-1, -1)
            elif (myAircraft.getYInFeet() < self.ownShip.getYInFeet()):
                return Action(1, -1)
            elif (myAircraft.getXInFeet > self.ownShip.getXInFeet()):
                return Action(-1, -1)
            elif (myAircraft.getXInFeet() < self.ownShip.getXInFeet()):
                return Action(1, -1)
        elif (myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryMed):
            if (myAircraft.getZInFeet() > self.ownShip.getZInFeet()):
                return Action(-1, 0)
            elif (myAircraft.getZInFeet() < self.ownShip.getZInFeet()):
                return Action(1, 0)
            elif (myAircraft.getYInFeet() > self.ownShip.getYInFeet()):
                return Action(-1, 0)
            elif (myAircraft.getYInFeet() < self.ownShip.getYInFeet()):
                return Action(1, 0)
            elif (myAircraft.getXInFeet() > self.ownShip.getXInFeet()):
                return Action(-1, 0)
            elif (myAircraft.getXInFeet() < self.ownShip.getXInFeet()):
                return Action(1, 0)
        elif (myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryHigh):
            if (myAircraft.getZInFeet() > self.ownShip.getZInFeet()):
                return Action(-1, 1)
            elif (myAircraft.getZInFeet() < self.ownShip.getZInFeet()):
                return Action(1, 1)
            elif (myAircraft.getYInFeet() > self.ownShip.getYInFeet()):
                return Action(-1, 1)
            elif (myAircraft.getYInFeet() < self.ownShip.getYInFeet()):
                return Action(1, 1)
            elif (myAircraft.getXInFeet() > self.ownShip.getXInFeet()):
                return Action(-1, 1)
            elif (myAircraft.getXInFeet() < self.ownShip.getXInFeet()):
                return Action(1, 1)
        else:
            return Action(0, -1)

    def setOwnShip(self, xInFeet: int, yInFeet: int, zInFeet: int,
                   heading: float, vSpeedFPS: int, gSpeedFPS: int,
                   alertLevel: AlertLevel, id: int):
        self.ownShip = Aircraft(xInFeet, yInFeet, zInFeet, heading, vSpeedFPS,
                                gSpeedFPS, alertLevel, id)

    def getAction(self):
        return self.myAction
class MainClass:
    def __init__(self):
        self.ownShip = Aircraft(0, 0, 0, 0, 0, 0, 0, 0)
        self.aircraftQueue = PriorityQueue()
        self.myAction = Action(0, 0)
        self.ads_bInt = ADS_BDriver()
        self.display = Display()
        self.loudSpeaker = LoudSpeaker()
        self.panelBtns = FrontPanelButtons()

    def refreshAircraftListFromADSB(self):
        adsData = self.ads_bInt.refresh()
        return ADS_BDataProcessor.getAircraftList(adsData)

    def buildAircraftPriorityQueue(self, aircraftList):
        self.aircraftQueue = PriorityQueue()
        for a in aircraftList:
            self.aircraftQueue.put(a)

    def updateDisplay(self, aircraftList, alertLevel, action):
        self.display.updateAircraftList(aircraftList)
        self.display.updateCurAlertLevel(alertLevel)
        self.display.updateCurAction(action)

    def updateLoudSpeaker(self, action):
        self.loudSpeaker.annunciate(action)

    def loopIter(self):
        aircraftList = self.refreshAircraftListFromADSB()

        if len(aircraftList) > 0:
            self.buildAircraftPriorityQueue(aircraftList)

            curAlertLevel = self.aircraftQueue.queue[0].getAlertLevel()
            curAction = self.determineAction

            self.updateDisplay(aircraftList, curAlertLevel, curAction)
            self.updateLoudSpeaker(curAction)

    def eventLoop(self):
        while True:
            self.loopIter()

    @property
    def determineAction(self):
        myAircraft = self.aircraftQueue.get()
        if myAircraft.getAlertLevel() == AlertLevel.AL_PrevAdvisory:
            return Action(0, 1)
        elif myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryLow:
            if myAircraft.getZInFeet() > self.ownShip.getZInFeet():
                return Action(-1, -1)
            elif myAircraft.getZInFeet() < self.ownShip.getZInFeet():
                return Action(1, -1)
            elif myAircraft.getYInFeet > self.ownShip.getYInFeet():
                return Action(-1, -1)
            elif myAircraft.getYInFeet() < self.ownShip.getYInFeet():
                return Action(1, -1)
            elif myAircraft.getXInFeet > self.ownShip.getXInFeet():
                return Action(-1, -1)
            elif myAircraft.getXInFeet() < self.ownShip.getXInFeet():
                return Action(1, -1)
        elif myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryMed:
            if myAircraft.getZInFeet() > self.ownShip.getZInFeet():
                return Action(-1, 0)
            elif myAircraft.getZInFeet() < self.ownShip.getZInFeet():
                return Action(1, 0)
            elif myAircraft.getYInFeet() > self.ownShip.getYInFeet():
                return Action(-1, 0)
            elif myAircraft.getYInFeet() < self.ownShip.getYInFeet():
                return Action(1, 0)
            elif myAircraft.getXInFeet() > self.ownShip.getXInFeet():
                return Action(-1, 0)
            elif myAircraft.getXInFeet() < self.ownShip.getXInFeet():
                return Action(1, 0)
        elif myAircraft.getAlertLevel() == AlertLevel.AL_ResolAdvisoryHigh:
            if myAircraft.getZInFeet() > self.ownShip.getZInFeet():
                return Action(-1, 1)
            elif myAircraft.getZInFeet() < self.ownShip.getZInFeet():
                return Action(1, 1)
            elif myAircraft.getYInFeet() > self.ownShip.getYInFeet():
                return Action(-1, 1)
            elif myAircraft.getYInFeet() < self.ownShip.getYInFeet():
                return Action(1, 1)
            elif myAircraft.getXInFeet() > self.ownShip.getXInFeet():
                return Action(-1, 1)
            elif myAircraft.getXInFeet() < self.ownShip.getXInFeet():
                return Action(1, 1)
        else:
            return Action(0, -1)

    def setOwnShip(
        self,
        xInFeet: int,
        yInFeet: int,
        zInFeet: int,
        heading: float,
        vSpeedFPS: int,
        gSpeedFPS: int,
        alertLevel: AlertLevel,
        id: int,
    ):
        self.ownShip = Aircraft(xInFeet, yInFeet, zInFeet, heading, vSpeedFPS, gSpeedFPS, alertLevel, id)

    def getAction(self):
        return self.myAction