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-146pull/178/head
parent
20ca99befd
commit
3db0fb6d22
|
|
@ -89,7 +89,7 @@ mp::ResponseCommandStatus Application::RunningCommandStatus() const {
|
|||
case ErrorCode::RUNNING:
|
||||
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Processing, (uint16_t)currentCommand->State());
|
||||
case ErrorCode::OK:
|
||||
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Finished, 0);
|
||||
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Finished, (uint16_t)currentCommand->Result());
|
||||
default:
|
||||
return mp::ResponseCommandStatus(mp::ResponseMsgParamCodes::Error, (uint16_t)currentCommand->Error());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdint.h>
|
||||
#include "error_codes.h"
|
||||
#include "progress_codes.h"
|
||||
#include "result_codes.h"
|
||||
|
||||
namespace modules {
|
||||
namespace motion {
|
||||
|
|
@ -73,6 +74,12 @@ public:
|
|||
/// Please see ErrorCode for more details
|
||||
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.
|
||||
/// 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.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace logic {
|
|||
LoadFilament loadFilament;
|
||||
|
||||
bool LoadFilament::Reset(uint8_t param) {
|
||||
result = ResultCode::OK;
|
||||
|
||||
if (!CheckToolIndex(param)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -72,6 +74,7 @@ bool LoadFilament::StepInner() {
|
|||
break;
|
||||
case FeedToFinda::Stopped:
|
||||
// as requested in MMU-116 - stopping an unsuccessful feed should retract as well but not check the filament
|
||||
result = ResultCode::Cancelled;
|
||||
verifyLoadedFilament = 0;
|
||||
// [[fallthrough]]
|
||||
case FeedToFinda::OK:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ public:
|
|||
/// @returns true if the state machine finished its job, false otherwise
|
||||
bool StepInner() override;
|
||||
|
||||
virtual ResultCode Result() const override { return result; }
|
||||
|
||||
private:
|
||||
void GoToRetractingFromFinda();
|
||||
void Reset2(bool feedPhaseLimited);
|
||||
|
|
@ -40,6 +42,9 @@ private:
|
|||
/// 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 ;) )
|
||||
uint8_t verifyLoadedFilament;
|
||||
|
||||
/// Result of the LoadFilament command
|
||||
ResultCode result;
|
||||
};
|
||||
|
||||
/// The one and only instance of LoadFilament state machine in the FW
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
@ -257,9 +257,7 @@ uint8_t Protocol::EncodeResponseQueryOperation(const RequestMsg &msg, ResponseCo
|
|||
txbuff[2] = ' ';
|
||||
txbuff[3] = (uint8_t)rcs.code;
|
||||
uint8_t *dst = txbuff + 4;
|
||||
if (rcs.code != ResponseMsgParamCodes::Finished) {
|
||||
dst += Value2Hex(rcs.value, dst);
|
||||
}
|
||||
dst += Value2Hex(rcs.value, dst);
|
||||
*dst = '\n';
|
||||
return dst - txbuff + 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ extern "C" {
|
|||
#endif //__cplusplus
|
||||
|
||||
#define project_version_major 2
|
||||
#define project_version_minor 0
|
||||
#define project_version_revision 19
|
||||
#define project_version_minor 1
|
||||
#define project_version_revision 1
|
||||
#define project_version_build 634
|
||||
#define FW_BUILD_NUMBER 0
|
||||
|
||||
|
|
|
|||
|
|
@ -310,18 +310,13 @@ TEST_CASE("protocol::EncodeResponseQueryOperation", "[protocol]") {
|
|||
CHECK(txbuff[2] == ' ');
|
||||
CHECK(txbuff[3] == (uint8_t)responseStatus);
|
||||
|
||||
if (responseStatus == mp::ResponseMsgParamCodes::Finished) {
|
||||
CHECK(txbuff[4] == '\n');
|
||||
CHECK(msglen == 5);
|
||||
} else {
|
||||
char chk[6];
|
||||
int chars = snprintf(chk, 6, "%x\n", encodedParamValue);
|
||||
REQUIRE(chars < 6);
|
||||
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');
|
||||
}
|
||||
char chk[6];
|
||||
int chars = snprintf(chk, 6, "%x\n", encodedParamValue);
|
||||
REQUIRE(chars < 6);
|
||||
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]") {
|
||||
|
|
@ -427,9 +422,7 @@ TEST_CASE("protocol::DecodeResponseQueryOperation", "[protocol][.]") {
|
|||
CHECK((uint8_t)rsp.request.code == rxbuff[0]);
|
||||
CHECK(rsp.request.value == rxbuff[1] - '0');
|
||||
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]") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue