Retry up to 6x in case of incorrect MMU FW version

Because it looks like the communication drop outs are caused by some electrical issues and we can loose even a byte from the version response, which is deadly for future operation.
This commit is contained in:
D.R.racer 2022-08-04 12:14:31 +02:00
parent 6e5fcb5838
commit 53e2d68183
2 changed files with 41 additions and 16 deletions

View File

@ -129,6 +129,7 @@ void ProtocolLogic::SendMsg(RequestMsg rq) {
} }
void StartSeq::Restart() { void StartSeq::Restart() {
retries = maxRetries;
SendVersion(0); SendVersion(0);
} }
@ -145,11 +146,21 @@ StepStatus StartSeq::Step() {
} else { } else {
logic->mmuFwVersionMajor = logic->rsp.paramValue; logic->mmuFwVersionMajor = logic->rsp.paramValue;
if (logic->mmuFwVersionMajor != supportedMmuFWVersionMajor) { if (logic->mmuFwVersionMajor != supportedMmuFWVersionMajor) {
if( --retries == 0){
// if (--retries == 0) has a specific meaning - since we are losing bytes on the UART for no obvious reason
// it can happen, that the reported version number is not complete - i.e. "1" instead of "19"
// Therefore we drop the MMU only if we run out of retries for this very reason.
// There is a limited amount of retries per the whole start seq.
// We also must be able to actually detect an unsupported MMU FW version, so the amount of retries shall be kept small.
return VersionMismatch; return VersionMismatch;
} else {
SendVersion(0);
} }
} else {
logic->dataTO.Reset(); // got meaningful response from the MMU, stop data layer timeout tracking logic->dataTO.Reset(); // got meaningful response from the MMU, stop data layer timeout tracking
SendVersion(1); SendVersion(1);
} }
}
break; break;
case State::S1Sent: // received response to S1 - minor case State::S1Sent: // received response to S1 - minor
if( logic->rsp.request.code != RequestMsgCodes::Version || logic->rsp.request.value != 1 ){ if( logic->rsp.request.code != RequestMsgCodes::Version || logic->rsp.request.value != 1 ){
@ -158,10 +169,15 @@ StepStatus StartSeq::Step() {
} else { } else {
logic->mmuFwVersionMinor = logic->rsp.paramValue; logic->mmuFwVersionMinor = logic->rsp.paramValue;
if (logic->mmuFwVersionMinor != supportedMmuFWVersionMinor){ if (logic->mmuFwVersionMinor != supportedMmuFWVersionMinor){
if( --retries == 0) {
return VersionMismatch; return VersionMismatch;
} else {
SendVersion(1);
} }
} else {
SendVersion(2); SendVersion(2);
} }
}
break; break;
case State::S2Sent: // received response to S2 - revision case State::S2Sent: // received response to S2 - revision
if( logic->rsp.request.code != RequestMsgCodes::Version || logic->rsp.request.value != 2 ){ if( logic->rsp.request.code != RequestMsgCodes::Version || logic->rsp.request.value != 2 ){
@ -170,13 +186,18 @@ StepStatus StartSeq::Step() {
} else { } else {
logic->mmuFwVersionBuild = logic->rsp.paramValue; logic->mmuFwVersionBuild = logic->rsp.paramValue;
if (logic->mmuFwVersionBuild < supportedMmuFWVersionBuild){ if (logic->mmuFwVersionBuild < supportedMmuFWVersionBuild){
if( --retries == 0 ) {
return VersionMismatch; return VersionMismatch;
} else {
SendVersion(2);
} }
} else {
// Start General Interrogation after line up. // Start General Interrogation after line up.
// For now we just send the state of the filament sensor, but we may request // For now we just send the state of the filament sensor, but we may request
// data point states from the MMU as well. TBD in the future, especially with another protocol // data point states from the MMU as well. TBD in the future, especially with another protocol
SendAndUpdateFilamentSensor(); SendAndUpdateFilamentSensor();
} }
}
break; break;
case State::FilamentSensorStateSent: case State::FilamentSensorStateSent:
state = State::Ready; state = State::Ready;

View File

@ -120,9 +120,13 @@ protected:
class StartSeq : public ProtocolLogicPartBase { class StartSeq : public ProtocolLogicPartBase {
public: public:
inline StartSeq(ProtocolLogic *logic) inline StartSeq(ProtocolLogic *logic)
: ProtocolLogicPartBase(logic) {} : ProtocolLogicPartBase(logic)
, retries(maxRetries) {}
void Restart() override; void Restart() override;
StepStatus Step() override; StepStatus Step() override;
private:
static constexpr uint8_t maxRetries = 6;
uint8_t retries;
}; };
class DelayedRestart : public ProtocolLogicPartBase { class DelayedRestart : public ProtocolLogicPartBase {