Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Files at this revision

API Documentation at this revision

Comitter:
FCH_31
Date:
Mon Oct 22 09:37:50 2018 +0000
Parent:
36:14a8da4108d5
Commit message:
avec radio;

Changed in this revision

Controller.cpp Show annotated file Show diff for this revision Revisions of this file
Controller.hpp Show annotated file Show diff for this revision Revisions of this file
DataBase.cpp Show annotated file Show diff for this revision Revisions of this file
DataBase.hpp Show annotated file Show diff for this revision Revisions of this file
ExtMemory.cpp Show annotated file Show diff for this revision Revisions of this file
ExtMemory.hpp Show annotated file Show diff for this revision Revisions of this file
Lora.cpp Show diff for this revision Revisions of this file
Lora.h Show diff for this revision Revisions of this file
Loracpp.txt Show annotated file Show diff for this revision Revisions of this file
Lorah.txt Show annotated file Show diff for this revision Revisions of this file
Radio.cpp Show annotated file Show diff for this revision Revisions of this file
Radio.h Show annotated file Show diff for this revision Revisions of this file
Service.cpp Show annotated file Show diff for this revision Revisions of this file
Service.hpp Show annotated file Show diff for this revision Revisions of this file
Tftlcd.cpp 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/Controller.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/Controller.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -19,7 +19,6 @@
 
 #ifndef TEST_ENVIRONMENT
 #include "Tftlcd.h"
-#include "Lora.h"
 #endif
 
 
@@ -34,9 +33,9 @@
 using namespace misnet;
 
 
-static DataBase dataBase    ;                   // Database creation 
-static MessageFactory messageFactory    ;       // Messages Maker   (Sensors, Config, Synchro ...)
-static ExtMemory extMemory  ;                   // Memoire externe
+static DataBase         dataBase            ;                   // Database creation 
+static MessageFactory   messageFactory      ;                   // Messages Maker   (Sensors, Config, Synchro ...)
+static ExtMemory        extMemory           ;                   // Memoire externe
 
 #ifndef TEST_ENVIRONMENT
 Tftlcd     tftlcd      ;   // eventuellement a déplacer   (uniquement valable sur les conf nucléo)
@@ -65,10 +64,11 @@
 
 #ifndef TEST_ENVIRONMENT
 void Controller::start (){     // @brief Start the Controller
-    initInterfaces      ()  ;   // Primary interface uart, i2c, spi ...
-    extMemory.read      (&dataBase)  ;   // Read memory to know the list of sensor availables, fill DataBase
-    initSensors         ()  ;   // Depend of the list of sensors  launch each
-    initActuators       ()  ;   // Depend of the list of actuator launch each
+
+    initInterfaces      ()          ;   // Primary interface uart, i2c, spi ...
+    extMemory.read      (&dataBase) ;   // Read memory to know the list of sensor availables, fill DataBase
+    initSensors         ()          ;   // Depend of the list of sensors  launch each
+    initActuators       ()          ;   // Depend of the list of actuator launch each
     
     // Read Radio parameter in Database for Lora interface   (example)
     uint32_t                        freq    ; 
@@ -80,14 +80,16 @@
     int16_t                         payload_heartbeat_period;
     dataBase.getRadioParameter  ( freq, bw, sf, pwr, bsz, terminal_heartbeat_period, payload_heartbeat_period) ; 
      
-    initLora        ( freq, bw, sf, pwr ) ;    // Initialise the radio module 
+    //initLora        ( freq, bw, sf, pwr ) ;    // Initialise the radio module 
     
-    printf( "*** APP ***  start   %ld %d %d %d %d %d \r\n",freq, bw, sf, pwr, bsz, time) ; 
+    printf( "*** CTRL ***  start   %ld %d %d %d %d %d \r\n",freq, bw, sf, pwr, bsz, time) ; 
 
     tftlcd.Update   ( freq, bw, sf, pwr, bsz,  payload_heartbeat_period ) ;     // Show information 
     
-    printf( "*** APP_ ***  Start Controller (Send message GoodHealth)\r\n");
+    printf( "*** CTRL ***  Start Controller (Send message GoodHealth)\r\n");
+    
     messageFactory.buildGoodhealth () ; 
+    
     //sendMessageLora () ; 
 }
 
@@ -97,11 +99,13 @@
     debugSerial = new RawSerial (USBTX,USBRX, 230400);        // Debug Link 
     tftlcd.Init () ;  
     // I2C, SPI, UART .... 
+    
+    printf( "*** CTRL ***  End of Init Interface \r\n");
 }
 
 
 void Controller::initSensors(){
-    printf( "*** APPP ***  initSensors \r\n");  
+    printf( "*** CTRL ***  initSensors \r\n");  
     // depend of the list identified   (example)
     //bme280 = new BME280(i2c_rt);
     // depend of the list identified 
@@ -118,7 +122,7 @@
 
 void Controller::manageSensors     () {
     readSensors                     () ; 
-    messageFactory.buildSensors           () ; 
+    messageFactory.buildSensors     () ; 
     sendMessage                     () ; 
 }
 
@@ -144,23 +148,23 @@
 
 void Controller::getScheduling (uint16_t &TimerPayload,  uint16_t &TimerGoodhealth, uint16_t &TimerSynchro, uint16_t &TimerListening ) {
 
-    TimerPayload        = 3L     ;   // TODO  Dépend de la lecture de la memoire  (ici simulé)
+    TimerPayload        = 5L     ;   // TODO  Dépend de la lecture de la memoire  (ici simulé)
     TimerGoodhealth     = 60L    ; 
     TimerSynchro        = 0L     ;  
     TimerListening      = 0L     ;                  
 }
 
 void Controller::sendMessage       () {
-    printf( "*** APP_ ***  sendMessage \r\n");
-    sendMessageLora () ; 
+    printf( "*** CTRL ***  sendMessage \r\n");
+    //sendMessageLora () ; 
 }
 
 
 void Controller::readSensors       () {
-    printf( "*** APP_ ***  readSensors \r\n");
-    printf("*** APP *** loop on all channels\r\n");
+    printf("*** CTRL ***  readSensors \r\n");
+    printf("*** CTRL ***  loop on all channels\r\n");
     short nbSensors = dataBase.getNbService(Service::SENSOR);
-    printf("*** APP *** there are %d sensors in this payload\r\n", nbSensors);
+    printf("*** CTRL *** there are %d sensors in this payload\r\n", nbSensors);
     // depend of the list identified 
     // Each sensor sends an event in the db
     //iks01a2.read () ; 
--- a/Controller.hpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/Controller.hpp	Mon Oct 22 09:37:50 2018 +0000
@@ -21,10 +21,29 @@
 #include "DataBase.hpp"
 
 
+
 namespace misnet {
     class Controller;
 }
 
+// A deplacer ... 
+typedef struct {
+    uint8_t         addrType        ;       // Smart Tool/ Gen / Iot/ Asset
+    uint16_t        terminalAddr    ;       //
+    uint8_t         subnetAddr      ;       //
+    uint8_t         raw[2]          ;       // Raw value content Type and Terminal/Network id
+    // TODO  Finish coding raw value
+} ModeParameter ;
+
+
+
+#define     SMART_TOOL_MODE     0x00
+#define     GENERIC_MODE        0x40
+#define     IOT_MODE            0x80
+#define     BROADCAST_MODE      0xC0
+
+
+
 
 class misnet::Controller {
 
--- a/DataBase.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/DataBase.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -61,7 +61,7 @@
     _terminal_heartbeat_period  = terminal_heartbeat_period   ;
     _payload_heartbeat_period  = payload_heartbeat_period   ;
 
-     printf( "*** DTB ***  setRadioParameter   %ld %d %d %d %d %d %d\r\n", _rf_frequency, _lora_bw,
+     printf( "*** DTB ***  setRadioParameter   %u %d %d %d %d %d %d\r\n", _rf_frequency, _lora_bw,
      _lora_sf, _tx_output_power, _buffer_size_max,_terminal_heartbeat_period, _payload_heartbeat_period);
 }
 #endif
--- a/DataBase.hpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/DataBase.hpp	Mon Oct 22 09:37:50 2018 +0000
@@ -48,14 +48,16 @@
         BROADCAST_IOT = 3   // Broadcast IOT (the terminal is not attached to a gateway)
     };
 
+ 
     public:              
         DataBase     ();
         ~DataBase    ();
 
+
         void        init () ;
 
         TERMINAL_TYPE getTerminalType() {
-            return this->_terminal_type;
+            //return this->_terminal_type;    // FC to compile
         }
 
         short         getNbService              (Service::DEVICE_TYPE cdt); // return the number of declared channels for the payload 
--- a/ExtMemory.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/ExtMemory.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -20,6 +20,8 @@
 // =====================================  Methods of class
 
 void ExtMemory::read (DataBase* dataBase) {
+    
+    printf ( "*** EXTM ***   Read start \n\r");
 
     // read eeprom  and initialize database
     //(Example)
@@ -29,7 +31,7 @@
     int32_t  pos=0;
     ServiceDefinition sd,prev_sd;
     Header hd;
-    EEPROM ep(I2C_SDA, I2C_SCL, EEPROM_ADDR, EEPROM::T24C04);
+    //EEPROM ep (I2C_SDA, I2C_SCL, EEPROM_ADDR, EEPROM::T24C04);     // FC to compile
 
     DEBUG( "*** EXTMEM Reading external memory ***\n");
 
@@ -38,8 +40,8 @@
 #endif
 
     // ---- read header block
-    ep.read(pos, (void *) &hd, sizeof(hd));
-    if (ep.getError() != 0) error(ep.getErrorMessage());
+    //ep.read(pos, (void *) &hd, sizeof(hd));
+    //if (ep.getError() != 0) error(ep.getErrorMessage());
     pos += sizeof(hd);
     DEBUG("*** [reading header] services:%d mode:0x%02x payloadID:0x%04x ***\n",
             hd.nb_of_services, hd.operating_mode, hd.payload_id);
@@ -50,7 +52,10 @@
     std::vector<Service*> services = std::vector<Service*>();
     Component* component;
     std::string name[6] = {"HTS221","LPS22HB","LSM303D","LSM6DSL","BME280","DS18B20"}; // debug purpose
+    
+    /*  FC   pour débloquer l'execution 
     while(servicesNbr<servicesTotal){
+
         while(ep.read(pos, (void *) &sd, sizeof(sd)),(servicesNbr<servicesTotal)){
             pos += sizeof(sd);
             if (ep.getError() != 0) { error(ep.getErrorMessage()); continue;}
@@ -85,6 +90,7 @@
         services.clear();
         DEBUG("\n");
     }
+    */
     Payload * payload = new Payload((misnet::Payload::PAYLOAD_ID) hd.payload_id, components, hd.payload_base_period);
     dataBase->setPayload(payload);
 
@@ -247,7 +253,12 @@
 //    // Enregistrement de la payload dans la database
 //    // ---------------------------------------------
 //    dataBase->setPayload(payload);
+
+    printf ( "*** EXTM ***   Read done \n\r");
+
 }
+
+/*
 void ExtMemory::populate (void) {
 
     int32_t   pos=0;
@@ -330,4 +341,5 @@
     pos += sizeof(sd);
     printf("service5 ID:0x%02x type:0x%02x code:0x%04x\n",
             sd_r.component_id, sd_r.service_type, sd_r.mistnet_code);
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file
--- a/ExtMemory.hpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/ExtMemory.hpp	Mon Oct 22 09:37:50 2018 +0000
@@ -43,7 +43,7 @@
         uint8_t     value_type;
         uint8_t     service_type;
         uint8_t     component_id;
-        uint8_t     value_type;
+        // uint8_t     value_type;      FC to compile
         uint8_t     component_group;
         uint8_t     service_state;
         uint8_t     access_type;
--- a/Lora.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,463 +0,0 @@
-/*
- * MISNet   
- *
- *  Lora:   Radio Management 
- *
- *  Created on: August 17, 2018       Author: Francis CHATAIN
- *
- */
-
-
-// =====================================  Includes
-#include "Lora.h"
-#include "mbed.h"
-#include "main.h"
-#include "sx1280-hal.h"
-
-// ==========================================================================  DEFINE
-#define MODE_LORA         // Lora modulation 
-
-#define TX_TIMEOUT_VALUE        100                         // ms   Number of tick size steps for tx timeout
-#define RX_TIMEOUT_VALUE        100                         // ms   Number of tick size steps for rx timeout
-#define RX_TIMEOUT_TICK_SIZE    RADIO_TICK_SIZE_1000_US     // Size of ticks (used for Tx and Rx timeout)
-#define MODE_ADDR               0x8000 
-
-
-// ==========================================================================  HW 
-DigitalOut  F_CS        ( D6 )  ;     // MBED description of pin
-DigitalOut  SD_CS       ( D8 )  ;     // MBED description of pin
-DigitalOut  ANT_SW      ( A3 )  ;
-DigitalOut  TxLed       ( A4 )  ;
-DigitalOut  RxLed       ( A5 )  ;
-
-
-// ==========================================================================  VARIABLES 
-uint16_t    RxIrqMask ;       // Mask of IRQs to listen to in rx mode
-uint16_t    TxIrqMask ;       // Mask of IRQs to listen to in tx mode
-
-
-uint32_t    valueTimeTx      ; 
-uint32_t    valueTimeLoop    ;
-
-int         dataCounter     = 0 ;
-uint8_t     oldFreq         ; 
-uint8_t     oldBw           ; 
-uint8_t     oldPwr          ; 
-uint8_t     oldSf           ; 
-uint8_t     oldTimer        ; 
-
-// States of the application
-typedef enum  { APP_LOWPOWER, APP_RX, APP_RX_TIMEOUT, APP_RX_ERROR, APP_TX, APP_TX_TIMEOUT, } AppStates_t ;
-AppStates_t AppState = APP_LOWPOWER;        // Init State of the application
-
-PacketStatus_t  PacketStatus        ;
-int8_t          RssiValue    = 0    ;
-int8_t          SnrValue     = 0    ;
-
-ModulationParams_t          modulationParams;
-PacketParams_t              PacketParams    ;        // Locals parameters and status for radio API
-PacketStatus_t              packetStatus    ;        // NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
-
-uint32_t                    RF_FREQUENCY        ;   // HzNominal frequency
-RadioLoRaBandwidths_t       LORA_BW             ;   /* 200; 400; 800; 1600 */
-RadioLoRaSpreadingFactors_t LORA_SF             ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
-int8_t                      TX_OUTPUT_POWER     ;   /* Output power in dBm [-18..+13] dBm */ 
-uint8_t                     BUFFER_SIZE_MAX     ;   /* Payload size max */
-int16_t                     TIMER               ;   /* timer entre reemission en ms */
-uint8_t                     BUFFER_SIZE_MIN     ;   /* Payload return size */
-
-
-// ==========================================================================  Function  
-void        initRadio              () ;
-void        setRadioTx             () ;
-void        setRadioRx             () ;
-void        watchDogRxCRNoReceived () ; 
-
-
-
-Timer       timerRadio       ;
-Timeout     watchDogRx          ;
-Timeout     watchDogTx          ;
-
-void OnTxDone       ( void );               // Function to be executed on Radio Tx Done event
-void OnRxDone       ( void );               // Function to be executed on Radio Rx Done event
-void OnTxTimeout    ( void );               // Function executed on Radio Tx Timeout event
-void OnRxTimeout    ( void );               // Function executed on Radio Rx Timeout event
-void OnRxError      ( IrqErrorCode_t );     // Function executed on Radio Rx Error event
-
-RadioCallbacks_t callbacks  =  {
-    &OnTxDone,        // txDone
-    &OnRxDone,        // rxDone
-    NULL,             // syncWordDone
-    NULL,             // headerDone
-    &OnTxTimeout,     // txTimeout
-    &OnRxTimeout,     // rxTimeout
-    &OnRxError,       // rxError
-    NULL,             // rangingDone
-    NULL,             // cadDone
-};
-
-//                    mosi, miso,   sclk,  nss,  busy , dio1 , dio2, dio3, rst , callbacks...
-SX1280Hal Radio     ( D11 , D12 ,   D13 ,  D7 ,  D3   , D5   , NC  , NC  , A0  , &callbacks );
-
-
-
-//===============================================================================================================================
-void initLora (uint32_t rf,RadioLoRaBandwidths_t bw,RadioLoRaSpreadingFactors_t sf,int8_t pwr) 
-//===============================================================================================================================
-{
-        // Default value initialisation 
-    printf( "*** 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
-
-    RF_FREQUENCY        =   rf              ;   // HzNominal frequency
-    LORA_BW             =   bw              ;   /* 200; 400; 800; 1600 */
-    LORA_SF             =   sf              ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
-    TX_OUTPUT_POWER     =   pwr             ;   /* Output power in dBm [-18..+13] dBm */ 
-    BUFFER_SIZE_MAX     =   100             ;   /* Payload size max */
-    BUFFER_SIZE_MIN     =   5               ;   /* Payload return size */
-    TIMER               =   1000            ;   /* timer entre reemission en ms */ 
-    
-    
-    
-    Radio.Reset                 ()              ;  
-    Radio.Init                  ()              ;
-    initRadio                   ()              ;            
-    Radio.SetRegulatorMode      ( USE_DCDC )    ;       // Can also be set in LDO mode but consume more power
-    wait_ms                     ( 10 )          ;       // wait for on board DC/DC start-up time
-    
-    TxLed   = 0     ;
-    RxLed   = 0     ;
-
-}
-
-
-//===============================================================================================================================
-void sendMessageLora () {
-//===============================================================================================================================
-    uint8_t         Buffer          [BUFFER_SIZE_MAX]       ;           // Buffer
-    char            frameMISNET     [BUFFER_SIZE_MAX]       ;           // Misnet Frame
-    uint8_t         *pointer                                ;
-    char            *ptr_int                                ;
-    
-    
-    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
-     
-    uint8_t     SFT                 =   0       ;
-    uint8_t     DFT                 =   0       ;
-    uint8_t     FDL                 =   8       ;
-    uint8_t     BL                  =   7       ;
-    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);
-
-    servicePayload =  (uint32_t)( (SFT & 0x03)  << 30) | 
-                      (uint32_t)( (DFT & 0x03)  << 28) | 
-                      (uint32_t)( (FDL & 0x3F)  << 22) | 
-                      (uint32_t)( (BL  & 0x07)  << 19) | 
-                      (uint32_t)( (DMI & 0xFF)  << 11) | 
-                      (RCA & 0x7FF)                   ;
-                      
-    //sprintf (serviceMessage, "%08X%08X", servicePayload, MIC) ;    // traces 
-    //printf( "*** LORA ***  SERVICE Payload = %08X \r\n ", servicePayload);
-    //printf( "*** LORA ***  SERVICE MIC     = %08X \r\n ", MIC);
-    
-    // CLEAR PART + Indianess correction 
-    pointer = (uint8_t*) &clearPart ;       for (int i = 0, j=1 ; i<2 ; i++, j--)  frameMISNET[j]   = pointer[i] ;
-       
-    // 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") ; 
-
-    
-    int n = sprintf (frameMISNET, "%1c%1c",  ID_TERMINAL, ID_GATEWAY);
-   
-    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") ; 
-       
-    
-    // Send SF, BW, COUNTER, POWER, FREQ, TIMETX, TIMELOOP, RSSIVALUE
-    frameMISNET[6] = LORA_SF            ; 
-    ptr_int = (char*) &LORA_BW          ; 
-    frameMISNET[7]= ptr_int[1]          ;   
-    frameMISNET[8]= ptr_int[0]          ;
-    frameMISNET[9] = TX_OUTPUT_POWER    ; 
-    ptr_int = (char*) &RF_FREQUENCY     ; for (int i = 0 ; i<4 ; i++)  frameMISNET[10+i] = ptr_int[i] ; 
-    ptr_int = (char*) &valueTimeTx      ; for (int i = 0 ; i<4 ; i++)  frameMISNET[14+i] = ptr_int[i] ;   //printf( "*** LORA ***  TimeTx   %d  %d  ", valueTimeTx, valueTimeLoop);  //delay temps Tx   
-    ptr_int = (char*) &valueTimeLoop    ; for (int i = 0 ; i<4 ; i++)  frameMISNET[18+i] = ptr_int[i] ;   //delay temps Loop  
-    frameMISNET[22] = RssiValue ; 
-    
-    memcpy                      ( Buffer    , frameMISNET   , 23    );
-    
-    valueTimeTx   =  0 ; 
-    valueTimeLoop =  0 ; 
-    timerRadio.reset        ()  ;    // Record tile for close loop
-    timerRadio.start        ()  ; 
-    setRadioTx              ()  ; 
-    TxLed           =       1   ;
-    PacketParams.Params.LoRa.PayloadLength          =   23         ;
-    Radio.SetPacketParams                           ( &PacketParams )           ;
-    Radio.SendPayload       ( Buffer    , 23,( TickTime_t ) {RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE} );
-    TxLed           =       0   ;
-
-    //printf( "*** LORA ***  ARM watchDogRxRxRxRx  \r\n" );
-    watchDogRx.attach (&watchDogRxCRNoReceived, 1.0);     // Arm watchDogRx  if the response is not received in less 500 ms =>  force retry   
-}
-//===============================================================================================================================
-
-
-// Time out si pas de message de CR recu
-void        watchDogRxCRNoReceived ()  { 
-    printf( "*** LORA ***  watchDogRxNoReceive NO RESPONSE    \r\n");    
-}   // Force new emission 
-
-
-
-
-//===============================================================================================================================
-void initRadio () {
-//===============================================================================================================================
-    F_CS   = 1  ;
-    SD_CS  = 1  ;
-    ANT_SW = 1  ;
-    
-    // SET MODULATION
-    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
-    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
-    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW_0200            ; 
-    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF7                ; 
-    // SET PACKET PARAM
-    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
-    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
-    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
-    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MAX         ;
-    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
-    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
-    // RADIO
-    Radio.SetStandby                                ( STDBY_RC  )               ;
-    Radio.SetPacketType                             ( modulationParams.PacketType );
-    Radio.SetModulationParams                       ( &modulationParams )       ;
-    Radio.SetPacketParams                           ( &PacketParams )           ;   
-    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
-    Radio.SetTxParams                               ( TX_OUTPUT_POWER, RADIO_RAMP_20_US )       ;
-    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
-    //AppState                    =                   APP_LOWPOWER;
-}
-//===============================================================================================================================
-
-
-
-//===============================================================================================================================
-void setRadioTx () {
-//=============================================================================================================================== 
-    RxLed  = 0  ;
-    TxLed  = 0  ;
-    F_CS   = 1  ;
-    SD_CS  = 1  ;
-    ANT_SW = 1  ;
-
-    // SET MODULATION
-    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
-    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
-    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW    ; 
-    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF    ; 
-
-    // SET PACKET PARAM
-    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
-    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
-    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
-    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MAX         ;
-    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
-    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
-
-    // RADIO
-    Radio.SetStandby                                ( STDBY_RC  )               ;
-    Radio.SetPacketType                             ( modulationParams.PacketType );
-    Radio.SetModulationParams                       ( &modulationParams )       ;
-    Radio.SetPacketParams                           ( &PacketParams )           ;
-    Radio.SetRfFrequency                            ( RF_FREQUENCY )            ;
-    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
-    Radio.SetTxParams                               ( TX_OUTPUT_POWER, RADIO_RAMP_20_US )       ;
-    Radio.SetDioIrqParams                           ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE );
-    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
-
-    //AppState                    =                   APP_LOWPOWER;
- 
- }
-
-
-//===============================================================================================================================
-void setRadioRx () {
-//===============================================================================================================================
-    RxLed  = 0  ;
-    TxLed  = 0  ;   
-    
-    F_CS   = 1  ;
-    SD_CS  = 1  ;
-    ANT_SW = 1  ;
-    
-    // SET MODULATION
-    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
-    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
-    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW_0200            ; 
-    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF7                ; 
-
-    // SET PACKET PARAM
-    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
-    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
-    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
-    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MIN         ;
-    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
-    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
-
-    // RADIO
-    Radio.SetStandby                                ( STDBY_RC  )               ;
-    Radio.SetPacketType                             ( modulationParams.PacketType );
-    Radio.SetModulationParams                       ( &modulationParams )       ;
-    Radio.SetPacketParams                           ( &PacketParams )           ;
-    Radio.SetRfFrequency                            ( RF_FREQUENCY + 440000UL)            ;
-
-    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
-    Radio.SetDioIrqParams                           ( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE )    ;
-    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, 0x00000000 } )   ;
-//    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
-}
-//===============================================================================================================================
-
-
-
-
-// ============================================================================ RADIO CALLBACK
-void OnTxDone       ( void ) {
-//==============================================================================
-    valueTimeTx = timerRadio.read_ms () ; 
-    printf( "*** LORA ***  OnTxDone \r\n" );
-    TxLed   = 0 ;
-    setRadioRx () ; 
-}
-//==============================================================================
-
-
-
-//void OnRxDone       ( void )                          { AppState = APP_RX         ;   }
-//==============================================================================
-void OnRxDone       ( void ) {
-//==============================================================================
-    uint8_t Buffer1 [BUFFER_SIZE_MAX+1];                  // Buffer Radio
-    uint8_t BufferSize = BUFFER_SIZE_MAX ;          // Size of the buffer
- 
-    RxLed               =   1   ;  // Show the reception 
-
-    printf( "*** LORA ***  RX DONE \r\n" );
-    valueTimeLoop = timerRadio.read_ms ()   ; 
-    timerRadio.stop       ()  ; 
-    watchDogRx.detach     ()  ;      
-    //printf( "*** LORA ***  DISARM watchDogRx  \r\n" );
-
-    Radio.GetPacketStatus(&packetStatus)    ; 
-    RssiValue = packetStatus.LoRa.RssiPkt   ; 
-    
-    memset              ( &Buffer1 , 0x00, BUFFER_SIZE_MAX );
-    Radio.GetPayload    ( Buffer1, &BufferSize, BUFFER_SIZE_MAX );
-    
-    RxLed               =   0   ;  // Show the reception 
-    
-    Buffer1[7] = 0 ; 
-
-    printf  ( "*** LORA *** RX DONE =>  %s \r\n", Buffer1 );   wait(1) ; // flush serial 
-     
-    // Extract value 
-    
-    switch (Buffer1[2]) {
-        case '1': RF_FREQUENCY    =   2400000000UL ; break ; 
-        case '2': RF_FREQUENCY    =   2400680000UL ; break ; 
-        case '3': RF_FREQUENCY    =   2423840000UL ; break ; 
-        case '4': RF_FREQUENCY    =   2424520000UL ; break ; 
-        case '5': RF_FREQUENCY    =   2448840000UL ; break ; 
-        case '6': RF_FREQUENCY    =   2449520000UL ; break ; 
-        case '7': RF_FREQUENCY    =   2473840000UL ; break ; 
-        case '8': RF_FREQUENCY    =   2474520000UL ; break ; 
-    }  
-                
-    switch (Buffer1[3]) {
-        case '1': LORA_BW           =   LORA_BW_0200     ;   break ; 
-        case '2': LORA_BW           =   LORA_BW_0400     ;   break ; 
-        case '3': LORA_BW           =   LORA_BW_0800     ;   break ; 
-        case '4': LORA_BW           =   LORA_BW_1600    ;   break ; 
-    }  
-               
-    switch (Buffer1[4]) {
-       case '1': TX_OUTPUT_POWER    =   -18         ;   break   ; 
-       case '2': TX_OUTPUT_POWER    =   0           ;   break   ; 
-       case '3': TX_OUTPUT_POWER    =   8           ;   break   ; 
-       case '4': TX_OUTPUT_POWER    =   10          ;   break   ; 
-       case '5': TX_OUTPUT_POWER    =   13          ;   break   ; 
-    }  
-                               
-    switch (Buffer1[5]) {
-       case '1': LORA_SF            =   LORA_SF5       ;   break     ; 
-       case '2': LORA_SF            =   LORA_SF6       ;   break     ; 
-       case '3': LORA_SF            =   LORA_SF7       ;   break     ; 
-       case '4': LORA_SF            =   LORA_SF8       ;   break     ; 
-       case '5': LORA_SF            =   LORA_SF9       ;   break     ; 
-       case '6': LORA_SF            =   LORA_SF10      ;   break     ; 
-       case '7': LORA_SF            =   LORA_SF12      ;   break     ; 
-    }  
-
-   int OLD_TIMER = TIMER ; 
-   
-   switch (Buffer1[6]) {
-        case '1': TIMER      =   50     ;   break     ; 
-        case '2': TIMER      =   75     ;   break     ; 
-        case '3': TIMER      =   125    ;   break     ; 
-        case '4': TIMER      =   250    ;   break     ; 
-        case '5': TIMER      =   500    ;   break     ; 
-        case '6': TIMER      =   1000   ;   break     ; 
-        case '7': TIMER      =   2000   ;   break     ; 
-     }    
-
-    RxLed               =   0             ;
-
-    if (oldFreq != Buffer1[2] || oldBw   != Buffer1[3] || oldPwr  != Buffer1[4] || oldSf   != Buffer1[5] || oldTimer   != Buffer1[6] ) {
-            oldFreq = Buffer1[2] ;
-            oldBw   = Buffer1[3] ;
-            oldPwr  = Buffer1[4] ;
-            oldSf   = Buffer1[5] ; 
-            oldTimer = Buffer1[6] ;
-            //printf  ( "*** LORA *** Reset Radio \r\n" );
-            //app.updateDisplay   ( LORA_SF, LORA_BW, TX_OUTPUT_POWER, BUFFER_SIZE_MAX, RF_FREQUENCY, TIMER ) ; 
-    }   
-    
-    if (OLD_TIMER != TIMER) {
-        //wakeUpTerminal.detach   ();
-        //wakeUpTerminal.attach   (&wakeUpTerminalFunction, (float) TIMER/1000);
-    }
-}
-//==============================================================================
-
-void OnTxTimeout    ( void )                        { AppState = APP_TX_TIMEOUT ;}
-void OnRxTimeout    ( void )                        { AppState = APP_RX_TIMEOUT ; }
-void OnRxError      ( IrqErrorCode_t errorCode )    { AppState = APP_RX_ERROR   ; }
-void OnRangingDone  ( IrqRangingCode_t val )        {  }
-void OnCadDone      ( bool channelActivityDetected ){  }
-
-
--- a/Lora.h	Tue Oct 16 07:29:51 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-/*
- * MISNet   
- *
- *  Lora:   Radio Management
- *
- *  Created on: August 17, 2018         Author: Francis CHATAIN
- *
- */
-#ifndef __LORA_H__
-#define __LORA_H__
-
-#include "mbed.h"
-#include "sx1280-hal.h"
-
-
-void initLora(uint32_t rf,RadioLoRaBandwidths_t bw,RadioLoRaSpreadingFactors_t sf,int8_t pwr) ; 
-void sendMessageLora () ; 
-
-#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Loracpp.txt	Mon Oct 22 09:37:50 2018 +0000
@@ -0,0 +1,463 @@
+/*
+ * MISNet   
+ *
+ *  Lora:   Radio Management 
+ *
+ *  Created on: August 17, 2018       Author: Francis CHATAIN
+ *
+ */
+
+
+// =====================================  Includes
+#include "Lora.h"
+#include "mbed.h"
+#include "main.h"
+#include "sx1280-hal.h"
+
+// ==========================================================================  DEFINE
+#define MODE_LORA         // Lora modulation 
+
+#define TX_TIMEOUT_VALUE        100                         // ms   Number of tick size steps for tx timeout
+#define RX_TIMEOUT_VALUE        100                         // ms   Number of tick size steps for rx timeout
+#define RX_TIMEOUT_TICK_SIZE    RADIO_TICK_SIZE_1000_US     // Size of ticks (used for Tx and Rx timeout)
+#define MODE_ADDR               0x8000 
+
+
+// ==========================================================================  HW 
+DigitalOut  F_CS        ( D6 )  ;     // MBED description of pin
+DigitalOut  SD_CS       ( D8 )  ;     // MBED description of pin
+DigitalOut  ANT_SW      ( A3 )  ;
+DigitalOut  TxLed       ( A4 )  ;
+DigitalOut  RxLed       ( A5 )  ;
+
+
+// ==========================================================================  VARIABLES 
+uint16_t    RxIrqMask ;       // Mask of IRQs to listen to in rx mode
+uint16_t    TxIrqMask ;       // Mask of IRQs to listen to in tx mode
+
+
+uint32_t    valueTimeTx      ; 
+uint32_t    valueTimeLoop    ;
+
+int         dataCounter     = 0 ;
+uint8_t     oldFreq         ; 
+uint8_t     oldBw           ; 
+uint8_t     oldPwr          ; 
+uint8_t     oldSf           ; 
+uint8_t     oldTimer        ; 
+
+// States of the application
+typedef enum  { APP_LOWPOWER, APP_RX, APP_RX_TIMEOUT, APP_RX_ERROR, APP_TX, APP_TX_TIMEOUT, } AppStates_t ;
+AppStates_t AppState = APP_LOWPOWER;        // Init State of the application
+
+PacketStatus_t  PacketStatus        ;
+int8_t          RssiValue    = 0    ;
+int8_t          SnrValue     = 0    ;
+
+ModulationParams_t          modulationParams;
+PacketParams_t              PacketParams    ;        // Locals parameters and status for radio API
+PacketStatus_t              packetStatus    ;        // NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
+
+uint32_t                    RF_FREQUENCY        ;   // HzNominal frequency
+RadioLoRaBandwidths_t       LORA_BW             ;   /* 200; 400; 800; 1600 */
+RadioLoRaSpreadingFactors_t LORA_SF             ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
+int8_t                      TX_OUTPUT_POWER     ;   /* Output power in dBm [-18..+13] dBm */ 
+uint8_t                     BUFFER_SIZE_MAX     ;   /* Payload size max */
+int16_t                     TIMER               ;   /* timer entre reemission en ms */
+uint8_t                     BUFFER_SIZE_MIN     ;   /* Payload return size */
+
+
+// ==========================================================================  Function  
+void        initRadio              () ;
+void        setRadioTx             () ;
+void        setRadioRx             () ;
+void        watchDogRxCRNoReceived () ; 
+
+
+
+Timer       timerRadio       ;
+Timeout     watchDogRx          ;
+Timeout     watchDogTx          ;
+
+void OnTxDone       ( void );               // Function to be executed on Radio Tx Done event
+void OnRxDone       ( void );               // Function to be executed on Radio Rx Done event
+void OnTxTimeout    ( void );               // Function executed on Radio Tx Timeout event
+void OnRxTimeout    ( void );               // Function executed on Radio Rx Timeout event
+void OnRxError      ( IrqErrorCode_t );     // Function executed on Radio Rx Error event
+
+RadioCallbacks_t callbacks  =  {
+    &OnTxDone,        // txDone
+    &OnRxDone,        // rxDone
+    NULL,             // syncWordDone
+    NULL,             // headerDone
+    &OnTxTimeout,     // txTimeout
+    &OnRxTimeout,     // rxTimeout
+    &OnRxError,       // rxError
+    NULL,             // rangingDone
+    NULL,             // cadDone
+};
+
+//                    mosi, miso,   sclk,  nss,  busy , dio1 , dio2, dio3, rst , callbacks...
+SX1280Hal Radio     ( D11 , D12 ,   D13 ,  D7 ,  D3   , D5   , NC  , NC  , A0  , &callbacks );
+
+
+
+//===============================================================================================================================
+void initLora (uint32_t rf,RadioLoRaBandwidths_t bw,RadioLoRaSpreadingFactors_t sf,int8_t pwr) 
+//===============================================================================================================================
+{
+        // Default value initialisation 
+    printf( "*** 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
+
+    RF_FREQUENCY        =   rf              ;   // HzNominal frequency
+    LORA_BW             =   bw              ;   /* 200; 400; 800; 1600 */
+    LORA_SF             =   sf              ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
+    TX_OUTPUT_POWER     =   pwr             ;   /* Output power in dBm [-18..+13] dBm */ 
+    BUFFER_SIZE_MAX     =   100             ;   /* Payload size max */
+    BUFFER_SIZE_MIN     =   5               ;   /* Payload return size */
+    TIMER               =   1000            ;   /* timer entre reemission en ms */ 
+    
+    
+    
+    Radio.Reset                 ()              ;  
+    Radio.Init                  ()              ;
+    initRadio                   ()              ;            
+    Radio.SetRegulatorMode      ( USE_DCDC )    ;       // Can also be set in LDO mode but consume more power
+    wait_ms                     ( 10 )          ;       // wait for on board DC/DC start-up time
+    
+    TxLed   = 0     ;
+    RxLed   = 0     ;
+
+}
+
+
+//===============================================================================================================================
+void sendMessageLora () {
+//===============================================================================================================================
+    uint8_t         Buffer          [BUFFER_SIZE_MAX]       ;           // Buffer
+    char            frameMISNET     [BUFFER_SIZE_MAX]       ;           // Misnet Frame
+    uint8_t         *pointer                                ;
+    char            *ptr_int                                ;
+    
+    
+    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
+     
+    uint8_t     SFT                 =   0       ;
+    uint8_t     DFT                 =   0       ;
+    uint8_t     FDL                 =   8       ;
+    uint8_t     BL                  =   7       ;
+    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);
+
+    servicePayload =  (uint32_t)( (SFT & 0x03)  << 30) | 
+                      (uint32_t)( (DFT & 0x03)  << 28) | 
+                      (uint32_t)( (FDL & 0x3F)  << 22) | 
+                      (uint32_t)( (BL  & 0x07)  << 19) | 
+                      (uint32_t)( (DMI & 0xFF)  << 11) | 
+                      (RCA & 0x7FF)                   ;
+                      
+    //sprintf (serviceMessage, "%08X%08X", servicePayload, MIC) ;    // traces 
+    //printf( "*** LORA ***  SERVICE Payload = %08X \r\n ", servicePayload);
+    //printf( "*** LORA ***  SERVICE MIC     = %08X \r\n ", MIC);
+    
+    // CLEAR PART + Indianess correction 
+    pointer = (uint8_t*) &clearPart ;       for (int i = 0, j=1 ; i<2 ; i++, j--)  frameMISNET[j]   = pointer[i] ;
+       
+    // 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") ; 
+
+    
+    int n = sprintf (frameMISNET, "%1c%1c",  ID_TERMINAL, ID_GATEWAY);
+   
+    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") ; 
+       
+    
+    // Send SF, BW, COUNTER, POWER, FREQ, TIMETX, TIMELOOP, RSSIVALUE
+    frameMISNET[6] = LORA_SF            ; 
+    ptr_int = (char*) &LORA_BW          ; 
+    frameMISNET[7]= ptr_int[1]          ;   
+    frameMISNET[8]= ptr_int[0]          ;
+    frameMISNET[9] = TX_OUTPUT_POWER    ; 
+    ptr_int = (char*) &RF_FREQUENCY     ; for (int i = 0 ; i<4 ; i++)  frameMISNET[10+i] = ptr_int[i] ; 
+    ptr_int = (char*) &valueTimeTx      ; for (int i = 0 ; i<4 ; i++)  frameMISNET[14+i] = ptr_int[i] ;   //printf( "*** LORA ***  TimeTx   %d  %d  ", valueTimeTx, valueTimeLoop);  //delay temps Tx   
+    ptr_int = (char*) &valueTimeLoop    ; for (int i = 0 ; i<4 ; i++)  frameMISNET[18+i] = ptr_int[i] ;   //delay temps Loop  
+    frameMISNET[22] = RssiValue ; 
+    
+    memcpy                      ( Buffer    , frameMISNET   , 23    );
+    
+    valueTimeTx   =  0 ; 
+    valueTimeLoop =  0 ; 
+    timerRadio.reset        ()  ;    // Record tile for close loop
+    timerRadio.start        ()  ; 
+    setRadioTx              ()  ; 
+    TxLed           =       1   ;
+    PacketParams.Params.LoRa.PayloadLength          =   23         ;
+    Radio.SetPacketParams                           ( &PacketParams )           ;
+    Radio.SendPayload       ( Buffer    , 23,( TickTime_t ) {RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE} );
+    TxLed           =       0   ;
+
+    //printf( "*** LORA ***  ARM watchDogRxRxRxRx  \r\n" );
+    watchDogRx.attach (&watchDogRxCRNoReceived, 1.0);     // Arm watchDogRx  if the response is not received in less 500 ms =>  force retry   
+}
+//===============================================================================================================================
+
+
+// Time out si pas de message de CR recu
+void        watchDogRxCRNoReceived ()  { 
+    printf( "*** LORA ***  watchDogRxNoReceive NO RESPONSE    \r\n");    
+}   // Force new emission 
+
+
+
+
+//===============================================================================================================================
+void initRadio () {
+//===============================================================================================================================
+    F_CS   = 1  ;
+    SD_CS  = 1  ;
+    ANT_SW = 1  ;
+    
+    // SET MODULATION
+    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
+    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
+    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW_0200            ; 
+    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF7                ; 
+    // SET PACKET PARAM
+    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
+    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
+    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
+    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MAX         ;
+    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
+    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
+    // RADIO
+    Radio.SetStandby                                ( STDBY_RC  )               ;
+    Radio.SetPacketType                             ( modulationParams.PacketType );
+    Radio.SetModulationParams                       ( &modulationParams )       ;
+    Radio.SetPacketParams                           ( &PacketParams )           ;   
+    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
+    Radio.SetTxParams                               ( TX_OUTPUT_POWER, RADIO_RAMP_20_US )       ;
+    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
+    //AppState                    =                   APP_LOWPOWER;
+}
+//===============================================================================================================================
+
+
+
+//===============================================================================================================================
+void setRadioTx () {
+//=============================================================================================================================== 
+    RxLed  = 0  ;
+    TxLed  = 0  ;
+    F_CS   = 1  ;
+    SD_CS  = 1  ;
+    ANT_SW = 1  ;
+
+    // SET MODULATION
+    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
+    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
+    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW    ; 
+    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF    ; 
+
+    // SET PACKET PARAM
+    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
+    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
+    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
+    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MAX         ;
+    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
+    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
+
+    // RADIO
+    Radio.SetStandby                                ( STDBY_RC  )               ;
+    Radio.SetPacketType                             ( modulationParams.PacketType );
+    Radio.SetModulationParams                       ( &modulationParams )       ;
+    Radio.SetPacketParams                           ( &PacketParams )           ;
+    Radio.SetRfFrequency                            ( RF_FREQUENCY )            ;
+    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
+    Radio.SetTxParams                               ( TX_OUTPUT_POWER, RADIO_RAMP_20_US )       ;
+    Radio.SetDioIrqParams                           ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
+
+    //AppState                    =                   APP_LOWPOWER;
+ 
+ }
+
+
+//===============================================================================================================================
+void setRadioRx () {
+//===============================================================================================================================
+    RxLed  = 0  ;
+    TxLed  = 0  ;   
+    
+    F_CS   = 1  ;
+    SD_CS  = 1  ;
+    ANT_SW = 1  ;
+    
+    // SET MODULATION
+    modulationParams.PacketType                     =   PACKET_TYPE_LORA        ;
+    modulationParams.Params.LoRa.CodingRate         =   LORA_CR_4_5             ;
+    modulationParams.Params.LoRa.Bandwidth          =   LORA_BW_0200            ; 
+    modulationParams.Params.LoRa.SpreadingFactor    =   LORA_SF7                ; 
+
+    // SET PACKET PARAM
+    PacketParams.PacketType                         =   PACKET_TYPE_LORA        ;
+    PacketParams.Params.LoRa.PreambleLength         =   0x08                    ;
+    PacketParams.Params.LoRa.HeaderType             =   LORA_PACKET_VARIABLE_LENGTH;
+    PacketParams.Params.LoRa.PayloadLength          =   BUFFER_SIZE_MIN         ;
+    PacketParams.Params.LoRa.Crc                    =   LORA_CRC_ON             ;
+    PacketParams.Params.LoRa.InvertIQ               =   LORA_IQ_INVERTED        ;
+
+    // RADIO
+    Radio.SetStandby                                ( STDBY_RC  )               ;
+    Radio.SetPacketType                             ( modulationParams.PacketType );
+    Radio.SetModulationParams                       ( &modulationParams )       ;
+    Radio.SetPacketParams                           ( &PacketParams )           ;
+    Radio.SetRfFrequency                            ( RF_FREQUENCY + 440000UL)            ;
+
+    Radio.SetBufferBaseAddresses                    ( 0x00, 0x00 );
+    Radio.SetDioIrqParams                           ( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE )    ;
+    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, 0x00000000 } )   ;
+//    Radio.SetRx                                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
+}
+//===============================================================================================================================
+
+
+
+
+// ============================================================================ RADIO CALLBACK
+void OnTxDone       ( void ) {
+//==============================================================================
+    valueTimeTx = timerRadio.read_ms () ; 
+    printf( "*** LORA ***  OnTxDone \r\n" );
+    TxLed   = 0 ;
+    setRadioRx () ; 
+}
+//==============================================================================
+
+
+
+//void OnRxDone       ( void )                          { AppState = APP_RX         ;   }
+//==============================================================================
+void OnRxDone       ( void ) {
+//==============================================================================
+    uint8_t Buffer1 [BUFFER_SIZE_MAX+1];                  // Buffer Radio
+    uint8_t BufferSize = BUFFER_SIZE_MAX ;          // Size of the buffer
+ 
+    RxLed               =   1   ;  // Show the reception 
+
+    printf( "*** LORA ***  RX DONE \r\n" );
+    valueTimeLoop = timerRadio.read_ms ()   ; 
+    timerRadio.stop       ()  ; 
+    watchDogRx.detach     ()  ;      
+    //printf( "*** LORA ***  DISARM watchDogRx  \r\n" );
+
+    Radio.GetPacketStatus(&packetStatus)    ; 
+    RssiValue = packetStatus.LoRa.RssiPkt   ; 
+    
+    memset              ( &Buffer1 , 0x00, BUFFER_SIZE_MAX );
+    Radio.GetPayload    ( Buffer1, &BufferSize, BUFFER_SIZE_MAX );
+    
+    RxLed               =   0   ;  // Show the reception 
+    
+    Buffer1[7] = 0 ; 
+
+    printf  ( "*** LORA *** RX DONE =>  %s \r\n", Buffer1 );   wait(1) ; // flush serial 
+     
+    // Extract value 
+    
+    switch (Buffer1[2]) {
+        case '1': RF_FREQUENCY    =   2400000000UL ; break ; 
+        case '2': RF_FREQUENCY    =   2400680000UL ; break ; 
+        case '3': RF_FREQUENCY    =   2423840000UL ; break ; 
+        case '4': RF_FREQUENCY    =   2424520000UL ; break ; 
+        case '5': RF_FREQUENCY    =   2448840000UL ; break ; 
+        case '6': RF_FREQUENCY    =   2449520000UL ; break ; 
+        case '7': RF_FREQUENCY    =   2473840000UL ; break ; 
+        case '8': RF_FREQUENCY    =   2474520000UL ; break ; 
+    }  
+                
+    switch (Buffer1[3]) {
+        case '1': LORA_BW           =   LORA_BW_0200     ;   break ; 
+        case '2': LORA_BW           =   LORA_BW_0400     ;   break ; 
+        case '3': LORA_BW           =   LORA_BW_0800     ;   break ; 
+        case '4': LORA_BW           =   LORA_BW_1600    ;   break ; 
+    }  
+               
+    switch (Buffer1[4]) {
+       case '1': TX_OUTPUT_POWER    =   -18         ;   break   ; 
+       case '2': TX_OUTPUT_POWER    =   0           ;   break   ; 
+       case '3': TX_OUTPUT_POWER    =   8           ;   break   ; 
+       case '4': TX_OUTPUT_POWER    =   10          ;   break   ; 
+       case '5': TX_OUTPUT_POWER    =   13          ;   break   ; 
+    }  
+                               
+    switch (Buffer1[5]) {
+       case '1': LORA_SF            =   LORA_SF5       ;   break     ; 
+       case '2': LORA_SF            =   LORA_SF6       ;   break     ; 
+       case '3': LORA_SF            =   LORA_SF7       ;   break     ; 
+       case '4': LORA_SF            =   LORA_SF8       ;   break     ; 
+       case '5': LORA_SF            =   LORA_SF9       ;   break     ; 
+       case '6': LORA_SF            =   LORA_SF10      ;   break     ; 
+       case '7': LORA_SF            =   LORA_SF12      ;   break     ; 
+    }  
+
+   int OLD_TIMER = TIMER ; 
+   
+   switch (Buffer1[6]) {
+        case '1': TIMER      =   50     ;   break     ; 
+        case '2': TIMER      =   75     ;   break     ; 
+        case '3': TIMER      =   125    ;   break     ; 
+        case '4': TIMER      =   250    ;   break     ; 
+        case '5': TIMER      =   500    ;   break     ; 
+        case '6': TIMER      =   1000   ;   break     ; 
+        case '7': TIMER      =   2000   ;   break     ; 
+     }    
+
+    RxLed               =   0             ;
+
+    if (oldFreq != Buffer1[2] || oldBw   != Buffer1[3] || oldPwr  != Buffer1[4] || oldSf   != Buffer1[5] || oldTimer   != Buffer1[6] ) {
+            oldFreq = Buffer1[2] ;
+            oldBw   = Buffer1[3] ;
+            oldPwr  = Buffer1[4] ;
+            oldSf   = Buffer1[5] ; 
+            oldTimer = Buffer1[6] ;
+            //printf  ( "*** LORA *** Reset Radio \r\n" );
+            //app.updateDisplay   ( LORA_SF, LORA_BW, TX_OUTPUT_POWER, BUFFER_SIZE_MAX, RF_FREQUENCY, TIMER ) ; 
+    }   
+    
+    if (OLD_TIMER != TIMER) {
+        //wakeUpTerminal.detach   ();
+        //wakeUpTerminal.attach   (&wakeUpTerminalFunction, (float) TIMER/1000);
+    }
+}
+//==============================================================================
+
+void OnTxTimeout    ( void )                        { AppState = APP_TX_TIMEOUT ;}
+void OnRxTimeout    ( void )                        { AppState = APP_RX_TIMEOUT ; }
+void OnRxError      ( IrqErrorCode_t errorCode )    { AppState = APP_RX_ERROR   ; }
+void OnRangingDone  ( IrqRangingCode_t val )        {  }
+void OnCadDone      ( bool channelActivityDetected ){  }
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lorah.txt	Mon Oct 22 09:37:50 2018 +0000
@@ -0,0 +1,19 @@
+/*
+ * MISNet   
+ *
+ *  Lora:   Radio Management
+ *
+ *  Created on: August 17, 2018         Author: Francis CHATAIN
+ *
+ */
+#ifndef __LORA_H__
+#define __LORA_H__
+
+#include "mbed.h"
+#include "sx1280-hal.h"
+
+
+void initLora(uint32_t rf,RadioLoRaBandwidths_t bw,RadioLoRaSpreadingFactors_t sf,int8_t pwr) ; 
+void sendMessageLora () ; 
+
+#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Radio.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -0,0 +1,436 @@
+/*
+ *  MISNet
+ *
+ *  TERMINAL Radio module
+ *
+ *  Created on: September 19, 2018    Author: Francis CHATAIN
+ *
+ */
+
+// ================================================================= INCLUDES
+
+#include "mbed.h"
+#include "main.h"
+#include "Radio.h"
+#include "sx1280-hal.h"
+#include <string.h>
+
+
+// ================================================================= VARIABLE & DEFINE
+
+extern "C"{
+  int _getpid       ()                  { return -1;}
+  int _kill         (int pid, int sig)  { return -1; }
+  extern int _write ()  ;   //{return -1;}
+}
+
+//DigitalOut  ledReceive      (PA_8)  ;
+//DigitalOut  ledSend         (PB_13) ;
+DigitalOut  ledReceive      (A5)  ;
+DigitalOut  ledSend         (A4) ;
+
+
+/******************************************************************************
+ * Declaration of RADIO variables and function
+ *****************************************************************************/
+
+// FEM      TxEN:PB3 RxEN:PB9
+//DigitalOut  femTx   (PB_3);
+//DigitalOut  femRx   (PB_9);
+
+#define     BUFFER_SIZE   100
+uint8_t     BufferSize  = BUFFER_SIZE;
+uint8_t     Buffer[BUFFER_SIZE];
+
+int8_t      RssiValue   = 0 ;
+int8_t      SnrValue    = 0 ;
+
+typedef enum { APP_IDLE=0, APP_LOWPOWER, APP_RX, APP_RX_TIMEOUT, APP_RX_ERROR, APP_TX, APP_TX_TIMEOUT,} AppStates_t;
+AppStates_t AppState = APP_LOWPOWER ;
+
+ModulationParams_t  ModulationParams ;
+ModulationParams_t  ModulationParamsEmitter ;
+ModulationParams_t  ModulationParamsReceiver;
+
+PacketParams_t      PacketParamsReceiver ;
+PacketStatus_t      PacketStatusReceiver ;
+
+PacketParams_t      PacketParamsEmitter  ;
+
+
+// Radio Callback event
+void OnTxDone       (void)                      { AppState = APP_TX         ; }
+void OnRxDone       (void)                      { AppState = APP_RX         ; }
+void OnTxTimeout    (void)                      { AppState = APP_TX_TIMEOUT ; }
+void OnRxTimeout    (void)                      { AppState = APP_RX_TIMEOUT ; }
+void OnRxError      (IrqErrorCode_t errorCode)  { AppState = APP_RX_ERROR   ; }
+void OnRangingDone  (IrqRangingCode_t val)      { }
+void OnCadDone      (bool channelActivityDetected){}
+
+RadioCallbacks_t callbacks ={
+    &OnTxDone       , &OnRxDone     ,       // tx / rx Done
+    NULL            , NULL          ,       // syncWordDone headerDone
+    &OnTxTimeout    , &OnRxTimeout  ,       // txTimeout rxTimeout
+    &OnRxError      ,                       // rxError
+    NULL            , NULL          ,       // rangingDone / cadDone
+};
+
+//  Timeout callback
+#define         TX_TIMEOUT_VALUE                100                 // ms
+#define         RX_TIMEOUT_VALUE                0x00000000          //   or 100    (ms)
+#define         RX_TIMEOUT_TICK_SIZE            RADIO_TICK_SIZE_1000_US
+
+uint16_t        RxIrqMask           = IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT   ;
+uint16_t        TxIrqMask           = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT   ;
+
+
+int8_t          rssi=0, snr=0;
+
+// SX1280   MOSI:PA7 MISO:PA6 CLK:PA5  CS:PA4  BSY:PB7  DIO1:PB6  DIO2:PB5  DIO3:PB4  RST:PB8
+// SX1280Hal   Radio   (PA_7, PA_6, PA_5, PA_4, PB_7, PB_6, PB_5, PB_4, PB_8, &callbacks);//mosi miso clk cs bsy dio1 dio2 dio3 rst   [DONGLE]
+SX1280Hal   Radio   ( D11 , D12 , D13 , D7 , D3  , D5  , NC  , NC  , A0 , &callbacks );     //   [NUCLEO] 
+
+//Radio Factory Parameter Sender and Receiver    only diff the Central Frequency emetter are shited by 800 Mhz
+uint8_t         _modulation         =   PACKET_TYPE_LORA;
+int             _spreadingFactor    =   2               ;
+int             _bandWidth          =   1               ;
+int             _codingRate         =   0               ;
+unsigned long   _frequencySend      =   2400000000UL    ;
+unsigned long   _frequencyReceive   =   2400000000UL    ;
+int             _outputPower        =   13              ;   // -18 to +13 dBm
+int             _size               =   10              ;
+
+int             _iq                 =   1               ;
+int             _crc                =   0               ;
+uint8_t         _ar[]               =   { 0xDD, 0xA0, 0x96, 0x69, 0xDD  }       ;  // only used in GENERIC and BLE mode
+uint8_t         _crcSeedLocal[3]    =   { 0x00, 0x45, 0x67              }       ;  // only used in GFSK, FLRC
+
+
+// Futur use with FLRC modulation
+//int           _mode               =   4               ;
+//int           _modeShape          =   1               ;
+//int           _modeIndex          =   2               ;
+//int           _whitening          =   1               ;
+//int           _bitrateBandwidth   =   12              ;
+
+//  ============================================================================================ Declaration Internal function
+
+RadioLoRaCodingRates_t      returnCrLORA    (int index) ;
+RadioLoRaSpreadingFactors_t returnSfLORA    (int index) ;
+RadioLoRaBandwidths_t       returnBwLORA    (int index) ;
+
+void                        setFemTxRx      (bool tx)   ;   // only if FEM HW 
+
+/* Evolution FLRC
+ * RadioCrcTypes_t          returnCrcLen    (int index) ;
+ * RadioFlrcBitrates_t      returnBrbwFLRC  (int index) ;
+ * RadioFlrcCodingRates_t   returnCrFLRC    (int index) ;
+ * RadioModShapings_t       returnMs        (int index) ;
+ */
+
+// ============================================================================================ EXTERNAL FUNCTION
+
+
+// ============================================================================================ Radio Self Test
+
+bool radioSelfTest  (uint16_t *rev) {
+  Radio.Init();
+  *rev = Radio.GetFirmwareVersion () ;
+  // printf("*** RAD_ ***  Selftest : Firmware R%u\r\n", rev);
+  wait(0.2);
+  //printf((rev==0xffff?"Self test FAIL\r\n":"Self test PASS\r\n"));
+  if    (*rev==0xffff)  return false ;
+  else                  return true  ;
+}
+
+// ============================================================================================ Radio Initialisation
+
+
+void radioInitReceiver          (RadioParameter radioParameter ) {
+    _modulation         = radioParameter.modulation         ;
+    _spreadingFactor    = radioParameter.spreadingFactor    ;
+    _bandWidth          = radioParameter.bandWidth          ;
+    _codingRate         = radioParameter.codingRate         ;
+    _frequencyReceive   = radioParameter.frequency          ;
+
+    if( _modulation == PACKET_TYPE_LORA ) {
+        ModulationParamsReceiver.PacketType                  =  PACKET_TYPE_LORA;
+        ModulationParamsReceiver.Params.LoRa.SpreadingFactor =  returnSfLORA    (_spreadingFactor)  ;
+        ModulationParamsReceiver.Params.LoRa.Bandwidth       =  returnBwLORA    (_bandWidth)        ;
+        ModulationParamsReceiver.Params.LoRa.CodingRate      =  returnCrLORA    (_codingRate)       ;
+        PacketParamsReceiver.PacketType                    =    PACKET_TYPE_LORA;
+        PacketParamsReceiver.Params.LoRa.PreambleLength    =    0x08;
+        PacketParamsReceiver.Params.LoRa.HeaderType        =    LORA_PACKET_VARIABLE_LENGTH;
+        PacketParamsReceiver.Params.LoRa.PayloadLength     =    7   ;
+        PacketParamsReceiver.Params.LoRa.Crc               =    _crc==1?LORA_CRC_ON:LORA_CRC_OFF;
+        PacketParamsReceiver.Params.LoRa.InvertIQ          =    _iq==1?LORA_IQ_INVERTED:LORA_IQ_NORMAL;
+         //Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength;
+     }
+}
+
+void radioInitEmitter           (RadioParameter radioParameter ) {
+    _modulation         = radioParameter.modulation         ;
+    _spreadingFactor    = radioParameter.spreadingFactor    ;
+    _bandWidth          = radioParameter.bandWidth          ;
+    _codingRate         = radioParameter.codingRate         ;
+    _size               = radioParameter.size               ;
+    _frequencySend      = radioParameter.frequency          ;
+
+    if( _modulation == PACKET_TYPE_LORA ) {
+        ModulationParamsEmitter.PacketType                  =   PACKET_TYPE_LORA                    ;
+        ModulationParamsEmitter.Params.LoRa.SpreadingFactor =   returnSfLORA    (_spreadingFactor)  ;
+        ModulationParamsEmitter.Params.LoRa.Bandwidth       =   returnBwLORA    (_bandWidth)        ;
+        ModulationParamsEmitter.Params.LoRa.CodingRate      =   returnCrLORA    (_codingRate)       ;
+        PacketParamsEmitter.PacketType                    =     PACKET_TYPE_LORA                    ;
+        PacketParamsEmitter.Params.LoRa.PreambleLength    =     0x08                                ;
+        PacketParamsEmitter.Params.LoRa.HeaderType        =     LORA_PACKET_VARIABLE_LENGTH         ;
+        PacketParamsEmitter.Params.LoRa.PayloadLength     =     _size                               ;
+        PacketParamsEmitter.Params.LoRa.Crc               =     _crc==1?LORA_CRC_ON:LORA_CRC_OFF    ;
+        PacketParamsEmitter.Params.LoRa.InvertIQ          =     _iq==1?LORA_IQ_INVERTED:LORA_IQ_NORMAL;
+         //Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength;
+     }
+}
+
+
+void radioInitRadio () {
+     Radio.SetStandby               ( STDBY_RC )        ;
+     Radio.SetCrcSeed               ( _crcSeedLocal )   ;
+     Radio.SetCrcPolynomial         ( 0x0123 )          ;
+     Radio.SetPollingMode           ( )                 ;
+     Radio.SetBufferBaseAddresses   ( 0x00, 0x00 )      ;
+     Radio.SetSyncWord              ( 1, _ar )          ;
+}
+
+void radioStartReceive (RadioParameter radioParameter) {
+    _frequencyReceive   = radioParameter.frequency          ;
+    _outputPower        = radioParameter.outputPower        ;
+
+//    setFemTxRx                  (0) ;
+    ledSend             =       0   ;
+    ledReceive          =       0   ;
+
+    Radio.SetPacketType         ( ModulationParamsReceiver.PacketType )     ;
+    Radio.SetModulationParams   ( &ModulationParamsReceiver )               ;
+    Radio.SetPacketParams       ( &PacketParamsReceiver )                   ;
+    Radio.SetRfFrequency        ( _frequencyReceive )                       ;
+    Radio.SetDioIrqParams       ( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE )        ;
+    Radio.SetRx                 ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } )   ;
+
+    AppState        =           APP_LOWPOWER        ;
+    memset                      ( &Buffer , 0x00, BufferSize )  ;
+}
+
+
+void    radioSend                   (RadioParameter radioParameter, uint8_t  *frame, uint8_t len) {
+        _frequencySend      = radioParameter.frequency          ;
+        _outputPower        = radioParameter.outputPower        ;
+
+        ledSend             =       1   ;
+        ledReceive          =       0   ;
+//        setFemTxRx(1);
+
+        Radio.SetPacketType         ( ModulationParamsEmitter.PacketType )      ;
+        Radio.SetModulationParams   ( &ModulationParamsEmitter )                ;
+        Radio.SetPacketParams       ( &PacketParamsEmitter )                    ;
+        Radio.SetRfFrequency        ( _frequencySend )                      ;
+        Radio.SetTxParams           ( _outputPower, RADIO_RAMP_20_US )  ;
+        Radio.SetDioIrqParams       ( TxIrqMask, TxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+        Radio.SendPayload           ( frame, len, ( TickTime_t ){ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE } );
+}
+
+// ============================================================================================ Radio Handler
+bool radioHandler(uint8_t *frame, uint8_t *len, int8_t *rssi, int8_t *snr){
+
+    bool event = false ;
+    Radio.ProcessIrqs();
+    switch( AppState )    {
+      case APP_RX:
+          printf ("*** RADIO ***  radioHandler   APP RX  \r\n"); 
+          AppState = APP_LOWPOWER;
+          memset    ( &Buffer , 0, BUFFER_SIZE )    ;
+          ledReceive = !ledReceive;
+          Radio.GetPayload( Buffer, len, BUFFER_SIZE );
+          //cdc2->printf   ("APP-RX Buffer = %s\r\n", Buffer);
+          //showRssiSnr () ;
+          Radio.GetPacketStatus(&PacketStatusReceiver);
+          *rssi =  PacketStatusReceiver.LoRa.RssiPkt;
+          *snr  =  PacketStatusReceiver.LoRa.SnrPkt;
+          memcpy (frame, Buffer, *len) ;
+          event = true ;
+          //printBytes (Buffer, 30) ;
+          setFemTxRx(0);   
+          Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+          Radio.SetRx( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
+          ledReceive = !ledReceive;
+      break;
+
+      case APP_TX:
+          printf ("*** RADIO ***  radioHandler   APP TX  \r\n"); 
+          AppState = APP_LOWPOWER;
+          //cdc2->printf   ("APP-TX \r\n");
+          setFemTxRx(0);   // if fem 
+          Radio.SetPacketType       ( ModulationParamsReceiver.PacketType )     ;
+          Radio.SetModulationParams ( &ModulationParamsReceiver )               ;
+          Radio.SetPacketParams     ( &PacketParamsReceiver )                   ;
+          Radio.SetRfFrequency      ( _frequencyReceive )                       ;
+
+          Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+          Radio.SetRx( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
+          ledSend = 0 ;
+      break;
+
+      case APP_RX_TIMEOUT:
+            printf ("*** RADIO ***  radioHandler   APP RX Timeout \r\n"); 
+            AppState = APP_LOWPOWER;
+            setFemTxRx(0);
+            Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+            Radio.SetRx( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
+      break;
+
+      case APP_RX_ERROR:
+          AppState = APP_LOWPOWER;
+      break;
+
+      case APP_TX_TIMEOUT:
+          printf ("*** RADIO ***  radioHandler   APP TX Timeout \r\n"); 
+          AppState = APP_LOWPOWER;
+          //cdc2->printf   ("APP-TX \r\n");
+          setFemTxRx(0);
+          Radio.SetPacketType       ( ModulationParamsReceiver.PacketType )     ;
+          Radio.SetModulationParams ( &ModulationParamsReceiver )               ;
+          Radio.SetPacketParams     ( &PacketParamsReceiver )                   ;
+          Radio.SetRfFrequency      ( _frequencyReceive )                       ;
+
+          Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
+          Radio.SetRx( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
+          ledSend = 0 ;
+      break;
+
+      case APP_LOWPOWER:
+      break;
+
+      default:
+      // Set low power
+      break;
+    }
+    return event ;
+}
+
+
+
+
+// ======================================================================================================  INTERNAL FUNCTION
+
+RadioLoRaCodingRates_t returnCrLORA (int index) {
+  // coding rate for LoRa
+  switch(index){
+    case 0: return LORA_CR_4_5;
+    case 1: return LORA_CR_4_6;
+    case 2: return LORA_CR_4_7;
+    case 3: return LORA_CR_4_8;
+    case 4: return LORA_CR_LI_4_5;
+    case 5: return LORA_CR_LI_4_6;
+    case 6: return LORA_CR_LI_4_7;
+    default :  return LORA_CR_4_5;
+  }
+}
+
+
+// SF for LoRa
+RadioLoRaSpreadingFactors_t returnSfLORA(int index) {
+  switch(index){
+    case 0:     return LORA_SF5 ;
+    case 1:     return LORA_SF6 ;
+    case 2:     return LORA_SF7 ;
+    case 3:     return LORA_SF8 ;
+    case 4:     return LORA_SF9 ;
+    case 5:     return LORA_SF10;
+    case 6:     return LORA_SF11;
+    case 7:     return LORA_SF12;
+    default :   return LORA_SF7 ;
+  }
+}
+RadioModShapings_t returnMs(int index){
+  // shaping for FLRC GFSK and BLE
+  switch(index){
+    case 0:     return RADIO_MOD_SHAPING_BT_OFF ;
+    case 1:     return RADIO_MOD_SHAPING_BT_1_0 ;
+    case 2:     return RADIO_MOD_SHAPING_BT_0_5 ;
+    default :   return RADIO_MOD_SHAPING_BT_1_0 ;
+  }
+}
+RadioLoRaBandwidths_t returnBwLORA(int index){
+  // bandwidth for LoRa
+  switch(index){
+    case 0:     return LORA_BW_0200     ;
+    case 1:     return LORA_BW_0400     ;
+    case 2:     return LORA_BW_0800     ;
+    case 3:     return LORA_BW_1600     ;
+    default :   return LORA_BW_1600     ;
+  }
+}
+
+
+void setFemTxRx(bool tx)    {
+    /*   Hoel module 
+    if      (tx) { femTx=1 ; femRx=0 ; }
+    else         { femRx=1 ; femTx=0 ; }
+    */
+}
+
+
+/*   Futur Use
+ *
+ *      else if( _modulation == PACKET_TYPE_FLRC )      {
+       ModulationParams.PacketType                    =     PACKET_TYPE_FLRC;
+       ModulationParams.Params.Flrc.BitrateBandwidth  =     returnBrbwFLRC  (_bitrateBandwidth);// FLRC_BR_0_260_BW_0_3;
+       ModulationParams.Params.Flrc.CodingRate        =     returnCrFLRC    (codingRate);//FLRC_CR_1_2;
+       ModulationParams.Params.Flrc.ModulationShaping =     returnMs        (_modeShape);//RADIO_MOD_SHAPING_BT_1_0;
+       PacketParams.PacketType                        =     PACKET_TYPE_FLRC;
+       PacketParams.Params.Flrc.PreambleLength        =     PREAMBLE_LENGTH_32_BITS;
+       PacketParams.Params.Flrc.SyncWordLength        =     FLRC_SYNCWORD_LENGTH_4_BYTE;
+       PacketParams.Params.Flrc.SyncWordMatch         =     RADIO_RX_MATCH_SYNCWORD_1;
+       PacketParams.Params.Flrc.HeaderType            =     RADIO_PACKET_VARIABLE_LENGTH;
+       PacketParams.Params.Flrc.PayloadLength         =     32  ;
+       PacketParams.Params.Flrc.CrcLength             =     RADIO_CRC_3_BYTES;
+       PacketParams.Params.Flrc.Whitening             =     _whitening==1?RADIO_WHITENING_ON:RADIO_WHITENING_OFF;//RADIO_WHITENING_OFF;
+       //Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.Flrc.PayloadLength;
+     }
+ *
+ *
+ *
+ *RadioFlrcBitrates_t returnBrbwFLRC(int index){
+  // bitrate and bandwidth for FLRC
+  switch(index){
+    case 0: return FLRC_BR_1_300_BW_1_2;
+    case 1: return FLRC_BR_1_040_BW_1_2;
+    case 2: return FLRC_BR_0_650_BW_0_6;
+    case 3: return FLRC_BR_0_520_BW_0_6;
+    case 4: return FLRC_BR_0_325_BW_0_3;
+    case 5: return FLRC_BR_0_260_BW_0_3;
+    default : return FLRC_BR_1_300_BW_1_2;
+  }
+}
+RadioFlrcCodingRates_t returnCrFLRC(int index){
+  switch(index){
+    case 0: return FLRC_CR_1_2;
+    case 1: return FLRC_CR_3_4;
+    case 2: return FLRC_CR_3_4;
+    default : return FLRC_CR_1_2;
+  }
+}
+
+RadioCrcTypes_t returnCrcLen(int index){
+  // CRC length for GFSK and FLRC
+  switch(index){
+    case 0: return RADIO_CRC_OFF;
+    case 1: return RADIO_CRC_1_BYTES;
+    case 2: return RADIO_CRC_2_BYTES;
+    case 3: return RADIO_CRC_3_BYTES;
+    default : return RADIO_CRC_OFF;
+  }
+}
+ *
+ *
+ *
+ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Radio.h	Mon Oct 22 09:37:50 2018 +0000
@@ -0,0 +1,41 @@
+/*
+ * lora.h
+ *
+ *  Created on: 2 sept. 2018
+ *      Author: F.Chatain
+ */
+
+#ifndef RADIO_H_
+#define RADIO_H_
+
+#include "sx1280.h"
+#include "mbed.h"
+//#include "main.h"
+
+
+#define     FRAME_SIZE          100
+#define     COMMANDLINE_SIZE    100
+
+typedef struct {
+    uint8_t         modulation      ;       // LORA / FLRC
+    int             spreadingFactor ;       // SFx
+    int             bandWidth       ;       // 200 400 ...
+    int             codingRate      ;       // 4/5
+    unsigned long   frequency       ;       // en Hz
+    int             outputPower     ;       // -18 to 13  (ne pas dépasser 5 FEM en service)
+    int             size            ;       // message size
+} RadioParameter ;
+
+
+bool    radioSelfTest           (uint16_t *rev) ;
+void    radioInitEmitter        (RadioParameter radioParameter );
+void    radioInitReceiver       (RadioParameter radioParameter );
+
+void    radioInitRadio          () ;
+void    radioSend               (RadioParameter radioParameter, uint8_t  *frame, uint8_t len ) ;
+void    radioStartReceive       (RadioParameter radioParameter);
+bool    radioHandler            (uint8_t  *frame, uint8_t *len, int8_t *rssi, int8_t *snr);
+
+//void  usbHandler          (USBSerial *cdc) ;
+
+#endif /* RADIO_H_ */
--- a/Service.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/Service.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -2,7 +2,7 @@
 
 using namespace misnet;
 
-Service::Service(DEVICE_TYPE type,
+Service::Service( DEVICE_TYPE type,
                  MISNET_CODE misnet_code,
                  STATE state,
                  ACCESS_TYPE access_type,
--- a/Service.hpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/Service.hpp	Mon Oct 22 09:37:50 2018 +0000
@@ -28,6 +28,7 @@
 public:
 
   typedef uint8_t MISNET_CODE ;
+  typedef uint8_t DEVICE_TYPE ;    //  FC to compile
 
   enum SERVICE_TYPE {
     SENSOR    = 1, 
@@ -90,7 +91,7 @@
   } ;
 
   // Constructor
-  /*
+
   Service(            DEVICE_TYPE type,
               MISNET_CODE misnet_code,
               STATE state,
@@ -105,7 +106,7 @@
               ACTION action,
               OUTPUT_MODE output_mode,
               std::string comment);
-*/
+
 
   virtual ~Service() { }
 
--- a/Tftlcd.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/Tftlcd.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -795,11 +795,16 @@
 //=========================================================================================
 void Tftlcd::Update  (uint32_t freq, uint16_t bw, uint8_t sf, int8_t pwr, uint8_t bsz, uint16_t timeM ) {
 //=========================================================================================
-    sprintf (bufferDisplay, "SF/BW  : %1d / %03d   " ,   sf/16, bw);   tft2.drawString (40,190,bufferDisplay)   ;       // SFX
-    sprintf (bufferDisplay, "POWER  : %d     " ,   pwr)   ;         tft2.drawString (40,210,bufferDisplay)   ;       // POWER
-    sprintf (bufferDisplay, "SIZE   : %2d    " ,   bsz)   ;         tft2.drawString (40,230,bufferDisplay)   ;       // Buffer size
-    sprintf (bufferDisplay, "TIMER  : %04d   " ,   timeM) ;         tft2.drawString (40,250,bufferDisplay)   ;       // Timer
-    sprintf (bufferDisplay, "FREQ   : %lu    " ,   freq)  ;         tft2.drawString (40,286,bufferDisplay)   ;       // Frequency
+    printf( "*** TFTL ***  Update Radio values\r\n")  ; 
+
+    sprintf (bufferDisplay, "SF/BW  : %1d / %03d   " ,   sf/16, bw);    tft2.drawString (40,190,bufferDisplay)   ;       // SFX
+    sprintf (bufferDisplay, "POWER  : %d     " ,   pwr)   ;             tft2.drawString (40,210,bufferDisplay)   ;       // POWER
+    sprintf (bufferDisplay, "SIZE   : %2d    " ,   bsz)   ;             tft2.drawString (40,230,bufferDisplay)   ;       // Buffer size
+    sprintf (bufferDisplay, "TIMER  : %04d   " ,   timeM) ;             tft2.drawString (40,250,bufferDisplay)   ;       // Timer
+    sprintf (bufferDisplay, "FREQ   : %lu    " ,   freq)  ;             tft2.drawString (40,286,bufferDisplay)   ;       // Frequency
+    
+    printf( "*** TFTL ***  Update Radio values Done \r\n")  ; 
+    
 }
 //=========================================================================================
 
--- a/main.cpp	Tue Oct 16 07:29:51 2018 +0000
+++ b/main.cpp	Mon Oct 22 09:37:50 2018 +0000
@@ -15,20 +15,33 @@
 #include "main.h"
 #include "Controller.hpp"
 
+#include "Radio.h"
+
 
 using namespace std;
 using namespace misnet;
 
 //  INSTANCE of CONTROLLER OBJECT 
 
-Controller     app                             ;       // Core of controller start also 
+Controller     controller                       ;       // Core of controller start also 
+
+// ---------------------   A mettre dans la database 
+RadioParameter  radioParam          ;       // Serial Read
+RadioParameter  radioParamFactory   ;       // Contain Factory
+RadioParameter  radioParamEmitter   ;       // Contain Config Emet
+RadioParameter  radioParamReceiver  ;       // Contain Config Receiver
+ModeParameter   modeParam           ;       // Mission Mode
+
+
+// A deplacer 
+static char *print_double   ( char* str, double v, int decimalDigits=2) ; 
 
 
 //******************************************************************************
 //     Timers
 //******************************************************************************
 uint16_t TimerPayload, TimerGoodhealth, TimerSynchro, TimerListening = 0L ;
-volatile uint32_t listenFlag=0, syncFlag=0, goodHealthFlag=0, payloadFlag=0, irqFlag=0; 
+volatile uint32_t listenFlag=0, syncFlag=0, goodHealthFlag=0, payloadFlag=0, irqFlag=0, statPayLoadCounter = 0 ; 
  
 LowPowerTicker  wakeUpPayload                   ;       // normal wake up 
 void wakeUpPayloadCallback      (void)          ; 
@@ -55,11 +68,11 @@
 // ============================================================================ Setup
 void setup () {
 
-    app.start    ();         // Start contgroller 
+    controller.start    ();         // Start controller 
     
     // -------------------------------------------------- Scheduler  by IRQ or watch dog 
     
-    app.getScheduling          (TimerPayload, TimerGoodhealth, TimerSynchro, TimerListening) ;   // What mode ? 
+    controller.getScheduling          (TimerPayload, TimerGoodhealth, TimerSynchro, TimerListening) ;   // What mode ? 
     
     wakeUpPayload.attach       (&wakeUpPayloadCallback,     (float)TimerPayload )   ;       // Mode A   +  All Mode   
     wakeUpGoodhealth.attach    (&wakeUpGoodhealthCallback,  (float)TimerGoodhealth) ;       // Mode A   +  All Mode 
@@ -71,8 +84,40 @@
         wakeUpListening.attach (&wakeUpListeningCallback,(float)TimerListening)     ;       // Mode C    
        
         
-     // TODO : Assicier l'IRQ du TAC switch au handler d'exception    wakeUpIrqTacSwitch
+     // TODO : Associer l'IRQ du TAC switch au handler d'exception    wakeUpIrqTacSwitch
      
+    
+    // ============================     A mettre dans l'init de la database et de la radio 
+    radioParamFactory.modulation            =  PACKET_TYPE_LORA ;
+    radioParamFactory.spreadingFactor       =  2                ;
+    radioParamFactory.bandWidth             =  1                ;
+    radioParamFactory.codingRate            =  0                ;
+    radioParamFactory.frequency             =  2400000000UL     ;
+    radioParamFactory.outputPower           =  -18              ;
+
+    radioParamReceiver = radioParamFactory ;
+    radioParam         = radioParamFactory ;
+    radioParamFactory.outputPower           =  0                ;
+    radioParamEmitter  = radioParamFactory ;
+
+    modeParam.addrType      = 1     ;
+    modeParam.terminalAddr  = 1     ;
+    modeParam.subnetAddr    = 0     ;
+    modeParam.raw[0]        = GENERIC_MODE ;
+    modeParam.raw[1]        = 0x01  ;
+    
+    uint16_t    FIRMWARE_Radio =    0   ;
+    bool        radioStatus             ;       // Status I/F
+    radioStatus = radioSelfTest (&FIRMWARE_Radio)   ;   // Radio Test
+    
+    if (radioStatus) printf ("*** MAIN ***  RADIO OK \r\n"); else printf ("*** MAIN ***  RADIO NOK \r\n") ; 
+
+    radioInitEmitter    ( radioParamEmitter )   ;
+    radioInitReceiver   ( radioParamReceiver)   ;
+    radioInitRadio      ()                      ;
+    //radioStartReceive   (radioParamReceiver)    ;
+     
+    printf ("*** MAIN ***  SETUP   End   \r\n");
            
 }
 //==============================================================================
@@ -80,32 +125,73 @@
 
 // ============================================================================= LOOP  
 void loop () { 
+
+    // A deplacer 
+    #define     FRAME_SIZE          100
+    uint8_t     frame[FRAME_SIZE]       ;
+    char        message[FRAME_SIZE], buffer1[FRAME_SIZE] ;
+    uint8_t     _len                    ; 
+    int8_t      _rssi                   ;
+    int8_t      _snr                    ;  
+    
     while(1) { 
+
         if(listenFlag){     // Listen radio
+            printf ("*** MAIN ***  LOOP : wakeUpListeningCallback   \r\n");
             listenFlag=0;  
-            app.manageListening();
-            printf ("*** MAIN ***  wakeUpListeningCallback   \r\n");
+            controller.manageListening();
         }  
         if(syncFlag){       // Prepare response
+            printf ("*** MAIN ***  LOOP : wakeUpSynchroCallback   \r\n");
             syncFlag=0; 
-            app.manageSynchro();
-            printf ("*** MAIN ***  wakeUpSynchroCallback   \r\n");
+            controller.manageSynchro();
         } 
         if(goodHealthFlag){ // Prepare response
+            printf ("*** MAIN ***  LOOP : wakeUpGoodhealthCallback  r\n");
             goodHealthFlag=0; 
-            app.manageGoodhealth(); 
-            printf ("*** MAIN ***  wakeUpGoodhealthCallback  r\n");
+            controller.manageGoodhealth(); 
         } 
         if(payloadFlag){    // read Sensors
+            printf ("*** MAIN ***  LOOP : wakeUpPayloadCallback cptr=%d\r\n", statPayLoadCounter); 
             payloadFlag=0; 
-            app.manageSensors(); 
-            printf ("*** MAIN ***  wakeUpPayloadCallback   \r\n"); 
+            //controller.manageSensors(); 
+            // To test ciphering and radio send a simple message
+
+            memset  ( &frame   , 0 , FRAME_SIZE ) ;
+            memset  ( &message , 0 , FRAME_SIZE ) ;
+            // Fab a simple test message 
+            frame[0] = 200      ; 
+            frame[1] = 55       ;  
+            frame[2] = 'T'       ;
+            frame[3] = 'E'       ;
+            frame[4] = 'S'       ;
+            frame[5] = 'T'       ;
+            frame[6] = 'S'       ;
+            
+            int n = sprintf  ( message, "%c%c___%s___",  
+                                    0x42, 
+                                    55,
+                                    print_double (buffer1, statPayLoadCounter)); 
+                                    
+            memcpy  ( frame    , message   , FRAME_SIZE );                        
+
+            // Send Message 
+            _len = strlen (message) ; 
+            radioParamEmitter.size  = _len ; 
+            radioInitEmitter    (radioParamEmitter)             ;
+            radioSend           (radioParamEmitter, frame, _len);
+            memset  ( &frame , 0 , FRAME_SIZE ) ;              
         }  
+        
+        if (radioHandler (frame, &_len, &_rssi, &_snr) ) {
+            printf ("*** MAIN ***  LOOP : radioHandler   \r\n"); 
+        }
+        
         if(irqFlag){        // handle IRQ actions
+            printf ("*** MAIN ***  LOOP : wakeUpIrqTacSwitch   \r\n"); 
             irqFlag=0; 
-            app.manageConfiguration(); 
-            printf ("*** MAIN ***  wakeUpIrqTacSwitch   \r\n"); 
-        } 
+            controller.manageConfiguration(); 
+         } 
         // deepsleep ();    // breaks UART 
         //sleep () ; 
         wait(1);
@@ -128,7 +214,8 @@
 
 // ============================================================ WATCH DOG PAYLOAD 
 void wakeUpPayloadCallback (void) {
-    //printf ("*** MAIN ***  wakeUpPayloadCallback   \r\n");  
+    statPayLoadCounter++ ; 
+    //printf ("*** MAIN ***  wakeUpPayloadCallback : %d  \r\n", statPayLoadCounter); 
     //app.manageSensors         () ;   // read Sensors   
     payloadFlag=1; 
 }
@@ -157,6 +244,42 @@
 //*****************************************************************************
 
 
+// A deplacer 
+
+/* Helper function for printing floats & doubles */
+static char *print_double(char* str, double v, int decimalDigits)
+{
+  int i = 1;
+  int intPart, fractPart;
+  int len;
+  char *ptr;
+
+  /* prepare decimal digits multiplicator */
+  for (;decimalDigits!=0; i*=10, decimalDigits--);
+
+  /* calculate integer & fractinal parts */
+  intPart = (int)v;
+  fractPart = (int)((v-(double)(int)v)*i);
+
+  /* fill in integer part */
+  sprintf(str, "%i.", intPart);
+
+  /* prepare fill in of fractional part */
+  len = strlen(str);
+  ptr = &str[len];
+
+  /* fill in leading fractional zeros */
+  for (i/=10;i>1; i/=10, ptr++) {
+    if (fractPart >= i) {
+      break;
+    }
+    *ptr = '0';
+  }
+
+  /* fill in (rest of) fractional part */
+  sprintf(ptr, "%i", fractPart);
+
+  return str;
+}
 
 
-