Skip to content
Snippets Groups Projects
Commit 7a44fe29 authored by Tomasz Kozak's avatar Tomasz Kozak
Browse files

Fix bug that lastWriteToFlash was accesed in wrong place

parent 933afdd0
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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;
......
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