From 610bf317a8bdbfd7783fe6c86f5ff28ec0945ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Sat, 9 Apr 2022 11:54:16 +0300 Subject: [PATCH] inverter-cli: Add more commands for -r flag Accept the QPI, QID, QVFW, QVFW2, QFLAG, QBOOT, and QOPM commands. https://github.com/ned-kelly/docker-voltronic-homeassistant/pull/76 --- sources/inverter-cli/inverter.cpp | 4 ++-- sources/inverter-cli/inverter.h | 2 +- sources/inverter-cli/main.cpp | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/inverter-cli/inverter.cpp b/sources/inverter-cli/inverter.cpp index d7e6f53..2b4b6ee 100644 --- a/sources/inverter-cli/inverter.cpp +++ b/sources/inverter-cli/inverter.cpp @@ -205,9 +205,9 @@ void cInverter::poll() { } } -void cInverter::ExecuteCmd(const string cmd) { +void cInverter::ExecuteCmd(const string cmd, int replylen) { // Sending any command raw - if (query(cmd.data(), 7)) { + if (query(cmd.data(), replylen)) { m.lock(); strcpy(status2, (const char*)buf+1); m.unlock(); diff --git a/sources/inverter-cli/inverter.h b/sources/inverter-cli/inverter.h index 3501b6b..6b47c62 100644 --- a/sources/inverter-cli/inverter.h +++ b/sources/inverter-cli/inverter.h @@ -35,7 +35,7 @@ class cInverter { string *GetWarnings(); int GetMode(); - void ExecuteCmd(const std::string cmd); + void ExecuteCmd(const std::string cmd, int); }; #endif // ___INVERTER_H diff --git a/sources/inverter-cli/main.cpp b/sources/inverter-cli/main.cpp index 2c7cbbb..40ac9e2 100644 --- a/sources/inverter-cli/main.cpp +++ b/sources/inverter-cli/main.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -177,7 +178,23 @@ int main(int argc, char* argv[]) { // Logic to send 'raw commands' to the inverter.. if (!rawcmd.empty()) { - ups->ExecuteCmd(rawcmd); + int replylen; + if (!strcmp(rawcmd.c_str(), "QPI")) + replylen = 8; + else if (!strcmp(rawcmd.c_str(), "QID")) + replylen = 18; + else if (!strcmp(rawcmd.c_str(), "QVFW")) + replylen = 18; + else if (!strcmp(rawcmd.c_str(), "QVFW2")) + replylen = 19; + else if (!strcmp(rawcmd.c_str(), "QFLAG")) + replylen = 15; + else if (!strcmp(rawcmd.c_str(), "QBOOT")) + replylen = 5; + else if (!strcmp(rawcmd.c_str(), "QOPM")) + replylen = 6; + else replylen = 7; + ups->ExecuteCmd(rawcmd, replylen); // We're piggybacking off the qpri status response... printf("Reply: %s\n", ups->GetQpiriStatus()->c_str()); exit(0);