Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter

- CitrineOS core extracted (CSMS OCPP 2.0.1)
- OpenOCPP extracted (firmware OCPP 1.6J/2.0.1)
- ShapeShifter library installed (pip install -e)
- ShapeShifter specification extracted
- EVerest extracted

TODO updated with progress
This commit is contained in:
Eric F
2026-06-08 00:38:27 -04:00
parent 468cfeaa50
commit d398a6ced2
7326 changed files with 1177561 additions and 7 deletions

View File

@@ -0,0 +1,79 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 - 2023 Pionix GmbH and Contributors to EVerest
#include "fsm_controller.hpp"
#include <everest/slac/fsm/evse/states/others.hpp>
FSMController::FSMController(slac::fsm::evse::Context& context) : ctx(context){};
void FSMController::signal_new_slac_message(slac::messages::HomeplugMessage& msg) {
if (running == false) {
return;
}
{
const std::lock_guard<std::mutex> feed_lck(feed_mtx);
ctx.slac_message_payload = msg;
fsm.handle_event(slac::fsm::evse::Event::SLAC_MESSAGE);
}
new_event = true;
new_event_cv.notify_all();
}
void FSMController::signal_reset() {
signal_simple_event(slac::fsm::evse::Event::RESET);
}
bool FSMController::signal_enter_bcd() {
return signal_simple_event(slac::fsm::evse::Event::ENTER_BCD);
}
bool FSMController::signal_leave_bcd() {
return signal_simple_event(slac::fsm::evse::Event::LEAVE_BCD);
}
bool FSMController::signal_simple_event(slac::fsm::evse::Event ev) {
const std::lock_guard<std::mutex> feed_lck(feed_mtx);
auto event_result = fsm.handle_event(ev);
new_event = true;
new_event_cv.notify_all();
return event_result == fsm::HandleEventResult::SUCCESS;
}
void FSMController::run() {
ctx.log_info("Starting the SLAC state machine");
fsm.reset<slac::fsm::evse::InitState>(ctx);
std::unique_lock<std::mutex> feed_lck(feed_mtx);
running = true;
while (true) {
auto feed_result = fsm.feed();
if (feed_result.transition()) {
// call immediately again
continue;
} else if (feed_result.internal_error() || feed_result.unhandled_event()) {
// FIXME (aw): would need to log here!
} else if (feed_result.has_value() == true) {
const auto timeout = *feed_result;
if (timeout == 0) {
// call feed directly again
continue;
}
new_event_cv.wait_for(feed_lck, std::chrono::milliseconds(timeout), [this] { return new_event; });
} else {
// nothing happened, no return value -> wait for new event
new_event_cv.wait(feed_lck, [this] { return new_event; });
}
if (new_event) {
// we got a new event, reset it and let run feed again
new_event = false;
}
}
}

View File

@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 - 2023 Pionix GmbH and Contributors to EVerest
#ifndef EVSE_SLAC_FSM_CONTROLLER_HPP
#define EVSE_SLAC_FSM_CONTROLLER_HPP
#include <everest/slac/fsm/evse/fsm.hpp>
#include <condition_variable>
#include <mutex>
class FSMController {
public:
explicit FSMController(slac::fsm::evse::Context& ctx);
void signal_new_slac_message(slac::messages::HomeplugMessage&);
void signal_reset();
bool signal_enter_bcd();
bool signal_leave_bcd();
void run();
private:
bool signal_simple_event(slac::fsm::evse::Event ev);
slac::fsm::evse::Context& ctx;
slac::fsm::evse::FSM fsm;
bool running{false};
std::mutex feed_mtx;
std::condition_variable new_event_cv;
bool new_event{false};
};
#endif // EVSE_SLAC_FSM_CONTROLLER_HPP

View File

