EZR
Dependencies: CRC16 FreescaleIAP FreescaleWatchdog GGSProtocol LM75B PIMA Parameters PersistentCircularQueue SerialNumberV2COM mbed-dev-watchdog_2016_03_04
Fork of smartRamalKW by
Diff: main.cpp
- Revision:
- 29:fec8fdf25d87
- Parent:
- 26:03c9ca836c79
- Child:
- 31:ef0e073126a1
--- a/main.cpp Tue Dec 08 13:23:49 2015 +0000 +++ b/main.cpp Tue Feb 23 20:35:38 2016 +0000 @@ -1,5 +1,7 @@ #include "main.h" +////////////////////////////////////////////////////////////// +// Global Variables static Watchdog wd; static Ticker tickerWd; SerialNumber sn; @@ -13,9 +15,44 @@ #endif Announce announce; +////////////////////////////////////////////////////////////// +// External vars + +#ifdef MBED_COMPILER +static const uint32_t _NodeAddress = DEFAULT_NODE_ADDRESS; +static const uint32_t _NetworkAddress = DEFAULT_NETWORK_ADDRESS; +static const uint32_t _NetworkChannel = DEFAULT_NETWORK_CHANNEL; +static const uint32_t _NodeRole = DEFAULT_NODE_ROLE; +static const uint32_t _SrcEndpoint = DEFAULT_SOURCE_ENDPOINT; +static const uint32_t _DestNode = DEFAULT_DESTINATION_NODE; +static const uint32_t _DestEndpoint = DEFAULT_DESTINATION_ENDPOINT; +static const uint32_t _DynamicDest = DEFAULT_DYNAMIC_DESTINATION; +static const uint32_t _AccessCycle = DEFAULT_ACCESS_CYCLE; +static const uint8_t _AppConfigDataPayload[APP_CONFIG_DATA_SIZE] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#else +extern volatile uint32_t _NodeAddress; +extern volatile uint32_t _NetworkAddress; +extern volatile uint32_t _NetworkChannel; +extern volatile uint32_t _NodeRole; +extern volatile uint32_t _SrcEndpoint; +extern volatile uint32_t _DestNode; +extern volatile uint32_t _DestEndpoint; +extern volatile uint32_t _DynamicDest; +extern volatile uint32_t _AccessCycle; +extern volatile uint8_t _AppConfigData; +const uint8_t * _AppConfigDataPayload = const_cast< const uint8_t * >( &_AppConfigData ); +#endif + +////////////////////////////////////////////////////////////// +// Main + int main() { +#ifdef WATCHDOG_ENABLED iniciaWd(); +#endif blinkLeds(); DEBUG(printf("##### %s #####\r\n", version)); @@ -25,7 +62,7 @@ DEBUG(printParameters()); isopowerDisable = 0; // Habilita regulador (PIMA + Alarme Caixa) - + #ifndef RAMAL boxAlarm.init(); #endif @@ -41,13 +78,56 @@ } #endif - ggsStream.baud(APP_PARAMETERS.RADIO_BAUDRATE_BPS); +#ifdef DIRECT_UART + ggsStream.baud( APP_PARAMETERS.RADIO_BAUDRATE_BPS ); + #ifdef UART_8N2 + ggsStream.format( 8, Serial::None, 2 ); + #endif +#else + // initializes serial + pinoSerial.baud( APP_PARAMETERS.RADIO_BAUDRATE_BPS ); + #ifdef UART_8N2 + pinoSerial.format( 8, Serial::None, 2 ); + #endif + +#endif + exec.carregaEndereco(sn.get()); exec.iniciaExecutorComandos(APP_PARAMETERS.INTERVALO_WD_NETWORK_S, APP_PARAMETERS.INTERVALO_SILENCIO_S); announce.setDelayCoefs(APP_PARAMETERS.DISCOVERY_DELAY_ANG_COEF_MS, APP_PARAMETERS.DISCOVERY_DELAY_LIN_COEF_MS); announce.setIntervals(APP_PARAMETERS.ANNOUNCE_INTERVAL_S, APP_PARAMETERS.INTERVALO_SILENCIO_S); + +#ifndef DIRECT_UART + // configures Pino stack + ggsStream.init( _SrcEndpoint, _DestNode, _DestEndpoint, _DynamicDest ); + PinoCfgStr pinoCfg = { + .nodeAddress = _NodeAddress, + .networkAddress = _NetworkAddress, + .networkChannel = static_cast< uint8_t >( _NetworkChannel ), + .nodeRole = static_cast< uint8_t >( _NodeRole ) + }; + ggsStream.checkCfg( pinoCfg, DEFAULT_PINO_CFG_ATTEMPTS ); + + // configures access cycle + uint16_t newCycle = static_cast< uint16_t >( _AccessCycle ); + ggsStream.checkCycle( newCycle, newCycle, DEFAULT_PINO_CFG_ATTEMPTS ); + + // waits for the stack to start + ggsStream.checkStop( DEFAULT_PINO_START_ATTEMPTS, _AppConfigDataPayload ); + ggsStream.setPerPoll( 2000 ); + + //AppConfigData cfg; + //ggsStream.readMsapAppDataConfiguration( cfg ); + //printf( "%u", cfg.seqNumber ); + +#endif + while(1){ +#ifndef DIRECT_UART + ggsStream.handleFrames(); + ggsStream.handleStream(); +#endif exec.trataPacoteGGS(); #ifndef RAMAL pima.trataPacotePiminha(); @@ -63,7 +143,6 @@ } } - void iniciaWd(){ wd.Configure(); tickerWd.attach(&feedWd, WATCHDOG_INTERVAL);