for testing STM32L476 Nucleo-64 + Semtech SX1276RF1IAS

Dependencies:   LoRaWAN-demo-76 mbed LoRaWAN-lib SX1276Lib

Fork of LoRaWAN-demo-76 by Semtech

Files at this revision

API Documentation at this revision

Comitter:
rukudias
Date:
Sat Feb 25 14:28:52 2017 +0000
Parent:
8:82d284fcb202
Commit message:
STM32L476 Nucleo-64 + Semtech SX1276RF1IAS hello world app

Changed in this revision

LoRaWAN-mbed-client-ttn.lib Show annotated file Show diff for this revision Revisions of this file
LoRaWAN-mbed-client.lib Show annotated file Show diff for this revision Revisions of this file
MbedJSONValue.lib Show diff for this revision Revisions of this file
app/Comissioning.h Show annotated file Show diff for this revision Revisions of this file
app/SerialDisplay.cpp Show diff for this revision Revisions of this file
app/SerialDisplay.h Show diff for this revision Revisions of this file
app/main.cpp Show annotated file Show diff for this revision Revisions of this file
app/vt100.h Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaWAN-mbed-client-ttn.lib	Sat Feb 25 14:28:52 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Semtech/code/LoRaWAN-demo-76/#82d284fcb202
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaWAN-mbed-client.lib	Sat Feb 25 14:28:52 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Semtech/code/LoRaWAN-demo-76/#82d284fcb202
--- a/MbedJSONValue.lib	Sun Dec 11 22:50:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/samux/code/MbedJSONValue/#10a99cdf7846
--- a/app/Comissioning.h	Sun Dec 11 22:50:32 2016 +0000
+++ b/app/Comissioning.h	Sat Feb 25 14:28:52 2017 +0000
@@ -29,12 +29,12 @@
 /*!
  * IEEE Organizationally Unique Identifier ( OUI ) (big endian)
  */
-#define IEEE_OUI                                    0x11, 0x22, 0x33
+#define IEEE_OUI                                    0x00, 0x00, 0x00
 
 /*!
  * Mote device IEEE EUI (big endian)
  */
-#define LORAWAN_DEVICE_EUI                          { IEEE_OUI, 0x44, 0x55, 0x66, 0x77, 0x88 }
+#define LORAWAN_DEVICE_EUI                          { IEEE_OUI, 0x00, 0x00, 0x00, 0x00, 0x88 }
 
 /*!
  * Application IEEE EUI (big endian)
@@ -54,7 +54,7 @@
 /*!
  * Device address on the network (big endian)
  */
