Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CRC16 FreescaleIAP FreescaleWatchdog GGSProtocol LM75B PIMA Parameters PersistentCircularQueue SerialNumberV2COM mbed-dev-watchdog_2016_03_04
Fork of smartRamalKW by
main.cpp
00001 #include "main.h" 00002 00003 static Watchdog wd; 00004 static Ticker tickerWd; 00005 SerialNumber sn; 00006 Parameters param ((char *)&APP_PARAMETERS, sizeof(APP_PARAMETERS)); 00007 CommandExecutor exec; 00008 MemoriaMassa mm; 00009 Alarm alarm; 00010 #ifndef RAMAL // objetos só existem se o equipamento é um smart breaker 00011 BoxAlarm boxAlarm; 00012 Pima pima; 00013 #endif 00014 Announce announce; 00015 00016 int main() 00017 { 00018 iniciaWd(); 00019 blinkLeds(); 00020 00021 DEBUG(printf("##### %s #####\r\n", version)); 00022 DEBUG(printSerialNumber()); 00023 00024 param.loadParameters(); 00025 DEBUG(printParameters()); 00026 00027 isopowerDisable = 0; // Habilita regulador (PIMA + Alarme Caixa) 00028 00029 #ifndef RAMAL 00030 boxAlarm.init(); 00031 #endif 00032 alarm.loadQueue(APP_PARAMETERS.ALARMS_QUEUE_SIZE, 3); 00033 mm.iniciaLeituras(APP_PARAMETERS.INTERVALO_MM_S, APP_PARAMETERS.MM_SIZE, 4, 5, 6); 00034 00035 #ifndef RAMAL 00036 pima.setExpirationTimeout(APP_PARAMETERS.PIMA_VALIDADE_MEDIDOR_S, APP_PARAMETERS.PIMA_VALIDADE_ENERGIA_ATIVA_S, APP_PARAMETERS.PIMA_VALIDADE_ENERGIA_REATIVA_INDUTIVA_S, APP_PARAMETERS.PIMA_VALIDADE_ENERGIA_REATIVA_CAPACITIVA_S); 00037 if(APP_PARAMETERS.PROTOCOLO_MEDIDOR == PROTOCOLO_PIMINHA){ 00038 pima.iniciaLeituraPiminha(APP_PARAMETERS.PIMA_AUTOBAUD_ENABLE, APP_PARAMETERS.PIMA_AUTOBAUD_TIMEOUT_S, APP_PARAMETERS.INTERVALO_WD_METER_S, APP_PARAMETERS.PIMA_TIMEOUT_PACOTE_S); 00039 } else{ 00040 pima.iniciaLeituraPima(APP_PARAMETERS.PIMA_AUTOBAUD_ENABLE, APP_PARAMETERS.PIMA_AUTOBAUD_TIMEOUT_S, APP_PARAMETERS.INTERVALO_WD_METER_S); 00041 } 00042 #endif 00043 00044 ggsStream.baud(APP_PARAMETERS.RADIO_BAUDRATE_BPS); 00045 exec.carregaEndereco(sn.get()); 00046 exec.iniciaExecutorComandos(APP_PARAMETERS.INTERVALO_WD_NETWORK_S, APP_PARAMETERS.INTERVALO_SILENCIO_S); 00047 announce.setDelayCoefs(APP_PARAMETERS.DISCOVERY_DELAY_ANG_COEF_MS, APP_PARAMETERS.DISCOVERY_DELAY_LIN_COEF_MS); 00048 announce.setIntervals(APP_PARAMETERS.ANNOUNCE_INTERVAL_S, APP_PARAMETERS.INTERVALO_SILENCIO_S); 00049 00050 #ifdef RAMAL 00051 announce.startAnnounceTimer(); 00052 #endif 00053 00054 while(1){ 00055 exec.trataPacoteGGS(); 00056 #ifndef RAMAL 00057 pima.trataPacotePiminha(); 00058 if(pima.hasMeterChanged()){ 00059 announce.startAnnounceTimer(); 00060 } 00061 #endif 00062 mm.executaLeitura(); 00063 #ifndef RAMAL 00064 boxAlarm.checkState(); 00065 #endif 00066 announce.handleAnnounceSending(); 00067 } 00068 00069 } 00070 00071 void iniciaWd(){ 00072 wd.Configure(); 00073 tickerWd.attach(&feedWd, WATCHDOG_INTERVAL); 00074 } 00075 00076 void feedWd(){ 00077 wd.Service(); 00078 } 00079 00080 void softReset(){ 00081 DEBUG(printf("[main] SoftReset\r\n")); 00082 tickerWd.detach(); 00083 } 00084 00085 void blinkLeds(){ 00086 ledPowerON = LED_ON; 00087 ledNetwork = LED_OFF; 00088 ledMeter = LED_OFF; 00089 ledLoad = LED_OFF; 00090 ledBox = LED_OFF; 00091 00092 wait_ms(200); 00093 ledNetwork = LED_ON; 00094 wait_ms(200); 00095 ledNetwork = LED_OFF; 00096 ledMeter = LED_ON; 00097 wait_ms(200); 00098 ledMeter = LED_OFF; 00099 ledLoad = LED_ON; 00100 wait_ms(200); 00101 ledLoad = LED_OFF; 00102 ledBox = LED_ON; 00103 wait_ms(200); 00104 ledBox = LED_OFF; 00105 } 00106 00107 void printSerialNumber(){ 00108 printf("[main] SN: "); 00109 for(int i=0; i < SERIAL_LENGTH; i++){ 00110 printf("%c", sn.get()[i]); 00111 } 00112 printf("\r\n"); 00113 } 00114 00115 void printParameters(){ 00116 printf("[main] Parameters:"); 00117 for(int i=0; i < sizeof(APP_PARAMETERS); i++){ 00118 printf(" %02x", ((char *)&APP_PARAMETERS)[i]); 00119 } 00120 printf("\r\n"); 00121 }
Generated on Thu Jul 14 2022 00:24:57 by
1.7.2
