Skip to content

Commit

Permalink
Adjustable command reply sizes (#22)
Browse files Browse the repository at this point in the history
This commit add a possibility to change reply sizes for specific commands:
QPIRI, QPIWS, QMOD, QPIGS
  • Loading branch information
manio authored Aug 28, 2023
2 parents 59298e5 + 676ced2 commit f6f5849
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
15 changes: 10 additions & 5 deletions inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

#include <termios.h>

cInverter::cInverter(std::string devicename) {
cInverter::cInverter(std::string devicename, int qpiri, int qpiws, int qmod, int qpigs) {
device = devicename;
status1[0] = 0;
status2[0] = 0;
warnings[0] = 0;
mode = 0;
qpiri = qpiri;
qpiws = qpiws;
qmod = qmod;
qpigs = qpigs;
}

string *cInverter::GetQpigsStatus() {
Expand Down Expand Up @@ -152,21 +156,22 @@ bool cInverter::query(const char *cmd, int replysize) {

void cInverter::poll() {
int n,j;
extern const int qpiri, qpiws, qmod, qpigs;
extern const bool runOnce;

while (true) {

// Reading mode
if (!ups_qmod_changed) {
if (query("QMOD", 5)) {
if (query("QMOD", qmod)) {
SetMode(buf[1]);
ups_qmod_changed = true;
}
}

// reading status (QPIGS)
if (!ups_qpigs_changed) {
if (query("QPIGS", 110)) {
if (query("QPIGS", qpigs)) {
m.lock();
strcpy(status1, (const char*)buf+1);
m.unlock();
Expand All @@ -176,7 +181,7 @@ void cInverter::poll() {

// Reading QPIRI status
if (!ups_qpiri_changed) {
if (query("QPIRI", 97)) {
if (query("QPIRI", qpiri)) {
m.lock();
strcpy(status2, (const char*)buf+1);
m.unlock();
Expand All @@ -186,7 +191,7 @@ void cInverter::poll() {

// Get any device warnings...
if (!ups_qpiws_changed) {
if (query("QPIWS", 36)) {
if (query("QPIWS", qpiws)) {
m.lock();
strcpy(warnings, (const char*)buf+1);
m.unlock();
Expand Down
2 changes: 1 addition & 1 deletion inverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class cInverter {
uint16_t cal_crc_half(uint8_t *pin, uint8_t len);

public:
cInverter(std::string devicename);
cInverter(std::string devicename, int qpiri, int qpiws, int qmod, int qpigs);
void poll();
void runMultiThread() {
t1 = std::thread(&cInverter::poll, this);
Expand Down
16 changes: 13 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ string devicename;
int runinterval;
float ampfactor;
float wattfactor;
int qpiri = 98;
int qpiws = 36;
int qmod = 5;
int qpigs = 110;

// ---------------------------------------

Expand Down Expand Up @@ -73,7 +77,6 @@ void getSettingsFile(string filename) {
string fileline, linepart1, linepart2;
ifstream infile;
infile.open(filename);

while(!infile.eof()) {
getline(infile, fileline);
size_t firstpos = fileline.find("#");
Expand All @@ -82,7 +85,6 @@ void getSettingsFile(string filename) {
size_t delimiter = fileline.find("=");
linepart1 = fileline.substr(0, delimiter);
linepart2 = fileline.substr(delimiter+1, string::npos - delimiter);

if(linepart1 == "device")
devicename = linepart2;
else if(linepart1 == "run_interval")
Expand All @@ -91,6 +93,14 @@ void getSettingsFile(string filename) {
attemptAddSetting(&ampfactor, linepart2);
else if(linepart1 == "watt_factor")
attemptAddSetting(&wattfactor, linepart2);
else if(linepart1 == "qpiri")
attemptAddSetting(&qpiri, linepart2);
else if(linepart1 == "qpiws")
attemptAddSetting(&qpiws, linepart2);
else if(linepart1 == "qmod")
attemptAddSetting(&qmod, linepart2);
else if(linepart1 == "qpigs")
attemptAddSetting(&qpigs, linepart2);
else
continue;
}
Expand Down Expand Up @@ -176,7 +186,7 @@ int main(int argc, char* argv[]) {
while (flock(fd, LOCK_EX)) sleep(1);

bool ups_status_changed(false);
ups = new cInverter(devicename);
ups = new cInverter(devicename, qpiri, qpiws, qmod, qpigs);

// Logic to send 'raw commands' to the inverter..
if (!rawcmd.empty()) {
Expand Down

0 comments on commit f6f5849

Please sign in to comment.