Simplified LoRaWAN library.
Fork of LoRaWAN-lib-v1_0_1 by
LoRaMac-api-v3.cpp@11:58f66381eb7c, 2017-11-10 (annotated)
- Committer:
- ubhat
- Date:
- Fri Nov 10 09:22:15 2017 +0000
- Revision:
- 11:58f66381eb7c
- Parent:
- 4:37c12dbc8dc7
Fix channel mask reset issue
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 2:14a5d6ad92d5 | 1 | /* |
mluis | 2:14a5d6ad92d5 | 2 | / _____) _ | | |
mluis | 2:14a5d6ad92d5 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 2:14a5d6ad92d5 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 2:14a5d6ad92d5 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 2:14a5d6ad92d5 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 2:14a5d6ad92d5 | 7 | (C)2013 Semtech |
mluis | 2:14a5d6ad92d5 | 8 | ___ _____ _ ___ _ _____ ___ ___ ___ ___ |
mluis | 2:14a5d6ad92d5 | 9 | / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| |
mluis | 2:14a5d6ad92d5 | 10 | \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| |
mluis | 2:14a5d6ad92d5 | 11 | |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| |
mluis | 2:14a5d6ad92d5 | 12 | embedded.connectivity.solutions=============== |
mluis | 2:14a5d6ad92d5 | 13 | |
mluis | 2:14a5d6ad92d5 | 14 | Description: LoRa MAC layer implementation |
mluis | 2:14a5d6ad92d5 | 15 | |
mluis | 2:14a5d6ad92d5 | 16 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 2:14a5d6ad92d5 | 17 | |
mluis | 2:14a5d6ad92d5 | 18 | Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE ) |
mluis | 2:14a5d6ad92d5 | 19 | */ |
mluis | 2:14a5d6ad92d5 | 20 | #include "board.h" |
mluis | 2:14a5d6ad92d5 | 21 | |
mluis | 2:14a5d6ad92d5 | 22 | #include "LoRaMac-api-v3.h" |
mluis | 2:14a5d6ad92d5 | 23 | #include "LoRaMacTest.h" |
mluis | 2:14a5d6ad92d5 | 24 | |
mluis | 2:14a5d6ad92d5 | 25 | /*! |
mluis | 2:14a5d6ad92d5 | 26 | * Extern function declarations. |
mluis | 2:14a5d6ad92d5 | 27 | */ |
mluis | 2:14a5d6ad92d5 | 28 | extern LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort, |
mluis | 2:14a5d6ad92d5 | 29 | void *fBuffer, uint16_t fBufferSize ); |
mluis | 2:14a5d6ad92d5 | 30 | extern LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, |
mluis | 2:14a5d6ad92d5 | 31 | uint8_t fPort, void *fBuffer, uint16_t fBufferSize ); |
mluis | 2:14a5d6ad92d5 | 32 | extern LoRaMacStatus_t SendFrameOnChannel( ChannelParams_t channel ); |
mluis | 2:14a5d6ad92d5 | 33 | extern uint32_t LoRaMacState; |
mluis | 2:14a5d6ad92d5 | 34 | extern LoRaMacFlags_t LoRaMacFlags; |
mluis | 2:14a5d6ad92d5 | 35 | |
mluis | 2:14a5d6ad92d5 | 36 | /*! |
mluis | 2:14a5d6ad92d5 | 37 | * Static variables |
mluis | 2:14a5d6ad92d5 | 38 | */ |
mluis | 2:14a5d6ad92d5 | 39 | static LoRaMacEventFlags_t LoRaMacEventFlags; |
mluis | 2:14a5d6ad92d5 | 40 | static LoRaMacEventInfo_t LoRaMacEventInfo; |
mluis | 2:14a5d6ad92d5 | 41 | static LoRaMacPrimitives_t LoRaMacPrimitives; |
mluis | 2:14a5d6ad92d5 | 42 | static LoRaMacCallback_t LoRaMacCallback; |
mluis | 2:14a5d6ad92d5 | 43 | static LoRaMacCallbacks_t LoRaMacCallbacks; |
mluis | 2:14a5d6ad92d5 | 44 | |
mluis | 2:14a5d6ad92d5 | 45 | /*! |
mluis | 2:14a5d6ad92d5 | 46 | * \brief MCPS-Confirm event function |
mluis | 2:14a5d6ad92d5 | 47 | * |
mluis | 2:14a5d6ad92d5 | 48 | * \param [IN] mcpsConfirm - Pointer to the confirm structure, |
mluis | 2:14a5d6ad92d5 | 49 | * containing confirm attributes. |
mluis | 2:14a5d6ad92d5 | 50 | */ |
mluis | 2:14a5d6ad92d5 | 51 | static void McpsConfirm( McpsConfirm_t *mcpsConfirm ) |
mluis | 2:14a5d6ad92d5 | 52 | { |
mluis | 2:14a5d6ad92d5 | 53 | LoRaMacEventInfo.Status = mcpsConfirm->Status; |
mluis | 2:14a5d6ad92d5 | 54 | LoRaMacEventFlags.Bits.Tx = 1; |
mluis | 2:14a5d6ad92d5 | 55 | |
mluis | 2:14a5d6ad92d5 | 56 | LoRaMacEventInfo.TxDatarate = mcpsConfirm->Datarate; |
mluis | 2:14a5d6ad92d5 | 57 | LoRaMacEventInfo.TxNbRetries = mcpsConfirm->NbRetries; |
mluis | 2:14a5d6ad92d5 | 58 | LoRaMacEventInfo.TxAckReceived = mcpsConfirm->AckReceived; |
mluis | 2:14a5d6ad92d5 | 59 | |
mluis | 2:14a5d6ad92d5 | 60 | if( ( LoRaMacFlags.Bits.McpsInd != 1 ) && ( LoRaMacFlags.Bits.MlmeReq != 1 ) ) |
mluis | 2:14a5d6ad92d5 | 61 | { |
mluis | 2:14a5d6ad92d5 | 62 | LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo ); |
mluis | 2:14a5d6ad92d5 | 63 | LoRaMacEventFlags.Value = 0; |
mluis | 2:14a5d6ad92d5 | 64 | } |
mluis | 2:14a5d6ad92d5 | 65 | } |
mluis | 2:14a5d6ad92d5 | 66 | |
mluis | 2:14a5d6ad92d5 | 67 | /*! |
mluis | 2:14a5d6ad92d5 | 68 | * \brief MCPS-Indication event function |
mluis | 2:14a5d6ad92d5 | 69 | * |
mluis | 2:14a5d6ad92d5 | 70 | * \param [IN] mcpsIndication - Pointer to the indication structure, |
mluis | 2:14a5d6ad92d5 | 71 | * containing indication attributes. |
mluis | 2:14a5d6ad92d5 | 72 | */ |
mluis | 2:14a5d6ad92d5 | 73 | static void McpsIndication( McpsIndication_t *mcpsIndication ) |
mluis | 2:14a5d6ad92d5 | 74 | { |
mluis | 2:14a5d6ad92d5 | 75 | LoRaMacEventInfo.Status = mcpsIndication->Status; |
mluis | 2:14a5d6ad92d5 | 76 | LoRaMacEventFlags.Bits.Rx = 1; |
mluis | 2:14a5d6ad92d5 | 77 | LoRaMacEventFlags.Bits.RxSlot = mcpsIndication->RxSlot; |
mluis | 2:14a5d6ad92d5 | 78 | LoRaMacEventFlags.Bits.Multicast = mcpsIndication->Multicast; |
mluis | 2:14a5d6ad92d5 | 79 | if( mcpsIndication->RxData == true ) |
mluis | 2:14a5d6ad92d5 | 80 | { |
mluis | 2:14a5d6ad92d5 | 81 | LoRaMacEventFlags.Bits.RxData = 1; |
mluis | 2:14a5d6ad92d5 | 82 | } |
mluis | 2:14a5d6ad92d5 | 83 | |
mluis | 2:14a5d6ad92d5 | 84 | LoRaMacEventInfo.RxPort = mcpsIndication->Port; |
mluis | 2:14a5d6ad92d5 | 85 | LoRaMacEventInfo.RxBuffer = mcpsIndication->Buffer; |
mluis | 2:14a5d6ad92d5 | 86 | LoRaMacEventInfo.RxBufferSize = mcpsIndication->BufferSize; |
mluis | 2:14a5d6ad92d5 | 87 | LoRaMacEventInfo.RxRssi = mcpsIndication->Rssi; |
mluis | 2:14a5d6ad92d5 | 88 | LoRaMacEventInfo.RxSnr = mcpsIndication->Snr; |
mluis | 2:14a5d6ad92d5 | 89 | |
mluis | 2:14a5d6ad92d5 | 90 | LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo ); |
mluis | 2:14a5d6ad92d5 | 91 | LoRaMacEventFlags.Value = 0; |
mluis | 2:14a5d6ad92d5 | 92 | } |
mluis | 2:14a5d6ad92d5 | 93 | |
mluis | 2:14a5d6ad92d5 | 94 | /*! |
mluis | 2:14a5d6ad92d5 | 95 | * \brief MLME-Confirm event function |
mluis | 2:14a5d6ad92d5 | 96 | * |
mluis | 2:14a5d6ad92d5 | 97 | * \param [IN] mlmeConfirm - Pointer to the confirm structure, |
mluis | 2:14a5d6ad92d5 | 98 | * containing confirm attributes. |
mluis | 2:14a5d6ad92d5 | 99 | */ |
mluis | 2:14a5d6ad92d5 | 100 | static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm ) |
mluis | 2:14a5d6ad92d5 | 101 | { |
mluis | 2:14a5d6ad92d5 | 102 | if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 2:14a5d6ad92d5 | 103 | { |
mluis | 2:14a5d6ad92d5 | 104 | switch( mlmeConfirm->MlmeRequest ) |
mluis | 2:14a5d6ad92d5 | 105 | { |
mluis | 2:14a5d6ad92d5 | 106 | case MLME_JOIN: |
mluis | 2:14a5d6ad92d5 | 107 | { |
mluis | 4:37c12dbc8dc7 | 108 | // Status is OK, node has joined the network |
mluis | 2:14a5d6ad92d5 | 109 | LoRaMacEventFlags.Bits.Tx = 1; |
mluis | 2:14a5d6ad92d5 | 110 | LoRaMacEventFlags.Bits.Rx = 1; |
mluis | 2:14a5d6ad92d5 | 111 | LoRaMacEventFlags.Bits.JoinAccept = 1; |
mluis | 2:14a5d6ad92d5 | 112 | break; |
mluis | 2:14a5d6ad92d5 | 113 | } |
mluis | 2:14a5d6ad92d5 | 114 | case MLME_LINK_CHECK: |
mluis | 2:14a5d6ad92d5 | 115 | { |
mluis | 2:14a5d6ad92d5 | 116 | LoRaMacEventFlags.Bits.Tx = 1; |
mluis | 2:14a5d6ad92d5 | 117 | LoRaMacEventFlags.Bits.Rx = 1; |
mluis | 2:14a5d6ad92d5 | 118 | LoRaMacEventFlags.Bits.LinkCheck = 1; |
mluis | 2:14a5d6ad92d5 | 119 | |
mluis | 2:14a5d6ad92d5 | 120 | LoRaMacEventInfo.DemodMargin = mlmeConfirm->DemodMargin; |
mluis | 2:14a5d6ad92d5 | 121 | LoRaMacEventInfo.NbGateways = mlmeConfirm->NbGateways; |
mluis | 2:14a5d6ad92d5 | 122 | break; |
mluis | 2:14a5d6ad92d5 | 123 | } |
mluis | 2:14a5d6ad92d5 | 124 | default: |
mluis | 2:14a5d6ad92d5 | 125 | break; |
mluis | 2:14a5d6ad92d5 | 126 | } |
mluis | 2:14a5d6ad92d5 | 127 | } |
mluis | 4:37c12dbc8dc7 | 128 | LoRaMacEventInfo.Status = mlmeConfirm->Status; |
mluis | 2:14a5d6ad92d5 | 129 | |
mluis | 2:14a5d6ad92d5 | 130 | if( LoRaMacFlags.Bits.McpsInd != 1 ) |
mluis | 2:14a5d6ad92d5 | 131 | { |
mluis | 2:14a5d6ad92d5 | 132 | LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo ); |
mluis | 2:14a5d6ad92d5 | 133 | LoRaMacEventFlags.Value = 0; |
mluis | 2:14a5d6ad92d5 | 134 | } |
mluis | 2:14a5d6ad92d5 | 135 | } |
mluis | 2:14a5d6ad92d5 | 136 | |
mluis | 2:14a5d6ad92d5 | 137 | void LoRaMacInit( LoRaMacCallbacks_t *callbacks ) |
mluis | 2:14a5d6ad92d5 | 138 | { |
mluis | 2:14a5d6ad92d5 | 139 | LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; |
mluis | 2:14a5d6ad92d5 | 140 | LoRaMacPrimitives.MacMcpsIndication = McpsIndication; |
mluis | 2:14a5d6ad92d5 | 141 | LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm; |
mluis | 2:14a5d6ad92d5 | 142 | |
mluis | 2:14a5d6ad92d5 | 143 | LoRaMacCallbacks.MacEvent = callbacks->MacEvent; |
mluis | 2:14a5d6ad92d5 | 144 | LoRaMacCallbacks.GetBatteryLevel = callbacks->GetBatteryLevel; |
mluis | 2:14a5d6ad92d5 | 145 | LoRaMacCallback.GetBatteryLevel = callbacks->GetBatteryLevel; |
mluis | 2:14a5d6ad92d5 | 146 | |
mluis | 2:14a5d6ad92d5 | 147 | LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallback ); |
mluis | 2:14a5d6ad92d5 | 148 | } |
mluis | 2:14a5d6ad92d5 | 149 | |
mluis | 2:14a5d6ad92d5 | 150 | void LoRaMacSetAdrOn( bool enable ) |
mluis | 2:14a5d6ad92d5 | 151 | { |
mluis | 2:14a5d6ad92d5 | 152 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 153 | |
mluis | 2:14a5d6ad92d5 | 154 | mibSet.Type = MIB_ADR; |
mluis | 2:14a5d6ad92d5 | 155 | mibSet.Param.AdrEnable = enable; |
mluis | 2:14a5d6ad92d5 | 156 | |
mluis | 2:14a5d6ad92d5 | 157 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 158 | } |
mluis | 2:14a5d6ad92d5 | 159 | |
mluis | 2:14a5d6ad92d5 | 160 | void LoRaMacInitNwkIds( uint32_t netID, uint32_t devAddr, uint8_t *nwkSKey, uint8_t *appSKey ) |
mluis | 2:14a5d6ad92d5 | 161 | { |
mluis | 2:14a5d6ad92d5 | 162 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 163 | |
mluis | 2:14a5d6ad92d5 | 164 | mibSet.Type = MIB_NET_ID; |
mluis | 2:14a5d6ad92d5 | 165 | mibSet.Param.NetID = netID; |
mluis | 2:14a5d6ad92d5 | 166 | |
mluis | 2:14a5d6ad92d5 | 167 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 168 | |
mluis | 2:14a5d6ad92d5 | 169 | mibSet.Type = MIB_DEV_ADDR; |
mluis | 2:14a5d6ad92d5 | 170 | mibSet.Param.DevAddr = devAddr; |
mluis | 2:14a5d6ad92d5 | 171 | |
mluis | 2:14a5d6ad92d5 | 172 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 173 | |
mluis | 2:14a5d6ad92d5 | 174 | mibSet.Type = MIB_NWK_SKEY; |
mluis | 2:14a5d6ad92d5 | 175 | mibSet.Param.NwkSKey = nwkSKey; |
mluis | 2:14a5d6ad92d5 | 176 | |
mluis | 2:14a5d6ad92d5 | 177 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 178 | |
mluis | 2:14a5d6ad92d5 | 179 | mibSet.Type = MIB_APP_SKEY; |
mluis | 2:14a5d6ad92d5 | 180 | mibSet.Param.AppSKey = appSKey; |
mluis | 2:14a5d6ad92d5 | 181 | |
mluis | 2:14a5d6ad92d5 | 182 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 183 | |
mluis | 2:14a5d6ad92d5 | 184 | mibSet.Type = MIB_NETWORK_JOINED; |
mluis | 2:14a5d6ad92d5 | 185 | mibSet.Param.IsNetworkJoined = true; |
mluis | 2:14a5d6ad92d5 | 186 | |
mluis | 2:14a5d6ad92d5 | 187 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 188 | } |
mluis | 2:14a5d6ad92d5 | 189 | |
mluis | 2:14a5d6ad92d5 | 190 | void LoRaMacMulticastChannelAdd( MulticastParams_t *channelParam ) |
mluis | 2:14a5d6ad92d5 | 191 | { |
mluis | 2:14a5d6ad92d5 | 192 | LoRaMacMulticastChannelLink( channelParam ); |
mluis | 2:14a5d6ad92d5 | 193 | } |
mluis | 2:14a5d6ad92d5 | 194 | |
mluis | 2:14a5d6ad92d5 | 195 | void LoRaMacMulticastChannelRemove( MulticastParams_t *channelParam ) |
mluis | 2:14a5d6ad92d5 | 196 | { |
mluis | 2:14a5d6ad92d5 | 197 | LoRaMacMulticastChannelUnlink( channelParam ); |
mluis | 2:14a5d6ad92d5 | 198 | } |
mluis | 2:14a5d6ad92d5 | 199 | |
mluis | 2:14a5d6ad92d5 | 200 | uint8_t LoRaMacJoinReq( uint8_t *devEui, uint8_t *appEui, uint8_t *appKey ) |
mluis | 2:14a5d6ad92d5 | 201 | { |
mluis | 2:14a5d6ad92d5 | 202 | MlmeReq_t mlmeRequest; |
mluis | 2:14a5d6ad92d5 | 203 | uint8_t status; |
mluis | 2:14a5d6ad92d5 | 204 | |
mluis | 2:14a5d6ad92d5 | 205 | mlmeRequest.Type = MLME_JOIN; |
mluis | 2:14a5d6ad92d5 | 206 | mlmeRequest.Req.Join.AppEui = appEui; |
mluis | 2:14a5d6ad92d5 | 207 | mlmeRequest.Req.Join.AppKey = appKey; |
mluis | 2:14a5d6ad92d5 | 208 | mlmeRequest.Req.Join.DevEui = devEui; |
mluis | 2:14a5d6ad92d5 | 209 | |
mluis | 2:14a5d6ad92d5 | 210 | switch( LoRaMacMlmeRequest( &mlmeRequest ) ) |
mluis | 2:14a5d6ad92d5 | 211 | { |
mluis | 2:14a5d6ad92d5 | 212 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 213 | { |
mluis | 2:14a5d6ad92d5 | 214 | status = 0; |
mluis | 2:14a5d6ad92d5 | 215 | break; |
mluis | 2:14a5d6ad92d5 | 216 | } |
mluis | 2:14a5d6ad92d5 | 217 | case LORAMAC_STATUS_BUSY: |
mluis | 2:14a5d6ad92d5 | 218 | { |
mluis | 2:14a5d6ad92d5 | 219 | status = 1; |
mluis | 2:14a5d6ad92d5 | 220 | break; |
mluis | 2:14a5d6ad92d5 | 221 | } |
mluis | 2:14a5d6ad92d5 | 222 | case LORAMAC_STATUS_NO_NETWORK_JOINED: |
mluis | 2:14a5d6ad92d5 | 223 | { |
mluis | 2:14a5d6ad92d5 | 224 | status = 2; |
mluis | 2:14a5d6ad92d5 | 225 | break; |
mluis | 2:14a5d6ad92d5 | 226 | } |
mluis | 2:14a5d6ad92d5 | 227 | case LORAMAC_STATUS_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 228 | case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 229 | { |
mluis | 2:14a5d6ad92d5 | 230 | status = 3; |
mluis | 2:14a5d6ad92d5 | 231 | break; |
mluis | 2:14a5d6ad92d5 | 232 | } |
mluis | 2:14a5d6ad92d5 | 233 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 234 | { |
mluis | 2:14a5d6ad92d5 | 235 | status = 4; |
mluis | 2:14a5d6ad92d5 | 236 | break; |
mluis | 2:14a5d6ad92d5 | 237 | } |
mluis | 2:14a5d6ad92d5 | 238 | case LORAMAC_STATUS_DEVICE_OFF: |
mluis | 2:14a5d6ad92d5 | 239 | { |
mluis | 2:14a5d6ad92d5 | 240 | status = 6; |
mluis | 2:14a5d6ad92d5 | 241 | break; |
mluis | 2:14a5d6ad92d5 | 242 | } |
mluis | 2:14a5d6ad92d5 | 243 | default: |
mluis | 2:14a5d6ad92d5 | 244 | { |
mluis | 2:14a5d6ad92d5 | 245 | status = 1; |
mluis | 2:14a5d6ad92d5 | 246 | break; |
mluis | 2:14a5d6ad92d5 | 247 | } |
mluis | 2:14a5d6ad92d5 | 248 | } |
mluis | 2:14a5d6ad92d5 | 249 | |
mluis | 2:14a5d6ad92d5 | 250 | return status; |
mluis | 2:14a5d6ad92d5 | 251 | } |
mluis | 2:14a5d6ad92d5 | 252 | |
mluis | 2:14a5d6ad92d5 | 253 | uint8_t LoRaMacLinkCheckReq( void ) |
mluis | 2:14a5d6ad92d5 | 254 | { |
mluis | 2:14a5d6ad92d5 | 255 | MlmeReq_t mlmeRequest; |
mluis | 2:14a5d6ad92d5 | 256 | uint8_t status; |
mluis | 2:14a5d6ad92d5 | 257 | |
mluis | 2:14a5d6ad92d5 | 258 | mlmeRequest.Type = MLME_LINK_CHECK; |
mluis | 2:14a5d6ad92d5 | 259 | |
mluis | 2:14a5d6ad92d5 | 260 | switch( LoRaMacMlmeRequest( &mlmeRequest ) ) |
mluis | 2:14a5d6ad92d5 | 261 | { |
mluis | 2:14a5d6ad92d5 | 262 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 263 | { |
mluis | 2:14a5d6ad92d5 | 264 | status = 0; |
mluis | 2:14a5d6ad92d5 | 265 | break; |
mluis | 2:14a5d6ad92d5 | 266 | } |
mluis | 2:14a5d6ad92d5 | 267 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 268 | { |
mluis | 2:14a5d6ad92d5 | 269 | status = 1; |
mluis | 2:14a5d6ad92d5 | 270 | break; |
mluis | 2:14a5d6ad92d5 | 271 | } |
mluis | 2:14a5d6ad92d5 | 272 | default: |
mluis | 2:14a5d6ad92d5 | 273 | { |
mluis | 2:14a5d6ad92d5 | 274 | status = 1; |
mluis | 2:14a5d6ad92d5 | 275 | break; |
mluis | 2:14a5d6ad92d5 | 276 | } |
mluis | 2:14a5d6ad92d5 | 277 | } |
mluis | 2:14a5d6ad92d5 | 278 | |
mluis | 2:14a5d6ad92d5 | 279 | return status; |
mluis | 2:14a5d6ad92d5 | 280 | } |
mluis | 2:14a5d6ad92d5 | 281 | |
mluis | 2:14a5d6ad92d5 | 282 | uint8_t LoRaMacSendFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize ) |
mluis | 2:14a5d6ad92d5 | 283 | { |
mluis | 2:14a5d6ad92d5 | 284 | MibRequestConfirm_t mibGet; |
mluis | 2:14a5d6ad92d5 | 285 | McpsReq_t mcpsRequest; |
mluis | 2:14a5d6ad92d5 | 286 | uint8_t retStatus; |
mluis | 2:14a5d6ad92d5 | 287 | |
mluis | 2:14a5d6ad92d5 | 288 | memset1( ( uint8_t* )&LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) ); |
mluis | 2:14a5d6ad92d5 | 289 | |
mluis | 2:14a5d6ad92d5 | 290 | mibGet.Type = MIB_CHANNELS_DATARATE; |
mluis | 2:14a5d6ad92d5 | 291 | LoRaMacMibGetRequestConfirm( &mibGet ); |
mluis | 2:14a5d6ad92d5 | 292 | |
mluis | 2:14a5d6ad92d5 | 293 | mcpsRequest.Type = MCPS_UNCONFIRMED; |
mluis | 2:14a5d6ad92d5 | 294 | mcpsRequest.Req.Unconfirmed.fBuffer = fBuffer; |
mluis | 2:14a5d6ad92d5 | 295 | mcpsRequest.Req.Unconfirmed.fBufferSize = fBufferSize; |
mluis | 2:14a5d6ad92d5 | 296 | mcpsRequest.Req.Unconfirmed.fPort = fPort; |
mluis | 2:14a5d6ad92d5 | 297 | mcpsRequest.Req.Unconfirmed.Datarate = mibGet.Param.ChannelsDatarate; |
mluis | 2:14a5d6ad92d5 | 298 | |
mluis | 2:14a5d6ad92d5 | 299 | switch( LoRaMacMcpsRequest( &mcpsRequest ) ) |
mluis | 2:14a5d6ad92d5 | 300 | { |
mluis | 2:14a5d6ad92d5 | 301 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 302 | retStatus = 0U; |
mluis | 2:14a5d6ad92d5 | 303 | break; |
mluis | 2:14a5d6ad92d5 | 304 | case LORAMAC_STATUS_BUSY: |
mluis | 2:14a5d6ad92d5 | 305 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 306 | break; |
mluis | 2:14a5d6ad92d5 | 307 | case LORAMAC_STATUS_NO_NETWORK_JOINED: |
mluis | 2:14a5d6ad92d5 | 308 | retStatus = 2U; |
mluis | 2:14a5d6ad92d5 | 309 | break; |
mluis | 2:14a5d6ad92d5 | 310 | case LORAMAC_STATUS_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 311 | case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 312 | retStatus = 3U; |
mluis | 2:14a5d6ad92d5 | 313 | break; |
mluis | 2:14a5d6ad92d5 | 314 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 315 | retStatus = 4U; |
mluis | 2:14a5d6ad92d5 | 316 | break; |
mluis | 2:14a5d6ad92d5 | 317 | case LORAMAC_STATUS_DEVICE_OFF: |
mluis | 2:14a5d6ad92d5 | 318 | retStatus = 6U; |
mluis | 2:14a5d6ad92d5 | 319 | break; |
mluis | 2:14a5d6ad92d5 | 320 | default: |
mluis | 2:14a5d6ad92d5 | 321 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 322 | break; |
mluis | 2:14a5d6ad92d5 | 323 | } |
mluis | 2:14a5d6ad92d5 | 324 | |
mluis | 2:14a5d6ad92d5 | 325 | return retStatus; |
mluis | 2:14a5d6ad92d5 | 326 | } |
mluis | 2:14a5d6ad92d5 | 327 | |
mluis | 2:14a5d6ad92d5 | 328 | uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries ) |
mluis | 2:14a5d6ad92d5 | 329 | { |
mluis | 2:14a5d6ad92d5 | 330 | MibRequestConfirm_t mibGet; |
mluis | 2:14a5d6ad92d5 | 331 | McpsReq_t mcpsRequest; |
mluis | 2:14a5d6ad92d5 | 332 | uint8_t retStatus; |
mluis | 2:14a5d6ad92d5 | 333 | |
mluis | 2:14a5d6ad92d5 | 334 | memset1( ( uint8_t* )&LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) ); |
mluis | 2:14a5d6ad92d5 | 335 | |
mluis | 2:14a5d6ad92d5 | 336 | mibGet.Type = MIB_CHANNELS_DATARATE; |
mluis | 2:14a5d6ad92d5 | 337 | LoRaMacMibGetRequestConfirm( &mibGet ); |
mluis | 2:14a5d6ad92d5 | 338 | |
mluis | 2:14a5d6ad92d5 | 339 | mcpsRequest.Type = MCPS_CONFIRMED; |
mluis | 2:14a5d6ad92d5 | 340 | mcpsRequest.Req.Confirmed.fBuffer = fBuffer; |
mluis | 2:14a5d6ad92d5 | 341 | mcpsRequest.Req.Confirmed.fBufferSize = fBufferSize; |
mluis | 2:14a5d6ad92d5 | 342 | mcpsRequest.Req.Confirmed.fPort = fPort; |
mluis | 3:b9d87593a8ae | 343 | mcpsRequest.Req.Confirmed.NbTrials = nbRetries; |
mluis | 2:14a5d6ad92d5 | 344 | mcpsRequest.Req.Confirmed.Datarate = mibGet.Param.ChannelsDatarate; |
mluis | 2:14a5d6ad92d5 | 345 | |
mluis | 2:14a5d6ad92d5 | 346 | switch( LoRaMacMcpsRequest( &mcpsRequest ) ) |
mluis | 2:14a5d6ad92d5 | 347 | { |
mluis | 2:14a5d6ad92d5 | 348 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 349 | retStatus = 0U; |
mluis | 2:14a5d6ad92d5 | 350 | break; |
mluis | 2:14a5d6ad92d5 | 351 | case LORAMAC_STATUS_BUSY: |
mluis | 2:14a5d6ad92d5 | 352 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 353 | break; |
mluis | 2:14a5d6ad92d5 | 354 | case LORAMAC_STATUS_NO_NETWORK_JOINED: |
mluis | 2:14a5d6ad92d5 | 355 | retStatus = 2U; |
mluis | 2:14a5d6ad92d5 | 356 | break; |
mluis | 2:14a5d6ad92d5 | 357 | case LORAMAC_STATUS_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 358 | case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 359 | retStatus = 3U; |
mluis | 2:14a5d6ad92d5 | 360 | break; |
mluis | 2:14a5d6ad92d5 | 361 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 362 | retStatus = 4U; |
mluis | 2:14a5d6ad92d5 | 363 | break; |
mluis | 2:14a5d6ad92d5 | 364 | case LORAMAC_STATUS_DEVICE_OFF: |
mluis | 2:14a5d6ad92d5 | 365 | retStatus = 6U; |
mluis | 2:14a5d6ad92d5 | 366 | break; |
mluis | 2:14a5d6ad92d5 | 367 | default: |
mluis | 2:14a5d6ad92d5 | 368 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 369 | break; |
mluis | 2:14a5d6ad92d5 | 370 | } |
mluis | 2:14a5d6ad92d5 | 371 | |
mluis | 2:14a5d6ad92d5 | 372 | return retStatus; |
mluis | 2:14a5d6ad92d5 | 373 | } |
mluis | 2:14a5d6ad92d5 | 374 | |
mluis | 2:14a5d6ad92d5 | 375 | uint8_t LoRaMacSend( LoRaMacHeader_t *macHdr, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize ) |
mluis | 2:14a5d6ad92d5 | 376 | { |
mluis | 2:14a5d6ad92d5 | 377 | uint8_t retStatus; |
mluis | 2:14a5d6ad92d5 | 378 | |
mluis | 2:14a5d6ad92d5 | 379 | memset1( ( uint8_t* ) &LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) ); |
mluis | 2:14a5d6ad92d5 | 380 | |
mluis | 2:14a5d6ad92d5 | 381 | switch( Send( macHdr, fPort, fBuffer, fBufferSize ) ) |
mluis | 2:14a5d6ad92d5 | 382 | { |
mluis | 2:14a5d6ad92d5 | 383 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 384 | retStatus = 0U; |
mluis | 2:14a5d6ad92d5 | 385 | break; |
mluis | 2:14a5d6ad92d5 | 386 | case LORAMAC_STATUS_BUSY: |
mluis | 2:14a5d6ad92d5 | 387 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 388 | break; |
mluis | 2:14a5d6ad92d5 | 389 | case LORAMAC_STATUS_NO_NETWORK_JOINED: |
mluis | 2:14a5d6ad92d5 | 390 | retStatus = 2U; |
mluis | 2:14a5d6ad92d5 | 391 | break; |
mluis | 2:14a5d6ad92d5 | 392 | case LORAMAC_STATUS_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 393 | case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 394 | retStatus = 3U; |
mluis | 2:14a5d6ad92d5 | 395 | break; |
mluis | 2:14a5d6ad92d5 | 396 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 397 | retStatus = 4U; |
mluis | 2:14a5d6ad92d5 | 398 | break; |
mluis | 2:14a5d6ad92d5 | 399 | case LORAMAC_STATUS_DEVICE_OFF: |
mluis | 2:14a5d6ad92d5 | 400 | retStatus = 6U; |
mluis | 2:14a5d6ad92d5 | 401 | break; |
mluis | 2:14a5d6ad92d5 | 402 | default: |
mluis | 2:14a5d6ad92d5 | 403 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 404 | break; |
mluis | 2:14a5d6ad92d5 | 405 | } |
mluis | 2:14a5d6ad92d5 | 406 | |
mluis | 2:14a5d6ad92d5 | 407 | return retStatus; |
mluis | 2:14a5d6ad92d5 | 408 | } |
mluis | 2:14a5d6ad92d5 | 409 | |
mluis | 2:14a5d6ad92d5 | 410 | uint8_t LoRaMacPrepareFrame( ChannelParams_t channel,LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize ) |
mluis | 2:14a5d6ad92d5 | 411 | { |
mluis | 2:14a5d6ad92d5 | 412 | uint8_t retStatus; |
mluis | 2:14a5d6ad92d5 | 413 | |
mluis | 2:14a5d6ad92d5 | 414 | switch( PrepareFrame( macHdr, fCtrl, fPort, fBuffer, fBufferSize ) ) |
mluis | 2:14a5d6ad92d5 | 415 | { |
mluis | 2:14a5d6ad92d5 | 416 | case LORAMAC_STATUS_OK: |
mluis | 2:14a5d6ad92d5 | 417 | retStatus = 0U; |
mluis | 2:14a5d6ad92d5 | 418 | break; |
mluis | 2:14a5d6ad92d5 | 419 | case LORAMAC_STATUS_BUSY: |
mluis | 2:14a5d6ad92d5 | 420 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 421 | break; |
mluis | 2:14a5d6ad92d5 | 422 | case LORAMAC_STATUS_NO_NETWORK_JOINED: |
mluis | 2:14a5d6ad92d5 | 423 | retStatus = 2U; |
mluis | 2:14a5d6ad92d5 | 424 | break; |
mluis | 2:14a5d6ad92d5 | 425 | case LORAMAC_STATUS_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 426 | case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR: |
mluis | 2:14a5d6ad92d5 | 427 | retStatus = 3U; |
mluis | 2:14a5d6ad92d5 | 428 | break; |
mluis | 2:14a5d6ad92d5 | 429 | case LORAMAC_STATUS_SERVICE_UNKNOWN: |
mluis | 2:14a5d6ad92d5 | 430 | retStatus = 4U; |
mluis | 2:14a5d6ad92d5 | 431 | break; |
mluis | 2:14a5d6ad92d5 | 432 | default: |
mluis | 2:14a5d6ad92d5 | 433 | retStatus = 1U; |
mluis | 2:14a5d6ad92d5 | 434 | break; |
mluis | 2:14a5d6ad92d5 | 435 | } |
mluis | 2:14a5d6ad92d5 | 436 | |
mluis | 2:14a5d6ad92d5 | 437 | return retStatus; |
mluis | 2:14a5d6ad92d5 | 438 | } |
mluis | 2:14a5d6ad92d5 | 439 | |
mluis | 2:14a5d6ad92d5 | 440 | uint8_t LoRaMacSendFrameOnChannel( ChannelParams_t channel ) |
mluis | 2:14a5d6ad92d5 | 441 | { |
mluis | 2:14a5d6ad92d5 | 442 | memset1( ( uint8_t* ) &LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) ); |
mluis | 2:14a5d6ad92d5 | 443 | |
mluis | 2:14a5d6ad92d5 | 444 | SendFrameOnChannel( channel ); |
mluis | 2:14a5d6ad92d5 | 445 | |
mluis | 2:14a5d6ad92d5 | 446 | /* SendFrameOnChannel has always status "OK" */ |
mluis | 2:14a5d6ad92d5 | 447 | return 0; |
mluis | 2:14a5d6ad92d5 | 448 | } |
mluis | 2:14a5d6ad92d5 | 449 | |
mluis | 2:14a5d6ad92d5 | 450 | uint8_t LoRaMacSendOnChannel( ChannelParams_t channel, LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize ) |
mluis | 2:14a5d6ad92d5 | 451 | { |
mluis | 2:14a5d6ad92d5 | 452 | uint8_t status = 0; |
mluis | 2:14a5d6ad92d5 | 453 | |
mluis | 2:14a5d6ad92d5 | 454 | if( ( LoRaMacState & 0x00000001 ) == 0x00000001 ) |
mluis | 2:14a5d6ad92d5 | 455 | { |
mluis | 2:14a5d6ad92d5 | 456 | return 1; // MAC is busy transmitting a previous frame |
mluis | 2:14a5d6ad92d5 | 457 | } |
mluis | 2:14a5d6ad92d5 | 458 | |
mluis | 2:14a5d6ad92d5 | 459 | status = LoRaMacPrepareFrame( channel, macHdr, fCtrl, fOpts, fPort, fBuffer, fBufferSize ); |
mluis | 2:14a5d6ad92d5 | 460 | if( status != 0 ) |
mluis | 2:14a5d6ad92d5 | 461 | { |
mluis | 2:14a5d6ad92d5 | 462 | return status; |
mluis | 2:14a5d6ad92d5 | 463 | } |
mluis | 2:14a5d6ad92d5 | 464 | |
mluis | 2:14a5d6ad92d5 | 465 | LoRaMacEventInfo.TxNbRetries = 0; |
mluis | 2:14a5d6ad92d5 | 466 | LoRaMacEventInfo.TxAckReceived = false; |
mluis | 2:14a5d6ad92d5 | 467 | |
mluis | 2:14a5d6ad92d5 | 468 | return LoRaMacSendFrameOnChannel( channel ); |
mluis | 2:14a5d6ad92d5 | 469 | } |
mluis | 2:14a5d6ad92d5 | 470 | |
mluis | 2:14a5d6ad92d5 | 471 | void LoRaMacSetDeviceClass( DeviceClass_t deviceClass ) |
mluis | 2:14a5d6ad92d5 | 472 | { |
mluis | 2:14a5d6ad92d5 | 473 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 474 | |
mluis | 2:14a5d6ad92d5 | 475 | mibSet.Type = MIB_DEVICE_CLASS; |
mluis | 2:14a5d6ad92d5 | 476 | mibSet.Param.Class = deviceClass; |
mluis | 2:14a5d6ad92d5 | 477 | |
mluis | 2:14a5d6ad92d5 | 478 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 479 | } |
mluis | 2:14a5d6ad92d5 | 480 | |
mluis | 2:14a5d6ad92d5 | 481 | void LoRaMacSetPublicNetwork( bool enable ) |
mluis | 2:14a5d6ad92d5 | 482 | { |
mluis | 2:14a5d6ad92d5 | 483 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 484 | |
mluis | 2:14a5d6ad92d5 | 485 | mibSet.Type = MIB_PUBLIC_NETWORK; |
mluis | 2:14a5d6ad92d5 | 486 | mibSet.Param.EnablePublicNetwork = enable; |
mluis | 2:14a5d6ad92d5 | 487 | |
mluis | 2:14a5d6ad92d5 | 488 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 489 | } |
mluis | 2:14a5d6ad92d5 | 490 | |
mluis | 2:14a5d6ad92d5 | 491 | void LoRaMacSetDutyCycleOn( bool enable ) |
mluis | 2:14a5d6ad92d5 | 492 | { |
mluis | 2:14a5d6ad92d5 | 493 | LoRaMacTestSetDutyCycleOn( enable ); |
mluis | 2:14a5d6ad92d5 | 494 | } |
mluis | 2:14a5d6ad92d5 | 495 | |
mluis | 2:14a5d6ad92d5 | 496 | void LoRaMacSetChannel( uint8_t id, ChannelParams_t params ) |
mluis | 2:14a5d6ad92d5 | 497 | { |
mluis | 2:14a5d6ad92d5 | 498 | LoRaMacChannelAdd( id, params ); |
mluis | 2:14a5d6ad92d5 | 499 | } |
mluis | 2:14a5d6ad92d5 | 500 | |
mluis | 2:14a5d6ad92d5 | 501 | void LoRaMacSetRx2Channel( Rx2ChannelParams_t param ) |
mluis | 2:14a5d6ad92d5 | 502 | { |
mluis | 2:14a5d6ad92d5 | 503 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 504 | |
mluis | 2:14a5d6ad92d5 | 505 | mibSet.Type = MIB_RX2_CHANNEL; |
mluis | 2:14a5d6ad92d5 | 506 | mibSet.Param.Rx2Channel = param; |
mluis | 2:14a5d6ad92d5 | 507 | |
mluis | 2:14a5d6ad92d5 | 508 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 509 | } |
mluis | 2:14a5d6ad92d5 | 510 | |
mluis | 2:14a5d6ad92d5 | 511 | void LoRaMacSetChannelsMask( uint16_t *mask ) |
mluis | 2:14a5d6ad92d5 | 512 | { |
mluis | 2:14a5d6ad92d5 | 513 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 514 | |
mluis | 2:14a5d6ad92d5 | 515 | mibSet.Type = MIB_CHANNELS_MASK; |
mluis | 2:14a5d6ad92d5 | 516 | mibSet.Param.ChannelsMask = mask; |
mluis | 2:14a5d6ad92d5 | 517 | |
mluis | 2:14a5d6ad92d5 | 518 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 519 | } |
mluis | 2:14a5d6ad92d5 | 520 | |
mluis | 2:14a5d6ad92d5 | 521 | void LoRaMacSetChannelsNbRep( uint8_t nbRep ) |
mluis | 2:14a5d6ad92d5 | 522 | { |
mluis | 2:14a5d6ad92d5 | 523 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 524 | |
mluis | 2:14a5d6ad92d5 | 525 | mibSet.Type = MIB_CHANNELS_NB_REP; |
mluis | 2:14a5d6ad92d5 | 526 | mibSet.Param.ChannelNbRep = nbRep; |
mluis | 2:14a5d6ad92d5 | 527 | |
mluis | 2:14a5d6ad92d5 | 528 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 529 | } |
mluis | 2:14a5d6ad92d5 | 530 | |
mluis | 2:14a5d6ad92d5 | 531 | void LoRaMacSetMaxRxWindow( uint32_t delay ) |
mluis | 2:14a5d6ad92d5 | 532 | { |
mluis | 2:14a5d6ad92d5 | 533 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 534 | |
mluis | 2:14a5d6ad92d5 | 535 | mibSet.Type = MIB_MAX_RX_WINDOW_DURATION; |
mluis | 2:14a5d6ad92d5 | 536 | mibSet.Param.MaxRxWindow = delay; |
mluis | 2:14a5d6ad92d5 | 537 | |
mluis | 2:14a5d6ad92d5 | 538 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 539 | } |
mluis | 2:14a5d6ad92d5 | 540 | |
mluis | 2:14a5d6ad92d5 | 541 | void LoRaMacSetReceiveDelay1( uint32_t delay ) |
mluis | 2:14a5d6ad92d5 | 542 | { |
mluis | 2:14a5d6ad92d5 | 543 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 544 | |
mluis | 2:14a5d6ad92d5 | 545 | mibSet.Type = MIB_RECEIVE_DELAY_1; |
mluis | 2:14a5d6ad92d5 | 546 | mibSet.Param.ReceiveDelay1 = delay; |
mluis | 2:14a5d6ad92d5 | 547 | |
mluis | 2:14a5d6ad92d5 | 548 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 549 | } |
mluis | 2:14a5d6ad92d5 | 550 | |
mluis | 2:14a5d6ad92d5 | 551 | void LoRaMacSetReceiveDelay2( uint32_t delay ) |
mluis | 2:14a5d6ad92d5 | 552 | { |
mluis | 2:14a5d6ad92d5 | 553 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 554 | |
mluis | 2:14a5d6ad92d5 | 555 | mibSet.Type = MIB_RECEIVE_DELAY_2; |
mluis | 2:14a5d6ad92d5 | 556 | mibSet.Param.ReceiveDelay2 = delay; |
mluis | 2:14a5d6ad92d5 | 557 | |
mluis | 2:14a5d6ad92d5 | 558 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 559 | } |
mluis | 2:14a5d6ad92d5 | 560 | |
mluis | 2:14a5d6ad92d5 | 561 | void LoRaMacSetJoinAcceptDelay1( uint32_t delay ) |
mluis | 2:14a5d6ad92d5 | 562 | { |
mluis | 2:14a5d6ad92d5 | 563 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 564 | |
mluis | 2:14a5d6ad92d5 | 565 | mibSet.Type = MIB_JOIN_ACCEPT_DELAY_1; |
mluis | 2:14a5d6ad92d5 | 566 | mibSet.Param.JoinAcceptDelay1 = delay; |
mluis | 2:14a5d6ad92d5 | 567 | |
mluis | 2:14a5d6ad92d5 | 568 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 569 | } |
mluis | 2:14a5d6ad92d5 | 570 | |
mluis | 2:14a5d6ad92d5 | 571 | void LoRaMacSetJoinAcceptDelay2( uint32_t delay ) |
mluis | 2:14a5d6ad92d5 | 572 | { |
mluis | 2:14a5d6ad92d5 | 573 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 574 | |
mluis | 2:14a5d6ad92d5 | 575 | mibSet.Type = MIB_JOIN_ACCEPT_DELAY_2; |
mluis | 2:14a5d6ad92d5 | 576 | mibSet.Param.JoinAcceptDelay2 = delay; |
mluis | 2:14a5d6ad92d5 | 577 | |
mluis | 2:14a5d6ad92d5 | 578 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 579 | } |
mluis | 2:14a5d6ad92d5 | 580 | |
mluis | 2:14a5d6ad92d5 | 581 | void LoRaMacSetChannelsDatarate( int8_t datarate ) |
mluis | 2:14a5d6ad92d5 | 582 | { |
mluis | 2:14a5d6ad92d5 | 583 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 584 | |
mluis | 2:14a5d6ad92d5 | 585 | mibSet.Type = MIB_CHANNELS_DATARATE; |
mluis | 2:14a5d6ad92d5 | 586 | mibSet.Param.ChannelsDatarate = datarate; |
mluis | 2:14a5d6ad92d5 | 587 | |
mluis | 2:14a5d6ad92d5 | 588 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 589 | } |
mluis | 2:14a5d6ad92d5 | 590 | |
mluis | 2:14a5d6ad92d5 | 591 | void LoRaMacSetChannelsTxPower( int8_t txPower ) |
mluis | 2:14a5d6ad92d5 | 592 | { |
mluis | 2:14a5d6ad92d5 | 593 | MibRequestConfirm_t mibSet; |
mluis | 2:14a5d6ad92d5 | 594 | |
mluis | 2:14a5d6ad92d5 | 595 | mibSet.Type = MIB_CHANNELS_TX_POWER; |
mluis | 2:14a5d6ad92d5 | 596 | mibSet.Param.ChannelsTxPower = txPower; |
mluis | 2:14a5d6ad92d5 | 597 | |
mluis | 2:14a5d6ad92d5 | 598 | LoRaMacMibSetRequestConfirm( &mibSet ); |
mluis | 2:14a5d6ad92d5 | 599 | } |
mluis | 2:14a5d6ad92d5 | 600 | |
mluis | 2:14a5d6ad92d5 | 601 | uint32_t LoRaMacGetUpLinkCounter( void ) |
mluis | 2:14a5d6ad92d5 | 602 | { |
mluis | 2:14a5d6ad92d5 | 603 | MibRequestConfirm_t mibGet; |
mluis | 2:14a5d6ad92d5 | 604 | |
mluis | 2:14a5d6ad92d5 | 605 | mibGet.Type = MIB_UPLINK_COUNTER; |
mluis | 2:14a5d6ad92d5 | 606 | |
mluis | 2:14a5d6ad92d5 | 607 | LoRaMacMibGetRequestConfirm( &mibGet ); |
mluis | 2:14a5d6ad92d5 | 608 | |
mluis | 2:14a5d6ad92d5 | 609 | return mibGet.Param.UpLinkCounter; |
mluis | 2:14a5d6ad92d5 | 610 | } |
mluis | 2:14a5d6ad92d5 | 611 | |
mluis | 2:14a5d6ad92d5 | 612 | uint32_t LoRaMacGetDownLinkCounter( void ) |
mluis | 2:14a5d6ad92d5 | 613 | { |
mluis | 2:14a5d6ad92d5 | 614 | MibRequestConfirm_t mibGet; |
mluis | 2:14a5d6ad92d5 | 615 | |
mluis | 2:14a5d6ad92d5 | 616 | mibGet.Type = MIB_DOWNLINK_COUNTER; |
mluis | 2:14a5d6ad92d5 | 617 | |
mluis | 2:14a5d6ad92d5 | 618 | LoRaMacMibGetRequestConfirm( &mibGet ); |
mluis | 2:14a5d6ad92d5 | 619 | |
mluis | 2:14a5d6ad92d5 | 620 | return mibGet.Param.DownLinkCounter; |
mluis | 2:14a5d6ad92d5 | 621 | } |
mluis | 2:14a5d6ad92d5 | 622 | |
mluis | 2:14a5d6ad92d5 | 623 | void LoRaMacSetMicTest( uint16_t txPacketCounter ) |
mluis | 2:14a5d6ad92d5 | 624 | { |
mluis | 2:14a5d6ad92d5 | 625 | LoRaMacTestSetMic( txPacketCounter ); |
mluis | 2:14a5d6ad92d5 | 626 | } |