Skip to content

Commit

Permalink
Merge branch 'main' into doc/powermeter_error_handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietfried authored Sep 8, 2024
2 parents 1ecf197 + 5e8371c commit d5def77
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ libevse-security:
# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: v0.16.2
git_tag: 3fef09231f0033a4af5d0af97d35851ecc00d399
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP"
# Josev
Josev:
Expand Down
3 changes: 1 addition & 2 deletions interfaces/ev_board_support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ cmds:
$ref: /ev_board_support#/EvCpState
allow_power_on:
description: >-
Sets allow_power_on flag. If false, contactor must never be switched
on. Onyly for dc charging
Sets allow_power_on flag. If false, contactor must never be switched on.
arguments:
value:
description: 'True: allow power on, false: do not allow power on.'
Expand Down
4 changes: 4 additions & 0 deletions modules/EvManager/main/car_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ void CarSimulation::state_machine() {
// do not draw power if EVSE paused by stopping PWM
if (sim_data.pwm_duty_cycle > 7.0 && sim_data.pwm_duty_cycle < 97.0) {
r_ev_board_support->call_set_cp_state(EvCpState::C);
r_ev_board_support->call_allow_power_on(true);
} else {
r_ev_board_support->call_set_cp_state(EvCpState::B);
r_ev_board_support->call_allow_power_on(false);
}
}
break;
Expand All @@ -49,6 +51,7 @@ void CarSimulation::state_machine() {
// Also draw power if EVSE stopped PWM - this is a break the rules simulator->mode to test the charging
// implementation!
r_ev_board_support->call_set_cp_state(EvCpState::C);
r_ev_board_support->call_allow_power_on(true);
}
break;

