Hex-current-measurements
Dependencies: mbed LoRaWAN-lib SX1276Lib
Diff: app/main.cpp
- Revision:
- 7:3173f0508a98
- Parent:
- 5:1e9f6a365854
- Child:
- 9:ee9dcbb9708d
diff -r a48936885eac -r 3173f0508a98 app/main.cpp --- a/app/main.cpp Wed May 18 11:34:12 2016 +0000 +++ b/app/main.cpp Tue Jul 05 15:01:57 2016 +0000 @@ -21,11 +21,6 @@ #include "SerialDisplay.h" /*! - * Join requests trials duty cycle. - */ -#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE 10000000 // 10 [s] value in us - -/*! * Defines the application data transmission duty cycle. 5s, value in [us]. */ #define APP_TX_DUTYCYCLE 5000000 @@ -96,13 +91,11 @@ #endif -#if( OVER_THE_AIR_ACTIVATION != 0 ) - static uint8_t DevEui[] = LORAWAN_DEVICE_EUI; static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI; static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY; -#else +#if( OVER_THE_AIR_ACTIVATION == 0 ) static uint8_t NwkSKey[] = LORAWAN_NWKSKEY; static uint8_t AppSKey[] = LORAWAN_APPSKEY; @@ -251,11 +244,10 @@ SerialDisplayUpdateDevAddr( DevAddr ); SerialDisplayUpdateKey( 12, NwkSKey ); SerialDisplayUpdateKey( 13, AppSKey ); -#else +#endif SerialDisplayUpdateEui( 5, DevEui ); SerialDisplayUpdateEui( 6, AppEui ); SerialDisplayUpdateKey( 7, AppKey ); -#endif mibReq.Type = MIB_NETWORK_JOINED; LoRaMacMibGetRequestConfirm( &mibReq ); @@ -483,6 +475,11 @@ LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; + // Switch LED 1 ON + Led1State = true; + Led1StateChanged = true; + TimerStart( &Led1Timer ); + UplinkStatusUpdated = true; } NextTx = true; @@ -644,6 +641,20 @@ LoRaMacMlmeRequest( &mlmeReq ); } break; + case 6: // (ix) + { + MlmeReq_t mlmeReq; + + mlmeReq.Type = MLME_JOIN; + + mlmeReq.Req.Join.DevEui = DevEui; + mlmeReq.Req.Join.AppEui = AppEui; + mlmeReq.Req.Join.AppKey = AppKey; + + LoRaMacMlmeRequest( &mlmeReq ); + DeviceState = DEVICE_STATE_SLEEP; + } + break; default: break; } @@ -677,6 +688,8 @@ { // Status is OK, node has joined the network IsNetworkJoinedStatusUpdate = true; + DeviceState = DEVICE_STATE_SEND; + NextTx = true; break; } case MLME_LINK_CHECK: @@ -711,6 +724,17 @@ BoardInit( ); SerialDisplayInit( ); + SerialDisplayUpdateEui( 5, DevEui ); + SerialDisplayUpdateEui( 6, AppEui ); + SerialDisplayUpdateKey( 7, AppKey ); + +#if( OVER_THE_AIR_ACTIVATION == 0 ) + SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); + SerialDisplayUpdateDevAddr( DevAddr ); + SerialDisplayUpdateKey( 12, NwkSKey ); + SerialDisplayUpdateKey( 13, AppSKey ); +#endif + DeviceState = DEVICE_STATE_INIT; while( 1 ) @@ -788,6 +812,10 @@ LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 ); LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 ); LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 ); + + mibReq.Type = MIB_RX2_CHANNEL; + mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; + LoRaMacMibSetRequestConfirm( &mibReq ); #endif #endif @@ -815,15 +843,7 @@ { LoRaMacMlmeRequest( &mlmeReq ); } - - SerialDisplayUpdateEui( 5, DevEui ); - SerialDisplayUpdateEui( 6, AppEui ); - SerialDisplayUpdateKey( 7, AppKey ); - - // Schedule next packet transmission - TxDutyCycleTime = OVER_THE_AIR_ACTIVATION_DUTYCYCLE; - DeviceState = DEVICE_STATE_CYCLE; - + DeviceState = DEVICE_STATE_SLEEP; #else mibReq.Type = MIB_NET_ID; mibReq.Param.NetID = LORAWAN_NETWORK_ID; @@ -845,11 +865,6 @@ mibReq.Param.IsNetworkJoined = true; LoRaMacMibSetRequestConfirm( &mibReq ); - SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); - SerialDisplayUpdateDevAddr( DevAddr ); - SerialDisplayUpdateKey( 12, NwkSKey ); - SerialDisplayUpdateKey( 13, AppSKey ); - DeviceState = DEVICE_STATE_SEND; #endif IsNetworkJoinedStatusUpdate = true; @@ -864,11 +879,6 @@ PrepareTxFrame( AppPort ); NextTx = SendFrame( ); - - // Switch LED 1 ON - Led1State = true; - Led1StateChanged = true; - TimerStart( &Led1Timer ); } if( ComplianceTest.Running == true ) {