Version FC
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: Service.cpp
- Revision:
- 20:b0281e8a375a
- Parent:
- 19:4b147d8f9164
- Child:
- 21:8524d815c587
diff -r 4b147d8f9164 -r b0281e8a375a Service.cpp --- a/Service.cpp Thu Aug 30 08:48:19 2018 +0000 +++ b/Service.cpp Sun Sep 02 22:24:14 2018 +0000 @@ -1,31 +1,105 @@ #include "Service.hpp" -Service::Service( DEVICE_TYPE type, - MISNET_CODE misnet_code, - STATE state, - ACCESS_TYPE access_type, - REQUEST_MODE request_mode, - UP_MODE up_mode, - ACCESS_PIN access_pins[6], - ACTION action, - OUTPUT_MODE output_mode, - std::string comment) { - this->device_type = type; - this->misnet_code = misnet_code; - this->state = state; - this->access_type = access_type; - this->request_mode = request_mode; - this->up_mode = up_mode; +using namespace misnet; + +Service::Service(DEVICE_TYPE type, + MISNET_CODE misnet_code, + STATE state, + ACCESS_TYPE access_type, + REQUEST_MODE request_mode, + UP_MODE up_mode, + ACCESS_PIN access_pins[6], + uint32_t subsample_rate, + ACTION action, + OUTPUT_MODE output_mode, + std::string comment) + : device_type(type), misnet_code(misnet_code), state(state), + access_type(access_type), request_mode(request_mode), + up_mode(up_mode), action(action), output_mode(output_mode), + comment(comment), subsample_rate(subsample_rate), activation_nb(0) { for (int i = 0; i < 6; i++) { this->access_pins[i] = access_pins[i]; } - this->action = action; - this->output_mode = output_mode; - this->comment = comment; +} + + +bool Service::processHeartbeat() { + if (this->readyToSample()) { + //DEBUG("\tReady to sample !\n"); + this->activation_nb = 0; + return true; + } + + //DEBUG("\tNot ready to sample...\n"); + ++(this->activation_nb); + + return false; } -std::ostream& operator<<(std::ostream& out, const Service& channel) { - out << "Device type : " << channel.device_type << ", MISNet code : " << (int) channel.misnet_code; - out << ", state : " << channel.state << ", comment : " << channel.comment; - return out; + +std::string Service::getValueAsString(GENERIC_VALUE& value) { + std::ostringstream stringStream; + + switch (value.type) { + case Service::NOT_SET: + break; + + case Service::BOOLEAN: + stringStream << (this->current_value.value.bool_value ? "true" : "false"); + break; + + case Service::CHAR: + stringStream << this->current_value.value.char_value; + break; + + case Service::UINT8_T: +#ifdef TEST_ENVIRONMENT + stringStream << std::to_string(this->current_value.value.uint8_value); +#else + stringStream << this->current_value.value.uint8_value; +#endif + break; + + case Service::INT8_T: +#ifdef TEST_ENVIRONMENT + stringStream << std::to_string(this->current_value.value.int8_value); +#else + stringStream << this->current_value.value.int8_value; +#endif + break; + + case Service::UINT16_T: + stringStream << this->current_value.value.uint16_value; + break; + + case Service::INT16_T: + stringStream << this->current_value.value.int16_value; + break; + + case Service::UINT32_T: + stringStream << this->current_value.value.uint32_value; + break; + + case Service::INT32_T: + stringStream << this->current_value.value.int32_value; + break; + + case Service::FLOAT: + stringStream << this->current_value.value.float_value; + break; + + case Service::DOUBLE: + stringStream << this->current_value.value.double_value; + break; + + case Service::TIME: + stringStream << this->current_value.value.time_value; + break; + + default: + stringStream << "Value not set !"; + break; + } + + return stringStream.str(); }