Add mapping logic and serialization for writing

This commit is contained in:
2022-09-20 23:17:40 +02:00
parent df1c8f3821
commit 8ceb762fe1
68 changed files with 49901 additions and 14 deletions

View File

@@ -0,0 +1,13 @@
#ifndef SERIALIZABLE_H_
#define SERIALIZABLE_H_
#include <nlohmann/json.hpp>
using json = nlohmann::json;
class Serializable {
public:
virtual json toJson() const = 0;
};
#endif // SERIALIZABLE_H_

22
app/include/Serializer.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef SERIALIZER_H_
#define SERIALIZER_H_
#include <memory>
#include <vector>
#include <nlohmann/json.hpp>
#include <fan/Fan.h>
using json = nlohmann::json;
class Serializer {
public:
Serializer();
void Serialize(std::vector<std::shared_ptr<Fan>> fans);
private:
void WriteJson(json o);
};
#endif // SERIALIZER_H_

View File

@@ -1,7 +1,9 @@
#ifndef FAN_H_
#define FAN_H_
class Fan {
#include <Serializable.h>
class Fan : public Serializable {
public:
virtual void pwm(int percent) = 0;
virtual int rpm() = 0;

View File

@@ -1,6 +1,7 @@
#ifndef HWMONFAN_H_
#define HWMONFAN_H_
#include <boost/json/object.hpp>
#include <memory>
#include <fan/Fan.h>
@@ -15,6 +16,8 @@ public:
void pwm(int percent) override;
int rpm() override;
json toJson() const override;
private:
std::shared_ptr<PwmControl> mPwmControl;
std::shared_ptr<Sensor> mRpmSensor;

View File

@@ -1,26 +1,31 @@
#ifndef PWMCONTROL_H_
#define PWMCONTROL_H_
#include <boost/json/object.hpp>
#include <string>
#include <Printable.h>
#include <Serializable.h>
enum class PWM_CONTROL_PROPERTY { CONTROL, ENABLE, MODE };
enum class PWM_ENABLE { FULL_SPEED = 0, MANUAL_CONTROL };
enum class PWM_MODE { DC = 0, PWM };
class PwmControl : public Printable {
class PwmControl : public Printable, public Serializable {
public:
PwmControl(std::string controlPath);
~PwmControl();
void pwm(int percent);
int pwm();
void enableManualControl();
void reset();
void EnableManualControl();
void Reset();
const std::string toString() const override;
json toJson() const override;
private:
int readValue(std::string path);

View File

@@ -13,6 +13,8 @@ public:
int value() override;
const std::string toString() const override;
json toJson() const override;
private:
const sensors_chip_name *mChipName;
const sensors_feature *mFeature;

View File

@@ -11,6 +11,8 @@ public:
int value() override;
const std::string toString() const override;
json toJson() const override;
};
#endif // NVIDIASENSOR_H_

View File

@@ -2,8 +2,9 @@
#define SENSOR_H_
#include <Printable.h>
#include <Serializable.h>
class Sensor : public Printable {
class Sensor : public Printable, public Serializable {
public:
// Read the current value
virtual int value() = 0;