mQ Branch for NA mote testing

Dependencies:   LoRaWAN-lib SX1272Lib-mQ lib_gps lib_mma8451q lib_mpl3115a2 mbed

Fork of LoRaWAN-NAMote72-Application-Demo by Semtech

Committer:
Benedict_Tizzano
Date:
Fri Mar 30 19:02:45 2018 +0000
Revision:
19:e136bd75eabd
Parent:
18:18408c3c2d0c
mQ Branch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ubhat 0:69f2e28d12c1 1 /*
ubhat 0:69f2e28d12c1 2 / _____) _ | |
ubhat 0:69f2e28d12c1 3 ( (____ _____ ____ _| |_ _____ ____| |__
ubhat 0:69f2e28d12c1 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
ubhat 0:69f2e28d12c1 5 _____) ) ____| | | || |_| ____( (___| | | |
ubhat 0:69f2e28d12c1 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
ubhat 0:69f2e28d12c1 7 (C)2015 Semtech
ubhat 0:69f2e28d12c1 8
ubhat 0:69f2e28d12c1 9 Description: Compliance Test for LoRaWAN End-Device
ubhat 0:69f2e28d12c1 10
ubhat 0:69f2e28d12c1 11 License: Revised BSD License, see LICENSE.TXT file include in the project
ubhat 0:69f2e28d12c1 12
ubhat 0:69f2e28d12c1 13 Maintainer: Uttam Bhat
ubhat 0:69f2e28d12c1 14 */
ubhat 0:69f2e28d12c1 15
ubhat 0:69f2e28d12c1 16 #include "ComplianceTest.h"
ubhat 0:69f2e28d12c1 17
ubhat 0:69f2e28d12c1 18
mluis 18:18408c3c2d0c 19 void PrepareComplianceTestFrame( McpsIndication_t *mcpsIndication )
ubhat 0:69f2e28d12c1 20 {
ubhat 0:69f2e28d12c1 21 uint8_t *pData;
ubhat 0:69f2e28d12c1 22
mluis 18:18408c3c2d0c 23 pData = &mcpsIndication->Buffer[0];
ubhat 0:69f2e28d12c1 24
ubhat 0:69f2e28d12c1 25 if( ComplianceTest.Running == false )
ubhat 0:69f2e28d12c1 26 {
ubhat 0:69f2e28d12c1 27 // Check compliance test enable command (i)
mluis 18:18408c3c2d0c 28 if( ( mcpsIndication->BufferSize == 4 ) &&
ubhat 0:69f2e28d12c1 29 ( pData[0] == 0x01 ) && ( pData[1] == 0x01 ) && ( pData[2] == 0x01 ) && (pData[3] == 0x01 ) )
ubhat 0:69f2e28d12c1 30 {
mluis 18:18408c3c2d0c 31 IsTxConfirmed = false;
ubhat 0:69f2e28d12c1 32 AppPort = 224;
ubhat 0:69f2e28d12c1 33 AppDataSize = 2;
ubhat 0:69f2e28d12c1 34 ComplianceTest.DownLinkCounter = 0;
ubhat 0:69f2e28d12c1 35 ComplianceTest.LinkCheck = false;
ubhat 0:69f2e28d12c1 36 ComplianceTest.DemodMargin = 0;
ubhat 0:69f2e28d12c1 37 ComplianceTest.NbGateways = 0;
ubhat 0:69f2e28d12c1 38 ComplianceTest.Running = true;
mluis 18:18408c3c2d0c 39 ComplianceTest.State = 1;
mluis 18:18408c3c2d0c 40
mluis 18:18408c3c2d0c 41 MibRequestConfirm_t mibReq;
mluis 18:18408c3c2d0c 42 mibReq.Type = MIB_ADR;
mluis 18:18408c3c2d0c 43 mibReq.Param.AdrEnable = true;
mluis 18:18408c3c2d0c 44 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 18:18408c3c2d0c 45
mluis 18:18408c3c2d0c 46 Gps.enable( false );
ubhat 0:69f2e28d12c1 47 }
ubhat 0:69f2e28d12c1 48 }
ubhat 0:69f2e28d12c1 49 else
ubhat 0:69f2e28d12c1 50 {
ubhat 0:69f2e28d12c1 51 ComplianceTest.State = pData[0];
ubhat 0:69f2e28d12c1 52 switch( ComplianceTest.State )
ubhat 0:69f2e28d12c1 53 {
ubhat 0:69f2e28d12c1 54 case 0: // Check compliance test disable command (ii)
mluis 18:18408c3c2d0c 55 DisableComplianceTest( );
ubhat 0:69f2e28d12c1 56 break;
ubhat 0:69f2e28d12c1 57 case 1: // (iii, iv)
ubhat 0:69f2e28d12c1 58 AppDataSize = 2;
ubhat 0:69f2e28d12c1 59 break;
ubhat 0:69f2e28d12c1 60 case 2: // Enable confirmed messages (v)
ubhat 0:69f2e28d12c1 61 IsTxConfirmed = true;
ubhat 0:69f2e28d12c1 62 ComplianceTest.State = 1;
ubhat 0:69f2e28d12c1 63 break;
ubhat 0:69f2e28d12c1 64 case 3: // Disable confirmed messages (vi)
ubhat 0:69f2e28d12c1 65 IsTxConfirmed = false;
ubhat 0:69f2e28d12c1 66 ComplianceTest.State = 1;
ubhat 0:69f2e28d12c1 67 break;
ubhat 0:69f2e28d12c1 68 case 4: // (vii)
mluis 18:18408c3c2d0c 69 AppDataSize = mcpsIndication->BufferSize;
mluis 18:18408c3c2d0c 70
mluis 18:18408c3c2d0c 71 if( AppDataSize > LORAWAN_APP_DATA_MAX_SIZE )
mluis 18:18408c3c2d0c 72 AppDataSize = LORAWAN_APP_DATA_MAX_SIZE;
mluis 18:18408c3c2d0c 73
ubhat 0:69f2e28d12c1 74 AppData[0] = 4;
ubhat 0:69f2e28d12c1 75 for( uint8_t i = 1; i < AppDataSize; i++ )
ubhat 0:69f2e28d12c1 76 {
mluis 18:18408c3c2d0c 77 AppData[i] = mcpsIndication->Buffer[i] + 1;
ubhat 0:69f2e28d12c1 78 }
ubhat 0:69f2e28d12c1 79 break;
ubhat 0:69f2e28d12c1 80 case 5: // (viii)
ubhat 0:69f2e28d12c1 81 {
ubhat 0:69f2e28d12c1 82 MlmeReq_t mlmeReq;
ubhat 0:69f2e28d12c1 83 mlmeReq.Type = MLME_LINK_CHECK;
ubhat 0:69f2e28d12c1 84 LoRaMacMlmeRequest( &mlmeReq );
ubhat 0:69f2e28d12c1 85 }
ubhat 0:69f2e28d12c1 86 break;
mluis 18:18408c3c2d0c 87 case 6: // (viii)
mluis 18:18408c3c2d0c 88 {
mluis 18:18408c3c2d0c 89 MlmeReq_t mlmeReq;
mluis 18:18408c3c2d0c 90
mluis 18:18408c3c2d0c 91 Otaa = true;
mluis 18:18408c3c2d0c 92
mluis 18:18408c3c2d0c 93 mlmeReq.Type = MLME_JOIN;
mluis 18:18408c3c2d0c 94
mluis 18:18408c3c2d0c 95 mlmeReq.Req.Join.DevEui = DevEui;
mluis 18:18408c3c2d0c 96 mlmeReq.Req.Join.AppEui = AppEui;
mluis 18:18408c3c2d0c 97 mlmeReq.Req.Join.AppKey = AppKey;
mluis 18:18408c3c2d0c 98 mlmeReq.Req.Join.NbTrials = 3;
mluis 18:18408c3c2d0c 99
mluis 18:18408c3c2d0c 100 LoRaMacMlmeRequest( &mlmeReq );
mluis 18:18408c3c2d0c 101
mluis 18:18408c3c2d0c 102 Gps.enable( true );
mluis 18:18408c3c2d0c 103 DeviceState = DEVICE_STATE_SLEEP;
mluis 18:18408c3c2d0c 104 }
mluis 18:18408c3c2d0c 105 break;
mluis 18:18408c3c2d0c 106 case 7: // (x)
mluis 18:18408c3c2d0c 107 {
mluis 18:18408c3c2d0c 108 if( mcpsIndication->BufferSize == 3 )
mluis 18:18408c3c2d0c 109 {
mluis 18:18408c3c2d0c 110 MlmeReq_t mlmeReq;
mluis 18:18408c3c2d0c 111 mlmeReq.Type = MLME_TXCW;
mluis 18:18408c3c2d0c 112 mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] );
mluis 18:18408c3c2d0c 113 LoRaMacMlmeRequest( &mlmeReq );
mluis 18:18408c3c2d0c 114 }
mluis 18:18408c3c2d0c 115 ComplianceTest.State = 1;
mluis 18:18408c3c2d0c 116 }
mluis 18:18408c3c2d0c 117 break;
ubhat 0:69f2e28d12c1 118 default:
ubhat 0:69f2e28d12c1 119 break;
ubhat 0:69f2e28d12c1 120 }
ubhat 0:69f2e28d12c1 121 }
ubhat 0:69f2e28d12c1 122 }
ubhat 0:69f2e28d12c1 123
ubhat 0:69f2e28d12c1 124 void RunComplianceTest( void )
ubhat 0:69f2e28d12c1 125 {
ubhat 0:69f2e28d12c1 126 if( ComplianceTest.LinkCheck == true )
ubhat 0:69f2e28d12c1 127 {
ubhat 0:69f2e28d12c1 128 ComplianceTest.LinkCheck = false;
ubhat 0:69f2e28d12c1 129 AppDataSize = 3;
ubhat 0:69f2e28d12c1 130 AppData[0] = 5;
ubhat 0:69f2e28d12c1 131 AppData[1] = ComplianceTest.DemodMargin;
ubhat 0:69f2e28d12c1 132 AppData[2] = ComplianceTest.NbGateways;
ubhat 0:69f2e28d12c1 133 ComplianceTest.State = 1;
ubhat 0:69f2e28d12c1 134 }
ubhat 0:69f2e28d12c1 135 else
ubhat 0:69f2e28d12c1 136 {
ubhat 0:69f2e28d12c1 137 switch( ComplianceTest.State )
mluis 18:18408c3c2d0c 138 {
ubhat 0:69f2e28d12c1 139 case 1:
ubhat 0:69f2e28d12c1 140 AppDataSize = 2;
ubhat 0:69f2e28d12c1 141 AppData[0] = ComplianceTest.DownLinkCounter >> 8;
ubhat 0:69f2e28d12c1 142 AppData[1] = ComplianceTest.DownLinkCounter;
ubhat 0:69f2e28d12c1 143 break;
ubhat 0:69f2e28d12c1 144 case 4:
ubhat 0:69f2e28d12c1 145 ComplianceTest.State = 1;
ubhat 0:69f2e28d12c1 146 break;
mluis 18:18408c3c2d0c 147 default:
mluis 18:18408c3c2d0c 148 break;
ubhat 0:69f2e28d12c1 149 }
ubhat 0:69f2e28d12c1 150 }
mluis 18:18408c3c2d0c 151 }
mluis 18:18408c3c2d0c 152
mluis 18:18408c3c2d0c 153 void DisableComplianceTest( void )
mluis 18:18408c3c2d0c 154 {
mluis 18:18408c3c2d0c 155 IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
mluis 18:18408c3c2d0c 156 AppPort = LORAWAN_APP_PORT;
mluis 18:18408c3c2d0c 157 AppDataSize = LORAWAN_APP_DATA_SIZE;
mluis 18:18408c3c2d0c 158 ComplianceTest.DownLinkCounter = 0;
mluis 18:18408c3c2d0c 159 ComplianceTest.Running = false;
mluis 18:18408c3c2d0c 160
mluis 18:18408c3c2d0c 161 MibRequestConfirm_t mibReq;
mluis 18:18408c3c2d0c 162 mibReq.Type = MIB_ADR;
mluis 18:18408c3c2d0c 163 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
mluis 18:18408c3c2d0c 164 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 18:18408c3c2d0c 165
mluis 18:18408c3c2d0c 166 Gps.enable( true );
mluis 18:18408c3c2d0c 167 }