1

Dependencies:   X_NUCLEO_IKS01A1 LoRaWAN-lib SX1276Lib mbed

Committer:
ubhat
Date:
Fri Aug 26 19:36:35 2016 +0000
Revision:
0:42863a11464a
SX1276 Shield based Applications

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ubhat 0:42863a11464a 1 /*
ubhat 0:42863a11464a 2 / _____) _ | |
ubhat 0:42863a11464a 3 ( (____ _____ ____ _| |_ _____ ____| |__
ubhat 0:42863a11464a 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
ubhat 0:42863a11464a 5 _____) ) ____| | | || |_| ____( (___| | | |
ubhat 0:42863a11464a 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
ubhat 0:42863a11464a 7 (C)2015 Semtech
ubhat 0:42863a11464a 8
ubhat 0:42863a11464a 9 Description: Compliance Test for LoRaWAN End-Device
ubhat 0:42863a11464a 10
ubhat 0:42863a11464a 11 License: Revised BSD License, see LICENSE.TXT file include in the project
ubhat 0:42863a11464a 12
ubhat 0:42863a11464a 13 Maintainer: Uttam Bhat
ubhat 0:42863a11464a 14 */
ubhat 0:42863a11464a 15
ubhat 0:42863a11464a 16 #include "ComplianceTest.h"
ubhat 0:42863a11464a 17
ubhat 0:42863a11464a 18
ubhat 0:42863a11464a 19 void PrepareComplianceTestFrame( McpsIndication_t *McpsIndication )
ubhat 0:42863a11464a 20 {
ubhat 0:42863a11464a 21 uint8_t *pData;
ubhat 0:42863a11464a 22
ubhat 0:42863a11464a 23 pData = &McpsIndication->Buffer[0];
ubhat 0:42863a11464a 24
ubhat 0:42863a11464a 25 if( ComplianceTest.Running == false )
ubhat 0:42863a11464a 26 {
ubhat 0:42863a11464a 27 // Check compliance test enable command (i)
ubhat 0:42863a11464a 28 if( ( McpsIndication->BufferSize == 4 ) &&
ubhat 0:42863a11464a 29 ( pData[0] == 0x01 ) && ( pData[1] == 0x01 ) && ( pData[2] == 0x01 ) && (pData[3] == 0x01 ) )
ubhat 0:42863a11464a 30 {
ubhat 0:42863a11464a 31 AppPort = 224;
ubhat 0:42863a11464a 32 AppDataSize = 2;
ubhat 0:42863a11464a 33 ComplianceTest.DownLinkCounter = 0;
ubhat 0:42863a11464a 34 ComplianceTest.LinkCheck = false;
ubhat 0:42863a11464a 35 ComplianceTest.DemodMargin = 0;
ubhat 0:42863a11464a 36 ComplianceTest.NbGateways = 0;
ubhat 0:42863a11464a 37 ComplianceTest.Running = true;
ubhat 0:42863a11464a 38 ComplianceTest.State = 1;
ubhat 0:42863a11464a 39 }
ubhat 0:42863a11464a 40 }
ubhat 0:42863a11464a 41 else
ubhat 0:42863a11464a 42 {
ubhat 0:42863a11464a 43 ComplianceTest.State = pData[0];
ubhat 0:42863a11464a 44 switch( ComplianceTest.State )
ubhat 0:42863a11464a 45 {
ubhat 0:42863a11464a 46 case 0: // Check compliance test disable command (ii)
ubhat 0:42863a11464a 47 IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
ubhat 0:42863a11464a 48 AppPort = LORAWAN_APP_PORT;
ubhat 0:42863a11464a 49 AppDataSize = LORAWAN_APP_DATA_SIZE;
ubhat 0:42863a11464a 50 ComplianceTest.DownLinkCounter = 0;
ubhat 0:42863a11464a 51 ComplianceTest.Running = false;
ubhat 0:42863a11464a 52
ubhat 0:42863a11464a 53 MibRequestConfirm_t mibReq;
ubhat 0:42863a11464a 54 mibReq.Type = MIB_ADR;
ubhat 0:42863a11464a 55 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
ubhat 0:42863a11464a 56 LoRaMacMibSetRequestConfirm( &mibReq );
ubhat 0:42863a11464a 57 break;
ubhat 0:42863a11464a 58 case 1: // (iii, iv)
ubhat 0:42863a11464a 59 AppDataSize = 2;
ubhat 0:42863a11464a 60 break;
ubhat 0:42863a11464a 61 case 2: // Enable confirmed messages (v)
ubhat 0:42863a11464a 62 IsTxConfirmed = true;
ubhat 0:42863a11464a 63 ComplianceTest.State = 1;
ubhat 0:42863a11464a 64 break;
ubhat 0:42863a11464a 65 case 3: // Disable confirmed messages (vi)
ubhat 0:42863a11464a 66 IsTxConfirmed = false;
ubhat 0:42863a11464a 67 ComplianceTest.State = 1;
ubhat 0:42863a11464a 68 break;
ubhat 0:42863a11464a 69 case 4: // (vii)
ubhat 0:42863a11464a 70 AppDataSize = McpsIndication->BufferSize;
ubhat 0:42863a11464a 71
ubhat 0:42863a11464a 72 AppData[0] = 4;
ubhat 0:42863a11464a 73 for( uint8_t i = 1; i < AppDataSize; i++ )
ubhat 0:42863a11464a 74 {
ubhat 0:42863a11464a 75 AppData[i] = McpsIndication->Buffer[i] + 1;
ubhat 0:42863a11464a 76 }
ubhat 0:42863a11464a 77 break;
ubhat 0:42863a11464a 78 case 5: // (viii)
ubhat 0:42863a11464a 79 {
ubhat 0:42863a11464a 80 MlmeReq_t mlmeReq;
ubhat 0:42863a11464a 81 mlmeReq.Type = MLME_LINK_CHECK;
ubhat 0:42863a11464a 82 LoRaMacMlmeRequest( &mlmeReq );
ubhat 0:42863a11464a 83 }
ubhat 0:42863a11464a 84 break;
ubhat 0:42863a11464a 85 default:
ubhat 0:42863a11464a 86 break;
ubhat 0:42863a11464a 87 }
ubhat 0:42863a11464a 88 }
ubhat 0:42863a11464a 89 }
ubhat 0:42863a11464a 90
ubhat 0:42863a11464a 91 void RunComplianceTest( void )
ubhat 0:42863a11464a 92 {
ubhat 0:42863a11464a 93 if( ComplianceTest.LinkCheck == true )
ubhat 0:42863a11464a 94 {
ubhat 0:42863a11464a 95 ComplianceTest.LinkCheck = false;
ubhat 0:42863a11464a 96 AppDataSize = 3;
ubhat 0:42863a11464a 97 AppData[0] = 5;
ubhat 0:42863a11464a 98 AppData[1] = ComplianceTest.DemodMargin;
ubhat 0:42863a11464a 99 AppData[2] = ComplianceTest.NbGateways;
ubhat 0:42863a11464a 100 ComplianceTest.State = 1;
ubhat 0:42863a11464a 101 }
ubhat 0:42863a11464a 102 else
ubhat 0:42863a11464a 103 {
ubhat 0:42863a11464a 104 switch( ComplianceTest.State )
ubhat 0:42863a11464a 105 {
ubhat 0:42863a11464a 106 case 1:
ubhat 0:42863a11464a 107 AppDataSize = 2;
ubhat 0:42863a11464a 108 AppData[0] = ComplianceTest.DownLinkCounter >> 8;
ubhat 0:42863a11464a 109 AppData[1] = ComplianceTest.DownLinkCounter;
ubhat 0:42863a11464a 110 break;
ubhat 0:42863a11464a 111
ubhat 0:42863a11464a 112 case 4:
ubhat 0:42863a11464a 113 ComplianceTest.State = 1;
ubhat 0:42863a11464a 114 break;
ubhat 0:42863a11464a 115 }
ubhat 0:42863a11464a 116 }
ubhat 0:42863a11464a 117 }