Newer
Older
#include <ArduinoJson.h>

Zoe Pfister
committed
#include "MeasurementData.hpp"

Zoe Pfister
committed
#include "SensorInformation.hpp"

Zoe Pfister
committed
#include <list>

Zoe Pfister
committed
#include <optional>

Zoe Pfister
committed
#include <string>
#include <utility>
#include <ErrorTypes.h>

Zoe Pfister
committed
// having the data be a struct of basic types makes sending easier,
// otherwise we would have to serialize the data before sending

Zoe Pfister
committed
class ClientDataPackage {

Zoe Michaela Dietmar Pfister
committed
private:
MeasurementData measurementData;
SensorInformation sensorInformation;
ErrorType errorType;

Zoe Michaela Dietmar Pfister
committed
unsigned long timestamp; // maybe make this array

Zoe Michaela Dietmar Pfister
committed
public:
ClientDataPackage(MeasurementData value,
SensorInformation sensorInformation,
ErrorType errorType,

Zoe Michaela Dietmar Pfister
committed
unsigned long timestamp)
: measurementData(value),
sensorInformation(sensorInformation),
timestamp(timestamp),
errorType(errorType) {
}
[[nodiscard]] ErrorType getErrorType() const {
return errorType;
}
void setErrorType(ErrorType error) {
ClientDataPackage::errorType = error;

Zoe Michaela Dietmar Pfister
committed
}

Zoe Michaela Dietmar Pfister
committed
[[nodiscard]] const MeasurementData &
getMeasurementData() const { return measurementData; }

Zoe Michaela Dietmar Pfister
committed
[[nodiscard]] const SensorInformation &
getSensorInformation() const { return sensorInformation; }

Zoe Michaela Dietmar Pfister
committed
[[nodiscard]] unsigned long getTimestamp() const { return timestamp; }

Zoe Michaela Dietmar Pfister
committed
[[nodiscard]] std::string getDataPackageAsMinifiedJsonString() const {
StaticJsonDocument<250> document; // 250 byte is the max send size of espnow

Zoe Michaela Dietmar Pfister
committed
document["hardwareName"] = sensorInformation.getHardwareNameString();
document["timestamp"] = timestamp;
document["sensorProtocol"] = sensorInformation.getProtocolString();
document["value"] = measurementData.getValue();

Zoe Michaela Dietmar Pfister
committed
document["channel"] = measurementData.getChannel();
document["i2cAddress"] = measurementData.getI2CAddress();

Zoe Michaela Dietmar Pfister
committed
document["measurementType"] = measurementData.getMeasurementTypeString();

Zoe Michaela Dietmar Pfister
committed
std::string jsonString;
serializeJson(document, jsonString);
return jsonString;
}
ClientDataPackage() : measurementData(MeasurementData(ERROR_VALUE,
MeasurementType::TEMPERATURE)),
sensorInformation(SensorInformation(HardwareName::NONE,
SensorProtocol::NULL_PROTOCOL)),
timestamp(0),
errorType(ErrorType::NO_DATA) {}