LoRA production board

Dependencies:   mbed LoRaWAN-lib SX1272Liby

Fork of frdm_LoRa_Connect_Woodstream_Demo_tjm by Timothy Mulrooney

Revision:
6:ee58dcb61940
Parent:
5:df5350d5e2fc
Child:
8:7af52843c8a9
--- a/app/main.cpp	Wed Mar 09 21:21:53 2016 +0000
+++ b/app/main.cpp	Fri Mar 11 20:01:15 2016 +0000
@@ -11,6 +11,10 @@
 License: Revised BSD License, see LICENSE.TXT file include in the project
 
 Maintainer: Miguel Luis and Gregory Cristian
+Modified: T. J. Mulrooney J-Factor Embedded Technoligies
+
+Version     Date        Comments
+0.1         3/10/16     first draft of Woodstream Demo
 */
 #include "mbed.h"
 #include "board.h"
@@ -20,6 +24,13 @@
 #include "Comissioning.h"
 #include "SerialDisplay.h"
 
+#include "vt100.h"
+extern VT100 vt;
+#define MAJOR 0
+#define MINOR 1
+
+char versionTimeDate[40];
+
 /*!
  * Join requests trials duty cycle.
  */
@@ -45,7 +56,7 @@
 /*!
  * LoRaWAN confirmed messages
  */
-#define LORAWAN_CONFIRMED_MSG_ON                    true
+#define LORAWAN_CONFIRMED_MSG_ON                    1
 
 /*!
  * LoRaWAN Adaptive Data Rate
@@ -265,6 +276,10 @@
     SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
     
     SerialDisplayUpdateLedState( 3, AppLedStateOn );
+                
+    vt.SetCursorPos( 43, 0 );
+    sprintf(versionTimeDate,"V %d.%d %s %s",MAJOR,MINOR,__DATE__,__TIME__);
+    vt.printf("%s",versionTimeDate);
 }
 
 void SerialRxProcess( void )
@@ -456,6 +471,12 @@
     // Switch LED 1 OFF
     Led1State = false;
     Led1StateChanged = true;
+                    
+//    char str[40];
+//    vt.SetCursorPos( 44, 0 );
+//    sprintf(str,"PowerOn: %X killStatus: %X",powerOn?1:0,killStatus?1:0);
+//    vt.printf("%s",str);
+
 }
 
 /*!
@@ -733,14 +754,14 @@
 
     led1 = 1;
     led2 = 1;
-    BoardInit( );
-    SerialDisplayInit( );
+    BoardInit( );                                       /* set up timers and any other board initialization */
+    SerialDisplayInit( );                               /* draw complete initial screen */
  
-    DeviceState = DEVICE_STATE_INIT;
+    DeviceState = DEVICE_STATE_INIT;                    /* set initial state to initilzation */
 
     while( 1 )
     {
-       SerialRxProcess( );
+        SerialRxProcess( );                             /* refresh screen if "r/R" hit */
         if( IsNetworkJoinedStatusUpdate == true )
         {
             IsNetworkJoinedStatusUpdate = false;
@@ -748,65 +769,71 @@
             LoRaMacMibGetRequestConfirm( &mibReq );
             SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined );
         }
-        if( Led1StateChanged == true )
+        if( Led1StateChanged == true )                  /* if LED changed update display and LED */               
         {
             Led1StateChanged = false;
             SerialDisplayUpdateLedState( 1, Led1State );
-           led1 = !Led1State;
+            led1 = !Led1State;
         }
-        if( Led2StateChanged == true )
+        if( Led2StateChanged == true )                  /* if LED changed update display and LED */
         {
             Led2StateChanged = false;
             SerialDisplayUpdateLedState( 2, Led2State );
             led2 = !Led2State;
        }
-        if( Led3StateChanged == true )
+        if( Led3StateChanged == true )                  /* if LED changed update display and LED */
         {
             Led3StateChanged = false;
             SerialDisplayUpdateLedState( 3, AppLedStateOn );
         }
-        if( UplinkStatusUpdated == true )
+        if( UplinkStatusUpdated == true )               /* data sent changed update the Uplink display */
         {
             UplinkStatusUpdated = false;
             SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize );
         }
-        if( DownlinkStatusUpdated == true )
+        if( DownlinkStatusUpdated == true )             /* data sent changed update the Downlink display */
         {
             DownlinkStatusUpdated = false;
             SerialDisplayUpdateLedState( 2, Led2State );
             SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize );
         }
         
-        switch( DeviceState )
+        switch( DeviceState )                           /* handle the device state*/
         {
-            case DEVICE_STATE_INIT:
+            case DEVICE_STATE_INIT:                     /* initial state called on start up */
             {
+                /* initialize to static functions in this file and battery function*/
                 LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
                 LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
                 LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
                 LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
                 LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks );
+                
+                vt.SetCursorPos( 43, 0 );
+                sprintf(versionTimeDate,"V %d.%d %s %s Battery: %d",MAJOR,MINOR,__DATE__,__TIME__,LoRaMacCallbacks.GetBatteryLevel());
+                vt.printf("%s",versionTimeDate);
 
                 TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );
 
-                TimerInit( &Led1Timer, OnLed1TimerEvent );
+                TimerInit( &Led1Timer, OnLed1TimerEvent );          /* initialize led1 timer for 25 ms but do not start*/
                 TimerSetValue( &Led1Timer, 25000 );
 
-                TimerInit( &Led2Timer, OnLed2TimerEvent );
+                TimerInit( &Led2Timer, OnLed2TimerEvent );          /* initialize led2 timer for 25 ms but do not start*/
                 TimerSetValue( &Led2Timer, 25000 );
 
                 mibReq.Type = MIB_ADR;
                 mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
-                LoRaMacMibSetRequestConfirm( &mibReq );
+                LoRaMacMibSetRequestConfirm( &mibReq );             /* set AdrEnable Paramter */
 
                 mibReq.Type = MIB_PUBLIC_NETWORK;
                 mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
-                LoRaMacMibSetRequestConfirm( &mibReq );
+                LoRaMacMibSetRequestConfirm( &mibReq );             /* set EnablePublicNetwork parameter */
 
 #if defined( USE_BAND_868 )
                 LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON );
                 SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON );
 #endif
+                /* update the VT100 display */
                 SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION );
                 SerialDisplayUpdateAdr( LORAWAN_ADR_ON );
                 SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK );
@@ -821,17 +848,18 @@
 #if( OVER_THE_AIR_ACTIVATION != 0 )
                 MlmeReq_t mlmeReq;
 
-                mlmeReq.Type = MLME_JOIN;
+                mlmeReq.Type = MLME_JOIN;               /* set up join command */
 
-                mlmeReq.Req.Join.DevEui = DevEui;
+                mlmeReq.Req.Join.DevEui = DevEui;       /* set up EUIs and key */
                 mlmeReq.Req.Join.AppEui = AppEui;
                 mlmeReq.Req.Join.AppKey = AppKey;
 
                 if( NextTx == true )
                 {
-                    LoRaMacMlmeRequest( &mlmeReq );
+                    LoRaMacMlmeRequest( &mlmeReq );     /* request to join network */
                 }
 
+                /* update VT100 display with EUIs and key info */
                 SerialDisplayUpdateEui( 5, DevEui );
                 SerialDisplayUpdateEui( 6, AppEui );
                 SerialDisplayUpdateKey( 7, AppKey );