56 constexpr uint8_t ComputeCRC8()
const {
58 crc = modules::crc::CRC8::CCITT_updateCX(0, (uint8_t)
code);
59 crc = modules::crc::CRC8::CCITT_updateCX(crc,
value);
70 ,
crc8(ComputeCRC8()) {
81 ,
crc8(ComputeCRC8()) {
84 constexpr uint8_t CRC()
const {
return crc8; }
93 constexpr uint8_t ComputeCRC8()
const {
94 uint8_t crc =
request.ComputeCRC8();
95 crc = modules::crc::CRC8::CCITT_updateCX(crc, (uint8_t)
paramCode);
107 this->request.
crc8 = ComputeCRC8();
110 constexpr uint8_t CRC()
const {
return request.
crc8; }
136 : rqState(RequestStates::Code)
137 , requestMsg(RequestMsgCodes::unknown, 0)
138 , rspState(ResponseStates::RequestCode)
139 , responseMsg(
RequestMsg(RequestMsgCodes::unknown, 0), ResponseMsgParamCodes::unknown, 0) {
213 rqState = RequestStates::Code;
218 rspState = ResponseStates::RequestCode;
224 enum class RequestStates : uint8_t {
233 RequestStates rqState;
234 RequestMsg requestMsg;
236 enum class ResponseStates : uint8_t {
245 ResponseStates rspState;
246 ResponseMsg responseMsg;
248 static constexpr
bool IsNewLine(uint8_t c) {
249 return c ==
'\n' || c ==
'\r';
251 static constexpr
bool IsDigit(uint8_t c) {
252 return c >=
'0' && c <=
'9';
254 static constexpr
bool IsCRCSeparator(uint8_t c) {
257 static constexpr
bool IsHexDigit(uint8_t c) {
258 return (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f');
260 static constexpr uint8_t Char2Nibble(uint8_t c) {
285 static constexpr uint8_t Nibble2Char(uint8_t n) {
311 static uint8_t UInt8ToHex(uint8_t value, uint8_t *dst);
314 static uint8_t UInt16ToHex(uint16_t value, uint8_t *dst);
316 static uint8_t BeginEncodeRequest(
const RequestMsg &msg, uint8_t *dst);
318 static uint8_t AppendCRC(uint8_t crc, uint8_t *dst);
static constexpr uint8_t CCITT_updateW(uint8_t crc, uint16_t w)
Compute/update CRC8 CCIIT from 16bits (convenience wrapper)
Definition: mmu2_crc.h:33
Definition: mmu2_protocol.h:133
static uint8_t EncodeRequest(const RequestMsg &msg, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:132
static uint8_t EncodeWriteRequest(uint8_t address, uint16_t value, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:144
static uint8_t EncodeResponseReadFINDA(const RequestMsg &msg, uint8_t findaValue, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:284
static uint8_t EncodeResponseQueryOperation(const RequestMsg &msg, ResponseCommandStatus rcs, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:288
DecodeStatus DecodeRequest(uint8_t c)
Definition: mmu2_protocol.cpp:29
const ResponseMsg GetResponseMsg() const
Definition: mmu2_protocol.h:209
static uint8_t EncodeResponseRead(const RequestMsg &msg, bool accepted, uint16_t value2, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:299
static constexpr uint8_t MaxRequestSize()
Definition: mmu2_protocol.h:162
void ResetRequestDecoder()
resets the internal request decoding state (typically after an error)
Definition: mmu2_protocol.h:212
DecodeStatus DecodeResponse(uint8_t c)
Definition: mmu2_protocol.cpp:157
static uint8_t EncodeResponseCmdAR(const RequestMsg &msg, ResponseMsgParamCodes ar, uint8_t *txbuff)
Definition: mmu2_protocol.cpp:265
static constexpr uint8_t MaxResponseSize()
Definition: mmu2_protocol.h:166
void ResetResponseDecoder()
resets the internal response decoding state (typically after an error)
Definition: mmu2_protocol.h:217
const RequestMsg GetRequestMsg() const
Definition: mmu2_protocol.h:206
The MMU communication protocol implementation and related stuff.
Definition: mmu2_protocol.cpp:15
DecodeStatus
Message decoding return values.
Definition: mmu2_protocol.h:123
@ MessageCompleted
message completed and successfully lexed
@ Error
input character broke message decoding
@ NeedMoreData
message incomplete yet, waiting for another byte to come
ResponseMsgParamCodes
Definition of response message parameter codes.
Definition: mmu2_protocol.h:35
RequestMsgCodes
Definition of request message codes.
Definition: mmu2_protocol.h:14
A request message - requests are being sent by the printer into the MMU.
Definition: mmu2_protocol.h:46
constexpr RequestMsg(RequestMsgCodes code, uint8_t value)
Definition: mmu2_protocol.h:66
uint16_t value2
in case or write messages - value to be written into the register
Definition: mmu2_protocol.h:49
uint8_t crc8
Definition: mmu2_protocol.h:54
uint8_t value
value of the request message or address of variable to read/write
Definition: mmu2_protocol.h:48
constexpr RequestMsg(RequestMsgCodes code, uint8_t address, uint16_t value)
Definition: mmu2_protocol.h:77
RequestMsgCodes code
code of the request message
Definition: mmu2_protocol.h:47
Combined commandStatus and its value into one data structure (optimization purposes)
Definition: mmu2_protocol.h:114
A response message - responses are being sent from the MMU into the printer as a response to a reques...
Definition: mmu2_protocol.h:88
ResponseMsgParamCodes paramCode
code of the parameter
Definition: mmu2_protocol.h:90
uint16_t paramValue
value of the parameter
Definition: mmu2_protocol.h:91
RequestMsg request
response is always preceeded by the request message
Definition: mmu2_protocol.h:89
constexpr ResponseMsg(RequestMsg request, ResponseMsgParamCodes paramCode, uint16_t paramValue)
Definition: mmu2_protocol.h:103