Simplified LoRaWAN library.
Fork of LoRaWAN-lib-v1_0_1 by
LoRaMacLayerService.cpp@12:54937781831b, 2018-04-03 (annotated)
- Committer:
- dgabino
- Date:
- Tue Apr 03 17:01:27 2018 +0000
- Revision:
- 12:54937781831b
Substituted api-v3 with MAC layer service
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dgabino | 12:54937781831b | 1 | /* |
dgabino | 12:54937781831b | 2 | / _____) _ | | |
dgabino | 12:54937781831b | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
dgabino | 12:54937781831b | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
dgabino | 12:54937781831b | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
dgabino | 12:54937781831b | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
dgabino | 12:54937781831b | 7 | (C)2015 Semtech |
dgabino | 12:54937781831b | 8 | |
dgabino | 12:54937781831b | 9 | Description: MAC Layer Services: MLME & MCPS |
dgabino | 12:54937781831b | 10 | |
dgabino | 12:54937781831b | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
dgabino | 12:54937781831b | 12 | |
dgabino | 12:54937781831b | 13 | Maintainer: Uttam Bhat |
dgabino | 12:54937781831b | 14 | */ |
dgabino | 12:54937781831b | 15 | |
dgabino | 12:54937781831b | 16 | #include "LoRaMacLayerService.h" |
dgabino | 12:54937781831b | 17 | |
dgabino | 12:54937781831b | 18 | /*! |
dgabino | 12:54937781831b | 19 | * \brief MCPS-Confirm event function |
dgabino | 12:54937781831b | 20 | * |
dgabino | 12:54937781831b | 21 | * \param [IN] McpsConfirm - Pointer to the confirm structure, |
dgabino | 12:54937781831b | 22 | * containing confirm attributes. |
dgabino | 12:54937781831b | 23 | */ |
dgabino | 12:54937781831b | 24 | void McpsConfirm( McpsConfirm_t *McpsConfirm ) |
dgabino | 12:54937781831b | 25 | { |
dgabino | 12:54937781831b | 26 | if( McpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
dgabino | 12:54937781831b | 27 | { |
dgabino | 12:54937781831b | 28 | if( McpsConfirm->McpsRequest==MCPS_CONFIRMED ) |
dgabino | 12:54937781831b | 29 | { |
dgabino | 12:54937781831b | 30 | LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived; |
dgabino | 12:54937781831b | 31 | } |
dgabino | 12:54937781831b | 32 | } |
dgabino | 12:54937781831b | 33 | |
dgabino | 12:54937781831b | 34 | LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate; |
dgabino | 12:54937781831b | 35 | LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter; |
dgabino | 12:54937781831b | 36 | LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower; |
dgabino | 12:54937781831b | 37 | |
dgabino | 12:54937781831b | 38 | IsTxIntUpdate = true; |
dgabino | 12:54937781831b | 39 | } |
dgabino | 12:54937781831b | 40 | |
dgabino | 12:54937781831b | 41 | /*! |
dgabino | 12:54937781831b | 42 | * \brief MCPS-Indication event function |
dgabino | 12:54937781831b | 43 | * |
dgabino | 12:54937781831b | 44 | * \param [IN] McpsIndication - Pointer to the indication structure, |
dgabino | 12:54937781831b | 45 | * containing indication attributes. |
dgabino | 12:54937781831b | 46 | */ |
dgabino | 12:54937781831b | 47 | void McpsIndication( McpsIndication_t *McpsIndication ) |
dgabino | 12:54937781831b | 48 | { |
dgabino | 12:54937781831b | 49 | uint8_t port; |
dgabino | 12:54937781831b | 50 | |
dgabino | 12:54937781831b | 51 | if( McpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) |
dgabino | 12:54937781831b | 52 | { |
dgabino | 12:54937781831b | 53 | return; |
dgabino | 12:54937781831b | 54 | } |
dgabino | 12:54937781831b | 55 | |
dgabino | 12:54937781831b | 56 | switch( McpsIndication->McpsIndication ) |
dgabino | 12:54937781831b | 57 | { |
dgabino | 12:54937781831b | 58 | case MCPS_UNCONFIRMED: |
dgabino | 12:54937781831b | 59 | { |
dgabino | 12:54937781831b | 60 | break; |
dgabino | 12:54937781831b | 61 | } |
dgabino | 12:54937781831b | 62 | case MCPS_CONFIRMED: |
dgabino | 12:54937781831b | 63 | { |
dgabino | 12:54937781831b | 64 | break; |
dgabino | 12:54937781831b | 65 | } |
dgabino | 12:54937781831b | 66 | case MCPS_PROPRIETARY: |
dgabino | 12:54937781831b | 67 | { |
dgabino | 12:54937781831b | 68 | break; |
dgabino | 12:54937781831b | 69 | } |
dgabino | 12:54937781831b | 70 | case MCPS_MULTICAST: |
dgabino | 12:54937781831b | 71 | { |
dgabino | 12:54937781831b | 72 | break; |
dgabino | 12:54937781831b | 73 | } |
dgabino | 12:54937781831b | 74 | default: |
dgabino | 12:54937781831b | 75 | break; |
dgabino | 12:54937781831b | 76 | } |
dgabino | 12:54937781831b | 77 | |
dgabino | 12:54937781831b | 78 | // Check Multicast |
dgabino | 12:54937781831b | 79 | // Check Port |
dgabino | 12:54937781831b | 80 | // Check Datarate |
dgabino | 12:54937781831b | 81 | // Check FramePending |
dgabino | 12:54937781831b | 82 | // Check Buffer |
dgabino | 12:54937781831b | 83 | // Check BufferSize |
dgabino | 12:54937781831b | 84 | // Check Rssi |
dgabino | 12:54937781831b | 85 | // Check Snr |
dgabino | 12:54937781831b | 86 | // Check RxSlot |
dgabino | 12:54937781831b | 87 | LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi; |
dgabino | 12:54937781831b | 88 | if( McpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 |
dgabino | 12:54937781831b | 89 | { |
dgabino | 12:54937781831b | 90 | // Invert and divide by 4 |
dgabino | 12:54937781831b | 91 | LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr + 1 ) & 0xFF ) >> 2; |
dgabino | 12:54937781831b | 92 | LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; |
dgabino | 12:54937781831b | 93 | } |
dgabino | 12:54937781831b | 94 | else |
dgabino | 12:54937781831b | 95 | { |
dgabino | 12:54937781831b | 96 | // Divide by 4 |
dgabino | 12:54937781831b | 97 | LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr & 0xFF ) >> 2; |
dgabino | 12:54937781831b | 98 | } |
dgabino | 12:54937781831b | 99 | LoRaMacDownlinkStatus.DownlinkCounter++; |
dgabino | 12:54937781831b | 100 | LoRaMacDownlinkStatus.RxData = McpsIndication->RxData; |
dgabino | 12:54937781831b | 101 | LoRaMacDownlinkStatus.Port = McpsIndication->Port; |
dgabino | 12:54937781831b | 102 | LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer; |
dgabino | 12:54937781831b | 103 | LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize; |
dgabino | 12:54937781831b | 104 | LoRaMacDownlinkStatus.RxSlot = McpsIndication->RxSlot; |
dgabino | 12:54937781831b | 105 | |
dgabino | 12:54937781831b | 106 | |
dgabino | 12:54937781831b | 107 | |
dgabino | 12:54937781831b | 108 | if( McpsIndication->RxData == true ) |
dgabino | 12:54937781831b | 109 | { |
dgabino | 12:54937781831b | 110 | switch( port ) |
dgabino | 12:54937781831b | 111 | { |
dgabino | 12:54937781831b | 112 | case 1: // The application LED can be controlled on port 1 or 2 |
dgabino | 12:54937781831b | 113 | case 2: |
dgabino | 12:54937781831b | 114 | break; |
dgabino | 12:54937781831b | 115 | default: |
dgabino | 12:54937781831b | 116 | break; |
dgabino | 12:54937781831b | 117 | } |
dgabino | 12:54937781831b | 118 | } |
dgabino | 12:54937781831b | 119 | |
dgabino | 12:54937781831b | 120 | IsRxUpdate = true; |
dgabino | 12:54937781831b | 121 | |
dgabino | 12:54937781831b | 122 | } |
dgabino | 12:54937781831b | 123 | |
dgabino | 12:54937781831b | 124 | /*! |
dgabino | 12:54937781831b | 125 | * \brief MLME-Confirm event function |
dgabino | 12:54937781831b | 126 | * |
dgabino | 12:54937781831b | 127 | * \param [IN] MlmeConfirm - Pointer to the confirm structure, |
dgabino | 12:54937781831b | 128 | * containing confirm attributes. |
dgabino | 12:54937781831b | 129 | */ |
dgabino | 12:54937781831b | 130 | void MlmeConfirm( MlmeConfirm_t *MlmeConfirm ) |
dgabino | 12:54937781831b | 131 | { |
dgabino | 12:54937781831b | 132 | if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
dgabino | 12:54937781831b | 133 | { |
dgabino | 12:54937781831b | 134 | if( MlmeConfirm->MlmeRequest==MLME_JOIN ) |
dgabino | 12:54937781831b | 135 | { |
dgabino | 12:54937781831b | 136 | IsNetworkJoinedStatusUpdate = true; |
dgabino | 12:54937781831b | 137 | } |
dgabino | 12:54937781831b | 138 | |
dgabino | 12:54937781831b | 139 | } |
dgabino | 12:54937781831b | 140 | |
dgabino | 12:54937781831b | 141 | // Schedule next packet transmission |
dgabino | 12:54937781831b | 142 | TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE ); |
dgabino | 12:54937781831b | 143 | TimerStart( &TxNextPacketTimer ); |
dgabino | 12:54937781831b | 144 | |
dgabino | 12:54937781831b | 145 | DeviceState = DEVICE_STATE_SLEEP; |
dgabino | 12:54937781831b | 146 | } |