示例#1
0
    def process(self):
        # Check to see if schedule file exists. If it does, change state to idle
        if Gateway.pingGateway():
            self.fsm.setState(IdleState(self.fsm))
            logging.info("Gateway ping succeeded")

        super().process()
示例#2
0
 def println():
     gateway = Gateway.gateway()
         
     ping = Gateway.pingGateway()
     
     temp = CPUTemperature().temperature
     
     load = LoadAverage().load_average
     
     pid = os.getpid()
     
     ppid = os.getppid()
     
     data = {
         "pid": pid,
         "parent pid": ppid,
         "ping gateway": gateway,
         "ping response": ping,
         "temperature": temp,
         "average load": load
         }
     
     logging.debug("Diagnostics: %s", str(data))
示例#3
0
    def process(self):

        #nextState = State(self.fsm)

        # We check to see if we can reach the default gateway
        if Gateway.pingGateway():
            self.fsm.last_gateway_ping = datetime.now()

        if (datetime.now() - self.fsm.last_gateway_ping).seconds > 5 * 60:
            self.fsm.setState(NoGateway(self.fsm))
            return

        # First we check the time to see if we should update
        current_time = datetime.now()

        if current_time.day == CHFSM.UPDATE_REBOOT_TIME[
                0] and current_time.hour == CHFSM.UPDATE_REBOOT_TIME[
                    1] and current_time.minute == CHFSM.UPDATE_REBOOT_TIME[
                        2] and current_time.second == CHFSM.UPDATE_REBOOT_TIME[
                            3]:
            self.fsm.setState(Update(self.fsm))
            return

        # We use stateCode to determine which relays should be set, then use this to change state (if needed)
        stateCode = 0

        stateCode |= self.buttonProcess()

        # Make sure schedule file exists and is valid
        if not os.path.isfile(self.fsm.schedule_file_path):
            self.fsm.setState(NoSchedule(self.fsm))
            return

        # If the schedule file exists, make sure it is the right size
        if os.path.getsize(self.fsm.schedule_file_path) != 7 * 24 * 60:
            self.fsm.setState(BadSchedule(self.fsm))
            return

        schedule = self.scheduleProcess()

        # Fourth bit represents the emergency off state. This will set the current state to idle
        if schedule & 4 and (0 <= current_time.second <= 1):
            self.fsm.ch_boost_on = False
            return

        stateCode |= schedule & 3

        if not os.path.isfile(self.fsm.commands_file_path):
            fh = open(self.fsm.commands_file_path, "wb")
            fh.close()

        stateCode |= self.commandProcess()

        # Translate state code into an FSM state
        if stateCode == 0:
            nextState = IdleState(self.fsm)
        elif stateCode == 1:
            nextState = CHState(self.fsm)
        elif stateCode == 2:
            nextState = HWState(self.fsm)
        elif stateCode == 3:
            nextState = BothState(self.fsm)

        # Only set state if it has changed
        if type(nextState) != type(self.fsm.getState()):
            self.fsm.setState(nextState)