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

Extend PhyVersoBSP with PpState, Temperature and OpaqueData #687

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions interfaces/generic_array.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: This interface publishes just generic data blobs.
vars:
vector_of_ints:
description: data blob.
type: object
$ref: /generic_array#/VectorOfInts
6 changes: 6 additions & 0 deletions interfaces/phyverso_mcu_temperature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Temperatures from MCU
vars:
MCUTemperatures:
description: Temperatures
type: object
$ref: /phyverso_mcu_temperature#/MCUTemperatures
22 changes: 22 additions & 0 deletions modules/PhyVersoBSP/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("//modules:module.bzl", "cc_everest_module")

IMPLS = [
"connector_2",
"connector_1",
"rcd_1",
"rcd_2",
"connector_lock_1",
"connector_lock_2",
"phyverso_mcu_temperature",
"system_specific_data_1",
"system_specific_data_2",
]

cc_everest_module(
name = "PhyVersoBSP",
deps = [
"//modules/PhyVersoBSP/phyverso_mcu_comms",
],
impls = IMPLS,
srcs = ["board_support_common.cpp", "board_support_common.hpp"],
)
4 changes: 3 additions & 1 deletion modules/PhyVersoBSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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_config)

target_include_directories(${MODULE_NAME}
PRIVATE
Expand All @@ -38,6 +37,9 @@ target_sources(${MODULE_NAME}
"rcd_2/ac_rcdImpl.cpp"
"connector_lock_1/connector_lockImpl.cpp"
"connector_lock_2/connector_lockImpl.cpp"
"phyverso_mcu_temperature/phyverso_mcu_temperatureImpl.cpp"
"system_specific_data_1/generic_arrayImpl.cpp"
"system_specific_data_2/generic_arrayImpl.cpp"
)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
Expand Down
6 changes: 6 additions & 0 deletions modules/PhyVersoBSP/PhyVersoBSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ void PhyVersoBSP::init() {
invoke_init(*p_rcd_2);
invoke_init(*p_connector_lock_1);
invoke_init(*p_connector_lock_2);
invoke_init(*p_phyverso_mcu_temperature);
invoke_init(*p_system_specific_data_1);
invoke_init(*p_system_specific_data_2);

std::filesystem::path mcu_config_file = config.mcu_config_file;

Expand Down Expand Up @@ -47,6 +50,9 @@ void PhyVersoBSP::ready() {
invoke_ready(*p_rcd_2);
invoke_ready(*p_connector_lock_1);
invoke_ready(*p_connector_lock_2);
invoke_ready(*p_phyverso_mcu_temperature);
invoke_ready(*p_system_specific_data_1);
invoke_ready(*p_system_specific_data_2);
}

} // namespace module
14 changes: 12 additions & 2 deletions modules/PhyVersoBSP/PhyVersoBSP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#ifndef PHY_VERSO_BSP_HPP
#define PHY_VERSO_BSP_HPP

Expand All @@ -15,6 +14,8 @@
#include <generated/interfaces/ac_rcd/Implementation.hpp>
#include <generated/interfaces/connector_lock/Implementation.hpp>
#include <generated/interfaces/evse_board_support/Implementation.hpp>
#include <generated/interfaces/generic_array/Implementation.hpp>
#include <generated/interfaces/phyverso_mcu_temperature/Implementation.hpp>

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
Expand Down Expand Up @@ -57,7 +58,10 @@ class PhyVersoBSP : public Everest::ModuleBase {
std::unique_ptr<evse_board_supportImplBase> p_connector_1,
std::unique_ptr<evse_board_supportImplBase> p_connector_2, std::unique_ptr<ac_rcdImplBase> p_rcd_1,
std::unique_ptr<ac_rcdImplBase> p_rcd_2, std::unique_ptr<connector_lockImplBase> p_connector_lock_1,
std::unique_ptr<connector_lockImplBase> p_connector_lock_2, Conf& config) :
std::unique_ptr<connector_lockImplBase> p_connector_lock_2,
std::unique_ptr<phyverso_mcu_temperatureImplBase> p_phyverso_mcu_temperature,
std::unique_ptr<generic_arrayImplBase> p_system_specific_data_1,
std::unique_ptr<generic_arrayImplBase> p_system_specific_data_2, Conf& config) :
ModuleBase(info),
mqtt(mqtt_provider),
telemetry(telemetry),
Expand All @@ -67,6 +71,9 @@ class PhyVersoBSP : public Everest::ModuleBase {
p_rcd_2(std::move(p_rcd_2)),
p_connector_lock_1(std::move(p_connector_lock_1)),
p_connector_lock_2(std::move(p_connector_lock_2)),
p_phyverso_mcu_temperature(std::move(p_phyverso_mcu_temperature)),
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){};