Expand All @@ -72,6 +75,7 @@ void CarSimulation::state_machine() {
case SimState::ISO_CHARGING_REGULATED:
if (state_has_changed) {
r_ev_board_support->call_set_cp_state(EvCpState::C);
r_ev_board_support->call_allow_power_on(true);
}
break;
case SimState::BCB_TOGGLE:
Expand Down
2 changes: 1 addition & 1 deletion modules/EvManager/main/car_simulatorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace module::main {
void car_simulatorImpl::init() {
loop_interval_ms = constants::DEFAULT_LOOP_INTERVAL_MS;
register_all_commands();
subscribe_to_external_mqtt();
subscribe_to_variables_on_init();

std::thread(&car_simulatorImpl::run, this).detach();
}

void car_simulatorImpl::ready() {
subscribe_to_external_mqtt();

car_simulation = std::make_unique<CarSimulation>(mod->r_ev_board_support, mod->r_ev, mod->r_slac);

Expand Down
4 changes: 2 additions & 2 deletions modules/OCPP/main/ocpp_1_6_charge_pointImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void ocpp_1_6_charge_pointImpl::ready() {
}

bool ocpp_1_6_charge_pointImpl::handle_stop() {
std::lock_guard<std::mutex>(this->m);
std::lock_guard<std::mutex> lock(this->m);
mod->charging_schedules_timer->stop();
bool success = mod->charge_point->stop();
if (success) {
Expand All @@ -21,7 +21,7 @@ bool ocpp_1_6_charge_pointImpl::handle_stop() {
return success;
}
bool ocpp_1_6_charge_pointImpl::handle_restart() {
std::lock_guard<std::mutex>(this->m);
std::lock_guard<std::mutex> lock(this->m);
mod->charging_schedules_timer->interval(std::chrono::seconds(this->mod->config.PublishChargingScheduleIntervalS));
bool success = mod->charge_point->restart();
if (success) {
Expand Down
4 changes: 2 additions & 2 deletions modules/OCPP/ocpp_generic/ocppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void ocppImpl::ready() {
}

bool ocppImpl::handle_stop() {
std::lock_guard<std::mutex>(this->chargepoint_state_mutex);
std::lock_guard<std::mutex> lock(this->chargepoint_state_mutex);
mod->charging_schedules_timer->stop();
bool success = mod->charge_point->stop();
if (success) {
Expand All @@ -112,7 +112,7 @@ bool ocppImpl::handle_stop() {
}

bool ocppImpl::handle_restart() {
std::lock_guard<std::mutex>(this->chargepoint_state_mutex);
std::lock_guard<std::mutex> lock(this->chargepoint_state_mutex);
mod->charging_schedules_timer->interval(std::chrono::seconds(this->mod->config.PublishChargingScheduleIntervalS));
bool success = mod->charge_point->restart();
if (success) {
Expand Down
1 change: 1 addition & 0 deletions modules/OCPP201/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ to_ocpp_meter_value(const types::powermeter::Powermeter& power_meter,
if (power_meter.energy_Wh_import_signed.has_value()) {
sampled_value = to_ocpp_sampled_value(reading_context, ocpp::v201::MeasurandEnum::Energy_Active_Import_Register,
"Wh", std::nullopt);
sampled_value.value = power_meter.energy_Wh_import.total;
const auto& energy_Wh_import_signed = power_meter.energy_Wh_import_signed.value();
if (energy_Wh_import_signed.total.has_value()) {
sampled_value.signedMeterValue = to_ocpp_signed_meter_value(energy_Wh_import_signed.total.value());
Expand Down
1 change: 1 addition & 0 deletions modules/PhyVersoBSP/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ IMPLS = [
cc_everest_module(
name = "PhyVersoBSP",
deps = [
"//modules/PhyVersoBSP/phyverso_gpio",
"//modules/PhyVersoBSP/phyverso_mcu_comms",
],
impls = IMPLS,
Expand Down
4 changes: 4 additions & 0 deletions modules/PhyVersoBSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ev_setup_cpp_module()
# insert your custom targets and additional config variables here
add_subdirectory(phyverso_mcu_comms)
add_subdirectory(phyverso_cli)
add_subdirectory(phyverso_gpio)

target_include_directories(${MODULE_NAME}
PRIVATE
Expand All @@ -19,13 +20,16 @@ target_include_directories(${MODULE_NAME}
"phyverso_mcu_comms/nanopb"
"phyverso_mcu_comms/protobuf"
"phyverso_config"
"phyverso_gpio"
)

target_link_libraries(${MODULE_NAME}
PRIVATE
Pal::Sigslot
everest::gpio
phyverso_mcu_comms
phyverso_config
phyverso_gpio
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

Expand Down
20 changes: 15 additions & 5 deletions modules/PhyVersoBSP/PhyVersoBSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ void PhyVersoBSP::init() {
return;
}

// init user gpios
if (not gpio.init_gpios()) {
EVLOG_error << "Could not initialize user GPIOs. Terminating.";
return;
}

invoke_init(*p_connector_1);
invoke_init(*p_connector_2);
invoke_init(*p_rcd_1);
Expand All @@ -26,10 +32,6 @@ void PhyVersoBSP::init() {
invoke_init(*p_system_specific_data_1);
invoke_init(*p_system_specific_data_2);

// pass PhyVersoBSP module config values to evConfig (everest/standalone json config bridge to evSerial that is
// talking to MCU)
everest_config_to_verso_config();

serial.signal_config_request.connect([&]() {
serial.send_config();
EVLOG_info << "Sent config packet to MCU";
Expand All @@ -38,6 +40,7 @@ void PhyVersoBSP::init() {

void PhyVersoBSP::ready() {
serial.run();
gpio.run();

invoke_ready(*p_connector_1);
invoke_ready(*p_connector_2);
Expand All @@ -61,13 +64,20 @@ void PhyVersoBSP::ready() {

// fills evConfig bridge with config values from manifest/everest config
void PhyVersoBSP::everest_config_to_verso_config() {
// TODO: fill evConfig Conf struct with this modules conf structure values
verso_config.conf.serial_port = this->config.serial_port;
verso_config.conf.baud_rate = this->config.baud_rate;
verso_config.conf.reset_gpio_bank = this->config.reset_gpio_bank;
verso_config.conf.reset_gpio_pin = this->config.reset_gpio_pin;
verso_config.conf.conn1_motor_lock_type = this->config.conn1_motor_lock_type;
verso_config.conf.conn2_motor_lock_type = this->config.conn2_motor_lock_type;
verso_config.conf.conn1_gpio_stop_button_enabled = this->config.conn1_gpio_stop_button_enabled;
verso_config.conf.conn1_gpio_stop_button_bank = this->config.conn1_gpio_stop_button_bank;
verso_config.conf.conn1_gpio_stop_button_pin = this->config.conn1_gpio_stop_button_pin;
verso_config.conf.conn1_gpio_stop_button_invert = this->config.conn1_gpio_stop_button_invert;
verso_config.conf.conn2_gpio_stop_button_enabled = this->config.conn2_gpio_stop_button_enabled;
verso_config.conf.conn2_gpio_stop_button_bank = this->config.conn2_gpio_stop_button_bank;
verso_config.conf.conn2_gpio_stop_button_pin = this->config.conn2_gpio_stop_button_pin;
verso_config.conf.conn2_gpio_stop_button_invert = this->config.conn2_gpio_stop_button_invert;
}

} // namespace module
15 changes: 13 additions & 2 deletions modules/PhyVersoBSP/PhyVersoBSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
#include "phyverso_gpio/evGpio.h"
#include "phyverso_mcu_comms/evSerial.h"
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1

Expand Down Expand Up @@ -52,6 +53,14 @@ struct Conf {
int reset_gpio_pin;
int conn1_motor_lock_type;
int conn2_motor_lock_type;
bool conn1_gpio_stop_button_enabled;
std::string conn1_gpio_stop_button_bank;
int conn1_gpio_stop_button_pin;
bool conn1_gpio_stop_button_invert;
bool conn2_gpio_stop_button_enabled;
std::string conn2_gpio_stop_button_bank;
int conn2_gpio_stop_button_pin;
bool conn2_gpio_stop_button_invert;
};

class PhyVersoBSP : public Everest::ModuleBase {
Expand All @@ -78,7 +87,8 @@ class PhyVersoBSP : public Everest::ModuleBase {
p_system_specific_data_1(std::move(p_system_specific_data_1)),
p_system_specific_data_2(std::move(p_system_specific_data_2)),
config(config),
serial(verso_config){};
serial(verso_config),
gpio(verso_config){};

Everest::MqttProvider& mqtt;
Everest::TelemetryProvider& telemetry;
Expand All @@ -96,6 +106,8 @@ class PhyVersoBSP : public Everest::ModuleBase {
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
evSerial serial;
evConfig verso_config;
evGpio gpio;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1

protected:
Expand All @@ -110,7 +122,6 @@ class PhyVersoBSP : public Everest::ModuleBase {

// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
evConfig verso_config;
void everest_config_to_verso_config();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
Expand Down
10 changes: 10 additions & 0 deletions modules/PhyVersoBSP/connector_1/evse_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ void evse_board_supportImpl::init() {
}
last_pp_state = s;
});

mod->gpio.signal_stop_button_state.connect([this](int connector, bool state) {
if (connector == 1 && (state != last_stop_button_state)) {
types::evse_manager::StopTransactionRequest request;
request.reason = types::evse_manager::StopTransactionReason::Local;
this->publish_request_stop_transaction(request);
EVLOG_info << "[1] Request stop button state: " << (state ? "PUSHED" : "RELEASED");
last_stop_button_state = state;
}
});
}

void evse_board_supportImpl::ready() {
Expand Down
2 changes: 2 additions & 0 deletions modules/PhyVersoBSP/connector_1/evse_board_supportImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
#include "board_support_common.hpp"
#include "evGpio.h"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1

namespace module {
Expand Down Expand Up @@ -60,6 +61,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
std::mutex caps_mutex;
CpState last_cp_state;
PpState last_pp_state; ///< The last pp state received from the MCU.
bool last_stop_button_state;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
10 changes: 10 additions & 0 deletions modules/PhyVersoBSP/connector_2/evse_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ void evse_board_supportImpl::init() {
}
last_pp_state = s;
});

mod->gpio.signal_stop_button_state.connect([this](int connector, bool state) {
if (connector == 2 && (state != last_stop_button_state)) {
types::evse_manager::StopTransactionRequest request;
request.reason = types::evse_manager::StopTransactionReason::Local;
this->publish_request_stop_transaction(request);
EVLOG_info << "[2] Request stop button state: " << (state ? "PUSHED" : "RELEASED");
last_stop_button_state = state;
}
});
}

void evse_board_supportImpl::ready() {
Expand Down
1 change: 1 addition & 0 deletions modules/PhyVersoBSP/connector_2/evse_board_supportImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
std::mutex caps_mutex;
CpState last_cp_state;
PpState last_pp_state; ///< The last pp state received from the MCU.
bool last_stop_button_state;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
32 changes: 32 additions & 0 deletions modules/PhyVersoBSP/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ config:
description: Connector 2 motor lock type; 1 == Hella Style time-based lock, 2 == Valeo potentiometer feedback based
type: integer
default: 2
conn1_gpio_stop_button_enabled:
description: Set to true to enable external charging stop button for connector 1 on a GPIO connected to the SOM
type: boolean
default: false
conn1_gpio_stop_button_bank:
description: GPIO peripheral bank for connector 1 stop button
type: string
default: gpiochip1
conn1_gpio_stop_button_pin:
description: GPIO peripheral pin for connector 1 stop button
type: integer
default: 36
conn1_gpio_stop_button_invert:
description: Set to true to invert pin logic
type: boolean
default: false
conn2_gpio_stop_button_enabled:
description: Set to true to enable external charging stop button for connector 2 on a GPIO connected to the SOM
type: boolean
default: false
conn2_gpio_stop_button_bank:
description: GPIO peripheral bank for connector 2 stop button
type: string
default: gpiochip1
conn2_gpio_stop_button_pin:
description: GPIO peripheral pin for connector 2 stop button
type: integer
default: 37
conn2_gpio_stop_button_invert:
description: Set to true to invert pin logic
type: boolean
default: false
provides:
connector_1:
interface: evse_board_support
Expand Down
18 changes: 18 additions & 0 deletions modules/PhyVersoBSP/phyverso_gpio/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cc_library(
name = "phyverso_gpio",
deps = [
"//modules/PhyVersoBSP/phyverso_mcu_comms",
"//lib/staging/gpio",
"@sigslot//:sigslot",
],
srcs = glob([
"**/*.h",
"**/*.c",
"**/*.cpp",
]),
visibility = ["//visibility:public"],
includes = [
".",
],
copts = ["-std=c++17"],
)
31 changes: 31 additions & 0 deletions modules/PhyVersoBSP/phyverso_gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.10)

# set the project name
project(phyverso_gpio VERSION 0.1)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_library(phyverso_gpio STATIC)
target_sources(phyverso_gpio
PRIVATE
evGpio.cpp
)

target_include_directories(phyverso_gpio
PUBLIC
"${PROJECT_BINARY_DIR}"
"../phyverso_mcu_comms"
)

target_link_libraries(phyverso_gpio
PUBLIC
date::date-tz
everest::nanopb
PRIVATE
Pal::Sigslot
everest::framework
everest::gpio
phyverso_config
fmt::fmt
)
Loading

0 comments on commit d5def77

Please sign in to comment.