test cli

Dependencies:   mbed-os-example-mbed5-lorawan

Fork of Projet_de_bachelor_code by LoRa_Bachelor

Revision:
23:3dfaed332d89
Parent:
18:1720bc3831ea
Child:
24:f00666a1be3a
--- a/main.cpp	Wed Jun 06 08:30:19 2018 +0100
+++ b/main.cpp	Fri Jun 08 18:13:32 2018 +0000
@@ -15,13 +15,15 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include "mbed.h"
+#include "Sensors.h"
+#include "qsd.h"
 
 #include "lorawan/LoRaWANInterface.h"
 #include "lorawan/system/lorawan_data_structures.h"
 #include "events/EventQueue.h"
 
 // Application helpers
-#include "DummySensor.h"
 #include "trace_helper.h"
 #include "lora_radio_helper.h"
 
@@ -58,7 +60,6 @@
 /**
  * Dummy sensor class object
  */
-DS1820  ds1820(PC_9);
 
 /**
 * This event queue is the global event queue for both the
@@ -90,8 +91,65 @@
 /**
  * Entry point for application
  */
+ 
+// Masque selection de bits
+#define MSK1    0xFF
+#define MSK2    0xFF00
+#define MSK3    0xFF0000
+#define MSK4    0xFF000000
+ 
+uint8_t MSGtosend[30];
+int pos, pos_1,pos_2;
+SENSORS capteur;
+QSD  qsd;
+int QSD_value;
+int QSD_VAL1,QSD_VAL2,QSD_VAL3,QSD_VAL4;
+
+int courant , courant_1,courant_2 ;
+
+int tension_bat;
+
 int main (void)
 {
+        tension_bat = capteur.vbat_sensor();
+        MSGtosend[0]=0x07;
+        MSGtosend[1]=0x01;
+        MSGtosend[2]= tension_bat ;   
+        /*
+        courant = capteur.current_sensor();
+        courant_1 = ((courant) & MSK1) >>0;
+        courant_2 = ((courant) & MSK2) >>8;
+        MSGtosend[0]=0x06;
+        MSGtosend[1]=0x02;
+        MSGtosend[2]=courant_2;
+        MSGtosend[3]=courant_1;
+        */
+        
+        /*
+        pos = capteur.transducer_sensor();
+        
+        pos_1 = (pos & MSK1) >>0;
+        pos_2 = (pos & MSK2) >>8;
+        
+        MSGtosend[0]=0x04;
+        MSGtosend[1]=0x02;
+        MSGtosend[2]=0x00;
+        MSGtosend[3]=pos;
+        */
+        /*
+        
+        QSD_value = qsd.read();
+        //printf("\r\n QSD Sensor Value = %d \r\n", QSD_value);
+        QSD_VAL1 = (QSD_value & MSK1)>>0;
+        QSD_VAL2 = (QSD_value & MSK2)>>8;
+        QSD_VAL3 = (QSD_value & MSK3)>>16;
+        QSD_VAL4 = (QSD_value & MSK4)>>24;
+        MSGtosend[0]=QSD_VAL4;
+        MSGtosend[1]=QSD_VAL3;
+        MSGtosend[2]=QSD_VAL2;
+        MSGtosend[3]=QSD_VAL1;
+        */
+        
     // setup tracing
     setup_trace();
 
@@ -141,8 +199,10 @@
 
     // make your event queue dispatching events forever
     ev_queue.dispatch_forever();
+    
+    return 0;
 
-    return 0;
+
 }
 
 
@@ -151,29 +211,17 @@
  */
 static void send_message()
 {
-    uint16_t packet_len;
-    int16_t retcode;
-    float sensor_value;
+     uint8_t packet_len;
+    int8_t retcode;
 
-    if (ds1820.begin()) {
-        ds1820.startConversion();
-        sensor_value = ds1820.read();
-        printf("\r\n Dummy Sensor Value = %3.1f \r\n", sensor_value);
-        ds1820.startConversion();
-    } else {
-        printf("\r\n No sensor found \r\n");
-        return;
-    }
+    packet_len = 4;
 
-    packet_len = sprintf((char*) tx_buffer, "Dummy Sensor Value is %3.1f",
-                    sensor_value);
-
-    retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
+    retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, MSGtosend, packet_len,
                            MSG_CONFIRMED_FLAG);
 
     if (retcode < 0) {
         retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")
-                : printf("\r\n send() - Error code %d \r\n", retcode);
+        : printf("\r\n send() - Error code %d \r\n", retcode);
         return;
     }
 
@@ -184,6 +232,7 @@
 /**
  * Receive a message from the Network Server
  */
+ /*
 static void receive_message()
 {
     int16_t retcode;
@@ -206,13 +255,14 @@
 
     memset(rx_buffer, 0, sizeof(rx_buffer));
 }
-
+*/
 /**
  * Event handler
  */
 static void lora_event_handler(lorawan_event_t event)
 {
-    switch (event) {
+    switch (event) 
+    {
         case CONNECTED:
             printf("\r\n Connection - Successful \r\n");
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
@@ -222,40 +272,13 @@
             }
 
             break;
-        case DISCONNECTED:
-            ev_queue.break_dispatch();
-            printf("\r\n Disconnected Successfully \r\n");
-            break;
         case TX_DONE:
             printf("\r\n Message Sent to Network Server \r\n");
             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
-                send_message();
-            }
-            break;
-        case TX_TIMEOUT:
-        case TX_ERROR:
-        case TX_CRYPTO_ERROR:
-        case TX_SCHEDULING_ERROR:
-            printf("\r\n Transmission Error - EventCode = %d \r\n", event);
-            // try again
-            if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
-                send_message();
-            }
-            break;
-        case RX_DONE:
-            printf("\r\n Received message from Network Server \r\n");
-            receive_message();
-            break;
-        case RX_TIMEOUT:
-        case RX_ERROR:
-            printf("\r\n Error in reception - Code = %d \r\n", event);
-            break;
-        case JOIN_FAILURE:
-            printf("\r\n OTAA Failed - Check Keys \r\n");
-            break;
-        default:
-            MBED_ASSERT("Unknown Event");
-    }
+               ev_queue.break_dispatch();
+               //timer.reset();
+            }                        
+    } 
+    
 }
-
 // EOF