:c
This commit is contained in:
parent
8eb18c12d2
commit
fd6476cd6e
10 changed files with 258 additions and 4 deletions
|
|
@ -3,9 +3,9 @@ project(hoymilesClient VERSION 0.1.0 LANGUAGES C CXX)
|
||||||
|
|
||||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
|
||||||
include_directories(inc inc/libmodbus inc/hoymiles inc/hoymiles/portParameters)
|
include_directories(inc inc/libmodbus inc/hoymiles inc/hoymiles/portParameters inc/hoymiles/sunspecParameters)
|
||||||
|
|
||||||
file(GLOB SOURCES src/*.cpp src/libmodbus/*.c src/hoymiles/*.cpp src/hoymiles/portParameters/*.cpp)
|
file(GLOB SOURCES src/*.cpp src/libmodbus/*.c src/hoymiles/*.cpp src/hoymiles/portParameters/*.cpp src/hoymiles/sunspecParameters/*.cpp)
|
||||||
|
|
||||||
add_executable(hoymilesClient_exec ${SOURCES})
|
add_executable(hoymilesClient_exec ${SOURCES})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,14 @@
|
||||||
|
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
|
#include "sunspec.h"
|
||||||
|
|
||||||
class Microinverter {
|
class Microinverter {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<class modbus> modbus;
|
std::shared_ptr<class modbus> modbus;
|
||||||
|
|
||||||
|
Sunspec sunspec;
|
||||||
|
|
||||||
int startAddress;
|
int startAddress;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
37
inc/hoymiles/sunspec.h
Normal file
37
inc/hoymiles/sunspec.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef SUNSPEC_H
|
||||||
|
#define SUNSPEC_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "modbus.h"
|
||||||
|
#include "sunspecParametersGeneric.h"
|
||||||
|
|
||||||
|
class Sunspec {
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<class modbus> modbus;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<SunspecParameter>> parameters;
|
||||||
|
|
||||||
|
std::string manufacturer;
|
||||||
|
std::string model;
|
||||||
|
std::string version;
|
||||||
|
|
||||||
|
std::string serialNumber;
|
||||||
|
uint16_t deviceAddress;
|
||||||
|
|
||||||
|
int sunspecAddress;
|
||||||
|
|
||||||
|
void setValues();
|
||||||
|
|
||||||
|
void populateParameters();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Sunspec(int address, std::shared_ptr<class modbus> modbus);
|
||||||
|
|
||||||
|
uint16_t getAddress();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
15
inc/hoymiles/sunspecParameters/sunspecParameters.h
Normal file
15
inc/hoymiles/sunspecParameters/sunspecParameters.h
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef SUNSPEC_PARAMETERS_H
|
||||||
|
#define SUNSPEC_PARAMETERS_H
|
||||||
|
|
||||||
|
#include "sunspecParametersGeneric.h"
|
||||||
|
|
||||||
|
class SunspecParameterManufacturer : public SunspecParameterString32 {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
SunspecParameterManufacturer();
|
||||||
|
|
||||||
|
void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
124
inc/hoymiles/sunspecParameters/sunspecParametersGeneric.h
Normal file
124
inc/hoymiles/sunspecParameters/sunspecParametersGeneric.h
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
#ifndef SUNSPEC_PARAMETERS_GENERIC_H
|
||||||
|
#define SUNSPEC_PARAMETERS_GENERIC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class SunspecParameter {
|
||||||
|
protected:
|
||||||
|
std::string name;
|
||||||
|
int registerAddressOffset;
|
||||||
|
int registerSize;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SunspecParameter(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
virtual ~SunspecParameter();
|
||||||
|
|
||||||
|
enum SunspecValueType { uint32, uint16, string32, string16, sunssf, int16, acc32, float32, enum16 };
|
||||||
|
|
||||||
|
union SunspecValue {
|
||||||
|
uint32_t u32;
|
||||||
|
uint16_t u16;
|
||||||
|
uint16_t ssf;
|
||||||
|
int i16;
|
||||||
|
uint16_t a32;
|
||||||
|
float f;
|
||||||
|
uint16_t e16;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SunspecValueType valueType;
|
||||||
|
SunspecValue value;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
|
||||||
|
std::pair<SunspecValue, SunspecValueType> getValue();
|
||||||
|
};
|
||||||
|
|
||||||
|
// class SunspecParameterUint32 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterUint32(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterUint16 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterUint16(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
class SunspecParameterString32 : public SunspecParameter {
|
||||||
|
protected:
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
};
|
||||||
|
|
||||||
|
// class SunspecParameterString16 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
// std::string value;
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterString16(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterSunssf : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterSunssf(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterInt16 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterInt16(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterAcc32 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterAcc32(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterFloat32 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterFloat32(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// class SunspecParameterEnum16 : public SunspecParameter {
|
||||||
|
// protected:
|
||||||
|
|
||||||
|
// public:
|
||||||
|
// SunspecParameterEnum16(std::string name, int registerAddressOffset, int registerSize);
|
||||||
|
|
||||||
|
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
// };
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
#include "microinverter.h"
|
#include "microinverter.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
|
#include "sunspec.h"
|
||||||
|
|
||||||
Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, int startAddress, long long serialNumber) {
|
Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, int startAddress, long long serialNumber) : sunspec(40000, modbus) {
|
||||||
this->modbus = modbus;
|
this->modbus = modbus;
|
||||||
this->startAddress = startAddress;
|
this->startAddress = startAddress;
|
||||||
this->serialNumber = serialNumber;
|
this->serialNumber = serialNumber;
|
||||||
|
|
|
||||||
34
src/hoymiles/sunspec.cpp
Normal file
34
src/hoymiles/sunspec.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include <string>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "sunspec.h"
|
||||||
|
#include "modbus.h"
|
||||||
|
#include "sunspecParameters.h"
|
||||||
|
|
||||||
|
Sunspec::Sunspec(int address, std::shared_ptr<class modbus> modbus) {
|
||||||
|
this->modbus = modbus;
|
||||||
|
this->sunspecAddress = address;
|
||||||
|
|
||||||
|
this->populateParameters();
|
||||||
|
|
||||||
|
this->setValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sunspec::setValues() {
|
||||||
|
uint16_t registers[70];
|
||||||
|
|
||||||
|
int registerCount;
|
||||||
|
registerCount = this->modbus.get()->modbus_read_holding_registers(this->sunspecAddress, 70, registers);
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||||
|
while(parametersIterator != this->parameters.end()) {
|
||||||
|
parametersIterator->get()->setValueFromRegisters(registers, 0);
|
||||||
|
parametersIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sunspec::populateParameters() {
|
||||||
|
SunspecParameterManufacturer manufacturer{};
|
||||||
|
this->parameters.push_back(std::make_shared<SunspecParameterManufacturer>(manufacturer));
|
||||||
|
}
|
||||||
23
src/hoymiles/sunspecParameters/sunspecParameters.cpp
Normal file
23
src/hoymiles/sunspecParameters/sunspecParameters.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "sunspecParameters.h"
|
||||||
|
|
||||||
|
SunspecParameterManufacturer::SunspecParameterManufacturer() : SunspecParameterString32("manufacturer", 4, 16) {
|
||||||
|
this->valueType = string32;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SunspecParameterManufacturer::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||||
|
std::string readValue;
|
||||||
|
|
||||||
|
for(int i{0}; i<this->registerSize; i++) {
|
||||||
|
std::stringstream readValueStringStream;
|
||||||
|
readValueStringStream << (registers[addressOffset + this->registerAddressOffset + i] >> 8) << " ";
|
||||||
|
readValueStringStream << (registers[addressOffset + this->registerAddressOffset + i] & 0x00FF) << " ";
|
||||||
|
|
||||||
|
readValue.append(readValueStringStream.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
this->value = readValue;
|
||||||
|
}
|
||||||
17
src/hoymiles/sunspecParameters/sunspecParametersGeneric.cpp
Normal file
17
src/hoymiles/sunspecParameters/sunspecParametersGeneric.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "sunspecParametersGeneric.h"
|
||||||
|
|
||||||
|
SunspecParameter::~SunspecParameter() {}
|
||||||
|
|
||||||
|
SunspecParameter::SunspecParameter(std::string name, int registerAddressOffset, int registerSize) {
|
||||||
|
this->name = name;
|
||||||
|
this->registerAddressOffset = registerAddressOffset;
|
||||||
|
this->registerSize = registerSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SunspecParameter::setValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||||
|
|
||||||
|
std::pair<SunspecParameter::SunspecValue, SunspecParameter::SunspecValueType> SunspecParameter::getValue() {}
|
||||||
|
|
||||||
|
SunspecParameterString32::SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize) : SunspecParameter(name, registerAddressOffset, registerSize) {}
|
||||||
|
|
||||||
|
void SunspecParameterString32::setValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||||
|
|
@ -19,7 +19,7 @@ int main(int argc, char **argv) {
|
||||||
signal(SIGTERM, sigHandler);
|
signal(SIGTERM, sigHandler);
|
||||||
signal(SIGABRT, sigHandler);
|
signal(SIGABRT, sigHandler);
|
||||||
|
|
||||||
std::string version{"v2.0beta"};
|
std::string version{"v2.0"};
|
||||||
std::cout << version << std::endl;
|
std::cout << version << std::endl;
|
||||||
|
|
||||||
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue