void operationPing(DogSetting& ds, ProcessInfo& pr, uint8_t dogNumber) { // If ping success - exit. bool pingResult = PingIP(ds.IP); SetNextTimeToOperate(dogNumber, ds.TestPeriod); // If ping OK - return. if (pingResult) { // Reset lost times if ping success. pr.LostTimes = 0; return; } if (++pr.LostTimes > ds.HostLostAfter) { // Reset lost times. pr.LostTimes = 0; // Switch relay to ON. SetRelayStatus(dogNumber, ON); // Increment restarts. ++pr.Restarts; // Set current operation to RESTART. pr.NextOpertion = OT_RESTART; // Prepare restart wait time. SetNextTimeToOperate(dogNumber, ds.RestartWaitTime); } }
void operationRestart(DogSetting& ds, ProcessInfo& pr, uint8_t dogNumber) { // Switch relay to OFF. SetRelayStatus(dogNumber, OFF); // Next operation is ping. pr.NextOpertion = OT_PING; // Prepare time to next ping. SetNextTimeToOperate(dogNumber, ds.WaitAfterRestart); }
void SetRelayStatus(int relayNumber, bool status) { Status rs; if(status) rs = ON; else rs = OFF; SetRelayStatus(relayNumber, rs); }
void Processing::init() { DEF_DeviceSetting(DeviceData); SetLists_DEF(); if (eeprom_read_byte((uint8_t*)EE_DATA_POS[0]) == INITIALIZED_EEPROM) { ReadEEPROMData(); } else { // First write default data. WriteEEPROMAllData(); } // Initialize next time to ping and process type. for (uint8_t i = 0; i < DOG_COUNT; i++) { SetNextTimeToOperate(i, DogList[i].TestPeriod); // Set all relays OFF. SetRelayStatus(i, OFF); } }
void SetAllRelaysOff() { for(int i = 0; i < RELAY_COUNT; i++) SetRelayStatus(i, OFF); }
void SetRelayStatus(Relay relay, bool status) { SetRelayStatus(relay, status); }
void SetRelayStatus(Relay relay, Status status) { SetRelayStatus(relay, status); }
void Watchdog() { uint32_t t = millis(); //watchdog funcionar apenas quando ninguem está acessando a interface if(InSession.LastReceivedPacketClock != 0) { if((t - InSession.LastReceivedPacketClock) >= WATCHDOG_EXECUTE * CLOCKS_PER_SEC) { InSession.LastReceivedPacketClock = 0; } else { bool flag = false; //só vai pausar a execução do watchdog quando tiver nenhuma porta reiniciando for(byte i = 0; i < MAX_RELAY; i++) { if(InSession.Watchdog.Port[i].Restart) { flag = true; break; } } InSession.Watchdog.Execute = flag; } } else { InSession.Watchdog.Execute = true; } if(InSession.Watchdog.Execute) { for(byte i = 0; i < MAX_RELAY; i++) { if(Relay[i].State == RELAY_OFF) { continue; } auto ip = Arduino.PatchPanel.Port[i].Ip; if(ip[0] != 0) { //se a porta tiver configurada //verifica se ja passou WATCHDOG_WAIT_TIME após reiniciar uma porta //senao, o ping nao acontece até acabar esse tempo if(!InSession.Watchdog.Port[i].Restart && InSession.Watchdog.Port[i].Clock != 0) { if((t - InSession.Watchdog.Port[i].Clock) < WATCHDOG_WAIT_TIME * CLOCKS_PER_SEC) { continue; } else { InSession.Watchdog.Port[i].Clock = 0; } } static uint32_t timer[MAX_RELAY]; //testa cada porta com um ping //se a quantidade de erros for maior que WATCHDOG_MAX_PING_ERROR_COUNT //seta para que essa porta seja reiniciada if((t - timer[i]) >= WATCHDOG_CHECK_TIME * CLOCKS_PER_SEC && !InSession.Watchdog.Port[i].Restart) { timer[i] = t; if(!Ping(ip)) { InSession.Watchdog.Port[i].ErrorCount ++; if(InSession.Watchdog.Port[i].ErrorCount >= WATCHDOG_MAX_PING_ERROR_COUNT) { InSession.Watchdog.Port[i].ErrorCount = 0; InSession.Watchdog.Port[i].Off = false; InSession.Watchdog.Port[i].Restart = true; continue; } } else { InSession.Watchdog.Port[i].ErrorCount = 0; } } //verifica se tem alguma porta para reiniciar //se tiver alguma, irá desligar a porta //depois de WATCHDOG_PORT_RESTART_TIME segundos irá ligar novamente if(InSession.Watchdog.Port[i].Restart) { if(!InSession.Watchdog.Port[i].Off) { InSession.Watchdog.Port[i].Off = true; InSession.Watchdog.Port[i].Clock = t; SetRelayStatus(i, RELAY_OFF, true); } else { if((t - InSession.Watchdog.Port[i].Clock) >= WATCHDOG_PORT_RESTART_TIME * CLOCKS_PER_SEC) { InSession.Watchdog.Port[i].Restart = false; InSession.Watchdog.Port[i].Off = false; InSession.Watchdog.Port[i].Clock = t; SetRelayStatus(i, RELAY_ON); } } } } } } }