Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up SerilaiInputHandler #281

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

hhvrc
Copy link
Member

@hhvrc hhvrc commented Sep 6, 2024

No description provided.

@hhvrc hhvrc self-assigned this Sep 6, 2024
Copy link
Contributor

github-actions bot commented Sep 6, 2024

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 8 file(s) not formatted
  • include/serial/command_handlers/CommandEntry.h
  • src/serial/SerialInputHandler.cpp
  • src/serial/command_handlers/CommandEntry.cpp
  • src/serial/command_handlers/echo.cpp
  • src/serial/command_handlers/jsonconfig.cpp
  • src/serial/command_handlers/keepalive.cpp
  • src/serial/command_handlers/networks.cpp
  • src/serial/command_handlers/rftransmit.cpp
clang-tidy reports: 68 concern(s)
  • include/serial/SerialInputHandler.h:3:10: error: [clang-diagnostic-error]

    'cstdint' file not found

        3 | #include <cstdint>
          |          ^~~~~~~~~
  • include/serial/command_handlers/CommandEntry.h:3:10: error: [clang-diagnostic-error]

    'string_view' file not found

        3 | #include <string_view>
          |          ^~~~~~~~~~~~~
  • include/serial/command_handlers/CommandEntry.h:6:11: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 'OpenShock' is non-const and globally accessible, consider making it const

        6 | namespace OpenShock::Serial {
          |           ^
  • include/serial/command_handlers/common.h:3:10: error: [clang-diagnostic-error]

    'serial/command_handlers/index.h' file not found

        3 | #include "serial/command_handlers/index.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • include/serial/command_handlers/common.h:14:7: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 'namespace' is non-const and globally accessible, consider making it const

       14 | using namespace std::string_view_literals;
          |       ^
  • include/serial/command_handlers/index.h:3:10: error: [clang-diagnostic-error]

    'serial/command_handlers/CommandEntry.h' file not found

        3 | #include "serial/command_handlers/CommandEntry.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • include/serial/command_handlers/index.h:7:11: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 'OpenShock' is non-const and globally accessible, consider making it const

        7 | namespace OpenShock::Serial::CommandHandlers {
          |           ^
  • src/main.cpp:1:10: error: [clang-diagnostic-error]

    'freertos/FreeRTOS.h' file not found

        1 | #include <freertos/FreeRTOS.h>
          |          ^~~~~~~~~~~~~~~~~~~~~
  • src/serial/SerialInputHandler.cpp:1:10: error: [clang-diagnostic-error]

    'serial/SerialInputHandler.h' file not found

        1 | #include "serial/SerialInputHandler.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/SerialInputHandler.cpp:62:13: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 's_echoEnabled' is non-const and globally accessible, consider making it const

       62 | static bool s_echoEnabled = true;
          |             ^
  • src/serial/SerialInputHandler.cpp:63:53: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 's_commandGroups' is non-const and globally accessible, consider making it const

       63 | static std::vector<OpenShock::Serial::CommandGroup> s_commandGroups;
          |                                                     ^
  • src/serial/SerialInputHandler.cpp:64:108: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 's_commandHandlers' is non-const and globally accessible, consider making it const

       64 | static std::unordered_map<std::string_view, OpenShock::Serial::CommandGroup, std::hash_ci, std::equals_ci> s_commandHandlers;
          |                                                                                                            ^
  • src/serial/SerialInputHandler.cpp:66:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleHelpCommand', which is reserved in the global namespace

       66 | void _handleHelpCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~
          |      handleHelpCommand
  • src/serial/SerialInputHandler.cpp:88:17: warning: [cppcoreguidelines-init-variables]

    variable 'buffer' is not initialized

       88 |     std::string buffer;
          |                 ^     
          |                        = 0
  • src/serial/SerialInputHandler.cpp:123:8: warning: [readability-identifier-length]

    variable name 'it' is too short, expected at least 3 characters

      123 |   auto it = s_commandHandlers.find(arg);
          |        ^
  • src/serial/SerialInputHandler.cpp:125:17: warning: [cppcoreguidelines-init-variables]

    variable 'buffer' is not initialized

      125 |     std::string buffer;
          |                 ^     
          |                        = 0
  • src/serial/SerialInputHandler.cpp:141:5: warning: [modernize-use-trailing-return-type]

    use a trailing return type for this function

      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          | ~~~ ^
          | auto                                                             -> int
  • src/serial/SerialInputHandler.cpp:141:34: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'findChar' of convertible types are easily swapped by mistake

      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/runner/work/Firmware/Firmware/src/serial/SerialInputHandler.cpp:141:46: note: the first parameter in the range is 'bufferSize'
      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                              ^~~~~~~~~~
    /home/runner/work/Firmware/Firmware/src/serial/SerialInputHandler.cpp:141:63: note: the last parameter in the range is 'c'
      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                                               ^
    /home/runner/work/Firmware/Firmware/src/serial/SerialInputHandler.cpp:141:34: note: 
      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                  ^
    /home/runner/work/Firmware/Firmware/src/serial/SerialInputHandler.cpp:141:58: note: 'std::size_t' and 'char' may be implicitly converted: 'std::size_t' (as 'unsigned long') -> 'char', 'char' -> 'std::size_t' (as 'unsigned long')
      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                                          ^
  • src/serial/SerialInputHandler.cpp:141:63: warning: [readability-identifier-length]

    parameter name 'c' is too short, expected at least 3 characters

      141 | int findChar(const char* buffer, std::size_t bufferSize, char c) {
          |                                                               ^
  • src/serial/SerialInputHandler.cpp:143:9: warning: [cppcoreguidelines-pro-bounds-pointer-arithmetic]

    do not use pointer arithmetic

      143 |     if (buffer[i] == c) {
          |         ^
  • src/serial/SerialInputHandler.cpp:192:8: warning: [readability-identifier-length]

    variable name 'it' is too short, expected at least 3 characters

      192 |   auto it = s_commandHandlers.find(command);
          |        ^
  • src/serial/command_handlers/CommandEntry.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/CommandEntry.h' file not found

        1 | #include "serial/command_handlers/CommandEntry.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/authtoken.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/authtoken.cpp:7:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleAuthtokenCommand', which is reserved in the global namespace

        7 | void _handleAuthtokenCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~
          |      handleAuthtokenCommand
  • src/serial/command_handlers/authtoken.cpp:9:17: warning: [cppcoreguidelines-init-variables]

    variable 'authToken' is not initialized

        9 |     std::string authToken;
          |                 ^        
          |                           = 0
  • src/serial/command_handlers/authtoken.cpp:20:8: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       20 |   bool result = OpenShock::Config::SetBackendAuthToken(arg);
          |        ^
          |               = false
  • src/serial/command_handlers/domain.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/domain.cpp:11:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleDomainCommand', which is reserved in the global namespace

       11 | void _handleDomainCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~
          |      handleDomainCommand
  • src/serial/command_handlers/domain.cpp:13:17: warning: [cppcoreguidelines-init-variables]

    variable 'domain' is not initialized

       13 |     std::string domain;
          |                 ^     
          |                        = 0
  • src/serial/command_handlers/domain.cpp:50:8: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       50 |   bool result = OpenShock::Config::SetBackendDomain(arg);
          |        ^
          |               = false
  • src/serial/command_handlers/echo.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/echo.cpp:9:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleSerialEchoCommand', which is reserved in the global namespace

        9 | void _handleSerialEchoCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~
          |      handleSerialEchoCommand
  • src/serial/command_handlers/echo.cpp:16:8: warning: [cppcoreguidelines-init-variables]

    variable 'enabled' is not initialized

       16 |   bool enabled;
          |        ^      
          |                = false
  • src/serial/command_handlers/echo.cpp:22:8: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       22 |   bool result   = OpenShock::Config::SetSerialInputConfigEchoEnabled(enabled);
          |        ^
          |               = false
  • src/serial/command_handlers/factoryreset.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/factoryreset.cpp:5:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleFactoryResetCommand', which is reserved in the global namespace

        5 | void _handleFactoryResetCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~~~
          |      handleFactoryResetCommand
  • src/serial/command_handlers/jsonconfig.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/jsonconfig.cpp:5:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleJsonConfigCommand', which is reserved in the global namespace

        5 | void _handleJsonConfigCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~
          |      handleJsonConfigCommand
  • src/serial/command_handlers/keepalive.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/keepalive.cpp:8:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleKeepAliveCommand', which is reserved in the global namespace

        8 | void _handleKeepAliveCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~
          |      handleKeepAliveCommand
  • src/serial/command_handlers/keepalive.cpp:9:8: warning: [cppcoreguidelines-init-variables]

    variable 'keepAliveEnabled' is not initialized

        9 |   bool keepAliveEnabled;
          |        ^               
          |                         = false
  • src/serial/command_handlers/keepalive.cpp:27:8: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       27 |   bool result = OpenShock::CommandHandler::SetKeepAliveEnabled(keepAliveEnabled);
          |        ^
          |               = false
  • src/serial/command_handlers/lcgoverride.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/lcgoverride.cpp:8:13: warning: [cppcoreguidelines-avoid-non-const-global-variables]

    variable 'TAG' is non-const and globally accessible, consider making it const

        8 | const char* TAG = "Serial::CommandHandlers::LcgOverride";
          |             ^
  • src/serial/command_handlers/lcgoverride.cpp:10:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleLcgOverrideCommand', which is reserved in the global namespace

       10 | void _handleLcgOverrideCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~~
          |      handleLcgOverrideCommand
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/lcgoverride.cpp:24:23: warning: 5 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
       24 |     if (arg.size() != 5) {
          |                       ^
  • src/serial/command_handlers/lcgoverride.cpp:29:10: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       29 |     bool result = OpenShock::Config::SetBackendLCGOverride(std::string());
          |          ^
          |                 = false
  • src/serial/command_handlers/lcgoverride.cpp:80:10: warning: [cppcoreguidelines-init-variables]

    variable 'result' is not initialized

       80 |     bool result = OpenShock::Config::SetBackendLCGOverride(domain);
          |          ^
          |                 = false
  • src/serial/command_handlers/networks.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/networks.cpp:12:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleNetworksCommand', which is reserved in the global namespace

       12 | void _handleNetworksCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~
          |      handleNetworksCommand
  • src/serial/command_handlers/networks.cpp:52:11: warning: [readability-identifier-length]

    variable name 'id' is too short, expected at least 3 characters

       52 |   uint8_t id     = 1;
          |           ^
  • src/serial/command_handlers/rawconfig.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/rawconfig.cpp:8:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleRawConfigCommand', which is reserved in the global namespace

        8 | void _handleRawConfigCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~
          |      handleRawConfigCommand
  • src/serial/command_handlers/restart.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/restart.cpp:5:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleRestartCommand', which is reserved in the global namespace

        5 | void _handleRestartCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~
          |      handleRestartCommand
  • src/serial/command_handlers/rftransmit.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/rftransmit.cpp:6:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleRFTransmitCommand', which is reserved in the global namespace

        6 | void _handleRFTransmitCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~
          |      handleRFTransmitCommand
  • src/serial/command_handlers/rftransmit.cpp:18:8: warning: [cppcoreguidelines-init-variables]

    variable 'parsed' is not initialized

       18 |   bool parsed = OpenShock::Serialization::JsonSerial::ParseShockerCommand(root, cmd);
          |        ^
          |               = false
  • src/serial/command_handlers/rftxpin.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/rftxpin.cpp:8:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleRfTxPinCommand', which is reserved in the global namespace

        8 | void _handleRfTxPinCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~
          |      handleRfTxPinCommand
  • src/serial/command_handlers/sysinfo.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/sysinfo.cpp:8:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleDebugInfoCommand', which is reserved in the global namespace

        8 | void _handleDebugInfoCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~
          |      handleDebugInfoCommand
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/sysinfo.cpp:21:75: warning: 24 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
       21 |   SERPR_RESPONSE("RTOSInfo|Uptime|%llid %llih %llim %llis", days, hours % 24, minutes % 60, seconds % 60);
          |                                                                           ^
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/sysinfo.cpp:21:89: warning: 60 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
       21 |   SERPR_RESPONSE("RTOSInfo|Uptime|%llid %llih %llim %llis", days, hours % 24, minutes % 60, seconds % 60);
          |                                                                                         ^
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/sysinfo.cpp:21:103: warning: 60 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
       21 |   SERPR_RESPONSE("RTOSInfo|Uptime|%llid %llih %llim %llis", days, hours % 24, minutes % 60, seconds % 60);
          |                                                                                                       ^
  • src/serial/command_handlers/sysinfo.cpp:24:8: warning: [cppcoreguidelines-init-variables]

    variable 'connected' is not initialized

       24 |   bool connected = OpenShock::WiFiManager::GetConnectedNetwork(network);
          |        ^
          |                  = false
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/sysinfo.cpp:30:5: warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays]
       30 |     char ipAddressBuffer[64];
          |     ^
    /home/runner/work/Firmware/Firmware/src/serial/command_handlers/sysinfo.cpp:30:26: warning: 64 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
       30 |     char ipAddressBuffer[64];
          |                          ^
  • src/serial/command_handlers/validgpios.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/validgpios.cpp:7:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleValidGpiosCommand', which is reserved in the global namespace

        7 | void _handleValidGpiosCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~~~~
          |      handleValidGpiosCommand
  • src/serial/command_handlers/validgpios.cpp:15:15: warning: [cppcoreguidelines-init-variables]

    variable 'buffer' is not initialized

       15 |   std::string buffer;
          |               ^     
          |                      = 0
  • src/serial/command_handlers/version.cpp:1:10: error: [clang-diagnostic-error]

    'serial/command_handlers/common.h' file not found

        1 | #include "serial/command_handlers/common.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • src/serial/command_handlers/version.cpp:7:6: warning: [bugprone-reserved-identifier]

    declaration uses identifier '_handleVersionCommand', which is reserved in the global namespace

        7 | void _handleVersionCommand(std::string_view arg) {
          |      ^~~~~~~~~~~~~~~~~~~~~
          |      handleVersionCommand
  • src/serialization/JsonAPI.cpp:1:10: error: [clang-diagnostic-error]

    'serialization/JsonAPI.h' file not found

        1 | #include "serialization/JsonAPI.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~

Have any feedback or feature suggestions? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

1 participant