Espotel / Mbed 2 deprecated LoRaWAN_Serial_port_driven_and_configurable_ELMO_based_on_TxRx_Template

Dependencies:   SX1272lib-PABOOST-HW-Modification mbed

Fork of LoRaWAN_ELMO_TxRx_Template by Espotel

Files at this revision

API Documentation at this revision

Comitter:
KosTee
Date:
Mon Oct 10 12:00:53 2016 +0000
Parent:
9:c7c39e01bda1
Commit message:
Comments and documentation added

Changed in this revision

RadioHandler.cpp Show annotated file Show diff for this revision Revisions of this file
RadioHandler.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/RadioHandler.cpp	Mon Oct 10 09:53:50 2016 +0000
+++ b/RadioHandler.cpp	Mon Oct 10 12:00:53 2016 +0000
@@ -8,6 +8,7 @@
 Description: LoRaMac classA device implementation
 License: Revised BSD License, see LICENSE.TXT file include in the project
 Maintainer: Miguel Luis and Gregory Cristian
+Latest modifier: Teemu Koskinen
 */
 
 /*! \file classA/LoRaMote/main.c */
@@ -23,6 +24,19 @@
 #include "RadioHandler.h"
 #include <stdlib.h>
 
+/* -- Latest updates -- */
+//Version 1.0b
+/* RadioHandler contains new funtions */
+//void RadioSetup( void );
+//void SetRadioValues(void);
+//void SetDevEui(void);
+//void SetAppEui(void);
+//void SetAppKey(void);
+/* Some of these functions should not be here cause they are not about radio handling. Refactoring is recommended if this branch is continued */
+
+
+
+
 
 DigitalOut Led2(LED2);
 
@@ -105,6 +119,7 @@
 //static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI;
 //static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY;
 
+//Setting the default values
 uint8_t DevEui[8] = LORAWAN_DEVICE_EUI;
 uint8_t AppEui[8] = LORAWAN_APPLICATION_EUI;
 uint8_t AppKey[16] = LORAWAN_APPLICATION_KEY;
@@ -815,6 +830,7 @@
     Serial port(SERIAL_TX, SERIAL_RX);
     port.baud(9600);
     
+    /* Read answer to entering the configuration mode */
     while( 1 )
     {
         if (port.readable()) 
@@ -829,6 +845,7 @@
                 port.printf("%d\r\n",strncmp( answer, answer_yes, 3));
                 if (strncmp( answer, answer_yes, 3) == 0 )
                 {
+                 /* Setting the new values function*/
                  SetRadioValues();            
                 }
                 memset(answer,' ', sizeof(answer));
@@ -845,6 +862,7 @@
   
 }
 
+/* Function for setting new values */
 void SetRadioValues(void)
 {
     Serial port(SERIAL_TX, SERIAL_RX);
@@ -854,6 +872,7 @@
     uint16_t index = 0;
     printf("\r\nWelcome configuration. Please enter your selection:\r\n\t1: SetDevEui\r\n\t2: SetAppEui\r\n\t3: SetAppKey\r\n");
     
+    /* Read answer which item is goin to be updated */
     while( 1 )
     {
         if (port.readable()) 
@@ -868,6 +887,7 @@
                 port.printf("%d\r\n",strncmp( answer, answer_yes, 3));
                 if (strncmp( answer, answer_yes, 1) == 0 )
                 {
+                    /* Setting new DevEui */
                     SetDevEui();           
                 }
                 strcpy(answer_yes,"2\n");
@@ -875,6 +895,7 @@
                 port.printf("%d\r\n",strncmp( answer, answer_yes, 3));
                 if (strncmp( answer, answer_yes, 1) == 0 )
                 {
+                    /* Setting new AppEui */
                     SetAppEui();           
                 }
                 strcpy(answer_yes,"3\n");
@@ -882,6 +903,7 @@
                 port.printf("%d\r\n",strncmp( answer, answer_yes, 3));
                 if (strncmp( answer, answer_yes, 1) == 0 )
                 {
+                    /* Setting new AppKey */
                     SetAppKey();           
                 }        
                 memset(answer,' ', sizeof(answer));
@@ -896,11 +918,13 @@
         }
     }
     port.printf("Returning to setup\r\n");
+    /* Init Radio with new values */
     RadioInit();
+    /* Print current values, configure more or exit menu */ 
     RadioSetup();
 }
 
-/* Set new RadioHandler values */
+/* Set new DevEui values one by one */
 void SetDevEui(void)
 {
     char answer[100];
@@ -943,6 +967,7 @@
     }   
 }
 
+/* Set new AppEui values one by one */
 void SetAppEui(void)
 {
     char answer[100];
@@ -986,6 +1011,7 @@
       
 }
 
