TX

Dependencies:   mbed BufferedSerial SX1276GenericLib X_NUCLEO_IKS01A2

Revision:
1:bd8b9ad01400
Parent:
0:a73914f20498
Child:
2:91a80cc7d87d
--- a/main.cpp	Thu Apr 18 13:56:50 2019 +0000
+++ b/main.cpp	Tue Jun 04 23:58:46 2019 +0000
@@ -38,7 +38,7 @@
 #define RX_TIMEOUT_VALUE    3500    // in ms
 
 //#define BUFFER_SIZE       32        // Define the payload size here
-#define BUFFER_SIZE         512       // Define the payload size here
+#define BUFFER_SIZE         64        // Define the payload size here
 
 /* Sensors instances */
 
@@ -52,9 +52,19 @@
 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
 static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
 
-char buffer1[32], buffer2[32]; // buffers to help theprinting of doubles
-
-uint32_t dados[16]; //data vector
+//uint32_t dados[16]; //data vector
+typedef struct {
+            float p; //pressure
+            float temperatureHTS221; //temperature from HTS221
+            float humidity; //humidity
+            float temperatureLPS22HB; //temperature from LPS22HB
+            int32_t w[3]; //angular velocity
+            int32_t a[3]; //acceleration of the accelerometer LSM303AGR
+            int32_t ag[3]; //acceleration of the accelerometer and gyroscope LSM6DSL 
+            int32_t m [3]; //heading 
+}Dados;
+        
+Dados dados;
 
 /* LoRa modem instances and configurations */
 
@@ -184,28 +194,21 @@
     Radio->Tx(1000000);
     
     while(1) {   
-        float p; //pressure
-        float temperatureHTS221; //temperature from HTS221
-        float humidity; //humidity
-        float temperatureLPS22HB; //temperature from LPS22HB
-        int32_t w[3]; //angular velocity
-        int32_t a[3]; //acceleration of the accelerometer LSM303AGR
-        int32_t ag[3]; //acceleration of the accelerometer and gyroscope LSM6DSL 
-        int32_t m [3]; //heading 
+    
         
-        press_temp->get_pressure(&p); //get the pressure
-        press_temp->get_temperature(&temperatureLPS22HB); //get temperature from LPS22HB
-        accelerometer->get_x_axes(a);//get the acceleration
-        acc_gyro->get_x_axes(ag);//get the acceleration
-        acc_gyro->get_g_axes(w);//get the angular velocity
-        magnetometer->get_m_axes(m); //get the magnetometer heading
-        hum_temp->get_temperature(&temperatureHTS221); //get temperature from HTS221
-        hum_temp->get_humidity(&humidity); //get humidity
+        press_temp->get_pressure(&dados.p); //get the pressure
+        press_temp->get_temperature(&dados.temperatureLPS22HB); //get temperature from LPS22HB
+        accelerometer->get_x_axes(dados.a);//get the acceleration
+        acc_gyro->get_x_axes(dados.ag);//get the acceleration
+        acc_gyro->get_g_axes(dados.w);//get the angular velocity
+        magnetometer->get_m_axes(dados.m); //get the magnetometer heading
+        hum_temp->get_temperature(&dados.temperatureHTS221); //get temperature from HTS221
+        hum_temp->get_humidity(&dados.humidity); //get humidity
         
         
         //sensors data
         
-        dados[0] = a[0];
+        /*dados[0] = a[0];
         dados[1] = a[1];
         dados[2] = a[2];
         dados[3] = ag[0];
@@ -220,12 +223,13 @@
         dados[12] = humidity;
         dados[13] = temperatureHTS221;
         dados[14] = temperatureLPS22HB;
-        dados[15] = p;
+        dados[15] = p;*/
+         
         
         if (transmited==true) {
             transmited = false;
             wait_ms(10);
-            Radio->Send( dados, sizeof(dados) );
+            Radio->Send( &dados, sizeof(dados) );
         }
     }
 }
@@ -275,40 +279,7 @@
 }
 
 /* Helper function for printing floats & doubles */
-static char *print_double(char* str, double v, int decimalDigits=2)
-{
-  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;
-}
 
 void OnTxDone(void *radio, void *userThisPtr, void *userData)
 {   
@@ -316,8 +287,8 @@
     transmited = true;
     if (DEBUG_MESSAGE) {
         pc.printf("> OnTxDone\r\n");
-        pc.printf("I transmited %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld\r\n", dados[0], dados[1], dados[2], dados[3], dados[4], dados[5], dados[6], dados[7], dados[8]);
-        pc.printf("and %6ld, %6ld, %6ld, %s, %7s, %7s %s\r\n", dados[9], dados[10], dados[11], print_double(buffer2, dados[12]), print_double(buffer1, dados[13]), print_double(buffer1, dados[14]), print_double(buffer2, dados[15]));
+        pc.printf("I transmited %d mg, %d mg, %d mg, %d mg, %d mg, %d mg, %d mdps, %d mdps, %d mdps\r\n", dados.a[0], dados.a[1], dados.a[2], dados.ag[0], dados.ag[1], dados.ag[2], dados.w[0], dados.w[1], dados.w[2]);
+        pc.printf("and %d mG, %d mG, %d mG, %g %%, %g C, %g C, %g mBar\r\n", dados.m[0], dados.m[1], dados.m[2], dados.humidity, dados.temperatureHTS221, dados.temperatureLPS22HB, dados.p);
     }    
 }