LMiC LoRa Semtech + Nucleo version sending every 10secs

Dependents:   LoRaWAN-test-10secs

Fork of LMiC by Alcatel-Lucent IoT Development

Revision:
7:758e1719910c
Parent:
1:d3b7bde3995c
Child:
9:c5820ce68bd6
--- a/oslmic.cpp	Fri Jan 08 09:57:53 2016 +0000
+++ b/oslmic.cpp	Wed Jan 13 14:23:31 2016 +0000
@@ -10,6 +10,20 @@
  *******************************************************************************/
 
 #include "lmic.h"
+#include "x_nucleo_iks01a1.h"
+#include "debug.h"
+
+/* Instantiate the expansion board */
+static X_NUCLEO_IKS01A1 *mems_expansion_board = X_NUCLEO_IKS01A1::Instance(D14, D15);
+
+/* Retrieve the composing elements of the expansion board */
+static GyroSensor *gyroscope = mems_expansion_board->GetGyroscope();
+static MotionSensor *accelerometer = mems_expansion_board->GetAccelerometer();
+static MagneticSensor *magnetometer = mems_expansion_board->magnetometer;
+static HumiditySensor *humidity_sensor = mems_expansion_board->ht_sensor;
+static PressureSensor *pressure_sensor = mems_expansion_board->pt_sensor;
+static TempSensor *temp_sensor1 = mems_expansion_board->ht_sensor;
+static TempSensor *temp_sensor2 = mems_expansion_board->pt_sensor;
 
 // RUNTIME STATE
 static struct {
@@ -82,24 +96,136 @@
     hal_enableIRQs();
 }
 
+/* Helper function for printing floats & doubles */
+static char *printDouble(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;
+}
+
 // execute jobs from timer and from run queue
 void os_runloop () {
-    while(1) {
-        osjob_t* j = NULL;
-        hal_disableIRQs();
-        // check for runnable jobs
-        if(OS.runnablejobs) {
-            j = OS.runnablejobs;
-            OS.runnablejobs = j->next;
-        } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
-            j = OS.scheduledjobs;
-            OS.scheduledjobs = j->next;
-        } else { // nothing pending
-            hal_sleep(); // wake by irq (timer already restarted)
-        }
-        hal_enableIRQs();
-        if(j) { // run job callback
-            j->func(j);
-        }
-    }
+/*      uint8_t id;
+      float value1, value2;
+      char buffer1[32], buffer2[32];
+      int32_t axes[3];
+      
+      debug_str("--- Starting new run ---\r\n");
+    
+      humidity_sensor->ReadID(&id);
+      debug_str("HTS221  humidity & temperature    = ");
+      debug_uint(id);
+      debug_str("\r\n");
+      pressure_sensor->ReadID(&id);
+      debug_str("LPS25H  pressure & temperature    = ");
+      debug_uint(id);
+      debug_str("\r\n");
+      magnetometer->ReadID(&id);
+      debug_str("LIS3MDL magnetometer              = ");
+      debug_uint(id);
+      debug_str("\r\n");
+      gyroscope->ReadID(&id);
+      debug_str("LSM6DS0 accelerometer & gyroscope = ");
+      debug_uint(id);
+      debug_str("\r\n");*/
+      
+//      wait(3);
+
+      while(1) {
+/*            debug_str("\r\n");
+        
+            temp_sensor1->GetTemperature(&value1);
+            humidity_sensor->GetHumidity(&value2);
+            debug_str("HTS221: [temp] ");
+            debug_str(printDouble(buffer1, value1));
+            debug_str("°C,   [hum] ");
+            debug_str(printDouble(buffer2, value2));
+            debug_str("%\r\n");
+            //pc.printf("HTS221: [temp] %7s°C,   [hum] %s%%\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));
+            
+            temp_sensor2->GetFahrenheit(&value1);
+            pressure_sensor->GetPressure(&value2);
+            debug_str("LPS25H: [temp] ");
+            debug_str(printDouble(buffer1, value1));
+            debug_str("°F, [press] ");
+            debug_str(printDouble(buffer2, value2));
+            debug_str("mbar\r\n");
+            //pc.printf("LPS25H: [temp] %7s°F, [press] %smbar\r\n", printDouble(buffer1, value1), printDouble(buffer2, value2));
+        
+            debug_str("---\r\n");
+        
+            magnetometer->Get_M_Axes(axes);
+            debug_str("LIS3MDL [mag/mgauss]:  ");
+            debug_uint(axes[0]);
+            debug_str(", ");
+            debug_uint(axes[1]);
+            debug_str(", ");
+            debug_uint(axes[2]);
+            debug_str("\r\n");
+            //pc.printf("LIS3MDL [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+        
+            accelerometer->Get_X_Axes(axes);
+            debug_str("LSM6DS0 [acc/mg]:      ");
+            debug_uint(axes[0]);
+            debug_str(", ");
+            debug_uint(axes[1]);
+            debug_str(", ");
+            debug_uint(axes[2]);
+            debug_str("\r\n");
+            //pc.printf("LSM6DS0 [acc/mg]:      %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
+        
+            gyroscope->Get_G_Axes(axes);
+            debug_str("LSM6DS0 [gyro/mdps]:   ");
+            debug_uint(axes[0]);
+            debug_str(", ");
+            debug_uint(axes[1]);
+            debug_str(", ");
+            debug_uint(axes[2]);
+            debug_str("\r\n");
+            //pc.printf("LSM6DS0 [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);*/
+
+            osjob_t* j = NULL;
+            hal_disableIRQs();
+            // check for runnable jobs
+            if(OS.runnablejobs) {
+                j = OS.runnablejobs;
+                OS.runnablejobs = j->next;
+            } else if(OS.scheduledjobs && hal_checkTimer(OS.scheduledjobs->deadline)) { // check for expired timed jobs
+                j = OS.scheduledjobs;
+                OS.scheduledjobs = j->next;
+            } else { // nothing pending
+                hal_sleep(); // wake by irq (timer already restarted)
+            }
+            hal_enableIRQs();
+            if(j) { // run job callback
+                j->func(j);
+            }
+      }
 }