Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Committer:
patrick_duc
Date:
Tue Sep 04 13:34:36 2018 +0000
Revision:
21:8524d815c587
Parent:
20:b0281e8a375a
Child:
24:92c30dabfda4
Ajout de la fonctionnalit? de d?termination si la valeur acquise sur un capteur doit ?tre envoy?e ? la gateway.; Ajout d'une classe Value qui encapsule les valeurs g?n?riques (pr?c?demment GENERIC_VALUE).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
FCH_31 10:1b37e3b41947 1 /*
FCH_31 10:1b37e3b41947 2 * MISNet
FCH_31 10:1b37e3b41947 3 *
FCH_31 10:1b37e3b41947 4 * ExtMemory: Accès EEPROM
FCH_31 10:1b37e3b41947 5 *
FCH_31 10:1b37e3b41947 6 * Created on: August 17, 2018 Author: Francis CHATAIN
FCH_31 10:1b37e3b41947 7 *
FCH_31 10:1b37e3b41947 8 */
FCH_31 10:1b37e3b41947 9
FCH_31 10:1b37e3b41947 10
FCH_31 10:1b37e3b41947 11 // ===================================== Includes
patrick_duc 21:8524d815c587 12 #include <cstdio>
patrick_duc 21:8524d815c587 13
patrick_duc 20:b0281e8a375a 14 #include "ExtMemory.hpp"
patrick_duc 19:4b147d8f9164 15 #include "Service.hpp"
patrick_duc 13:5414193da1de 16 #include "Component.hpp"
patrick_duc 13:5414193da1de 17 #include "Payload.hpp"
patrick_duc 20:b0281e8a375a 18
FCH_31 10:1b37e3b41947 19
patrick_duc 20:b0281e8a375a 20 using namespace misnet;
FCH_31 10:1b37e3b41947 21
FCH_31 10:1b37e3b41947 22
patrick_duc 20:b0281e8a375a 23 // ===================================== Methods of class
patrick_duc 20:b0281e8a375a 24
FCH_31 10:1b37e3b41947 25 void ExtMemory::read (DataBase* dataBase) {
FCH_31 10:1b37e3b41947 26 // read eeprom and initialize database
FCH_31 10:1b37e3b41947 27 //(Example)
patrick_duc 13:5414193da1de 28
patrick_duc 20:b0281e8a375a 29 DEBUG( "*** EXTMEM Reading external memory ***\n");
patrick_duc 13:5414193da1de 30
patrick_duc 20:b0281e8a375a 31 #ifndef TEST_ENVIRONMENT
patrick_duc 20:b0281e8a375a 32 dataBase->setRadioParameter ( (uint32_t)2400000000UL, LORA_BW_0400, LORA_SF7, (int8_t)-18, (uint8_t)100, (uint16_t)2000, (uint16_t)2000) ;
patrick_duc 20:b0281e8a375a 33 #endif
patrick_duc 13:5414193da1de 34
patrick_duc 13:5414193da1de 35
patrick_duc 13:5414193da1de 36 /* ******************************************************************************
patrick_duc 13:5414193da1de 37 In this example, the terminal holds 3 components :
patrick_duc 13:5414193da1de 38 * the first is a BME280 component, containing 3 sensors :
patrick_duc 13:5414193da1de 39 * a presence sensor (IPSO code = 102)
patrick_duc 13:5414193da1de 40 * a temperature sensor (IPSO code = 103)
patrick_duc 13:5414193da1de 41 * a humidity sensor (IPSO code = 104)
patrick_duc 13:5414193da1de 42 * the second is a LSM303A component, containing 2 sensors :
patrick_duc 13:5414193da1de 43 * an accelerometer sensor (IPSO code = 113)
patrick_duc 13:5414193da1de 44 * a barometer sensor (IPSO code = 115)
patrick_duc 13:5414193da1de 45 * the third one is a DS18B20 containing an actuator (audio, IPCO code = 139).
patrick_duc 13:5414193da1de 46
patrick_duc 13:5414193da1de 47 The terminal is of type IOT_PAYLOAD_3 (why not ?).
patrick_duc 13:5414193da1de 48 ****************************************************************************** */
FCH_31 10:1b37e3b41947 49
FCH_31 10:1b37e3b41947 50
patrick_duc 13:5414193da1de 51 /* **************************************************************************************
patrick_duc 13:5414193da1de 52 Pour Hoel et Francis, de la part de Patrick : je me doute bien que les composants BME280,
patrick_duc 13:5414193da1de 53 LSM303A et DS18B20 ne contiennent pas les devices décrits ici, c'est juste un exemple ;-)
patrick_duc 13:5414193da1de 54 ************************************************************************************** */
patrick_duc 13:5414193da1de 55
patrick_duc 19:4b147d8f9164 56 Service::ACCESS_PIN access_pins[6] = { 1, 2, 3, 4, 5, 6 };
patrick_duc 13:5414193da1de 57
patrick_duc 20:b0281e8a375a 58 // Construction du premier service du premier composant
patrick_duc 13:5414193da1de 59 // ----------------------------------------------------
patrick_duc 20:b0281e8a375a 60 Service* service1 = new Service(Service::SENSOR,
patrick_duc 13:5414193da1de 61 102,
patrick_duc 20:b0281e8a375a 62 Service::ENABLED,
patrick_duc 19:4b147d8f9164 63 Service::UART_,
patrick_duc 19:4b147d8f9164 64 Service::IRQ_,
patrick_duc 21:8524d815c587 65 Service::BY_DELTA,
patrick_duc 13:5414193da1de 66 access_pins,
patrick_duc 20:b0281e8a375a 67 300,
patrick_duc 19:4b147d8f9164 68 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 69 Service::IO,
patrick_duc 20:b0281e8a375a 70 "Premier service du composant BME280 sur cette payload");
patrick_duc 13:5414193da1de 71
patrick_duc 20:b0281e8a375a 72 // Construction du deuxieme service du premier composant
patrick_duc 13:5414193da1de 73 // -----------------------------------------------------
patrick_duc 20:b0281e8a375a 74 Service* service2 = new Service(Service::SENSOR,
patrick_duc 13:5414193da1de 75 103,
patrick_duc 20:b0281e8a375a 76 Service::ENABLED,
patrick_duc 19:4b147d8f9164 77 Service::UART_,
patrick_duc 19:4b147d8f9164 78 Service::IRQ_,
patrick_duc 21:8524d815c587 79 Service::BY_DELTA,
patrick_duc 13:5414193da1de 80 access_pins,
patrick_duc 20:b0281e8a375a 81 120,
patrick_duc 19:4b147d8f9164 82 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 83 Service::IO,
patrick_duc 20:b0281e8a375a 84 "Deuxieme service du composant BME280 sur cette payload");
patrick_duc 13:5414193da1de 85
patrick_duc 20:b0281e8a375a 86 // Construction du troisieme service du premier composant
patrick_duc 13:5414193da1de 87 // ------------------------------------------------------
patrick_duc 20:b0281e8a375a 88 Service* service3 = new Service(Service::SENSOR,
patrick_duc 13:5414193da1de 89 104,
patrick_duc 20:b0281e8a375a 90 Service::DISABLED,
patrick_duc 19:4b147d8f9164 91 Service::UART_,
patrick_duc 19:4b147d8f9164 92 Service::IRQ_,
patrick_duc 21:8524d815c587 93 Service::BY_DELTA,
patrick_duc 13:5414193da1de 94 access_pins,
patrick_duc 20:b0281e8a375a 95 30,
patrick_duc 19:4b147d8f9164 96 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 97 Service::IO,
patrick_duc 20:b0281e8a375a 98 "Troisieme service du composant BME280 sur cette payload");
patrick_duc 13:5414193da1de 99
patrick_duc 13:5414193da1de 100 // Construction du premier composant
patrick_duc 13:5414193da1de 101 // ---------------------------------
patrick_duc 20:b0281e8a375a 102 std::vector<Service*> services = std::vector<Service*>();
patrick_duc 20:b0281e8a375a 103 services.push_back(service1);
patrick_duc 20:b0281e8a375a 104 services.push_back(service2);
patrick_duc 20:b0281e8a375a 105 services.push_back(service3);
patrick_duc 13:5414193da1de 106
patrick_duc 20:b0281e8a375a 107 Component* component1 = new Component(Component::BME280, services);
patrick_duc 13:5414193da1de 108
patrick_duc 20:b0281e8a375a 109 // Construction du premier service du deuxieme composant
patrick_duc 13:5414193da1de 110 // -----------------------------------------------------
patrick_duc 20:b0281e8a375a 111 Service* service4 = new Service(Service::SENSOR,
patrick_duc 13:5414193da1de 112 113,
patrick_duc 20:b0281e8a375a 113 Service::ENABLED,
patrick_duc 19:4b147d8f9164 114 Service::UART_,
patrick_duc 19:4b147d8f9164 115 Service::IRQ_,
patrick_duc 21:8524d815c587 116 Service::BY_DELTA,
patrick_duc 13:5414193da1de 117 access_pins,
patrick_duc 20:b0281e8a375a 118 60,
patrick_duc 19:4b147d8f9164 119 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 120 Service::IO,
patrick_duc 20:b0281e8a375a 121 "Premier service du composant LSM303A sur cette payload");
patrick_duc 13:5414193da1de 122
patrick_duc 20:b0281e8a375a 123 // Construction du deuxieme service du deuxieme composant
patrick_duc 13:5414193da1de 124 // ------------------------------------------------------
patrick_duc 20:b0281e8a375a 125 Service* service5 = new Service(Service::SENSOR,
patrick_duc 13:5414193da1de 126 115,
patrick_duc 20:b0281e8a375a 127 Service::DISABLED,
patrick_duc 19:4b147d8f9164 128 Service::UART_,
patrick_duc 19:4b147d8f9164 129 Service::IRQ_,
patrick_duc 21:8524d815c587 130 Service::BY_DELTA,
patrick_duc 13:5414193da1de 131 access_pins,
patrick_duc 20:b0281e8a375a 132 80,
patrick_duc 19:4b147d8f9164 133 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 134 Service::IO,
patrick_duc 20:b0281e8a375a 135 "Deuxieme service du composant LSM303A sur cette payload");
patrick_duc 13:5414193da1de 136
patrick_duc 13:5414193da1de 137 // Construction du deuxieme composant
patrick_duc 13:5414193da1de 138 // ----------------------------------
patrick_duc 20:b0281e8a375a 139 services.clear();
patrick_duc 20:b0281e8a375a 140 services.push_back(service4);
patrick_duc 20:b0281e8a375a 141 services.push_back(service5);
patrick_duc 13:5414193da1de 142
patrick_duc 20:b0281e8a375a 143 Component* component2 = new Component(Component::LSM303A, services);
patrick_duc 13:5414193da1de 144
patrick_duc 13:5414193da1de 145
patrick_duc 20:b0281e8a375a 146 // Construction du premier service du troisieme composant
patrick_duc 13:5414193da1de 147 // ------------------------------------------------------
patrick_duc 20:b0281e8a375a 148 Service* service6 = new Service(Service::ACTUATOR,
patrick_duc 13:5414193da1de 149 139,
patrick_duc 20:b0281e8a375a 150 Service::ENABLED,
patrick_duc 19:4b147d8f9164 151 Service::UART_,
patrick_duc 19:4b147d8f9164 152 Service::IRQ_,
patrick_duc 21:8524d815c587 153 Service::BY_DELTA,
patrick_duc 13:5414193da1de 154 access_pins,
patrick_duc 20:b0281e8a375a 155 50,
patrick_duc 19:4b147d8f9164 156 Service::MESSAGE,
patrick_duc 19:4b147d8f9164 157 Service::IO,
patrick_duc 20:b0281e8a375a 158 "Premier service du composant DS18B20 sur cette payload");
patrick_duc 13:5414193da1de 159
patrick_duc 13:5414193da1de 160 // Construction du troisieme composant
patrick_duc 13:5414193da1de 161 // -----------------------------------
patrick_duc 20:b0281e8a375a 162 services.clear();
patrick_duc 20:b0281e8a375a 163 services.push_back(service6);
patrick_duc 13:5414193da1de 164
patrick_duc 20:b0281e8a375a 165 Component* component3 = new Component(Component::DS18B20, services);
patrick_duc 13:5414193da1de 166
patrick_duc 13:5414193da1de 167
patrick_duc 13:5414193da1de 168 // Construction de la payload
patrick_duc 13:5414193da1de 169 // --------------------------
patrick_duc 18:d5e7e56b0a0d 170 std::vector<Component*> components = std::vector<Component*>();
patrick_duc 13:5414193da1de 171 components.push_back(component1);
patrick_duc 13:5414193da1de 172 components.push_back(component2);
patrick_duc 13:5414193da1de 173 components.push_back(component3);
patrick_duc 13:5414193da1de 174
patrick_duc 20:b0281e8a375a 175 Payload * payload = new Payload(Payload::IOT_PAYLOAD_3, components, 10000);
patrick_duc 20:b0281e8a375a 176
patrick_duc 20:b0281e8a375a 177 /* Payload sampling information, based on this example
patrick_duc 20:b0281e8a375a 178 ---------------------------------------------------
patrick_duc 20:b0281e8a375a 179 - Payload base period is 10000, which means 176 microseconds * 10000, i.e. 1.76 seconds
patrick_duc 20:b0281e8a375a 180 - Service 1 : subsample rate is 300, so the service sampling period is 528 seconds
patrick_duc 20:b0281e8a375a 181 - Service 2 : subsample rate is 120, so the service sampling period is 211.2 seconds
patrick_duc 20:b0281e8a375a 182 - Service 3 : subsample rate is 30, so the service sampling period is 52.8 seconds
patrick_duc 20:b0281e8a375a 183 - Service 4 : subsample rate is 60, so the service sampling period is 105.6 seconds
patrick_duc 20:b0281e8a375a 184 - Service 5 : subsample rate is 80, so the service sampling period is 140.8 seconds
patrick_duc 20:b0281e8a375a 185 - Service 6 : subsample rate is 50, so the service sampling period is 35.2 seconds
patrick_duc 20:b0281e8a375a 186 - GCD (Greatest Common Divisor) of its services is 10, so the payload will be awaken
patrick_duc 20:b0281e8a375a 187 every 17.6 seconds.
patrick_duc 20:b0281e8a375a 188 */
patrick_duc 13:5414193da1de 189
patrick_duc 13:5414193da1de 190 // Enregistrement de la payload dans la database
patrick_duc 13:5414193da1de 191 // ---------------------------------------------
patrick_duc 13:5414193da1de 192 dataBase->setPayload(payload);
patrick_duc 13:5414193da1de 193 }