Version FC
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: Service.cpp
- Branch:
- Integration
- Revision:
- 39:13e66d087ae9
- Parent:
- 32:3bef9b81f639
--- a/Service.cpp Fri Oct 19 06:32:59 2018 +0000 +++ b/Service.cpp Fri Oct 19 15:08:35 2018 +0000 @@ -2,26 +2,29 @@ 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, - Value& delta_threshold, - Value& low_threshold_limit, - Value& high_threshold_limit, - 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), subsample_rate(subsample_rate), delta_threshold(delta_threshold), - low_threshold_limit(low_threshold_limit), high_threshold_limit(high_threshold_limit), - action(action), output_mode(output_mode), - comment(comment), activation_nb(0) { +Service::Service(SERVICE_TYPE type, + MISNET_CODE misnet_code, + uint8_t channel_number, + misnet::Value::VALUE_TYPE value_type, + STATE state, + ACCESS_TYPE access_type, + REQUEST_MODE request_mode, + UP_MODE up_mode, + ACCESS_PIN access_pins[6], + uint32_t subsample_rate, + Value& delta_threshold, + Value& low_threshold_limit, + Value& high_threshold_limit, + ACTION action, + OUTPUT_MODE output_mode, + std::string comment, + Component * parent) +: device_type(type), misnet_code(misnet_code), channel_number(channel_number), value_type(value_type), + state(state), access_type(access_type), request_mode(request_mode), +up_mode(up_mode), subsample_rate(subsample_rate), delta_threshold(delta_threshold), +low_threshold_limit(low_threshold_limit), high_threshold_limit(high_threshold_limit), +action(action), output_mode(output_mode), +comment(comment), parent(parent), activation_nb(0) { for (int i = 0; i < 6; i++) { this->access_pins[i] = access_pins[i]; } @@ -30,7 +33,6 @@ this->previous_value._value.type = Value::NOT_SET; } - bool Service::processHeartbeat() { if (this->readyToSample()) { //DEBUG("\tReady to sample !\n"); @@ -44,19 +46,20 @@ return false; } +bool Service::valueToBeSentToGateway() { + if (this->up_mode == Service::BY_RANGE) { +#ifdef TEST_ENVIRONMENT + DEBUG("About to compare value %s to low limit (%s) and high limit (%s)\n", + this->current_value.toString().c_str(), this->low_threshold_limit.toString().c_str(), + this->high_threshold_limit.toString().c_str()); +#endif + return ((this->low_threshold_limit.compareTo(this->current_value) > 0) + || (this->current_value.compareTo(this->high_threshold_limit) > 0)); + } -bool Service::valueToBeSentToGateway() { - if (this->up_mode == Service::BY_RANGE) { - DEBUG("About to compare value %s to low limit (%s) and high limit (%s)\n", - this->current_value.toString().c_str(), this->low_threshold_limit.toString().c_str(), - this->high_threshold_limit.toString().c_str()); - return ((this->low_threshold_limit.compareTo(this->current_value) > 0) - || (this->current_value.compareTo(this->high_threshold_limit) > 0)); - } + if (this->up_mode == Service::BY_DELTA) { + return this->current_value.isAbsoluteDifferenceValueGreaterThanDelta(this->previous_value, this->delta_threshold); + } - if (this->up_mode == Service::BY_DELTA) { - return this->current_value.isAbsoluteDifferenceValueGreaterThanDelta(this->previous_value, this->delta_threshold); - } - - return (this->current_value.isDifferentFrom(this->previous_value)); + return (this->current_value.isDifferentFrom(this->previous_value)); }