-#define LORAWAN_DEVICE_ADDRESS                      ( uint32_t )0x07229c04
+#define LORAWAN_DEVICE_ADDRESS                      ( uint32_t )0x00000004
 
 /*!
  * AES encryption/decryption cipher network session key
--- a/app/SerialDisplay.cpp	Sun Dec 11 22:50:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,444 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2015 Semtech
-
-Description: VT100 serial display management
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#include "board.h"
-#include "vt100.h"
-#include "SerialDisplay.h"
-
-VT100 vt( USBTX, USBRX );
-
-void SerialPrintCheckBox( bool activated, uint8_t color )
-{
-    if( activated == true )
-    {
-        vt.SetAttribute( VT100::ATTR_OFF, color, color );
-    }
-    else
-    {
-        vt.SetAttribute( VT100::ATTR_OFF );
-    }
-    vt.printf( " " );
-    vt.SetAttribute( VT100::ATTR_OFF );
-}
-
-void SerialDisplayUpdateActivationMode( bool otaa )
-{
-    vt.SetCursorPos( 4, 17 );
-    SerialPrintCheckBox( otaa, VT100::WHITE );
-    vt.SetCursorPos( 9, 17 );
-    SerialPrintCheckBox( !otaa, VT100::WHITE );
-}
-
-void SerialDisplayUpdateEui( uint8_t line, uint8_t *eui )
-{
-    vt.SetCursorPos( line, 27 );
-    for( uint8_t i = 0; i < 8; i++ )
-    {
-        vt.printf( "%02X ", eui[i] );
-    }
-    vt.SetCursorPos( line, 50 );
-    vt.printf( "]" );
-}
-
-void SerialDisplayUpdateKey( uint8_t line, uint8_t *key )
-{
-    vt.SetCursorPos( line, 27 );
-    for( uint8_t i = 0; i < 16; i++ )
-    {
-        vt.printf( "%02X ", key[i] );
-    }
-    vt.SetCursorPos( line, 74 );
-    vt.printf( "]" );
-}
-
-void SerialDisplayUpdateNwkId( uint8_t id )
-{
-    vt.SetCursorPos( 10, 27 );
-    vt.printf( "%03d", id );
-}
-
-void SerialDisplayUpdateDevAddr( uint32_t addr )
-{
-    vt.SetCursorPos( 11, 27 );
-    vt.printf( "%02X %02X %02X %02X", ( addr >> 24 ) & 0xFF, ( addr >> 16 ) & 0xFF, ( addr >> 8 ) & 0xFF, addr & 0xFF );
-}
-
-void SerialDisplayUpdateFrameType( bool confirmed )
-{
-    vt.SetCursorPos( 15, 17 );
-    SerialPrintCheckBox( confirmed, VT100::WHITE );
-    vt.SetCursorPos( 15, 32 );
-    SerialPrintCheckBox( !confirmed, VT100::WHITE );
-}
-
-void SerialDisplayUpdateAdr( bool adr )
-{
-    vt.SetCursorPos( 16, 27 );
-    if( adr == true )
-    {
-        vt.printf( " ON" );
-    }
-    else
-    {
-        vt.printf( "OFF" );
-    }
-}
-
-void SerialDisplayUpdateDutyCycle( bool dutyCycle )
-{
-    vt.SetCursorPos( 17, 27 );
-    if( dutyCycle == true )
-    {
-        vt.printf( " ON" );
-    }
-    else
-    {
-        vt.printf( "OFF" );
-    }
-}
-
-void SerialDisplayUpdatePublicNetwork( bool network )
-{
-    vt.SetCursorPos( 19, 17 );
-    SerialPrintCheckBox( network, VT100::WHITE );
-    vt.SetCursorPos( 19, 30 );
-    SerialPrintCheckBox( !network, VT100::WHITE );
-}
-
-void SerialDisplayUpdateNetworkIsJoined( bool state )
-{
-    vt.SetCursorPos( 20, 17 );
-    SerialPrintCheckBox( !state, VT100::RED );
-    vt.SetCursorPos( 20, 30 );
-    SerialPrintCheckBox( state, VT100::GREEN );
-}
-
-void SerialDisplayUpdateLedState( uint8_t id, uint8_t state )
-{
-    switch( id )
-    {
-        case 1:
-            vt.SetCursorPos( 22, 17 );
-            SerialPrintCheckBox( state, VT100::RED );
-            break;
-        case 2:
-            vt.SetCursorPos( 22, 31 );
-            SerialPrintCheckBox( state, VT100::GREEN );
-            break;
-        case 3:
-            vt.SetCursorPos( 22, 45 );
-            SerialPrintCheckBox( state, VT100::BLUE );
-            break;
-    }
-}
-
-void SerialDisplayUpdateData( uint8_t line, uint8_t *buffer, uint8_t size )
-{
-    if( size != 0 )
-    {
-        vt.SetCursorPos( line, 27 );
-        for( uint8_t i = 0; i < size; i++ )
-        {
-            vt.printf( "%02X ", buffer[i] );
-            if( ( ( i + 1 ) % 16 ) == 0 )
-            {
-                line++;
-                vt.SetCursorPos( line, 27 );
-            }
-        }
-        for( uint8_t i = size; i < 64; i++ )
-        {
-            vt.printf( "__ " );
-            if( ( ( i + 1 ) % 16 ) == 0 )
-            {
-                line++;
-                vt.SetCursorPos( line, 27 );
-            }
-        }
-        vt.SetCursorPos( line - 1, 74 );
-        vt.printf( "]" );
-    }
-    else
-    {
-        vt.SetCursorPos( line, 27 );
-        for( uint8_t i = 0; i < 64; i++ )
-        {
-            vt.printf( "__ " );
-            if( ( ( i + 1 ) % 16 ) == 0 )
-            {
-                line++;
-                vt.SetCursorPos( line, 27 );
-            }
-        }
-        vt.SetCursorPos( line - 1, 74 );
-        vt.printf( "]" );
-    }
-}
-
-void SerialDisplayUpdateUplinkAcked( bool state )
-{
-    vt.SetCursorPos( 24, 36 );
-    SerialPrintCheckBox( state, VT100::GREEN );
-}
-
-void SerialDisplayUpdateUplink( bool acked, uint8_t datarate, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize )
-{
-    // Acked
-    SerialDisplayUpdateUplinkAcked( acked );
-    // Datarate
-    vt.SetCursorPos( 25, 33 );
-    vt.printf( "DR%d", datarate );
-    // Counter
-    vt.SetCursorPos( 26, 27 );
-    vt.printf( "%10d", counter );
-    // Port
-    vt.SetCursorPos( 27, 34 );
-    vt.printf( "%3d", port );
-    // Data
-    SerialDisplayUpdateData( 28, buffer, bufferSize );
-    // Help message
-    vt.SetCursorPos( 42, 1 );
-    vt.printf( "To refresh screen please hit 'r' key." );
-}
-
-void SerialDisplayUpdateDonwlinkRxData( bool state )
-{
-    vt.SetCursorPos( 34, 4 );
-    SerialPrintCheckBox( state, VT100::GREEN );
-}
-
-void SerialDisplayUpdateDownlink( bool rxData, int16_t rssi, int8_t snr, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize )
-{
-    // Rx data
-    SerialDisplayUpdateDonwlinkRxData( rxData );
-    // RSSI
-    vt.SetCursorPos( 33, 32 );
-    vt.printf( "%5d", rssi );
-    // SNR
-    vt.SetCursorPos( 34, 32 );
-    vt.printf( "%5d", snr );
-    // Counter
-    vt.SetCursorPos( 35, 27 );
-    vt.printf( "%10d", counter );
-    if( rxData == true )
-    {
-        // Port
-        vt.SetCursorPos( 36, 34 );
-        vt.printf( "%3d", port );
-        // Data
-        SerialDisplayUpdateData( 37, buffer, bufferSize );
-    }
-    else
-    {
-        // Port
-        vt.SetCursorPos( 36, 34 );
-        vt.printf( "   " );
-        // Data
-        SerialDisplayUpdateData( 37, NULL, 0 );
-    }
-}
-
-void SerialDisplayDrawFirstLine( void )
-{
-    vt.PutBoxDrawingChar( 'l' );
-    for( int8_t i = 0; i <= 77; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'k' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayDrawTitle( const char* title )
-{
-    vt.PutBoxDrawingChar( 'x' );
-    vt.printf( "%s", title );
-    vt.PutBoxDrawingChar( 'x' );
-    vt.printf( "\r\n" );
-}
-void SerialDisplayDrawTopSeparator( void )
-{
-    vt.PutBoxDrawingChar( 't' );
-    for( int8_t i = 0; i <= 11; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'w' );
-    for( int8_t i = 0; i <= 64; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'u' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayDrawColSeparator( void )
-{
-    vt.PutBoxDrawingChar( 'x' );
-    for( int8_t i = 0; i <= 11; i++ )
-    {
-        vt.PutBoxDrawingChar( ' ' );
-    }
-    vt.PutBoxDrawingChar( 't' );
-    for( int8_t i = 0; i <= 64; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'u' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayDrawSeparator( void )
-{
-    vt.PutBoxDrawingChar( 't' );
-    for( int8_t i = 0; i <= 11; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'n' );
-    for( int8_t i = 0; i <= 64; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'u' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayDrawLine( const char* firstCol, const char* secondCol )
-{
-    vt.PutBoxDrawingChar( 'x' );
-    vt.printf( "%s", firstCol );
-    vt.PutBoxDrawingChar( 'x' );
-    vt.printf( "%s", secondCol );
-    vt.PutBoxDrawingChar( 'x' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayDrawBottomLine( void )
-{
-    vt.PutBoxDrawingChar( 'm' );
-    for( int8_t i = 0; i <= 11; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'v' );
-    for( int8_t i = 0; i <= 64; i++ )
-    {
-        vt.PutBoxDrawingChar( 'q' );
-    }
-    vt.PutBoxDrawingChar( 'j' );
-    vt.printf( "\r\n" );
-}
-
-void SerialDisplayInit( void )
-{
-    vt.ClearScreen( 2 );
-    vt.SetCursorMode( false );
-    vt.SetCursorPos( 0, 0 );
-    
-    // "+-----------------------------------------------------------------------------+" );
-    SerialDisplayDrawFirstLine( );
-    // "¦                      LoRaWAN Demonstration Application                      ¦" );
-    SerialDisplayDrawTitle( "                      LoRaWAN Demonstration Application                       " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawTopSeparator( );
-    // "¦ Activation ¦ [ ]Over The Air                                                ¦" );
-    SerialDisplayDrawLine( " Activation ", " [ ]Over The Air                                                 " );
-    // "¦            ¦ DevEui    [__ __ __ __ __ __ __ __]                            ¦" );
-    SerialDisplayDrawLine( "            ", " DevEui    [__ __ __ __ __ __ __ __]                             " );
-    // "¦            ¦ AppEui    [__ __ __ __ __ __ __ __]                            ¦" );
-    SerialDisplayDrawLine( "            ", " AppEui    [__ __ __ __ __ __ __ __]                             " );
-    // "¦            ¦ AppKey  [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]      ¦" );
-    SerialDisplayDrawLine( "            ", " AppKey    [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]     " );
-    // "¦            +----------------------------------------------------------------¦" );
-    SerialDisplayDrawColSeparator( );
-    // "¦            ¦ [x]Personalisation                                             ¦" );
-    SerialDisplayDrawLine( "            ", " [ ]Personalisation                                              " );
-    // "¦            ¦ NwkId     [___]                                                ¦" );
-    SerialDisplayDrawLine( "            ", " NwkId     [___]                                                 " );
-    // "¦            ¦ DevAddr   [__ __ __ __]                                        ¦" );
-    SerialDisplayDrawLine( "            ", " DevAddr   [__ __ __ __]                                         " );
-    // "¦            ¦ NwkSKey   [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]    ¦" );
-    SerialDisplayDrawLine( "            ", " NwkSKey   [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]     " );
-    // "¦            ¦ AppSKey   [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]    ¦" );
-    SerialDisplayDrawLine( "            ", " AppSKey   [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __]     " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawSeparator( );
-    // "¦ MAC params ¦ [ ]Confirmed / [ ]Unconfirmed                                  ¦" );
-    SerialDisplayDrawLine( " MAC params ", " [ ]Confirmed / [ ]Unconfirmed                                   " );
-    // "¦            ¦ ADR       [   ]                                                ¦" );
-    SerialDisplayDrawLine( "            ", " ADR       [   ]                                                 " );
-    // "¦            ¦ Duty cycle[   ]                                                ¦" );
-    SerialDisplayDrawLine( "            ", " Duty cycle[   ]                                                 " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawSeparator( );
-    // "¦ Network    ¦ [ ]Public  / [ ]Private                                        ¦" );
-    SerialDisplayDrawLine( " Network    ", " [ ]Public  / [ ]Private                                         " );
-    // "¦            ¦ [ ]Joining / [ ]Joined                                         ¦" );
-    SerialDisplayDrawLine( "            ", " [ ]Joining / [ ]Joined                                          " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawSeparator( );
-    // "¦ LED status ¦ [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App)                       ¦" );
-    SerialDisplayDrawLine( " LED status ", " [ ]LED1(Tx) / [ ]LED2(Rx) / [ ]LED3(App)                        " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawSeparator( );
-    // "¦ Uplink     ¦ Acked              [ ]                                         ¦" );
-    SerialDisplayDrawLine( " Uplink     ", " Acked              [ ]                                          " );
-    // "¦            ¦ Datarate        [    ]                                         ¦" );
-    SerialDisplayDrawLine( "            ", " Datarate        [    ]                                          " );
-    // "¦            ¦ Counter   [          ]                                         ¦" );
-    SerialDisplayDrawLine( "            ", " Counter   [          ]                                          " );
-    // "¦            ¦ Port             [   ]                                         ¦" );
-    SerialDisplayDrawLine( "            ", " Port             [   ]                                          " );
-    // "¦            ¦ Data      [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", " Data      [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "+------------+----------------------------------------------------------------¦" );
-    SerialDisplayDrawSeparator( );
-    // "¦ Downlink   ¦ RSSI           [     ] dBm                                     ¦" );
-    SerialDisplayDrawLine( " Downlink   ", " RSSI           [     ] dBm                                      " );
-    // "¦ [ ]Data    ¦ SNR      [     ] dB                                            ¦" );
-    SerialDisplayDrawLine( " [ ]Data    ", " SNR            [     ] dB                                       " );
-    // "¦            ¦ Counter  [          ]                                          ¦" );
-    // "¦            ¦ Counter   [          ]                                         ¦" );
-    SerialDisplayDrawLine( "            ", " Counter   [          ]                                          " );
-    // "¦            ¦ Port             [   ]                                         ¦" );
-    SerialDisplayDrawLine( "            ", " Port             [   ]                                          " );
-    // "¦            ¦ Data      [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", " Data      [__ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "¦            ¦            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     ¦" );
-    SerialDisplayDrawLine( "            ", "            __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __      " );
-    // "+------------+----------------------------------------------------------------+" );
-    SerialDisplayDrawBottomLine( );
-    vt.printf( "To refresh screen please hit 'r' key.\r\n" );
-}
-
-bool SerialDisplayReadable( void )
-{
-    return vt.Readable( );
-}
-
-uint8_t SerialDisplayGetChar( void )
-{
-    return vt.GetChar( );
-}
--- a/app/SerialDisplay.h	Sun Dec 11 22:50:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2015 Semtech
-
-Description: VT100 serial display management
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __SERIAL_DISPLAY_H__
-#define __SERIAL_DISPLAY_H__
-
-void SerialDisplayInit( void );
-void SerialDisplayUpdateUplink( bool acked, uint8_t datarate, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize );
-void SerialDisplayUpdateDownlink( bool rxData, int16_t rssi, int8_t snr, uint16_t counter, uint8_t port, uint8_t *buffer, uint8_t bufferSize );
-void SerialDisplayPrintCheckBox( bool activated );
-void SerialDisplayUpdateLedState( uint8_t id, uint8_t state );
-void SerialDisplayUpdateActivationMode( bool otaa );
-void SerialDisplayUpdateEui( uint8_t line, uint8_t *eui );
-void SerialDisplayUpdateKey( uint8_t line, uint8_t *key );
-void SerialDisplayUpdateNwkId( uint8_t id );
-void SerialDisplayUpdateDevAddr( uint32_t addr );
-void SerialDisplayUpdateFrameType( bool confirmed );
-void SerialDisplayUpdateAdr( bool adr );
-void SerialDisplayUpdateDutyCycle( bool dutyCycle );
-void SerialDisplayUpdatePublicNetwork( bool network );
-void SerialDisplayUpdateData( uint8_t *buffer );
-void SerialDisplayUpdateNetworkIsJoined( bool state );
-void SerialDisplayUpdateUplinkAcked( bool state );
-void SerialDisplayUpdateDonwlinkRxData( bool state );
-bool SerialDisplayReadable( void );
-uint8_t SerialDisplayGetChar( void );
-
-#endif // __SERIAL_DISPLAY_H__
--- a/app/main.cpp	Sun Dec 11 22:50:32 2016 +0000
+++ b/app/main.cpp	Sat Feb 25 14:28:52 2017 +0000
@@ -18,7 +18,6 @@
 
 #include "LoRaMac.h"
 #include "Comissioning.h"
-#include "SerialDisplay.h"
 
 /*!
  * Defines the application data transmission duty cycle. 5s, value in [us].
@@ -46,18 +45,19 @@
  *
  * \remark Please note that when ADR is enabled the end-device should be static
  */
