57 constexpr uint8_t ComputeCRC8()
const {
59 crc = modules::crc::CRC8::CCITT_updateCX(0, (uint8_t)
code);
60 crc = modules::crc::CRC8::CCITT_updateCX(crc,
value);
71 ,
crc8(ComputeCRC8()) {
82 ,
crc8(ComputeCRC8()) {
85 constexpr uint8_t CRC()
const {
return crc8; }
94 constexpr uint8_t ComputeCRC8()
const {
95 uint8_t crc =
request.ComputeCRC8();
96 crc = modules::crc::CRC8::CCITT_updateCX(crc, (uint8_t)
paramCode);
108 this->request.
crc8 = ComputeCRC8();
111 constexpr uint8_t CRC()
const {
return request.
crc8; }
137 : rqState(RequestStates::Code)
138 , requestMsg(RequestMsgCodes::unknown, 0)
139 , rspState(ResponseStates::RequestCode)
140 , responseMsg(
RequestMsg(RequestMsgCodes::unknown, 0), ResponseMsgParamCodes::unknown, 0) {
206 rqState = RequestStates::Code;
211 rspState = ResponseStates::RequestCode;
217 enum class RequestStates : uint8_t {
226 RequestStates rqState;
227 RequestMsg requestMsg;
229 enum class ResponseStates : uint8_t {
238 ResponseStates rspState;
239 ResponseMsg responseMsg;
241 static constexpr
bool IsNewLine(uint8_t c) {
242 return c ==
'\n' || c ==
'\r';
244 static constexpr
bool IsDigit(uint8_t c) {
245 return c >=
'0' && c <=
'9';
247 static constexpr
bool IsCRCSeparator(uint8_t c) {
250 static constexpr
bool IsHexDigit(uint8_t c) {
251 return (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f');
253 static constexpr uint8_t Char2Nibble(uint8_t c) {
278 static constexpr uint8_t Nibble2Char(uint8_t n) {
304 static uint8_t UInt8ToHex(uint8_t value, uint8_t *dst);
307 static uint8_t UInt16ToHex(uint16_t value, uint8_t *dst);
309 static uint8_t BeginEncodeRequest(
const RequestMsg &msg, uint8_t *dst);
311 static uint8_t AppendCRC(uint8_t crc, uint8_t *dst);
static mp::Protocol protocol
Global instance of the protocol codec.
Definition: application.cpp:31
static constexpr uint8_t CCITT_updateW(uint8_t crc, uint16_t w)
Compute/update CRC8 CCIIT from 16bits (convenience wrapper)
Definition: crc.h:30
Definition: protocol.h:134
static uint8_t EncodeRequest(const RequestMsg &msg, uint8_t *txbuff)
Definition: protocol.cpp:128
static uint8_t EncodeWriteRequest(uint8_t address, uint16_t value, uint8_t *txbuff)
Definition: protocol.cpp:140
static uint8_t EncodeResponseReadFINDA(const RequestMsg &msg, uint8_t findaValue, uint8_t *txbuff)
Definition: protocol.cpp:280
static uint8_t EncodeResponseQueryOperation(const RequestMsg &msg, ResponseCommandStatus rcs, uint8_t *txbuff)
Definition: protocol.cpp:284
DecodeStatus DecodeRequest(uint8_t c)
Definition: protocol.cpp:29
const ResponseMsg GetResponseMsg() const
Definition: protocol.h:202
static uint8_t EncodeResponseRead(const RequestMsg &msg, bool accepted, uint16_t value2, uint8_t *txbuff)
Definition: protocol.cpp:295
static constexpr uint8_t MaxRequestSize()
Definition: protocol.h:163
void ResetRequestDecoder()
resets the internal request decoding state (typically after an error)
Definition: protocol.h:205
DecodeStatus DecodeResponse(uint8_t c)
Definition: protocol.cpp:153
static uint8_t EncodeResponseCmdAR(const RequestMsg &msg, ResponseMsgParamCodes ar, uint8_t *txbuff)
Definition: protocol.cpp:261
static constexpr uint8_t MaxResponseSize()
Definition: protocol.h:167
void ResetResponseDecoder()
resets the internal response decoding state (typically after an error)
Definition: protocol.h:210
const RequestMsg GetRequestMsg() const
Definition: protocol.h:199
The MMU communication protocol implementation and related stuff.
Definition: protocol.cpp:15
DecodeStatus
Message decoding return values.
Definition: protocol.h:124
@ 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: protocol.h:36
RequestMsgCodes
Definition of request message codes.
Definition: protocol.h:15
The modules namespace contains models of MMU's components.
Definition: command_base.h:8
A request message - requests are being sent by the printer into the MMU.
Definition: protocol.h:47
constexpr RequestMsg(RequestMsgCodes code, uint8_t value)
Definition: protocol.h:67
uint16_t value2
in case or write messages - value to be written into the register
Definition: protocol.h:50
uint8_t crc8
Definition: protocol.h:55
uint8_t value
value of the request message or address of variable to read/write
Definition: protocol.h:49
constexpr RequestMsg(RequestMsgCodes code, uint8_t address, uint16_t value)
Definition: protocol.h:78
RequestMsgCodes code
code of the request message
Definition: protocol.h:48
Combined commandStatus and its value into one data structure (optimization purposes)
Definition: protocol.h:115
A response message - responses are being sent from the MMU into the printer as a response to a reques...
Definition: protocol.h:89
ResponseMsgParamCodes paramCode
code of the parameter
Definition: protocol.h:91
uint16_t paramValue
value of the parameter
Definition: protocol.h:92
RequestMsg request
response is always preceeded by the request message
Definition: protocol.h:90
constexpr ResponseMsg(RequestMsg request, ResponseMsgParamCodes paramCode, uint16_t paramValue)
Definition: protocol.h:104