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-02
Revision:
20:b0281e8a375a
Parent:
19:4b147d8f9164
Child:
21:8524d815c587

File content as of revision 20:b0281e8a375a:

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


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