Application example using LoRaWAN-lib MAC layer implementation
Dependencies: mbed LoRaWAN-lib SX1272Lib
Fork of LoRaWAN-demo-72 by
Diff: app/main.cpp
- Revision:
- 6:f9224695ed01
- Parent:
- 5:62862ef9480b
--- a/app/main.cpp Tue Jul 05 15:00:47 2016 +0000 +++ b/app/main.cpp Wed Mar 22 12:42:27 2017 +0000 @@ -21,15 +21,15 @@ #include "SerialDisplay.h" /*! - * Defines the application data transmission duty cycle. 5s, value in [us]. + * Defines the application data transmission duty cycle. 5s, value in [ms]. */ -#define APP_TX_DUTYCYCLE 5000000 +#define APP_TX_DUTYCYCLE 5000 /*! * Defines a random delay for application data transmission duty cycle. 1s, * value in [us]. */ -#define APP_TX_DUTYCYCLE_RND 1000000 +#define APP_TX_DUTYCYCLE_RND 1000 /*! * Default datarate @@ -340,7 +340,7 @@ { McpsReq_t mcpsReq; LoRaMacTxInfo_t txInfo; - + if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK ) { // Send empty frame in order to flush MAC commands @@ -605,7 +605,7 @@ AppDataSize = LORAWAN_APP_DATA_SIZE; ComplianceTest.DownLinkCounter = 0; ComplianceTest.Running = false; - + MibRequestConfirm_t mibReq; mibReq.Type = MIB_ADR; mibReq.Param.AdrEnable = LORAWAN_ADR_ON; @@ -645,6 +645,21 @@ { MlmeReq_t mlmeReq; + // Disable TestMode and revert back to normal operation + IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; + AppPort = LORAWAN_APP_PORT; + AppDataSize = LORAWAN_APP_DATA_SIZE; + ComplianceTest.DownLinkCounter = 0; + ComplianceTest.Running = false; + + MibRequestConfirm_t mibReq; + mibReq.Type = MIB_ADR; + mibReq.Param.AdrEnable = LORAWAN_ADR_ON; + LoRaMacMibSetRequestConfirm( &mibReq ); +#if defined( USE_BAND_868 ) + LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); +#endif + mlmeReq.Type = MLME_JOIN; mlmeReq.Req.Join.DevEui = DevEui; @@ -655,6 +670,17 @@ DeviceState = DEVICE_STATE_SLEEP; } break; + case 7: // (x) + { + if( mcpsIndication->BufferSize == 3 ) + { + MlmeReq_t mlmeReq; + mlmeReq.Type = MLME_TXCW; + mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] ); + LoRaMacMlmeRequest( &mlmeReq ); + } + } + break; default: break; } @@ -787,10 +813,10 @@ TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); TimerInit( &Led1Timer, OnLed1TimerEvent ); - TimerSetValue( &Led1Timer, 25000 ); + TimerSetValue( &Led1Timer, 25 ); TimerInit( &Led2Timer, OnLed2TimerEvent ); - TimerSetValue( &Led2Timer, 25000 ); + TimerSetValue( &Led2Timer, 25 ); mibReq.Type = MIB_ADR; mibReq.Param.AdrEnable = LORAWAN_ADR_ON; @@ -883,7 +909,7 @@ if( ComplianceTest.Running == true ) { // Schedule next packet transmission - TxDutyCycleTime = 5000000; // 5000000 us + TxDutyCycleTime = 5000; // 5000 ms } else {