Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Revision:
20:b0281e8a375a
Parent:
19:4b147d8f9164
Child:
21:8524d815c587
--- a/ExtMemory.cpp	Thu Aug 30 08:48:19 2018 +0000
+++ b/ExtMemory.cpp	Sun Sep 02 22:24:14 2018 +0000
@@ -6,27 +6,29 @@
  *  Created on: August 17, 2018       Author: Francis CHATAIN
  *
  */
- 
-
 
 
 // =====================================  Includes
-#include "ExtMemory.h"
+#include "ExtMemory.hpp"
 #include "Service.hpp"
 #include "Component.hpp"
 #include "Payload.hpp"
-#include "DataBase.h"
+
 
-// =====================================  Method of class
+using namespace misnet;
 
 
+// =====================================  Methods of class
+
 void ExtMemory::read (DataBase* dataBase) {
     // read eeprom  and initialize database
     //(Example)
 
-    printf( "*** EXTMEM Reading external memory ***\n");
+    DEBUG( "*** EXTMEM Reading external memory ***\n");
 
-    dataBase->setRadioParameter ( (uint32_t)2400000000UL, LORA_BW_0400, LORA_SF7, (int8_t)-18, (uint8_t)100, (uint16_t)2000) ;
+#ifndef TEST_ENVIRONMENT
+    dataBase->setRadioParameter ( (uint32_t)2400000000UL, LORA_BW_0400, LORA_SF7, (int8_t)-18, (uint8_t)100, (uint16_t)2000, (uint16_t)2000) ;
+#endif
 
 
     /* ******************************************************************************
@@ -51,109 +53,114 @@
 
     Service::ACCESS_PIN access_pins[6] = { 1, 2, 3, 4, 5, 6 };
 
-    // Construction du premier channel du premier composant
+    // Construction du premier service du premier composant
     // ----------------------------------------------------
-    Service* channel1 = new Service(Service::SENSOR,
+    Service* service1 = new Service(Service::SENSOR,
                             102,
-                            Service::ENABLE_,
+                            Service::ENABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            300,
                             Service::MESSAGE,
                             Service::IO,
-                            "Premier channel du composant BME280 sur cette payload");
+                            "Premier service du composant BME280 sur cette payload");
 
-    // Construction du deuxieme channel du premier composant
+    // Construction du deuxieme service du premier composant
     // -----------------------------------------------------
-    Service* channel2 = new Service(Service::SENSOR,
+    Service* service2 = new Service(Service::SENSOR,
                             103,
-                            Service::ENABLE_,
+                            Service::ENABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            120,
                             Service::MESSAGE,
                             Service::IO,
-                            "Deuxieme channel du composant BME280 sur cette payload");
+                            "Deuxieme service du composant BME280 sur cette payload");
 
-    // Construction du troisieme channel du premier composant
+    // Construction du troisieme service du premier composant
     // ------------------------------------------------------
-    Service* channel3 = new Service(Service::SENSOR,
+    Service* service3 = new Service(Service::SENSOR,
                             104,
-                            Service::ENABLE_,
+                            Service::DISABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            30,
                             Service::MESSAGE,
                             Service::IO,
-                            "Troisieme channel du composant BME280 sur cette payload");
+                            "Troisieme service du composant BME280 sur cette payload");
 
     // Construction du premier composant
     // ---------------------------------
-    std::vector<Service*> channels = std::vector<Service*>();
-    channels.push_back(channel1);
-    channels.push_back(channel2);
-    channels.push_back(channel3);
-
-    Component* component1 = new Component(Component::BME280, channels);
+    std::vector<Service*> services = std::vector<Service*>();
+    services.push_back(service1);
+    services.push_back(service2);
+    services.push_back(service3);
 
+    Component* component1 = new Component(Component::BME280, services);
 
-    // Construction du premier channel du deuxieme composant
+    // Construction du premier service du deuxieme composant
     // -----------------------------------------------------
-    Service* channel4 = new Service(Service::SENSOR,
+    Service* service4 = new Service(Service::SENSOR,
                             113,
-                            Service::ENABLE_,
+                            Service::ENABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            60,
                             Service::MESSAGE,
                             Service::IO,
-                            "Premier channel du composant LSM303A sur cette payload");
+                            "Premier service du composant LSM303A sur cette payload");
 
-    // Construction du deuxieme channel du deuxieme composant
+    // Construction du deuxieme service du deuxieme composant
     // ------------------------------------------------------
-    Service* channel5 = new Service(Service::SENSOR,
+    Service* service5 = new Service(Service::SENSOR,
                             115,
-                            Service::ENABLE_,
+                            Service::DISABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            80,
                             Service::MESSAGE,
                             Service::IO,
-                            "Deuxieme channel du composant LSM303A sur cette payload");
+                            "Deuxieme service du composant LSM303A sur cette payload");
 
     // Construction du deuxieme composant
     // ----------------------------------
-    channels.clear();
-    channels.push_back(channel4);
-    channels.push_back(channel5);
+    services.clear();
+    services.push_back(service4);
+    services.push_back(service5);
 
-    Component* component2 = new Component(Component::LSM303A, channels);
+    Component* component2 = new Component(Component::LSM303A, services);
 
 
-    // Construction du premier channel du troisieme composant
+    // Construction du premier service du troisieme composant
     // ------------------------------------------------------
-    Service* channel6 = new Service(Service::ACTUATOR,
+    Service* service6 = new Service(Service::ACTUATOR,
                             139,
-                            Service::ENABLE_,
+                            Service::ENABLED,
                             Service::UART_,
                             Service::IRQ_,
                             Service::BY_VALUE,
                             access_pins,
+                            50,
                             Service::MESSAGE,
                             Service::IO,
-                            "Premier channel du composant DS18B20 sur cette payload");
+                            "Premier service du composant DS18B20 sur cette payload");
 
     // Construction du troisieme composant
     // -----------------------------------
-    channels.clear();
-    channels.push_back(channel6);
+    services.clear();
+    services.push_back(service6);
 
-    Component* component3 = new Component(Component::DS18B20, channels);
+    Component* component3 = new Component(Component::DS18B20, services);
 
 
     // Construction de la payload
@@ -163,13 +170,22 @@
     components.push_back(component2);
     components.push_back(component3);
 
-    Payload * payload = new Payload(Payload::IOT_PAYLOAD_3, components);
+    Payload * payload = new Payload(Payload::IOT_PAYLOAD_3, components, 10000);
+
+    /* Payload sampling information, based on this example
+       ---------------------------------------------------
+        - Payload base period is 10000, which means 176 microseconds * 10000, i.e. 1.76 seconds
+            - Service 1 : subsample rate is 300, so the service sampling period is 528 seconds
+            - Service 2 : subsample rate is 120, so the service sampling period is 211.2 seconds
+            - Service 3 : subsample rate is 30, so the service sampling period is 52.8 seconds
+            - Service 4 : subsample rate is 60, so the service sampling period is 105.6 seconds
+            - Service 5 : subsample rate is 80, so the service sampling period is 140.8 seconds
+            - Service 6 : subsample rate is 50, so the service sampling period is 35.2 seconds
+        - GCD (Greatest Common Divisor) of its services is 10, so the payload will be awaken
+          every 17.6 seconds.
+    */
 
     // Enregistrement de la payload dans la database
     // ---------------------------------------------
     dataBase->setPayload(payload);
-
-    // Affichage de la payload, juste pour vérifier...
-    // ***********************************************
-    std::cout << *payload << std::endl;
 }