Application example using LoRaWAN-lib MAC layer implementation

Dependencies:   mbed LoRaWAN-lib SX1276Lib

Dependents:   LoRaWAN-mbed-client-ttn0

LoRaWAN-demo is a ClassA device example project using LoRaWAN-lib and SX1276Lib libraries.

This demo application sends a frame every 4 to 6 seconds (randomly) and displays its current status using a serial port as display(VT100).

The serial port settings are as shown in below image. To access the serial port settings please click on "Setup" menu and then "Serial port..."

/media/uploads/mluis/serial_port_settings.png

The terminal window should be setup as shown in below image. To access the terminal window settings please click on "Setup" menu and then "Terminal..."

/media/uploads/mluis/terminal_window_settings.png

The image below shows the VT100 application status.

Application main screen

The application gives the possibility to either activate the device using

  • Over The Air Activation (OTAA)
  • Personalization activation (PA)

The activation mode can be adjusted in Comissioning.h by changing the following parameter:

/*!
 * When set to 1 the application uses the Over-the-Air activation procedure
 * When set to 0 the application uses the Personalization activation procedure
 */
#define OVER_THE_AIR_ACTIVATION                     1


The application gives the possibility to select which kind of network we are connecting to.

  • Public Network (true)
  • Private Network (false)

The netork type can be changed as follows:

/*!
 * Indicates if the end-device is to be connected to a private or public network
 */
#define LORAWAN_PUBLIC_NETWORK                      true


OTAA
When OTAA is selected the user must porvide a device EUI, an application EUI and an application key.
These can be adjusted by changing the following parameters:

/*!
 * Mote device IEEE EUI (big endian)
 */
#define LORAWAN_DEVICE_EUI                          { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }

/*!
 * Application IEEE EUI (big endian)
 */
#define LORAWAN_APPLICATION_EUI                     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

/*!
 * AES encryption/decryption cipher application key
 */
#define LORAWAN_APPLICATION_KEY                     { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }


PA
When PA is selected the user must porvide a network ID, a device address, a network session key and an application session key.
These can be adjusted by changing the following parameters:

/*!
 * Current network ID
 */
#define LORAWAN_NETWORK_ID                          ( uint32_t )0

/*!
 * Device address on the network (big endian)
 */
#define LORAWAN_DEVICE_ADDRESS                      ( uint32_t )0x12345678

/*!
 * AES encryption/decryption cipher network session key
 */
#define LORAWAN_NWKSKEY                             { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }

/*!
 * AES encryption/decryption cipher application session key
 */
#define LORAWAN_APPSKEY                             { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }


On top of main.c the user has the possibility to tweak some application settings such as:

  • Join requests transmission frequency
  • Frames transmission frequency
  • Application default datarate
  • Confirmed or Unconfirmed frames transmission
  • ADR (Adaptive Datarate) ON/OFF
  • Application port to be used by the transmitted frames

The join requests transmission frequency can be adjusted by changing the follwoing parameter:

/*!
 * Join requests trials duty cycle.
 */
#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE           10000000  // 10 [s] value in us


The frame transmission frequency can be adjusted by changing the follwoing parameters:

/*!
 * Defines the application data transmission duty cycle. 5s, value in [us].
 */
#define APP_TX_DUTYCYCLE                            5000000

/*!
 * Defines a random delay for application data transmission duty cycle. 1s,
 * value in [us].
 */
#define APP_TX_DUTYCYCLE_RND                        1000000


The frame transmission scheduling is then executed as follows:

        if( ScheduleNextTx == true )
        {
            ScheduleNextTx = false;
            // Schedule next packet transmission
            TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
            TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
            TimerStart( &TxNextPacketTimer );
        }


The application default datarate can be adjusted by changing the following parameter:

Quote:

When ADR is off this setting is the fixed datarate that will be used by the application.
When ADR is on this setting is the initial datarate used by the application.

/*!
 * Default mote datarate
 */
#define LORAWAN_DEFAULT_DATARATE                    DR_0


The transmitted frame contents will depend on LORAWAN_CONFIRMED_MSG_ON value.

/*!
 * LoRaWAN confirmed messages
 */
#define LORAWAN_CONFIRMED_MSG_ON                    true
  • If LORAWAN_CONFIRMED_MSG_ON equals false then the application payload is one byte corresponding to the AppLed state.
  • If LORAWAN_CONFIRMED_MSG_ON equals true then the application payload is six bytes corresponding to the AppLed state, Downlink counter (unsigned 16 bits), received RSSI (signed 16 bits) and received SNR (signed 8 bits).

/*!
 * \brief   Prepares the payload of the frame
 */