@@ -0,0 +1,177 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 - 2026 Pionix GmbH and Contributors to EVerest
#include "slacImpl.hpp"
#include <chrono>
#include <future>
#include <everest/slac/io.hpp>
#include <fmt/core.h>
#include <slac/channel.hpp>
#include <thread>
#include "fsm_controller.hpp"
static std::promise<void> module_ready;
// FIXME (aw): this is ugly, but due to the design of the auto-generated module skeleton ..
static std::unique_ptr<FSMController> fsm_ctrl{nullptr};
namespace module {
namespace main {
static std::string mac_to_ascii(const std::string& mac_binary) {
if (mac_binary.size() < 6)
return "";
return fmt::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", mac_binary[0], mac_binary[1], mac_binary[2],
mac_binary[3], mac_binary[4], mac_binary[5]);
}
void slacImpl::init() {
// setup evse fsm thread
std::thread(&slacImpl::run, this).detach();
}
void slacImpl::ready() {
// let the waiting run thread go
module_ready.set_value();
}
void slacImpl::run() {
// wait until ready
module_ready.get_future().get();
if (config.startup_delay_ms > 0) {
EVLOG_info << "Delaying SLAC startup by " << config.startup_delay_ms << "ms";
std::this_thread::sleep_for(std::chrono::milliseconds(config.startup_delay_ms));
EVLOG_info << "Continuing with SLAC initialization";
}
// initialize slac i/o
SlacIO slac_io;
try {
slac_io.init(config.device);
} catch (const std::exception& e) {
EVLOG_error << fmt::format("Couldn't open device {} for SLAC communication. Reason: {}", config.device,
e.what());
raise_error(
error_factory->create_error("generic/CommunicationFault", "", "Could not open device " + config.device));
return;
}
// setup callbacks
slac::fsm::evse::ContextCallbacks callbacks;
callbacks.send_raw_slac = [&slac_io](slac::messages::HomeplugMessage& msg) { slac_io.send(msg); };
callbacks.signal_dlink_ready = [this](bool value) { publish_dlink_ready(value); };
callbacks.signal_state = [this](const std::string& value) {
try {
publish_state(types::slac::string_to_state(value));
} catch (const std::exception& e) {
EVLOG_error << fmt::format("Tried to publish unknown SLAC state '{}'. Error: {}", value, e.what());
}
};
callbacks.signal_error_routine_request = [this]() { publish_request_error_routine(nullptr); };
callbacks.log_debug = [](const std::string& text) { EVLOG_debug << text; };
callbacks.log_info = [](const std::string& text) { EVLOG_info << text; };
callbacks.log_warn = [](const std::string& text) { EVLOG_warning << text; };
callbacks.log_error = [](const std::string& text) { EVLOG_error << text; };
if (config.publish_mac_on_first_parm_req) {
callbacks.signal_ev_mac_address_parm_req = [this](const std::string& mac) { publish_ev_mac_address(mac); };
}
if (config.publish_mac_on_match_cnf) {
callbacks.signal_ev_mac_address_match_cnf = [this](const std::string& mac) { publish_ev_mac_address(mac); };
}
auto fsm_ctx = slac::fsm::evse::Context(callbacks);
fsm_ctx.slac_config.set_key_timeout_ms = config.set_key_timeout_ms;
fsm_ctx.slac_config.slac_init_timeout_ms = config.slac_init_timeout_ms;
fsm_ctx.slac_config.ac_mode_five_percent = config.ac_mode_five_percent;
fsm_ctx.slac_config.sounding_atten_adjustment = config.sounding_attenuation_adjustment;
fsm_ctx.slac_config.chip_reset.enabled = config.do_chip_reset;
fsm_ctx.slac_config.chip_reset.delay_ms = config.chip_reset_delay_ms;
fsm_ctx.slac_config.chip_reset.timeout_ms = config.chip_reset_timeout_ms;
fsm_ctx.slac_config.link_status.do_detect = config.link_status_detection;
fsm_ctx.slac_config.link_status.retry_ms = config.link_status_retry_ms;
fsm_ctx.slac_config.link_status.timeout_ms = config.link_status_timeout_ms;
fsm_ctx.slac_config.link_status.debug_simulate_failed_matching = config.debug_simulate_failed_matching;
fsm_ctx.slac_config.reset_instead_of_fail = config.reset_instead_of_fail;
fsm_ctx.slac_config.regenerate_key_on_reset = !config.hack_disable_regenerate_key_on_reset;
fsm_ctx.slac_config.generate_nmk();
memcpy(fsm_ctx.evse_mac, slac_io.get_mac_addr(), ETH_ALEN);
fsm_ctrl = std::make_unique<FSMController>(fsm_ctx);
// Qualcomm PLC chip emits VS_ATTENUATION_CHARACTERISTICS (vendor MMTYPE 0xA14E) as
// unsolicited broadcasts during sounding from a sibling MAC. FSM does not handle this
// MMTYPE and logs "Received non-expected SLAC message of type 0xA14E" per frame, which
// adds RX/log load. Drop it pre-FSM. Other MMTYPEs (incl. CM_SET_KEY.CNF, CM_ATTEN_PROFILE.IND)
// pass through unchanged.
slac_io.run([](slac::messages::HomeplugMessage& msg) {
if (msg.get_mmtype() == slac::defs::qualcomm::MMTYPE_VS_ATTENUATION_CHARACTERISTICS) {
return;
}
fsm_ctrl->signal_new_slac_message(msg);
});
fsm_ctrl->run();
}
void slacImpl::handle_reset(bool& enable) {
// FIXME (aw): the enable could be used for power saving etc, but it is not implemented yet
// CC: as power saving is not implemented, we actually don't need to reset at beginning of session (enable=true): At
// start of everest it is being reset once and then it is enough to reset at the end of each session. This saves
// some hundreds of msecs at the beginning of the charging session as we do not need to set up keys. Then
// EvseManager can switch on 5% PWM basically immediately as SLAC is already ready.
if (!enable) {
fsm_ctrl->signal_reset();
}
};
void slacImpl::handle_enter_bcd() {
fsm_ctrl->signal_enter_bcd();
};
void slacImpl::handle_leave_bcd() {
fsm_ctrl->signal_leave_bcd();
};
void slacImpl::handle_dlink_terminate() {
// With receiving a D-LINK_TERMINATE.request from HLE, the communication node
// shall leave the logical network within TP_match_leave. All parameters related
// to the current link shall be set to the default value and shall change to the status "Unmatched".
EVLOG_info << "D-LINK_TERMINATE.request received, leaving network.";
fsm_ctrl->signal_reset();
};
void slacImpl::handle_dlink_error() {
// The D-LINK_ERROR.request requests lower layers to terminate the data link and restart the matching
// process by a control pilot transition through state E (on EVSE side this should be state F though)
// CP signal is handled by EvseManager, so we just need to reset the SLAC state machine here.
// DLINK_ERROR will be send from HLC layers when they detect that the connection is dead.
EVLOG_warning << "D-LINK_ERROR.request received";
fsm_ctrl->signal_reset();
};
void slacImpl::handle_dlink_pause() {
// The D-LINK_PAUSE.request requests lower layers to enter a power saving mode. While being in this
// mode, the state will be kept to "Matched".
// So we don't need to do anything here as we do not support low power mode to power down the PLC modem.
// This is optional in ISO15118-3.
EVLOG_info << "D-LINK_PAUSE.request received. Staying in MATCHED, PLC chip stays powered on (low power mode "
"optional in -3)";
};
} // namespace main
} // namespace module

