diff --git a/.oclint b/.oclint index 4550abf..344ddc2 100644 --- a/.oclint +++ b/.oclint @@ -1,6 +1,9 @@ disable-rules: - LongMethod # HighNcssMethod is enough -rule-paths: [] + - AvoidDefaultArgumentsOnVirtualMethods +rule-paths: + - /usr/local/lib/oclint/rules + - libs/oclint/oclint-rules/build/rules.dl rule-configurations: - key: LONG_LINE value: 120 diff --git a/include/regilo/hokuyocontroller.hpp b/include/regilo/hokuyocontroller.hpp index 68268a0..d1836a4 100644 --- a/include/regilo/hokuyocontroller.hpp +++ b/include/regilo/hokuyocontroller.hpp @@ -67,8 +67,12 @@ class HokuyoController : public IHokuyoController, public ScanControllercreateFormattedCommand(CMD_GET_SCAN, fromStep, toStep, clusterCount); } - virtual bool parseScanData(std::istream& in, ScanData& data) override; + virtual inline std::string getScanCommand() const override + { + return this->createFormattedCommand(CMD_GET_SCAN, fromStep, toStep, clusterCount); + } + + virtual bool parseScanData(std::istream& input, ScanData& data) override; public: static std::string CMD_GET_VERSION; ///< A command for getting the scanner version. @@ -126,13 +130,15 @@ HokuyoController::HokuyoController() : ScanController -HokuyoController::HokuyoController(const std::string& logPath) : ScanController(logPath) +HokuyoController::HokuyoController(const std::string& logPath) : + ScanController(logPath) { this->RESPONSE_END = "\n\n"; } template -HokuyoController::HokuyoController(std::iostream& logStream) : ScanController(logStream) +HokuyoController::HokuyoController(std::iostream& logStream) : + ScanController(logStream) { this->RESPONSE_END = "\n\n"; } @@ -140,31 +146,35 @@ HokuyoController::HokuyoController(std::iostream& logStream) template std::map HokuyoController::getVersionInfo() { + if(ProtocolController::template sendCommand(CMD_GET_VERSION) != '0') + { + return std::map(); + } + std::map versionInfo; + std::string line; - if(ProtocolController::template sendCommand(CMD_GET_VERSION) == '0') + while(std::getline(this->deviceOutput, line)) { - std::string line; - while(std::getline(this->deviceOutput, line)) - { - if(line.empty()) continue; + if(line.empty()) continue; - std::size_t colonPos = line.find(':'); - std::string name = line.substr(0, colonPos); - std::string value = line.substr(colonPos + 1); + std::size_t colonPos = line.find(':'); + std::string name = line.substr(0, colonPos); + std::string value = line.substr(colonPos + 1); - boost::algorithm::trim(name); - boost::algorithm::trim(value); + boost::algorithm::trim(name); + boost::algorithm::trim(value); - versionInfo[name] = value; - } + versionInfo[name] = value; } return versionInfo; } template -void HokuyoController::setScanParameters(std::size_t fromStep, std::size_t toStep, std::size_t clusterCount) +void HokuyoController::setScanParameters( + std::size_t fromStep, std::size_t toStep, std::size_t clusterCount +) { if(fromStep > maxStep) throw std::invalid_argument("Invalid fromStep argument."); if(toStep > maxStep) throw std::invalid_argument("Invalid fromStep argument."); @@ -177,22 +187,22 @@ void HokuyoController::setScanParameters(std::size_t fromSte } template -bool HokuyoController::parseScanData(std::istream& in, ScanData& data) +bool HokuyoController::parseScanData(std::istream& input, ScanData& data) { char status; - in >> status; + input >> status; if(status != '0') return false; double resolution = M_PI / 512; int lastIndex = 0; std::size_t step = fromStep - 1; - while(in) + while(input) { step++; char high, low; - in >> high >> low; + input >> high >> low; if(step < validFromStep || step > validToStep) continue; diff --git a/include/regilo/neatocontroller.hpp b/include/regilo/neatocontroller.hpp index 1ad21ca..e5e37d7 100644 --- a/include/regilo/neatocontroller.hpp +++ b/include/regilo/neatocontroller.hpp @@ -32,6 +32,8 @@ namespace regilo { +namespace balg = boost::algorithm; + /** * @brief The INeatoController interface is used for the NeatoController class. */ @@ -80,7 +82,8 @@ class INeatoController : public virtual IScanController /** * @brief Set the specified motor to run in a direction at a requested speed. * @param left Distance in millimeters to drive the left wheel (pos = forward, neg = backward). - * @param right Distance in millimeters to drive the right wheel (pos = forward, neg = backward). + * @param right Distance in millimeters to drive the right wheel (pos = forward, + * neg = backward). * @param speed Speed in millimeters/second. */ virtual void setMotor(int left, int right, int speed) = 0; @@ -104,11 +107,11 @@ class NeatoController : public INeatoController, public ScanController NeatoSerialController; typedef NeatoController NeatoSocketController; template -std::string NeatoController::ON = "on"; +std::string NeatoController::ON_VALUE = "on"; template -std::string NeatoController::OFF = "off"; +std::string NeatoController::OFF_VALUE = "off"; template -std::string NeatoController::LDS_SCAN_HEADER = "AngleInDegrees,DistInMM,Intensity,ErrorCodeHEX"; +std::string NeatoController::LDS_SCAN_HEADER = + "AngleInDegrees,DistInMM,Intensity,ErrorCodeHEX"; template std::string NeatoController::LDS_SCAN_FOOTER = "ROTATION_SPEED,"; @@ -197,13 +201,15 @@ NeatoController::NeatoController() : ScanController -NeatoController::NeatoController(const std::string& logPath) : ScanController(logPath) +NeatoController::NeatoController(const std::string& logPath) : + ScanController(logPath) { this->RESPONSE_END = std::string(1, 0x1a); } template -NeatoController::NeatoController(std::iostream& logStream) : ScanController(logStream) +NeatoController::NeatoController(std::iostream& logStream) : + ScanController(logStream) { this->RESPONSE_END = std::string(1, 0x1a); } @@ -211,14 +217,14 @@ NeatoController::NeatoController(std::iostream& logStream) : template void NeatoController::setTestMode(bool testMode) { - this->sendFormattedCommand(CMD_TEST_MODE, (testMode ? ON : OFF).c_str()); + this->sendFormattedCommand(CMD_TEST_MODE, (testMode ? ON_VALUE : OFF_VALUE).c_str()); this->testMode = testMode; } template void NeatoController::setLdsRotation(bool ldsRotation) { - this->sendFormattedCommand(CMD_SET_LDS_ROTATION, (ldsRotation ? ON : OFF).c_str()); + this->sendFormattedCommand(CMD_SET_LDS_ROTATION, (ldsRotation ? ON_VALUE : OFF_VALUE).c_str()); this->ldsRotation = ldsRotation; } @@ -243,52 +249,52 @@ void NeatoController::setMotor(int left, int right, int spee } template -bool NeatoController::parseScanData(std::istream& in, ScanData& data) +bool NeatoController::parseScanData(std::istream& input, ScanData& data) { int lastIndex = 0; double M_PI_180 = M_PI / 180.0; std::string line; - std::getline(in, line); - boost::algorithm::trim(line); + std::getline(input, line); + balg::trim(line); - if(line == NeatoController::LDS_SCAN_HEADER) + if(line != NeatoController::LDS_SCAN_HEADER) { - while(true) + return false; + } + + while(true) + { + std::getline(input, line); + balg::trim(line); + + if(balg::starts_with(line, NeatoController::LDS_SCAN_FOOTER)) { - std::getline(in, line); - boost::algorithm::trim(line); - - if(boost::algorithm::starts_with(line, NeatoController::LDS_SCAN_FOOTER)) - { - std::vector values; - boost::algorithm::split(values, line, boost::algorithm::is_any_of(",")); - data.rotationSpeed = std::stod(values.at(1)); - - break; - } - else - { - std::vector values; - boost::algorithm::split(values, line, boost::algorithm::is_any_of(",")); - - int index = lastIndex++; - double angle = std::stod(values.at(0)) * M_PI_180; - double distance = std::stod(values.at(1)); - int intensity = std::stoi(values.at(2)); - int errorCode = std::stoi(values.at(3)); - bool error = (errorCode != 0); - - if(error) distance = -1; - - data.emplace_back(index, angle, distance, intensity, errorCode, error); - } + std::vector values; + balg::split(values, line, balg::is_any_of(",")); + data.rotationSpeed = std::stod(values.at(1)); + + break; } + else + { + std::vector values; + balg::split(values, line, balg::is_any_of(",")); + + int index = lastIndex++; + double angle = std::stod(values.at(0)) * M_PI_180; + double distance = std::stod(values.at(1)); + int intensity = std::stoi(values.at(2)); + int errorCode = std::stoi(values.at(3)); + bool error = errorCode != 0; - return true; + if(error) distance = -1; + + data.emplace_back(index, angle, distance, intensity, errorCode, error); + } } - return false; + return true; } template diff --git a/include/regilo/scancontroller.hpp b/include/regilo/scancontroller.hpp index a55620f..c1dd7d2 100644 --- a/include/regilo/scancontroller.hpp +++ b/include/regilo/scancontroller.hpp @@ -65,11 +65,11 @@ class ScanController : public virtual IScanController, public ProtocolController /** * @brief Parse the raw scan data. - * @param in The input stream that stores the raw scan data. + * @param input The input stream that stores the raw scan data. * @param data Output for the scanned data. * @return True if the parsing ends without an error. */ - virtual bool parseScanData(std::istream& in, ScanData& data) = 0; + virtual bool parseScanData(std::istream& input, ScanData& data) = 0; public: using ProtocolController::ProtocolController; diff --git a/include/regilo/timedlog.hpp b/include/regilo/timedlog.hpp index 8e11f09..8e2d1d6 100644 --- a/include/regilo/timedlog.hpp +++ b/include/regilo/timedlog.hpp @@ -110,7 +110,10 @@ class ITimedLog : public virtual ILog * @return Time since epoch as Duration. */ template - inline Duration getLastCommandTimeAs() const { return std::chrono::duration_cast(this->getLastCommandNanoseconds()); } + inline Duration getLastCommandTimeAs() const + { + return std::chrono::duration_cast(this->getLastCommandNanoseconds()); + } /** * @brief Sync command times with real time. It means that all read methods will block @@ -151,7 +154,10 @@ class TimedLog : public Log, public ITimedLog */ virtual ~TimedLog() = default; - virtual inline const ITimedLogMetadata* getTimedMetadata() const override { return (TimedLogMetadata*)metadata; } + virtual inline const ITimedLogMetadata* getTimedMetadata() const override + { + return (TimedLogMetadata*)metadata; + } inline virtual std::chrono::nanoseconds getLastCommandNanoseconds() const override { @@ -164,7 +170,10 @@ class TimedLog : public Log, public ITimedLog */ inline DurationT getLastCommandTime() const { return lastCommandTime; } - virtual inline void syncTime(bool sync = true) override { firstReadTime = (sync ? DurationT::max() : DurationT::zero()); } + virtual inline void syncTime(bool sync = true) override + { + firstReadTime = (sync ? DurationT::max() : DurationT::zero()); + } }; extern template class TimedLog; @@ -195,7 +204,8 @@ void TimedLog::writeMetadata(std::ostream& metaStream) if(metadata == nullptr) metadata = new TimedLogMetadata(); Log::writeMetadata(metaStream); - metaStream << "timeres " << DurationT::period::num << ' ' << DurationT::period::den << std::endl; + metaStream << "timeres " << DurationT::period::num << ' ' << DurationT::period::den + << std::endl; } template @@ -205,15 +215,15 @@ std::string TimedLog::readData(std::string& logCommand) std::string response = Log::readData(logCommand); - std::int64_t commandTimeCount = 0; + std::int64_t timeCount = 0; readName(stream, 't'); - stream >> commandTimeCount; + stream >> timeCount; if(stream) { long double numRatio = getTimedMetadata()->getNum() / (long double) DurationT::period::num; long double denRation = DurationT::period::den / (long double) getTimedMetadata()->getDen(); - lastCommandTime = DurationT(std::int64_t(std::round(commandTimeCount * numRatio * denRation))); + lastCommandTime = DurationT(std::int64_t(std::round(timeCount * numRatio * denRation))); if(firstReadTime == DurationT::max()) firstReadTime = epoch(); else diff --git a/include/regilo/version.hpp b/include/regilo/version.hpp index 9c7a6d9..6f4a2d8 100644 --- a/include/regilo/version.hpp +++ b/include/regilo/version.hpp @@ -32,11 +32,17 @@ namespace regilo { class Version { public: - static const std::string VERSION; ///< The whole version number in format [.[.[.]]]. - static const std::string VERSION_MAJOR; ///< The major part of the version number (format [.[.[.]]]). - static const std::string VERSION_MINOR; ///< The minor part of the version number (format [.[.[.]]]). - static const std::string VERSION_PATCH; ///< The patch part of the version number (format [.[.[.]]]). - static const std::string VERSION_TWEAK; ///< The tweak part of the version number (format [.[.[.]]]). + ///< The whole version number in format [.[.]]. + static const std::string VERSION; + + ///< The major part of the version number (format [.[.]]). + static const std::string VERSION_MAJOR; + + ///< The minor part of the version number (format [.[.]]). + static const std::string VERSION_MINOR; + + ///< The patch part of the version number (format [.[.]]). + static const std::string VERSION_PATCH; }; }