Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Service.cpp

Committer:
patrick_duc
Date:
2018-10-19
Branch:
Integration
Revision:
39:13e66d087ae9
Parent:
32:3bef9b81f639

File content as of revision 39:13e66d087ae9:

#include "Service.hpp"

using namespace misnet;

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];
    }

    this->current_value._value.type = Value::NOT_SET;
    this->previous_value._value.type = Value::NOT_SET;
}

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;
}

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));
    }

    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));
}