Fix computation of CRC
came out of unit tests of read/write registers functionality.pull/198/head
parent
5d2a0dab04
commit
bd5965957d
|
|
@ -8,7 +8,7 @@ namespace modules {
|
||||||
/// @brief The MMU communication protocol implementation and related stuff.
|
/// @brief The MMU communication protocol implementation and related stuff.
|
||||||
///
|
///
|
||||||
/// See description of the new protocol in the MMU 2021 doc
|
/// See description of the new protocol in the MMU 2021 doc
|
||||||
/// @@TODO possibly add some checksum to verify the correctness of messages
|
|
||||||
namespace protocol {
|
namespace protocol {
|
||||||
|
|
||||||
/// Definition of request message codes
|
/// Definition of request message codes
|
||||||
|
|
@ -58,7 +58,7 @@ struct RequestMsg {
|
||||||
uint8_t crc = 0;
|
uint8_t crc = 0;
|
||||||
crc = modules::crc::CRC8::CCITT_updateCX(0, (uint8_t)code);
|
crc = modules::crc::CRC8::CCITT_updateCX(0, (uint8_t)code);
|
||||||
crc = modules::crc::CRC8::CCITT_updateCX(crc, value);
|
crc = modules::crc::CRC8::CCITT_updateCX(crc, value);
|
||||||
crc = modules::crc::CRC8::CCITT_updateCX(crc, value2);
|
crc = modules::crc::CRC8::CCITT_updateW(crc, value2);
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,5 @@ TEST_CASE("application::ReportVersion", "[application]") {
|
||||||
|
|
||||||
application.ReportReadRegister(mp::RequestMsg(mp::RequestMsgCodes::Version, 0));
|
application.ReportReadRegister(mp::RequestMsg(mp::RequestMsgCodes::Version, 0));
|
||||||
|
|
||||||
REQUIRE(modules::serial::tx == "S0 A2*54\n");
|
REQUIRE(modules::serial::tx == "S0 A2*37\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,9 @@ std::string MakeCRC(const std::string_view src) {
|
||||||
// code
|
// code
|
||||||
uint8_t crc = modules::crc::CRC8::CCITT_updateCX(0, src[0]);
|
uint8_t crc = modules::crc::CRC8::CCITT_updateCX(0, src[0]);
|
||||||
// scan hex value
|
// scan hex value
|
||||||
uint16_t rqValue = std::stoul(src.data() + 1, nullptr, 16);
|
uint8_t rqValue = std::stoul(src.data() + 1, nullptr, 16);
|
||||||
crc = modules::crc::CRC8::CCITT_updateW(crc, rqValue);
|
crc = modules::crc::CRC8::CCITT_updateCX(crc, rqValue);
|
||||||
|
crc = modules::crc::CRC8::CCITT_updateW(crc, 0);
|
||||||
if (!src[2])
|
if (!src[2])
|
||||||
return MakeCRC(crc); // eof
|
return MakeCRC(crc); // eof
|
||||||
// [2] is a space
|
// [2] is a space
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ set(PROJECT_VERSION_MINOR
|
||||||
CACHE STRING "Project minor version" FORCE
|
CACHE STRING "Project minor version" FORCE
|
||||||
)
|
)
|
||||||
set(PROJECT_VERSION_REV
|
set(PROJECT_VERSION_REV
|
||||||
2
|
3
|
||||||
CACHE STRING "Project revision" FORCE
|
CACHE STRING "Project revision" FORCE
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue