diff --git a/modules/include/TecErrorCode.h b/modules/include/TecErrorCode.h index 21594457b791b8501f2b8f1fb792c887a97911b9..8d9500d19dd60c671dd9d18d6ba4bb1c6f321b34 100644 --- a/modules/include/TecErrorCode.h +++ b/modules/include/TecErrorCode.h @@ -1,6 +1,9 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later #pragma once #include <map> +#include <string> /** The codes are defined in the MeCom Protocol Specification by meerstetter, document ID 5117C Section 1.3.4 * "Server Error Codes" on page 4. */ enum class TecErrorCode { diff --git a/modules/include/TecModule.h b/modules/include/TecModule.h index c42364eadb58adccf935fe5fe2a6314f4001ab05..f300c2f9286b74622ca267b3bca59031177e99c5 100644 --- a/modules/include/TecModule.h +++ b/modules/include/TecModule.h @@ -1,3 +1,5 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later #pragma once #include <tec/TecChimeraInterface.h> @@ -103,7 +105,4 @@ struct TecModule : ctk::ApplicationModule { std::shared_ptr<TecChimeraInterface> tecIface; TecController tec{tecIface}; - - private: - std::string getErrorString(TecFrame& f); }; diff --git a/modules/include/TecParameters.h b/modules/include/TecParameters.h index 7454f4879e59e269a8501c8075451245eb63efea..3de580d4ae9b56d6dae5922c2b796aa2086092fe 100644 --- a/modules/include/TecParameters.h +++ b/modules/include/TecParameters.h @@ -1,27 +1,31 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later #pragma once -#include <map> + #include <tec/TecFrame.h> + #include <list> +#include <map> enum class ValueType { Int, Float }; enum class Direction { Read, ReadWrite }; struct ParameterDescriptor { - /// Base name of the process varable (aka DOOCS property), without ".RD", ".RW" suffix etc. + /// Base name of the process variable (aka DOOCS property), without ".RD", ".RW" suffix etc. std::string pvName; /// TecParameter identifier for the hardware protocol - TecFrame::TecParameter value; + TecFrame::TecParameter value{TecFrame::TecParameter::ErrorParameter}; /// Value type - ValueType valueType; + ValueType valueType{ValueType::Int}; /// Direction - Direction direction; + Direction direction{Direction::ReadWrite}; /// Engineering unit std::string unit; - /// Parameter desccription + /// Parameter description std::string description; /// Base name of the process variable for the read-group command @@ -384,37 +388,3 @@ static std::list<ParameterDescriptor> descriptors{ {"ctrl_ch1_sensorTypeSelection", TecFrame::TecParameter::ExpObjMeasSensorTypeSelection, ValueType::Int, Direction::ReadWrite, "unit", "description", "readCh1WriteGroup14", "writeCh1Group14", "writeToFlashCh1Group14", "setRbCh1Group14"}}; - -bool checkDescriptorsList() { - std::cout << "checkDescriptorsList():: Checking descriptors list structure." << std::endl; - bool error = false; - std::map<TecFrame::TecParameter, ParameterDescriptor> tecParameterMap; - std::map<std::string, ParameterDescriptor> pvNameMap; - for(const auto& descriptor : descriptors) { - // first check if there is no twice the same TecFrame::TecParameter - if(tecParameterMap.find(descriptor.value) == tecParameterMap.end()) - tecParameterMap[descriptor.value] = descriptor; - else { - error = true; - std::cout << "checkDescriptorsList():: Descriptor with TecFrame::TecParameter " << descriptor.value - << " already in the list." << std::endl; - } - // check if there is no twice the same pvName - if(pvNameMap.find(descriptor.pvName) == pvNameMap.end()) - pvNameMap[descriptor.pvName] = descriptor; - else { - error = true; - std::cout << "checkDescriptorsList():: Descriptor with pvName " << descriptor.pvName << " already in the list." - << std::endl; - } - } - - if(error) { - std::cout << "checkDescriptorsList():: Descriptors list structure is NOT CORRECT!" << std::endl; - } - else { - std::cout << "checkDescriptorsList():: Descriptors list structure is CORRECT!" << std::endl; - } - - return !error; -} diff --git a/modules/src/TecModule.cc b/modules/src/TecModule.cc index 23c8bb4c6e4fc4079b47a893e786d5a8495d405d..36aafb6830cc482370653776d253ea06a53d472c 100644 --- a/modules/src/TecModule.cc +++ b/modules/src/TecModule.cc @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de // SPDX-License-Identifier: LGPL-3.0-or-later #include "TecModule.h" @@ -9,11 +9,72 @@ #include <regex> namespace detail { + // FIXME: - think getErrorString should ideally be a TecFrame class method + // - would be nice to mark TecFrame::getState as const. + // could not use the const qualifier here because method is not + // marked const + // - Nice if TecFrame::getErrorCode could return TecErrorCode enum + // + static std::string getErrorString(TecFrame& f) { + switch(f.getState()) { + case TecFrame::TecFrameCRCError: + return "Failed CRC check on frame."; + case TecFrame::TecFrameTimedOut: + return "Tec frame timed out"; + case TecFrame::TecFrameWithError: + return TecErrorDescriptions.at(static_cast<TecErrorCode>(f.getErrorCode())); + default: + return ""; + } + } + + /**********************************************************************************************************************/ + static bool checkDescriptorsList() { + std::cout << "checkDescriptorsList():: Checking descriptors list structure." << std::endl; + bool error = false; + std::map<TecFrame::TecParameter, ParameterDescriptor> tecParameterMap; + std::map<std::string, ParameterDescriptor> pvNameMap; + for(const auto& descriptor : descriptors) { + // first check if there is no twice the same TecFrame::TecParameter + if(tecParameterMap.find(descriptor.value) == tecParameterMap.end()) { + tecParameterMap[descriptor.value] = descriptor; + } + else { + error = true; + std::cout << "checkDescriptorsList():: Descriptor with TecFrame::TecParameter " << descriptor.value + << " already in the list." << std::endl; + } + // check if there is no twice the same pvName + if(pvNameMap.find(descriptor.pvName) == pvNameMap.end()) { + pvNameMap[descriptor.pvName] = descriptor; + } + else { + error = true; + std::cout << "checkDescriptorsList():: Descriptor with pvName " << descriptor.pvName << " already in the list." + << std::endl; + } + } + + if(error) { + std::cout << "checkDescriptorsList():: Descriptors list structure is NOT CORRECT!" << std::endl; + } + else { + std::cout << "checkDescriptorsList():: Descriptors list structure is CORRECT!" << std::endl; + } + + return !error; + } + static std::string commandToDescription(const std::string& command) { if(command == "write" || command == "read") return command + " of "; if(command == "setRb") return "set from readback for "; - if(command == "writeToFlash") return "write to FLASH of "; + if(command == "writeToFlash") { + return "write to FLASH of "; + } + assert(false); + + return {}; } std::string generateGroupDescription(const std::string& groupName) { @@ -24,25 +85,29 @@ namespace detail { std::string description = "Trigger " + commandToDescription(match[1]); if(match[2].matched) { - if(match[3].matched) + if(match[3].matched) { description += ("channel " + match[3].str() + " "); - else + } + else { description += "autotune "; + } } - else + else { description += "generic "; + } if(match[1] == "read") { description += "read-only parameters group"; - } else + } + else { description += "read-write group"; + } - if (match[7].matched) + if(match[7].matched) { description += (" " + match[7].str()); + } } - else { - assert(false); - } + assert(false); return "description"; } @@ -51,7 +116,7 @@ namespace detail { TecModule::TecModule(EntityOwner* owner, const std::string& name, const std::string& description, ctk::HierarchyModifier hierarchyModifier, const std::unordered_set<std::string>& tags) : ctk::ApplicationModule(owner, name, description, hierarchyModifier, tags) { - assert(checkDescriptorsList()); + assert(detail::checkDescriptorsList()); createReadWriteMaps(); createCommandGroupMaps(); createEnablePeriodicList(); @@ -154,8 +219,9 @@ void TecModule::readPeriodic() { } } - if(enableHeartbeat && readRequests.size() == 0) + if(enableHeartbeat && readRequests.empty()) { readRequests.emplace_back(0, TecFrame::DeviceType, TecFrame::TecFrameType::TecParameterValueRead, 1); + } auto answers = doTecCommunication(readRequests); @@ -238,7 +304,7 @@ void TecModule::doResetDevice() { if(enableDebug) { std::cout << "Error: Frame not parsed, skipping" << std::endl; } - errorlog.append("Device reset failed: " + getErrorString(*frame)); + errorlog.append("Device reset failed: " + detail::getErrorString(*frame)); } } @@ -260,15 +326,15 @@ void TecModule::checkAndUpdateReadResponses(TecFrame* frame, ctk::ScalarOutput<T if(frame->getState() == TecFrame::TecFrameState::TecFrameParsed) { if(accessor.getValueType() == typeid(int)) { - accessor = frame->getIntParameterValue(); + accessor = static_cast<T>(frame->getIntParameterValue()); } else { - accessor = frame->getFloatParameterValue(); + accessor = static_cast<T>(frame->getFloatParameterValue()); } accessor.setDataValidity(ctk::DataValidity::ok); accessor.write(); if(enableDebug) { - std::cout << "Setting " + std::string(accessor.getValueType().name()) + " paramter " + std::cout << "Setting " + std::string(accessor.getValueType().name()) + " parameter " << frame->getParameterOffset() << " to " << accessor << std::endl; } } @@ -276,7 +342,7 @@ void TecModule::checkAndUpdateReadResponses(TecFrame* frame, ctk::ScalarOutput<T if(enableDebug) { std::cout << "Error: Frame not parsed, skipping" << std::endl; } - errorlog.append("Read on " + accessor.getName() + " failed: " + getErrorString(*frame)); + errorlog.append("Read on " + accessor.getName() + " failed: " + detail::getErrorString(*frame)); accessor.setDataValidity(ctk::DataValidity::faulty); accessor.write(); } @@ -289,7 +355,9 @@ void TecModule::writeGroup(std::list<TecFrame::TecParameter>& group) { // create request to disable write to flash std::vector<TecFrame> writeRequests; - writeRequests.emplace_back(0, TecFrame::ParameterSystemFlashSaveOff, TecFrame::TecParameterValueSet, 1, (int)1); + // FIXME: Make the constructors of TecFrame explicit to avoid this cast + writeRequests.emplace_back( + 0, TecFrame::ParameterSystemFlashSaveOff, TecFrame::TecParameterValueSet, 1, static_cast<int>(1)); writeGroupInternal(group, writeRequests); } @@ -301,7 +369,10 @@ void TecModule::writeGroupToFlash(std::list<TecFrame::TecParameter>& group) { // create request to enable write to flash std::vector<TecFrame> writeRequests; - writeRequests.emplace_back(0, TecFrame::ParameterSystemFlashSaveOff, TecFrame::TecParameterValueSet, 1, (int)0); + + // FIXME: Make the constructors of TecFrame explicit to avoid this cast + writeRequests.emplace_back( + 0, TecFrame::ParameterSystemFlashSaveOff, TecFrame::TecParameterValueSet, 1, static_cast<int>(0)); writeGroupInternal(group, writeRequests); } @@ -358,12 +429,13 @@ void TecModule::checkAndUpdateWriteResponses(TecFrame* frame, ctk::ScalarOutput< errorlog.append("Hardware communication timeout limit on write response for " + accessor.getName() + " exceeded."); return; } + if(frame->getState() == TecFrame::TecFrameState::TecFrameParsed) { if(accessor.getValueType() == typeid(int)) { - accessor = frame->getIntParameterValue(); + accessor = static_cast<T>(frame->getIntParameterValue()); } else { - accessor = frame->getFloatParameterValue(); + accessor = static_cast<T>(frame->getFloatParameterValue()); } accessor.write(); } @@ -371,7 +443,7 @@ void TecModule::checkAndUpdateWriteResponses(TecFrame* frame, ctk::ScalarOutput< if(enableDebug) { std::cout << "Error: Frame not parsed, skipping" << std::endl; } - errorlog.append("Write on " + accessor.getName() + " failed: " + getErrorString(*frame)); + errorlog.append("Write on " + accessor.getName() + " failed: " + detail::getErrorString(*frame)); } } @@ -414,9 +486,10 @@ void TecModule::setInputFromOutputGroup(std::list<TecFrame::TecParameter>& group std::vector<std::shared_ptr<TecFrame>> TecModule::doTecCommunication(std::vector<TecFrame>& requests) { // No frames passed, nothing to do - if(requests.size() == 0) return {}; + if(requests.empty()) return {}; std::vector<std::shared_ptr<TecFrame>> answers; + answers.reserve(requests.size()); // add frames tec.clearAllFrames(); @@ -436,8 +509,8 @@ std::vector<std::shared_ptr<TecFrame>> TecModule::doTecCommunication(std::vector if(enableDebug) std::cout << "constructAllFrames:" << std::endl; tec.constructAllFrames(); if(enableDebug) { - for(uint8_t i = 0; i < tec.getFrameCount(); i++) { - tec.getFrameAt(i)->print(); + for(auto i = 0U; i < tec.getFrameCount(); i++) { + tec.getFrameAt(static_cast<uint8_t>(i))->print(); } std::cout << "copyCommandsToHardware:" << std::endl; } @@ -467,7 +540,7 @@ std::vector<std::shared_ptr<TecFrame>> TecModule::doTecCommunication(std::vector if(enableDebug) std::cout << "parseAllFrames:" << std::endl; tec.parseAllFrames(); for(auto i = 0U; i < tec.getFrameCount(); i++) { - answers.push_back(tec.getFrameAt(i)); + answers.push_back(tec.getFrameAt(static_cast<uint8_t>(i))); } } else { // timed out @@ -490,26 +563,6 @@ std::vector<std::shared_ptr<TecFrame>> TecModule::doTecCommunication(std::vector /**********************************************************************************************************************/ -// FIXME: - think getErrorString should ideally be a TecFrame class method -// - would be nice to mark TecFrame::getState as const. -// could not use the const qualifier here because method is not -// marked const -// - Nice if TecFrame::getErrorCode could return TecErrorCode enum -// -std::string TecModule::getErrorString(TecFrame& f) { - switch(f.getState()) { - case TecFrame::TecFrameCRCError: - return "Failed CRC check on frame."; - case TecFrame::TecFrameTimedOut: - return "Tec frame timed out"; - case TecFrame::TecFrameWithError: - return TecErrorDescriptions.at(static_cast<TecErrorCode>(f.getErrorCode())); - default: - return ""; - } -} - -/**********************************************************************************************************************/ void TecModule::ErrorLog::append(const std::string& e) { errorStatus = true; @@ -520,7 +573,7 @@ void TecModule::ErrorLog::append(const std::string& e) { /**********************************************************************************************************************/ void TecModule::ErrorLog::reset() { - errorStatus = 0; + errorStatus = false; errorMessage = ""; dirty = true; } diff --git a/tests/executable_src/testAllParameters.cc b/tests/executable_src/testAllParameters.cc index 9860cfa61c93a3cb8c5c0db58d2a45ca2e27c5ea..8070025d74922c169a3ec272d6f8c380df5b2373 100644 --- a/tests/executable_src/testAllParameters.cc +++ b/tests/executable_src/testAllParameters.cc @@ -1,15 +1,20 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. -#define BOOST_TEST_MODULE testWrite +#define BOOST_TEST_MODULE testAllParameters + // Only after defining the name include the unit test header. #include <boost/test/included/unit_test.hpp> -#include <ChimeraTK/ApplicationCore/TestFacility.h> -#include <ChimeraTK/BackendFactory.h> #include "Server.h" #include "TecDummy.h" #include "TecParameters.h" +#include <ChimeraTK/ApplicationCore/TestFacility.h> +#include <ChimeraTK/BackendFactory.h> + #include <random> using namespace boost::unit_test_framework; @@ -47,12 +52,16 @@ BOOST_FIXTURE_TEST_CASE(testControlSystemVariables, Fixture_t) { BOOST_CHECK_NO_THROW(pvManager->getProcessVariable("/TecModule0/" + params.pvName + "_rd")); auto pv = pvManager->getProcessVariable("/TecModule0/" + params.pvName + "_rd"); BOOST_CHECK(pv->isReadOnly()); - if(params.valueType == ValueType::Int) + if(params.valueType == ValueType::Int) { BOOST_CHECK_MESSAGE(pv->getValueType() == typeid(int), "Check if _rd valueType is integer"); - else if(params.valueType == ValueType::Float) + } + else if(params.valueType == ValueType::Float) { BOOST_CHECK_MESSAGE(pv->getValueType() == typeid(float), "Check if _rd valueType is float"); - else + } + else { BOOST_ASSERT(false); + } + // if this variable exists, it has to be try { @@ -70,12 +79,15 @@ BOOST_FIXTURE_TEST_CASE(testControlSystemVariables, Fixture_t) { pv = pvManager->getProcessVariable("/TecModule0/" + params.pvName + "_wr"); BOOST_CHECK(params.direction == Direction::ReadWrite); BOOST_CHECK(pv->isWriteable()); - if(params.valueType == ValueType::Int) + if(params.valueType == ValueType::Int) { BOOST_CHECK_MESSAGE(pv->getValueType() == typeid(int), "Check if _wr valueType is integer"); - else if(params.valueType == ValueType::Float) + } + else if(params.valueType == ValueType::Float) { BOOST_CHECK_MESSAGE(pv->getValueType() == typeid(float), "Check if _wr valueType is float"); - else + } + else { BOOST_ASSERT(false); + } } catch(ChimeraTK::logic_error&) { // If this variable does not exist, the parameter has to be read-only @@ -84,8 +96,8 @@ BOOST_FIXTURE_TEST_CASE(testControlSystemVariables, Fixture_t) { } // Check if the group accessors exist - for(auto& group : {readGroups, writeGroups, writeToFlashGroups}) { - for(auto& entry : group) { + for(const auto& group : {readGroups, writeGroups, writeToFlashGroups}) { + for(const auto& entry : group) { BOOST_REQUIRE_NO_THROW(pvManager->getProcessVariable("/TecModule0/" + entry + "_wr")); auto pv = pvManager->getProcessVariable("/TecModule0/" + entry + "_wr"); BOOST_CHECK(pv->isWriteable()); @@ -102,10 +114,10 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Prepare a list of random number to use as data for each group // The maximum canaries we need is number of descriptors times 3, if all // descriptors were in all three groups - std::unordered_set<int> canaries; + std::unordered_set<unsigned int> canaries; std::random_device r; while(canaries.size() < descriptors.size() * 3) { - canaries.insert(static_cast<int>(r())); + canaries.insert(r()); } for(auto params = descriptors.begin(); params != descriptors.end(); ++params) { @@ -126,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // And see that all members of the group are now set to the canary value for(auto& group : readGroup) { // Get a unique marker - int canary = *canaries.begin(); + auto canary = *canaries.begin(); canaries.erase(canaries.begin()); // Check that all CS variables are not containing the canary value @@ -142,12 +154,15 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Fill all the parameters in the dummy device that are contained in the group for(auto& param : group.second) { - if(param->valueType == ValueType::Float) + if(param->valueType == ValueType::Float) { dummy->set(param->value, static_cast<float>(canary)); - else if(param->valueType == ValueType::Int) - dummy->set(param->value, canary); - else + } + else if(param->valueType == ValueType::Int) { + dummy->set(param->value, static_cast<int>(canary)); + } + else { BOOST_REQUIRE(false); + } } std::cout << "Testing read group " << group.first << std::endl; @@ -159,7 +174,7 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { for(auto& param : group.second) { if(param->valueType == ValueType::Float) { BOOST_CHECK_CLOSE( - testFacility.readScalar<float>("/TecModule0/" + param->pvName + "_rd"), static_cast<float>(canary), 1e5f); + testFacility.readScalar<float>("/TecModule0/" + param->pvName + "_rd"), static_cast<float>(canary), 1e5F); } else if(param->valueType == ValueType::Int) { BOOST_CHECK_EQUAL(testFacility.readScalar<int>("/TecModule0/" + param->pvName + "_rd"), canary); @@ -170,18 +185,21 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Check normal writing for(auto& group : writeGroup) { // Get a unique marker - int canary = *canaries.begin(); + auto canary = *canaries.begin(); canaries.erase(canaries.begin()); // Write inverse pattern into all parameter registers in the dummy and set the // Last write to flash flag on them for(auto& param : group.second) { - if(param->valueType == ValueType::Float) + if(param->valueType == ValueType::Float) { dummy->set(param->value, static_cast<float>(~canary)); - else if(param->valueType == ValueType::Int) - dummy->set(param->value, ~canary); - else + } + else if(param->valueType == ValueType::Int) { + dummy->set(param->value, static_cast<int>(~canary)); + } + else { BOOST_REQUIRE(false); + } dummy->setLastWriteToFlash(param->value, true); } @@ -194,7 +212,7 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { testFacility.writeScalar<float>("/TecModule0/" + param->pvName + "_wr", static_cast<float>(canary)); } else if(param->valueType == ValueType::Int) { - testFacility.writeScalar<int>("/TecModule0/" + param->pvName + "_wr", canary); + testFacility.writeScalar<int>("/TecModule0/" + param->pvName + "_wr", static_cast<int>(canary)); } } @@ -206,12 +224,15 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Check in dummy that the requested parameters now contain the canary value // and the last write to flash flag was cleared for(auto& param : group.second) { - if(param->valueType == ValueType::Float) - BOOST_CHECK_CLOSE(dummy->getFloat(param->value), static_cast<float>(canary), 1e5f); - else if(param->valueType == ValueType::Int) + if(param->valueType == ValueType::Float) { + BOOST_CHECK_CLOSE(dummy->getFloat(param->value), static_cast<float>(canary), 1e5F); + } + else if(param->valueType == ValueType::Int) { BOOST_CHECK_EQUAL(dummy->getInt(param->value), canary); - else + } + else { BOOST_REQUIRE(false); + } BOOST_REQUIRE(not dummy->getLastWriteToFlash(param->value)); } } @@ -219,18 +240,21 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Check writing to flash for(auto& group : writeToFlashGroup) { // Get a unique marker - int canary = *canaries.begin(); + auto canary = *canaries.begin(); canaries.erase(canaries.begin()); // Check in dummy that the requested parameters do not already contain the canary // and clear the writeToFlash flag for those parameters for(auto& param : group.second) { - if(param->valueType == ValueType::Float) + if(param->valueType == ValueType::Float) { dummy->set(param->value, static_cast<float>(~canary)); - else if(param->valueType == ValueType::Int) - dummy->set(param->value, ~canary); - else + } + else if(param->valueType == ValueType::Int) { + dummy->set(param->value, static_cast<int>(~canary)); + } + else { BOOST_REQUIRE(false); + } dummy->setLastWriteToFlash(param->value, false); } @@ -239,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { testFacility.writeScalar<float>("/TecModule0/" + param->pvName + "_wr", static_cast<float>(canary)); } else if(param->valueType == ValueType::Int) { - testFacility.writeScalar<int>("/TecModule0/" + param->pvName + "_wr", canary); + testFacility.writeScalar<int>("/TecModule0/" + param->pvName + "_wr", static_cast<int>(canary)); } } @@ -253,12 +277,15 @@ BOOST_FIXTURE_TEST_CASE(testGroupValues, Fixture_t) { // Fill all the for(auto& param : group.second) { - if(param->valueType == ValueType::Float) - BOOST_CHECK_CLOSE(dummy->getFloat(param->value), static_cast<float>(canary), 1e5f); - else if(param->valueType == ValueType::Int) - BOOST_CHECK_EQUAL(dummy->getInt(param->value), canary); - else + if(param->valueType == ValueType::Float) { + BOOST_CHECK_CLOSE(dummy->getFloat(param->value), static_cast<float>(canary), 1e5F); + } + else if(param->valueType == ValueType::Int) { + BOOST_CHECK_EQUAL(dummy->getInt(param->value), static_cast<int>(canary)); + } + else { BOOST_REQUIRE(false); + } BOOST_REQUIRE(dummy->getLastWriteToFlash(param->value)); } } diff --git a/tests/executable_src/testCrcErrors.cc b/tests/executable_src/testCrcErrors.cc index f598692f9fcdbf285a6f2d7fa21072883f2411bc..619669f861664fd56072565f11ce6c10467e3596 100644 --- a/tests/executable_src/testCrcErrors.cc +++ b/tests/executable_src/testCrcErrors.cc @@ -1,12 +1,17 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testCrcError // Only after defining the name include the unit test header. #include <boost/test/included/unit_test.hpp> -#include <ChimeraTK/ApplicationCore/TestFacility.h> -#include <ChimeraTK/BackendFactory.h> + #include "Server.h" #include "TecDummy.h" +#include <ChimeraTK/ApplicationCore/TestFacility.h> +#include <ChimeraTK/BackendFactory.h> + using namespace boost::unit_test_framework; struct Fixture_t { @@ -55,7 +60,7 @@ BOOST_FIXTURE_TEST_CASE(testCrcErrorWrite, Fixture_t) { BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 42); BOOST_CHECK(errorMessage.readLatest()); BOOST_CHECK(errorStatus.readLatest()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(errorStatus != 0); dummy->simulateCrcError = false; @@ -71,7 +76,7 @@ BOOST_FIXTURE_TEST_CASE(testCrcErrorWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readLatest()); BOOST_CHECK(errorStatus.readLatest()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(errorStatus == 0); } @@ -108,7 +113,7 @@ BOOST_FIXTURE_TEST_CASE(testSerialTimeoutWriteToFlash, Fixture_t) { BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 42); BOOST_CHECK(errorMessage.readLatest()); BOOST_CHECK(errorStatus.readLatest()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(errorStatus); dummy->simulateCrcError = false; @@ -125,7 +130,7 @@ BOOST_FIXTURE_TEST_CASE(testSerialTimeoutWriteToFlash, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readLatest()); BOOST_CHECK(errorStatus.readLatest()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); } diff --git a/tests/executable_src/testErrorCodes.cc b/tests/executable_src/testErrorCodes.cc index c1597b9d52a440aa01b698f927fd992557f768c3..04a6f54985ccfeae17c387a6e6aae740285f5dbd 100644 --- a/tests/executable_src/testErrorCodes.cc +++ b/tests/executable_src/testErrorCodes.cc @@ -1,12 +1,17 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testErrorCodes // Only after defining the name include the unit test header. #include <boost/test/included/unit_test.hpp> -#include <ChimeraTK/ApplicationCore/TestFacility.h> -#include <ChimeraTK/BackendFactory.h> + #include "Server.h" #include "TecDummy.h" +#include <ChimeraTK/ApplicationCore/TestFacility.h> +#include <ChimeraTK/BackendFactory.h> + using namespace boost::unit_test_framework; struct Fixture_t { @@ -61,7 +66,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { BOOST_CHECK_CLOSE(dummy->getFloat(TecFrame::TecParameter::TemTargetObjectTemp), 0.0, 0.0001); BOOST_CHECK(!errorMessage.readNonBlocking()); BOOST_CHECK(!errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); // inject error in dummy @@ -73,7 +78,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos); BOOST_CHECK(errorStatus); BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1); @@ -85,7 +90,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); // check other variable in different group: no error should be observed @@ -97,7 +102,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { BOOST_CHECK_CLOSE(dummy->getFloat(TecFrame::TecParameter::TemTargetObjectTemp), 3.1415, 0.0001); BOOST_CHECK(!errorMessage.readNonBlocking()); BOOST_CHECK(!errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); // verify that error is still there for the first variable @@ -105,7 +110,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos); BOOST_CHECK(errorStatus); BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1); @@ -119,7 +124,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos); BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanTargetTemp") != std::string::npos); BOOST_CHECK(errorStatus); @@ -143,7 +148,7 @@ BOOST_FIXTURE_TEST_CASE(testOutOfRangeWrite, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); } } @@ -174,7 +179,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { BOOST_CHECK(firmwareVersion.dataValidity() == ctk::DataValidity::ok); // no error for this variable BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") != std::string::npos); BOOST_CHECK(errorStatus); @@ -185,7 +190,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); BOOST_CHECK(!serialNumber.readNonBlocking()); // DataValidity of variables must not change @@ -216,7 +221,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { BOOST_CHECK(firmwareVersion.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") != std::string::npos); BOOST_CHECK(std::string(errorMessage).find("mon_firmwareVersion") != std::string::npos); BOOST_CHECK(errorStatus); @@ -226,7 +231,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); // Clear error in dummy for only one variable and retry read @@ -241,7 +246,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { BOOST_CHECK(firmwareVersion.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") == std::string::npos); BOOST_CHECK(std::string(errorMessage).find("mon_firmwareVersion") != std::string::npos); BOOST_CHECK(errorStatus); @@ -264,7 +269,7 @@ BOOST_FIXTURE_TEST_CASE(testReadOnDemandError, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); } @@ -290,7 +295,7 @@ BOOST_FIXTURE_TEST_CASE(testReadPeriodicError, Fixture_t) { BOOST_CHECK(serialNumber.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") != std::string::npos); BOOST_CHECK(errorStatus); @@ -301,7 +306,7 @@ BOOST_FIXTURE_TEST_CASE(testReadPeriodicError, Fixture_t) { BOOST_CHECK(serialNumber.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") != std::string::npos); BOOST_CHECK(errorStatus); @@ -312,7 +317,7 @@ BOOST_FIXTURE_TEST_CASE(testReadPeriodicError, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); theServer.periodicRead.sendTrigger(); @@ -322,7 +327,7 @@ BOOST_FIXTURE_TEST_CASE(testReadPeriodicError, Fixture_t) { BOOST_CHECK(serialNumber.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_serialNumber") != std::string::npos); BOOST_CHECK(errorStatus); @@ -340,7 +345,7 @@ BOOST_FIXTURE_TEST_CASE(testReadPeriodicError, Fixture_t) { testFacility.stepApplication(); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) == ""); + BOOST_CHECK(std::string(errorMessage).empty()); BOOST_CHECK(not errorStatus); } diff --git a/tests/executable_src/testHeartbeat.cc b/tests/executable_src/testHeartbeat.cc index 04a0c7eb47e0cec0a7ffcd18bf47c9b45d86fc4c..f4030da11813f6f9810185b850d0d0f146811341 100644 --- a/tests/executable_src/testHeartbeat.cc +++ b/tests/executable_src/testHeartbeat.cc @@ -1,13 +1,17 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testHeartbeat // Only after defining the name include the unit test header. #include <boost/test/included/unit_test.hpp> -#include <ChimeraTK/ApplicationCore/TestFacility.h> #include "Server.h" #include "TecDummy.h" +#include <ChimeraTK/ApplicationCore/TestFacility.h> + namespace ctk = ChimeraTK; // Declare the server instance @@ -143,7 +147,7 @@ BOOST_FIXTURE_TEST_CASE(testHearbeatFailCausesModuleError, Fixture_t) { BOOST_CHECK(deviceType.dataValidity() == ctk::DataValidity::faulty); BOOST_CHECK(errorMessage.readNonBlocking()); BOOST_CHECK(errorStatus.readNonBlocking()); - BOOST_CHECK(std::string(errorMessage) != ""); + BOOST_CHECK(not std::string(errorMessage).empty()); BOOST_CHECK(std::string(errorMessage).find("mon_deviceType") != std::string::npos); BOOST_CHECK(errorStatus); BOOST_CHECK_EQUAL(setDeviceType, deviceType); diff --git a/tests/executable_src/testReadOnDemand.cc b/tests/executable_src/testReadOnDemand.cc index 874bf29ab7e08054dde4296d5b1a3dfa86b46f97..305f91f6550a39427bf92a885dc3e1194f7fabed 100644 --- a/tests/executable_src/testReadOnDemand.cc +++ b/tests/executable_src/testReadOnDemand.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testRead // Only after defining the name include the unit test header. diff --git a/tests/executable_src/testReadPeriodic.cc b/tests/executable_src/testReadPeriodic.cc index a05dd0d78808b64293fc2669a68165e7b755669a..6151ab93e681f9596a25ca019cfcaa2ec6cd6fd8 100644 --- a/tests/executable_src/testReadPeriodic.cc +++ b/tests/executable_src/testReadPeriodic.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testReadPriodic // Only after defining the name include the unit test header. @@ -64,7 +67,7 @@ BOOST_AUTO_TEST_CASE(testPeriodicReadFloat) { std::cout << "temperature:" << temperature << std::endl; BOOST_CHECK_EQUAL(temperature, 0.0); - auto setTemperatureValue = 0.002f; + auto setTemperatureValue = 0.002F; for(auto i = 0; i < 6; i++) { setTemperatureValue = setTemperatureValue * 10.0f; TECDummy->set(TecFrame::TecParameter::MonSinkTemperature, setTemperatureValue); diff --git a/tests/executable_src/testTecModule.cc b/tests/executable_src/testTecModule.cc index 39a00b856b8ca40363eee764ee9736e525ca1299..312c5bf5908528fc82852664490d6e8f029cd4d0 100644 --- a/tests/executable_src/testTecModule.cc +++ b/tests/executable_src/testTecModule.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testTemplateServer // Only after defining the name include the unit test header. diff --git a/tests/executable_src/testTimeout.cc b/tests/executable_src/testTimeout.cc index 25efe980b12091334d6bfd64885d8820e1f1dd40..1a8efdab23144056447cec8ab7fb4162da8c5e07 100644 --- a/tests/executable_src/testTimeout.cc +++ b/tests/executable_src/testTimeout.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testTimeout // Only after defining the name include the unit test header. diff --git a/tests/executable_src/testWrite.cc b/tests/executable_src/testWrite.cc index aa1355a01feda7518770969aa44c1ceb34e6243d..6ae1a8be68df26818de9166c3a5244272eec94b7 100644 --- a/tests/executable_src/testWrite.cc +++ b/tests/executable_src/testWrite.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + // Define a name for the test module. #define BOOST_TEST_MODULE testWrite // Only after defining the name include the unit test header. diff --git a/tests/include/TecDummy.h b/tests/include/TecDummy.h index d439f591e5081a5e0ba29b3b77173da95109c348..4ca4d25d463c11cbbf3143cc45365d91aa004994 100644 --- a/tests/include/TecDummy.h +++ b/tests/include/TecDummy.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + #pragma once #include <ChimeraTK/DummyBackend.h> @@ -9,11 +12,11 @@ #include "TecErrorCode.h" struct TecDummy : ChimeraTK::DummyBackend { - TecDummy(std::string mapFileName) : DummyBackend(mapFileName) { + explicit TecDummy(const std::string& mapFileName) : DummyBackend(mapFileName) { // inititialize write to flash as disabled on startup; rawValues[TecFrame::ParameterSystemFlashSaveOff] = 1; } - ~TecDummy() override {} + ~TecDummy() override = default; enum class TecFramePart { MARKER, @@ -28,8 +31,12 @@ struct TecDummy : ChimeraTK::DummyBackend { // getter and setter functions for parameters int getInt(TecFrame::TecParameter param) { return rawValues[param]; } + // FIXME: Find a better way to do this + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) float getFloat(TecFrame::TecParameter param) { return *(reinterpret_cast<float*>(&(rawValues[param]))); } void set(TecFrame::TecParameter param, int value) { rawValues[param] = value; } + // FIXME: Find a better way to do this + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) void set(TecFrame::TecParameter param, float value) { rawValues[param] = *(reinterpret_cast<int*>(&value)); } // returns whether the last write operation for the given parameter was stored in flash or not. Will return false @@ -52,8 +59,8 @@ struct TecDummy : ChimeraTK::DummyBackend { // time again. size_t loopDoneDelay{0}; - // Map containin error flags which will be sent back as a reply during the next communication for the given parameter. - // A value of zero or the absense of a value results in no error being generated. + // Map containing error flags which will be sent back as a reply during the next communication for the given parameter. + // A value of zero or the absence of a value results in no error being generated. std::map<TecFrame::TecParameter, TecErrorCode> errorFlags; protected: @@ -81,8 +88,8 @@ struct TecDummy : ChimeraTK::DummyBackend { void read(uint64_t bar, uint64_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); + static std::map<TecFramePart, std::string> splitFrame(const std::string& command); + std::string getCrc(std::string& frame) const; // 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 3df77cb37b999ed747899c06dc44d193bd1c0d44..2c8dbb3a2d8906b3a95a65bd293a798a96654960 100644 --- a/tests/src/TecDummy.cc +++ b/tests/src/TecDummy.cc @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, http://msk.desy.de +// SPDX-License-Identifier: LGPL-3.0-or-later + #include "TecDummy.h" #include <arpa/inet.h> @@ -83,29 +86,29 @@ void TecDummy::read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeIn // convert command into string // FIXME: this can be done better if the DummyRegisterRawAccessor would allow us to use the raw pointer to this... - std::string commandString(reg_command.getNumberOfElements() * 4, 0); - for(size_t i = 0; i < reg_command.getNumberOfElements(); ++i) { + std::string commandString(reg_command.getNumberOfElements() * 4UL, 0); + for(auto i = 0U; i < reg_command.getNumberOfElements(); ++i) { uint32_t word = ntohl(reg_command[i]); - std::memcpy(&(commandString[4 * i]), &word, 4); + std::memcpy(&(commandString[4UL * i]), &word, 4); } // process frame by frame constexpr size_t nFrames = 16; - constexpr size_t frameLength = 16 * 4; + constexpr size_t frameLength = 16 * 4UL; 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"); + auto endOfFrame = frameData.find_first_of('\r'); if(endOfFrame == std::string::npos) { reply += std::string(frameLength, '\0'); continue; } frameData.erase(endOfFrame); - std::string frameReply{""}; + std::string frameReply; if(not simulateSerialTimeout) { // perform data processing frameReply = processFrame(frameData); @@ -131,7 +134,7 @@ void TecDummy::read(uint64_t bar, uint64_t address, int32_t* data, size_t sizeIn for(size_t i = 0; i < reply.length() / 4; ++i) { uint32_t word; std::memcpy(&word, &(reply[4 * i]), 4); - reg_command[i] = htonl(word); + reg_command[static_cast<unsigned int>(i)] = htonl(word); } *data = 1; } @@ -189,7 +192,7 @@ std::map<TecDummy::TecFramePart, std::string> TecDummy::splitFrame(const std::st return result; } -std::string TecDummy::getCrc(std::string& data) { +std::string TecDummy::getCrc(std::string& data) const { // CRC-16 CCITT, no reflections, no final xor , with an initial value 0 - which boils down to the XMODEM variant of // the CRC16-CCITT. boost::crc_xmodem_t crc; @@ -197,7 +200,7 @@ std::string TecDummy::getCrc(std::string& data) { crc.process_bytes(data.c_str(), data.length()); if(this->simulateCrcError) { - crc.process_byte(rand() % std::numeric_limits<uint8_t>::max()); + crc.process_byte(static_cast<unsigned char>(rand() % std::numeric_limits<uint8_t>::max())); } std::stringstream ss; @@ -209,7 +212,7 @@ std::string TecDummy::getCrc(std::string& data) { std::string TecDummy::processFrame(const std::string& command) { std::cout << "TecDummy::processFrame() command = " << command << std::endl; auto parsedFrame = splitFrame(command); - std::string result = ""; + std::string result; // extract parameter ID auto parameterId = @@ -236,7 +239,7 @@ std::string TecDummy::processFrame(const std::string& command) { result += getCrc(result); } // Handle store command - int32_t value = std::stol("0x" + parsedFrame[TecFramePart::PAYLOAD], nullptr, 16); + int32_t value = static_cast<int32_t>(std::stol("0x" + parsedFrame[TecFramePart::PAYLOAD], nullptr, 16)); std::cout << "Storing raw value " << value << "(" << parsedFrame[TecFramePart::PAYLOAD] << ") for parameter " << parameterId << std::endl; @@ -251,7 +254,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; + auto isLastWriteToFlash = rawValues.at(TecFrame::ParameterSystemFlashSaveOff) == 0; lastWriteToFlash[parameterId] = isLastWriteToFlash; } else if(parsedFrame[TecFramePart::COMMAND] == "?VR") {