Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LoRaWAN-lib mbed lib_mpl3115a2 lib_mma8451q lib_gps SX1272Lib
Dependents: LoRaWAN-NAMote72-BVS-confirmed-tester-0-7v1_copy
LoRaMacLayerService.cpp
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 (C)2015 Semtech 00008 00009 Description: MAC Layer Services: MLME & MCPS 00010 00011 License: Revised BSD License, see LICENSE.TXT file include in the project 00012 00013 Maintainer: Uttam Bhat 00014 */ 00015 00016 #include "LoRaMacLayerService.h" 00017 #include "SerialDisplay.h" 00018 00019 /*! 00020 * \brief MCPS-Confirm event function 00021 * 00022 * \param [IN] McpsConfirm - Pointer to the confirm structure, 00023 * containing confirm attributes. 00024 */ 00025 void McpsConfirm( McpsConfirm_t *mcpsConfirm ) 00026 { 00027 if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) 00028 { 00029 switch( mcpsConfirm->McpsRequest ) 00030 { 00031 case MCPS_UNCONFIRMED: 00032 { 00033 // Check Datarate 00034 // Check TxPower 00035 break; 00036 } 00037 case MCPS_CONFIRMED: 00038 { 00039 // Check Datarate 00040 // Check TxPower 00041 // Check AckReceived 00042 // Check NbRetries 00043 LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived; 00044 break; 00045 } 00046 case MCPS_PROPRIETARY: 00047 { 00048 break; 00049 } 00050 default: 00051 break; 00052 } 00053 } 00054 00055 LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; 00056 LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; 00057 LoRaMacUplinkStatus.TxPower = mcpsConfirm->TxPower; 00058 LoRaMacUplinkStatus.UpLinkFrequency = mcpsConfirm->UpLinkFrequency; 00059 SerialDisplayTxUpdate( ); 00060 00061 IsTxIntUpdate = true; 00062 NextTx = true; 00063 } 00064 00065 /*! 00066 * \brief MCPS-Indication event function 00067 * 00068 * \param [IN] McpsIndication - Pointer to the indication structure, 00069 * containing indication attributes. 00070 */ 00071 void McpsIndication( McpsIndication_t *mcpsIndication ) 00072 { 00073 Gps.service( ); 00074 00075 if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) 00076 { 00077 return; 00078 } 00079 00080 switch( mcpsIndication->McpsIndication ) 00081 { 00082 case MCPS_UNCONFIRMED: 00083 { 00084 break; 00085 } 00086 case MCPS_CONFIRMED: 00087 { 00088 break; 00089 } 00090 case MCPS_PROPRIETARY: 00091 { 00092 break; 00093 } 00094 case MCPS_MULTICAST: 00095 { 00096 break; 00097 } 00098 default: 00099 break; 00100 } 00101 00102 // Check Multicast 00103 // Check Port 00104 // Check Datarate 00105 // Check FramePending 00106 // Check Buffer 00107 // Check BufferSize 00108 // Check Rssi 00109 // Check Snr 00110 // Check RxSlot 00111 LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi; 00112 if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 00113 { 00114 // Invert and divide by 4 00115 LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2; 00116 LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; 00117 } 00118 else 00119 { 00120 // Divide by 4 00121 LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2; 00122 } 00123 LoRaMacDownlinkStatus.DownlinkCounter++; 00124 LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData; 00125 LoRaMacDownlinkStatus.Port = mcpsIndication->Port; 00126 LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer; 00127 LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize; 00128 LoRaMacDownlinkStatus.RxSlot = mcpsIndication->RxSlot; 00129 00130 if( ComplianceTest.Running == 1 ) 00131 { 00132 ComplianceTest.DownLinkCounter++; 00133 } 00134 00135 if( mcpsIndication->RxData == true ) 00136 { 00137 switch( mcpsIndication->Port ) 00138 { 00139 case 1: // The application LED can be controlled on port 1 or 2 00140 case 2: 00141 break; 00142 case 224: 00143 PrepareComplianceTestFrame( mcpsIndication ); 00144 break; 00145 default: 00146 break; 00147 } 00148 } 00149 00150 IsRxUpdate = true; 00151 } 00152 00153 /*! 00154 * \brief MLME-Confirm event function 00155 * 00156 * \param [IN] MlmeConfirm - Pointer to the confirm structure, 00157 * containing confirm attributes. 00158 */ 00159 void MlmeConfirm( MlmeConfirm_t *MlmeConfirm ) 00160 { 00161 MibRequestConfirm_t mibGet; 00162 00163 // Debug for join not alternating between DR0/DR4 00164 if( MlmeConfirm->MlmeRequest == MLME_JOIN ) 00165 { 00166 mibGet.Type = MIB_CHANNELS_DATARATE; 00167 LoRaMacMibGetRequestConfirm( &mibGet ); 00168 SerialDisplayJoinDataRateUpdate( mibGet.Param.ChannelsDatarate ); 00169 LoRaMacJoinStatus.LastDatarate = mibGet.Param.ChannelsDatarate; 00170 } 00171 00172 if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) 00173 { 00174 switch( MlmeConfirm->MlmeRequest ) 00175 { 00176 case MLME_JOIN: 00177 { 00178 // Status is OK, node has joined the network 00179 IsNetworkJoinedStatusUpdate = true; 00180 DeviceState = DEVICE_STATE_SEND; 00181 break; 00182 } 00183 case MLME_LINK_CHECK: 00184 { 00185 // Check DemodMargin 00186 // Check NbGateways 00187 if( ComplianceTest.Running == true ) 00188 { 00189 ComplianceTest.LinkCheck = true; 00190 ComplianceTest.DemodMargin = MlmeConfirm->DemodMargin; 00191 ComplianceTest.NbGateways = MlmeConfirm->NbGateways; 00192 } 00193 break; 00194 } 00195 default: 00196 break; 00197 } 00198 } 00199 00200 NextTx = true; 00201 }
Generated on Fri Jul 15 2022 22:53:35 by
1.7.2