Everest::MqttProvider& mqtt;
Expand All @@ -77,6 +84,9 @@ class PhyVersoBSP : public Everest::ModuleBase {
const std::unique_ptr<ac_rcdImplBase> p_rcd_2;
const std::unique_ptr<connector_lockImplBase> p_connector_lock_1;
const std::unique_ptr<connector_lockImplBase> p_connector_lock_2;
const std::unique_ptr<phyverso_mcu_temperatureImplBase> p_phyverso_mcu_temperature;
const std::unique_ptr<generic_arrayImplBase> p_system_specific_data_1;
const std::unique_ptr<generic_arrayImplBase> p_system_specific_data_2;
const Conf& config;

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
Expand Down
29 changes: 27 additions & 2 deletions modules/PhyVersoBSP/connector_1/evse_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void evse_board_supportImpl::init() {
EVLOG_info << "[1] CP Voltage: " << t.cp_voltage_hi << " " << t.cp_voltage_lo;
}
});

mod->serial.signal_pp_state.connect([this](int connector, PpState s) {
if (connector == 1) {
EVLOG_info << "[1] PpState " << s;
}
last_pp_state = s;
});
}

void evse_board_supportImpl::ready() {
Expand Down Expand Up @@ -108,8 +115,26 @@ void evse_board_supportImpl::handle_evse_replug(int& value) {
}

types::board_support_common::ProximityPilot evse_board_supportImpl::handle_ac_read_pp_ampacity() {
// IMPLEMENT ME
return {types::board_support_common::Ampacity::A_32};
switch (last_pp_state) {
case PpState_STATE_NC: {
return {types::board_support_common::Ampacity::None};
}
case PpState_STATE_13A: {
return {types::board_support_common::Ampacity::A_13};
}
case PpState_STATE_20A: {
return {types::board_support_common::Ampacity::A_20};
}
case PpState_STATE_32A: {
return {types::board_support_common::Ampacity::A_32};
}
case PpState_STATE_70A: {
return {types::board_support_common::Ampacity::A_63_3ph_70_1ph};
}
default: {
return {types::board_support_common::Ampacity::None};
}
}
}

void evse_board_supportImpl::handle_ac_set_overcurrent_limit_A(double& value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
types::evse_board_support::HardwareCapabilities caps;
std::mutex caps_mutex;
CpState last_cp_state;
PpState last_pp_state; ///< The last pp state received from the MCU.
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
29 changes: 27 additions & 2 deletions modules/PhyVersoBSP/connector_2/evse_board_supportImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void evse_board_supportImpl::init() {
EVLOG_info << "[2] CP Voltage: " << t.cp_voltage_hi << " " << t.cp_voltage_lo;
}
});

mod->serial.signal_pp_state.connect([this](int connector, PpState s) {
if (connector == 2) {
EVLOG_info << "[2] PpState " << s;
}
last_pp_state = s;
});
}