static void PrepareTxFrame( uint8_t port )
{

    switch( port )
    {
    case 15:
        {
            AppData[0] = AppLedStateOn;
            if( IsTxConfirmed == true )
            {
                AppData[1] = LoRaMacDownlinkStatus.DownlinkCounter >> 8;
                AppData[2] = LoRaMacDownlinkStatus.DownlinkCounter;
                AppData[3] = LoRaMacDownlinkStatus.Rssi >> 8;
                AppData[4] = LoRaMacDownlinkStatus.Rssi;
                AppData[5] = LoRaMacDownlinkStatus.Snr;
            }
        }
        break;
    case 224:
...
}


The ADR enabling/disabling can be adjusted by changing the following parameter:

/*!
 * LoRaWAN Adaptive Data Rate
 *
 * \remark Please note that when ADR is enabled the end-device should be static
 */
#define LORAWAN_ADR_ON                              1


The application port can be adjusted by changing the following parameter:

/*!
 * LoRaWAN application port
 */
#define LORAWAN_APP_PORT                            15
Committer:
mluis
Date:
Mon Apr 24 13:38:31 2017 +0000
Revision:
9:ee9dcbb9708d
Parent:
7:3173f0508a98
WARNING: Radio API timings changed from micro-seconds to milliseconds; ; Synchronized with https://github.com/Lora-net/LoRaMac-node git revision e506c246652fa44c3f24cecb89d0707b49ece739; Updated all libraries to the latest versions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mluis 0:92bca02df485 1 /*
mluis 0:92bca02df485 2 / _____) _ | |
mluis 0:92bca02df485 3 ( (____ _____ ____ _| |_ _____ ____| |__
mluis 0:92bca02df485 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
mluis 0:92bca02df485 5 _____) ) ____| | | || |_| ____( (___| | | |
mluis 0:92bca02df485 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 0:92bca02df485 7 (C)2015 Semtech
mluis 0:92bca02df485 8
mluis 0:92bca02df485 9 Description: LoRaMac classA device implementation
mluis 0:92bca02df485 10
mluis 0:92bca02df485 11 License: Revised BSD License, see LICENSE.TXT file include in the project
mluis 0:92bca02df485 12
mluis 0:92bca02df485 13 Maintainer: Miguel Luis and Gregory Cristian
mluis 0:92bca02df485 14 */
mluis 0:92bca02df485 15 #include "mbed.h"
mluis 0:92bca02df485 16 #include "board.h"
mluis 0:92bca02df485 17 #include "radio.h"
mluis 0:92bca02df485 18
mluis 0:92bca02df485 19 #include "LoRaMac.h"
mluis 9:ee9dcbb9708d 20 #include "Commissioning.h"
mluis 0:92bca02df485 21 #include "SerialDisplay.h"
mluis 0:92bca02df485 22
mluis 0:92bca02df485 23 /*!
mluis 9:ee9dcbb9708d 24 * Defines the application data transmission duty cycle. 5s, value in [ms].
mluis 0:92bca02df485 25 */
mluis 9:ee9dcbb9708d 26 #define APP_TX_DUTYCYCLE 5000
mluis 1:352f608c3337 27
mluis 1:352f608c3337 28 /*!
mluis 1:352f608c3337 29 * Defines a random delay for application data transmission duty cycle. 1s,
mluis 9:ee9dcbb9708d 30 * value in [ms].
mluis 1:352f608c3337 31 */
mluis 9:ee9dcbb9708d 32 #define APP_TX_DUTYCYCLE_RND 1000
mluis 0:92bca02df485 33
mluis 0:92bca02df485 34 /*!
mluis 5:1e9f6a365854 35 * Default datarate
mluis 3:9c6f7f082151 36 */
mluis 3:9c6f7f082151 37 #define LORAWAN_DEFAULT_DATARATE DR_0
mluis 3:9c6f7f082151 38
mluis 3:9c6f7f082151 39 /*!
mluis 0:92bca02df485 40 * LoRaWAN confirmed messages
mluis 0:92bca02df485 41 */
mluis 0:92bca02df485 42 #define LORAWAN_CONFIRMED_MSG_ON true
mluis 0:92bca02df485 43
mluis 0:92bca02df485 44 /*!
mluis 3:9c6f7f082151 45 * LoRaWAN Adaptive Data Rate
mluis 0:92bca02df485 46 *
mluis 0:92bca02df485 47 * \remark Please note that when ADR is enabled the end-device should be static
mluis 0:92bca02df485 48 */
mluis 0:92bca02df485 49 #define LORAWAN_ADR_ON 1
mluis 0:92bca02df485 50
mluis 1:352f608c3337 51 #if defined( USE_BAND_868 )
mluis 1:352f608c3337 52
mluis 3:9c6f7f082151 53 #include "LoRaMacTest.h"
mluis 3:9c6f7f082151 54
mluis 0:92bca02df485 55 /*!
mluis 0:92bca02df485 56 * LoRaWAN ETSI duty cycle control enable/disable
mluis 0:92bca02df485 57 *
mluis 0:92bca02df485 58 * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes
mluis 0:92bca02df485 59 */
mluis 9:ee9dcbb9708d 60 #define LORAWAN_DUTYCYCLE_ON false
mluis 0:92bca02df485 61
mluis 5:1e9f6a365854 62 #define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP 1
mluis 5:1e9f6a365854 63
mluis 9:ee9dcbb9708d 64 #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 )
mluis 5:1e9f6a365854 65
mluis 5:1e9f6a365854 66 #define LC4 { 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
mluis 5:1e9f6a365854 67 #define LC5 { 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
mluis 5:1e9f6a365854 68 #define LC6 { 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
mluis 5:1e9f6a365854 69 #define LC7 { 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
mluis 5:1e9f6a365854 70 #define LC8 { 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
mluis 5:1e9f6a365854 71 #define LC9 { 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 }
mluis 5:1e9f6a365854 72 #define LC10 { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 }
mluis 5:1e9f6a365854 73
mluis 5:1e9f6a365854 74 #endif
mluis 5:1e9f6a365854 75
mluis 1:352f608c3337 76 #endif
mluis 1:352f608c3337 77
mluis 0:92bca02df485 78 /*!
mluis 0:92bca02df485 79 * LoRaWAN application port
mluis 0:92bca02df485 80 */
mluis 0:92bca02df485 81 #define LORAWAN_APP_PORT 15
mluis 0:92bca02df485 82
mluis 0:92bca02df485 83 /*!
mluis 0:92bca02df485 84 * User application data buffer size
mluis 0:92bca02df485 85 */
mluis 0:92bca02df485 86 #if ( LORAWAN_CONFIRMED_MSG_ON == 1 )
mluis 0:92bca02df485 87 #define LORAWAN_APP_DATA_SIZE 6
mluis 0:92bca02df485 88
mluis 0:92bca02df485 89 #else
mluis 0:92bca02df485 90 #define LORAWAN_APP_DATA_SIZE 1
mluis 0:92bca02df485 91
mluis 0:92bca02df485 92 #endif
mluis 0:92bca02df485 93
mluis 0:92bca02df485 94 static uint8_t DevEui[] = LORAWAN_DEVICE_EUI;
mluis 0:92bca02df485 95 static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI;
mluis 0:92bca02df485 96 static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY;
mluis 0:92bca02df485 97
mluis 7:3173f0508a98 98 #if( OVER_THE_AIR_ACTIVATION == 0 )
mluis 0:92bca02df485 99
mluis 0:92bca02df485 100 static uint8_t NwkSKey[] = LORAWAN_NWKSKEY;
mluis 0:92bca02df485 101 static uint8_t AppSKey[] = LORAWAN_APPSKEY;
mluis 0:92bca02df485 102
mluis 3:9c6f7f082151 103 /*!
mluis 3:9c6f7f082151 104 * Device address
mluis 3:9c6f7f082151 105 */
mluis 3:9c6f7f082151 106 static uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS;
mluis 0:92bca02df485 107
mluis 3:9c6f7f082151 108 #endif
mluis 0:92bca02df485 109
mluis 0:92bca02df485 110 /*!
mluis 1:352f608c3337 111 * Application port
mluis 1:352f608c3337 112 */
mluis 1:352f608c3337 113 static uint8_t AppPort = LORAWAN_APP_PORT;
mluis 1:352f608c3337 114
mluis 1:352f608c3337 115 /*!
mluis 1:352f608c3337 116 * User application data size
mluis 1:352f608c3337 117 */
mluis 1:352f608c3337 118 static uint8_t AppDataSize = LORAWAN_APP_DATA_SIZE;
mluis 1:352f608c3337 119
mluis 1:352f608c3337 120 /*!
mluis 1:352f608c3337 121 * User application data buffer size
mluis 1:352f608c3337 122 */
mluis 1:352f608c3337 123 #define LORAWAN_APP_DATA_MAX_SIZE 64
mluis 1:352f608c3337 124
mluis 1:352f608c3337 125 /*!
mluis 0:92bca02df485 126 * User application data
mluis 0:92bca02df485 127 */
mluis 1:352f608c3337 128 static uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE];
mluis 1:352f608c3337 129
mluis 1:352f608c3337 130 /*!
mluis 1:352f608c3337 131 * Indicates if the node is sending confirmed or unconfirmed messages
mluis 1:352f608c3337 132 */
mluis 1:352f608c3337 133 static uint8_t IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
mluis 0:92bca02df485 134
mluis 0:92bca02df485 135 /*!
mluis 0:92bca02df485 136 * Defines the application data transmission duty cycle
mluis 0:92bca02df485 137 */
mluis 0:92bca02df485 138 static uint32_t TxDutyCycleTime;
mluis 0:92bca02df485 139
mluis 1:352f608c3337 140 /*!
mluis 1:352f608c3337 141 * Timer to handle the application data transmission duty cycle
mluis 1:352f608c3337 142 */
mluis 1:352f608c3337 143 static TimerEvent_t TxNextPacketTimer;
mluis 0:92bca02df485 144
mluis 3:9c6f7f082151 145 /*!
mluis 3:9c6f7f082151 146 * Specifies the state of the application LED
mluis 3:9c6f7f082151 147 */
mluis 3:9c6f7f082151 148 static bool AppLedStateOn = false;
mluis 3:9c6f7f082151 149 volatile bool Led3StateChanged = false;
mluis 0:92bca02df485 150 /*!
mluis 3:9c6f7f082151 151 * Timer to handle the state of LED1
mluis 0:92bca02df485 152 */
mluis 3:9c6f7f082151 153 static TimerEvent_t Led1Timer;
mluis 3:9c6f7f082151 154 volatile bool Led1State = false;
mluis 3:9c6f7f082151 155 volatile bool Led1StateChanged = false;
mluis 3:9c6f7f082151 156 /*!
mluis 3:9c6f7f082151 157 * Timer to handle the state of LED2
mluis 3:9c6f7f082151 158 */
mluis 3:9c6f7f082151 159 static TimerEvent_t Led2Timer;
mluis 3:9c6f7f082151 160 volatile bool Led2State = false;
mluis 3:9c6f7f082151 161 volatile bool Led2StateChanged = false;
mluis 0:92bca02df485 162
mluis 0:92bca02df485 163 /*!
mluis 0:92bca02df485 164 * Indicates if a new packet can be sent
mluis 0:92bca02df485 165 */
mluis 3:9c6f7f082151 166 static bool NextTx = true;
mluis 0:92bca02df485 167
mluis 3:9c6f7f082151 168 /*!
mluis 3:9c6f7f082151 169 * Device states
mluis 3:9c6f7f082151 170 */
mluis 9:ee9dcbb9708d 171 static enum eDeviceState
mluis 3:9c6f7f082151 172 {
mluis 3:9c6f7f082151 173 DEVICE_STATE_INIT,
mluis 3:9c6f7f082151 174 DEVICE_STATE_JOIN,
mluis 3:9c6f7f082151 175 DEVICE_STATE_SEND,
mluis 3:9c6f7f082151 176 DEVICE_STATE_CYCLE,
mluis 3:9c6f7f082151 177 DEVICE_STATE_SLEEP
mluis 3:9c6f7f082151 178 }DeviceState;
mluis 0:92bca02df485 179
mluis 3:9c6f7f082151 180 /*!
mluis 3:9c6f7f082151 181 * LoRaWAN compliance tests support data
mluis 3:9c6f7f082151 182 */
mluis 3:9c6f7f082151 183 struct ComplianceTest_s
mluis 3:9c6f7f082151 184 {
mluis 3:9c6f7f082151 185 bool Running;
mluis 3:9c6f7f082151 186 uint8_t State;
mluis 3:9c6f7f082151 187 bool IsTxConfirmed;
mluis 3:9c6f7f082151 188 uint8_t AppPort;
mluis 3:9c6f7f082151 189 uint8_t AppDataSize;
mluis 3:9c6f7f082151 190 uint8_t *AppDataBuffer;
mluis 3:9c6f7f082151 191 uint16_t DownLinkCounter;
mluis 3:9c6f7f082151 192 bool LinkCheck;
mluis 3:9c6f7f082151 193 uint8_t DemodMargin;
mluis 3:9c6f7f082151 194 uint8_t NbGateways;
mluis 3:9c6f7f082151 195 }ComplianceTest;
mluis 0:92bca02df485 196
mluis 3:9c6f7f082151 197 /*
mluis 3:9c6f7f082151 198 * SerialDisplay managment variables
mluis 3:9c6f7f082151 199 */
mluis 1:352f608c3337 200
mluis 3:9c6f7f082151 201 /*!
mluis 3:9c6f7f082151 202 * Indicates if the MAC layer network join status has changed.
mluis 3:9c6f7f082151 203 */
mluis 3:9c6f7f082151 204 static bool IsNetworkJoinedStatusUpdate = false;
mluis 3:9c6f7f082151 205
mluis 3:9c6f7f082151 206 /*!
mluis 3:9c6f7f082151 207 * Strucure containing the Uplink status
mluis 3:9c6f7f082151 208 */
mluis 0:92bca02df485 209 struct sLoRaMacUplinkStatus
mluis 0:92bca02df485 210 {
mluis 0:92bca02df485 211 uint8_t Acked;
mluis 0:92bca02df485 212 int8_t Datarate;
mluis 0:92bca02df485 213 uint16_t UplinkCounter;
mluis 0:92bca02df485 214 uint8_t Port;
mluis 0:92bca02df485 215 uint8_t *Buffer;
mluis 0:92bca02df485 216 uint8_t BufferSize;
mluis 0:92bca02df485 217 }LoRaMacUplinkStatus;
mluis 3:9c6f7f082151 218 volatile bool UplinkStatusUpdated = false;
mluis 0:92bca02df485 219
mluis 3:9c6f7f082151 220 /*!
mluis 3:9c6f7f082151 221 * Strucure containing the Downlink status
mluis 3:9c6f7f082151 222 */
mluis 0:92bca02df485 223 struct sLoRaMacDownlinkStatus
mluis 0:92bca02df485 224 {
mluis 0:92bca02df485 225 int16_t Rssi;
mluis 0:92bca02df485 226 int8_t Snr;
mluis 0:92bca02df485 227 uint16_t DownlinkCounter;
mluis 0:92bca02df485 228 bool RxData;
mluis 0:92bca02df485 229 uint8_t Port;
mluis 0:92bca02df485 230 uint8_t *Buffer;
mluis 0:92bca02df485 231 uint8_t BufferSize;
mluis 0:92bca02df485 232 }LoRaMacDownlinkStatus;
mluis 3:9c6f7f082151 233 volatile bool DownlinkStatusUpdated = false;
mluis 0:92bca02df485 234
mluis 0:92bca02df485 235 void SerialDisplayRefresh( void )
mluis 0:92bca02df485 236 {
mluis 3:9c6f7f082151 237 MibRequestConfirm_t mibReq;
mluis 3:9c6f7f082151 238
mluis 0:92bca02df485 239 SerialDisplayInit( );
mluis 0:92bca02df485 240 SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
mluis 0:92bca02df485 241
mluis 0:92bca02df485 242 #if( OVER_THE_AIR_ACTIVATION == 0 )
mluis 0:92bca02df485 243 SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
mluis 3:9c6f7f082151 244 SerialDisplayUpdateDevAddr( DevAddr );
mluis 0:92bca02df485 245 SerialDisplayUpdateKey( 12, NwkSKey );
mluis 0:92bca02df485 246 SerialDisplayUpdateKey( 13, AppSKey );
mluis 7:3173f0508a98 247 #endif
mluis 0:92bca02df485 248 SerialDisplayUpdateEui( 5, DevEui );
mluis 0:92bca02df485 249 SerialDisplayUpdateEui( 6, AppEui );
mluis 0:92bca02df485 250 SerialDisplayUpdateKey( 7, AppKey );
mluis 3:9c6f7f082151 251
mluis 3:9c6f7f082151 252 mibReq.Type = MIB_NETWORK_JOINED;
mluis 3:9c6f7f082151 253 LoRaMacMibGetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 254 SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
mluis 0:92bca02df485 255
mluis 0:92bca02df485 256 SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
mluis 1:352f608c3337 257 #if defined( USE_BAND_868 )
mluis 0:92bca02df485 258 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
mluis 1:352f608c3337 259 #else
mluis 1:352f608c3337 260 SerialDisplayUpdateDutyCycle( false );
mluis 1:352f608c3337 261 #endif
mluis 0:92bca02df485 262 SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
mluis 0:92bca02df485 263
mluis 0:92bca02df485 264 SerialDisplayUpdateLedState( 3, AppLedStateOn );
mluis 0:92bca02df485 265 }
mluis 0:92bca02df485 266
mluis 0:92bca02df485 267 void SerialRxProcess( void )
mluis 0:92bca02df485 268 {
mluis 0:92bca02df485 269 if( SerialDisplayReadable( ) == true )
mluis 0:92bca02df485 270 {
mluis 0:92bca02df485 271 switch( SerialDisplayGetChar( ) )
mluis 0:92bca02df485 272 {
mluis 0:92bca02df485 273 case 'R':
mluis 0:92bca02df485 274 case 'r':
mluis 0:92bca02df485 275 // Refresh Serial screen
mluis 0:92bca02df485 276 SerialDisplayRefresh( );
mluis 0:92bca02df485 277 break;
mluis 0:92bca02df485 278 default:
mluis 0:92bca02df485 279 break;
mluis 0:92bca02df485 280 }
mluis 0:92bca02df485 281 }
mluis 0:92bca02df485 282 }
mluis 0:92bca02df485 283
mluis 0:92bca02df485 284 /*!
mluis 3:9c6f7f082151 285 * \brief Prepares the payload of the frame
mluis 0:92bca02df485 286 */
mluis 0:92bca02df485 287 static void PrepareTxFrame( uint8_t port )
mluis 0:92bca02df485 288 {
mluis 1:352f608c3337 289 switch( port )
mluis 1:352f608c3337 290 {
mluis 1:352f608c3337 291 case 15:
mluis 1:352f608c3337 292 {
mluis 1:352f608c3337 293 AppData[0] = AppLedStateOn;
mluis 1:352f608c3337 294 if( IsTxConfirmed == true )
mluis 1:352f608c3337 295 {
mluis 1:352f608c3337 296 AppData[1] = LoRaMacDownlinkStatus.DownlinkCounter >> 8;
mluis 1:352f608c3337 297 AppData[2] = LoRaMacDownlinkStatus.DownlinkCounter;
mluis 1:352f608c3337 298 AppData[3] = LoRaMacDownlinkStatus.Rssi >> 8;
mluis 1:352f608c3337 299 AppData[4] = LoRaMacDownlinkStatus.Rssi;
mluis 1:352f608c3337 300 AppData[5] = LoRaMacDownlinkStatus.Snr;
mluis 1:352f608c3337 301 }
mluis 1:352f608c3337 302 }
mluis 1:352f608c3337 303 break;
mluis 1:352f608c3337 304 case 224:
mluis 3:9c6f7f082151 305 if( ComplianceTest.LinkCheck == true )
mluis 1:352f608c3337 306 {
mluis 3:9c6f7f082151 307 ComplianceTest.LinkCheck = false;
mluis 1:352f608c3337 308 AppDataSize = 3;
mluis 1:352f608c3337 309 AppData[0] = 5;
mluis 3:9c6f7f082151 310 AppData[1] = ComplianceTest.DemodMargin;
mluis 3:9c6f7f082151 311 AppData[2] = ComplianceTest.NbGateways;
mluis 3:9c6f7f082151 312 ComplianceTest.State = 1;
mluis 1:352f608c3337 313 }
mluis 1:352f608c3337 314 else
mluis 1:352f608c3337 315 {
mluis 3:9c6f7f082151 316 switch( ComplianceTest.State )
mluis 1:352f608c3337 317 {
mluis 1:352f608c3337 318 case 4:
mluis 3:9c6f7f082151 319 ComplianceTest.State = 1;
mluis 1:352f608c3337 320 break;
mluis 1:352f608c3337 321 case 1:
mluis 1:352f608c3337 322 AppDataSize = 2;
mluis 3:9c6f7f082151 323 AppData[0] = ComplianceTest.DownLinkCounter >> 8;
mluis 3:9c6f7f082151 324 AppData[1] = ComplianceTest.DownLinkCounter;
mluis 1:352f608c3337 325 break;
mluis 1:352f608c3337 326 }
mluis 1:352f608c3337 327 }
mluis 1:352f608c3337 328 break;
mluis 3:9c6f7f082151 329 default:
mluis 3:9c6f7f082151 330 break;
mluis 1:352f608c3337 331 }
mluis 0:92bca02df485 332 }
mluis 0:92bca02df485 333
mluis 3:9c6f7f082151 334 /*!
mluis 3:9c6f7f082151 335 * \brief Prepares the payload of the frame
mluis 3:9c6f7f082151 336 *
mluis 3:9c6f7f082151 337 * \retval [0: frame could be send, 1: error]
mluis 3:9c6f7f082151 338 */
mluis 0:92bca02df485 339 static bool SendFrame( void )
mluis 0:92bca02df485 340 {
mluis 3:9c6f7f082151 341 McpsReq_t mcpsReq;
mluis 3:9c6f7f082151 342 LoRaMacTxInfo_t txInfo;
mluis 9:ee9dcbb9708d 343
mluis 3:9c6f7f082151 344 if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK )
mluis 1:352f608c3337 345 {
mluis 3:9c6f7f082151 346 // Send empty frame in order to flush MAC commands
mluis 3:9c6f7f082151 347 mcpsReq.Type = MCPS_UNCONFIRMED;
mluis 3:9c6f7f082151 348 mcpsReq.Req.Unconfirmed.fBuffer = NULL;
mluis 3:9c6f7f082151 349 mcpsReq.Req.Unconfirmed.fBufferSize = 0;
mluis 3:9c6f7f082151 350 mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
mluis 5:1e9f6a365854 351
mluis 3:9c6f7f082151 352 LoRaMacUplinkStatus.Acked = false;
mluis 3:9c6f7f082151 353 LoRaMacUplinkStatus.Port = 0;
mluis 3:9c6f7f082151 354 LoRaMacUplinkStatus.Buffer = NULL;
mluis 3:9c6f7f082151 355 LoRaMacUplinkStatus.BufferSize = 0;
mluis 3:9c6f7f082151 356 SerialDisplayUpdateFrameType( false );
mluis 1:352f608c3337 357 }
mluis 1:352f608c3337 358 else
mluis 1:352f608c3337 359 {
mluis 3:9c6f7f082151 360 LoRaMacUplinkStatus.Acked = false;
mluis 3:9c6f7f082151 361 LoRaMacUplinkStatus.Port = AppPort;
mluis 3:9c6f7f082151 362 LoRaMacUplinkStatus.Buffer = AppData;
mluis 3:9c6f7f082151 363 LoRaMacUplinkStatus.BufferSize = AppDataSize;
mluis 3:9c6f7f082151 364 SerialDisplayUpdateFrameType( IsTxConfirmed );
mluis 3:9c6f7f082151 365
mluis 3:9c6f7f082151 366 if( IsTxConfirmed == false )
mluis 3:9c6f7f082151 367 {
mluis 3:9c6f7f082151 368 mcpsReq.Type = MCPS_UNCONFIRMED;
mluis 3:9c6f7f082151 369 mcpsReq.Req.Unconfirmed.fPort = AppPort;
mluis 3:9c6f7f082151 370 mcpsReq.Req.Unconfirmed.fBuffer = AppData;
mluis 3:9c6f7f082151 371 mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize;
mluis 3:9c6f7f082151 372 mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
mluis 3:9c6f7f082151 373 }
mluis 3:9c6f7f082151 374 else
mluis 3:9c6f7f082151 375 {
mluis 3:9c6f7f082151 376 mcpsReq.Type = MCPS_CONFIRMED;
mluis 3:9c6f7f082151 377 mcpsReq.Req.Confirmed.fPort = AppPort;
mluis 3:9c6f7f082151 378 mcpsReq.Req.Confirmed.fBuffer = AppData;
mluis 3:9c6f7f082151 379 mcpsReq.Req.Confirmed.fBufferSize = AppDataSize;
mluis 4:00cf2370c99d 380 mcpsReq.Req.Confirmed.NbTrials = 8;
mluis 3:9c6f7f082151 381 mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
mluis 3:9c6f7f082151 382 }
mluis 1:352f608c3337 383 }
mluis 1:352f608c3337 384
mluis 3:9c6f7f082151 385 if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
mluis 0:92bca02df485 386 {
mluis 0:92bca02df485 387 return false;
mluis 0:92bca02df485 388 }
mluis 3:9c6f7f082151 389 return true;
mluis 0:92bca02df485 390 }
mluis 0:92bca02df485 391
mluis 0:92bca02df485 392 /*!
mluis 0:92bca02df485 393 * \brief Function executed on TxNextPacket Timeout event
mluis 0:92bca02df485 394 */
mluis 0:92bca02df485 395 static void OnTxNextPacketTimerEvent( void )
mluis 0:92bca02df485 396 {
mluis 3:9c6f7f082151 397 MibRequestConfirm_t mibReq;
mluis 3:9c6f7f082151 398 LoRaMacStatus_t status;
mluis 3:9c6f7f082151 399
mluis 0:92bca02df485 400 TimerStop( &TxNextPacketTimer );
mluis 3:9c6f7f082151 401
mluis 3:9c6f7f082151 402 mibReq.Type = MIB_NETWORK_JOINED;
mluis 3:9c6f7f082151 403 status = LoRaMacMibGetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 404
mluis 3:9c6f7f082151 405 if( status == LORAMAC_STATUS_OK )
mluis 3:9c6f7f082151 406 {
mluis 3:9c6f7f082151 407 if( mibReq.Param.IsNetworkJoined == true )
mluis 3:9c6f7f082151 408 {
mluis 3:9c6f7f082151 409 DeviceState = DEVICE_STATE_SEND;
mluis 3:9c6f7f082151 410 NextTx = true;
mluis 3:9c6f7f082151 411 }
mluis 3:9c6f7f082151 412 else
mluis 3:9c6f7f082151 413 {
mluis 3:9c6f7f082151 414 DeviceState = DEVICE_STATE_JOIN;
mluis 3:9c6f7f082151 415 }
mluis 3:9c6f7f082151 416 }
mluis 0:92bca02df485 417 }
mluis 0:92bca02df485 418
mluis 0:92bca02df485 419 /*!
mluis 0:92bca02df485 420 * \brief Function executed on Led 1 Timeout event
mluis 0:92bca02df485 421 */
mluis 0:92bca02df485 422 static void OnLed1TimerEvent( void )
mluis 0:92bca02df485 423 {
mluis 0:92bca02df485 424 TimerStop( &Led1Timer );
mluis 3:9c6f7f082151 425 // Switch LED 1 OFF
mluis 1:352f608c3337 426 Led1State = false;
mluis 0:92bca02df485 427 Led1StateChanged = true;
mluis 0:92bca02df485 428 }
mluis 0:92bca02df485 429
mluis 0:92bca02df485 430 /*!
mluis 0:92bca02df485 431 * \brief Function executed on Led 2 Timeout event
mluis 0:92bca02df485 432 */
mluis 0:92bca02df485 433 static void OnLed2TimerEvent( void )
mluis 0:92bca02df485 434 {
mluis 0:92bca02df485 435 TimerStop( &Led2Timer );
mluis 3:9c6f7f082151 436 // Switch LED 2 OFF
mluis 1:352f608c3337 437 Led2State = false;
mluis 0:92bca02df485 438 Led2StateChanged = true;
mluis 0:92bca02df485 439 }
mluis 0:92bca02df485 440
mluis 0:92bca02df485 441 /*!
mluis 3:9c6f7f082151 442 * \brief MCPS-Confirm event function
mluis 3:9c6f7f082151 443 *
mluis 5:1e9f6a365854 444 * \param [IN] mcpsConfirm - Pointer to the confirm structure,
mluis 3:9c6f7f082151 445 * containing confirm attributes.
mluis 0:92bca02df485 446 */
mluis 5:1e9f6a365854 447 static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
mluis 0:92bca02df485 448 {
mluis 5:1e9f6a365854 449 if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
mluis 0:92bca02df485 450 {
mluis 5:1e9f6a365854 451 switch( mcpsConfirm->McpsRequest )
mluis 3:9c6f7f082151 452 {
mluis 3:9c6f7f082151 453 case MCPS_UNCONFIRMED:
mluis 3:9c6f7f082151 454 {
mluis 3:9c6f7f082151 455 // Check Datarate
mluis 3:9c6f7f082151 456 // Check TxPower
mluis 3:9c6f7f082151 457 break;
mluis 3:9c6f7f082151 458 }
mluis 3:9c6f7f082151 459 case MCPS_CONFIRMED:
mluis 3:9c6f7f082151 460 {
mluis 3:9c6f7f082151 461 // Check Datarate
mluis 3:9c6f7f082151 462 // Check TxPower
mluis 3:9c6f7f082151 463 // Check AckReceived
mluis 5:1e9f6a365854 464 // Check NbTrials
mluis 5:1e9f6a365854 465 LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived;
mluis 3:9c6f7f082151 466 break;
mluis 3:9c6f7f082151 467 }
mluis 3:9c6f7f082151 468 case MCPS_PROPRIETARY:
mluis 3:9c6f7f082151 469 {
mluis 3:9c6f7f082151 470 break;
mluis 3:9c6f7f082151 471 }
mluis 3:9c6f7f082151 472 default:
mluis 3:9c6f7f082151 473 break;
mluis 3:9c6f7f082151 474 }
mluis 5:1e9f6a365854 475 LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate;
mluis 5:1e9f6a365854 476 LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter;
mluis 5:1e9f6a365854 477
mluis 7:3173f0508a98 478 // Switch LED 1 ON
mluis 7:3173f0508a98 479 Led1State = true;
mluis 7:3173f0508a98 480 Led1StateChanged = true;
mluis 7:3173f0508a98 481 TimerStart( &Led1Timer );
mluis 7:3173f0508a98 482
mluis 3:9c6f7f082151 483 UplinkStatusUpdated = true;
mluis 3:9c6f7f082151 484 }
mluis 3:9c6f7f082151 485 NextTx = true;
mluis 3:9c6f7f082151 486 }
mluis 3:9c6f7f082151 487
mluis 3:9c6f7f082151 488 /*!
mluis 3:9c6f7f082151 489 * \brief MCPS-Indication event function
mluis 3:9c6f7f082151 490 *
mluis 5:1e9f6a365854 491 * \param [IN] mcpsIndication - Pointer to the indication structure,
mluis 3:9c6f7f082151 492 * containing indication attributes.
mluis 3:9c6f7f082151 493 */
mluis 5:1e9f6a365854 494 static void McpsIndication( McpsIndication_t *mcpsIndication )
mluis 3:9c6f7f082151 495 {
mluis 5:1e9f6a365854 496 if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
mluis 3:9c6f7f082151 497 {
mluis 3:9c6f7f082151 498 return;
mluis 3:9c6f7f082151 499 }
mluis 3:9c6f7f082151 500
mluis 5:1e9f6a365854 501 switch( mcpsIndication->McpsIndication )
mluis 3:9c6f7f082151 502 {
mluis 3:9c6f7f082151 503 case MCPS_UNCONFIRMED:
mluis 3:9c6f7f082151 504 {
mluis 3:9c6f7f082151 505 break;
mluis 3:9c6f7f082151 506 }
mluis 3:9c6f7f082151 507 case MCPS_CONFIRMED:
mluis 3:9c6f7f082151 508 {
mluis 3:9c6f7f082151 509 break;
mluis 3:9c6f7f082151 510 }
mluis 3:9c6f7f082151 511 case MCPS_PROPRIETARY:
mluis 3:9c6f7f082151 512 {
mluis 3:9c6f7f082151 513 break;
mluis 3:9c6f7f082151 514 }
mluis 3:9c6f7f082151 515 case MCPS_MULTICAST:
mluis 3:9c6f7f082151 516 {
mluis 3:9c6f7f082151 517 break;
mluis 3:9c6f7f082151 518 }
mluis 3:9c6f7f082151 519 default:
mluis 3:9c6f7f082151 520 break;
mluis 3:9c6f7f082151 521 }
mluis 3:9c6f7f082151 522
mluis 3:9c6f7f082151 523 // Check Multicast
mluis 3:9c6f7f082151 524 // Check Port
mluis 3:9c6f7f082151 525 // Check Datarate
mluis 3:9c6f7f082151 526 // Check FramePending
mluis 3:9c6f7f082151 527 // Check Buffer
mluis 3:9c6f7f082151 528 // Check BufferSize
mluis 3:9c6f7f082151 529 // Check Rssi
mluis 3:9c6f7f082151 530 // Check Snr
mluis 3:9c6f7f082151 531 // Check RxSlot
mluis 5:1e9f6a365854 532 LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi;
mluis 5:1e9f6a365854 533 if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
mluis 3:9c6f7f082151 534 {
mluis 3:9c6f7f082151 535 // Invert and divide by 4
mluis 5:1e9f6a365854 536 LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2;
mluis 3:9c6f7f082151 537 LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr;
mluis 0:92bca02df485 538 }
mluis 0:92bca02df485 539 else
mluis 0:92bca02df485 540 {
mluis 3:9c6f7f082151 541 // Divide by 4
mluis 5:1e9f6a365854 542 LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2;
mluis 3:9c6f7f082151 543 }
mluis 3:9c6f7f082151 544 LoRaMacDownlinkStatus.DownlinkCounter++;
mluis 5:1e9f6a365854 545 LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData;
mluis 5:1e9f6a365854 546 LoRaMacDownlinkStatus.Port = mcpsIndication->Port;
mluis 5:1e9f6a365854 547 LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer;
mluis 5:1e9f6a365854 548 LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize;
mluis 3:9c6f7f082151 549
mluis 3:9c6f7f082151 550 if( ComplianceTest.Running == true )
mluis 3:9c6f7f082151 551 {
mluis 3:9c6f7f082151 552 ComplianceTest.DownLinkCounter++;
mluis 3:9c6f7f082151 553 }
mluis 0:92bca02df485 554
mluis 5:1e9f6a365854 555 if( mcpsIndication->RxData == true )
mluis 3:9c6f7f082151 556 {
mluis 5:1e9f6a365854 557 switch( mcpsIndication->Port )
mluis 0:92bca02df485 558 {
mluis 3:9c6f7f082151 559 case 1: // The application LED can be controlled on port 1 or 2
mluis 3:9c6f7f082151 560 case 2:
mluis 5:1e9f6a365854 561 if( mcpsIndication->BufferSize == 1 )
mluis 1:352f608c3337 562 {
mluis 5:1e9f6a365854 563 AppLedStateOn = mcpsIndication->Buffer[0] & 0x01;
mluis 3:9c6f7f082151 564 Led3StateChanged = true;
mluis 3:9c6f7f082151 565 }
mluis 3:9c6f7f082151 566 break;
mluis 3:9c6f7f082151 567 case 224:
mluis 3:9c6f7f082151 568 if( ComplianceTest.Running == false )
mluis 3:9c6f7f082151 569 {
mluis 3:9c6f7f082151 570 // Check compliance test enable command (i)
mluis 5:1e9f6a365854 571 if( ( mcpsIndication->BufferSize == 4 ) &&
mluis 5:1e9f6a365854 572 ( mcpsIndication->Buffer[0] == 0x01 ) &&
mluis 5:1e9f6a365854 573 ( mcpsIndication->Buffer[1] == 0x01 ) &&
mluis 5:1e9f6a365854 574 ( mcpsIndication->Buffer[2] == 0x01 ) &&
mluis 5:1e9f6a365854 575 ( mcpsIndication->Buffer[3] == 0x01 ) )
mluis 1:352f608c3337 576 {
mluis 3:9c6f7f082151 577 IsTxConfirmed = false;
mluis 3:9c6f7f082151 578 AppPort = 224;
mluis 3:9c6f7f082151 579 AppDataSize = 2;
mluis 3:9c6f7f082151 580 ComplianceTest.DownLinkCounter = 0;
mluis 3:9c6f7f082151 581 ComplianceTest.LinkCheck = false;
mluis 3:9c6f7f082151 582 ComplianceTest.DemodMargin = 0;
mluis 3:9c6f7f082151 583 ComplianceTest.NbGateways = 0;
mluis 3:9c6f7f082151 584 ComplianceTest.Running = true;
mluis 3:9c6f7f082151 585 ComplianceTest.State = 1;
mluis 9:ee9dcbb9708d 586
mluis 3:9c6f7f082151 587 MibRequestConfirm_t mibReq;
mluis 3:9c6f7f082151 588 mibReq.Type = MIB_ADR;
mluis 3:9c6f7f082151 589 mibReq.Param.AdrEnable = true;
mluis 3:9c6f7f082151 590 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 591
mluis 3:9c6f7f082151 592 #if defined( USE_BAND_868 )
mluis 3:9c6f7f082151 593 LoRaMacTestSetDutyCycleOn( false );
mluis 3:9c6f7f082151 594 #endif
mluis 1:352f608c3337 595 }
mluis 1:352f608c3337 596 }
mluis 0:92bca02df485 597 else
mluis 0:92bca02df485 598 {
mluis 5:1e9f6a365854 599 ComplianceTest.State = mcpsIndication->Buffer[0];
mluis 3:9c6f7f082151 600 switch( ComplianceTest.State )
mluis 3:9c6f7f082151 601 {
mluis 3:9c6f7f082151 602 case 0: // Check compliance test disable command (ii)
mluis 3:9c6f7f082151 603 IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
mluis 3:9c6f7f082151 604 AppPort = LORAWAN_APP_PORT;
mluis 3:9c6f7f082151 605 AppDataSize = LORAWAN_APP_DATA_SIZE;
mluis 3:9c6f7f082151 606 ComplianceTest.DownLinkCounter = 0;
mluis 3:9c6f7f082151 607 ComplianceTest.Running = false;
mluis 9:ee9dcbb9708d 608
mluis 3:9c6f7f082151 609 MibRequestConfirm_t mibReq;
mluis 3:9c6f7f082151 610 mibReq.Type = MIB_ADR;
mluis 3:9c6f7f082151 611 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
mluis 3:9c6f7f082151 612 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 613 #if defined( USE_BAND_868 )
mluis 3:9c6f7f082151 614 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
mluis 3:9c6f7f082151 615 #endif
mluis 3:9c6f7f082151 616 break;
mluis 3:9c6f7f082151 617 case 1: // (iii, iv)
mluis 3:9c6f7f082151 618 AppDataSize = 2;
mluis 3:9c6f7f082151 619 break;
mluis 3:9c6f7f082151 620 case 2: // Enable confirmed messages (v)
mluis 3:9c6f7f082151 621 IsTxConfirmed = true;
mluis 3:9c6f7f082151 622 ComplianceTest.State = 1;
mluis 3:9c6f7f082151 623 break;
mluis 3:9c6f7f082151 624 case 3: // Disable confirmed messages (vi)
mluis 3:9c6f7f082151 625 IsTxConfirmed = false;
mluis 3:9c6f7f082151 626 ComplianceTest.State = 1;
mluis 3:9c6f7f082151 627 break;
mluis 3:9c6f7f082151 628 case 4: // (vii)
mluis 5:1e9f6a365854 629 AppDataSize = mcpsIndication->BufferSize;
mluis 3:9c6f7f082151 630
mluis 3:9c6f7f082151 631 AppData[0] = 4;
mluis 3:9c6f7f082151 632 for( uint8_t i = 1; i < AppDataSize; i++ )
mluis 3:9c6f7f082151 633 {
mluis 5:1e9f6a365854 634 AppData[i] = mcpsIndication->Buffer[i] + 1;
mluis 3:9c6f7f082151 635 }
mluis 3:9c6f7f082151 636 break;
mluis 3:9c6f7f082151 637 case 5: // (viii)
mluis 3:9c6f7f082151 638 {
mluis 3:9c6f7f082151 639 MlmeReq_t mlmeReq;
mluis 3:9c6f7f082151 640 mlmeReq.Type = MLME_LINK_CHECK;
mluis 3:9c6f7f082151 641 LoRaMacMlmeRequest( &mlmeReq );
mluis 3:9c6f7f082151 642 }
mluis 3:9c6f7f082151 643 break;
mluis 7:3173f0508a98 644 case 6: // (ix)
mluis 7:3173f0508a98 645 {
mluis 7:3173f0508a98 646 MlmeReq_t mlmeReq;
mluis 7:3173f0508a98 647
mluis 9:ee9dcbb9708d 648 // Disable TestMode and revert back to normal operation
mluis 9:ee9dcbb9708d 649 IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
mluis 9:ee9dcbb9708d 650 AppPort = LORAWAN_APP_PORT;
mluis 9:ee9dcbb9708d 651 AppDataSize = LORAWAN_APP_DATA_SIZE;
mluis 9:ee9dcbb9708d 652 ComplianceTest.DownLinkCounter = 0;
mluis 9:ee9dcbb9708d 653 ComplianceTest.Running = false;
mluis 9:ee9dcbb9708d 654
mluis 9:ee9dcbb9708d 655 MibRequestConfirm_t mibReq;
mluis 9:ee9dcbb9708d 656 mibReq.Type = MIB_ADR;
mluis 9:ee9dcbb9708d 657 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
mluis 9:ee9dcbb9708d 658 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 9:ee9dcbb9708d 659 #if defined( USE_BAND_868 )
mluis 9:ee9dcbb9708d 660 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
mluis 9:ee9dcbb9708d 661 #endif
mluis 9:ee9dcbb9708d 662
mluis 7:3173f0508a98 663 mlmeReq.Type = MLME_JOIN;
mluis 7:3173f0508a98 664
mluis 7:3173f0508a98 665 mlmeReq.Req.Join.DevEui = DevEui;
mluis 7:3173f0508a98 666 mlmeReq.Req.Join.AppEui = AppEui;
mluis 7:3173f0508a98 667 mlmeReq.Req.Join.AppKey = AppKey;
mluis 9:ee9dcbb9708d 668 mlmeReq.Req.Join.NbTrials = 3;
mluis 7:3173f0508a98 669
mluis 7:3173f0508a98 670 LoRaMacMlmeRequest( &mlmeReq );
mluis 7:3173f0508a98 671 DeviceState = DEVICE_STATE_SLEEP;
mluis 7:3173f0508a98 672 }
mluis 7:3173f0508a98 673 break;
mluis 9:ee9dcbb9708d 674 case 7: // (x)
mluis 9:ee9dcbb9708d 675 {
mluis 9:ee9dcbb9708d 676 if( mcpsIndication->BufferSize == 3 )
mluis 9:ee9dcbb9708d 677 {
mluis 9:ee9dcbb9708d 678 MlmeReq_t mlmeReq;
mluis 9:ee9dcbb9708d 679 mlmeReq.Type = MLME_TXCW;
mluis 9:ee9dcbb9708d 680 mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] );
mluis 9:ee9dcbb9708d 681 LoRaMacMlmeRequest( &mlmeReq );
mluis 9:ee9dcbb9708d 682 }
mluis 9:ee9dcbb9708d 683 else if( mcpsIndication->BufferSize == 7 )
mluis 9:ee9dcbb9708d 684 {
mluis 9:ee9dcbb9708d 685 MlmeReq_t mlmeReq;
mluis 9:ee9dcbb9708d 686 mlmeReq.Type = MLME_TXCW_1;
mluis 9:ee9dcbb9708d 687 mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] );
mluis 9:ee9dcbb9708d 688 mlmeReq.Req.TxCw.Frequency = ( uint32_t )( ( mcpsIndication->Buffer[3] << 16 ) | ( mcpsIndication->Buffer[4] << 8 ) | mcpsIndication->Buffer[5] ) * 100;
mluis 9:ee9dcbb9708d 689 mlmeReq.Req.TxCw.Power = mcpsIndication->Buffer[6];
mluis 9:ee9dcbb9708d 690 LoRaMacMlmeRequest( &mlmeReq );
mluis 9:ee9dcbb9708d 691 }
mluis 9:ee9dcbb9708d 692 ComplianceTest.State = 1;
mluis 9:ee9dcbb9708d 693 }
mluis 9:ee9dcbb9708d 694 break;
mluis 3:9c6f7f082151 695 default:
mluis 3:9c6f7f082151 696 break;
mluis 3:9c6f7f082151 697 }
mluis 0:92bca02df485 698 }
mluis 3:9c6f7f082151 699 break;
mluis 3:9c6f7f082151 700 default:
mluis 3:9c6f7f082151 701 break;
mluis 0:92bca02df485 702 }
mluis 0:92bca02df485 703 }
mluis 1:352f608c3337 704
mluis 3:9c6f7f082151 705 // Switch LED 2 ON for each received downlink
mluis 3:9c6f7f082151 706 Led2State = true;
mluis 3:9c6f7f082151 707 Led2StateChanged = true;
mluis 3:9c6f7f082151 708 TimerStart( &Led2Timer );
mluis 3:9c6f7f082151 709 DownlinkStatusUpdated = true;
mluis 3:9c6f7f082151 710 }
mluis 3:9c6f7f082151 711
mluis 3:9c6f7f082151 712 /*!
mluis 3:9c6f7f082151 713 * \brief MLME-Confirm event function
mluis 3:9c6f7f082151 714 *
mluis 5:1e9f6a365854 715 * \param [IN] mlmeConfirm - Pointer to the confirm structure,
mluis 3:9c6f7f082151 716 * containing confirm attributes.
mluis 3:9c6f7f082151 717 */
mluis 5:1e9f6a365854 718 static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
mluis 3:9c6f7f082151 719 {
mluis 9:ee9dcbb9708d 720 switch( mlmeConfirm->MlmeRequest )
mluis 3:9c6f7f082151 721 {
mluis 9:ee9dcbb9708d 722 case MLME_JOIN:
mluis 3:9c6f7f082151 723 {
mluis 9:ee9dcbb9708d 724 if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
mluis 3:9c6f7f082151 725 {
mluis 3:9c6f7f082151 726 // Status is OK, node has joined the network
mluis 3:9c6f7f082151 727 IsNetworkJoinedStatusUpdate = true;
mluis 7:3173f0508a98 728 DeviceState = DEVICE_STATE_SEND;
mluis 9:ee9dcbb9708d 729 }
mluis 9:ee9dcbb9708d 730 else
mluis 9:ee9dcbb9708d 731 {
mluis 9:ee9dcbb9708d 732 // Join was not successful. Try to join again
mluis 9:ee9dcbb9708d 733 DeviceState = DEVICE_STATE_JOIN;
mluis 3:9c6f7f082151 734 }
mluis 9:ee9dcbb9708d 735 break;
mluis 9:ee9dcbb9708d 736 }
mluis 9:ee9dcbb9708d 737 case MLME_LINK_CHECK:
mluis 9:ee9dcbb9708d 738 {
mluis 9:ee9dcbb9708d 739 if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
mluis 3:9c6f7f082151 740 {
mluis 3:9c6f7f082151 741 // Check DemodMargin
mluis 3:9c6f7f082151 742 // Check NbGateways
mluis 3:9c6f7f082151 743 if( ComplianceTest.Running == true )
mluis 3:9c6f7f082151 744 {
mluis 3:9c6f7f082151 745 ComplianceTest.LinkCheck = true;
mluis 5:1e9f6a365854 746 ComplianceTest.DemodMargin = mlmeConfirm->DemodMargin;
mluis 5:1e9f6a365854 747 ComplianceTest.NbGateways = mlmeConfirm->NbGateways;
mluis 3:9c6f7f082151 748 }
mluis 3:9c6f7f082151 749 }
mluis 9:ee9dcbb9708d 750 break;
mluis 3:9c6f7f082151 751 }
mluis 9:ee9dcbb9708d 752 default:
mluis 9:ee9dcbb9708d 753 break;
mluis 3:9c6f7f082151 754 }
mluis 3:9c6f7f082151 755 NextTx = true;
mluis 3:9c6f7f082151 756 UplinkStatusUpdated = true;
mluis 0:92bca02df485 757 }
mluis 0:92bca02df485 758
mluis 0:92bca02df485 759 /**
mluis 0:92bca02df485 760 * Main application entry point.
mluis 0:92bca02df485 761 */
mluis 0:92bca02df485 762 int main( void )
mluis 0:92bca02df485 763 {
mluis 3:9c6f7f082151 764 LoRaMacPrimitives_t LoRaMacPrimitives;
mluis 3:9c6f7f082151 765 LoRaMacCallback_t LoRaMacCallbacks;
mluis 3:9c6f7f082151 766 MibRequestConfirm_t mibReq;
mluis 0:92bca02df485 767
mluis 0:92bca02df485 768 BoardInit( );
mluis 3:9c6f7f082151 769 SerialDisplayInit( );
mluis 0:92bca02df485 770
mluis 7:3173f0508a98 771 SerialDisplayUpdateEui( 5, DevEui );
mluis 7:3173f0508a98 772 SerialDisplayUpdateEui( 6, AppEui );
mluis 7:3173f0508a98 773 SerialDisplayUpdateKey( 7, AppKey );
mluis 7:3173f0508a98 774
mluis 7:3173f0508a98 775 #if( OVER_THE_AIR_ACTIVATION == 0 )
mluis 7:3173f0508a98 776 SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
mluis 7:3173f0508a98 777 SerialDisplayUpdateDevAddr( DevAddr );
mluis 7:3173f0508a98 778 SerialDisplayUpdateKey( 12, NwkSKey );
mluis 7:3173f0508a98 779 SerialDisplayUpdateKey( 13, AppSKey );
mluis 7:3173f0508a98 780 #endif
mluis 7:3173f0508a98 781
mluis 3:9c6f7f082151 782 DeviceState = DEVICE_STATE_INIT;
mluis 0:92bca02df485 783
mluis 0:92bca02df485 784 while( 1 )
mluis 0:92bca02df485 785 {
mluis 0:92bca02df485 786 SerialRxProcess( );
mluis 0:92bca02df485 787 if( IsNetworkJoinedStatusUpdate == true )
mluis 0:92bca02df485 788 {
mluis 0:92bca02df485 789 IsNetworkJoinedStatusUpdate = false;
mluis 3:9c6f7f082151 790 mibReq.Type = MIB_NETWORK_JOINED;
mluis 3:9c6f7f082151 791 LoRaMacMibGetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 792 SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
mluis 0:92bca02df485 793 }
mluis 0:92bca02df485 794 if( Led1StateChanged == true )
mluis 0:92bca02df485 795 {
mluis 0:92bca02df485 796 Led1StateChanged = false;
mluis 1:352f608c3337 797 SerialDisplayUpdateLedState( 1, Led1State );
mluis 0:92bca02df485 798 }
mluis 0:92bca02df485 799 if( Led2StateChanged == true )
mluis 0:92bca02df485 800 {
mluis 0:92bca02df485 801 Led2StateChanged = false;
mluis 1:352f608c3337 802 SerialDisplayUpdateLedState( 2, Led2State );
mluis 0:92bca02df485 803 }
mluis 0:92bca02df485 804 if( Led3StateChanged == true )
mluis 0:92bca02df485 805 {
mluis 0:92bca02df485 806 Led3StateChanged = false;
mluis 0:92bca02df485 807 SerialDisplayUpdateLedState( 3, AppLedStateOn );
mluis 0:92bca02df485 808 }
mluis 3:9c6f7f082151 809 if( UplinkStatusUpdated == true )
mluis 0:92bca02df485 810 {
mluis 3:9c6f7f082151 811 UplinkStatusUpdated = false;
mluis 3:9c6f7f082151 812 SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize );
mluis 3:9c6f7f082151 813 }
mluis 3:9c6f7f082151 814 if( DownlinkStatusUpdated == true )
mluis 3:9c6f7f082151 815 {
mluis 3:9c6f7f082151 816 DownlinkStatusUpdated = false;
mluis 1:352f608c3337 817 SerialDisplayUpdateLedState( 2, Led2State );
mluis 0:92bca02df485 818 SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize );
mluis 0:92bca02df485 819 }
mluis 3:9c6f7f082151 820
mluis 3:9c6f7f082151 821 switch( DeviceState )
mluis 0:92bca02df485 822 {
mluis 3:9c6f7f082151 823 case DEVICE_STATE_INIT:
mluis 3:9c6f7f082151 824 {
mluis 3:9c6f7f082151 825 LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
mluis 3:9c6f7f082151 826 LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
mluis 3:9c6f7f082151 827 LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
mluis 3:9c6f7f082151 828 LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
mluis 3:9c6f7f082151 829 LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks );
mluis 3:9c6f7f082151 830
mluis 3:9c6f7f082151 831 TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );
mluis 3:9c6f7f082151 832
mluis 3:9c6f7f082151 833 TimerInit( &Led1Timer, OnLed1TimerEvent );
mluis 9:ee9dcbb9708d 834 TimerSetValue( &Led1Timer, 25 );
mluis 3:9c6f7f082151 835
mluis 3:9c6f7f082151 836 TimerInit( &Led2Timer, OnLed2TimerEvent );
mluis 9:ee9dcbb9708d 837 TimerSetValue( &Led2Timer, 25 );
mluis 3:9c6f7f082151 838
mluis 3:9c6f7f082151 839 mibReq.Type = MIB_ADR;
mluis 3:9c6f7f082151 840 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
mluis 3:9c6f7f082151 841 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 842
mluis 3:9c6f7f082151 843 mibReq.Type = MIB_PUBLIC_NETWORK;
mluis 3:9c6f7f082151 844 mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
mluis 3:9c6f7f082151 845 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 846
mluis 3:9c6f7f082151 847 #if defined( USE_BAND_868 )
mluis 3:9c6f7f082151 848 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
mluis 3:9c6f7f082151 849 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
mluis 5:1e9f6a365854 850
mluis 9:ee9dcbb9708d 851 #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 )
mluis 5:1e9f6a365854 852 LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 );
mluis 5:1e9f6a365854 853 LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 );
mluis 5:1e9f6a365854 854 LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 );
mluis 5:1e9f6a365854 855 LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 );
mluis 5:1e9f6a365854 856 LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 );
mluis 5:1e9f6a365854 857 LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 );
mluis 5:1e9f6a365854 858 LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 );
mluis 7:3173f0508a98 859
mluis 9:ee9dcbb9708d 860 mibReq.Type = MIB_RX2_DEFAULT_CHANNEL;
mluis 9:ee9dcbb9708d 861 mibReq.Param.Rx2DefaultChannel = ( Rx2ChannelParams_t ){ 869525000, DR_3 };
mluis 9:ee9dcbb9708d 862 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 9:ee9dcbb9708d 863
mluis 7:3173f0508a98 864 mibReq.Type = MIB_RX2_CHANNEL;
mluis 7:3173f0508a98 865 mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 };
mluis 7:3173f0508a98 866 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 5:1e9f6a365854 867 #endif
mluis 5:1e9f6a365854 868
mluis 3:9c6f7f082151 869 #endif
mluis 3:9c6f7f082151 870 SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
mluis 3:9c6f7f082151 871 SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
mluis 3:9c6f7f082151 872 SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
mluis 3:9c6f7f082151 873
mluis 3:9c6f7f082151 874 LoRaMacDownlinkStatus.DownlinkCounter = 0;
mluis 3:9c6f7f082151 875
mluis 3:9c6f7f082151 876 DeviceState = DEVICE_STATE_JOIN;
mluis 3:9c6f7f082151 877 break;
mluis 3:9c6f7f082151 878 }
mluis 3:9c6f7f082151 879 case DEVICE_STATE_JOIN:
mluis 3:9c6f7f082151 880 {
mluis 3:9c6f7f082151 881 #if( OVER_THE_AIR_ACTIVATION != 0 )
mluis 3:9c6f7f082151 882 MlmeReq_t mlmeReq;
mluis 3:9c6f7f082151 883
mluis 3:9c6f7f082151 884 mlmeReq.Type = MLME_JOIN;
mluis 3:9c6f7f082151 885
mluis 3:9c6f7f082151 886 mlmeReq.Req.Join.DevEui = DevEui;
mluis 3:9c6f7f082151 887 mlmeReq.Req.Join.AppEui = AppEui;
mluis 3:9c6f7f082151 888 mlmeReq.Req.Join.AppKey = AppKey;
mluis 3:9c6f7f082151 889
mluis 3:9c6f7f082151 890 if( NextTx == true )
mluis 3:9c6f7f082151 891 {
mluis 3:9c6f7f082151 892 LoRaMacMlmeRequest( &mlmeReq );
mluis 3:9c6f7f082151 893 }
mluis 7:3173f0508a98 894 DeviceState = DEVICE_STATE_SLEEP;
mluis 3:9c6f7f082151 895 #else
mluis 3:9c6f7f082151 896 mibReq.Type = MIB_NET_ID;
mluis 3:9c6f7f082151 897 mibReq.Param.NetID = LORAWAN_NETWORK_ID;
mluis 3:9c6f7f082151 898 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 899
mluis 3:9c6f7f082151 900 mibReq.Type = MIB_DEV_ADDR;
mluis 3:9c6f7f082151 901 mibReq.Param.DevAddr = DevAddr;
mluis 3:9c6f7f082151 902 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 903
mluis 3:9c6f7f082151 904 mibReq.Type = MIB_NWK_SKEY;
mluis 3:9c6f7f082151 905 mibReq.Param.NwkSKey = NwkSKey;
mluis 3:9c6f7f082151 906 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 907
mluis 3:9c6f7f082151 908 mibReq.Type = MIB_APP_SKEY;
mluis 3:9c6f7f082151 909 mibReq.Param.AppSKey = AppSKey;
mluis 3:9c6f7f082151 910 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 911
mluis 3:9c6f7f082151 912 mibReq.Type = MIB_NETWORK_JOINED;
mluis 3:9c6f7f082151 913 mibReq.Param.IsNetworkJoined = true;
mluis 3:9c6f7f082151 914 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 3:9c6f7f082151 915
mluis 3:9c6f7f082151 916 DeviceState = DEVICE_STATE_SEND;
mluis 3:9c6f7f082151 917 #endif
mluis 3:9c6f7f082151 918 IsNetworkJoinedStatusUpdate = true;
mluis 3:9c6f7f082151 919 break;
mluis 3:9c6f7f082151 920 }
mluis 3:9c6f7f082151 921 case DEVICE_STATE_SEND:
mluis 3:9c6f7f082151 922 {
mluis 3:9c6f7f082151 923 if( NextTx == true )
mluis 3:9c6f7f082151 924 {
mluis 3:9c6f7f082151 925 SerialDisplayUpdateUplinkAcked( false );
mluis 3:9c6f7f082151 926 SerialDisplayUpdateDonwlinkRxData( false );
mluis 3:9c6f7f082151 927 PrepareTxFrame( AppPort );
mluis 3:9c6f7f082151 928
mluis 3:9c6f7f082151 929 NextTx = SendFrame( );
mluis 3:9c6f7f082151 930 }
mluis 3:9c6f7f082151 931 if( ComplianceTest.Running == true )
mluis 3:9c6f7f082151 932 {
mluis 5:1e9f6a365854 933 // Schedule next packet transmission
mluis 9:ee9dcbb9708d 934 TxDutyCycleTime = 5000; // 5000 ms
mluis 3:9c6f7f082151 935 }
mluis 3:9c6f7f082151 936 else
mluis 3:9c6f7f082151 937 {
mluis 3:9c6f7f082151 938 // Schedule next packet transmission
mluis 3:9c6f7f082151 939 TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
mluis 3:9c6f7f082151 940 }
mluis 3:9c6f7f082151 941 DeviceState = DEVICE_STATE_CYCLE;
mluis 3:9c6f7f082151 942 break;
mluis 3:9c6f7f082151 943 }
mluis 3:9c6f7f082151 944 case DEVICE_STATE_CYCLE:
mluis 3:9c6f7f082151 945 {
mluis 5:1e9f6a365854 946 DeviceState = DEVICE_STATE_SLEEP;
mluis 5:1e9f6a365854 947
mluis 3:9c6f7f082151 948 // Schedule next packet transmission
mluis 1:352f608c3337 949 TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
mluis 1:352f608c3337 950 TimerStart( &TxNextPacketTimer );
mluis 3:9c6f7f082151 951 break;
mluis 3:9c6f7f082151 952 }
mluis 3:9c6f7f082151 953 case DEVICE_STATE_SLEEP:
mluis 3:9c6f7f082151 954 {
mluis 3:9c6f7f082151 955 // Wake up through events
mluis 3:9c6f7f082151 956 break;
mluis 3:9c6f7f082151 957 }
mluis 3:9c6f7f082151 958 default:
mluis 3:9c6f7f082151 959 {
mluis 3:9c6f7f082151 960 DeviceState = DEVICE_STATE_INIT;
mluis 3:9c6f7f082151 961 break;
mluis 3:9c6f7f082151 962 }
mluis 0:92bca02df485 963 }
mluis 0:92bca02df485 964 }
mluis 0:92bca02df485 965 }