Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Branch:
Integration
Revision:
38:9b43b2415093
Parent:
33:6ae45cba7958
Child:
39:13e66d087ae9
--- a/DataBase.hpp	Tue Oct 16 11:28:33 2018 +0000
+++ b/DataBase.hpp	Fri Oct 19 06:32:59 2018 +0000
@@ -1,7 +1,7 @@
 /*
- * MISNet   
+ * MISNet
  *
- *  DataBase:   Contient les données du terminal 
+ *  DataBase:   Contient les données du terminal
  *
  *  Created on: August 17, 2018         Author: Francis CHATAIN
  *
@@ -10,13 +10,13 @@
 #ifndef __DATABASE_HPP__
 #define __DATABASE_HPP__
 
+#include <list>
+
 #include "Context.h"
 
 #ifndef TEST_ENVIRONMENT
 #include "mbed.h"
 #include "sx1280-hal.h"
-#include <string>
-#include <list>
 #endif
 
 #include "main.h"
@@ -24,9 +24,14 @@
 #include "Component.hpp"
 #include "CandidateComponent.hpp"
 #include "Payload.hpp"
+#include "ClearMessagePart.hpp"
+#include "ControlMessagePart.hpp"
+#include "NormalIOTClearMessagePart.hpp"
+#include "IOTConfigDataMessagePart.hpp"
+#include "IOTValuesDataMessagePart.hpp"
 
 
-// =======================================  Define 
+// =======================================  Define
 
 #define  MODE_STO   0x0000      //  P2P Smart Tool 
 #define  MODE_GEN   0x4000      //  P2P Generic
@@ -34,13 +39,15 @@
 #define  MODE_BCA   0xC000      //  STAR Broacast mode 
 
 
-namespace misnet {
-    class DataBase;
+namespace misnet
+{
+class DataBase;
 }
 
-// =======================================  Class content 
-class misnet::DataBase 
+// =======================================  Class content
+class misnet::DataBase
 {
+public:
     enum TERMINAL_TYPE {
         SMART_TOOL = 0,     // Smart Tool
         GENERIC = 1,        // Generic tool
@@ -48,51 +55,158 @@
         BROADCAST_IOT = 3   // Broadcast IOT (the terminal is not attached to a gateway)
     };
 
-    public:              
-        DataBase     ();
-        ~DataBase    ();
+    DataBase() {}
+    virtual ~DataBase() {}
+
+    void init ();
+
+    void setTerminalType(TERMINAL_TYPE terminal_type) {
+        this->_terminal_type = terminal_type;
+    }
+
+    TERMINAL_TYPE getTerminalType() {
+        return this->_terminal_type;
+    }
+
+    uint16_t getTerminalId() {
+        return this->_terminal_id;
+    }
+
+    void setTerminalId(uint16_t terminal_id) {
+        this->_terminal_id = terminal_id;
+    }
+
+    uint8_t getGatewayId() {
+        return this->_gateway_id;
+    }
+
+    void setGatewayId(uint8_t gateway_id) {
+        this->_gateway_id = gateway_id;
+    }
 
-        void        init () ;
+    uint8_t getApplicationId() {
+        return this->_application_id;
+    }
+
+    void setApplicationId(uint8_t application_id) {
+        this->_application_id = application_id;
+    }
+
+    void setPayloadModuleId(uint16_t payload_module_id) {
+        this->_payload_module_id = payload_module_id;
+    }
+
+    uint16_t getPayloadModuleId() {
+        return this->_payload_module_id;
+    }
 
-        TERMINAL_TYPE getTerminalType() {
-            return this->_terminal_type;
-        }
+    void setPayloadHeartbeatPeriod(uint16_t payload_heartbeat_period) {
+        this->_payload_heartbeat_period = payload_heartbeat_period;
+    }
+
+    void setPlatformHeartbeatPeriod(uint16_t platform_heartbeat_period) {
+        this->_platform_heartbeat_period = platform_heartbeat_period;
+    }
+
+    void setClearMessagePart();
+
+    misnet::ClearMessagePart* getClearMessagePart() {
+        return _clear_message_part;
+    }
+
+    void setIOTConfigDataMessagePart();
+
+    misnet::IOTConfigDataMessagePart* getIOTConfigDataMessagePart() {
+        return _iot_config_data_message_part;
+    }
 
-        short         getNbService              (Service::DEVICE_TYPE cdt); // return the number of declared channels for the payload 
-        Service::DEVICE_TYPE getServiceType     (short NumService)  ;        // Get Service type 
+    void setIOTValuesDataMessagePart(misnet::IOTValuesDataMessagePart* iotValuesDataMessagePart) {
+        DEBUG("Setting IOT values data message part to %p\n", iotValuesDataMessagePart);
+        _iot_values_data_message_part = iotValuesDataMessagePart;
+    }
+
+    misnet::IOTValuesDataMessagePart* getIOTValuesDataMessagePart() {
+        return _iot_values_data_message_part;
+    }
+
+    void setPendingServices(std::vector<misnet::Service *>& pendingServices) {
+        _pending_services = pendingServices;
+    }
 
+    std::vector<misnet::Service *>& getPendingServices() {
+        return _pending_services;
+    }
+
+    short getNbService(Service::DEVICE_TYPE cdt); // return the number of declared channels for the payload
+
+    void SetSensorState(short channel_rank, Service::STATE sensorState) ; // Set Sensor State  (Disable/Enable)
+    Service::STATE  GetSensorState(short channel_rank) ;                            // Get Sensor State  (Disable/Enable) know if the device shall requested
+
+    void SetSensorValue(uint8_t value);             // Set Sensor Value + compute value before storage
+    uint8_t GetSensorMessage(short channel_rank);   // Get Sensor Message  (False si no change no threahold, response formated)
+
+    short getNbActuator();
+    void SetActuatorState();
+    Service::STATE GetActuatorState(short actuator_rank);
+
+    void setPayload(misnet::Payload* payload) {
+        this->_payload = payload;
+    }
 
-        void            SetSensorState     (short channel_rank, Service::STATE sensorState) ; // Set Sensor State  (Disable/Enable)  
-        Service::STATE  GetSensorState     (short channel_rank) ;                            // Get Sensor State  (Disable/Enable) know if the device shall requested 
+    misnet::Payload* getPayload() {
+        return this->_payload;
+    }
+
+    std::list<misnet::Service*> * getCandidateServicesList();
 
-        void            SetSensorValue     (uint8_t value) ;             // Set Sensor Value + compute value before storage
-        uint8_t         GetSensorMessage   (short channel_rank)     ;             // Get Sensor Message  (False si no change no threahold, response formated)
+    // Initialise database for a standard IOT terminal
+    void initNormalIotTerminal(uint16_t terminal_id, uint8_t gateway_id, uint16_t payload_module_id,
+            uint16_t platform_heartbeat_period, uint16_t payload_heartbeat_period) {
+        this->setTerminalType(misnet::DataBase::NORMAL_IOT);
+        this->setTerminalId(terminal_id);
+        this->setGatewayId(gateway_id);
+        this->setPayloadModuleId(payload_module_id);
+        this->setPayloadHeartbeatPeriod(payload_heartbeat_period);
+        this->setPlatformHeartbeatPeriod(platform_heartbeat_period);
+        this->setClearMessagePart();
+        this->setIOTConfigDataMessagePart();
+        this->setIOTValuesDataMessagePart(NULL);
+    }
+
+    // Initialise database for a broadcast IOT terminal
+    void initBroadcastIotTerminal(uint16_t terminal_id, uint8_t application_id, uint16_t payload_module_id,
+            uint16_t platform_heartbeat_period, uint16_t payload_heartbeat_period) {
+        this->setTerminalType(misnet::DataBase::BROADCAST_IOT);
+        this->setTerminalId(terminal_id);
+        this->setApplicationId(application_id);
+        this->setPayloadModuleId(payload_module_id);
+        this->setPayloadHeartbeatPeriod(payload_heartbeat_period);
+        this->setPlatformHeartbeatPeriod(platform_heartbeat_period);
+        this->setClearMessagePart();
+        this->setIOTConfigDataMessagePart();
+        this->setIOTValuesDataMessagePart(NULL);
+    }
 
 
-        short           getNbActuator      () ;
-        void            SetActuatorState   () ;
-        Service::STATE  GetActuatorState   (short actuator_rank) ;
+    // =============================================================== Radio Parameter (getter/setter)
 
-         
-        // =============================================================== Radio Parameter (getter/setter) 
-   
 
 #ifndef TEST_ENVIRONMENT
-    void getRadioParameter ( uint32_t                   &rfFrequency, 
-                        RadioLoRaBandwidths_t           &loraBw,
-                        RadioLoRaSpreadingFactors_t     &loraSf ,
-                        int8_t                          &txOutputPower,
-                        uint8_t                         &bufferSizeMax,
-                        int16_t                         &terminal_heartbeat_period,
-                        int16_t                         &payload_heartbeat_period);
+    void getRadioParameter(uint32_t                   &rfFrequency,
+                             RadioLoRaBandwidths_t           &loraBw,
+                             RadioLoRaSpreadingFactors_t     &loraSf ,
+                             int8_t                          &txOutputPower,
+                             uint8_t                         &bufferSizeMax,
+                             int16_t                         &terminal_heartbeat_period,
+                             int16_t                         &payload_heartbeat_period);
 
-    void setRadioParameter ( uint32_t                   rfFrequency, 
-                        RadioLoRaBandwidths_t           loraBw,
-                        RadioLoRaSpreadingFactors_t     loraSf ,
-                        int8_t                          txOutputPower,
-                        uint8_t                         ufferSizeMax,
-                        int16_t                         terminal_heartbeat_period,
-                        int16_t                         payload_heartbeat_period);
+    void setRadioParameter ( uint32_t                   rfFrequency,
+                             RadioLoRaBandwidths_t           loraBw,
+                             RadioLoRaSpreadingFactors_t     loraSf ,
+                             int8_t                          txOutputPower,
+                             uint8_t                         ufferSizeMax,
+                             int16_t                         terminal_heartbeat_period,
+                             int16_t                         payload_heartbeat_period);
 #endif
 
     void setPayload(Payload* payload) {
@@ -107,22 +221,38 @@
 
 
     // Private variables /methods
-    private:
+private:
 #ifndef TEST_ENVIRONMENT
-        uint32_t                    _rf_frequency        ;   // HzNominal frequency
-        RadioLoRaBandwidths_t       _lora_bw             ;   /* 200; 400; 800; 1600 */
-        RadioLoRaSpreadingFactors_t _lora_sf             ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
-        int8_t                      _tx_output_power     ;   /* Output power in dBm [-18..+13] dBm */ 
-        uint8_t                     _buffer_size_max     ;   /* Payload size max */
+    uint32_t                    _rf_frequency        ;   // HzNominal frequency
+    RadioLoRaBandwidths_t       _lora_bw             ;   /* 200; 400; 800; 1600 */
+    RadioLoRaSpreadingFactors_t _lora_sf             ;   /* SF5; SF6=; SF7; SF8 ; SF9; SF10; SF11 ; SF12 */
+    int8_t                      _tx_output_power     ;   /* Output power in dBm [-18..+13] dBm */
+    uint8_t                     _buffer_size_max     ;   /* Payload size max */
 #endif
-        uint16_t                    _terminal_heartbeat_period; // Terminal heartbeat period
-        uint16_t                    _payload_heartbeat_period;  // Sensors' scan period
-        misnet::Payload*            _payload             ;          // Payload definition
 
+    // Normal or broadcast IOT terminal
+    uint16_t _terminal_id;
+    uint8_t _gateway_id;
+    uint8_t _application_id;
+    uint16_t _payload_module_id;
+
+    // Smart tool
+    uint16_t _smart_tool_id;
+
+    // Generic peer-to-peer terminal
+    uint16_t _link_id;
 
-    // Protected variable /method 
-    protected:
+    TERMINAL_TYPE _terminal_type;
+    uint16_t _platform_heartbeat_period; // Platform heartbeat period
+    uint16_t _payload_heartbeat_period; // Sensors' scan period
+    misnet::Payload* _payload; // Payload definition
+    misnet::ClearMessagePart* _clear_message_part;
+    misnet::IOTConfigDataMessagePart* _iot_config_data_message_part;
+    misnet::IOTValuesDataMessagePart* _iot_values_data_message_part;
 
-} ; 
+    // Services whose value must be read (a payload heart beat is ongoing)
+    // but their value requests an asynchronous read
+    std::vector<misnet::Service *> _pending_services;
+} ;
 
 #endif  // __DATABASE_HPP__