From dae690d1af88066e92325734aec8b9be83ca6253 Mon Sep 17 00:00:00 2001 From: Martin Hierholzer <martin.hierholzer@desy.de> Date: Mon, 23 Mar 2020 14:53:28 +0100 Subject: [PATCH] split command string into frames --- tests/include/TecDummy.h | 2 +- tests/src/TecDummy.cc | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/include/TecDummy.h b/tests/include/TecDummy.h index 536b60f..1e33e09 100644 --- a/tests/include/TecDummy.h +++ b/tests/include/TecDummy.h @@ -24,7 +24,7 @@ struct TecDummy : ChimeraTK::DummyBackend { void read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes) override; // In this function the TEC device is actually simulated. - std::string dataProcessing(const std::string& command); + std::string processFrame(const std::string& command); class BackendRegisterer { public: diff --git a/tests/src/TecDummy.cc b/tests/src/TecDummy.cc index 3a3d337..12b7d31 100644 --- a/tests/src/TecDummy.cc +++ b/tests/src/TecDummy.cc @@ -25,8 +25,31 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB std::memcpy(&(commandString[4 * i]), &word, 4); } - // perform data processing - auto reply = dataProcessing(commandString); + // process frame by frame + constexpr size_t nFrames = 16; + constexpr size_t frameLength = 16 * 4; + std::string reply; + for(size_t frame = 0; frame < nFrames; ++frame) { + size_t start = frame * frameLength + 8; + auto frameData = commandString.substr(start, frameLength); + + // remove everything from the 0x0D character, because only 0x00 following + auto endOfFrame = frameData.find_first_of("\r"); + if(endOfFrame == std::string::npos) { + reply += std::string(frameLength, '\0'); + continue; + } + frameData.erase(endOfFrame); + + // perform data processing + auto frameReply = processFrame(frameData); + + // append to answer + frameReply += "\r"; + frameReply += std::string(frameLength - frameReply.size(), '\0'); + reply += frameReply; + } + assert(reply.size() == nFrames * frameLength); // convert reply back into byte stream for(size_t i = 0; i < reply.length(); ++i) { @@ -40,11 +63,11 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB /*********************************************************************************************************************/ -std::string TecDummy::dataProcessing(const std::string& command) { +std::string TecDummy::processFrame(const std::string& command) { // Place data processing code here. Parse data from the "command" dummy accessor and place the reply on the same // accessor. Just return this function, the done flag is automatically set by the caller. Remove this comment after // implementation. - std::cout << "TecDummy::dataProcessing() command = " << command << std::endl; + std::cout << "TecDummy::processFrame() command = " << command << std::endl; return "MY REPLY"; } -- GitLab