Ejemplo n.º 1
0
    def __init__(self, localConfig, logger):
        self.localConfig = localConfig
        self.logger = logger
        self.periphController = PeripheralController()

        self.commandProcessor = CommandProcessor(logger, self.periphController, self.localConfig)
Ejemplo n.º 2
0
class DiversityMain:
    port = None
    name = None
    logger = None
    main_thread = None
    listenerSocket = None
    senderSocket = None
    localConfig = None
    periphController = None
    commandProcessor = None

    def __init__(self, localConfig, logger):
        self.localConfig = localConfig
        self.logger = logger
        self.periphController = PeripheralController()

        self.commandProcessor = CommandProcessor(logger, self.periphController, self.localConfig)

    def start(self):
        self.event = threading.Event()
        self.main_thread = Thread(target=self.startMainThread, args=("test",))
        self.main_thread.start()
        self.periphController.startThread()

    def startMainThread(self, teset):
        self.startReportingTimer()
        self.event.wait()
        self.logger.write("reporttimer", "out")

    def startReportingTimer(self):
        if self.event.isSet():
            self.logger.write("reporttimer", "Not restarting")
        else:
            self.timer = Timer(1, self.doReport, args=["WOW"])
            self.timer.start()

    freqcounter = 0
    reportAtStartup = True

    def doReport(self, message):
        global localConfig
        freq = int(localConfig.connectfreq)
        # self.logger.write("main_thread","reporting")
        self.freqcounter += 1
        if self.freqcounter >= freq or self.commandProcessor.wantPostNow() == True or self.reportAtStartup == True:
            self.reportAtStartup = False
            self.freqcounter = 0
            self.postalive()
        self.startReportingTimer()

    def join(self):
        self.main_thread.join()

    def stop(self):
        self.periphController.stopThread()
        self.timer.cancel()
        self.event.set()

    def postalive(self):
        postdata = {"cid": localConfig.clientid, "psw": localConfig.password}
        self.commandProcessor.postAlive()