Moved to updated library
This commit is contained in:
parent
381dcbdc57
commit
098d944793
10 changed files with 15 additions and 26 deletions
|
|
@ -3,17 +3,10 @@ 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(CTest)
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
include_directories(inc inc/libmodbus inc/hoymiles inc/hoymiles/portParameters)
|
include_directories(inc inc/libmodbus inc/hoymiles inc/hoymiles/portParameters)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
add_executable(hoymilesClient_exec ${SOURCES})
|
add_executable(hoymilesClient_exec ${SOURCES})
|
||||||
|
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/inc/libmodbus/config.h)
|
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/inc/libmodbus/config.h)
|
||||||
|
|
||||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
|
||||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
|
||||||
include(CPack)
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,15 @@ class Microinverter {
|
||||||
private:
|
private:
|
||||||
// std::shared_ptr<modbus_t*> modbus_context;
|
// std::shared_ptr<modbus_t*> modbus_context;
|
||||||
|
|
||||||
std::shared_ptr<modbus> modbus;
|
std::shared_ptr<class modbus> modbus;
|
||||||
|
|
||||||
// std::mutex *modbus_context_mutex;
|
// std::mutex *modbus_context_mutex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Microinverter(class modbus modbus, long serialNumber);
|
Microinverter(
|
||||||
|
std::shared_ptr<class modbus> modbus, long serialNumber);
|
||||||
|
|
||||||
long serialNumber;
|
long serialNumber;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ void Dtu::populateMicroinverters() {
|
||||||
getMicroinverterBySerialNumber.second->ports.push_back(port);
|
getMicroinverterBySerialNumber.second->ports.push_back(port);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Microinverter microinverter{ this->modbus_context, serialNumber };
|
Microinverter microinverter{ this->modbus, serialNumber };
|
||||||
this->microinverters.push_back(microinverter);
|
this->microinverters.push_back(microinverter);
|
||||||
this->microinverters.back().ports.push_back(port);
|
this->microinverters.back().ports.push_back(port);
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ void Dtu::populateMicroinverters() {
|
||||||
portStartAddress += 0x0028;
|
portStartAddress += 0x0028;
|
||||||
|
|
||||||
// this->modbus_context_mutex.lock();
|
// this->modbus_context_mutex.lock();
|
||||||
registerCount = modbus_read_registers(*this->modbus_context.get(), portStartAddress + 0x0021, 1, readArray);
|
registerCount = this->modbus.get()->modbus_read_holding_registers(portStartAddress + 0x0021, 1, readArray);
|
||||||
// this->modbus_context_mutex.unlock();
|
// this->modbus_context_mutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,8 @@
|
||||||
#include "microinverter.h"
|
#include "microinverter.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
|
|
||||||
struct _modbus;
|
Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, long serialNumber) {
|
||||||
typedef _modbus modbus_t;
|
this->modbus = modbus;
|
||||||
|
|
||||||
Microinverter::Microinverter(std::shared_ptr<modbus_t*> modbus_context, long serialNumber) {
|
|
||||||
this->modbus_context = modbus_context;
|
|
||||||
// this->modbus_context_mutex = modbus_context_mutex;
|
// this->modbus_context_mutex = modbus_context_mutex;
|
||||||
|
|
||||||
this->serialNumber = serialNumber;
|
this->serialNumber = serialNumber;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
#include "portParameters.h"
|
#include "portParameters.h"
|
||||||
|
|
||||||
Port::Port(std::shared_ptr<modbus_t*> modbus_context, uint16_t portStartAddress) {
|
Port::Port(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress) {
|
||||||
this->modbus_context = modbus_context;
|
this->modbus = modbus;
|
||||||
// this->modbus_context_mutex = modbus_context_mutex;
|
// this->modbus_context_mutex = modbus_context_mutex;
|
||||||
|
|
||||||
this->portStartAddress = portStartAddress;
|
this->portStartAddress = portStartAddress;
|
||||||
|
|
@ -71,7 +71,7 @@ void Port::fixCurrent() {
|
||||||
void Port::updateParameters() {
|
void Port::updateParameters() {
|
||||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()};
|
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()};
|
||||||
while (parametersIterator != this->parameters.end()) {
|
while (parametersIterator != this->parameters.end()) {
|
||||||
parametersIterator->get()->updateValue(this->modbus_context, this->portStartAddress);
|
parametersIterator->get()->updateValue(this->modbus, this->portStartAddress);
|
||||||
parametersIterator++;
|
parametersIterator++;
|
||||||
}
|
}
|
||||||
this->fixCurrent();
|
this->fixCurrent();
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@
|
||||||
|
|
||||||
#include "portParametersGeneric.h"
|
#include "portParametersGeneric.h"
|
||||||
|
|
||||||
struct _modbus;
|
|
||||||
typedef _modbus modbus_t;
|
|
||||||
|
|
||||||
PortParameter::PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize) {
|
PortParameter::PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
|
|
||||||
|
|
@ -32,18 +29,19 @@ std::string PortParameter::getOutputValue() {
|
||||||
return "yeet";
|
return "yeet";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortParameter::updateValue(std::shared_ptr<modbus_t*> modbus_context, uint16_t portStartAddress) {
|
void PortParameter::updateValue(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress) {
|
||||||
uint16_t readArray[this->registerSize];
|
uint16_t readArray[this->registerSize];
|
||||||
int registerCount;
|
int registerCount;
|
||||||
|
|
||||||
// modbus_context_mutex->lock();
|
// modbus_context_mutex->lock();
|
||||||
registerCount = modbus_read_registers(*modbus_context.get(), portStartAddress + this->parameterAddressOffset, this->registerSize, readArray);
|
registerCount = modbus.get()->modbus_read_holding_registers(portStartAddress + this->parameterAddressOffset, this->registerSize, readArray);
|
||||||
// modbus_context_mutex->unlock();
|
// modbus_context_mutex->unlock();
|
||||||
|
|
||||||
if(registerCount == -1){
|
if(registerCount != 0){
|
||||||
this->age++;
|
this->age++;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
registerCount = this->registerSize;
|
||||||
this->setValueFromRegisters(readArray, registerCount);
|
this->setValueFromRegisters(readArray, registerCount);
|
||||||
this->age = 0;
|
this->age = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue