Version FC
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: DataBase.cpp
- Branch:
- Integration
- Revision:
- 38:9b43b2415093
- Parent:
- 20:b0281e8a375a
- Child:
- 39:13e66d087ae9
--- a/DataBase.cpp Tue Oct 16 11:28:33 2018 +0000 +++ b/DataBase.cpp Fri Oct 19 06:32:59 2018 +0000 @@ -1,7 +1,7 @@ /* - * MISNet + * MISNet * - * Frame: Gestionnaire de fabrication des messages et décodage des messages recus + * Frame: Gestionnaire de fabrication des messages et décodage des messages recus * * Created on: August 17, 2018 Author: Francis CHATAIN * @@ -9,8 +9,10 @@ // ===================================== Includes -//#include "main.h" #include "DataBase.hpp" +#include "SMTClearMessagePart.hpp" +#include "BroadcastIOTClearMessagePart.hpp" +#include "GenericClearMessagePart.hpp" using namespace misnet; @@ -19,39 +21,34 @@ // ===================================== Method of class -// ===================================== Constructor -DataBase::DataBase () {} -DataBase::~DataBase () {} - -void DataBase::init () {} - +// ===================================== Constructor #ifndef TEST_ENVIRONMENT -void DataBase::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) -{ - rfFrequency = _rf_frequency ; - loraBw = _lora_bw ; - loraSf = _lora_sf ; - txOutputPower = _tx_output_power ; - bufferSizeMax = _buffer_size_max ; - terminal_heartbeat_period = _terminal_heartbeat_period; - payload_heartbeat_period = _payload_heartbeat_period; +void DataBase::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) +{ + rfFrequency = _rf_frequency ; + loraBw = _lora_bw ; + loraSf = _lora_sf ; + txOutputPower = _tx_output_power ; + bufferSizeMax = _buffer_size_max ; + terminal_heartbeat_period = _terminal_heartbeat_period; + payload_heartbeat_period = _payload_heartbeat_period; } -void DataBase::setRadioParameter ( 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 DataBase::setRadioParameter ( 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) { _rf_frequency = rfFrequency ; _lora_bw = loraBw ; @@ -61,18 +58,56 @@ _terminal_heartbeat_period = terminal_heartbeat_period ; _payload_heartbeat_period = payload_heartbeat_period ; - printf( "*** DTB *** setRadioParameter %ld %d %d %d %d %d %d\r\n", _rf_frequency, _lora_bw, - _lora_sf, _tx_output_power, _buffer_size_max,_terminal_heartbeat_period, _payload_heartbeat_period); + printf( "*** DTB *** setRadioParameter %ld %d %d %d %d %d %d\r\n", _rf_frequency, _lora_bw, + _lora_sf, _tx_output_power, _buffer_size_max,_terminal_heartbeat_period, _payload_heartbeat_period); } #endif -short DataBase::getNbService(Service::DEVICE_TYPE deviceType) { +void DataBase::setClearMessagePart() +{ + switch (this->getTerminalType()) { + case DataBase::NORMAL_IOT: + _clear_message_part = new NormalIOTClearMessagePart(_terminal_id, _gateway_id); + break; + case DataBase::BROADCAST_IOT: + _clear_message_part = new BroadcastIOTClearMessagePart(_terminal_id, _gateway_id); + break; + case DataBase::SMART_TOOL: + _clear_message_part = new SMTClearMessagePart(_smart_tool_id); + break; + case DataBase::GENERIC_PEER2PEER: + _clear_message_part = new GenericClearMessagePart(_link_id); + break; + default: + break; + } +} + + +void DataBase::setIOTConfigDataMessagePart() +{ + this->_iot_config_data_message_part = new misnet::IOTConfigDataMessagePart(); + + std::vector<Service*>::iterator serviceIt = this->_payload->getServices().begin(); + for (; serviceIt != this->_payload->getServices().end(); serviceIt++) { + //DEBUG("About to add description of channel %d\n", (*serviceIt)->getChannelNumber()); + ChannelDescription* channelDescription = new ChannelDescription((*serviceIt)->getChannelNumber(), + (*serviceIt)->getConfiguration(), + (*serviceIt)->getMisnetCode(), + (*serviceIt)->getValueType()); + this->_iot_config_data_message_part->addChannelDescription(channelDescription); + } +} + + +short DataBase::getNbService(Service::SERVICE_TYPE deviceType) +{ short result = 0; std::vector<Service*> channels = this->_payload->getServices(); - for(std::vector<Service*>::iterator it = channels.begin(); it != channels.end(); it++) { + for (std::vector<Service*>::iterator it = channels.begin(); it != channels.end(); it++) { Service* channel = *it; if (channel->getDeviceType() == deviceType) { result++; @@ -83,7 +118,8 @@ } -Service::DEVICE_TYPE DataBase::getServiceType (short channel) { +Service::SERVICE_TYPE DataBase::getServiceType(short channel) +{ return this->_payload->getServiceByRank(channel)->getDeviceType(); } @@ -96,10 +132,10 @@ std::vector<Component*>::iterator componentIt = this->_payload->getComponents().begin(); for (; componentIt != this->_payload->getComponents().end(); componentIt++) { - bool activeSensor = false; - for(std::vector<Service*>::iterator serviceIt = (*componentIt)->getServices().begin(); - serviceIt != (*componentIt)->getServices().end(); - serviceIt++) { + //bool activeSensor = false; + for (std::vector<Service*>::iterator serviceIt = (*componentIt)->getServices().begin(); + serviceIt != (*componentIt)->getServices().end(); + serviceIt++) { // Check that the service is enabled if ((*serviceIt)->getState() == Service::ENABLED) { @@ -123,3 +159,26 @@ return result; } + + +std::list<Service*> * DataBase::getCandidateServicesList() +{ + std::list<Service*> * result = new std::list<Service*>(); + std::vector<misnet::Service*>& services = this->_payload->getServices(); + + for (std::vector<Service*>::iterator serviceIt = services.begin(); + serviceIt != services.end(); + serviceIt++) { + + // Check that the service is enabled + if ((*serviceIt)->getState() == Service::ENABLED) { + + // Check that the subsampling rate matches this activation number + if ((*serviceIt)->processHeartbeat()) { + result->push_back(*serviceIt); + } + } + } + + return result; +}