Voici le programme que vous m'avez demandé aujourd'hui

Dependencies:   mbed-os-example-mbed5-lorawan

Fork of mbed-os-example-mbed5-lorawan by mbed-os-examples

Files at this revision

API Documentation at this revision

Comitter:
Ranyd04
Date:
Fri Jun 08 18:13:32 2018 +0000
Parent:
22:a4fc83409028
Commit message:
Programme que vous m'avez demand?

Changed in this revision

DummySensor.h Show diff for this revision Revisions of this file
Sensors.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors.h 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
mbed-lora-radio-drv.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os-example-lorawan.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
qsd.cpp Show annotated file Show diff for this revision Revisions of this file
qsd.h Show annotated file Show diff for this revision Revisions of this file
--- a/DummySensor.h	Wed Jun 06 08:30:19 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/**
- * Copyright (c) 2017, Arm Limited and affiliates.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MBED_LORAWAN_DUMMYSENSOR_H_
-#define MBED_LORAWAN_DUMMYSENSOR_H_
-
-/*
- * A dummy sensor for Mbed LoRa Test Application
- */
-class DS1820
-{
-public:
-    DS1820(uint32_t) { value = 1.0; };
-    bool begin() { return true; };
-    void startConversion() {};
-    float read() {
-        value += 1.1;
-        return value;
-    }
-
-private:
-    float value;
-};
-
-
-
-#endif /* MBED_LORAWAN_DUMMYSENSOR_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors.cpp	Fri Jun 08 18:13:32 2018 +0000
@@ -0,0 +1,55 @@
+#include "Sensors.h"
+#include "mbed.h"
+
+int  SENSORS::current_sensor(){
+            float courant_mes;
+            int courant_lu;
+            DigitalOut alim_control(PA_10);
+            AnalogIn courant(PA_5);
+            alim_control = 1;
+            courant_mes = courant.read();
+            courant_lu = courant_mes * 250;
+            printf("courant = %f = %d mA\n", courant_mes,courant_lu);
+            return courant_lu;
+        }
+        
+int  SENSORS::transducer_sensor(){
+            float transducteur_volt;
+            int transducteur_pos;
+            AnalogIn transducteur(PA_2);
+            DigitalOut alim_control(PA_10);
+            DigitalOut control_trans(PB_5);
+            DigitalOut control_QSD(PA_9);
+            control_QSD = 1;
+            alim_control=1;
+            control_trans=1;
+            wait(2.0);
+            transducteur_volt =  transducteur.read();
+            transducteur_pos = transducteur_volt;
+            return  transducteur_pos;
+        }
+        
+int  SENSORS::vbat_sensor(){
+            float bat_mes;
+            int bat_lu;
+            AnalogIn tension_bat(PA_4);
+            int u_bat;
+            DigitalOut alim_control(PA_10);
+            DigitalOut control_trans(PB_5);
+            DigitalOut control_QSD(PA_9);
+            bat_mes = tension_bat.read();
+            DigitalOut led(PA_11);
+            bat_lu = bat_mes * 1800;
+            if(bat_lu<1700)
+            {
+                u_bat = 1;
+                led = 1;
+            }
+            else
+            {
+                u_bat = 0;
+                led = 0;
+            }
+            return u_bat;
+      
+        }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors.h	Fri Jun 08 18:13:32 2018 +0000
@@ -0,0 +1,16 @@
+#ifndef SENSORS_H
+#define SENSORS_H
+
+#include "mbed.h"
+
+class SENSORS{
+    public:
+    int current_sensor();
+    int transducer_sensor();
+    int vbat_sensor();
+    int temp_qsd_sensor();
+    int external_temp_sensor();
+    };
+    
+#endif 
+     
\ No newline at end of file
--- 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
--- a/mbed-lora-radio-drv.lib	Wed Jun 06 08:30:19 2018 +0100
+++ b/mbed-lora-radio-drv.lib	Fri Jun 08 18:13:32 2018 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers#c4dd25eec9ae30f9532e498ea7e2cacd758c733e
+https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers/#c4dd25eec9ae30f9532e498ea7e2cacd758c733e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os-example-lorawan.lib	Fri Jun 08 18:13:32 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/mbed-os-examples/code/mbed-os-example-lorawan/#a4fc83409028
--- a/mbed_app.json	Wed Jun 06 08:30:19 2018 +0100
+++ b/mbed_app.json	Fri Jun 08 18:13:32 2018 +0000
@@ -33,9 +33,9 @@
             "lora.over-the-air-activation": true,
             "lora.duty-cycle-on": true,
             "lora.phy": 0,
-            "lora.device-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
-            "lora.application-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
-            "lora.application-key": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }"
+            "lora.device-eui": "{ 0x07, 0x98, 0x40, 0x40, 0x76, 0x07, 0x98, 0x40 }",
+            "lora.application-eui": "{ 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0xC0, 0x1A }",
+            "lora.application-key": "{ 0x01, 0x29, 0x7E, 0x14, 0x4A, 0x8E, 0x55, 0xAD, 0x3D, 0xF3, 0x5F, 0x5A, 0x63, 0x3B, 0x9B, 0x31 }"
         },
 
         "K64F": {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qsd.cpp	Fri Jun 08 18:13:32 2018 +0000
@@ -0,0 +1,29 @@
+
+#include "qsd.h"
+
+int QSD::read(void){
+            int test = 0;
+            DigitalOut alim_control(PA_10);
+            DigitalOut control_trans(PB_5);
+            DigitalOut control_QSD(PA_9);
+            alim_control = 1;
+            control_trans=0;
+            control_QSD=0;
+            wait(2.0);
+            cs->write(0);
+            test |= spi->write(0x00);
+            test |= spi->write(0x00) << 8;
+            test |= spi->write(0x00) << 16;
+            test |= spi->write(0x00) << 24;
+            cs->write(1);
+            control_QSD=1;
+            return test;
+        }
+        
+QSD::QSD(){
+           spi = new SPI(PB_15, PB_14 ,PB_13);
+           cs = new DigitalOut(PB_12);
+           spi->format(8, 0);
+           spi->frequency(1000000);
+           cs->write(1);
+        };
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qsd.h	Fri Jun 08 18:13:32 2018 +0000
@@ -0,0 +1,17 @@
+
+#ifndef QSD_H
+#define QSD_H
+
+#include "mbed.h"
+
+class QSD{
+    public:
+        SPI *spi;
+        DigitalOut *cs;
+        QSD();
+        
+        int read(void);   
+           
+};
+
+#endif
\ No newline at end of file