diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp index 26fff1f4..e736d822 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp @@ -42,8 +42,3 @@ PowerLimitControlType ActivePowerControlCommand::getType() { return (PowerLimitControlType)(((uint16_t)_payload[14] << 8) | _payload[15]); } - -bool ActivePowerControlCommand::handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) -{ - return true; -} \ No newline at end of file diff --git a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h index c0867085..47089baf 100644 --- a/lib/Hoymiles/src/commands/ActivePowerControlCommand.h +++ b/lib/Hoymiles/src/commands/ActivePowerControlCommand.h @@ -16,6 +16,4 @@ public: void setActivePowerLimit(float limit, PowerLimitControlType type = RelativNonPersistent); float getLimit(); PowerLimitControlType getType(); - - virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id); }; \ No newline at end of file diff --git a/lib/Hoymiles/src/commands/DevControlCommand.cpp b/lib/Hoymiles/src/commands/DevControlCommand.cpp index 54b42175..1a8e64d9 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.cpp +++ b/lib/Hoymiles/src/commands/DevControlCommand.cpp @@ -13,4 +13,15 @@ void DevControlCommand::udpateCRC(uint8_t len) uint16_t crc = crc16(&_payload[10], len); _payload[10 + len] = (uint8_t)(crc >> 8); _payload[10 + len + 1] = (uint8_t)(crc); +} + +bool DevControlCommand::handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) +{ + for (uint8_t i = 0; i < max_fragment_id; i++) { + if (fragment[i].mainCmd != (_payload[0] | 0x80)) { + return false; + } + } + + 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 f230bd0b..c9937d02 100644 --- a/lib/Hoymiles/src/commands/DevControlCommand.h +++ b/lib/Hoymiles/src/commands/DevControlCommand.h @@ -6,6 +6,8 @@ class DevControlCommand : public CommandAbstract { public: explicit DevControlCommand(uint64_t target_address = 0, uint64_t router_address = 0); + virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id); + protected: void udpateCRC(uint8_t len); }; \ No newline at end of file diff --git a/lib/Hoymiles/src/inverters/InverterAbstract.cpp b/lib/Hoymiles/src/inverters/InverterAbstract.cpp index caa23033..6fa04253 100644 --- a/lib/Hoymiles/src/inverters/InverterAbstract.cpp +++ b/lib/Hoymiles/src/inverters/InverterAbstract.cpp @@ -90,6 +90,7 @@ void InverterAbstract::addRxFragment(uint8_t fragment[], uint8_t len) // Packets with 0x81 will be seen as 1 memcpy(_rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].fragment, &fragment[10], len - 11); _rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].len = len - 11; + _rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].mainCmd = fragment[0]; _rxFragmentBuffer[(fragmentCount & 0b01111111) - 1].wasReceived = true; if ((fragmentCount & 0b01111111) > _rxFragmentLastPacketId) { diff --git a/lib/Hoymiles/src/types.h b/lib/Hoymiles/src/types.h index e598910d..43c6ffee 100644 --- a/lib/Hoymiles/src/types.h +++ b/lib/Hoymiles/src/types.h @@ -11,6 +11,7 @@ union serial_u { #define MAX_RF_PAYLOAD_SIZE 32 typedef struct { + uint8_t mainCmd; uint8_t fragment[MAX_RF_PAYLOAD_SIZE]; uint8_t len; bool wasReceived;