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

app/ComplianceTest.cpp

Committer:
ubhat
Date:
2016-05-17
Revision:
0:69f2e28d12c1
Child:
10:7f990e019807

File content as of revision 0:69f2e28d12c1:

/*
 / _____)             _              | |
( (____  _____ ____ _| |_ _____  ____| |__
 \____ \| ___ |    (_   _) ___ |/ ___)  _ \
 _____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
    (C)2015 Semtech

Description: Compliance Test for LoRaWAN End-Device

License: Revised BSD License, see LICENSE.TXT file include in the project

Maintainer: Uttam Bhat
*/

#include "ComplianceTest.h"


void PrepareComplianceTestFrame( McpsIndication_t *McpsIndication )
{
    uint8_t *pData;

    pData = &McpsIndication->Buffer[0];
    
    if( ComplianceTest.Running == false )
    {
        // Check compliance test enable command (i)
        if( ( McpsIndication->BufferSize == 4 ) && 
            ( pData[0] == 0x01 ) && ( pData[1] == 0x01 ) && ( pData[2] == 0x01 ) && (pData[3] == 0x01 ) )
        {
            AppPort = 224;
            AppDataSize = 2;
            ComplianceTest.DownLinkCounter = 0;
            ComplianceTest.LinkCheck = false;
            ComplianceTest.DemodMargin = 0;
            ComplianceTest.NbGateways = 0;
            ComplianceTest.Running = true;
            ComplianceTest.State = 1;       
        }
    }
    else
    {    
        ComplianceTest.State = pData[0];
        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 );
            break;
        case 1: // (iii, iv)
            AppDataSize = 2;
            break;
        case 2: // Enable confirmed messages (v)
            IsTxConfirmed = true;
            ComplianceTest.State = 1;
            break;
        case 3:  // Disable confirmed messages (vi)
            IsTxConfirmed = false;
            ComplianceTest.State = 1;
            break;
        case 4: // (vii)
            AppDataSize = McpsIndication->BufferSize;

            AppData[0] = 4;
            for( uint8_t i = 1; i < AppDataSize; i++ )
            {
                AppData[i] = McpsIndication->Buffer[i] + 1;
            }
            break;
        case 5: // (viii)
            {
                MlmeReq_t mlmeReq;
                mlmeReq.Type = MLME_LINK_CHECK;
                LoRaMacMlmeRequest( &mlmeReq );
            }
            break;
        default:
            break;
        }
    }
}

void RunComplianceTest( void )
{
    if( ComplianceTest.LinkCheck == true )
    {
        ComplianceTest.LinkCheck = false;
        AppDataSize = 3;
        AppData[0] = 5;
        AppData[1] = ComplianceTest.DemodMargin;
        AppData[2] = ComplianceTest.NbGateways;
        ComplianceTest.State = 1;
    }
    else
    {
        switch( ComplianceTest.State )
        {        
        case 1:
            AppDataSize = 2;
            AppData[0] = ComplianceTest.DownLinkCounter >> 8;
            AppData[1] = ComplianceTest.DownLinkCounter;
            break;

        case 4:
            ComplianceTest.State = 1;
            break;
        }
    }
}