Starting work on implementing structures
This commit is contained in:
parent
974ae853b9
commit
670ca56b0b
3 changed files with 72 additions and 10 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
#ifndef HOYMILES_H
|
#ifndef HOYMILES_H
|
||||||
#define HOYMILES_H
|
#define HOYMILES_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct _modbus;
|
struct _modbus;
|
||||||
typedef _modbus modbus_t;
|
typedef _modbus modbus_t;
|
||||||
|
|
||||||
|
|
@ -8,12 +11,47 @@ class Dtu{
|
||||||
private:
|
private:
|
||||||
modbus_t *modbus_t;
|
modbus_t *modbus_t;
|
||||||
|
|
||||||
|
std::vector<Microinverter> microinverters;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dtu(const char *ip_address, int port);
|
Dtu(const char *ip_address, int port);
|
||||||
|
|
||||||
void readTest();
|
void readTest(uint16_t address, int registers);
|
||||||
|
|
||||||
~Dtu();
|
~Dtu();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Microinverter{
|
||||||
|
private:
|
||||||
|
uint16_t readArray[33];
|
||||||
|
uint16_t address;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const int serialNumber;
|
||||||
|
std::pair<int, int> portNumber;
|
||||||
|
|
||||||
|
std::pair<float, int> plantVoltage;
|
||||||
|
std::pair<float, int> plantCurrent;
|
||||||
|
|
||||||
|
std::pair<float, int> gridVoltage;
|
||||||
|
std::pair<float, int> gridFrequency;
|
||||||
|
|
||||||
|
std::pair<float, int> plantPower;
|
||||||
|
|
||||||
|
std::pair<long, int> todayProduction;
|
||||||
|
std::pair<long, int> totalProduction;
|
||||||
|
|
||||||
|
std::pair<int, int> temperature;
|
||||||
|
|
||||||
|
std::pair<int, int> operatingStatus;
|
||||||
|
std::pair<int, int> alarmCode;
|
||||||
|
std::pair<int, int> alarmCount;
|
||||||
|
|
||||||
|
std::pair<int, int> linkStatus;
|
||||||
|
|
||||||
|
Microinverter(uint16_t address);
|
||||||
|
|
||||||
|
void updateValues();
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,16 +1,31 @@
|
||||||
#include "hoymiles.h"
|
#include "hoymiles.h"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Dtu::Dtu(const char *ip_address, int port) {
|
Dtu::Dtu(const char *ip_address, int port) {
|
||||||
this->modbus_t = modbus_new_tcp(ip_address, port);
|
this->modbus_t = modbus_new_tcp(ip_address, port);
|
||||||
modbus_connect(this->modbus_t);
|
if(modbus_connect(this->modbus_t) == -1){
|
||||||
|
std::cerr << "conn_error";
|
||||||
|
modbus_free(this->modbus_t);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dtu::readTest(){
|
void Dtu::readTest(uint16_t address, int registers) {
|
||||||
uint16_t tempArray[32];
|
uint16_t readArray[registers];
|
||||||
modbus_read_registers(this->modbus_t, 0x13ef, 1, tempArray);
|
int registerCount;
|
||||||
|
registerCount = modbus_read_registers(this->modbus_t, address, registers, readArray);
|
||||||
|
if(registerCount == -1){
|
||||||
|
std::cerr << "read_error";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i{0}; i < registerCount; i++) {
|
||||||
|
std::clog << readArray[i] << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dtu::~Dtu() {
|
Dtu::~Dtu() {
|
||||||
delete this->modbus_t;
|
modbus_close(this->modbus_t);
|
||||||
|
modbus_free(this->modbus_t);
|
||||||
}
|
}
|
||||||
11
src/main.cpp
11
src/main.cpp
|
|
@ -1,6 +1,9 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "hoymiles.h"
|
#include "hoymiles.h"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
|
|
@ -10,7 +13,13 @@ int main(){
|
||||||
int port {502};
|
int port {502};
|
||||||
|
|
||||||
Dtu dtu {ip_address.c_str(), port};
|
Dtu dtu {ip_address.c_str(), port};
|
||||||
dtu.readTest();
|
|
||||||
|
bool buttonPressed{false};
|
||||||
|
for(int i{0}; i<10; i++){
|
||||||
|
dtu.readTest(0x1034, 2);
|
||||||
|
std::clog << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue