1
Dependencies: X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed
Diff: app/LoRaDeviceStateProc.cpp
- Revision:
- 6:711a4e008afa
- Parent:
- 0:42863a11464a
- Child:
- 7:730764a067dc
--- a/app/LoRaDeviceStateProc.cpp Sun Nov 26 03:26:34 2017 +0000 +++ b/app/LoRaDeviceStateProc.cpp Tue Nov 28 08:20:09 2017 +0000 @@ -30,10 +30,14 @@ MlmeReq_t mlmeReq; +uint16_t ChannelMaskTemp[6] = {0}; + +static bool DutyCycleFlag = false; /*! * \brief Function executed on TxNextPacket Timeout event */ + static void OnTxNextPacketTimerEvent( void ) { MibRequestConfirm_t mibReq; @@ -48,7 +52,14 @@ { if( mibReq.Param.IsNetworkJoined == true ) { - DeviceState = DEVICE_STATE_SEND; + DeviceState = DEVICE_STATE_SEND; + + if( DutyCycleFlag == false) + { + IsDutyCycleUpdate = true; + + DutyCycleFlag = true; + } } else { @@ -58,6 +69,25 @@ } } +/*! + * \brief Function executed on Duty Cycle Timeout event + */ +static void OnDutyCycleEvent( void ) +{ + TimerStop( &TxDutyCycleTimer ); + + IsDutyCycleUpdate = true; + + DutyCycleCntr++; + + if( DutyCycleCntr >= (2 * APP_TX_DUTYCYCLE_HOUR ) ) + { + DutyCycleIndx++; + + DutyCycleCntr = 0; + } +} + void DeviceInit( void ) { LoRaPrimitives.MacMcpsConfirm = McpsConfirm; @@ -68,6 +98,8 @@ TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); + TimerInit( &TxDutyCycleTimer, OnDutyCycleEvent ); + LoRaMibReq.Type = MIB_ADR; LoRaMibReq.Param.AdrEnable = LORAWAN_ADR_ON; LoRaMacMibSetRequestConfirm( &LoRaMibReq ); @@ -80,6 +112,86 @@ LoRaMibReq.Param.ChannelsTxPower = LORAWAN_TX_POWER; LoRaMacMibSetRequestConfirm( &LoRaMibReq ); + LoRaMibReq.Type = MIB_CHANNELS_MASK; + LoRaMibReq.Param.ChannelsMask = ChannelMaskTemp; + +#ifdef USE_BAND_915_HYBRID_BLOCK_A + + ChannelMaskTemp[0] = 0x00FF; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0001; + +#elif defined USE_BAND_915_HYBRID_BLOCK_B + + ChannelMaskTemp[0] = 0xFF00; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0002; + +#elif defined USE_BAND_915_HYBRID_BLOCK_C + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0x00FF; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0004; + +#elif defined USE_BAND_915_HYBRID_BLOCK_D + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0xFF00; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0008; + +#elif defined USE_BAND_915_HYBRID_BLOCK_E + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0x00FF; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0010; + +#elif defined USE_BAND_915_HYBRID_BLOCK_F + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0xFF00; + ChannelMaskTemp[3] = 0x0000; + ChannelMaskTemp[4] = 0x0020; + +#elif defined USE_BAND_915_HYBRID_BLOCK_G + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0x00FF; + ChannelMaskTemp[4] = 0x0040; + +#elif defined USE_BAND_915_HYBRID_BLOCK_H + + ChannelMaskTemp[0] = 0x0000; + ChannelMaskTemp[1] = 0x0000; + ChannelMaskTemp[2] = 0x0000; + ChannelMaskTemp[3] = 0xFF00; + ChannelMaskTemp[4] = 0x0080; + +#elif defined USE_BAND_915 + + ChannelMaskTemp[0] = 0xFFFF; + ChannelMaskTemp[1] = 0xFFFF; + ChannelMaskTemp[2] = 0xFFFF; + ChannelMaskTemp[3] = 0xFFFF; + ChannelMaskTemp[4] = 0x00FF; + ChannelMaskTemp[5] = 0x0000; + +#endif + + LoRaMacMibSetRequestConfirm( &LoRaMibReq ); + LoRaMacDownlinkStatus.DownlinkCounter = 0; } @@ -222,4 +334,4 @@ return false; } return true; -} \ No newline at end of file +}