NAMote72 application example using LoRaWAN-lib MAC layer implementation

Dependencies:   LoRaWAN-lib SX1272Lib lib_gps lib_mpl3115a2 mbed

LoRaWAN-demo is a ClassA device example project using LoRaWAN-lib and SX1272Lib 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)
 *
 * \remark In this application the value is automatically generated by calling
 *         BoardGetUniqueId function
 */
#define LORAWAN_DEVICE_EUI                          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

/*!
 * 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)
 *
 * \remark In this application the value is automatically generated using
 *         a pseudo random generator seeded with a value derived from
 *         BoardUniqueId value
 */
#define LORAWAN_DEVICE_ADDRESS                      ( uint32_t )0x00000000

/*!
 * 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 5:
        {
            Gps.service( );
            Mpl3115a2.ReadTemperature( );
            AppData[0] = AppLedStateOn;                        // (bit 0 == 1) => LED on
            AppData[1] = ( int32_t )Mpl3115a2.Temperature;     // Signed degrees Celcius in half degree units. So, +/-63 °C
            AppData[2] = BoardGetBatteryLevel( );              // Per LoRaWAN spec; 0 = Charging; 1...254 = level, 255 = N/A
            AppData[3] = ( Gps.LatitudeBinary >> 16 ) & 0xFF;
            AppData[4] = ( Gps.LatitudeBinary >> 8 ) & 0xFF;
            AppData[5] = Gps.LatitudeBinary & 0xFF;
            AppData[6] = ( Gps.LongitudeBinary >> 16 ) & 0xFF;
            AppData[7] = ( Gps.LongitudeBinary >> 8 ) & 0xFF;
            AppData[8] = Gps.LongitudeBinary & 0xFF;

            uint16_t altitudeGps = atoi( Gps.NmeaGpsData.NmeaAltitude );
            AppData[9] = ( altitudeGps >> 8 ) & 0xFF;
            AppData[10] = altitudeGps & 0xFF;
        }
        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                            5
Committer:
mluis
Date:
Mon Apr 24 13:42:18 2017 +0000
Revision:
9:37deeefbfe45
Parent:
0:8e36e3d5d706
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:8e36e3d5d706 1 /*
mluis 0:8e36e3d5d706 2 / _____) _ | |
mluis 0:8e36e3d5d706 3 ( (____ _____ ____ _| |_ _____ ____| |__
mluis 0:8e36e3d5d706 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
mluis 0:8e36e3d5d706 5 _____) ) ____| | | || |_| ____( (___| | | |
mluis 0:8e36e3d5d706 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 0:8e36e3d5d706 7 (C)2015 Semtech
mluis 0:8e36e3d5d706 8
mluis 0:8e36e3d5d706 9 Description: VT100 serial display management
mluis 0:8e36e3d5d706 10
mluis 0:8e36e3d5d706 11 License: Revised BSD License, see LICENSE.TXT file include in the project
mluis 0:8e36e3d5d706 12
mluis 0:8e36e3d5d706 13 Maintainer: Miguel Luis and Gregory Cristian
mluis 0:8e36e3d5d706 14 */
mluis 0:8e36e3d5d706 15 #include "board.h"
mluis 0:8e36e3d5d706 16 #include "vt100.h"
mluis 0:8e36e3d5d706 17 #include "SerialDisplay.h"
mluis 0:8e36e3d5d706 18
mluis 0:8e36e3d5d706 19 VT100 vt( USBTX, USBRX );
mluis 0:8e36e3d5d706 20
mluis 0:8e36e3d5d706 21 void SerialPrintCheckBox( bool activated, uint8_t color )
mluis 0:8e36e3d5d706 22 {
mluis 0:8e36e3d5d706 23 if( activated == true )
mluis 0:8e36e3d5d706 24 {
mluis 0:8e36e3d5d706 25 vt.SetAttribute( VT100::ATTR_OFF, color, color );
mluis 0:8e36e3d5d706 26 }
mluis 0:8e36e3d5d706 27 else
mluis 0:8e36e3d5d706 28 {
mluis 0:8e36e3d5d706 29 vt.SetAttribute( VT100::ATTR_OFF );
mluis 0:8e36e3d5d706 30 }
mluis 0:8e36e3d5d706 31 vt.printf( " " );
mluis 0:8e36e3d5d706 32 vt.SetAttribute( VT100::ATTR_OFF );
mluis 0:8e36e3d5d706 33 }
mluis 0:8e36e3d5d706 34
mluis 0:8e36e3d5d706 35 void SerialDisplayUpdateActivationMode( bool otaa )
mluis 0:8e36e3d5d706 36 {
mluis 0:8e36e3d5d706 37 vt.SetCursorPos( 4, 17 );
mluis 0:8e36e3d5d706 38 SerialPrintCheckBox( otaa, VT100::WHITE );
mluis 0:8e36e3d5d706 39 vt.SetCursorPos( 9, 17 );
mluis 0:8e36e3d5d706 40 SerialPrintCheckBox( !otaa, VT100::WHITE );
mluis 0:8e36e3d5d706 41 }
mluis 0:8e36e3d5d706 42
mluis 0:8e36e3d5d706 43 void SerialDisplayUpdateEui( uint8_t line, uint8_t *eui )
mluis 0:8e36e3d5d706 44 {
mluis 0:8e36e3d5d706 45 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 46 for( uint8_t i = 0; i < 8; i++ )
mluis 0:8e36e3d5d706 47 {
mluis 0:8e36e3d5d706 48 vt.printf( "%02X ", eui[i] );
mluis 0:8e36e3d5d706 49 }
mluis 0:8e36e3d5d706 50 vt.SetCursorPos( line, 50 );
mluis 0:8e36e3d5d706 51 vt.printf( "]" );
mluis 0:8e36e3d5d706 52 }
mluis 0:8e36e3d5d706 53
mluis 0:8e36e3d5d706 54 void SerialDisplayUpdateKey( uint8_t line, uint8_t *key )
mluis 0:8e36e3d5d706 55 {
mluis 0:8e36e3d5d706 56 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 57 for( uint8_t i = 0; i < 16; i++ )
mluis 0:8e36e3d5d706 58 {
mluis 0:8e36e3d5d706 59 vt.printf( "%02X ", key[i] );
mluis 0:8e36e3d5d706 60 }
mluis 0:8e36e3d5d706 61 vt.SetCursorPos( line, 74 );
mluis 0:8e36e3d5d706 62 vt.printf( "]" );
mluis 0:8e36e3d5d706 63 }
mluis 0:8e36e3d5d706 64
mluis 0:8e36e3d5d706 65 void SerialDisplayUpdateNwkId( uint8_t id )
mluis 0:8e36e3d5d706 66 {
mluis 0:8e36e3d5d706 67 vt.SetCursorPos( 10, 27 );
mluis 0:8e36e3d5d706 68 vt.printf( "%03d", id );
mluis 0:8e36e3d5d706 69 }
mluis 0:8e36e3d5d706 70
mluis 0:8e36e3d5d706 71 void SerialDisplayUpdateDevAddr( uint32_t addr )
mluis 0:8e36e3d5d706 72 {
mluis 0:8e36e3d5d706 73 vt.SetCursorPos( 11, 27 );
mluis 0:8e36e3d5d706 74 vt.printf( "%02X %02X %02X %02X", ( addr >> 24 ) & 0xFF, ( addr >> 16 ) & 0xFF, ( addr >> 8 ) & 0xFF, addr & 0xFF );
mluis 0:8e36e3d5d706 75 }
mluis 0:8e36e3d5d706 76
mluis 0:8e36e3d5d706 77 void SerialDisplayUpdateFrameType( bool confirmed )
mluis 0:8e36e3d5d706 78 {
mluis 0:8e36e3d5d706 79 vt.SetCursorPos( 15, 17 );
mluis 0:8e36e3d5d706 80 SerialPrintCheckBox( confirmed, VT100::WHITE );
mluis 0:8e36e3d5d706 81 vt.SetCursorPos( 15, 32 );
mluis 0:8e36e3d5d706 82 SerialPrintCheckBox( !confirmed, VT100::WHITE );
mluis 0:8e36e3d5d706 83 }
mluis 0:8e36e3d5d706 84
mluis 0:8e36e3d5d706 85 void SerialDisplayUpdateAdr( bool adr )
mluis 0:8e36e3d5d706 86 {
mluis 0:8e36e3d5d706 87 vt.SetCursorPos( 16, 27 );
mluis 0:8e36e3d5d706 88 if( adr == true )
mluis 0:8e36e3d5d706 89 {
mluis 0:8e36e3d5d706 90 vt.printf( " ON" );
mluis 0:8e36e3d5d706 91 }
mluis 0:8e36e3d5d706 92 else
mluis 0:8e36e3d5d706 93 {
mluis 0:8e36e3d5d706 94 vt.printf( "OFF" );
mluis 0:8e36e3d5d706 95 }
mluis 0:8e36e3d5d706 96 }
mluis 0:8e36e3d5d706 97
mluis 0:8e36e3d5d706 98 void SerialDisplayUpdateDutyCycle( bool dutyCycle )
mluis 0:8e36e3d5d706 99 {
mluis 0:8e36e3d5d706 100 vt.SetCursorPos( 17, 27 );
mluis 0:8e36e3d5d706 101 if( dutyCycle == true )
mluis 0:8e36e3d5d706 102 {
mluis 0:8e36e3d5d706 103 vt.printf( " ON" );
mluis 0:8e36e3d5d706 104 }
mluis 0:8e36e3d5d706 105 else
mluis 0:8e36e3d5d706 106 {
mluis 0:8e36e3d5d706 107 vt.printf( "OFF" );
mluis 0:8e36e3d5d706 108 }
mluis 0:8e36e3d5d706 109 }
mluis 0:8e36e3d5d706 110
mluis 0:8e36e3d5d706 111 void SerialDisplayUpdatePublicNetwork( bool network )
mluis 0:8e36e3d5d706 112 {
mluis 0:8e36e3d5d706 113 vt.SetCursorPos( 19, 17 );
mluis 0:8e36e3d5d706 114 SerialPrintCheckBox( network, VT100::WHITE );
mluis 0:8e36e3d5d706 115 vt.SetCursorPos( 19, 30 );
mluis 0:8e36e3d5d706 116 SerialPrintCheckBox( !network, VT100::WHITE );
mluis 0:8e36e3d5d706 117 }
mluis 0:8e36e3d5d706 118
mluis 0:8e36e3d5d706 119 void SerialDisplayUpdateNetworkIsJoined( bool state )
mluis 0:8e36e3d5d706 120 {
mluis 0:8e36e3d5d706 121 vt.SetCursorPos( 20, 17 );
mluis 0:8e36e3d5d706 122 SerialPrintCheckBox( !state, VT100::RED );
mluis 0:8e36e3d5d706 123 vt.SetCursorPos( 20, 30 );
mluis 0:8e36e3d5d706 124 SerialPrintCheckBox( state, VT100::GREEN );
mluis 0:8e36e3d5d706 125 }
mluis 0:8e36e3d5d706 126
mluis 0:8e36e3d5d706 127 void SerialDisplayUpdateLedState( uint8_t id, uint8_t state )
mluis 0:8e36e3d5d706 128 {
mluis 0:8e36e3d5d706 129 switch( id )
mluis 0:8e36e3d5d706 130 {
mluis 0:8e36e3d5d706 131 case 1:
mluis 0:8e36e3d5d706 132 vt.SetCursorPos( 22, 17 );
mluis 0:8e36e3d5d706 133 SerialPrintCheckBox( state, VT100::RED );
mluis 0:8e36e3d5d706 134 break;
mluis 0:8e36e3d5d706 135 case 2:
mluis 0:8e36e3d5d706 136 vt.SetCursorPos( 22, 31 );
mluis 0:8e36e3d5d706 137 SerialPrintCheckBox( state, VT100::GREEN );
mluis 0:8e36e3d5d706 138 break;
mluis 0:8e36e3d5d706 139 case 3:
mluis 0:8e36e3d5d706 140 vt.SetCursorPos( 22, 45 );
mluis 0:8e36e3d5d706 141 SerialPrintCheckBox( state, VT100::BLUE );
mluis 0:8e36e3d5d706 142 break;
mluis 0:8e36e3d5d706 143 }
mluis 0:8e36e3d5d706 144 }
mluis 0:8e36e3d5d706 145
mluis 0:8e36e3d5d706 146 void SerialDisplayUpdateData( uint8_t line, uint8_t *buffer, uint8_t size )
mluis 0:8e36e3d5d706 147 {
mluis 0:8e36e3d5d706 148 if( size != 0 )
mluis 0:8e36e3d5d706 149 {
mluis 0:8e36e3d5d706 150 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 151 for( uint8_t i = 0; i < size; i++ )
mluis 0:8e36e3d5d706 152 {
mluis 0:8e36e3d5d706 153 vt.printf( "%02X ", buffer[i] );
mluis 0:8e36e3d5d706 154 if( ( ( i + 1 ) % 16 ) == 0 )
mluis 0:8e36e3d5d706 155 {
mluis 0:8e36e3d5d706 156 line++;
mluis 0:8e36e3d5d706 157 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 158 }
mluis 0:8e36e3d5d706 159 }
mluis 0:8e36e3d5d706 160 for( uint8_t i = size; i < 64; i++ )
mluis 0:8e36e3d5d706 161 {
mluis 0:8e36e3d5d706 162 vt.printf( "__ " );
mluis 0:8e36e3d5d706 163 if( ( ( i + 1 ) % 16 ) == 0 )
mluis 0:8e36e3d5d706 164 {
mluis 0:8e36e3d5d706 165 line++;
mluis 0:8e36e3d5d706 166 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 167 }
mluis 0:8e36e3d5d706 168 }
mluis 0:8e36e3d5d706 169 vt.SetCursorPos( line - 1, 74 );
mluis 0:8e36e3d5d706 170 vt.printf( "]" );
mluis 0:8e36e3d5d706 171 }
mluis 0:8e36e3d5d706 172 else
mluis 0:8e36e3d5d706 173 {
mluis 0:8e36e3d5d706 174 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 175 for( uint8_t i = 0; i < 64; i++ )
mluis 0:8e36e3d5d706 176 {
mluis 0:8e36e3d5d706 177 vt.printf( "__ " );
mluis 0:8e36e3d5d706 178 if( ( ( i + 1 ) % 16 ) == 0 )
mluis 0:8e36e3d5d706 179 {
mluis 0:8e36e3d5d706 180 line++;
mluis 0:8e36e3d5d706 181 vt.SetCursorPos( line, 27 );
mluis 0:8e36e3d5d706 182 }
mluis 0:8e36e3d5d706 183 }
mluis 0:8e36e3d5d706 184 vt.SetCursorPos( line - 1, 74 );
mluis 0:8e36e3d5d706 185 vt.printf( "]" );
mluis 0:8e36e3d5d706 186 }
mluis 0:8e36e3d5d706 187 }
mluis 0:8e36e3d5d706 188
mluis 0:8e36e3d5d706 189 void SerialDisplayUpdateUplinkAcked( bool state )
mluis 0:8e36e3d5d706 190 {
mluis 0:8e36e3d5d706 191 vt.SetCursorPos( 24, 36 );
mluis 0:8e36e3d5d706 192 SerialPrintCheckBox( state, VT100::GREEN );
mluis 0:8e36e3d5d706 193 }
mluis 0:8e36e3d5d706 194
mluis 0:8e36e3d5d706 195 void SerialDisplayUpdateUplink( bool acked, uint8_t datarate, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize )
mluis 0:8e36e3d5d706 196 {
mluis 0:8e36e3d5d706 197 // Acked
mluis 0:8e36e3d5d706 198 SerialDisplayUpdateUplinkAcked( acked );
mluis 0:8e36e3d5d706 199 // Datarate
mluis 0:8e36e3d5d706 200 vt.SetCursorPos( 25, 33 );
mluis 0:8e36e3d5d706 201 vt.printf( "DR%d", datarate );
mluis 0:8e36e3d5d706 202 // Counter
mluis 0:8e36e3d5d706 203 vt.SetCursorPos( 26, 27 );
mluis 0:8e36e3d5d706 204 vt.printf( "%10d", counter );
mluis 0:8e36e3d5d706 205 // Port
mluis 0:8e36e3d5d706 206 vt.SetCursorPos( 27, 34 );
mluis 0:8e36e3d5d706 207 vt.printf( "%3d", port );
mluis 0:8e36e3d5d706 208 // Data
mluis 0:8e36e3d5d706 209 SerialDisplayUpdateData( 28, buffer, bufferSize );
mluis 0:8e36e3d5d706 210 // Help message
mluis 0:8e36e3d5d706 211 vt.SetCursorPos( 42, 1 );
mluis 0:8e36e3d5d706 212 vt.printf( "To refresh screen please hit 'r' key." );
mluis 0:8e36e3d5d706 213 }
mluis 0:8e36e3d5d706 214
mluis 0:8e36e3d5d706 215 void SerialDisplayUpdateDonwlinkRxData( bool state )
mluis 0:8e36e3d5d706 216 {
mluis 0:8e36e3d5d706 217 vt.SetCursorPos( 34, 4 );
mluis 0:8e36e3d5d706 218 SerialPrintCheckBox( state, VT100::GREEN );
mluis 0:8e36e3d5d706 219 }
mluis 0:8e36e3d5d706 220
mluis 0:8e36e3d5d706 221 void SerialDisplayUpdateDownlink( bool rxData, int16_t rssi, int8_t snr, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize )
mluis 0:8e36e3d5d706 222 {
mluis 0:8e36e3d5d706 223 // Rx data
mluis 0:8e36e3d5d706 224 SerialDisplayUpdateDonwlinkRxData( rxData );
mluis 0:8e36e3d5d706 225 // RSSI
mluis 0:8e36e3d5d706 226 vt.SetCursorPos( 33, 32 );
mluis 0:8e36e3d5d706 227 vt.printf( "%5d", rssi );
mluis 0:8e36e3d5d706 228 // SNR
mluis 0:8e36e3d5d706 229 vt.SetCursorPos( 34, 32 );
mluis 0:8e36e3d5d706 230 vt.printf( "%5d", snr );
mluis 0:8e36e3d5d706 231 // Counter
mluis 0:8e36e3d5d706 232 vt.SetCursorPos( 35, 27 );
mluis 0:8e36e3d5d706 233 vt.printf( "%10d", counter );
mluis 0:8e36e3d5d706 234 if( rxData == true )
mluis 0:8e36e3d5d706 235 {
mluis 0:8e36e3d5d706 236 // Port
mluis 0:8e36e3d5d706 237 vt.SetCursorPos( 36, 34 );
mluis 0:8e36e3d5d706 238 vt.printf( "%3d", port );
mluis 0:8e36e3d5d706 239 // Data
mluis 0:8e36e3d5d706 240 SerialDisplayUpdateData( 37, buffer, bufferSize );
mluis 0:8e36e3d5d706 241 }
mluis 0:8e36e3d5d706 242 else
mluis 0:8e36e3d5d706 243 {
mluis 0:8e36e3d5d706 244 // Port
mluis 0:8e36e3d5d706 245 vt.SetCursorPos( 36, 34 );
mluis 0:8e36e3d5d706 246 vt.printf( " " );
mluis 0:8e36e3d5d706 247 // Data
mluis 0:8e36e3d5d706 248 SerialDisplayUpdateData( 37, NULL, 0 );
mluis 0:8e36e3d5d706 249 }
mluis 0:8e36e3d5d706 250 }
mluis 0:8e36e3d5d706 251
mluis 0:8e36e3d5d706 252 void SerialDisplayDrawFirstLine( void )
mluis 0:8e36e3d5d706 253 {
mluis 0:8e36e3d5d706 254 vt.PutBoxDrawingChar( 'l' );
mluis 0:8e36e3d5d706 255 for( int8_t i = 0; i <= 77; i++ )
mluis 0:8e36e3d5d706 256 {
mluis 0:8e36e3d5d706 257 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 258 }
mluis 0:8e36e3d5d706 259 vt.PutBoxDrawingChar( 'k' );
mluis 0:8e36e3d5d706 260 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 261 }
mluis 0:8e36e3d5d706 262
mluis 0:8e36e3d5d706 263 void SerialDisplayDrawTitle( const char* title )
mluis 0:8e36e3d5d706 264 {
mluis 0:8e36e3d5d706 265 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 266 vt.printf( "%s", title );
mluis 0:8e36e3d5d706 267 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 268 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 269 }
mluis 0:8e36e3d5d706 270 void SerialDisplayDrawTopSeparator( void )
mluis 0:8e36e3d5d706 271 {
mluis 0:8e36e3d5d706 272 vt.PutBoxDrawingChar( 't' );
mluis 0:8e36e3d5d706 273 for( int8_t i = 0; i <= 11; i++ )
mluis 0:8e36e3d5d706 274 {
mluis 0:8e36e3d5d706 275 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 276 }
mluis 0:8e36e3d5d706 277 vt.PutBoxDrawingChar( 'w' );
mluis 0:8e36e3d5d706 278 for( int8_t i = 0; i <= 64; i++ )
mluis 0:8e36e3d5d706 279 {
mluis 0:8e36e3d5d706 280 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 281 }
mluis 0:8e36e3d5d706 282 vt.PutBoxDrawingChar( 'u' );
mluis 0:8e36e3d5d706 283 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 284 }
mluis 0:8e36e3d5d706 285
mluis 0:8e36e3d5d706 286 void SerialDisplayDrawColSeparator( void )
mluis 0:8e36e3d5d706 287 {
mluis 0:8e36e3d5d706 288 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 289 for( int8_t i = 0; i <= 11; i++ )
mluis 0:8e36e3d5d706 290 {
mluis 0:8e36e3d5d706 291 vt.PutBoxDrawingChar( ' ' );
mluis 0:8e36e3d5d706 292 }
mluis 0:8e36e3d5d706 293 vt.PutBoxDrawingChar( 't' );
mluis 0:8e36e3d5d706 294 for( int8_t i = 0; i <= 64; i++ )
mluis 0:8e36e3d5d706 295 {
mluis 0:8e36e3d5d706 296 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 297 }
mluis 0:8e36e3d5d706 298 vt.PutBoxDrawingChar( 'u' );
mluis 0:8e36e3d5d706 299 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 300 }
mluis 0:8e36e3d5d706 301
mluis 0:8e36e3d5d706 302 void SerialDisplayDrawSeparator( void )
mluis 0:8e36e3d5d706 303 {
mluis 0:8e36e3d5d706 304 vt.PutBoxDrawingChar( 't' );
mluis 0:8e36e3d5d706 305 for( int8_t i = 0; i <= 11; i++ )
mluis 0:8e36e3d5d706 306 {
mluis 0:8e36e3d5d706 307 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 308 }
mluis 0:8e36e3d5d706 309 vt.PutBoxDrawingChar( 'n' );
mluis 0:8e36e3d5d706 310 for( int8_t i = 0; i <= 64; i++ )
mluis 0:8e36e3d5d706 311 {
mluis 0:8e36e3d5d706 312 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 313 }
mluis 0:8e36e3d5d706 314 vt.PutBoxDrawingChar( 'u' );
mluis 0:8e36e3d5d706 315 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 316 }
mluis 0:8e36e3d5d706 317
mluis 0:8e36e3d5d706 318 void SerialDisplayDrawLine( const char* firstCol, const char* secondCol )
mluis 0:8e36e3d5d706 319 {
mluis 0:8e36e3d5d706 320 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 321 vt.printf( "%s", firstCol );
mluis 0:8e36e3d5d706 322 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 323 vt.printf( "%s", secondCol );
mluis 0:8e36e3d5d706 324 vt.PutBoxDrawingChar( 'x' );
mluis 0:8e36e3d5d706 325 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 326 }
mluis 0:8e36e3d5d706 327
mluis 0:8e36e3d5d706 328 void SerialDisplayDrawBottomLine( void )
mluis 0:8e36e3d5d706 329 {
mluis 0:8e36e3d5d706 330 vt.PutBoxDrawingChar( 'm' );
mluis 0:8e36e3d5d706 331 for( int8_t i = 0; i <= 11; i++ )
mluis 0:8e36e3d5d706 332 {
mluis 0:8e36e3d5d706 333 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 334 }
mluis 0:8e36e3d5d706 335 vt.PutBoxDrawingChar( 'v' );
mluis 0:8e36e3d5d706 336 for( int8_t i = 0; i <= 64; i++ )
mluis 0:8e36e3d5d706 337 {
mluis 0:8e36e3d5d706 338 vt.PutBoxDrawingChar( 'q' );
mluis 0:8e36e3d5d706 339 }
mluis 0:8e36e3d5d706 340 vt.PutBoxDrawingChar( 'j' );
mluis 0:8e36e3d5d706 341 vt.printf( "\r\n" );
mluis 0:8e36e3d5d706 342 }
mluis 0:8e36e3d5d706 343
mluis 0:8e36e3d5d706 344 void SerialDisplayInit( void )
mluis 0:8e36e3d5d706 345 {
mluis 0:8e36e3d5d706 346 vt.ClearScreen( 2 );
mluis 0:8e36e3d5d706 347 vt.SetCursorMode( false );
mluis 0:8e36e3d5d706 348 vt.SetCursorPos( 0, 0 );
mluis 0:8e36e3d5d706 349
mluis 0:8e36e3d5d706 350 // "+-----------------------------------------------------------------------------+" );
mluis 0:8e36e3d5d706 351 SerialDisplayDrawFirstLine( );
mluis 0:8e36e3d5d706 352 // "¦ LoRaWAN Demonstration Application ¦" );
mluis 0:8e36e3d5d706 353 SerialDisplayDrawTitle( " LoRaWAN Demonstration Application " );
mluis 0:8e36e3d5d706 354 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 355 SerialDisplayDrawTopSeparator( );
mluis 0:8e36e3d5d706 356 // "¦ Activation ¦ [ ]Over The Air ¦" );
mluis 0:8e36e3d5d706 357 SerialDisplayDrawLine( " Activation ", " [ ]Over The Air " );
mluis 0:8e36e3d5d706 358 // "¦ ¦ DevEui [__ __ __ __ __ __ __ __] ¦" );
mluis 0:8e36e3d5d706 359 SerialDisplayDrawLine( " ", " DevEui [__ __ __ __ __ __ __ __] " );
mluis 0:8e36e3d5d706 360 // "¦ ¦ AppEui [__ __ __ __ __ __ __ __] ¦" );
mluis 0:8e36e3d5d706 361 SerialDisplayDrawLine( " ", " AppEui [__ __ __ __ __ __ __ __] " );
mluis 0:8e36e3d5d706 362 // "¦ ¦ AppKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" );
mluis 0:8e36e3d5d706 363 SerialDisplayDrawLine( " ", " AppKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " );
mluis 0:8e36e3d5d706 364 // "¦ +----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 365 SerialDisplayDrawColSeparator( );
mluis 0:8e36e3d5d706 366 // "¦ ¦ [x]Personalisation ¦" );
mluis 0:8e36e3d5d706 367 SerialDisplayDrawLine( " ", " [ ]Personalisation " );
mluis 0:8e36e3d5d706 368 // "¦ ¦ NwkId [___] ¦" );
mluis 0:8e36e3d5d706 369 SerialDisplayDrawLine( " ", " NwkId [___] " );
mluis 0:8e36e3d5d706 370 // "¦ ¦ DevAddr [__ __ __ __] ¦" );
mluis 0:8e36e3d5d706 371 SerialDisplayDrawLine( " ", " DevAddr [__ __ __ __] " );
mluis 0:8e36e3d5d706 372 // "¦ ¦ NwkSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" );
mluis 0:8e36e3d5d706 373 SerialDisplayDrawLine( " ", " NwkSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " );
mluis 0:8e36e3d5d706 374 // "¦ ¦ AppSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] ¦" );
mluis 0:8e36e3d5d706 375 SerialDisplayDrawLine( " ", " AppSKey [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __] " );
mluis 0:8e36e3d5d706 376 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 377 SerialDisplayDrawSeparator( );
mluis 0:8e36e3d5d706 378 // "¦ MAC params ¦ [ ]Confirmed / [ ]Unconfirmed ¦" );
mluis 0:8e36e3d5d706 379 SerialDisplayDrawLine( " MAC params ", " [ ]Confirmed / [ ]Unconfirmed " );
mluis 0:8e36e3d5d706 380 // "¦ ¦ ADR [ ] ¦" );
mluis 0:8e36e3d5d706 381 SerialDisplayDrawLine( " ", " ADR [ ] " );
mluis 0:8e36e3d5d706 382 // "¦ ¦ Duty cycle[ ] ¦" );
mluis 0:8e36e3d5d706 383 SerialDisplayDrawLine( " ", " Duty cycle[ ] " );
mluis 0:8e36e3d5d706 384 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 385 SerialDisplayDrawSeparator( );
mluis 0:8e36e3d5d706 386 // "¦ Network ¦ [ ]Public / [ ]Private ¦" );
mluis 0:8e36e3d5d706 387 SerialDisplayDrawLine( " Network ", " [ ]Public / [ ]Private " );
mluis 0:8e36e3d5d706 388 // "¦ ¦ [ ]Joining / [ ]Joined ¦" );
mluis 0:8e36e3d5d706 389 SerialDisplayDrawLine( " ", " [ ]Joining / [ ]Joined " );
mluis 0:8e36e3d5d706 390 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 391 SerialDisplayDrawSeparator( );
mluis 0:8e36e3d5d706 392 // "¦ LED status ¦ [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App) ¦" );
mluis 0:8e36e3d5d706 393 SerialDisplayDrawLine( " LED status ", " [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App) " );
mluis 0:8e36e3d5d706 394 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 395 SerialDisplayDrawSeparator( );
mluis 0:8e36e3d5d706 396 // "¦ Uplink ¦ Acked [ ] ¦" );
mluis 0:8e36e3d5d706 397 SerialDisplayDrawLine( " Uplink ", " Acked [ ] " );
mluis 0:8e36e3d5d706 398 // "¦ ¦ Datarate [ ] ¦" );
mluis 0:8e36e3d5d706 399 SerialDisplayDrawLine( " ", " Datarate [ ] " );
mluis 0:8e36e3d5d706 400 // "¦ ¦ Counter [ ] ¦" );
mluis 0:8e36e3d5d706 401 SerialDisplayDrawLine( " ", " Counter [ ] " );
mluis 0:8e36e3d5d706 402 // "¦ ¦ Port [ ] ¦" );
mluis 0:8e36e3d5d706 403 SerialDisplayDrawLine( " ", " Port [ ] " );
mluis 0:8e36e3d5d706 404 // "¦ ¦ Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 405 SerialDisplayDrawLine( " ", " Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 406 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 407 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 408 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 409 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 410 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 411 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 412 // "+------------+----------------------------------------------------------------¦" );
mluis 0:8e36e3d5d706 413 SerialDisplayDrawSeparator( );
mluis 0:8e36e3d5d706 414 // "¦ Downlink ¦ RSSI [ ] dBm ¦" );
mluis 0:8e36e3d5d706 415 SerialDisplayDrawLine( " Downlink ", " RSSI [ ] dBm " );
mluis 0:8e36e3d5d706 416 // "¦ [ ]Data ¦ SNR [ ] dB ¦" );
mluis 0:8e36e3d5d706 417 SerialDisplayDrawLine( " [ ]Data ", " SNR [ ] dB " );
mluis 0:8e36e3d5d706 418 // "¦ ¦ Counter [ ] ¦" );
mluis 0:8e36e3d5d706 419 // "¦ ¦ Counter [ ] ¦" );
mluis 0:8e36e3d5d706 420 SerialDisplayDrawLine( " ", " Counter [ ] " );
mluis 0:8e36e3d5d706 421 // "¦ ¦ Port [ ] ¦" );
mluis 0:8e36e3d5d706 422 SerialDisplayDrawLine( " ", " Port [ ] " );
mluis 0:8e36e3d5d706 423 // "¦ ¦ Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 424 SerialDisplayDrawLine( " ", " Data [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 425 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 426 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 427 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 428 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 429 // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" );
mluis 0:8e36e3d5d706 430 SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " );
mluis 0:8e36e3d5d706 431 // "+------------+----------------------------------------------------------------+" );
mluis 0:8e36e3d5d706 432 SerialDisplayDrawBottomLine( );
mluis 0:8e36e3d5d706 433 vt.printf( "To refresh screen please hit 'r' key.\r\n" );
mluis 0:8e36e3d5d706 434 }
mluis 0:8e36e3d5d706 435
mluis 0:8e36e3d5d706 436 bool SerialDisplayReadable( void )
mluis 0:8e36e3d5d706 437 {
mluis 0:8e36e3d5d706 438 return vt.Readable( );
mluis 0:8e36e3d5d706 439 }
mluis 0:8e36e3d5d706 440
mluis 0:8e36e3d5d706 441 uint8_t SerialDisplayGetChar( void )
mluis 0:8e36e3d5d706 442 {
mluis 0:8e36e3d5d706 443 return vt.GetChar( );
mluis 0:8e36e3d5d706 444 }