+/* Set new AppKey values one by one */
 void SetAppKey(void)
 {
     char answer[100];
@@ -1028,5 +1054,3 @@
       
 }
 
-
-
--- a/RadioHandler.h	Mon Oct 10 09:53:50 2016 +0000
+++ b/RadioHandler.h	Mon Oct 10 12:00:53 2016 +0000
@@ -12,7 +12,6 @@
 #ifndef __RADIOHANDLER_H__
 #define __RADIOHANDLER_H__
 
-
 void RadioInit( void );
 void RequestPacketTx( char *DataString, bool PeriodicRequested );
 void RadioHandler( void );
@@ -22,11 +21,8 @@
 void SetAppEui(void);
 void SetAppKey(void);
 
-//#if( OVER_THE_AIR_ACTIVATION != 0 )
-/* Copied these values to .h for easier handling. TK */
 extern uint8_t DevEui[8];
 extern uint8_t AppEui[8];
 extern uint8_t AppKey[16];
 
-
 #endif // __RADIOHANDLER_H__
--- a/main.cpp	Mon Oct 10 09:53:50 2016 +0000
+++ b/main.cpp	Mon Oct 10 12:00:53 2016 +0000
@@ -11,21 +11,37 @@
 Description: Main code for LORA radio code template
 License: Revised BSD License, see LICENSE.TXT file include in the project
 Maintainer: Pasi Pulkkinen
-Version 1.0
+Latest modifier: Teemu Koskinen
+Version 1.0b (b represents Serial port driven branch/fork)
 */
 
 #include "mbed.h"
 #include "RadioHandler.h"
 #include "Comissioning.h"
 
-// --- Important notes! ---
-// USE_BAND_868 has been defined in LoRaMac-board.h
-// OVER_THE_AIR_ACTIVATION at Comissioning.h is enabled
-// LORAWAN_PUBLIC_NETWORK at Comissioning.h is true
-// LORAWAN_DEVICE_EUI at Comissioning.h should be unique for each board
-// LORAWAN_APPLICATION_EUI at Comissioning.h should be unique for each conduit. Copy this to conduit network ID EUI
-// LORAWAN_APPLICATION_KEY at Comissioning.h ensures secure end to end communication. Copy this to conduit network key
-// dConduitBugs at LoRaMac.cpp patches a bug in Multitech Conduit Firmware 1.1.2 2016-01-13T09:59:04
+/* --- Important notes! --- */
+/* Original comments */
+// 1: USE_BAND_868 has been defined in LoRaMac-board.h
+// 2: OVER_THE_AIR_ACTIVATION at Comissioning.h is enabled
+// 3: LORAWAN_PUBLIC_NETWORK at Comissioning.h is true
+
+/* Configurable parameters through serial port after ButtonPressed */
+// 4: LORAWAN_DEVICE_EUI at Comissioning.h should be unique for each board
+// 5: LORAWAN_APPLICATION_EUI at Comissioning.h should be unique for each conduit. Copy this to conduit network ID EUI
+// 6: LORAWAN_APPLICATION_KEY at Comissioning.h ensures secure end to end communication. Copy this to conduit network key
+
+/* I am currently using Conduit 1.2.2 and this bugfix is not necessary anymore */
+// 7: dConduitBugs at LoRaMac.cpp patches a bug in Multitech Conduit Firmware 1.1.2 2016-01-13T09:59:04
+
+/* Serial port communication expanded */
+// 8: Up to 100 characters from Serial port are sent to gateway by presseing enter (\n)
+// 9: Button pressed prints current setup values and possibility to congigure them.
+
+/* -- Latest updates -- */
+//Version 1.0b
+//RadioHandler contains lot of new funtions
+/* Some of these functions should not be here cause they are not about radio handling. Refactoring is recommended if this branch is continued */
+
 
 DigitalOut Led1(LED1);
 static bool ButtonPressed = false;
@@ -52,7 +68,8 @@
 
     while( 1 )
     {
-        // Show some debug stuff in case Elmo button is pressed. Request packet transmission    
+        /* Device waits for ButtongPressed or readable input */ 
+        /* If readable and enter (\n) given device will send given message */    
         if (debugPort.readable()) {
             data[index]=debugPort.getc();
             
@@ -69,12 +86,7 @@
                 index=0;
                 }
         }  
-        
-
-
-
-
-                
+        /* ButtonPressed enters the config menu */                
         if (ButtonPressed)
         {        
             debugPort.printf("\r\nButton was pressed\r\n");
@@ -84,7 +96,7 @@
             //State/Status resets for next time
             ButtonPressed = false;
         }
-        
+        /* Scheduled communication */
         RadioHandler();
     }
 }
\ No newline at end of file