diff --git a/tests/src/TecDummy.cc b/tests/src/TecDummy.cc index 21539f1fe491ac5b786bf056d6b0e7bb2564f876..9acbd36b382b6565adfc0dbdfda28452b23c41a0 100644 --- a/tests/src/TecDummy.cc +++ b/tests/src/TecDummy.cc @@ -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); }