Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Revision:
4:41a92fbf702a
Parent:
3:3adb454ba1d2
Child:
5:aa8a8d1a5aa7
--- a/main.cpp	Thu Aug 03 08:52:04 2017 +0000
+++ b/main.cpp	Sun Aug 13 19:45:38 2017 +0000
@@ -2,12 +2,12 @@
 #include "radio.h"
 #include "sx1280-hal.h"
 #include "stdio.h"
-
+#include "XNucleoIKS01A2.h"
 
-#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 01" )    // display firmware version on RS232
+#define FIRMWARE_VERSION ( ( char* )"Firmware Version: 0.1" )   // display firmware version on RS232
 #define MODE_LORA                                               // Lora modulation 
 #define RF_FREQUENCY     2400000000UL                           // HzNominal frequency
-#define TX_OUTPUT_POWER  -18                                     // Output power in dBm [-18..+13] dBm
+#define TX_OUTPUT_POWER  -18                                    // Output power in dBm [-18..+13] dBm
 
 typedef enum         // States of the application
 {
@@ -81,8 +81,23 @@
 ModulationParams_t modulationParams;
 
 
-/* Specify serial datarate for UART debug output */
-void baud   ( int baudrate )    { Serial s( USBTX, USBRX ); s.baud( baudrate );}
+/* Instantiate the expansion board */
+static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
+
+/* Retrieve the composing elements of the expansion board */
+static LSM303AGRMagSensor   *magnetometer = mems_expansion_board->magnetometer;
+static HTS221Sensor         *hum_temp = mems_expansion_board->ht_sensor;
+static LPS22HBSensor        *press_temp = mems_expansion_board->pt_sensor;
+static LSM6DSLSensor        *acc_gyro = mems_expansion_board->acc_gyro;
+static LSM303AGRAccSensor   *accelerometer = mems_expansion_board->accelerometer;
+
+uint8_t     id1, id2, id3, id4, id5, id6, id7;
+float       valueTH1, valueTH2, valueTP1, valueTP2;
+char        buffer1[32], buffer2[32], buffer3[32], buffer4[32];
+int32_t     axesA[3], axesM[3], axesG1[3], axesG2[3];
+
+static char *print_double(char* str, double v, int decimalDigits=2) ; 
+void baud   ( int baudrate ) ; 
 
 void setup () {
     baud    (115200); 
@@ -127,20 +142,107 @@
     Radio.SetDioIrqParams           ( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
     Radio.SetRx                     ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
 
-    AppState = APP_LOWPOWER;   
+    AppState = APP_LOWPOWER;    
     
-    }
+    /* Enable all sensors */
+    hum_temp->enable        ();
+    press_temp->enable      ();
+    magnetometer->enable    ();
+    accelerometer->enable   ();
+    acc_gyro->enable_x      ();
+    acc_gyro->enable_g      ();
+  
+    printf("\r\n--- Starting new run ---\r\n");
+
+    hum_temp->read_id       (&id1);
+    printf("HTS221  humidity & temperature    = 0x%X\r\n", id1);
+    press_temp->read_id     (&id2);
+    printf("LPS22HB  pressure & temperature   = 0x%X\r\n", id2);
+    magnetometer->read_id   (&id3);
+    printf("LSM303AGR magnetometer            = 0x%X\r\n", id3);
+    accelerometer->read_id  (&id4);
+    printf("LSM303AGR accelerometer           = 0x%X\r\n", id4);
+    acc_gyro->read_id       (&id5);
+    printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id5);
+  
+}
 
 void loop () {   
+    wait(4);
+    
+    F_CS   = 1  ;
+    SD_CS  = 1  ;
+    RxLed  = 1  ;
+    TxLed  = 1  ;
+    ANT_SW = 1  ;
+
+    wait( 0.5 ); // wait for on board DC/DC start-up time
+  
+    /* Enable all sensors */
+    hum_temp->enable        ();
+    press_temp->enable      ();
+    magnetometer->enable    ();
+    accelerometer->enable   ();
+    acc_gyro->enable_x      ();
+    acc_gyro->enable_g      ();
+
+    //wait_ms( 500 ); // wait for on board DC/DC start-up time
+
+    wait(0.5);
+    printf("============================================================== \r\n");
+
+    hum_temp->get_temperature   (&valueTH1)   ;    wait_ms( 10 );
+    hum_temp->get_humidity      (&valueTH2)   ;    wait_ms( 10 );
+
+    printf("HTS221    : [temp] %7s C, [hum]   %s%%\r\n"    , print_double(buffer1, valueTH1), print_double(buffer2, valueTH2));
+ 
+    press_temp->get_temperature (&valueTP1)   ;   
+    press_temp->get_pressure    (&valueTP2)   ;
+    printf("LPS22HB   : [temp] %7s C, [press] %s mbar\r\n" , print_double(buffer3, valueTP1), print_double(buffer4, valueTP2));
+    
+    magnetometer->get_m_axes    (axesM)       ;
+    printf("LSM303AGR : [mag/mgauss]  %6ld, %6ld, %6ld\r\n", axesM[0], axesM[1], axesM[2]);  
+
+    accelerometer->get_x_axes   (axesA)       ;
+    printf("LSM303AGR : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesA[0], axesA[1], axesA[2]);
+     
+    acc_gyro->get_x_axes        (axesG1)      ;
+    acc_gyro->get_g_axes        (axesG2)      ;
+    printf("LSM6DSL   : [acc/mg]      %6ld, %6ld, %6ld\r\n", axesG1[0], axesG1[1], axesG1[2]);
+    printf("LSM6DSL   : [gyro/mdps]   %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]);
+    
+    printf("============================================================== \r\n");
+ 
+    /* Disable all sensors */
+    hum_temp->disable        ();
+    press_temp->disable      ();
+    magnetometer->disable    ();
+    accelerometer->disable   ();
+    acc_gyro->disable_x      ();
+    acc_gyro->disable_g      ();
+ 
+     
+     
     TxLed = 1 ; 
-    int n = sprintf                      ( Message, "MSG DATA IOT TERMINAL: %d", cptr++) ; 
-    //sprintf                     ( Message, "MSG DATA IOT TERMINAL: %d", cptr++) ; 
+    //int n = sprintf             ( Message, "MSG DATA IOT TERMINAL: %d", cptr++) ; 
+    
+    memset  ( &Buffer , 0x00, BufferSize );
+    memset  ( &Message, 0x00, BufferSize );
+    
+    int n = sprintf             ( Message, "%1s %1s %s %s %s&",  
+                                    ID_TERMINAL, 
+                                    ID_GATEWAY,
+                                    print_double(buffer1, valueTH1), 
+                                    print_double(buffer2, valueTH2), 
+                                    print_double(buffer3, valueTP2) ) ; 
+                                     
     memcpy                      ( Buffer    , Message   , MESSAGESIZE );
     printf                      ( "*** TERM ***  Message = %s \r\n", Buffer );
     Radio.SetDioIrqParams       ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE );
     Radio.SendPayload           ( Buffer    , BufferSize,( TickTime_t ){ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE } );
     TxLed = 0 ; 
-    wait_ms (2000) ;  
+ 
+    
 }
  
     
@@ -161,3 +263,46 @@
     SnrValue = packetStatus.Lr24.SnrPkt;
     printf("rssi: %d; snr: %d\n\r", RssiValue, SnrValue );
     */
+    
+    
+    
+/* 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;
+}
+
+
+
+/* Specify serial datarate for UART debug output */
+void baud   ( int baudrate )    { Serial s( USBTX, USBRX ); s.baud( baudrate );}