Skip to content
Snippets Groups Projects
Measurement.hpp 2.1 KiB
Newer Older
//
// Created by cynthya on 10/6/22.
//

#ifndef CLIENT_MEASUREMENTDATA_HPP
#define CLIENT_MEASUREMENTDATA_HPP

#include "ArduinoJson.h"
#include "SensorProtocol.hpp"
#include "SensorInformation.hpp"
#include <list>
#include <optional>
#include <string>
#include <utility>
#include "ErrorTypes.h"
class Measurement {
    Measurement(double value, int channel, int i2cAddress, MeasurementType measurementType,
                ErrorType errorType)
            : value(value), measurementType(measurementType), channel(channel),
              i2cAddress(i2cAddress), errorType(errorType) {
    }

    Measurement(double value, MeasurementType measurementType)
            : value(value), measurementType(measurementType) {
        channel = NO_CHANNEL;
        i2cAddress = NO_I2C_ADDRESS;
        errorType = ErrorType::DATA_OK;
    }

    Measurement() {
        value = ERROR_VALUE;
        measurementType = MeasurementType::NULL_MEASUREMENT;
        channel = NO_CHANNEL;
        i2cAddress = NO_I2C_ADDRESS;
        errorType = ErrorType::NULL_MESSAGE;
    }

    [[nodiscard]] double getValue() const { return value; }

    [[nodiscard]] const MeasurementType &
    getMeasurementType() const { return measurementType; }

    [[nodiscard]] std::string getMeasurementTypeString() const {
        return MeasurementTypes::measurementTypeToString(measurementType);
    }

    [[nodiscard]] const int &getChannel() const { return channel; }

    [[nodiscard]] const ErrorType &getErrorType() const { return errorType; }

    [[nodiscard]] std::string getErrorTypeString() const {
        return ErrorTypes::errorTypeToString(errorType);
    }

    void setErrorType(ErrorType type) {
        errorType = type;
    }

    [[nodiscard]] const int &
    getI2CAddress() const { return i2cAddress; }


private:
    double value;
    MeasurementType measurementType;
    ErrorType errorType;
    // TODO: is it possible for a sensor to have both a channel and an i2cAddress?
    int channel = NO_CHANNEL;
    int i2cAddress = NO_I2C_ADDRESS;