Fix: Ensure that only completly assembled packets are put into the command queue
This commit is contained in:
parent
686112e4ee
commit
be09c4052f
@ -17,10 +17,15 @@ public:
|
||||
bool isInitialized();
|
||||
|
||||
template <typename T>
|
||||
T* enqueCommand()
|
||||
void enqueCommand(std::shared_ptr<T> cmd)
|
||||
{
|
||||
_commandQueue.push(std::make_shared<T>());
|
||||
return static_cast<T*>(_commandQueue.back().get());
|
||||
_commandQueue.push(cmd);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> prepareCommand()
|
||||
{
|
||||
return std::make_shared<T>();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@ -18,9 +18,10 @@ bool HMS_Abstract::sendChangeChannelRequest()
|
||||
return false;
|
||||
}
|
||||
|
||||
ChannelChangeCommand* cmdChannel = _radio->enqueCommand<ChannelChangeCommand>();
|
||||
auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>();
|
||||
cmdChannel->setChannel(HoymilesRadio_CMT::getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency()));
|
||||
cmdChannel->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmdChannel);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -20,9 +20,10 @@ bool HMT_Abstract::sendChangeChannelRequest()
|
||||
return false;
|
||||
}
|
||||
|
||||
ChannelChangeCommand* cmdChannel = _radio->enqueCommand<ChannelChangeCommand>();
|
||||
auto cmdChannel = _radio->prepareCommand<ChannelChangeCommand>();
|
||||
cmdChannel->setChannel(HoymilesRadio_CMT::getChannelFromFrequency(Hoymiles.getRadioCmt()->getInverterTargetFrequency()));
|
||||
cmdChannel->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmdChannel);
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -29,9 +29,10 @@ bool HM_Abstract::sendStatsRequest()
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
RealTimeRunDataCommand* cmd = _radio->enqueCommand<RealTimeRunDataCommand>();
|
||||
auto cmd = _radio->prepareCommand<RealTimeRunDataCommand>();
|
||||
cmd->setTime(now);
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -60,9 +61,10 @@ bool HM_Abstract::sendAlarmLogRequest(bool force)
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
AlarmDataCommand* cmd = _radio->enqueCommand<AlarmDataCommand>();
|
||||
auto cmd = _radio->prepareCommand<AlarmDataCommand>();
|
||||
cmd->setTime(now);
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
EventLog()->setLastAlarmRequestSuccess(CMD_PENDING);
|
||||
|
||||
return true;
|
||||
@ -82,13 +84,15 @@ bool HM_Abstract::sendDevInfoRequest()
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
DevInfoAllCommand* cmdAll = _radio->enqueCommand<DevInfoAllCommand>();
|
||||
auto cmdAll = _radio->prepareCommand<DevInfoAllCommand>();
|
||||
cmdAll->setTime(now);
|
||||
cmdAll->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmdAll);
|
||||
|
||||
DevInfoSimpleCommand* cmdSimple = _radio->enqueCommand<DevInfoSimpleCommand>();
|
||||
auto cmdSimple = _radio->prepareCommand<DevInfoSimpleCommand>();
|
||||
cmdSimple->setTime(now);
|
||||
cmdSimple->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmdSimple);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -107,9 +111,10 @@ bool HM_Abstract::sendSystemConfigParaRequest()
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
SystemConfigParaCommand* cmd = _radio->enqueCommand<SystemConfigParaCommand>();
|
||||
auto cmd = _radio->prepareCommand<SystemConfigParaCommand>();
|
||||
cmd->setTime(now);
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
SystemConfigPara()->setLastLimitRequestSuccess(CMD_PENDING);
|
||||
|
||||
return true;
|
||||
@ -128,9 +133,10 @@ bool HM_Abstract::sendActivePowerControlRequest(float limit, PowerLimitControlTy
|
||||
_activePowerControlLimit = limit;
|
||||
_activePowerControlType = type;
|
||||
|
||||
ActivePowerControlCommand* cmd = _radio->enqueCommand<ActivePowerControlCommand>();
|
||||
auto cmd = _radio->prepareCommand<ActivePowerControlCommand>();
|
||||
cmd->setActivePowerLimit(limit, type);
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
SystemConfigPara()->setLastLimitCommandSuccess(CMD_PENDING);
|
||||
|
||||
return true;
|
||||
@ -153,9 +159,10 @@ bool HM_Abstract::sendPowerControlRequest(bool turnOn)
|
||||
_powerState = 0;
|
||||
}
|
||||
|
||||
PowerControlCommand* cmd = _radio->enqueCommand<PowerControlCommand>();
|
||||
auto cmd = _radio->prepareCommand<PowerControlCommand>();
|
||||
cmd->setPowerOn(turnOn);
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
PowerCommand()->setLastPowerCommandSuccess(CMD_PENDING);
|
||||
|
||||
return true;
|
||||
@ -169,9 +176,10 @@ bool HM_Abstract::sendRestartControlRequest()
|
||||
|
||||
_powerState = 2;
|
||||
|
||||
PowerControlCommand* cmd = _radio->enqueCommand<PowerControlCommand>();
|
||||
auto cmd = _radio->prepareCommand<PowerControlCommand>();
|
||||
cmd->setRestart();
|
||||
cmd->setTargetAddress(serial());
|
||||
_radio->enqueCommand(cmd);
|
||||
PowerCommand()->setLastPowerCommandSuccess(CMD_PENDING);
|
||||
|
||||
return true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user