Skip to content

Commit

Permalink
Merge branch 'main' into fix/rust_link_gcov
Browse files Browse the repository at this point in the history
Signed-off-by: Dima Dorezyuk <[email protected]>
  • Loading branch information
dorezyuk authored Apr 5, 2024
2 parents b6a52d8 + 70d1136 commit a8c4f6a
Show file tree
Hide file tree
Showing 39 changed files with 732 additions and 101 deletions.
16 changes: 8 additions & 8 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
/cmake/ @hikinggrass @a-w50

# modules
/modules/API/ @hikinggrass
/modules/Auth/ @pietfried
/modules/Energymanager/ @corneliusclaussen
/modules/EnergyNode/ @corneliusclaussen
/modules/API/ @hikinggrass @pietfried
/modules/Auth/ @pietfried @corneliusclaussen
/modules/Energymanager/ @corneliusclaussen @hikinggrass
/modules/EnergyNode/ @corneliusclaussen @hikinggrass
/modules/EvseManager/ @corneliusclaussen @SebaLukas
/modules/EvseSecurity/ @AssemblyJohn @pietfried
/modules/EvseV2G/ @corneliusclaussen @SebaLukas
/modules/EvseSlac/ @a-w50 @corneliusclaussen @SebaLukas
/modules/OCPP/ @hikinggrass @pietfried
/modules/OCPP201/ @hikinggrass @pietfried
/modules/PacketSniffer @corneliusclaussen @SebaLukas
/modules/PyEvJosev @SebaLukas
/modules/Setup @hikinggrass
/modules/YetiDriver @corneliusclaussen
/modules/simulation/ @SebaLukas
/modules/PyEvJosev @SebaLukas @corneliusclaussen
/modules/Setup @hikinggrass @corneliusclaussen
/modules/YetiDriver @corneliusclaussen @hikinggrass
/modules/simulation/ @SebaLukas @pietfried
/modules/rust_examples/ @SirVer @golovasteek @dorezyuk

# Rust & Bazel
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14.7)

project(everest-core
VERSION 2024.2.0
VERSION 2024.3.0
DESCRIPTION "The open operating system for e-mobility charging stations"
LANGUAGES CXX C
)
Expand Down
6 changes: 3 additions & 3 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ libtimer:
# Slac module
libslac:
git: https://github.com/EVerest/libslac.git
git_tag: 486cd8b
git_tag: v0.3.0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBSLAC"
libfsm:
git: https://github.com/EVerest/libfsm.git
Expand All @@ -47,13 +47,13 @@ libcurl:
# and would otherwise be overwritten by the version used there
libevse-security:
git: https://github.com/EVerest/libevse-security.git
git_tag: bce1ba4
git_tag: v0.5.0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBEVSE_SECURITY"

# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: 778e080
git_tag: v0.10.0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP"
# Josev
Josev:
Expand Down
15 changes: 13 additions & 2 deletions lib/staging/slac/fsm/ev/include/slac/fsm/ev/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ template <> struct MMTYPE<slac::messages::cm_slac_match_req> {
template <> struct MMTYPE<slac::messages::cm_set_key_req> {
static const uint16_t value = slac::defs::MMTYPE_CM_SET_KEY | slac::defs::MMTYPE_MODE_REQ;
};

template <typename SlacMessageType> struct MMV {
// this is the default value for homeplug av 2.0 messages, which are
// backward compatible with homeplug av 1.1 messages
// non-backward (to 1.1) compatible message are CM_CHAN_EST,
// CM_AMP_MAP and CM_NW_STATS, these need to use AV_2_0
// older av 1.0 message need to use AV_1_0
static constexpr auto value = slac::defs::MMV::AV_1_1;
};
} // namespace _context_detail