void evse_board_supportImpl::ready() {
Expand Down Expand Up @@ -108,8 +115,26 @@ void evse_board_supportImpl::handle_evse_replug(int& value) {
}

types::board_support_common::ProximityPilot evse_board_supportImpl::handle_ac_read_pp_ampacity() {
// IMPLEMENT ME
return {types::board_support_common::Ampacity::A_32};
switch (last_pp_state) {
case PpState_STATE_NC: {
return {types::board_support_common::Ampacity::None};
}
case PpState_STATE_13A: {
return {types::board_support_common::Ampacity::A_13};
}
case PpState_STATE_20A: {
return {types::board_support_common::Ampacity::A_20};
}
case PpState_STATE_32A: {
return {types::board_support_common::Ampacity::A_32};
}
case PpState_STATE_70A: {
return {types::board_support_common::Ampacity::A_63_3ph_70_1ph};
}
default: {
return {types::board_support_common::Ampacity::None};
}
}
}

void evse_board_supportImpl::handle_ac_set_overcurrent_limit_A(double& value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class evse_board_supportImpl : public evse_board_supportImplBase {
types::evse_board_support::HardwareCapabilities caps;
std::mutex caps_mutex;
CpState last_cp_state;
PpState last_pp_state; ///< The last pp state received from the MCU.
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down
6 changes: 4 additions & 2 deletions modules/PhyVersoBSP/connector_lock_1/connector_lockImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ void connector_lockImpl::ready() {
}

void connector_lockImpl::handle_lock() {
// your code for cmd lock goes here
EVLOG_info << "Locking connector 1";
mod->serial.lock(1, true);
}

void connector_lockImpl::handle_unlock() {
// your code for cmd unlock goes here
EVLOG_info << "Unlocking connector 1";
mod->serial.lock(1, false);
}

} // namespace connector_lock_1
Expand Down
6 changes: 4 additions & 2 deletions modules/PhyVersoBSP/connector_lock_2/connector_lockImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ void connector_lockImpl::ready() {
}

void connector_lockImpl::handle_lock() {
// your code for cmd lock goes here
EVLOG_info << "Locking connector 2";
mod->serial.lock(2, true);
}

void connector_lockImpl::handle_unlock() {
// your code for cmd unlock goes here
EVLOG_info << "Unlocking connector 2";
mod->serial.lock(2, false);
}

} // namespace connector_lock_2
Expand Down
9 changes: 9 additions & 0 deletions modules/PhyVersoBSP/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ provides:
connector_lock_2:
interface: connector_lock
description: Lock interface
phyverso_mcu_temperature:
interface: phyverso_mcu_temperature
description: Temperatures from MCU
system_specific_data_1:
interface: generic_array
description: Opaque data blobs coming from connector 1
system_specific_data_2:
interface: generic_array
description: Opaque data blobs coming from connector 2
enable_external_mqtt: true
enable_telemetry: true
metadata:
Expand Down
23 changes: 23 additions & 0 deletions modules/PhyVersoBSP/phyverso_cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ void help() {
printf("\nUsage: ./phyverso_cli /dev/ttyXXX /path/to/config.json\n\n");
}

constexpr auto REFERENCE_VOLTAGE = 3.3;
constexpr auto NUMBER_OF_BITS = 12;
constexpr auto VOLTAGE_TO_TEMPERATURE_SLOPE = -31.0;
constexpr auto VOLTAGE_TO_TEMPERATURE_OFFSET = 92.8;

/// @brief Converts the raw reading to temperature.
float get_temp(int raw) {
float voltage = (static_cast<float>(raw) / ((1 << NUMBER_OF_BITS) - 1)) * REFERENCE_VOLTAGE;
return VOLTAGE_TO_TEMPERATURE_SLOPE * voltage + VOLTAGE_TO_TEMPERATURE_OFFSET;
}

int main(int argc, char* argv[]) {
int selected_connector = 1;

Expand Down Expand Up @@ -148,6 +159,18 @@ int main(int argc, char* argv[]) {
}
});

p.signal_temperature.connect([](Temperature t) {
printf("Temperatures reported: ");
for (size_t i = 0; i < t.temp_count; ++i) {
printf("[T_%zu]: %.1f\t", i, get_temp(t.temp[i]));
}
printf("\n");
});

p.signal_opaque_data.connect([](int connector, const std::vector<int32_t>& data) {
printf("Received data from connector %i\n", connector);
});

while (true) {
char c = getc(stdin);
switch (c) {
Expand Down
28 changes: 0 additions & 28 deletions modules/PhyVersoBSP/phyverso_config/CMakeLists.txt

This file was deleted.

46 changes: 46 additions & 0 deletions modules/PhyVersoBSP/phyverso_mcu_comms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cc_library(
name = "phyverso_config",
deps = [
"//lib/3rd_party/nanopb",
"@everest-framework//:framework",
],
srcs = glob([
"protobuf/*.h",
"protobuf/*.c",
]) + [
"evConfig.h",
"evConfig.cpp"
],
visibility = ["//visibility:public"],
includes = [
".",
"protobuf",
],
)

cc_library(
name = "phyverso_mcu_comms",
deps = [
":phyverso_config",
"//lib/3rd_party/nanopb",
"@com_github_HowardHinnant_date//:date",
"@everest-framework//:framework",
"@sigslot//:sigslot",
],
srcs = glob([
"**/*.h",
"**/*.c",
"**/*.cpp",
],
exclude = [
"evConfig.h",
"evConfig.cpp",
]),
visibility = ["//visibility:public"],
includes = [
".",
"protobuf",
"bsl",
],
copts = ["-std=c++17"],
)
Loading
Loading