![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version FC
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: ExtMemory.cpp
- Branch:
- Integration
- Revision:
- 38:9b43b2415093
- Parent:
- 36:14a8da4108d5
- Child:
- 39:13e66d087ae9
--- a/ExtMemory.cpp Tue Oct 16 11:28:33 2018 +0000 +++ b/ExtMemory.cpp Fri Oct 19 06:32:59 2018 +0000 @@ -9,33 +9,259 @@ // ===================================== Includes -#include <cstdio> #include "ExtMemory.hpp" -#include "Service.hpp" + +#ifdef TEST_ENVIRONMENT +#include "ConcreteService.hpp" +#endif + #include "Component.hpp" #include "Payload.hpp" + using namespace misnet; + // ===================================== Methods of class void ExtMemory::read (DataBase* dataBase) { - // read eeprom and initialize database //(Example) + DEBUG("*** EXTMEM Reading external memory ***\n"); + +#ifndef TEST_ENVIRONMENT uint8_t componentID=0xff; int16_t servicesNbr=0, servicesTotal=0; int32_t pos=0; ServiceDefinition sd,prev_sd; Header hd; EEPROM ep(I2C_SDA, I2C_SCL, EEPROM_ADDR, EEPROM::T24C04); +#endif - DEBUG( "*** EXTMEM Reading external memory ***\n"); + +#ifdef TEST_ENVIRONMENT + /* ****************************************************************************** + In this example, the terminal holds 3 components : + * the first is a BME280 component, containing 3 sensors : + * a presence sensor (IPSO code = 102) + * a temperature sensor (IPSO code = 103) + * a humidity sensor (IPSO code = 104) + * the second is a LSM303A component, containing 2 sensors : + * an accelerometer sensor (IPSO code = 113) + * a barometer sensor (IPSO code = 115) + * the third one is a DS18B20 containing an actuator (audio, IPCO code = 139). + + The terminal is of type IOT_PAYLOAD_3 (why not ?). + ****************************************************************************** */ + + + /* ************************************************************************************** + Pour Hoel et Francis, de la part de Patrick : je me doute bien que les composants BME280, + LSM303A et DS18B20 ne contiennent pas les devices décrits ici, c'est juste un exemple ;-) + ************************************************************************************** */ + + Service::ACCESS_PIN access_pins[6] = {1, 2, 3, 4, 5, 6}; + //Value::GENERIC_VALUE generic_value = { 0.0, Value::NOT_SET }; + + Value delta_threshold, low_threshold_limit, high_threshold_limit; + + std::vector<Service*> services = std::vector<Service*>(); + + // Construction du premier composant + // --------------------------------- + Component* component1 = new Component(Component::BME280, services); + + // Construction du premier service du premier composant + // ---------------------------------------------------- + delta_threshold.setUint16Value(100); + low_threshold_limit.setUint16Value(10000); + high_threshold_limit.setUint16Value(12000); + + Service* service1 = new ConcreteService(misnet::Service::SENSOR, + 102, + 1, + misnet::Value::UINT16_T, + Service::ENABLED, + Service::UART_, + Service::READ_BY_IRQ, + Service::BY_DELTA, + access_pins, + 300, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Premier service du composant BME280 sur cette payload", + component1); + + // Construction du deuxieme service du premier composant + // ----------------------------------------------------- + delta_threshold.setFloatValue(1.0); + low_threshold_limit.setFloatValue(100.0); + high_threshold_limit.setFloatValue(110.0); + + Service* service2 = new ConcreteService(Service::SENSOR, + 103, + 2, + misnet::Value::FLOAT, + Service::ENABLED, + Service::UART_, + Service::READ_BY_IRQ, + Service::BY_RANGE, + access_pins, + 120, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Deuxieme service du composant BME280 sur cette payload", + component1); + + // Construction du troisieme service du premier composant + // ------------------------------------------------------ + Service* service3 = new ConcreteService(Service::SENSOR, + 104, + 3, + misnet::Value::FLOAT, + Service::DISABLED, + Service::UART_, + Service::READ_BY_IRQ, + Service::BY_DELTA, + access_pins, + 30, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Troisieme service du composant BME280 sur cette payload", + component1); + + // Insertion des services du premier composant + // ------------------------------------------- + component1->getServices().push_back(service1); + component1->getServices().push_back(service2); + component1->getServices().push_back(service3); + -#ifndef TEST_ENVIRONMENT + // Construction du deuxieme composant + // ---------------------------------- + Component* component2 = new Component(Component::LSM303A, services); + + // Construction du premier service du deuxieme composant + // ----------------------------------------------------- + delta_threshold.setInt8Value(2); + low_threshold_limit.setInt8Value(100); + high_threshold_limit.setInt8Value(110); + + Service* service4 = new ConcreteService(Service::SENSOR, + 113, + 4, + misnet::Value::INT8_T, + Service::ENABLED, + Service::UART_, + Service::SYNCHRONOUS_READ, + Service::BY_DELTA, + access_pins, + 60, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Premier service du composant LSM303A sur cette payload", + component2); + + // Construction du deuxieme service du deuxieme composant + // ------------------------------------------------------ + Service* service5 = new ConcreteService(Service::SENSOR, + 115, + 5, + misnet::Value::INT8_T, + Service::DISABLED, + Service::UART_, + Service::SYNCHRONOUS_READ, + Service::BY_DELTA, + access_pins, + 80, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Deuxieme service du composant LSM303A sur cette payload", + component2); + + // Insertion des services du deuxieme composant + // -------------------------------------------- + component2->getServices().push_back(service4); + component2->getServices().push_back(service5); + + + // Construction du troisieme composant + // ----------------------------------- + Component* component3 = new Component(Component::DS18B20, services); + + // Construction du premier service du troisieme composant + // ------------------------------------------------------ + delta_threshold.setDoubleValue(1.0); + low_threshold_limit.setDoubleValue(0.0); + high_threshold_limit.setDoubleValue(1.0); + + Service* service6 = new ConcreteService(Service::ACTUATOR, + 139, + 6, + misnet::Value::DOUBLE, + Service::ENABLED, + Service::UART_, + Service::SYNCHRONOUS_READ, + Service::BY_RANGE, + access_pins, + 50, + delta_threshold, + low_threshold_limit, + high_threshold_limit, + Service::MESSAGE, + Service::IO, + "Premier service du composant DS18B20 sur cette payload", + component3); + + // Insertion des services du troisieme composant + // --------------------------------------------- + component3->getServices().push_back(service6); + + + // Construction de la payload + // -------------------------- + std::vector<Component*> components = std::vector<Component*>(); + components.push_back(component1); + components.push_back(component2); + components.push_back(component3); + + 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); + +#else dataBase->setRadioParameter ( (uint32_t)2400000000UL, LORA_BW_0400, LORA_SF7, (int8_t)-18, (uint8_t)100, (uint16_t)2000, (uint16_t)2000) ; -#endif // ---- read header block ep.read(pos, (void *) &hd, sizeof(hd)); @@ -87,167 +313,10 @@ } Payload * payload = new Payload((misnet::Payload::PAYLOAD_ID) hd.payload_id, components, hd.payload_base_period); dataBase->setPayload(payload); - - - /* ****************************************************************************** - In this example, the terminal holds 3 components : - * the first is a BME280 component, containing 3 sensors : - * a presence sensor (IPSO code = 102) - * a temperature sensor (IPSO code = 103) - * a humidity sensor (IPSO code = 104) - * the second is a LSM303A component, containing 2 sensors : - * an accelerometer sensor (IPSO code = 113) - * a barometer sensor (IPSO code = 115) - * the third one is a DS18B20 containing an actuator (audio, IPCO code = 139). - - The terminal is of type IOT_PAYLOAD_3 (why not ?). - ****************************************************************************** */ +#endif +} - /* ************************************************************************************** - Pour Hoel et Francis, de la part de Patrick : je me doute bien que les composants BME280, - LSM303A et DS18B20 ne contiennent pas les devices décrits ici, c'est juste un exemple ;-) - ************************************************************************************** */ - -// Service::ACCESS_PIN access_pins[6] = { 1, 2, 3, 4, 5, 6 }; -// -// // Construction du premier service du premier composant -// // ---------------------------------------------------- -// Service* service1 = new Service(Service::SENSOR, -// 102, -// Service::ENABLED, -// Service::UART_, -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 300, -// Service::MESSAGE, -// Service::IO, -// "Premier service du composant BME280 sur cette payload"); -// -// // Construction du deuxieme service du premier composant -// // ----------------------------------------------------- -// Service* service2 = new Service(Service::SENSOR, -// 103, -// Service::ENABLED, -// Service::UART_, -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 120, -// Service::MESSAGE, -// Service::IO, -// "Deuxieme service du composant BME280 sur cette payload"); -// -// // Construction du troisieme service du premier composant -// // ------------------------------------------------------ -// Service* service3 = new Service(Service::SENSOR, -// 104, -// Service::DISABLED, -// Service::UART_, -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 30, -// Service::MESSAGE, -// Service::IO, -// "Troisieme service du composant BME280 sur cette payload"); -// -// // Construction du premier composant -// // --------------------------------- -// 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 service du deuxieme composant -// // ----------------------------------------------------- -// Service* service4 = new Service(Service::SENSOR, -// 113, -// Service::ENABLED, -// Service::UART_, -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 60, -// Service::MESSAGE, -// Service::IO, -// "Premier service du composant LSM303A sur cette payload"); -// -// // Construction du deuxieme service du deuxieme composant -// // ------------------------------------------------------ -// Service* service5 = new Service(Service::SENSOR, -// 115, -// Service::DISABLED, -// Service::UART_, -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 80, -// Service::MESSAGE, -// Service::IO, -// "Deuxieme service du composant LSM303A sur cette payload"); -// -// // Construction du deuxieme composant -// // ---------------------------------- -// services.clear(); -// services.push_back(service4); -// services.push_back(service5); -// -// Component* component2 = new Component(Component::LSM303A, services); -// -// -// // Construction du premier service du troisieme composant -// // ------------------------------------------------------ -// Service* service6 = new Service(Service::ACTUATOR, -// 139, -// Service::ENABLED, -// Service::UART_, - -// Service::IRQ_, -// Service::BY_DELTA, -// access_pins, -// 50, -// Service::MESSAGE, -// Service::IO, -// "Premier service du composant DS18B20 sur cette payload"); -// -// // Construction du troisieme composant -// // ----------------------------------- -// services.clear(); -// services.push_back(service6); -// -// Component* component3 = new Component(Component::DS18B20, services); -// -// -// // Construction de la payload -// // -------------------------- -// std::vector<Component*> components = std::vector<Component*>(); -// components.push_back(component1); -// components.push_back(component2); -// components.push_back(component3); -// -// 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); -} void ExtMemory::populate (void) { int32_t pos=0;