-#define LORAWAN_ADR_ON                              1
+#define LORAWAN_ADR_ON                              0
 
 #if defined( USE_BAND_868 )
 
 #include "LoRaMacTest.h"
+#include <string>
 
 /*!
  * LoRaWAN ETSI duty cycle control enable/disable
  *
  * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes
  */
-#define LORAWAN_DUTYCYCLE_ON                        true
+#define LORAWAN_DUTYCYCLE_ON                        false
 
 #define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP          1
 
@@ -107,6 +107,7 @@
 
 #endif
 
+
 /*!
  * Application port
  */
@@ -141,30 +142,27 @@
  * Timer to handle the application data transmission duty cycle
  */
 static TimerEvent_t TxNextPacketTimer;
-
-/*!
- * Specifies the state of the application LED
- */
-static bool AppLedStateOn = false;
-volatile bool Led3StateChanged = false;
-/*!
- * Timer to handle the state of LED1
- */
-static TimerEvent_t Led1Timer;
-volatile bool Led1State = false;
-volatile bool Led1StateChanged = false;
-/*!
- * Timer to handle the state of LED2
- */
-static TimerEvent_t Led2Timer;
-volatile bool Led2State = false;
-volatile bool Led2StateChanged = false;
+Serial pc_debug(USBTX, USBRX);
 
 /*!
  * Indicates if a new packet can be sent
  */
 static bool NextTx = true;
 
