mQ Branch for NA mote testing
Dependencies: LoRaWAN-lib SX1272Lib-mQ lib_gps lib_mma8451q lib_mpl3115a2 mbed
Fork of LoRaWAN-NAMote72-Application-Demo by
Diff: app/LoRaMacLayerService.cpp
- Revision:
- 18:18408c3c2d0c
- Parent:
- 5:6ffeac53b7cb
--- a/app/LoRaMacLayerService.cpp Sun Apr 16 23:12:47 2017 +0000 +++ b/app/LoRaMacLayerService.cpp Mon Apr 24 13:47:27 2017 +0000 @@ -14,6 +14,7 @@ */ #include "LoRaMacLayerService.h" +#include "SerialDisplay.h" /*! * \brief MCPS-Confirm event function @@ -21,11 +22,11 @@ * \param [IN] McpsConfirm - Pointer to the confirm structure, * containing confirm attributes. */ -void McpsConfirm( McpsConfirm_t *McpsConfirm ) +void McpsConfirm( McpsConfirm_t *mcpsConfirm ) { - if( McpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) + if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) { - switch( McpsConfirm->McpsRequest ) + switch( mcpsConfirm->McpsRequest ) { case MCPS_UNCONFIRMED: { @@ -39,7 +40,7 @@ // Check TxPower // Check AckReceived // Check NbRetries - LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived; + LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived; break; } case MCPS_PROPRIETARY: @@ -51,11 +52,14 @@ } } - LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate; - LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter; - LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower; + LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; + LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; + LoRaMacUplinkStatus.TxPower = mcpsConfirm->TxPower; + LoRaMacUplinkStatus.UpLinkFrequency = mcpsConfirm->UpLinkFrequency; + SerialDisplayTxUpdate( ); IsTxIntUpdate = true; + NextTx = true; } /*! @@ -64,18 +68,16 @@ * \param [IN] McpsIndication - Pointer to the indication structure, * containing indication attributes. */ -void McpsIndication( McpsIndication_t *McpsIndication ) +void McpsIndication( McpsIndication_t *mcpsIndication ) { - uint8_t port; - Gps.service( ); - if( McpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) + if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) { return; } - switch( McpsIndication->McpsIndication ) + switch( mcpsIndication->McpsIndication ) { case MCPS_UNCONFIRMED: { @@ -106,44 +108,39 @@ // Check Rssi // Check Snr // Check RxSlot - LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi; - if( McpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 + LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi; + if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 { // Invert and divide by 4 - LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr + 1 ) & 0xFF ) >> 2; + LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2; LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; } else { // Divide by 4 - LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr & 0xFF ) >> 2; + LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2; } LoRaMacDownlinkStatus.DownlinkCounter++; - LoRaMacDownlinkStatus.RxData = McpsIndication->RxData; - LoRaMacDownlinkStatus.Port = McpsIndication->Port; - LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer; - LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize; - LoRaMacDownlinkStatus.RxSlot = McpsIndication->RxSlot; + LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData; + LoRaMacDownlinkStatus.Port = mcpsIndication->Port; + LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer; + LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize; + LoRaMacDownlinkStatus.RxSlot = mcpsIndication->RxSlot; if( ComplianceTest.Running == 1 ) { - port = 224; ComplianceTest.DownLinkCounter++; } - else + + if( mcpsIndication->RxData == true ) { - port = McpsIndication->Port; - } - - if( McpsIndication->RxData == true ) - { - switch( port ) + switch( mcpsIndication->Port ) { case 1: // The application LED can be controlled on port 1 or 2 - case 2: + case 2: break; case 224: - PrepareComplianceTestFrame( McpsIndication ); + PrepareComplianceTestFrame( mcpsIndication ); break; default: break; @@ -151,7 +148,6 @@ } IsRxUpdate = true; - } /*! @@ -162,6 +158,17 @@ */ void MlmeConfirm( MlmeConfirm_t *MlmeConfirm ) { + MibRequestConfirm_t mibGet; + + // Debug for join not alternating between DR0/DR4 + if( MlmeConfirm->MlmeRequest == MLME_JOIN ) + { + mibGet.Type = MIB_CHANNELS_DATARATE; + LoRaMacMibGetRequestConfirm( &mibGet ); + SerialDisplayJoinDataRateUpdate( mibGet.Param.ChannelsDatarate ); + LoRaMacJoinStatus.LastDatarate = mibGet.Param.ChannelsDatarate; + } + if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) { switch( MlmeConfirm->MlmeRequest ) @@ -170,6 +177,7 @@ { // Status is OK, node has joined the network IsNetworkJoinedStatusUpdate = true; + DeviceState = DEVICE_STATE_SEND; break; } case MLME_LINK_CHECK: @@ -189,9 +197,5 @@ } } - // Schedule next packet transmission - TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE ); - TimerStart( &TxNextPacketTimer ); - - DeviceState = DEVICE_STATE_SLEEP; -} \ No newline at end of file + NextTx = true; +}