From 46c308bc1406ccf7415698ca24e69865022edaee Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 29 Nov 2021 01:08:49 +0300 Subject: p18: fix get-p-status --- src/p18/response.cc | 22 +++++++++++++++------- src/p18/response.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/p18/response.cc b/src/p18/response.cc index 8236ad0..f361dee 100644 --- a/src/p18/response.cc +++ b/src/p18/response.cc @@ -58,22 +58,25 @@ size_t GetResponse::getDataSize() const { return rawSize_ - 5; } -std::vector GetResponse::getList(std::vector itemLengths) const { +std::vector GetResponse::getList(std::vector itemLengths, int expectAtLeast) const { std::string buf(getData(), getDataSize()); auto list = ::split(buf, ','); + if (expectAtLeast == -1) + expectAtLeast = (int)itemLengths.size(); + if (!itemLengths.empty()) { // check list length - if (list.size() < itemLengths.size()) { + if (list.size() < expectAtLeast) { std::ostringstream error; error << "while parsing " << demangle_type_name(typeid(*this).name()); - error << ": list is expected to be " << itemLengths.size() << " items long, "; + error << ": list is expected to be " << expectAtLeast << " items long, "; error << "got only " << list.size() << " items"; throw ParseError(error.str()); } // check each item's length - for (int i = 0; i < itemLengths.size(); i++) { + for (int i = 0; i < list.size(); i++) { if (list[i].size() != itemLengths[i]) { std::ostringstream error; error << "while parsing " << demangle_type_name(typeid(*this).name()); @@ -682,13 +685,17 @@ void ParallelGeneralStatus::unpack() { 4, // TTTT 4, // UUUU 1, // V + // FIXME: marked red in the docs 1, // W + // FIXME: marked red in the docs 1, // X 1, // Y 1, // Z 1, // a - 3, // bbb. Note: this one is marked in red in the doc. I don't know what that means. - }); + 3, // bbb. Note: this one is marked in red in the doc. Apparently it means + // that it may be missing on some models, see + // https://github.com/gch1p/inverter-tools/issues/1#issuecomment-981158688 + }, 28); parallel_id_connection_status = static_cast(stou(list[0])); work_mode = static_cast(stou(list[1])); @@ -718,7 +725,8 @@ void ParallelGeneralStatus::unpack() { battery_power_direction = static_cast(stou(list[25])); dc_ac_power_direction = static_cast(stou(list[26])); line_power_direction = static_cast(stou(list[27])); - max_temp = stou(list[28]); + if (list.size() >= 29) + max_temp = stou(list[28]); } formattable_ptr ParallelGeneralStatus::format(formatter::Format format) { diff --git a/src/p18/response.h b/src/p18/response.h index be6eece..b14c9b0 100644 --- a/src/p18/response.h +++ b/src/p18/response.h @@ -145,7 +145,7 @@ class GetResponse : public BaseResponse { protected: const char* getData() const; size_t getDataSize() const; - std::vector getList(std::vector itemLengths) const; + std::vector getList(std::vector itemLengths, int expectAtLeast = -1) const; public: using BaseResponse::BaseResponse; -- cgit v1.2.3