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
announce.cpp
00001 #include "announce.h" 00002 00003 Announce::Announce(){ 00004 announceDelayAngCoef = 1; 00005 announceDelayLinCoef = 0; 00006 announceIntervalSec = 600; 00007 silenceIntervalSec = 2; 00008 sendNow = false; 00009 } 00010 00011 void Announce::setDelayCoefs(int delayAngCoef, int delayLinCoef){ 00012 announceDelayAngCoef = delayAngCoef; 00013 announceDelayLinCoef = delayLinCoef; 00014 } 00015 00016 void Announce::setIntervals(int announce, int silence){ 00017 announceIntervalSec = announce; 00018 silenceIntervalSec = silence; 00019 } 00020 00021 void Announce::startAnnounceTimer(){ 00022 announceBuffer[0] = PREAMBULO1; 00023 announceBuffer[1] = PREAMBULO2; 00024 announceBuffer[2] = TAMANHO_ENDERECO + TAMANHO_ENDERECO + 2 + MEDIDOR_LENGTH; // 25 00025 00026 for(int i=0; i < TAMANHO_ENDERECO; i++){ 00027 announceBuffer[i+3] = ((sn.get()[2*i+9] & 0x0f) << 4) | (sn.get()[2*i+10] & 0x0f); 00028 } 00029 00030 for(int i=0; i < 8; i++){ 00031 announceBuffer[i+11] = 0xff; 00032 } 00033 announceBuffer[19] = 0x00; // Numero de sequencia 00034 announceBuffer[20] = CMD_BUSCAR_CONCENTRADOR; 00035 00036 delay = announceDelayAngCoef * (((sn.get()[23] & 0x0f)*10) + (sn.get()[24] & 0x0f)) + announceDelayLinCoef; // Delay variavel de acordo com o numero de serie do modulo 00037 DEBUG(printf("[GGS] Sending announce in %d ms...\r\n", delay)); 00038 00039 announceTimeout.attach_us(this, &Announce::triggerAnnounceSending, delay*1000); 00040 } 00041 00042 void Announce::stopAnnounceTimer(){ 00043 announceTimeout.detach(); 00044 } 00045 00046 void Announce::triggerAnnounceSending(){ 00047 sendNow = true; 00048 } 00049 00050 void Announce::handleAnnounceSending(){ 00051 if(!sendNow){ 00052 return; 00053 } 00054 sendNow = false; 00055 00056 if(exec.getTimerGGS() < (float)silenceIntervalSec){ 00057 DEBUG(printf("[GGS] Network busy. Sending announce in %d ms...\r\n", delay)); 00058 announceTimeout.attach_us(this, &Announce::triggerAnnounceSending, delay*1000); 00059 return; 00060 } 00061 00062 announceBuffer[19]++; 00063 announceBuffer[19] %= 256; 00064 #ifdef RAMAL 00065 memcpy(announceBuffer+21, MEDIDOR_DEFAULT_SN, MEDIDOR_LENGTH); 00066 #else 00067 memcpy(announceBuffer+21, pima.getMeterNumber(), MEDIDOR_LENGTH); 00068 #endif 00069 unsigned short int crc = getCRC(announceBuffer, 2, announceBuffer[2] + 1); 00070 announceBuffer[28] = crc%256; // CRC1 00071 announceBuffer[29] = crc/256; // CRC2 00072 enviaRespostaGGS(announceBuffer, 30); 00073 00074 DEBUG(printf("[GGS] Sending new announce in %d s\r\n", announceIntervalSec + delay/1000)); 00075 announceTimeout.attach_us(this, &Announce::triggerAnnounceSending, announceIntervalSec*1000*1000 + delay*1000); 00076 }
Generated on Thu Jul 14 2022 00:24:57 by
1.7.2
