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

Revision:
18:18408c3c2d0c
Parent:
12:504203733f11
--- a/app/ComplianceTest.cpp	Sun Apr 16 23:12:47 2017 +0000
+++ b/app/ComplianceTest.cpp	Mon Apr 24 13:47:27 2017 +0000
@@ -16,18 +16,19 @@
 #include "ComplianceTest.h"
 
 
-void PrepareComplianceTestFrame( McpsIndication_t *McpsIndication )
+void PrepareComplianceTestFrame( McpsIndication_t *mcpsIndication )
 {
     uint8_t *pData;
 
-    pData = &McpsIndication->Buffer[0];
+    pData = &mcpsIndication->Buffer[0];
     
     if( ComplianceTest.Running == false )
     {
         // Check compliance test enable command (i)
-        if( ( McpsIndication->BufferSize == 4 ) && 
+        if( ( mcpsIndication->BufferSize == 4 ) && 
             ( pData[0] == 0x01 ) && ( pData[1] == 0x01 ) && ( pData[2] == 0x01 ) && (pData[3] == 0x01 ) )
         {
+            IsTxConfirmed = false;
             AppPort = 224;
             AppDataSize = 2;
             ComplianceTest.DownLinkCounter = 0;
@@ -35,7 +36,14 @@
             ComplianceTest.DemodMargin = 0;
             ComplianceTest.NbGateways = 0;
             ComplianceTest.Running = true;
-            ComplianceTest.State = 1;       
+            ComplianceTest.State = 1;
+
+            MibRequestConfirm_t mibReq;
+            mibReq.Type = MIB_ADR;
+            mibReq.Param.AdrEnable = true;
+            LoRaMacMibSetRequestConfirm( &mibReq );
+
+            Gps.enable( false );
         }
     }
     else
@@ -44,16 +52,7 @@
         switch( ComplianceTest.State )
         {
         case 0: // Check compliance test disable command (ii)
-            IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
-            AppPort = LORAWAN_APP_PORT;
-            AppDataSize = LORAWAN_APP_DATA_SIZE;
-            ComplianceTest.DownLinkCounter = 0;
-            ComplianceTest.Running = false;
-            
-            MibRequestConfirm_t mibReq;
-            mibReq.Type = MIB_ADR;
-            mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
-            LoRaMacMibSetRequestConfirm( &mibReq );
+            DisableComplianceTest( );
             break;
         case 1: // (iii, iv)
             AppDataSize = 2;
@@ -67,12 +66,15 @@
             ComplianceTest.State = 1;
             break;
         case 4: // (vii)
-            AppDataSize = McpsIndication->BufferSize;
-
+            AppDataSize = mcpsIndication->BufferSize;
+            
+            if( AppDataSize > LORAWAN_APP_DATA_MAX_SIZE )
+                AppDataSize = LORAWAN_APP_DATA_MAX_SIZE;
+            
             AppData[0] = 4;
             for( uint8_t i = 1; i < AppDataSize; i++ )
             {
-                AppData[i] = McpsIndication->Buffer[i] + 1;
+                AppData[i] = mcpsIndication->Buffer[i] + 1; 
             }
             break;
         case 5: // (viii)
@@ -82,6 +84,37 @@
                 LoRaMacMlmeRequest( &mlmeReq );
             }
             break;
+        case 6: // (viii)
+            {
+                MlmeReq_t mlmeReq;
+
+                Otaa = true;
+
+                mlmeReq.Type = MLME_JOIN;
+
+                mlmeReq.Req.Join.DevEui = DevEui;
+                mlmeReq.Req.Join.AppEui = AppEui;
+                mlmeReq.Req.Join.AppKey = AppKey;
+                mlmeReq.Req.Join.NbTrials = 3;
+
+                LoRaMacMlmeRequest( &mlmeReq );
+
+                Gps.enable( true );
+                DeviceState = DEVICE_STATE_SLEEP;
+            }
+            break;
+        case 7: // (x)
+            {
+                if( mcpsIndication->BufferSize == 3 )
+                {
+                    MlmeReq_t mlmeReq;
+                    mlmeReq.Type = MLME_TXCW;
+                    mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] );
+                    LoRaMacMlmeRequest( &mlmeReq );
+                }
+                ComplianceTest.State = 1;
+            }
+            break;
         default:
             break;
         }
@@ -102,16 +135,33 @@
     else
     {
         switch( ComplianceTest.State )
-        {        
+        {
         case 1:
             AppDataSize = 2;
             AppData[0] = ComplianceTest.DownLinkCounter >> 8;
             AppData[1] = ComplianceTest.DownLinkCounter;
             break;
-
         case 4:
             ComplianceTest.State = 1;
             break;
+        default:
+            break;
         }
     }
-}
\ No newline at end of file
+}
+
+void DisableComplianceTest( void )
+{
+    IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
+    AppPort = LORAWAN_APP_PORT;
+    AppDataSize = LORAWAN_APP_DATA_SIZE;
+    ComplianceTest.DownLinkCounter = 0;
+    ComplianceTest.Running = false;
+    
+    MibRequestConfirm_t mibReq;
+    mibReq.Type = MIB_ADR;
+    mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
+    LoRaMacMibSetRequestConfirm( &mibReq );
+
+    Gps.enable( true );
+}