View File

@@ -0,0 +1,85 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef MAIN_SLAC_IMPL_HPP
#define MAIN_SLAC_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/slac/Implementation.hpp>
#include "../EvseSlac.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace main {
struct Conf {
std::string device;
int number_of_sounds;
bool ac_mode_five_percent;
int set_key_timeout_ms;
int sounding_attenuation_adjustment;
bool publish_mac_on_match_cnf;
bool publish_mac_on_first_parm_req;
bool do_chip_reset;
int chip_reset_delay_ms;
int chip_reset_timeout_ms;
bool link_status_detection;
int link_status_retry_ms;
int link_status_timeout_ms;
bool debug_simulate_failed_matching;
bool reset_instead_of_fail;
int startup_delay_ms;
int slac_init_timeout_ms;
bool hack_disable_regenerate_key_on_reset;
};
class slacImpl : public slacImplBase {
public:
slacImpl() = delete;
slacImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<EvseSlac>& mod, Conf& config) :
slacImplBase(ev, "main"), mod(mod), config(config){};
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
protected:
// command handler functions (virtual)
virtual void handle_reset(bool& enable) override;
virtual void handle_enter_bcd() override;
virtual void handle_leave_bcd() override;
virtual void handle_dlink_terminate() override;
virtual void handle_dlink_error() override;
virtual void handle_dlink_pause() override;
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<EvseSlac>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
void run();
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1
// insert other definitions here
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1
} // namespace main
} // namespace module
#endif // MAIN_SLAC_IMPL_HPP