+int8_t txPower =  LORAMAC_DEFAULT_TX_POWER;
+uint32_t upCnt =  0;
+uint32_t downCnt =  0;
+
+//#define DR_0                                        0  // SF12 - BW125
+//#define DR_1                                        1  // SF11 - BW125
+//#define DR_2                                        2  // SF10 - BW125
+//#define DR_3                                        3  // SF9  - BW125
+//#define DR_4                                        4  // SF8  - BW125
+//#define DR_5                                        5  // SF7  - BW125
+
+int8_t sf = LORAWAN_DEFAULT_DATARATE;
+
+
 /*!
  * Device states
  */
@@ -172,9 +170,12 @@
 {
     DEVICE_STATE_INIT,
     DEVICE_STATE_JOIN,
+    DEVICE_STATE_WAIT_REQUEST,
+    DEVICE_STATE_PROCESS_REQUEST,
     DEVICE_STATE_SEND,
     DEVICE_STATE_CYCLE,
-    DEVICE_STATE_SLEEP
+    DEVICE_STATE_SLEEP,
+    DEVICE_STATE_PROCESS_RESPONSE,
 }DeviceState;
 
 /*!
@@ -232,103 +233,20 @@
 }LoRaMacDownlinkStatus;
 volatile bool DownlinkStatusUpdated = false;
 
+static TimerEvent_t SendTimerEvent;
+static void OnSendTimerEvent( void )
+{
+    pc_debug.printf("OnSendTimerEvent\r\n");
+    DeviceState = DEVICE_STATE_PROCESS_REQUEST;
+    TimerStop( &SendTimerEvent ); 
+}
+std::string status_str = "Ok";
 void SerialDisplayRefresh( void )
 {
     MibRequestConfirm_t mibReq;
-
-    SerialDisplayInit( );
-    SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
-
-#if( OVER_THE_AIR_ACTIVATION == 0 )
-    SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
-    SerialDisplayUpdateDevAddr( DevAddr );
-    SerialDisplayUpdateKey( 12, NwkSKey );
-    SerialDisplayUpdateKey( 13, AppSKey );
-#endif
-    SerialDisplayUpdateEui( 5, DevEui );
-    SerialDisplayUpdateEui( 6, AppEui );
-    SerialDisplayUpdateKey( 7, AppKey );
-
     mibReq.Type = MIB_NETWORK_JOINED;
     LoRaMacMibGetRequestConfirm( &mibReq );
-    SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
 
-    SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
-#if defined( USE_BAND_868 )
-    SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
-#else
-    SerialDisplayUpdateDutyCycle( false );
-#endif
-    SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
-    
-    SerialDisplayUpdateLedState( 3, AppLedStateOn );
-}
-
-void SerialRxProcess( void )
-{
-    if( SerialDisplayReadable( ) == true )
-    {
-        switch( SerialDisplayGetChar( ) )
-        {
-            case 'R':
-            case 'r':
-                // Refresh Serial screen
-                SerialDisplayRefresh( );
-                break;
-            default:
-                break;
-        }
-    }
-}
-
-/*!
- * \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:
-        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 4:
-                ComplianceTest.State = 1;
-                break;
-            case 1:
-                AppDataSize = 2;
-                AppData[0] = ComplianceTest.DownLinkCounter >> 8;
-                AppData[1] = ComplianceTest.DownLinkCounter;
-                break;
-            }
-        }
-        break;
-    default:
-        break;
-    }
 }
 
 /*!
@@ -347,29 +265,31 @@
         mcpsReq.Type = MCPS_UNCONFIRMED;
         mcpsReq.Req.Unconfirmed.fBuffer = NULL;
         mcpsReq.Req.Unconfirmed.fBufferSize = 0;
-        mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
+        mcpsReq.Req.Unconfirmed.Datarate = sf;
 
         LoRaMacUplinkStatus.Acked = false;
         LoRaMacUplinkStatus.Port = 0;
         LoRaMacUplinkStatus.Buffer = NULL;
         LoRaMacUplinkStatus.BufferSize = 0;
-        SerialDisplayUpdateFrameType( false );
+        pc_debug.printf("SendFrame::LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK\r\n");
     }
     else
     {
+        pc_debug.printf("SendFrame::LoRaMacQueryTxPossible MaxPossiblePayload %d\r\n",txInfo.MaxPossiblePayload);
+        pc_debug.printf("SendFrame::LoRaMacQueryTxPossible CurrentPayloadSize %d\r\n",txInfo.CurrentPayloadSize);
         LoRaMacUplinkStatus.Acked = false;
         LoRaMacUplinkStatus.Port = AppPort;
         LoRaMacUplinkStatus.Buffer = AppData;
         LoRaMacUplinkStatus.BufferSize = AppDataSize;
-        SerialDisplayUpdateFrameType( IsTxConfirmed );
-
+        pc_debug.printf("SendFrame::LoRaMacQueryTxPossible( AppDataSize, &txInfo ) == LORAMAC_STATUS_OK\r\n");
+         
         if( IsTxConfirmed == false )
         {
             mcpsReq.Type = MCPS_UNCONFIRMED;
             mcpsReq.Req.Unconfirmed.fPort = AppPort;
             mcpsReq.Req.Unconfirmed.fBuffer = AppData;
             mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize;
-            mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
+            mcpsReq.Req.Unconfirmed.Datarate = sf;
         }
         else
         {
@@ -378,14 +298,20 @@
             mcpsReq.Req.Confirmed.fBuffer = AppData;
             mcpsReq.Req.Confirmed.fBufferSize = AppDataSize;
             mcpsReq.Req.Confirmed.NbTrials = 8;
-            mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
+            mcpsReq.Req.Confirmed.Datarate = sf;
         }
     }
-
-    if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
+    
+    LoRaMacStatus_t status = LoRaMacMcpsRequest( &mcpsReq );
+    
+    if( status == LORAMAC_STATUS_OK )
     {
+        pc_debug.printf("SendFrame::LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK\r\n");
         return false;
     }
+    pc_debug.printf("SendFrame::LoRaMacMcpsRequest( &mcpsReq ) != LORAMAC_STATUS_OK status %d\r\n",status);
+    status_str = "Error";
+    DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
     return true;
 }
 
@@ -394,6 +320,7 @@
  */
 static void OnTxNextPacketTimerEvent( void )
 {
+    pc_debug.printf("OnTxNextPacketTimerEvent::\r\n");
     MibRequestConfirm_t mibReq;
     LoRaMacStatus_t status;
 
@@ -404,41 +331,27 @@
 
     if( status == LORAMAC_STATUS_OK )
     {
+        pc_debug.printf("OnTxNextPacketTimerEvent:: status == LORAMAC_STATUS_OK\r\n");
         if( mibReq.Param.IsNetworkJoined == true )
         {
-            DeviceState = DEVICE_STATE_SEND;
-            NextTx = true;
+            pc_debug.printf("OnTxNextPacketTimerEvent:: mibReq.Param.IsNetworkJoined == true\r\n");
+            status_str = "Ok";
+            DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
+           
         }
         else
         {
+            pc_debug.printf("OnTxNextPacketTimerEvent:: mibReq.Param.IsNetworkJoined != true\r\n");
             DeviceState = DEVICE_STATE_JOIN;
         }
+    }else{
+        pc_debug.printf("OnTxNextPacketTimerEvent status != LORAMAC_STATUS_OK %d\r\n");
+        status_str = "Error";
+        DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
     }
 }
 
 /*!
- * \brief Function executed on Led 1 Timeout event
- */
-static void OnLed1TimerEvent( void )
-{
-    TimerStop( &Led1Timer );
-    // Switch LED 1 OFF
-    Led1State = false;
-    Led1StateChanged = true;
-}
-
-/*!
- * \brief Function executed on Led 2 Timeout event
- */
-static void OnLed2TimerEvent( void )
-{
-    TimerStop( &Led2Timer );
-    // Switch LED 2 OFF
-    Led2State = false;
-    Led2StateChanged = true;
-}
-
-/*!
  * \brief   MCPS-Confirm event function
  *
  * \param   [IN] mcpsConfirm - Pointer to the confirm structure,
@@ -446,8 +359,10 @@
  */
 static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
 {
-    if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+    LoRaMacEventInfoStatus_t status_mcps = mcpsConfirm->Status;
+    if( status_mcps == LORAMAC_EVENT_INFO_STATUS_OK )
     {
+        pc_debug.printf("McpsConfirm:: mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK\r\n");
         switch( mcpsConfirm->McpsRequest )
         {
             case MCPS_UNCONFIRMED:
@@ -474,15 +389,12 @@
         }
         LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate;
         LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter;
-
-        // Switch LED 1 ON
-        Led1State = true;
-        Led1StateChanged = true;
-        TimerStart( &Led1Timer );
-
         UplinkStatusUpdated = true;
+    }else{
+        pc_debug.printf("McpsConfirm:: mcpsConfirm->Status != LORAMAC_EVENT_INFO_STATUS_OK %d\r\n",status_mcps);  
+        status_str = "Error";
+        DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
     }
-    NextTx = true;
 }
 
 /*!
@@ -493,11 +405,16 @@
  */
 static void McpsIndication( McpsIndication_t *mcpsIndication )
 {
-    if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
+    LoRaMacEventInfoStatus_t status_mcps = mcpsIndication->Status;
+    if( status_mcps != LORAMAC_EVENT_INFO_STATUS_OK )
     {
+        pc_debug.printf("McpsIndication:: mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK %d\r\n",status_mcps);
+        status_str = "Error";
+        DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
         return;
     }
 
+    pc_debug.printf("McpsIndication:: mcpsIndication->Status == LORAMAC_EVENT_INFO_STATUS_OK\r\n");
     switch( mcpsIndication->McpsIndication )
     {
         case MCPS_UNCONFIRMED:
@@ -529,6 +446,7 @@
     // Check Rssi
     // Check Snr
     // Check RxSlot
+    
     LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi;
     if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
     {
@@ -560,8 +478,7 @@
         case 2:
             if( mcpsIndication->BufferSize == 1 )
             {
-                AppLedStateOn = mcpsIndication->Buffer[0] & 0x01;
-                Led3StateChanged = true;
+                //AppLedStateOn = mcpsIndication->Buffer[0] & 0x01;
             }
             break;
         case 224:
@@ -664,12 +581,8 @@
             break;
         }
     }
-
-    // Switch LED 2 ON for each received downlink
-    Led2State = true;
-    Led2StateChanged = true;
-    TimerStart( &Led2Timer );
     DownlinkStatusUpdated = true;
+    status_str = "Ok";
 }
 
 /*!
@@ -679,11 +592,13 @@
  *               containing confirm attributes.
  */
 static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
