From 90711ddd76d3306e91accecda0bf6bfcd750db4d Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 16 May 2024 19:58:20 +0200 Subject: [PATCH] Code Refactoring: Use internal inverter instance in handleResponse method --- .../src/commands/ActivePowerControlCommand.cpp | 14 +++++++------- .../src/commands/ActivePowerControlCommand.h | 2 +- lib/Hoymiles/src/commands/AlarmDataCommand.cpp | 16 ++++++++-------- lib/Hoymiles/src/commands/AlarmDataCommand.h | 2 +- .../src/commands/ChannelChangeCommand.cpp | 2 +- .../src/commands/ChannelChangeCommand.h | 2 +- lib/Hoymiles/src/commands/CommandAbstract.h | 2 +- .../src/commands/DevControlCommand.cpp | 2 +- lib/Hoymiles/src/commands/DevControlCommand.h | 2 +- .../src/commands/DevInfoAllCommand.cpp | 14 +++++++------- lib/Hoymiles/src/commands/DevInfoAllCommand.h | 2 +- .../src/commands/DevInfoSimpleCommand.cpp | 14 +++++++------- .../src/commands/DevInfoSimpleCommand.h | 2 +- .../src/commands/GridOnProFilePara.cpp | 14 +++++++------- lib/Hoymiles/src/commands/GridOnProFilePara.h | 2 +- lib/Hoymiles/src/commands/MultiDataCommand.cpp | 2 +- lib/Hoymiles/src/commands/MultiDataCommand.h | 2 +- .../src/commands/PowerControlCommand.cpp | 8 ++++---- .../src/commands/PowerControlCommand.h | 2 +- .../src/commands/RealTimeRunDataCommand.cpp | 18 +++++++++--------- .../src/commands/RealTimeRunDataCommand.h | 2 +- .../src/commands/RequestFrameCommand.cpp | 2 +- .../src/commands/RequestFrameCommand.h | 2 +- .../src/commands/SystemConfigParaCommand.cpp | 18 +++++++++--------- .../src/commands/SystemConfigParaCommand.h | 2 +- .../src/inverters/InverterAbstract.cpp | 2 +- 26 files changed, 76 insertions(+), 76 deletions(-) diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp index 417c65b0..b9e8eea2 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp @@ -62,24 +62,24 @@ void ActivePowerControlCommand::setActivePowerLimit(const float limit, const Pow udpateCRC(CRC_SIZE); } -bool ActivePowerControlCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool ActivePowerControlCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { - if (!DevControlCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!DevControlCommand::handleResponse(fragment, max_fragment_id)) { return false; } if ((getType() == PowerLimitControlType::RelativNonPersistent) || (getType() == PowerLimitControlType::RelativPersistent)) { - inverter.SystemConfigPara()->setLimitPercent(getLimit()); + _inv->SystemConfigPara()->setLimitPercent(getLimit()); } else { - const uint16_t max_power = inverter.DevInfo()->getMaxPower(); + const uint16_t max_power = _inv->DevInfo()->getMaxPower(); if (max_power > 0) { - inverter.SystemConfigPara()->setLimitPercent(static_cast(getLimit()) / max_power * 100); + _inv->SystemConfigPara()->setLimitPercent(static_cast(getLimit()) / max_power * 100); } else { // TODO(tbnobody): Not implemented yet because we only can publish the percentage value } } - inverter.SystemConfigPara()->setLastUpdateCommand(millis()); - inverter.SystemConfigPara()->setLastLimitCommandSuccess(CMD_OK); + _inv->SystemConfigPara()->setLastUpdateCommand(millis()); + _inv->SystemConfigPara()->setLastLimitCommandSuccess(CMD_OK); return true; } diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h index b4ef0a7b..375b278b 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h @@ -16,7 +16,7 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(); void setActivePowerLimit(const float limit, const PowerLimitControlType type = RelativNonPersistent); diff --git a/lib/Hoymiles/src/commands/AlarmDataCommand.cpp b/lib/Hoymiles/src/commands/AlarmDataCommand.cpp index bbe35e29..98a97d0b 100644 --- a/lib/Hoymiles/src/commands/AlarmDataCommand.cpp +++ b/lib/Hoymiles/src/commands/AlarmDataCommand.cpp @@ -36,24 +36,24 @@ String AlarmDataCommand::getCommandName() const return "AlarmData"; } -bool AlarmDataCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool AlarmDataCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } // Move all fragments into target buffer uint8_t offs = 0; - inverter.EventLog()->beginAppendFragment(); - inverter.EventLog()->clearBuffer(); + _inv->EventLog()->beginAppendFragment(); + _inv->EventLog()->clearBuffer(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.EventLog()->appendFragment(offs, fragment[i].fragment, fragment[i].len); + _inv->EventLog()->appendFragment(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.EventLog()->endAppendFragment(); - inverter.EventLog()->setLastAlarmRequestSuccess(CMD_OK); - inverter.EventLog()->setLastUpdate(millis()); + _inv->EventLog()->endAppendFragment(); + _inv->EventLog()->setLastAlarmRequestSuccess(CMD_OK); + _inv->EventLog()->setLastUpdate(millis()); return true; } diff --git a/lib/Hoymiles/src/commands/AlarmDataCommand.h b/lib/Hoymiles/src/commands/AlarmDataCommand.h index 5b939d53..ef8404c3 100644 --- a/lib/Hoymiles/src/commands/AlarmDataCommand.h +++ b/lib/Hoymiles/src/commands/AlarmDataCommand.h @@ -9,6 +9,6 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(); }; diff --git a/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp b/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp index f044d9d5..ad89f2d5 100644 --- a/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp +++ b/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp @@ -67,7 +67,7 @@ void ChannelChangeCommand::setCountryMode(const CountryModeId_t mode) } } -bool ChannelChangeCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool ChannelChangeCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { return true; } diff --git a/lib/Hoymiles/src/commands/ChannelChangeCommand.h b/lib/Hoymiles/src/commands/ChannelChangeCommand.h index 2b4a5aad..70b5f64c 100644 --- a/lib/Hoymiles/src/commands/ChannelChangeCommand.h +++ b/lib/Hoymiles/src/commands/ChannelChangeCommand.h @@ -15,7 +15,7 @@ public: void setCountryMode(const CountryModeId_t mode); - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual uint8_t getMaxResendCount(); }; diff --git a/lib/Hoymiles/src/commands/CommandAbstract.h b/lib/Hoymiles/src/commands/CommandAbstract.h index a9f81680..c93cb341 100644 --- a/lib/Hoymiles/src/commands/CommandAbstract.h +++ b/lib/Hoymiles/src/commands/CommandAbstract.h @@ -37,7 +37,7 @@ public: virtual CommandAbstract* getRequestFrameCommand(const uint8_t frame_no); - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) = 0; + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) = 0; virtual void gotTimeout(); // Sets the amount how often the specific command is resent if all fragments where missing diff --git a/lib/Hoymiles/src/commands/DevControlCommand.cpp b/lib/Hoymiles/src/commands/DevControlCommand.cpp index abf5f529..b73f74f0 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.cpp +++ b/lib/Hoymiles/src/commands/DevControlCommand.cpp @@ -39,7 +39,7 @@ void DevControlCommand::udpateCRC(const uint8_t len) _payload[10 + len + 1] = (uint8_t)(crc); } -bool DevControlCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool DevControlCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { for (uint8_t i = 0; i < max_fragment_id; i++) { if (fragment[i].mainCmd != (_payload[0] | 0x80)) { diff --git a/lib/Hoymiles/src/commands/DevControlCommand.h b/lib/Hoymiles/src/commands/DevControlCommand.h index 1fb1361d..7e7637ed 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.h +++ b/lib/Hoymiles/src/commands/DevControlCommand.h @@ -7,7 +7,7 @@ class DevControlCommand : public CommandAbstract { public: explicit DevControlCommand(InverterAbstract* inv, const uint64_t router_address = 0); - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); protected: void udpateCRC(const uint8_t len); diff --git a/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp b/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp index be544886..8a258ac2 100644 --- a/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp +++ b/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp @@ -34,22 +34,22 @@ String DevInfoAllCommand::getCommandName() const return "DevInfoAll"; } -bool DevInfoAllCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool DevInfoAllCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } // Move all fragments into target buffer uint8_t offs = 0; - inverter.DevInfo()->beginAppendFragment(); - inverter.DevInfo()->clearBufferAll(); + _inv->DevInfo()->beginAppendFragment(); + _inv->DevInfo()->clearBufferAll(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.DevInfo()->appendFragmentAll(offs, fragment[i].fragment, fragment[i].len); + _inv->DevInfo()->appendFragmentAll(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.DevInfo()->endAppendFragment(); - inverter.DevInfo()->setLastUpdateAll(millis()); + _inv->DevInfo()->endAppendFragment(); + _inv->DevInfo()->setLastUpdateAll(millis()); return true; } diff --git a/lib/Hoymiles/src/commands/DevInfoAllCommand.h b/lib/Hoymiles/src/commands/DevInfoAllCommand.h index 4f76783f..8ddfd834 100644 --- a/lib/Hoymiles/src/commands/DevInfoAllCommand.h +++ b/lib/Hoymiles/src/commands/DevInfoAllCommand.h @@ -9,5 +9,5 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); }; diff --git a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp index e5899653..d134a0ac 100644 --- a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp +++ b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp @@ -34,22 +34,22 @@ String DevInfoSimpleCommand::getCommandName() const return "DevInfoSimple"; } -bool DevInfoSimpleCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool DevInfoSimpleCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } // Move all fragments into target buffer uint8_t offs = 0; - inverter.DevInfo()->beginAppendFragment(); - inverter.DevInfo()->clearBufferSimple(); + _inv->DevInfo()->beginAppendFragment(); + _inv->DevInfo()->clearBufferSimple(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.DevInfo()->appendFragmentSimple(offs, fragment[i].fragment, fragment[i].len); + _inv->DevInfo()->appendFragmentSimple(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.DevInfo()->endAppendFragment(); - inverter.DevInfo()->setLastUpdateSimple(millis()); + _inv->DevInfo()->endAppendFragment(); + _inv->DevInfo()->setLastUpdateSimple(millis()); return true; } diff --git a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h index 5cd548cc..927f1eab 100644 --- a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h +++ b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h @@ -9,5 +9,5 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); }; diff --git a/lib/Hoymiles/src/commands/GridOnProFilePara.cpp b/lib/Hoymiles/src/commands/GridOnProFilePara.cpp index d7d64e13..77930377 100644 --- a/lib/Hoymiles/src/commands/GridOnProFilePara.cpp +++ b/lib/Hoymiles/src/commands/GridOnProFilePara.cpp @@ -35,22 +35,22 @@ String GridOnProFilePara::getCommandName() const return "GridOnProFilePara"; } -bool GridOnProFilePara::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool GridOnProFilePara::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } // Move all fragments into target buffer uint8_t offs = 0; - inverter.GridProfile()->beginAppendFragment(); - inverter.GridProfile()->clearBuffer(); + _inv->GridProfile()->beginAppendFragment(); + _inv->GridProfile()->clearBuffer(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.GridProfile()->appendFragment(offs, fragment[i].fragment, fragment[i].len); + _inv->GridProfile()->appendFragment(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.GridProfile()->endAppendFragment(); - inverter.GridProfile()->setLastUpdate(millis()); + _inv->GridProfile()->endAppendFragment(); + _inv->GridProfile()->setLastUpdate(millis()); return true; } diff --git a/lib/Hoymiles/src/commands/GridOnProFilePara.h b/lib/Hoymiles/src/commands/GridOnProFilePara.h index 79df2232..b2380c75 100644 --- a/lib/Hoymiles/src/commands/GridOnProFilePara.h +++ b/lib/Hoymiles/src/commands/GridOnProFilePara.h @@ -9,5 +9,5 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); }; diff --git a/lib/Hoymiles/src/commands/MultiDataCommand.cpp b/lib/Hoymiles/src/commands/MultiDataCommand.cpp index ff8a4004..0e7bf51f 100644 --- a/lib/Hoymiles/src/commands/MultiDataCommand.cpp +++ b/lib/Hoymiles/src/commands/MultiDataCommand.cpp @@ -85,7 +85,7 @@ CommandAbstract* MultiDataCommand::getRequestFrameCommand(const uint8_t frame_no return &_cmdRequestFrame; } -bool MultiDataCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool MultiDataCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // All fragments are available --> Check CRC uint16_t crc = 0xffff, crcRcv = 0; diff --git a/lib/Hoymiles/src/commands/MultiDataCommand.h b/lib/Hoymiles/src/commands/MultiDataCommand.h index 4fddd098..5693287f 100644 --- a/lib/Hoymiles/src/commands/MultiDataCommand.h +++ b/lib/Hoymiles/src/commands/MultiDataCommand.h @@ -14,7 +14,7 @@ public: CommandAbstract* getRequestFrameCommand(const uint8_t frame_no); - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); protected: void setDataType(const uint8_t data_type); diff --git a/lib/Hoymiles/src/commands/PowerControlCommand.cpp b/lib/Hoymiles/src/commands/PowerControlCommand.cpp index cfa61d5e..927c3330 100644 --- a/lib/Hoymiles/src/commands/PowerControlCommand.cpp +++ b/lib/Hoymiles/src/commands/PowerControlCommand.cpp @@ -44,14 +44,14 @@ String PowerControlCommand::getCommandName() const return "PowerControl"; } -bool PowerControlCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool PowerControlCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { - if (!DevControlCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!DevControlCommand::handleResponse(fragment, max_fragment_id)) { return false; } - inverter.PowerCommand()->setLastUpdateCommand(millis()); - inverter.PowerCommand()->setLastPowerCommandSuccess(CMD_OK); + _inv->PowerCommand()->setLastUpdateCommand(millis()); + _inv->PowerCommand()->setLastPowerCommandSuccess(CMD_OK); return true; } diff --git a/lib/Hoymiles/src/commands/PowerControlCommand.h b/lib/Hoymiles/src/commands/PowerControlCommand.h index a7bf019b..d40c356d 100644 --- a/lib/Hoymiles/src/commands/PowerControlCommand.h +++ b/lib/Hoymiles/src/commands/PowerControlCommand.h @@ -9,7 +9,7 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(); void setPowerOn(const bool state); diff --git a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp index 2d6919dd..b1396a4d 100644 --- a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp +++ b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp @@ -35,10 +35,10 @@ String RealTimeRunDataCommand::getCommandName() const return "RealTimeRunData"; } -bool RealTimeRunDataCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool RealTimeRunDataCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } @@ -46,7 +46,7 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract& inverter, const fr // In case of low power in the inverter it occours that some incomplete fragments // with a valid CRC are received. const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); - const uint8_t expectedSize = inverter.Statistics()->getExpectedByteCount(); + const uint8_t expectedSize = _inv->Statistics()->getExpectedByteCount(); if (fragmentsSize < expectedSize) { Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n", getCommandName().c_str(), fragmentsSize, expectedSize); @@ -56,15 +56,15 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract& inverter, const fr // Move all fragments into target buffer uint8_t offs = 0; - inverter.Statistics()->beginAppendFragment(); - inverter.Statistics()->clearBuffer(); + _inv->Statistics()->beginAppendFragment(); + _inv->Statistics()->clearBuffer(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.Statistics()->appendFragment(offs, fragment[i].fragment, fragment[i].len); + _inv->Statistics()->appendFragment(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.Statistics()->endAppendFragment(); - inverter.Statistics()->resetRxFailureCount(); - inverter.Statistics()->setLastUpdate(millis()); + _inv->Statistics()->endAppendFragment(); + _inv->Statistics()->resetRxFailureCount(); + _inv->Statistics()->setLastUpdate(millis()); return true; } diff --git a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h index e41bdbf2..9341247f 100644 --- a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h +++ b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h @@ -9,6 +9,6 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(); }; diff --git a/lib/Hoymiles/src/commands/RequestFrameCommand.cpp b/lib/Hoymiles/src/commands/RequestFrameCommand.cpp index deffe63b..0abb5235 100644 --- a/lib/Hoymiles/src/commands/RequestFrameCommand.cpp +++ b/lib/Hoymiles/src/commands/RequestFrameCommand.cpp @@ -47,7 +47,7 @@ uint8_t RequestFrameCommand::getFrameNo() const return _payload[9] & (~0x80); } -bool RequestFrameCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool RequestFrameCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { return true; } diff --git a/lib/Hoymiles/src/commands/RequestFrameCommand.h b/lib/Hoymiles/src/commands/RequestFrameCommand.h index 577ab9d0..2924e69b 100644 --- a/lib/Hoymiles/src/commands/RequestFrameCommand.h +++ b/lib/Hoymiles/src/commands/RequestFrameCommand.h @@ -12,5 +12,5 @@ public: void setFrameNo(const uint8_t frame_no); uint8_t getFrameNo() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); }; diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp index 9e3f89a5..0c142afc 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp @@ -35,10 +35,10 @@ String SystemConfigParaCommand::getCommandName() const return "SystemConfigPara"; } -bool SystemConfigParaCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) +bool SystemConfigParaCommand::handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id) { // Check CRC of whole payload - if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) { + if (!MultiDataCommand::handleResponse(fragment, max_fragment_id)) { return false; } @@ -46,7 +46,7 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract& inverter, const f // In case of low power in the inverter it occours that some incomplete fragments // with a valid CRC are received. const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); - const uint8_t expectedSize = inverter.SystemConfigPara()->getExpectedByteCount(); + const uint8_t expectedSize = _inv->SystemConfigPara()->getExpectedByteCount(); if (fragmentsSize < expectedSize) { Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n", getCommandName().c_str(), fragmentsSize, expectedSize); @@ -56,15 +56,15 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract& inverter, const f // Move all fragments into target buffer uint8_t offs = 0; - inverter.SystemConfigPara()->beginAppendFragment(); - inverter.SystemConfigPara()->clearBuffer(); + _inv->SystemConfigPara()->beginAppendFragment(); + _inv->SystemConfigPara()->clearBuffer(); for (uint8_t i = 0; i < max_fragment_id; i++) { - inverter.SystemConfigPara()->appendFragment(offs, fragment[i].fragment, fragment[i].len); + _inv->SystemConfigPara()->appendFragment(offs, fragment[i].fragment, fragment[i].len); offs += (fragment[i].len); } - inverter.SystemConfigPara()->endAppendFragment(); - inverter.SystemConfigPara()->setLastUpdateRequest(millis()); - inverter.SystemConfigPara()->setLastLimitRequestSuccess(CMD_OK); + _inv->SystemConfigPara()->endAppendFragment(); + _inv->SystemConfigPara()->setLastUpdateRequest(millis()); + _inv->SystemConfigPara()->setLastLimitRequestSuccess(CMD_OK); return true; } diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.h b/lib/Hoymiles/src/commands/SystemConfigParaCommand.h index f33e8481..147f18da 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.h +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.h @@ -9,6 +9,6 @@ public: virtual String getCommandName() const; - virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); + virtual bool handleResponse(const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(); }; diff --git a/lib/Hoymiles/src/inverters/InverterAbstract.cpp b/lib/Hoymiles/src/inverters/InverterAbstract.cpp index 6f757198..17a0d4e7 100644 --- a/lib/Hoymiles/src/inverters/InverterAbstract.cpp +++ b/lib/Hoymiles/src/inverters/InverterAbstract.cpp @@ -255,7 +255,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd) } } - if (!cmd.handleResponse(*this, _rxFragmentBuffer, _rxFragmentMaxPacketId)) { + if (!cmd.handleResponse(_rxFragmentBuffer, _rxFragmentMaxPacketId)) { cmd.gotTimeout(); return FRAGMENT_HANDLE_ERROR; }