예제 #1
0
    def __init__(self, **kwargs):

        debug = False
        raceid = 0

        if kwargs.has_key("raceid"):
            raceid = kwargs.get("raceid")

        if kwargs.has_key("debug"):
            debug = (kwargs.get("debug") == 1)

        self.__serial = None
        self.__debugmode = debug
        self.__msg_temp = ""
        self.__lastCardId = ""
        self.__lastCards = {}
        self.__nodes = {}
        self.__nodeQueues = {}
        self.__nodesAngemeldet = 0

        #setup
        self.__active = True
        self.__port = '/dev/ttyUSB0'
        self.__raceid = raceid

        self.__setupRace(raceid)

        self.__starten()

        ausgabe(TYPE_DBG, "INIT beendet", self.__debugmode)

        return None
예제 #2
0
    def __parseCommand(self, newcommand):

        returnStatus = True

        if self.__raceid > 0:

            if newcommand.isValid:

                ausgabe(
                    TYPE_CMD, newcommand.commando + " " + newcommand.cardId +
                    " " + newcommand.slot, self.__debugmode)

                if newcommand.commando == COM_COMMAND_ADD:
                    self.__command_ADD(newcommand.cardId, newcommand.slot)

                elif newcommand.commando == COM_COMMAND_RMV:
                    self.__command_RMV(newcommand.cardId, newcommand.slot)

                elif newcommand.commando == COM_COMMAND_CHK:
                    self.__command_CHK(newcommand.cardId, newcommand.slot)

                elif newcommand.commando == COM_COMMAND_COL:
                    self.__command_COL(newcommand.slot)

                elif newcommand.commando == COM_COMMAND_WLK:
                    self.__command_WLK(newcommand.cid)

                elif newcommand.commando == COM_COMMAND_EXS:
                    self.__command_EXS(newcommand.cardId, newcommand.accessory,
                                       newcommand.slot)

        else:
            ausgabe(TYPE_ERR, "Kein Race gewaehlt", self.__debugmode)

        return returnStatus
예제 #3
0
    def beenden(self):

        returnStatus = True

        self.__active = False

        ausgabe(TYPE_DBG, "Node ({}) beenden".format(self.slot),
                self.__debugmode)

        #Threads beenden
        #Serial schliessen
        if not self.__con is None:
            self.__con.close()

        self.__queue.put(None)

        return returnStatus
예제 #4
0
    def sendToNode(self, message, nodeId=None):

        returnStatus = True

        if not nodeId is None:
            pass

        if not self.__con is None:

            message = message + ";"

            self.__con.write(message)

        else:
            ausgabe(TYPE_ERR, "Slot {} nicht verfuegbar".format(self.slot))

            returnStatus = False

        return returnStatus
예제 #5
0
    def __sendToNode(self, message, slot, nodeId=None):

        returnStatus = True

        if not nodeId is None:
            ausgabe(TYPE_DBG, str(nodeId), self.__debugmode)

        message = message + ";"

        #Nodeid stellt die i2c-adresse dar
        ausgabe(TYPE_OUT, message, self.__debugmode)

        if self.__nodes.has_key(slot):
            node = self.__nodes[slot]
            node.sendToNode(message, nodeId)
        else:
            returnStatus = False

        return returnStatus
예제 #6
0
    def __listenToNode(self):

        try:

            while self.__active == True:
                message = ""

                if not self.__con is None:
                    message = self.__con.readline().strip()

                if len(message) > 0:
                    #print(message)
                    message = self.__msg_temp + message
                    #print message

                    if message[:
                               3] == COM_PREFIX_CMD or message[:
                                                               3] == COM_PREFIX_ASK:

                        if message[-1:] == ";":
                            #Hier jetzt irgenwat machen
                            newcommand = self.__parseCommand(
                                message.replace(";", ""))
                            newcommand.cid = self.channelid
                            self.__queue.put(newcommand)

                            self.__msg_temp = ""
                        else:
                            self.__msg_temp = message

                    elif message[:3] == COM_INFO_RSP:
                        #sollte eigentlich nicht vorkommen
                        ausgabe(TYPE_RSP, message, self.__debugmode)

                    else:
                        ausgabe(TYPE_INF, message, self.__debugmode)

                time.sleep(0.01)

        except KeyboardInterrupt:
            ausgabe(TYPE_DBG,
                    "Abbruch mit STRG+C ({}) beendet".format(self.port),
                    self.__debugmode)
            self.beenden()

        except:
            self.beenden()

        ausgabe(TYPE_DBG, "ListenToNode ({}) beendet".format(self.port),
                self.__debugmode)
예제 #7
0
    def __readQueue(self):

        try:
            while self.__active:
                if self.__nodesAngemeldet > 0:
                    newcommand = self.__q.get()
                    if not newcommand is None:
                        ausgabe(TYPE_DBG,
                                "Neue Meldung von {}".format(newcommand.slot),
                                self.__debugmode)

                        self.__parseCommand(newcommand)
                    else:
                        ausgabe(TYPE_DBG, "None erhalten", self.__debugmode)
                        self.__nodesAngemeldet = self.__nodesAngemeldet - 1
                    self.__q.task_done()

                time.sleep(0.01)
        except KeyboardInterrupt:
            ausgabe(TYPE_DBG, "Abbruch mit STRG+C readQueue", self.__debugmode)

        ausgabe(TYPE_DBG, "readQueue beendet", self.__debugmode)
예제 #8
0
    def beenden(self):

        for cid, node in self.__nodes.items():
            ausgabe(TYPE_DBG, "Node {} beenden".format(node.slot),
                    self.__debugmode)
            node.beenden()
            #print(node.active, node.slot)
            self.__nodes[cid] = None
            time.sleep(1)

        self.__active = False

        ausgabe(TYPE_DBG, "Alle Node beendet", self.__debugmode)
        time.sleep(3)

        ausgabe(TYPE_DBG, "q-Thread Status: {}".format(self.__thQ.is_alive()),
                self.__debugmode)

        self.__thQ = None
예제 #9
0
    def __del__(self):

        ausgabe(TYPE_DBG, "Node ({}) beendet".format(self.slot),
                self.__debugmode)