-{
-    if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+{   
+    LoRaMacEventInfoStatus_t status_mlme = mlmeConfirm->Status;
+    if( status_mlme == LORAMAC_EVENT_INFO_STATUS_OK )
     {
+        pc_debug.printf("MlmeConfirm:: mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK\r\n");
         switch( mlmeConfirm->MlmeRequest )
-        {
+        {      
             case MLME_JOIN:
             {
                 // Status is OK, node has joined the network
@@ -707,8 +622,11 @@
             default:
                 break;
         }
+    }else{
+        pc_debug.printf("MlmeConfirm:: mlmeConfirm->Status != LORAMAC_EVENT_INFO_STATUS_OK %d\r\n",status_mlme);
+        status_str = "Error";
+        DeviceState = DEVICE_STATE_PROCESS_RESPONSE;
     }
-    NextTx = true;
     UplinkStatusUpdated = true;
 }
 
@@ -722,76 +640,57 @@
     MibRequestConfirm_t mibReq;
 
     BoardInit( );
-    SerialDisplayInit( );
-
-    SerialDisplayUpdateEui( 5, DevEui );
-    SerialDisplayUpdateEui( 6, AppEui );
-    SerialDisplayUpdateKey( 7, AppKey );
+    
+    TimerInit( &SendTimerEvent, OnSendTimerEvent );
+    TimerSetValue( &SendTimerEvent, 60000000 );//us
+    
+    
+    pc_debug.baud(115200);
+    pc_debug.printf("Start\r\n");  
+      
+#if( OVER_THE_AIR_ACTIVATION == 0 )
 
-#if( OVER_THE_AIR_ACTIVATION == 0 )
-    SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID );
-    SerialDisplayUpdateDevAddr( DevAddr );
-    SerialDisplayUpdateKey( 12, NwkSKey );
-    SerialDisplayUpdateKey( 13, AppSKey );
 #endif
 
     DeviceState = DEVICE_STATE_INIT;
-
+    
     while( 1 )
     {
-        SerialRxProcess( );
         if( IsNetworkJoinedStatusUpdate == true )
         {
             IsNetworkJoinedStatusUpdate = false;
             mibReq.Type = MIB_NETWORK_JOINED;
             LoRaMacMibGetRequestConfirm( &mibReq );
-            SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
-        }
-        if( Led1StateChanged == true )
-        {
-            Led1StateChanged = false;
-            SerialDisplayUpdateLedState( 1, Led1State );
-        }
-        if( Led2StateChanged == true )
-        {
-            Led2StateChanged = false;
-            SerialDisplayUpdateLedState( 2, Led2State );
-        }
-        if( Led3StateChanged == true )
-        {
-            Led3StateChanged = false;
-            SerialDisplayUpdateLedState( 3, AppLedStateOn );
+            pc_debug.printf("mibReq.Param.IsNetworkJoined %d\r\n",mibReq.Param.IsNetworkJoined);
         }
         if( UplinkStatusUpdated == true )
         {
             UplinkStatusUpdated = false;
-            SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize );
+            pc_debug.printf("UplinkStatusUpdated == true\r\n");
+            upCnt = LoRaMacUplinkStatus.UplinkCounter;
         }
         if( DownlinkStatusUpdated == true )
         {
             DownlinkStatusUpdated = false;
-            SerialDisplayUpdateLedState( 2, Led2State );
-            SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize );
+            pc_debug.printf("DownlinkStatusUpdated == true\r\n");
+            downCnt = LoRaMacDownlinkStatus.DownlinkCounter;
         }
         
         switch( DeviceState )
         {
             case DEVICE_STATE_INIT:
             {
+                pc_debug.printf("DEVICE_STATE_INIT\r\n");
+                
                 LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
                 LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
                 LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
                 LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
+                
                 LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks );
 
                 TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );
 
-                TimerInit( &Led1Timer, OnLed1TimerEvent );
-                TimerSetValue( &Led1Timer, 25000 );
-
-                TimerInit( &Led2Timer, OnLed2TimerEvent );
-                TimerSetValue( &Led2Timer, 25000 );
-
                 mibReq.Type = MIB_ADR;
                 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
                 LoRaMacMibSetRequestConfirm( &mibReq );
@@ -799,11 +698,21 @@
                 mibReq.Type = MIB_PUBLIC_NETWORK;
                 mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
                 LoRaMacMibSetRequestConfirm( &mibReq );
+//                #defined( USE_BAND_868 )  
+//                #define TX_POWER_20_DBM                             0
+//                #define TX_POWER_14_DBM                             1
+//                #define TX_POWER_11_DBM                             2
+//                #define TX_POWER_08_DBM                             3
+//                #define TX_POWER_05_DBM                             4
+//                #define TX_POWER_02_DBM                             5
+                
+                mibReq.Type = MIB_CHANNELS_TX_POWER;
+                mibReq.Param.ChannelsTxPower = txPower;
+                LoRaMacMibSetRequestConfirm( &mibReq );
+                
 
 #if defined( USE_BAND_868 )
                 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
-                SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
-
 #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) 
                 LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 );
                 LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 );
