Allow result codes on a Finished Command state

Helpful for the printer to show, that a command has been cancelled (or anything else we can think of in the future).
MMU-146
pull/196/head
D.R.racer 2022-08-05 09:48:40 +02:00 committed by DRracer
parent 283403306e
commit bf5c0f3f23
8 changed files with 40 additions and 21 deletions

View File

@ -89,7 +89,7 @@ mp::ResponseCommandStatus Application::RunningCommandStatus() const {
case ErrorCode::RUNNING: case ErrorCode::RUNNING:
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Processing, (uint16_t)currentCommand->State()); return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Processing, (uint16_t)currentCommand->State());
case ErrorCode::OK: case ErrorCode::OK:
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Finished, 0); return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Finished, (uint16_t)currentCommand->Result());
default: default:
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Error, (uint16_t)currentCommand->Error()); return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Error, (uint16_t)currentCommand->Error());
} }

View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include "error_codes.h" #include "error_codes.h"
#include "progress_codes.h" #include "progress_codes.h"
#include "result_codes.h"
namespace modules { namespace modules {
namespace motion { namespace motion {
@ -73,6 +74,12 @@ public:
/// Please see ErrorCode for more details /// Please see ErrorCode for more details
virtual ErrorCode Error() const { return error; } virtual ErrorCode Error() const { return error; }
/// @returns result of a command - only valid after the command finished its work.
/// Default returned value is OK for all commands.
/// So far there is only one example usage: LoadFilament can be terminated with a button -> Result will be Cancelled.
/// The printer then can display "Loading cancelled"
virtual ResultCode Result() const { return ResultCode::OK; }
/// Switches the state machine into an error state of code ec. /// Switches the state machine into an error state of code ec.
/// It shall be used to halt the firmware while retaining the capability of reporting the error state to the printer /// It shall be used to halt the firmware while retaining the capability of reporting the error state to the printer
/// - a kind of similar to runtime assertions. /// - a kind of similar to runtime assertions.

View File

@ -16,6 +16,8 @@ namespace logic {
LoadFilament loadFilament; LoadFilament loadFilament;
bool LoadFilament::Reset(uint8_t param) { bool LoadFilament::Reset(uint8_t param) {
result = ResultCode::OK;
if (!CheckToolIndex(param)) { if (!CheckToolIndex(param)) {
return false; return false;
} }
@ -72,6 +74,7 @@ bool LoadFilament::StepInner() {
break; break;
case FeedToFinda::Stopped: case FeedToFinda::Stopped:
// as requested in MMU-116 - stopping an unsuccessful feed should retract as well but not check the filament // as requested in MMU-116 - stopping an unsuccessful feed should retract as well but not check the filament
result = ResultCode::Cancelled;
verifyLoadedFilament = 0; verifyLoadedFilament = 0;
// [[fallthrough]] // [[fallthrough]]
case FeedToFinda::OK: case FeedToFinda::OK:

View File

@ -25,6 +25,8 @@ public:
/// @returns true if the state machine finished its job, false otherwise /// @returns true if the state machine finished its job, false otherwise
bool StepInner() override; bool StepInner() override;
virtual ResultCode Result() const override { return result; }
private: private:
void GoToRetractingFromFinda(); void GoToRetractingFromFinda();
void Reset2(bool feedPhaseLimited); void Reset2(bool feedPhaseLimited);
@ -40,6 +42,9 @@ private:
/// That ensures the filament can be loaded into the selector later when needed. /// That ensures the filament can be loaded into the selector later when needed.
/// verifyLoadedFilament holds the number of re-checks to be performed (we expect >1 re-checks will be requested one day ;) ) /// verifyLoadedFilament holds the number of re-checks to be performed (we expect >1 re-checks will be requested one day ;) )
uint8_t verifyLoadedFilament; uint8_t verifyLoadedFilament;
/// Result of the LoadFilament command
ResultCode result;
}; };
/// The one and only instance of LoadFilament state machine in the FW /// The one and only instance of LoadFilament state machine in the FW

13
src/logic/result_codes.h Normal file
View File

@ -0,0 +1,13 @@
/// @file result_codes.h
#pragma once
#include <stdint.h>
/// A complete set of result codes which may be a result of a high-level command/operation.
/// This header file shall be included in the printer's firmware as well as a reference,
/// therefore the error codes have been extracted to one place.
///
/// Please note that currently only LoadFilament can return something else than "OK"
enum class ResultCode : uint_fast16_t {
OK = 0,
Cancelled = 1
};

View File

@ -257,9 +257,7 @@ uint8_t Protocol::EncodeResponseQueryOperation(const RequestMsg &msg, ResponseCo
txbuff[2] = ' '; txbuff[2] = ' ';
txbuff[3] = (uint8_t)rcs.code; txbuff[3] = (uint8_t)rcs.code;
uint8_t *dst = txbuff + 4; uint8_t *dst = txbuff + 4;
if (rcs.code != ResponseMsgParamCodes::Finished) { dst += Value2Hex(rcs.value, dst);
dst += Value2Hex(rcs.value, dst);
}
*dst = '\n'; *dst = '\n';
return dst - txbuff + 1; return dst - txbuff + 1;
} }

View File

@ -7,8 +7,8 @@ extern "C" {
#endif //__cplusplus #endif //__cplusplus
#define project_version_major 2 #define project_version_major 2
#define project_version_minor 0 #define project_version_minor 1
#define project_version_revision 19 #define project_version_revision 1
#define project_version_build 634 #define project_version_build 634
#define FW_BUILD_NUMBER 0 #define FW_BUILD_NUMBER 0

View File

@ -310,18 +310,13 @@ TEST_CASE("protocol::EncodeResponseQueryOperation", "[protocol]") {
CHECK(txbuff[2] == ' '); CHECK(txbuff[2] == ' ');
CHECK(txbuff[3] == (uint8_t)responseStatus); CHECK(txbuff[3] == (uint8_t)responseStatus);
if (responseStatus == mp::ResponseMsgParamCodes::Finished) { char chk[6];
CHECK(txbuff[4] == '\n'); int chars = snprintf(chk, 6, "%x\n", encodedParamValue);
CHECK(msglen == 5); REQUIRE(chars < 6);
} else { std::string chks(chk, chk + chars);
char chk[6]; std::string txs((const char *)(&txbuff[4]), (const char *)(&txbuff[msglen]));
int chars = snprintf(chk, 6, "%x\n", encodedParamValue); REQUIRE(chk == txs);
REQUIRE(chars < 6); CHECK(txbuff[msglen - 1] == '\n');
std::string chks(chk, chk + chars);
std::string txs((const char *)(&txbuff[4]), (const char *)(&txbuff[msglen]));
REQUIRE(chk == txs);
CHECK(txbuff[msglen - 1] == '\n');
}
} }
TEST_CASE("protocol::DecodeRequest", "[protocol]") { TEST_CASE("protocol::DecodeRequest", "[protocol]") {
@ -427,9 +422,7 @@ TEST_CASE("protocol::DecodeResponseQueryOperation", "[protocol][.]") {
CHECK((uint8_t)rsp.request.code == rxbuff[0]); CHECK((uint8_t)rsp.request.code == rxbuff[0]);
CHECK(rsp.request.value == rxbuff[1] - '0'); CHECK(rsp.request.value == rxbuff[1] - '0');
CHECK((uint8_t)rsp.paramCode == rxbuff[3]); CHECK((uint8_t)rsp.paramCode == rxbuff[3]);
if ((uint8_t)rsp.paramCode != (uint8_t)mp::ResponseMsgParamCodes::Finished) { CHECK((uint8_t)rsp.paramValue == rxbuff[4] - '0');
CHECK((uint8_t)rsp.paramValue == rxbuff[4] - '0');
}
} }
TEST_CASE("protocol::DecodeRequestErrors", "[protocol]") { TEST_CASE("protocol::DecodeRequestErrors", "[protocol]") {