From 85b0b72532a26d005ccac1a9595094eb65a4da9f Mon Sep 17 00:00:00 2001 From: Pascal Brunot Date: Mon, 12 Aug 2024 10:00:19 +0200 Subject: [PATCH] Various CPPLinter warnings fixes --- include/BaseRfidWrapper.hpp | 2 +- include/BufferedMsg.hpp | 6 +++--- include/FabBackend.hpp | 2 +- include/RFIDWrapper.hpp | 2 +- include/card.hpp | 1 - src/FabBackend.cpp | 10 ++++------ src/LCDWrapper.cpp | 2 +- src/MQTTtypes.cpp | 4 ++-- src/MachineConfig.cpp | 2 +- src/RFIDWrapper.tpp | 2 +- src/Tasks.cpp | 2 +- src/mock/MockMQTTBroker.cpp | 4 ++-- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/BaseRfidWrapper.hpp b/include/BaseRfidWrapper.hpp index 98788b86..2420e433 100644 --- a/include/BaseRfidWrapper.hpp +++ b/include/BaseRfidWrapper.hpp @@ -23,7 +23,7 @@ namespace fabomatic virtual auto selfTest() const -> bool = 0; virtual auto reset() const -> void = 0; - virtual auto setDisabledUntil(std::optional t) -> void = 0; + virtual auto setDisabledUntil(const std::optional &t) -> void = 0; }; } // namespace fabomatic #endif // BASERFIDWRAPPER_HPP_ \ No newline at end of file diff --git a/include/BufferedMsg.hpp b/include/BufferedMsg.hpp index b20d6b41..861c02ee 100644 --- a/include/BufferedMsg.hpp +++ b/include/BufferedMsg.hpp @@ -15,9 +15,9 @@ namespace fabomatic /// @brief Message that can be saved in Flash for future replay struct BufferedMsg { - std::string mqtt_message; - std::string mqtt_topic; - bool wait_for_answer; + std::string mqtt_message{}; + std::string mqtt_topic{}; + bool wait_for_answer = false; BufferedMsg() = default; BufferedMsg(const std::string &message, const std::string &topic, bool wait) : mqtt_message(message), mqtt_topic(topic), wait_for_answer{wait} {}; BufferedMsg(const BufferedMsg &source) = default; diff --git a/include/FabBackend.hpp b/include/FabBackend.hpp index dfbf1e36..d8a0a60b 100644 --- a/include/FabBackend.hpp +++ b/include/FabBackend.hpp @@ -92,7 +92,7 @@ namespace fabomatic auto configure(const SavedConfig &config) -> void; // Must be called before using the server auto disconnect() -> void; - auto setChannel(int32_t channel) -> void; + auto setChannel(int16_t channel) -> void; // Rule of 5 https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five FabBackend(const FabBackend &) = delete; // copy constructor diff --git a/include/RFIDWrapper.hpp b/include/RFIDWrapper.hpp index 980dd718..20791299 100644 --- a/include/RFIDWrapper.hpp +++ b/include/RFIDWrapper.hpp @@ -47,7 +47,7 @@ namespace fabomatic [[nodiscard]] auto getUid() const -> card::uid_t override; - [[nodiscard]] auto setDisabledUntil(std::optional delay) -> void override; + [[nodiscard]] auto setDisabledUntil(const std::optional &delay) -> void override; /// @brief Returns the driver object for testing/simulation Driver &getDriver(); diff --git a/include/card.hpp b/include/card.hpp index d3782805..a93920fe 100644 --- a/include/card.hpp +++ b/include/card.hpp @@ -8,7 +8,6 @@ #include "conf.hpp" #include "Logging.hpp" -#include namespace fabomatic::card { diff --git a/src/FabBackend.cpp b/src/FabBackend.cpp index af2a49cc..13995b74 100644 --- a/src/FabBackend.cpp +++ b/src/FabBackend.cpp @@ -483,11 +483,9 @@ namespace fabomatic { return true; } - else - { - ESP_LOGW(TAG, "Failed to publish query %s", query.payload().data()); - this->disconnect(); - } + + ESP_LOGW(TAG, "Failed to publish query %s", query.payload().data()); + this->disconnect(); } if (query.buffered()) @@ -580,7 +578,7 @@ namespace fabomatic * * @param channel The channel number. */ - void FabBackend::setChannel(int32_t channel) + void FabBackend::setChannel(int16_t channel) { this->channel = channel; } diff --git a/src/LCDWrapper.cpp b/src/LCDWrapper.cpp index 9da4c310..3c2e2cae 100644 --- a/src/LCDWrapper.cpp +++ b/src/LCDWrapper.cpp @@ -155,7 +155,7 @@ namespace fabomatic void LCDWrapper::prettyPrint(const DisplayBuffer &buf, const BoardInfo &bi) const { - std::stringstream ss; + std::stringstream ss{}; ss << "/" << std::string(conf::lcd::COLS, '-') << "\\\r\n"; // LCD top for (const auto &row : buf) diff --git a/src/MQTTtypes.cpp b/src/MQTTtypes.cpp index 4470a454..dc3673b2 100644 --- a/src/MQTTtypes.cpp +++ b/src/MQTTtypes.cpp @@ -39,7 +39,7 @@ namespace fabomatic::MQTTInterface std::stringstream ss{}; // Get MAC address - const auto serial = esp32::esp_serial(); + const auto serial = esp32::esp_serial_str(); ss << "{\"action\":\"alive\"," << "\"version\":\"" << FABOMATIC_BUILD << "," << GIT_VERSION << "\"," @@ -148,4 +148,4 @@ namespace fabomatic::MQTTInterface auto response = std::make_unique(doc["request_ok"].as()); return response; } -} // namespace fabomatic::MQTT \ No newline at end of file +} // namespace fabomatic::MQTTInterface \ No newline at end of file diff --git a/src/MachineConfig.cpp b/src/MachineConfig.cpp index 62914289..5b027861 100644 --- a/src/MachineConfig.cpp +++ b/src/MachineConfig.cpp @@ -5,7 +5,7 @@ namespace fabomatic { auto MachineConfig::toString() const -> const std::string { - std::stringstream sstream; + std::stringstream sstream{}; sstream << "MachineConfig (ID:" << machine_id.id; sstream << ", Name:" << machine_name; diff --git a/src/RFIDWrapper.tpp b/src/RFIDWrapper.tpp index 0966f210..cccb3667 100644 --- a/src/RFIDWrapper.tpp +++ b/src/RFIDWrapper.tpp @@ -34,7 +34,7 @@ namespace fabomatic } template - [[nodiscard]] auto RFIDWrapper::setDisabledUntil(std::optional delay) -> void + [[nodiscard]] auto RFIDWrapper::setDisabledUntil(const std::optional &delay) -> void { this->disabledUntil = delay; } diff --git a/src/Tasks.cpp b/src/Tasks.cpp index 8ec0aabf..249d6e8c 100644 --- a/src/Tasks.cpp +++ b/src/Tasks.cpp @@ -137,7 +137,7 @@ namespace fabomatic::Tasks auto Task::toString() const -> const std::string { - std::stringstream ss; + std::stringstream ss{}; ss << "Task " << getId() << ", active=" << active << ",Period(ms)=" << period << ", Delay(ms)=" << delay << ",Last run=" << last_run.time_since_epoch() diff --git a/src/mock/MockMQTTBroker.cpp b/src/mock/MockMQTTBroker.cpp index 59cb0ff6..46d47ec4 100644 --- a/src/mock/MockMQTTBroker.cpp +++ b/src/mock/MockMQTTBroker.cpp @@ -161,7 +161,7 @@ namespace fabomatic }); if (elem != secrets::cards::whitelist.end()) { - std::stringstream ss; + std::stringstream ss{}; const auto &[id, level, name] = *elem; ss << "{\"request_ok\":true,\"is_valid\":" << (level != FabUser::UserLevel::Unknown ? "true" : "false") << ",\"level\":" << +static_cast(level) @@ -170,7 +170,7 @@ namespace fabomatic } // Still return a valid user - std::stringstream ss; + std::stringstream ss{}; ss << "{\"request_ok\":true,\"is_valid\":true,\"level\":" << +2 << ",\"name\":\"User" << uid_str << "\"}"; return ss.str();