Skip to content
Snippets Groups Projects
Commit be3d5d6b authored by Jens Georg's avatar Jens Georg
Browse files

Implement CRC in dummy

Removes need for call to_upper() which would also cause trouble because
the CRC values would not match if the string is modified after
caluclating the CRC

Implements #6654
parent 38457cc6
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
#include <tec/TecFrame.h>
#include <boost/algorithm/string.hpp>
#include <boost/crc.hpp>
#include <sstream>
TecDummy::BackendRegisterer TecDummy::backendRegisterer;
......@@ -49,7 +49,6 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB
// perform data processing
auto frameReply = processFrame(frameData);
boost::to_upper(frameReply);
// append to answer
frameReply += "\r";
......@@ -117,8 +116,16 @@ std::map<TecDummy::TecFramePart, std::string> TecDummy::splitFrame(const std::st
return result;
}
std::string TecDummy::getCrc(std::string&) {
return std::string{"DEAD"};
std::string TecDummy::getCrc(std::string& data) {
// CRC-16 CCITT, but with initial value 0 instead of 0xFFFF
boost::crc_ccitt_type crc{0};
crc.process_bytes(data.c_str(), data.length());
std::stringstream ss;
ss << std::hex << std::setw(4) << std::setfill('0') << std::uppercase << crc.checksum();
return ss.str();
}
std::string TecDummy::processFrame(const std::string& command) {
......@@ -146,7 +153,7 @@ std::string TecDummy::processFrame(const std::string& command) {
parameterId = std::stoul("0x" + parsedFrame[TecFramePart::PARAMETER_ID], 0, 16);
result = "!" + parsedFrame[TecFramePart::ADDRESS] + parsedFrame[TecFramePart::SEQUENCE];
std::stringstream ss;
ss << std::hex << std::setw(8) << std::setfill('0') << rawValues[static_cast<TecFrame::TecParameter>(parameterId)];
ss << std::hex << std::setw(8) << std::setfill('0') << std::uppercase << rawValues[static_cast<TecFrame::TecParameter>(parameterId)];
result += ss.str();
result += getCrc(result);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment