Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Branch:
Integration
Revision:
39:13e66d087ae9
Parent:
13:5414193da1de
--- a/Lora.cpp	Fri Oct 19 06:32:59 2018 +0000
+++ b/Lora.cpp	Fri Oct 19 15:08:35 2018 +0000
@@ -7,12 +7,15 @@
  *
  */
 
+#include "Context.h"
 
 // =====================================  Includes
+#ifndef TEST_ENVIRONMENT
 #include "Lora.h"
 #include "mbed.h"
 #include "main.h"
 #include "sx1280-hal.h"
+#endif
 
 // ==========================================================================  DEFINE
 #define MODE_LORA         // Lora modulation 
@@ -107,7 +110,7 @@
 //===============================================================================================================================
 {
         // Default value initialisation 
-    printf( "*** LORA ***  Lora Initialisation    \r\n");
+    DEBUG( "*** LORA ***  Lora Initialisation    \r\n");
     
     RxIrqMask = IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT;       // Mask of IRQs to listen to in rx mode
     TxIrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT;       // Mask of IRQs to listen to in tx mode
@@ -135,7 +138,7 @@
 
 
 //===============================================================================================================================
-void sendMessageLora () {
+void sendMessageLora (uint8_t terminalId, uint16_t gatewayId) {
 //===============================================================================================================================
     uint8_t         Buffer          [BUFFER_SIZE_MAX]       ;           // Buffer
     char            frameMISNET     [BUFFER_SIZE_MAX]       ;           // Misnet Frame
@@ -146,10 +149,9 @@
     dataCounter = dataCounter + 1 ;
     memset  ( &Buffer       , 0x00, BUFFER_SIZE_MAX );
     memset  ( &frameMISNET  , 0x00, BUFFER_SIZE_MAX );
-    
- 
+
     uint16_t    clearPart           =   0x0     ; 
-    
+
     uint32_t    servicePayload      =   0x0     ; 
     //char        serviceMessage[16]              ;     // TRACES
      
@@ -160,10 +162,10 @@
     uint8_t     DMI                 =   66      ;
     uint16_t    RCA                 =   0xBEEF & 0x7FFF ;
     uint32_t    MIC                 =   0xCAFECAFE  & 0xFFFFFFFF  ;
- 
+
 
-    clearPart   =  MODE_ADDR | ( ID_TERMINAL << 6 ) |  ID_GATEWAY ; 
-    printf( "*** LORA ***  CLEAR PART= %8X \r\n ", clearPart);
+    clearPart   =  MODE_ADDR | ( terminalId << 6 ) |  gatewayId ; 
+    DEBUG( "*** LORA ***  CLEAR PART= %8X \r\n ", clearPart);
 
     servicePayload =  (uint32_t)( (SFT & 0x03)  << 30) | 
                       (uint32_t)( (DFT & 0x03)  << 28) | 
@@ -182,17 +184,20 @@
     // SERVICE + Indianess correction 
     pointer = (uint8_t*) &servicePayload ;  for (int i=0, j=3 ; i<4 ; i++, j--)    frameMISNET[2+i] = pointer[j] ;
     pointer = (uint8_t*) &MIC ;             for (int i=0, j=3 ; i<4 ; i++, j--)    frameMISNET[6+i] = pointer[j] ;
-  
-    printf( "*** LORA ***  START Buffer  "); for (int i = 0 ; i<10 ; i++)  printf ("%02X,", frameMISNET[i] ) ; printf( "\n") ; 
+
+#ifdef TEST_ENVIRONMENT
+    DEBUG( "*** LORA ***  START Buffer  "); for (int i = 0 ; i<10 ; i++)  DEBUG("%02X,", frameMISNET[i] ) ; DEBUG("\n") ;
+#endif
 
     
-    int n = sprintf (frameMISNET, "%1c%1c",  ID_TERMINAL, ID_GATEWAY);
+    int n = sprintf (frameMISNET, "%1c%1c",  terminalId, gatewayId);
    
     pointer = (uint8_t*) &dataCounter  ; for (int i = 0 ; i<4 ; i++)  frameMISNET[2+i] = pointer[i] ;
                                                                  //(int32*)&frameMISNET[2]=(int32*)&ptr_int; // -> aton OR ntoa                                                                                                                         
-
-    printf( "*** LORA ***  TX SEND   %05d  ", dataCounter);
-       for (int i = 0 ; i<10 ; i++)  printf ("%d,", frameMISNET[i] ) ; printf( "\n") ; 
+#ifdef TEST_ENVIRONMENT
+    DEBUG("*** LORA ***  TX SEND   %05d  ", dataCounter);
+    for (int i = 0 ; i<10 ; i++)  DEBUG("%d,", frameMISNET[i] ) ; DEBUG("\n") ;
+#endif
        
     
     // Send SF, BW, COUNTER, POWER, FREQ, TIMETX, TIMELOOP, RSSIVALUE
@@ -227,7 +232,7 @@
 
 // Time out si pas de message de CR recu
 void        watchDogRxCRNoReceived ()  { 
-    printf( "*** LORA ***  watchDogRxNoReceive NO RESPONSE    \r\n");    
+    DEBUG( "*** LORA ***  watchDogRxNoReceive NO RESPONSE    \r\n");    
 }   // Force new emission 
 
 
@@ -350,7 +355,7 @@
 void OnTxDone       ( void ) {
 //==============================================================================
     valueTimeTx = timerRadio.read_ms () ; 
-    printf( "*** LORA ***  OnTxDone \r\n" );
+    DEBUG( "*** LORA ***  OnTxDone \r\n" );
     TxLed   = 0 ;
     setRadioRx () ; 
 }
@@ -367,7 +372,7 @@
  
     RxLed               =   1   ;  // Show the reception 
 
-    printf( "*** LORA ***  RX DONE \r\n" );
+    DEBUG( "*** LORA ***  RX DONE \r\n" );
     valueTimeLoop = timerRadio.read_ms ()   ; 
     timerRadio.stop       ()  ; 
     watchDogRx.detach     ()  ;      
@@ -383,7 +388,7 @@
     
     Buffer1[7] = 0 ; 
 
-    printf  ( "*** LORA *** RX DONE =>  %s \r\n", Buffer1 );   wait(1) ; // flush serial 
+    DEBUG  ( "*** LORA *** RX DONE =>  %s \r\n", Buffer1 );   wait(1) ; // flush serial 
      
     // Extract value