Skip to content
Snippets Groups Projects
Commit 8e287197 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

wip #6587: small refactoring of TecDummy::processFrame()

parent 6feb1544
No related branches found
No related tags found
No related merge requests found
......@@ -126,27 +126,24 @@ std::string TecDummy::processFrame(const std::string& command) {
auto parsedFrame = splitFrame(command);
std::string result = "";
// lastWriteToFlash[TecFrame::ParameterSystemFlashSaveOff] should be a
// safe default. TecFrame::ParameterSystemFlashSaveOff is a dummy entry for
// lastWriteToFlash.
uint32_t parameterId = TecFrame::ParameterSystemFlashSaveOff;
// extract parameter ID
auto parameterId =
static_cast<TecFrame::TecParameter>(std::stoul("0x" + parsedFrame[TecFramePart::PARAMETER_ID], nullptr, 16));
// Handle store command
if(parsedFrame[TecFramePart::COMMAND] == "VS") {
parameterId = std::stoul("0x" + parsedFrame[TecFramePart::PARAMETER_ID], 0, 16);
int32_t value = std::stol("0x" + parsedFrame[TecFramePart::PAYLOAD], 0, 16);
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;
rawValues[static_cast<TecFrame::TecParameter>(parameterId)] = value;
rawValues[parameterId] = value;
result = "!" + parsedFrame[TecFramePart::ADDRESS] + parsedFrame[TecFramePart::SEQUENCE];
result += getCrc(result);
}
else if(parsedFrame[TecFramePart::COMMAND] == "?VR") {
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') << rawValues[parameterId];
result += ss.str();
result += getCrc(result);
}
......@@ -154,7 +151,7 @@ std::string TecDummy::processFrame(const std::string& command) {
//
// mark received parameter as written to flash or not
auto isLastWriteToFlash = (not rawValues.at(TecFrame::ParameterSystemFlashSaveOff)) ? true : false;
lastWriteToFlash[static_cast<TecFrame::TecParameter>(parameterId)] = isLastWriteToFlash;
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