Skip to content

Commit

Permalink
Code Refactoring: Use internal inverter instance in gotTimeout method
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed May 16, 2024
1 parent 6a7bed0 commit 6d6d62b
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/ActivePowerControlCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ PowerLimitControlType ActivePowerControlCommand::getType()
return (PowerLimitControlType)(((uint16_t)_payload[14] << 8) | _payload[15]);
}

void ActivePowerControlCommand::gotTimeout(InverterAbstract& inverter)
void ActivePowerControlCommand::gotTimeout()
{
inverter.SystemConfigPara()->setLastLimitCommandSuccess(CMD_NOK);
_inv->SystemConfigPara()->setLastLimitCommandSuccess(CMD_NOK);
}
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/ActivePowerControlCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ActivePowerControlCommand : public DevControlCommand {
virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();

void setActivePowerLimit(const float limit, const PowerLimitControlType type = RelativNonPersistent);
float getLimit() const;
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/AlarmDataCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool AlarmDataCommand::handleResponse(InverterAbstract& inverter, const fragment
return true;
}

void AlarmDataCommand::gotTimeout(InverterAbstract& inverter)
void AlarmDataCommand::gotTimeout()
{
inverter.EventLog()->setLastAlarmRequestSuccess(CMD_NOK);
_inv->EventLog()->setLastAlarmRequestSuccess(CMD_NOK);
}
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/AlarmDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class AlarmDataCommand : public MultiDataCommand {
virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();
};
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/CommandAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void CommandAbstract::convertSerialToPacketId(uint8_t buffer[], const uint64_t s
buffer[0] = s.b[3];
}

void CommandAbstract::gotTimeout(InverterAbstract& inverter)
void CommandAbstract::gotTimeout()
{
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/CommandAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CommandAbstract {
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 void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();

// Sets the amount how often the specific command is resent if all fragments where missing
virtual uint8_t getMaxResendCount() const;
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/PowerControlCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ bool PowerControlCommand::handleResponse(InverterAbstract& inverter, const fragm
return true;
}

void PowerControlCommand::gotTimeout(InverterAbstract& inverter)
void PowerControlCommand::gotTimeout()
{
inverter.PowerCommand()->setLastPowerCommandSuccess(CMD_NOK);
_inv->PowerCommand()->setLastPowerCommandSuccess(CMD_NOK);
}

void PowerControlCommand::setPowerOn(const bool state)
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/PowerControlCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PowerControlCommand : public DevControlCommand {
virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();

void setPowerOn(const bool state);
void setRestart();
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract& inverter, const fr
return true;
}

void RealTimeRunDataCommand::gotTimeout(InverterAbstract& inverter)
void RealTimeRunDataCommand::gotTimeout()
{
inverter.Statistics()->incrementRxFailureCount();
_inv->Statistics()->incrementRxFailureCount();
}
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/RealTimeRunDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class RealTimeRunDataCommand : public MultiDataCommand {
virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();
};
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract& inverter, const f
return true;
}

void SystemConfigParaCommand::gotTimeout(InverterAbstract& inverter)
void SystemConfigParaCommand::gotTimeout()
{
inverter.SystemConfigPara()->setLastLimitRequestSuccess(CMD_NOK);
_inv->SystemConfigPara()->setLastLimitRequestSuccess(CMD_NOK);
}
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/SystemConfigParaCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class SystemConfigParaCommand : public MultiDataCommand {
virtual String getCommandName() const;

virtual bool handleResponse(InverterAbstract& inverter, const fragment_t fragment[], const uint8_t max_fragment_id);
virtual void gotTimeout(InverterAbstract& inverter);
virtual void gotTimeout();
};
10 changes: 5 additions & 5 deletions lib/Hoymiles/src/inverters/InverterAbstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
if (cmd.getSendCount() <= cmd.getMaxResendCount()) {
return FRAGMENT_ALL_MISSING_RESEND;
} else {
cmd.gotTimeout(*this);
cmd.gotTimeout();
return FRAGMENT_ALL_MISSING_TIMEOUT;
}
}
Expand All @@ -237,7 +237,7 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
if (_rxFragmentRetransmitCnt++ < cmd.getMaxRetransmitCount()) {
return _rxFragmentLastPacketId + 1;
} else {
cmd.gotTimeout(*this);
cmd.gotTimeout();
return FRAGMENT_RETRANSMIT_TIMEOUT;
}
}
Expand All @@ -249,16 +249,16 @@ uint8_t InverterAbstract::verifyAllFragments(CommandAbstract& cmd)
if (_rxFragmentRetransmitCnt++ < cmd.getMaxRetransmitCount()) {
return i + 1;
} else {
cmd.gotTimeout(*this);
cmd.gotTimeout();
return FRAGMENT_RETRANSMIT_TIMEOUT;
}
}
}

if (!cmd.handleResponse(*this, _rxFragmentBuffer, _rxFragmentMaxPacketId)) {
cmd.gotTimeout(*this);
cmd.gotTimeout();
return FRAGMENT_HANDLE_ERROR;
}

return FRAGMENT_OK;
}
}

0 comments on commit 6d6d62b

Please sign in to comment.