@@ -819,17 +728,22 @@
 #endif
 
 #endif
-                SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
-                SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
-                SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
-
-                LoRaMacDownlinkStatus.DownlinkCounter = 0;
-
+                mibReq.Type = MIB_UPLINK_COUNTER;
+                mibReq.Param.UpLinkCounter = upCnt;
+                LoRaMacMibSetRequestConfirm( &mibReq );
+                
+                mibReq.Type = MIB_DOWNLINK_COUNTER;
+                mibReq.Param.DownLinkCounter = downCnt;
+                LoRaMacMibSetRequestConfirm( &mibReq );
+                
+                
+                LoRaMacDownlinkStatus.DownlinkCounter = downCnt;
                 DeviceState = DEVICE_STATE_JOIN;
                 break;
             }
             case DEVICE_STATE_JOIN:
             {
+                pc_debug.printf("DEVICE_STATE_JOIN\r\n");
 #if( OVER_THE_AIR_ACTIVATION != 0 )
                 MlmeReq_t mlmeReq;
 
@@ -865,36 +779,46 @@
                 mibReq.Param.IsNetworkJoined = true;
                 LoRaMacMibSetRequestConfirm( &mibReq );
 
-                DeviceState = DEVICE_STATE_SEND;
+                DeviceState = DEVICE_STATE_WAIT_REQUEST;
 #endif
                 IsNetworkJoinedStatusUpdate = true;
+                TimerStart( &SendTimerEvent );
+                break;
+            }
+            case DEVICE_STATE_WAIT_REQUEST:
+            {
+                break;
+            }
+            case DEVICE_STATE_PROCESS_REQUEST:
+            {
+                std::string send_data = "Test!";
+                pc_debug.printf("DEVICE_STATE_PROCESS_REQUEST %s\r\n",send_data.c_str());
+               
+                int pos = 0;
+                for(;pos < send_data.size();pos++){
+                    AppData[pos] = send_data.at(pos);
+                }
+                AppData[pos] = '\0';
+                AppDataSize = pos;
+                AppPort = 10;
+                DeviceState = DEVICE_STATE_SEND;
                 break;
             }
             case DEVICE_STATE_SEND:
             {
+                pc_debug.printf("DEVICE_STATE_SEND\r\n");
                 if( NextTx == true )
                 {
-                    SerialDisplayUpdateUplinkAcked( false );
-                    SerialDisplayUpdateDonwlinkRxData( false );
-                    PrepareTxFrame( AppPort );
-
                     NextTx = SendFrame( );
                 }
-                if( ComplianceTest.Running == true )
-                {
-                    // Schedule next packet transmission
-                    TxDutyCycleTime = 5000000; // 5000000 us
-                }
-                else
-                {
-                    // Schedule next packet transmission
-                    TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
-                }
+                
+                TxDutyCycleTime = 5000000; //us
                 DeviceState = DEVICE_STATE_CYCLE;
                 break;
             }
             case DEVICE_STATE_CYCLE:
             {
+                pc_debug.printf("DEVICE_STATE_CYCLE\r\n");
                 DeviceState = DEVICE_STATE_SLEEP;
 
                 // Schedule next packet transmission
@@ -907,6 +831,16 @@
                 // Wake up through events
                 break;
             }
