diff --git a/tests/include/TecDummy.h b/tests/include/TecDummy.h index 8d06c17e4959d6bab8ee8dc32ee013b21a6cd8e1..81772192b73440677b3e05028f04e7a13bbae71c 100644 --- a/tests/include/TecDummy.h +++ b/tests/include/TecDummy.h @@ -10,21 +10,20 @@ struct TecDummy : ChimeraTK::DummyBackend { TecDummy(std::string mapFileName) : DummyBackend(mapFileName) { - // inititialize write to flash as disabled on startup; + // inititialize write to flash as disabled on startup; rawValues[TecFrame::ParameterSystemFlashSaveOff] = 1; - } ~TecDummy() override {} enum class TecFramePart { - MARKER, - ADDRESS, - SEQUENCE, - COMMAND, - PARAMETER_ID, - CHANNEL, - PAYLOAD, - CRC, + MARKER, + ADDRESS, + SEQUENCE, + COMMAND, + PARAMETER_ID, + CHANNEL, + PAYLOAD, + CRC, }; // getter and setter functions for parameters @@ -35,7 +34,10 @@ struct TecDummy : ChimeraTK::DummyBackend { // returns whether the last write operation for the given parameter was stored in flash or not. Will return false // if the parameter has not been yet at all. - bool getLastWriteToFlash(TecFrame::TecParameter param) { return lastWriteToFlash[param]; } + bool getLastWriteToFlash(TecFrame::TecParameter param) { + if(lastWriteToFlash.find(param) != lastWriteToFlash.end()) return lastWriteToFlash.at(param); + return false; + } // flag whether timeouts should be simulated. This simulates e.g. a broken UART connection between FPGA and TEC device bool simulateSerialTimeout{false}; @@ -75,8 +77,8 @@ struct TecDummy : ChimeraTK::DummyBackend { void read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes) override; - std::map<TecFramePart, std::string> splitFrame(const std::string &command); - std::string getCrc(std::string &frame); + std::map<TecFramePart, std::string> splitFrame(const std::string& command); + std::string getCrc(std::string& frame); // In this function the TEC device is actually simulated. std::string processFrame(const std::string& command); diff --git a/tests/src/TecDummy.cc b/tests/src/TecDummy.cc index aad297274d9d31247e36260e24050fc958acffa7..719827a8cfe56c227c4b852722cd16ceac638af9 100644 --- a/tests/src/TecDummy.cc +++ b/tests/src/TecDummy.cc @@ -160,6 +160,11 @@ std::string TecDummy::processFrame(const std::string& command) { rawValues[parameterId] = value; result = "!" + parsedFrame[TecFramePart::ADDRESS] + parsedFrame[TecFramePart::SEQUENCE]; result += getCrc(result); + + // + // mark received parameter as written to flash or not + auto isLastWriteToFlash = (not rawValues.at(TecFrame::ParameterSystemFlashSaveOff)) ? true : false; + lastWriteToFlash[parameterId] = isLastWriteToFlash; } else if(parsedFrame[TecFramePart::COMMAND] == "?VR") { // Handle read command @@ -170,10 +175,7 @@ std::string TecDummy::processFrame(const std::string& command) { result += getCrc(result); } - // - // mark received parameter as written to flash or not - auto isLastWriteToFlash = (not rawValues.at(TecFrame::ParameterSystemFlashSaveOff)) ? true : false; - lastWriteToFlash[parameterId] = isLastWriteToFlash; + std::cout << "Returning result " << result << std::endl;