From 6a7bed0ecf314364cd9be9649db5903fb73d1170 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 16 May 2024 19:54:09 +0200 Subject: [PATCH] Code Refactoring: Add inverter reference to each command Instead of just adding the target_address to a command this patch adds a reference to the whole inverter instance --- lib/Hoymiles/src/HoymilesRadio.h | 4 +-- .../commands/ActivePowerControlCommand.cpp | 8 ++--- .../src/commands/ActivePowerControlCommand.h | 4 +-- .../src/commands/AlarmDataCommand.cpp | 8 ++--- lib/Hoymiles/src/commands/AlarmDataCommand.h | 4 +-- .../src/commands/ChannelChangeCommand.cpp | 4 +-- .../src/commands/ChannelChangeCommand.h | 2 +- lib/Hoymiles/src/commands/CommandAbstract.cpp | 9 ++++-- lib/Hoymiles/src/commands/CommandAbstract.h | 8 +++-- .../src/commands/DevControlCommand.cpp | 8 ++--- lib/Hoymiles/src/commands/DevControlCommand.h | 4 +-- .../src/commands/DevInfoAllCommand.cpp | 8 ++--- lib/Hoymiles/src/commands/DevInfoAllCommand.h | 4 +-- .../src/commands/DevInfoSimpleCommand.cpp | 8 ++--- .../src/commands/DevInfoSimpleCommand.h | 4 +-- .../src/commands/GridOnProFilePara.cpp | 8 ++--- lib/Hoymiles/src/commands/GridOnProFilePara.h | 4 +-- .../src/commands/MultiDataCommand.cpp | 8 ++--- lib/Hoymiles/src/commands/MultiDataCommand.h | 4 +-- lib/Hoymiles/src/commands/ParaSetCommand.cpp | 8 ++--- lib/Hoymiles/src/commands/ParaSetCommand.h | 4 +-- .../src/commands/PowerControlCommand.cpp | 8 ++--- .../src/commands/PowerControlCommand.h | 4 +-- .../src/commands/RealTimeRunDataCommand.cpp | 8 ++--- .../src/commands/RealTimeRunDataCommand.h | 4 +-- .../src/commands/RequestFrameCommand.cpp | 8 ++--- .../src/commands/RequestFrameCommand.h | 4 +-- .../src/commands/SingleDataCommand.cpp | 6 ++-- lib/Hoymiles/src/commands/SingleDataCommand.h | 4 +-- .../src/commands/SystemConfigParaCommand.cpp | 8 ++--- .../src/commands/SystemConfigParaCommand.h | 4 +-- lib/Hoymiles/src/inverters/HMS_Abstract.cpp | 3 +- lib/Hoymiles/src/inverters/HMT_Abstract.cpp | 3 +- lib/Hoymiles/src/inverters/HM_Abstract.cpp | 29 +++++++------------ 34 files changed, 105 insertions(+), 111 deletions(-) diff --git a/lib/Hoymiles/src/HoymilesRadio.h b/lib/Hoymiles/src/HoymilesRadio.h index cb2a947cd..296b479bb 100644 --- a/lib/Hoymiles/src/HoymilesRadio.h +++ b/lib/Hoymiles/src/HoymilesRadio.h @@ -22,9 +22,9 @@ class HoymilesRadio { } template - std::shared_ptr prepareCommand() + std::shared_ptr prepareCommand(InverterAbstract* inv) { - return std::make_shared(); + return std::make_shared(inv); } protected: diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp index 95af23cfc..f1f670b34 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -25,8 +25,8 @@ ID Target Addr Source Addr Cmd SCmd ? Limit Type CRC16 CRC8 #define CRC_SIZE 6 -ActivePowerControlCommand::ActivePowerControlCommand(const uint64_t target_address, const uint64_t router_address) - : DevControlCommand(target_address, router_address) +ActivePowerControlCommand::ActivePowerControlCommand(InverterAbstract* inv, const uint64_t router_address) + : DevControlCommand(inv, router_address) { _payload[10] = 0x0b; _payload[11] = 0x00; @@ -97,4 +97,4 @@ PowerLimitControlType ActivePowerControlCommand::getType() void ActivePowerControlCommand::gotTimeout(InverterAbstract& inverter) { inverter.SystemConfigPara()->setLastLimitCommandSuccess(CMD_NOK); -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h index b7831fb86..78176796f 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h @@ -12,7 +12,7 @@ typedef enum { // ToDo: to be verified by field tests class ActivePowerControlCommand : public DevControlCommand { public: - explicit ActivePowerControlCommand(const uint64_t target_address = 0, const uint64_t router_address = 0); + explicit ActivePowerControlCommand(InverterAbstract* inv, const uint64_t router_address = 0); virtual String getCommandName() const; @@ -22,4 +22,4 @@ class ActivePowerControlCommand : public DevControlCommand { void setActivePowerLimit(const float limit, const PowerLimitControlType type = RelativNonPersistent); float getLimit() const; PowerLimitControlType getType(); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/AlarmDataCommand.cpp b/lib/Hoymiles/src/commands/AlarmDataCommand.cpp index 143a6cd56..350d0f925 100644 --- a/lib/Hoymiles/src/commands/AlarmDataCommand.cpp +++ b/lib/Hoymiles/src/commands/AlarmDataCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -23,8 +23,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap AlarmId Pa #include "AlarmDataCommand.h" #include "inverters/InverterAbstract.h" -AlarmDataCommand::AlarmDataCommand(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +AlarmDataCommand::AlarmDataCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x11); @@ -60,4 +60,4 @@ bool AlarmDataCommand::handleResponse(InverterAbstract& inverter, const fragment void AlarmDataCommand::gotTimeout(InverterAbstract& inverter) { inverter.EventLog()->setLastAlarmRequestSuccess(CMD_NOK); -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/AlarmDataCommand.h b/lib/Hoymiles/src/commands/AlarmDataCommand.h index abdfc5f83..f5248b1ff 100644 --- a/lib/Hoymiles/src/commands/AlarmDataCommand.h +++ b/lib/Hoymiles/src/commands/AlarmDataCommand.h @@ -5,10 +5,10 @@ class AlarmDataCommand : public MultiDataCommand { public: - explicit AlarmDataCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit AlarmDataCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(InverterAbstract& inverter); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp b/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp index 301785098..f044d9d50 100644 --- a/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp +++ b/lib/Hoymiles/src/commands/ChannelChangeCommand.cpp @@ -19,8 +19,8 @@ ID Target Addr Source Addr ? ? ? CH ? CRC8 */ #include "ChannelChangeCommand.h" -ChannelChangeCommand::ChannelChangeCommand(const uint64_t target_address, const uint64_t router_address, const uint8_t channel) - : CommandAbstract(target_address, router_address) +ChannelChangeCommand::ChannelChangeCommand(InverterAbstract* inv, const uint64_t router_address, const uint8_t channel) + : CommandAbstract(inv, router_address) { _payload[0] = 0x56; _payload[13] = 0x14; diff --git a/lib/Hoymiles/src/commands/ChannelChangeCommand.h b/lib/Hoymiles/src/commands/ChannelChangeCommand.h index 44a4c9ebd..2b4a5aad4 100644 --- a/lib/Hoymiles/src/commands/ChannelChangeCommand.h +++ b/lib/Hoymiles/src/commands/ChannelChangeCommand.h @@ -6,7 +6,7 @@ class ChannelChangeCommand : public CommandAbstract { public: - explicit ChannelChangeCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const uint8_t channel = 0); + explicit ChannelChangeCommand(InverterAbstract* inv, const uint64_t router_address = 0, const uint8_t channel = 0); virtual String getCommandName() const; diff --git a/lib/Hoymiles/src/commands/CommandAbstract.cpp b/lib/Hoymiles/src/commands/CommandAbstract.cpp index dafe2b175..15102fbbb 100644 --- a/lib/Hoymiles/src/commands/CommandAbstract.cpp +++ b/lib/Hoymiles/src/commands/CommandAbstract.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -29,13 +29,16 @@ Source Address: 80 12 23 04 #include "CommandAbstract.h" #include "crc.h" #include +#include "../inverters/InverterAbstract.h" -CommandAbstract::CommandAbstract(const uint64_t target_address, const uint64_t router_address) +CommandAbstract::CommandAbstract(InverterAbstract* inv, const uint64_t router_address) { memset(_payload, 0, RF_LEN); _payload_size = 0; - setTargetAddress(target_address); + _inv = inv; + + setTargetAddress(_inv->serial()); setRouterAddress(router_address); setSendCount(0); setTimeout(0); diff --git a/lib/Hoymiles/src/commands/CommandAbstract.h b/lib/Hoymiles/src/commands/CommandAbstract.h index 677fc0d12..b543ed668 100644 --- a/lib/Hoymiles/src/commands/CommandAbstract.h +++ b/lib/Hoymiles/src/commands/CommandAbstract.h @@ -13,7 +13,7 @@ class InverterAbstract; class CommandAbstract { public: - explicit CommandAbstract(const uint64_t target_address = 0, const uint64_t router_address = 0); + explicit CommandAbstract(InverterAbstract* inv, const uint64_t router_address = 0); virtual ~CommandAbstract() {}; const uint8_t* getDataPayload(); @@ -21,7 +21,6 @@ class CommandAbstract { uint8_t getDataSize() const; - void setTargetAddress(const uint64_t address); uint64_t getTargetAddress() const; void setRouterAddress(const uint64_t address); @@ -56,6 +55,9 @@ class CommandAbstract { uint64_t _targetAddress; uint64_t _routerAddress; + InverterAbstract* _inv; + private: + void setTargetAddress(const uint64_t address); static void convertSerialToPacketId(uint8_t buffer[], const uint64_t serial); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/DevControlCommand.cpp b/lib/Hoymiles/src/commands/DevControlCommand.cpp index a5e7d2b60..abf5f529f 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.cpp +++ b/lib/Hoymiles/src/commands/DevControlCommand.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -23,8 +23,8 @@ ID Target Addr Source Addr Cmd Payload CRC16 CRC8 #include "DevControlCommand.h" #include "crc.h" -DevControlCommand::DevControlCommand(const uint64_t target_address, const uint64_t router_address) - : CommandAbstract(target_address, router_address) +DevControlCommand::DevControlCommand(InverterAbstract* inv, const uint64_t router_address) + : CommandAbstract(inv, router_address) { _payload[0] = 0x51; _payload[9] = 0x81; @@ -48,4 +48,4 @@ bool DevControlCommand::handleResponse(InverterAbstract& inverter, const fragmen } return true; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/DevControlCommand.h b/lib/Hoymiles/src/commands/DevControlCommand.h index c24bc60b2..1fb1361dc 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.h +++ b/lib/Hoymiles/src/commands/DevControlCommand.h @@ -5,10 +5,10 @@ class DevControlCommand : public CommandAbstract { public: - explicit DevControlCommand(const uint64_t target_address = 0, const uint64_t router_address = 0); + 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); protected: void udpateCRC(const uint8_t len); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp b/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp index c7bd80272..be544886c 100644 --- a/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp +++ b/lib/Hoymiles/src/commands/DevInfoAllCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -21,8 +21,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "DevInfoAllCommand.h" #include "inverters/InverterAbstract.h" -DevInfoAllCommand::DevInfoAllCommand(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +DevInfoAllCommand::DevInfoAllCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x01); @@ -52,4 +52,4 @@ bool DevInfoAllCommand::handleResponse(InverterAbstract& inverter, const fragmen inverter.DevInfo()->endAppendFragment(); inverter.DevInfo()->setLastUpdateAll(millis()); return true; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/DevInfoAllCommand.h b/lib/Hoymiles/src/commands/DevInfoAllCommand.h index 3facffa7c..4f76783fa 100644 --- a/lib/Hoymiles/src/commands/DevInfoAllCommand.h +++ b/lib/Hoymiles/src/commands/DevInfoAllCommand.h @@ -5,9 +5,9 @@ class DevInfoAllCommand : public MultiDataCommand { public: - explicit DevInfoAllCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit DevInfoAllCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp index 2afaae4bd..e58996537 100644 --- a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp +++ b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -21,8 +21,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "DevInfoSimpleCommand.h" #include "inverters/InverterAbstract.h" -DevInfoSimpleCommand::DevInfoSimpleCommand(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +DevInfoSimpleCommand::DevInfoSimpleCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x00); @@ -52,4 +52,4 @@ bool DevInfoSimpleCommand::handleResponse(InverterAbstract& inverter, const frag inverter.DevInfo()->endAppendFragment(); inverter.DevInfo()->setLastUpdateSimple(millis()); return true; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h index 66a7301a9..5cd548cca 100644 --- a/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h +++ b/lib/Hoymiles/src/commands/DevInfoSimpleCommand.h @@ -5,9 +5,9 @@ class DevInfoSimpleCommand : public MultiDataCommand { public: - explicit DevInfoSimpleCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit DevInfoSimpleCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/GridOnProFilePara.cpp b/lib/Hoymiles/src/commands/GridOnProFilePara.cpp index c98c7e5a5..d7d64e139 100644 --- a/lib/Hoymiles/src/commands/GridOnProFilePara.cpp +++ b/lib/Hoymiles/src/commands/GridOnProFilePara.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -22,8 +22,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "Hoymiles.h" #include "inverters/InverterAbstract.h" -GridOnProFilePara::GridOnProFilePara(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +GridOnProFilePara::GridOnProFilePara(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x02); @@ -53,4 +53,4 @@ bool GridOnProFilePara::handleResponse(InverterAbstract& inverter, const fragmen inverter.GridProfile()->endAppendFragment(); inverter.GridProfile()->setLastUpdate(millis()); return true; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/GridOnProFilePara.h b/lib/Hoymiles/src/commands/GridOnProFilePara.h index 382ebcbb1..79df22329 100644 --- a/lib/Hoymiles/src/commands/GridOnProFilePara.h +++ b/lib/Hoymiles/src/commands/GridOnProFilePara.h @@ -5,9 +5,9 @@ class GridOnProFilePara : public MultiDataCommand { public: - explicit GridOnProFilePara(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit GridOnProFilePara(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/MultiDataCommand.cpp b/lib/Hoymiles/src/commands/MultiDataCommand.cpp index bbd320916..ff8a40041 100644 --- a/lib/Hoymiles/src/commands/MultiDataCommand.cpp +++ b/lib/Hoymiles/src/commands/MultiDataCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -28,8 +28,9 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "MultiDataCommand.h" #include "crc.h" -MultiDataCommand::MultiDataCommand(const uint64_t target_address, const uint64_t router_address, const uint8_t data_type, const time_t time) - : CommandAbstract(target_address, router_address) +MultiDataCommand::MultiDataCommand(InverterAbstract* inv, const uint64_t router_address, const uint8_t data_type, const time_t time) + : CommandAbstract(inv, router_address) + , _cmdRequestFrame(inv) { _payload[0] = 0x15; _payload[9] = 0x80; @@ -79,7 +80,6 @@ time_t MultiDataCommand::getTime() const CommandAbstract* MultiDataCommand::getRequestFrameCommand(const uint8_t frame_no) { - _cmdRequestFrame.setTargetAddress(getTargetAddress()); _cmdRequestFrame.setFrameNo(frame_no); return &_cmdRequestFrame; diff --git a/lib/Hoymiles/src/commands/MultiDataCommand.h b/lib/Hoymiles/src/commands/MultiDataCommand.h index 821074745..4fddd098e 100644 --- a/lib/Hoymiles/src/commands/MultiDataCommand.h +++ b/lib/Hoymiles/src/commands/MultiDataCommand.h @@ -7,7 +7,7 @@ class MultiDataCommand : public CommandAbstract { public: - explicit MultiDataCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const uint8_t data_type = 0, const time_t time = 0); + explicit MultiDataCommand(InverterAbstract* inv, const uint64_t router_address = 0, const uint8_t data_type = 0, const time_t time = 0); void setTime(const time_t time); time_t getTime() const; @@ -23,4 +23,4 @@ class MultiDataCommand : public CommandAbstract { static uint8_t getTotalFragmentSize(const fragment_t fragment[], const uint8_t max_fragment_id); RequestFrameCommand _cmdRequestFrame; -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/ParaSetCommand.cpp b/lib/Hoymiles/src/commands/ParaSetCommand.cpp index a33749450..8b71867bd 100644 --- a/lib/Hoymiles/src/commands/ParaSetCommand.cpp +++ b/lib/Hoymiles/src/commands/ParaSetCommand.cpp @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ #include "ParaSetCommand.h" -ParaSetCommand::ParaSetCommand(const uint64_t target_address, const uint64_t router_address) - : CommandAbstract(target_address, router_address) +ParaSetCommand::ParaSetCommand(InverterAbstract* inv, const uint64_t router_address) + : CommandAbstract(inv, router_address) { _payload[0] = 0x52; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/ParaSetCommand.h b/lib/Hoymiles/src/commands/ParaSetCommand.h index 424d0e373..224aba390 100644 --- a/lib/Hoymiles/src/commands/ParaSetCommand.h +++ b/lib/Hoymiles/src/commands/ParaSetCommand.h @@ -5,5 +5,5 @@ class ParaSetCommand : public CommandAbstract { public: - explicit ParaSetCommand(const uint64_t target_address = 0, const uint64_t router_address = 0); -}; \ No newline at end of file + explicit ParaSetCommand(InverterAbstract* inv, const uint64_t router_address = 0); +}; diff --git a/lib/Hoymiles/src/commands/PowerControlCommand.cpp b/lib/Hoymiles/src/commands/PowerControlCommand.cpp index fbf12db80..b8340841c 100644 --- a/lib/Hoymiles/src/commands/PowerControlCommand.cpp +++ b/lib/Hoymiles/src/commands/PowerControlCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -26,8 +26,8 @@ ID Target Addr Source Addr Cmd SCmd ? CRC16 CRC8 #define CRC_SIZE 2 -PowerControlCommand::PowerControlCommand(const uint64_t target_address, const uint64_t router_address) - : DevControlCommand(target_address, router_address) +PowerControlCommand::PowerControlCommand(InverterAbstract* inv, const uint64_t router_address) + : DevControlCommand(inv, router_address) { _payload[10] = 0x00; // TurnOn _payload[11] = 0x00; @@ -76,4 +76,4 @@ void PowerControlCommand::setRestart() _payload[10] = 0x02; // Restart udpateCRC(CRC_SIZE); // 2 byte crc -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/PowerControlCommand.h b/lib/Hoymiles/src/commands/PowerControlCommand.h index 8b9f11ac4..e792f3b3c 100644 --- a/lib/Hoymiles/src/commands/PowerControlCommand.h +++ b/lib/Hoymiles/src/commands/PowerControlCommand.h @@ -5,7 +5,7 @@ class PowerControlCommand : public DevControlCommand { public: - explicit PowerControlCommand(const uint64_t target_address = 0, const uint64_t router_address = 0); + explicit PowerControlCommand(InverterAbstract* inv, const uint64_t router_address = 0); virtual String getCommandName() const; @@ -14,4 +14,4 @@ class PowerControlCommand : public DevControlCommand { void setPowerOn(const bool state); void setRestart(); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp index 5f04c948b..bc800b992 100644 --- a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp +++ b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -22,8 +22,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "Hoymiles.h" #include "inverters/InverterAbstract.h" -RealTimeRunDataCommand::RealTimeRunDataCommand(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +RealTimeRunDataCommand::RealTimeRunDataCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x0b); @@ -71,4 +71,4 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract& inverter, const fr void RealTimeRunDataCommand::gotTimeout(InverterAbstract& inverter) { inverter.Statistics()->incrementRxFailureCount(); -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h index 7a0eeec14..82c4f3774 100644 --- a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h +++ b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.h @@ -5,10 +5,10 @@ class RealTimeRunDataCommand : public MultiDataCommand { public: - explicit RealTimeRunDataCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit RealTimeRunDataCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(InverterAbstract& inverter); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/RequestFrameCommand.cpp b/lib/Hoymiles/src/commands/RequestFrameCommand.cpp index 68c4977f7..deffe63b3 100644 --- a/lib/Hoymiles/src/commands/RequestFrameCommand.cpp +++ b/lib/Hoymiles/src/commands/RequestFrameCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -22,8 +22,8 @@ ID Target Addr Source Addr Frm CRC8 */ #include "RequestFrameCommand.h" -RequestFrameCommand::RequestFrameCommand(const uint64_t target_address, const uint64_t router_address, uint8_t frame_no) - : SingleDataCommand(target_address, router_address) +RequestFrameCommand::RequestFrameCommand(InverterAbstract* inv, const uint64_t router_address, uint8_t frame_no) + : SingleDataCommand(inv, router_address) { if (frame_no > 127) { frame_no = 0; @@ -50,4 +50,4 @@ uint8_t RequestFrameCommand::getFrameNo() const bool RequestFrameCommand::handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id) { return true; -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/RequestFrameCommand.h b/lib/Hoymiles/src/commands/RequestFrameCommand.h index 92663b708..577ab9d07 100644 --- a/lib/Hoymiles/src/commands/RequestFrameCommand.h +++ b/lib/Hoymiles/src/commands/RequestFrameCommand.h @@ -5,7 +5,7 @@ class RequestFrameCommand : public SingleDataCommand { public: - explicit RequestFrameCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, uint8_t frame_no = 0); + explicit RequestFrameCommand(InverterAbstract* inv, const uint64_t router_address = 0, uint8_t frame_no = 0); virtual String getCommandName() const; @@ -13,4 +13,4 @@ class RequestFrameCommand : public SingleDataCommand { uint8_t getFrameNo() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/commands/SingleDataCommand.cpp b/lib/Hoymiles/src/commands/SingleDataCommand.cpp index 4f775146d..3b648814a 100644 --- a/lib/Hoymiles/src/commands/SingleDataCommand.cpp +++ b/lib/Hoymiles/src/commands/SingleDataCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -19,8 +19,8 @@ ID Target Addr Source Addr CRC8 */ #include "SingleDataCommand.h" -SingleDataCommand::SingleDataCommand(const uint64_t target_address, const uint64_t router_address) - : CommandAbstract(target_address, router_address) +SingleDataCommand::SingleDataCommand(InverterAbstract* inv, const uint64_t router_address) + : CommandAbstract(inv, router_address) { _payload[0] = 0x15; setTimeout(100); diff --git a/lib/Hoymiles/src/commands/SingleDataCommand.h b/lib/Hoymiles/src/commands/SingleDataCommand.h index d05151691..39f3c480c 100644 --- a/lib/Hoymiles/src/commands/SingleDataCommand.h +++ b/lib/Hoymiles/src/commands/SingleDataCommand.h @@ -5,5 +5,5 @@ class SingleDataCommand : public CommandAbstract { public: - explicit SingleDataCommand(const uint64_t target_address = 0, const uint64_t router_address = 0); -}; \ No newline at end of file + explicit SingleDataCommand(InverterAbstract* inv, const uint64_t router_address = 0); +}; diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp index 0c8e7ded7..7149394cf 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ /* @@ -22,8 +22,8 @@ ID Target Addr Source Addr Idx DT ? Time Gap Pa #include "Hoymiles.h" #include "inverters/InverterAbstract.h" -SystemConfigParaCommand::SystemConfigParaCommand(const uint64_t target_address, const uint64_t router_address, const time_t time) - : MultiDataCommand(target_address, router_address) +SystemConfigParaCommand::SystemConfigParaCommand(InverterAbstract* inv, const uint64_t router_address, const time_t time) + : MultiDataCommand(inv, router_address) { setTime(time); setDataType(0x05); @@ -71,4 +71,4 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract& inverter, const f void SystemConfigParaCommand::gotTimeout(InverterAbstract& inverter) { inverter.SystemConfigPara()->setLastLimitRequestSuccess(CMD_NOK); -} \ No newline at end of file +} diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.h b/lib/Hoymiles/src/commands/SystemConfigParaCommand.h index e2480a973..ee6b3b95b 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.h +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.h @@ -5,10 +5,10 @@ class SystemConfigParaCommand : public MultiDataCommand { public: - explicit SystemConfigParaCommand(const uint64_t target_address = 0, const uint64_t router_address = 0, const time_t time = 0); + explicit SystemConfigParaCommand(InverterAbstract* inv, const uint64_t router_address = 0, const time_t time = 0); virtual String getCommandName() const; virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id); virtual void gotTimeout(InverterAbstract& inverter); -}; \ No newline at end of file +}; diff --git a/lib/Hoymiles/src/inverters/HMS_Abstract.cpp b/lib/Hoymiles/src/inverters/HMS_Abstract.cpp index ffa7d7219..4fc64b036 100644 --- a/lib/Hoymiles/src/inverters/HMS_Abstract.cpp +++ b/lib/Hoymiles/src/inverters/HMS_Abstract.cpp @@ -18,10 +18,9 @@ bool HMS_Abstract::sendChangeChannelRequest() return false; } - auto cmdChannel = _radio->prepareCommand(); + auto cmdChannel = _radio->prepareCommand(this); cmdChannel->setCountryMode(Hoymiles.getRadioCmt()->getCountryMode()); cmdChannel->setChannel(Hoymiles.getRadioCmt()->getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency())); - cmdChannel->setTargetAddress(serial()); _radio->enqueCommand(cmdChannel); return true; diff --git a/lib/Hoymiles/src/inverters/HMT_Abstract.cpp b/lib/Hoymiles/src/inverters/HMT_Abstract.cpp index 5c232b900..50c895cc6 100644 --- a/lib/Hoymiles/src/inverters/HMT_Abstract.cpp +++ b/lib/Hoymiles/src/inverters/HMT_Abstract.cpp @@ -20,10 +20,9 @@ bool HMT_Abstract::sendChangeChannelRequest() return false; } - auto cmdChannel = _radio->prepareCommand(); + auto cmdChannel = _radio->prepareCommand(this); cmdChannel->setCountryMode(Hoymiles.getRadioCmt()->getCountryMode()); cmdChannel->setChannel(Hoymiles.getRadioCmt()->getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency())); - cmdChannel->setTargetAddress(serial()); _radio->enqueCommand(cmdChannel); return true; diff --git a/lib/Hoymiles/src/inverters/HM_Abstract.cpp b/lib/Hoymiles/src/inverters/HM_Abstract.cpp index 62f5af297..45efc99db 100644 --- a/lib/Hoymiles/src/inverters/HM_Abstract.cpp +++ b/lib/Hoymiles/src/inverters/HM_Abstract.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ #include "HM_Abstract.h" #include "HoymilesRadio.h" @@ -30,9 +30,8 @@ bool HM_Abstract::sendStatsRequest() time_t now; time(&now); - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setTime(now); - cmd->setTargetAddress(serial()); _radio->enqueCommand(cmd); return true; @@ -62,9 +61,8 @@ bool HM_Abstract::sendAlarmLogRequest(const bool force) time_t now; time(&now); - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setTime(now); - cmd->setTargetAddress(serial()); EventLog()->setLastAlarmRequestSuccess(CMD_PENDING); _radio->enqueCommand(cmd); @@ -85,14 +83,12 @@ bool HM_Abstract::sendDevInfoRequest() time_t now; time(&now); - auto cmdAll = _radio->prepareCommand(); + auto cmdAll = _radio->prepareCommand(this); cmdAll->setTime(now); - cmdAll->setTargetAddress(serial()); _radio->enqueCommand(cmdAll); - auto cmdSimple = _radio->prepareCommand(); + auto cmdSimple = _radio->prepareCommand(this); cmdSimple->setTime(now); - cmdSimple->setTargetAddress(serial()); _radio->enqueCommand(cmdSimple); return true; @@ -112,9 +108,8 @@ bool HM_Abstract::sendSystemConfigParaRequest() time_t now; time(&now); - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setTime(now); - cmd->setTargetAddress(serial()); SystemConfigPara()->setLastLimitRequestSuccess(CMD_PENDING); _radio->enqueCommand(cmd); @@ -134,9 +129,8 @@ bool HM_Abstract::sendActivePowerControlRequest(float limit, const PowerLimitCon _activePowerControlLimit = limit; _activePowerControlType = type; - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setActivePowerLimit(limit, type); - cmd->setTargetAddress(serial()); SystemConfigPara()->setLastLimitCommandSuccess(CMD_PENDING); _radio->enqueCommand(cmd); @@ -160,9 +154,8 @@ bool HM_Abstract::sendPowerControlRequest(const bool turnOn) _powerState = 0; } - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setPowerOn(turnOn); - cmd->setTargetAddress(serial()); PowerCommand()->setLastPowerCommandSuccess(CMD_PENDING); _radio->enqueCommand(cmd); @@ -177,9 +170,8 @@ bool HM_Abstract::sendRestartControlRequest() _powerState = 2; - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setRestart(); - cmd->setTargetAddress(serial()); PowerCommand()->setLastPowerCommandSuccess(CMD_PENDING); _radio->enqueCommand(cmd); @@ -219,9 +211,8 @@ bool HM_Abstract::sendGridOnProFileParaRequest() time_t now; time(&now); - auto cmd = _radio->prepareCommand(); + auto cmd = _radio->prepareCommand(this); cmd->setTime(now); - cmd->setTargetAddress(serial()); _radio->enqueCommand(cmd); return true;