diff --git a/tests/src/TecDummy.cc b/tests/src/TecDummy.cc index ddef712b22ea28a847900cffdc45c48f7e9aa0bd..9b4dd5ddf92a46124cc5905ba70f695508949f6b 100644 --- a/tests/src/TecDummy.cc +++ b/tests/src/TecDummy.cc @@ -22,11 +22,10 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB if(bar != TecDummy_bar || address != TecDummy_address_loopDone) return; if(reg_loopStart != 1) return; - if (loopDoneDelay) { + if(loopDoneDelay) { loopDoneDelay--; return; } - // convert command into string // FIXME: this can be done better if the DummyRegisterRawAccessor would allow us to use the raw pointer to this... @@ -53,13 +52,16 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB frameData.erase(endOfFrame); std::string frameReply{""}; - if(!simulateSerialTimeout){ + if(!simulateSerialTimeout) { // perform data processing frameReply = processFrame(frameData); } - else{ + else { // In case of timeout, the marker is written to the start of the frame - const uint32_t timeoutMarker{TEC_TIMEOUT}; + // The byte order is swapped here to compensate swapping of the reg_command, + // this is neccessary, because the TEC lib checks the timeout marker before + // changing the byte order of the received frame. + const uint32_t timeoutMarker{htonl(TEC_TIMEOUT)}; frameReply = std::string(sizeof(uint32_t), '\0'); std::memcpy(&(frameReply[0]), &timeoutMarker, sizeof(uint32_t)); } @@ -68,7 +70,6 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB frameReply += "\r"; frameReply += std::string(frameLength - frameReply.size(), '\0'); reply += frameReply; - } assert(reply.size() == nFrames * frameLength); @@ -78,7 +79,6 @@ void TecDummy::read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInB std::memcpy(&word, &(reply[4 * i]), 4); reg_command[i] = htonl(word); } - *data = 1; } @@ -165,7 +165,8 @@ std::string TecDummy::processFrame(const std::string& command) { // Handle store command int32_t value = std::stol("0x" + parsedFrame[TecFramePart::PAYLOAD], nullptr, 16); - std::cout << "Storing raw value " << value << "(" << parsedFrame[TecFramePart::PAYLOAD] << ") for parameter " << parameterId << std::endl; + std::cout << "Storing raw value " << value << "(" << parsedFrame[TecFramePart::PAYLOAD] << ") for parameter " + << parameterId << std::endl; rawValues[parameterId] = value; result = "!" + parsedFrame[TecFramePart::ADDRESS] + parsedFrame[TecFramePart::SEQUENCE];