Skip to content

Commit

Permalink
SlacSimulator initialize state with UNMATCHED (#963)
Browse files Browse the repository at this point in the history
This could publish an empty string on startup while an enum was expected, leading to failures when running EVerest with schema validation enabled

remove default empty string from state_to_string
enable -Werror=switch-enum for SlacSimulator module

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Nov 21, 2024
1 parent cd5190a commit 3e55818
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions modules/simulation/SlacSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ ev_setup_cpp_module()

# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
target_compile_options(${MODULE_NAME}
PRIVATE
-Wimplicit-fallthrough
-Werror=switch-enum
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

target_sources(${MODULE_NAME}
Expand Down
2 changes: 1 addition & 1 deletion modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ev_slacImpl : public ev_slacImplBase {

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
util::State state;
util::State state{util::State::UNMATCHED};
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
2 changes: 1 addition & 1 deletion modules/simulation/SlacSimulator/evse/slacImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class slacImpl : public slacImplBase {
void set_state_to_unmatched();
void set_state_to_matching();

util::State state;
util::State state{util::State::UNMATCHED};
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
4 changes: 2 additions & 2 deletions modules/simulation/SlacSimulator/util/state.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "state.hpp"
#include <stdexcept>
#include <string>

namespace module::util {
Expand All @@ -13,9 +14,8 @@ std::string state_to_string(State state) {
return "MATCHING";
case State::MATCHED:
return "MATCHED";
default:
return "";
}
throw std::out_of_range("Could not convert State to string");
}

} // namespace module::util

0 comments on commit 3e55818

Please sign in to comment.