Damian Gabino / LoRaWAN-lib

Fork of LoRaWAN-lib-v1_0_1 by Uttam Bhat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LoRaMacLayerService.cpp Source File

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         if( McpsConfirm->McpsRequest==MCPS_CONFIRMED  )
00029         {     
00030             LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived;
00031         }        
00032     }
00033 
00034     LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate;
00035     LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter;
00036     LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower;
00037 
00038     IsTxIntUpdate = true;
00039 }
00040 
00041 /*!
00042  * \brief   MCPS-Indication event function
00043  *
00044  * \param   [IN] McpsIndication - Pointer to the indication structure,
00045  *               containing indication attributes.
00046  */
00047 void McpsIndication( McpsIndication_t  *McpsIndication )
00048 {
00049     uint8_t port;
00050 
00051     if( McpsIndication->Status  != LORAMAC_EVENT_INFO_STATUS_OK  )
00052     {
00053         return;
00054     }
00055 
00056     switch( McpsIndication->McpsIndication  )
00057     {
00058         case MCPS_UNCONFIRMED :
00059         {
00060             break;
00061         }
00062         case MCPS_CONFIRMED :
00063         {
00064             break;
00065         }
00066         case MCPS_PROPRIETARY :
00067         {
00068             break;
00069         }
00070         case MCPS_MULTICAST :
00071         {
00072             break;
00073         }
00074         default:
00075             break;
00076     }
00077 
00078     // Check Multicast
00079     // Check Port
00080     // Check Datarate
00081     // Check FramePending
00082     // Check Buffer
00083     // Check BufferSize
00084     // Check Rssi
00085     // Check Snr
00086     // Check RxSlot
00087     LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi ;
00088     if( McpsIndication->Snr  & 0x80 ) // The SNR sign bit is 1
00089     {
00090         // Invert and divide by 4
00091         LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr  + 1 ) & 0xFF ) >> 2;
00092         LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr;
00093     }
00094     else
00095     {
00096         // Divide by 4
00097         LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr  & 0xFF ) >> 2;
00098     }
00099     LoRaMacDownlinkStatus.DownlinkCounter++;
00100     LoRaMacDownlinkStatus.RxData = McpsIndication->RxData ;      
00101     LoRaMacDownlinkStatus.Port = McpsIndication->Port ;
00102     LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer ;
00103     LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize ;
00104     LoRaMacDownlinkStatus.RxSlot = McpsIndication->RxSlot ;
00105 
00106  
00107     
00108     if( McpsIndication->RxData  == true )
00109     {
00110         switch( port )
00111         {
00112         case 1: // The application LED can be controlled on port 1 or 2
00113         case 2:            
00114             break;
00115         default:
00116             break;
00117         }
00118     }
00119 
00120     IsRxUpdate = true;
00121 
00122 }
00123 
00124 /*!
00125  * \brief   MLME-Confirm event function
00126  *
00127  * \param   [IN] MlmeConfirm - Pointer to the confirm structure,
00128  *               containing confirm attributes.
00129  */
00130 void MlmeConfirm( MlmeConfirm_t  *MlmeConfirm )
00131 {
00132     if( MlmeConfirm->Status  == LORAMAC_EVENT_INFO_STATUS_OK  )
00133     {
00134         if( MlmeConfirm->MlmeRequest ==MLME_JOIN  )
00135         {
00136             IsNetworkJoinedStatusUpdate = true;
00137         }
00138  
00139     }
00140 
00141     // Schedule next packet transmission
00142     TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE );
00143     TimerStart( &TxNextPacketTimer );
00144 
00145     DeviceState = DEVICE_STATE_SLEEP;
00146 }