+            case DEVICE_STATE_PROCESS_RESPONSE:
+            {
+
+                pc_debug.printf("DEVICE_STATE_PROCESS_RESPONSE\r\n");
+                pc_debug.printf("rssi %d snr %d %s \r\n",LoRaMacDownlinkStatus.Rssi,LoRaMacDownlinkStatus.Snr,status_str.c_str());
+                DeviceState = DEVICE_STATE_WAIT_REQUEST;
+                NextTx = true;
+                TimerStart( &SendTimerEvent );
+                break;
+            }
             default:
             {
                 DeviceState = DEVICE_STATE_INIT;
--- a/app/vt100.h	Sun Dec 11 22:50:32 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,213 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2015 Semtech
-
-Description: VT100 terminal support class
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __VT100_H__
-#define __VT100_H__
-
-#ifndef STRING_STACK_LIMIT
-#define STRING_STACK_LIMIT    120
-#endif
-
-/**
- * Implements VT100 terminal commands support.
- * Implments also the same behaviour has RawSerial class. The only difference
- * is located in putc fucntion where writeable check is made befor sending the character.
- */
-class VT100 : public SerialBase
-{
-public:
-    enum TextAttributes
-    {
-        ATTR_OFF      = 0,
-        BOLD          = 1,
-        USCORE        = 4,
-        BLINK         = 5,
-        REVERSE       = 7,
-        BOLD_OFF      = 21,
-        USCORE_OFF    = 24,
-        BLINK_OFF     = 25,
-        REVERSE_OFF   = 27,
-    };
-
-    enum Colors
-    {
-        BLACK   = 0,
-        RED     = 1,
-        GREEN   = 2,
-        BROWN   = 3,
-        BLUE    = 4,
-        MAGENTA = 5,
-        CYAN    = 6,
-        WHITE   = 7,
-    };
-
-    VT100( PinName tx, PinName rx ): SerialBase( tx, rx )
-    {
-        this->baud( 115200 );
-        // initializes terminal to "power-on" settings
-        // ESC c
-        this->printf( "\x1B\x63" );
-    }
-    
-    void ClearScreen( uint8_t param )
-    {
-        // ESC [ Ps J
-        // 0    Clear screen from cursor down
-        // 1    Clear screen from cursor up
-        // 2    Clear entire screen 
-        this->printf( "\x1B[%dJ", param );
-    }
-
-    void ClearLine( uint8_t param )
-    {
-        // ESC [ Ps K
-        // 0    Erase from the active position to the end of the line, inclusive (default)
-        // 1    Erase from the start of the screen to the active position, inclusive
-        // 2    Erase all of the line, inclusive
-        this->printf( "\x1B[%dK", param );
-    }
-
-    void SetAttribute( uint8_t attr )
-    {
-        // ESC [ Ps;...;Ps m
-        this->printf( "\x1B[%dm", attr );
-    }
-
-    void SetAttribute( uint8_t attr, uint8_t fgcolor, uint8_t bgcolor )
-    {
-        // ESC [ Ps;...;Ps m
-        this->printf( "\x1B[%d;%d;%dm", attr, fgcolor + 30, bgcolor + 40 );
-    }
-
-    void SetCursorMode( uint8_t visible )
-    {
-        if( visible == true )
-        {
-            // ESC [ ? 25 h
-            this->printf( "\x1B[?25h" );
-        }
-        else
-        {
-            // ESC [ ? 25 l
-            this->printf( "\x1B[?25l" );
-        }
-    }
-
-    void SetCursorPos( uint8_t line, uint8_t col )
-    {
-        // ESC [ Pl ; Pc H
-        this->printf( "\x1B[%d;%dH", line, col );
-    }
-
-    void PutStringAt( uint8_t line, uint8_t col, const char *s )
-    {
-        this->SetCursorPos( line, col );
-        this->printf( "%s", s );
-    }
-
-    void PutCharAt( uint8_t line, uint8_t col, uint8_t c )
-    {
-        this->SetCursorPos( line, col );
-        this->printf( "%c", c );
-    }
-
-    void PutHexAt( uint8_t line, uint8_t col, uint16_t n )
-    {
-        this->SetCursorPos( line, col );
-        this->printf( "%X", n );
-    }
-
-    void PutBoxDrawingChar( uint8_t c )
-    {
-        this->printf( "\x1B(0%c\x1b(B", c );
-    }
-    
-    bool Readable( void )
-    {
-        return this->readable( );
-    }
-    
-    uint8_t GetChar( void )
-    {
-        return this->getc( );
-    }
-
-    /*
-     * RawSerial class implmentation copy.
-     */
-    /** Read a char from the serial port
-     *
-     * @returns The char read from the serial port
-     */
-    int getc( )
-    {
-        return _base_getc();
-    }
-
-    /** Write a char to the serial port
-     *
-     * @param c The char to write
-     *
-     * @returns The written char or -1 if an error occured
-     */
-    int putc( int c )
-    {
-        while( this->writeable( ) != 1 );
-        return _base_putc( c );
-    }
-
-    /** Write a string to the serial port
-     *
-     * @param str The string to write
-     *
-     * @returns 0 if the write succeeds, EOF for error
-     */
-    int puts( const char *str )
-    {
-        while( *str )
-            putc( *str++ );
-        return 0;
-    }
-
-    // Experimental support for printf in RawSerial. No Stream inheritance
-    // means we can't call printf() directly, so we use sprintf() instead.
-    // We only call malloc() for the sprintf() buffer if the buffer
-    // length is above a certain threshold, otherwise we use just the stack.
-    int printf( const char *format, ... )
-    {
-        std::va_list arg;
-        va_start( arg, format );
-        int len = vsnprintf( NULL, 0, format, arg );
-        if( len < STRING_STACK_LIMIT )
-        {
-            char temp[STRING_STACK_LIMIT];
-            vsprintf( temp, format, arg );
-            puts( temp );
-        }
-        else
-        {
-            char *temp = new char[len + 1];
-            vsprintf( temp, format, arg );
-            puts( temp );
-            delete[] temp;
-        }
-        va_end( arg );
-        return len;
-    }
-
-private:
-    
-};
-
-#endif // __VT100_H__
--- a/mbed.bld	Sun Dec 11 22:50:32 2016 +0000
+++ b/mbed.bld	Sat Feb 25 14:28:52 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file