struct ContextCallbacks {
Expand All @@ -55,10 +64,12 @@ struct Context {
slac::messages::HomeplugMessage slac_message;

// FIXME (aw): message should be const, but libslac doesn't allow for const ptr - needs changes in libslac
template <typename SlacMessageType> void send_slac_message(const uint8_t* dest_mac, SlacMessageType& message) {
template <typename SlacMessageType>
void send_slac_message(const uint8_t* dest_mac, SlacMessageType const& message) {
slac::messages::HomeplugMessage hp_message;
hp_message.setup_ethernet_header(dest_mac);
hp_message.setup_payload(&message, sizeof(message), _context_detail::MMTYPE<SlacMessageType>::value);
hp_message.setup_payload(&message, sizeof(message), _context_detail::MMTYPE<SlacMessageType>::value,
_context_detail::MMV<SlacMessageType>::value);
callbacks.send_raw_slac(hp_message);
}

Expand Down
132 changes: 130 additions & 2 deletions lib/staging/slac/fsm/evse/include/slac/fsm/evse/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace slac::fsm::evse {

namespace _context_detail {

template <typename SlacMessageType> struct MMTYPE;
template <> struct MMTYPE<slac::messages::cm_slac_parm_cnf> {
static const uint16_t value = slac::defs::MMTYPE_CM_SLAC_PARAM | slac::defs::MMTYPE_MODE_CNF;
Expand All @@ -27,8 +28,115 @@ template <> struct MMTYPE<slac::messages::cm_validate_cnf> {
template <> struct MMTYPE<slac::messages::cm_slac_match_cnf> {
static const uint16_t value = slac::defs::MMTYPE_CM_SLAC_MATCH | slac::defs::MMTYPE_MODE_CNF;
};

template <> struct MMTYPE<slac::messages::qualcomm::cm_reset_device_req> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_CM_RESET_DEVICE | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::qualcomm::cm_reset_device_cnf> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_CM_RESET_DEVICE | slac::defs::MMTYPE_MODE_CNF;
};

template <> struct MMTYPE<slac::messages::qualcomm::link_status_req> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_LINK_STATUS | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::qualcomm::link_status_cnf> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_LINK_STATUS | slac::defs::MMTYPE_MODE_CNF;
};

template <> struct MMTYPE<slac::messages::qualcomm::op_attr_req> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_OP_ATTR | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::qualcomm::op_attr_cnf> {
static const uint16_t value = slac::defs::qualcomm::MMTYPE_OP_ATTR | slac::defs::MMTYPE_MODE_CNF;
};

// This message has no CNF counterpart
template <> struct MMTYPE<slac::messages::lumissil::nscm_reset_device_req> {
static const uint16_t value = slac::defs::lumissil::MMTYPE_NSCM_RESET_DEVICE | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::lumissil::nscm_get_version_req> {
static const uint16_t value = slac::defs::lumissil::MMTYPE_NSCM_GET_VERSION | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::lumissil::nscm_get_version_cnf> {
static const uint16_t value = slac::defs::lumissil::MMTYPE_NSCM_GET_VERSION | slac::defs::MMTYPE_MODE_CNF;
};

template <> struct MMTYPE<slac::messages::lumissil::nscm_get_d_link_status_req> {
static const uint16_t value = slac::defs::lumissil::MMTYPE_NSCM_GET_D_LINK_STATUS | slac::defs::MMTYPE_MODE_REQ;
};

template <> struct MMTYPE<slac::messages::lumissil::nscm_get_d_link_status_cnf> {
static const uint16_t value = slac::defs::lumissil::MMTYPE_NSCM_GET_D_LINK_STATUS | slac::defs::MMTYPE_MODE_CNF;
};

template <typename SlacMessageType> struct MMV {
// this is the default value for homeplug av 2.0 messages, which are
// backward compatible with homeplug av 1.1 messages
// non-backward (to 1.1) compatible message are CM_CHAN_EST,
// CM_AMP_MAP and CM_NW_STATS, these need to use AV_2_0
// older av 1.0 message need to use AV_1_0
static constexpr auto value = slac::defs::MMV::AV_1_1;
};

template <> struct MMV<slac::messages::qualcomm::cm_reset_device_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::qualcomm::cm_reset_device_cnf> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::qualcomm::link_status_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::qualcomm::link_status_cnf> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::qualcomm::op_attr_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::qualcomm::op_attr_cnf> {
static constexpr auto value = slac::defs::MMV::AV_1_0;
};

template <> struct MMV<slac::messages::lumissil::nscm_reset_device_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0; // FIXME this is unclear
};

template <> struct MMV<slac::messages::lumissil::nscm_get_version_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0; // FIXME this is unclear
};

template <> struct MMV<slac::messages::lumissil::nscm_get_version_cnf> {
static constexpr auto value = slac::defs::MMV::AV_1_0; // FIXME this is unclear
};

template <> struct MMV<slac::messages::lumissil::nscm_get_d_link_status_req> {
static constexpr auto value = slac::defs::MMV::AV_1_0; // FIXME this is unclear
};

template <> struct MMV<slac::messages::lumissil::nscm_get_d_link_status_cnf> {
static constexpr auto value = slac::defs::MMV::AV_1_0; // FIXME this is unclear
};

} // namespace _context_detail

// FIXME (aw): this should be moved to common headers (in libslac)
enum class ModemVendor {
Unknown,
Qualcomm,
Lumissil,
VertexCom,
};

struct ContextCallbacks {
std::function<void(slac::messages::HomeplugMessage&)> send_raw_slac{nullptr};
std::function<void(const std::string&)> signal_state{nullptr};
Expand All @@ -54,6 +162,23 @@ struct EvseSlacConfig {
// timeout for CM_SET_KEY.REQ
int set_key_timeout_ms = 500;

// Settings CM_DEVICE_RESET.REQ
struct chip_reset_struct {
bool enabled = false;
int timeout_ms = 500;
int delay_ms = 100;
} chip_reset;

// Settings for LINK_STATUS detection
struct link_status_struct {
bool do_detect = false;
int retry_ms = 100;
int timeout_ms = 5000;
bool debug_simulate_failed_matching = false;
} link_status;

int request_info_delay_ms = 100;

// offset for adjusting the calculated sounding attenuation
int sounding_atten_adjustment = 0;
};
Expand All @@ -68,10 +193,11 @@ struct Context {
slac::messages::HomeplugMessage slac_message_payload;

// FIXME (aw): message should be const, but libslac doesn't allow for const ptr - needs changes in libslac
template <typename SlacMessageType> void send_slac_message(const uint8_t* mac, SlacMessageType& message) {
template <typename SlacMessageType> void send_slac_message(const uint8_t* mac, SlacMessageType const& message) {
slac::messages::HomeplugMessage hp_message;
hp_message.setup_ethernet_header(mac);
hp_message.setup_payload(&message, sizeof(message), _context_detail::MMTYPE<SlacMessageType>::value);
hp_message.setup_payload(&message, sizeof(message), _context_detail::MMTYPE<SlacMessageType>::value,
_context_detail::MMV<SlacMessageType>::value);
callbacks.send_raw_slac(hp_message);
}

Expand All @@ -85,6 +211,8 @@ struct Context {
// logging util
void log_info(const std::string& text);

ModemVendor modem_vendor{ModemVendor::Unknown};

private:
const ContextCallbacks& callbacks;
};
Expand Down
1 change: 1 addition & 0 deletions lib/staging/slac/fsm/evse/include/slac/fsm/evse/fsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class Event {
RETRY_MATCHING,
MATCH_COMPLETE,
FAILED,
SUCCESS,
};

using FSMReturnType = int;
Expand Down
54 changes: 54 additions & 0 deletions lib/staging/slac/fsm/evse/include/slac/fsm/evse/states/others.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define EVSE_SLAC_STATES_OTHERS_HPP

#include "../fsm.hpp"
#include <chrono>

namespace slac::fsm::evse {

Expand All @@ -21,6 +22,27 @@ struct ResetState : public FSMSimpleState {
bool setup_has_been_send{false};
};

struct ResetChipState : public FSMSimpleState {
using FSMSimpleState::FSMSimpleState;

HandleEventReturnType handle_event(AllocatorType&, Event) final;

void enter() final;
CallbackReturnType callback() final;

// for now returns true if CM_RESET_CNF is received
bool handle_slac_message(slac::messages::HomeplugMessage&);

bool reset_delay_done{false};
bool chip_reset_has_been_sent{false};

enum class SubState {
DELAY,
SEND_RESET,
DONE,
} sub_state{SubState::DELAY};
};

struct IdleState : public FSMSimpleState {
using FSMSimpleState::FSMSimpleState;

Expand All @@ -46,6 +68,38 @@ struct FailedState : public FSMSimpleState {
void enter() final;
};

struct WaitForLinkState : public FSMSimpleState {
using FSMSimpleState::FSMSimpleState;

HandleEventReturnType handle_event(AllocatorType&, Event) final;

void enter() final;
CallbackReturnType callback() final;

// for now returns true if link up detected is received
bool handle_slac_message(slac::messages::HomeplugMessage&);

bool link_status_req_sent{false};
std::chrono::steady_clock::time_point start_time;
};

struct InitState : public FSMSimpleState {
using FSMSimpleState::FSMSimpleState;

HandleEventReturnType handle_event(AllocatorType&, Event) final;

CallbackReturnType callback() final;

void handle_slac_message(slac::messages::HomeplugMessage&);

// For now we are requesting only one version info packet, but probably there will be more in the future.
enum class SubState {
QUALCOMM_OP_ATTR,
LUMISSIL_GET_VERSION,
DONE,
} sub_state{SubState::QUALCOMM_OP_ATTR};
};

} // namespace slac::fsm::evse

#endif // EVSE_SLAC_STATES_OTHERS_HPP
7 changes: 6 additions & 1 deletion lib/staging/slac/fsm/evse/src/states/matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ FSMSimpleState::HandleEventReturnType MatchingState::handle_event(AllocatorType&
} else if (ev == Event::RESET) {
return sa.create_simple<ResetState>(ctx);
} else if (ev == Event::MATCH_COMPLETE) {
return sa.create_simple<MatchedState>(ctx);
// Wait for link up to be confirmed before going to MATCHED state if enabled in config
if (ctx.slac_config.link_status.do_detect) {
return sa.create_simple<WaitForLinkState>(ctx);
} else {
return sa.create_simple<MatchedState>(ctx);
}
} else if (ev == Event::RETRY_MATCHING) {
num_retries++;
if (num_retries == slac::defs::C_EV_MATCH_RETRY) {
Expand Down
13 changes: 10 additions & 3 deletions lib/staging/slac/fsm/evse/src/states/matching_handle_slac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,16 @@ void MatchingState::handle_cm_slac_match_req(const slac::messages::cm_slac_match

session_log(ctx, *session, "Received CM_SLAC_MATCH_REQ, sending CM_SLAC_MATCH_CNF -> session complete");

auto match_confirm = create_cm_slac_match_cnf(*session, msg, ctx.slac_config.session_nmk);

ctx.send_slac_message(tmp_ev_mac, match_confirm);
if (not ctx.slac_config.link_status.debug_simulate_failed_matching) {
auto match_confirm = create_cm_slac_match_cnf(*session, msg, ctx.slac_config.session_nmk);
ctx.send_slac_message(tmp_ev_mac, match_confirm);
} else {
ctx.log_info("Sending wrong NMK to EV to simulate a failed link setup after match request");
uint8_t wrong_session_nmk[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
auto match_confirm = create_cm_slac_match_cnf(*session, msg, wrong_session_nmk);
ctx.send_slac_message(tmp_ev_mac, match_confirm);
}

session->state = MatchingSubState::MATCH_COMPLETE;

Expand Down
Loading

0 comments on commit a8c4f6a

Please sign in to comment.