Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Service.cpp

Committer:
patrick_duc
Date:
2018-09-04
Revision:
21:8524d815c587
Parent:
20:b0281e8a375a
Child:
22:a5929d3668b6

File content as of revision 21:8524d815c587:

#include "Service.hpp"

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


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) {
    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.isAbsoluteDifferenceValueGreatherThanDelta(this->previous_value, this->delta_threshold);
  }

  return (this->current_value.isDifferentFrom(this->previous_value));
}