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: X_NUCLEO_IKS01A2 driver_mbed_TH02 mbed LoRaWAN-lib-v1_0_1 SX1272Lib
Fork of Training-Aug2018-SX1272-X-NUCLEO-IKS01A2 by
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 00018 /*! 00019 * \brief MCPS-Confirm event function 00020 * 00021 * \param [IN] McpsConfirm - Pointer to the confirm structure, 00022 * containing confirm attributes. 00023 */ 00024 void McpsConfirm( McpsConfirm_t *McpsConfirm ) 00025 { 00026 if( McpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) 00027 { 00028 switch( McpsConfirm->McpsRequest ) 00029 { 00030 case MCPS_UNCONFIRMED: 00031 { 00032 // Check Datarate 00033 // Check TxPower 00034 break; 00035 } 00036 case MCPS_CONFIRMED: 00037 { 00038 // Check Datarate 00039 // Check TxPower 00040 // Check AckReceived 00041 // Check NbRetries 00042 LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived; 00043 break; 00044 } 00045 case MCPS_PROPRIETARY: 00046 { 00047 break; 00048 } 00049 default: 00050 break; 00051 } 00052 } 00053 00054 LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate; 00055 LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter; 00056 LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower; 00057 00058 IsTxIntUpdate = true; 00059 } 00060 00061 /*! 00062 * \brief MCPS-Indication event function 00063 * 00064 * \param [IN] McpsIndication - Pointer to the indication structure, 00065 * containing indication attributes. 00066 */ 00067 void McpsIndication( McpsIndication_t *McpsIndication ) 00068 { 00069 uint8_t port; 00070 00071 if( McpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) 00072 { 00073 return; 00074 } 00075 00076 switch( McpsIndication->McpsIndication ) 00077 { 00078 case MCPS_UNCONFIRMED: 00079 { 00080 break; 00081 } 00082 case MCPS_CONFIRMED: 00083 { 00084 break; 00085 } 00086 case MCPS_PROPRIETARY: 00087 { 00088 break; 00089 } 00090 case MCPS_MULTICAST: 00091 { 00092 break; 00093 } 00094 default: 00095 break; 00096 } 00097 00098 // Check Multicast 00099 // Check Port 00100 // Check Datarate 00101 // Check FramePending 00102 // Check Buffer 00103 // Check BufferSize 00104 // Check Rssi 00105 // Check Snr 00106 // Check RxSlot 00107 LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi; 00108 if( McpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 00109 { 00110 // Invert and divide by 4 00111 LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr + 1 ) & 0xFF ) >> 2; 00112 LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; 00113 } 00114 else 00115 { 00116 // Divide by 4 00117 LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr & 0xFF ) >> 2; 00118 } 00119 LoRaMacDownlinkStatus.DownlinkCounter++; 00120 LoRaMacDownlinkStatus.RxData = McpsIndication->RxData; 00121 LoRaMacDownlinkStatus.Port = McpsIndication->Port; 00122 LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer; 00123 LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize; 00124 LoRaMacDownlinkStatus.RxSlot = McpsIndication->RxSlot; 00125 00126 if( ComplianceTest.Running == 1 ) 00127 { 00128 port = 224; 00129 ComplianceTest.DownLinkCounter++; 00130 } 00131 else 00132 { 00133 port = McpsIndication->Port; 00134 } 00135 00136 if( McpsIndication->RxData == true ) 00137 { 00138 switch( port ) 00139 { 00140 case 1: // The application LED can be controlled on port 1 or 2 00141 case 2: 00142 break; 00143 case 224: 00144 PrepareComplianceTestFrame( McpsIndication ); 00145 break; 00146 default: 00147 break; 00148 } 00149 } 00150 00151 IsRxUpdate = true; 00152 00153 } 00154 00155 /*! 00156 * \brief MLME-Confirm event function 00157 * 00158 * \param [IN] MlmeConfirm - Pointer to the confirm structure, 00159 * containing confirm attributes. 00160 */ 00161 void MlmeConfirm( MlmeConfirm_t *MlmeConfirm ) 00162 { 00163 if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) 00164 { 00165 switch( MlmeConfirm->MlmeRequest ) 00166 { 00167 case MLME_JOIN: 00168 { 00169 // Status is OK, node has joined the network 00170 IsNetworkJoinedStatusUpdate = true; 00171 break; 00172 } 00173 case MLME_LINK_CHECK: 00174 { 00175 // Check DemodMargin 00176 // Check NbGateways 00177 if( ComplianceTest.Running == true ) 00178 { 00179 ComplianceTest.LinkCheck = true; 00180 ComplianceTest.DemodMargin = MlmeConfirm->DemodMargin; 00181 ComplianceTest.NbGateways = MlmeConfirm->NbGateways; 00182 } 00183 break; 00184 } 00185 default: 00186 break; 00187 } 00188 } 00189 00190 // Schedule next packet transmission 00191 TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE ); 00192 TimerStart( &TxNextPacketTimer ); 00193 00194 DeviceState = DEVICE_STATE_SLEEP; 00195 }
Generated on Tue Jul 12 2022 20:36:27 by
1.7.2
