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,5 @@
add_subdirectory(CppExamples)
if(${EVEREST_ENABLE_RS_SUPPORT})
add_subdirectory(RustExamples)
endif()
add_subdirectory(error-framework)

View File

@@ -0,0 +1,5 @@
ev_add_module(Example)
ev_add_module(ExampleUser)
ev_add_module(TerminalCostAndPriceMessage)
ev_add_module(TerminalDisplayMessage)
ev_add_module(OCPPExtensionExample)

View File

@@ -0,0 +1,22 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"example/exampleImpl.cpp"
"store/kvsImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
#include "Example.hpp"
namespace module {
void Example::init() {
invoke_init(*p_example);
invoke_init(*p_store);
}
void Example::ready() {
invoke_ready(*p_example);
invoke_ready(*p_store);
mqtt.publish("external/topic", "data");
}
} // namespace module

View File

@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_HPP
#define EXAMPLE_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/example/Implementation.hpp>
#include <generated/interfaces/kvs/Implementation.hpp>
// headers for required interface implementations
#include <generated/interfaces/kvs/Interface.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class Example : public Everest::ModuleBase {
public:
Example() = delete;
Example(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, std::unique_ptr<exampleImplBase> p_example,
std::unique_ptr<kvsImplBase> p_store, std::unique_ptr<kvsIntf> r_kvs, Conf& config) :
ModuleBase(info),
mqtt(mqtt_provider),
p_example(std::move(p_example)),
p_store(std::move(p_store)),
r_kvs(std::move(r_kvs)),
config(config){};
Everest::MqttProvider& mqtt;
const std::unique_ptr<exampleImplBase> p_example;
const std::unique_ptr<kvsImplBase> p_store;
const std::unique_ptr<kvsIntf> r_kvs;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // EXAMPLE_HPP

View File

@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
#include "exampleImpl.hpp"
// initial cpp template for interface example_child
// this file should not be overwritten by the code generator again
namespace module {
namespace example {
void exampleImpl::init() {
mod->mqtt.subscribe("external/a",
[](json data) { EVLOG_error << "received data from external MQTT handler: " << data.dump(); });
}
void exampleImpl::ready() {
publish_max_current(config.current);
mod->r_kvs->call_store("test", "test");
}
bool exampleImpl::handle_uses_something(std::string& key) {
if (mod->r_kvs->call_exists(key)) {
EVLOG_debug << "IT SHOULD NOT AND DOES NOT EXIST";
}
Array test_array = {1, 2, 3};
mod->r_kvs->call_store(key, test_array);
bool exi = mod->r_kvs->call_exists(key);
if (exi) {
EVLOG_debug << "IT ACTUALLY EXISTS";
}
auto ret = mod->r_kvs->call_load(key);
Array arr = std::get<Array>(ret);
EVLOG_debug << "loaded array: " << arr << ", original array: " << test_array;
return exi;
};
} // namespace example
} // namespace module

View File

@@ -0,0 +1,65 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_EXAMPLE_IMPL_HPP
#define EXAMPLE_EXAMPLE_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/example/Implementation.hpp>
#include "../Example.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace example {
struct Conf {
double current;
std::string enum_test;
int enum_test2;
};
class exampleImpl : public exampleImplBase {
public:
exampleImpl() = delete;
exampleImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<Example>& mod, Conf& config) :
exampleImplBase(ev, "example"), 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 bool handle_uses_something(std::string& key) override;
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<Example>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
// 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 example
} // namespace module
#endif // EXAMPLE_EXAMPLE_IMPL_HPP

View File

@@ -0,0 +1,37 @@
description: Simple example module written in C++
provides:
example:
interface: example
description: This implements an example interface that uses multiple framework features
config:
current:
description: The current the physical connector can supply
type: number
minimum: 1
maximum: 60
enum_test:
description: A config value that tests the enum type
type: string
enum:
- one
- two
- three
enum_test2:
description: Another config value that tests the enum type
type: integer
enum:
- 1
- 2
- 3
store:
interface: kvs
description: This implements the kvs interface, mostly for testing multiple interfaces in one manifest
requires:
kvs:
interface: kvs
enable_external_mqtt: true
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Kai-Uwe Hermann
- Andreas Heinrich

View File

@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
#include "kvsImpl.hpp"
namespace module {
namespace store {
void kvsImpl::init() {
}
void kvsImpl::ready() {
}
void kvsImpl::handle_store(std::string& key,
std::variant<std::nullptr_t, Array, Object, bool, double, int, std::string>& value) {
mod->r_kvs->call_store(key, value);
};
std::variant<std::nullptr_t, Array, Object, bool, double, int, std::string> kvsImpl::handle_load(std::string& key) {
return mod->r_kvs->call_load(key);
};
void kvsImpl::handle_delete(std::string& key) {
mod->r_kvs->call_delete(key);
};
bool kvsImpl::handle_exists(std::string& key) {
return mod->r_kvs->call_exists(key);
};
} // namespace store
} // namespace module

View File

@@ -0,0 +1,67 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef STORE_KVS_IMPL_HPP
#define STORE_KVS_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/kvs/Implementation.hpp>
#include "../Example.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace store {
struct Conf {};
class kvsImpl : public kvsImplBase {
public:
kvsImpl() = delete;
kvsImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<Example>& mod, Conf& config) :
kvsImplBase(ev, "store"), 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_store(std::string& key,
std::variant<std::nullptr_t, Array, Object, bool, double, int, std::string>& value) override;
virtual std::variant<std::nullptr_t, Array, Object, bool, double, int, std::string>
handle_load(std::string& key) override;
virtual void handle_delete(std::string& key) override;
virtual bool handle_exists(std::string& key) override;
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<Example>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
// 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 store
} // namespace module
#endif // STORE_KVS_IMPL_HPP

View File

@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"example_user/example_userImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
#include "ExampleUser.hpp"
namespace module {
void ExampleUser::init() {
invoke_init(*p_example_user);
}
void ExampleUser::ready() {
invoke_ready(*p_example_user);
}
} // namespace module

View File

@@ -0,0 +1,63 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_USER_HPP
#define EXAMPLE_USER_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/example_user/Implementation.hpp>
// headers for required interface implementations
#include <generated/interfaces/example/Interface.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class ExampleUser : public Everest::ModuleBase {
public:
ExampleUser() = delete;
ExampleUser(const ModuleInfo& info, std::unique_ptr<example_userImplBase> p_example_user,
std::unique_ptr<exampleIntf> r_example, Conf& config) :
ModuleBase(info), p_example_user(std::move(p_example_user)), r_example(std::move(r_example)), config(config){};
const std::unique_ptr<example_userImplBase> p_example_user;
const std::unique_ptr<exampleIntf> r_example;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // EXAMPLE_USER_HPP

View File

@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
#include "example_userImpl.hpp"
namespace module {
namespace example_user {
void example_userImpl::init() {
}
void example_userImpl::ready() {
mod->r_example->call_uses_something("hello_there");
}
} // namespace example_user
} // namespace module

View File

@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_USER_EXAMPLE_USER_IMPL_HPP
#define EXAMPLE_USER_EXAMPLE_USER_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/example_user/Implementation.hpp>
#include "../ExampleUser.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace example_user {
struct Conf {};
class example_userImpl : public example_userImplBase {
public:
example_userImpl() = delete;
example_userImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<ExampleUser>& mod, Conf& config) :
example_userImplBase(ev, "example_user"), mod(mod), config(config){};
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
protected:
// no commands defined for this interface
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<ExampleUser>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
Everest::error::ErrorHandle received_error;
// 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 example_user
} // namespace module
#endif // EXAMPLE_USER_EXAMPLE_USER_IMPL_HPP

View File

@@ -0,0 +1,13 @@
description: Simple example module written in C++ and using the other example module
provides:
example_user:
interface: example_user
description: This implements the example_user interface
requires:
example:
interface: example
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Kai-Uwe Hermann
- Andreas Heinrich

View File

@@ -0,0 +1,22 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"data_transfer/ocpp_data_transferImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
install(FILES Custom.json DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP/profile_schemas)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Json schema for Custom configuration keys",
"$comment": "This is just an example schema and can be modified according to custom requirements",
"type": "object",
"required": [],
"properties": {
"ExampleConfigurationKey": {
"type": "string",
"description": "Custom key",
"readOnly": false
}
}
}

View File

@@ -0,0 +1,93 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "OCPPExtensionExample.hpp"
namespace module {
void OCPPExtensionExample::init() {
invoke_init(*p_data_transfer);
}
void OCPPExtensionExample::ready() {
invoke_ready(*p_data_transfer);
std::istringstream ss(this->config.keys_to_monitor);
std::vector<types::ocpp::ComponentVariable> component_variables;
std::string key;
while (std::getline(ss, key, ',')) {
// Push each token into the vector
component_variables.push_back({{""}, {key}}); // For OCPP1.6 we only need to specify the variable.name
}
// We register monitors for custom configuration keys here
this->r_ocpp->call_monitor_variables(component_variables);
// anytime this configuration key is changed by the CSMS and we have
// registered a monitor, this callback is executed
this->r_ocpp->subscribe_event_data([](types::ocpp::EventData event_data) {
// Add your custom handler here
EVLOG_info << "Configuration key: " << event_data.component_variable.variable.name
<< " has been changed by CSMS to: " << event_data.actual_value;
});
std::vector<types::ocpp::SetVariableRequest> set_variable_requests;
set_variable_requests.push_back({{{""}, {"ExampleConfigurationKey"}}, "ExampleValue"});
EVLOG_info << "Setting custom configuration key...";
const auto set_variable_results = this->r_ocpp->call_set_variables(set_variable_requests, "example");
for (const auto& set_variable_result : set_variable_results) {
if (set_variable_result.status == types::ocpp::SetVariableStatusEnumType::Accepted) {
EVLOG_info << "Successfully set ExampleConfigurationKey";
} else {
EVLOG_info << "Could not set ExampleConfigurationKey: "
<< types::ocpp::set_variable_status_enum_type_to_string(set_variable_result.status);
}
}
// adding a configuration key that does not exist to show that this will be
// part of the unknown keys of the result
component_variables.push_back({{""}, {"KeyThatIsNotConfigured"}});
std::vector<types::ocpp::GetVariableRequest> get_variables_requests;
for (const auto& component_variable : component_variables) {
get_variables_requests.push_back({component_variable});
}
EVLOG_info << "Requesting configuration keys from OCPP...";
const auto get_variables_results = this->r_ocpp->call_get_variables(get_variables_requests);
for (const auto& get_variables_result : get_variables_results) {
if (get_variables_result.status == types::ocpp::GetVariableStatusEnumType::Accepted) {
EVLOG_info << "Key: " << get_variables_result.component_variable.variable.name << ": "
<< get_variables_result.value.value();
} else {
EVLOG_info << "Unknown: " << get_variables_result.component_variable.variable.name;
}
}
types::ocpp::DataTransferRequest data_transfer_request;
data_transfer_request.vendor_id = "EVerest";
data_transfer_request.data.emplace("hi");
auto data_transfer_response = this->r_data_transfer->call_data_transfer(data_transfer_request);
switch (data_transfer_response.status) {
case types::ocpp::DataTransferStatus::Accepted:
EVLOG_info << "Data transfer was accepted";
break;
case types::ocpp::DataTransferStatus::Rejected:
EVLOG_info << "Data transfer was rejected";
break;
case types::ocpp::DataTransferStatus::UnknownVendorId:
EVLOG_info << "Data transfer was rejected (UnknownVendorId)";
break;
case types::ocpp::DataTransferStatus::UnknownMessageId:
EVLOG_info << "Data transfer was rejected (UnknownMessageId)";
break;
default:
break;
}
}
} // namespace module

View File

@@ -0,0 +1,72 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef OCPPEXTENSION_EXAMPLE_HPP
#define OCPPEXTENSION_EXAMPLE_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/ocpp_data_transfer/Implementation.hpp>
// headers for required interface implementations
#include <generated/interfaces/ocpp/Interface.hpp>
#include <generated/interfaces/ocpp_data_transfer/Interface.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {
std::string keys_to_monitor;
};
class OCPPExtensionExample : public Everest::ModuleBase {
public:
OCPPExtensionExample() = delete;
OCPPExtensionExample(const ModuleInfo& info, std::unique_ptr<ocpp_data_transferImplBase> p_data_transfer,
std::unique_ptr<ocppIntf> r_ocpp, std::unique_ptr<ocpp_data_transferIntf> r_data_transfer,
Conf& config) :
ModuleBase(info),
p_data_transfer(std::move(p_data_transfer)),
r_ocpp(std::move(r_ocpp)),
r_data_transfer(std::move(r_data_transfer)),
config(config){};
const std::unique_ptr<ocpp_data_transferImplBase> p_data_transfer;
const std::unique_ptr<ocppIntf> r_ocpp;
const std::unique_ptr<ocpp_data_transferIntf> r_data_transfer;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // OCPPEXTENSION_EXAMPLE_HPP

View File

@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "ocpp_data_transferImpl.hpp"
namespace module {
namespace data_transfer {
void ocpp_data_transferImpl::init() {
}
void ocpp_data_transferImpl::ready() {
}
types::ocpp::DataTransferResponse
ocpp_data_transferImpl::handle_data_transfer(types::ocpp::DataTransferRequest& request) {
types::ocpp::DataTransferResponse response;
response.status = types::ocpp::DataTransferStatus::Rejected;
if (request.vendor_id == "EVerest") {
response.data = "hello there";
response.status = types::ocpp::DataTransferStatus::Accepted;
} else {
response.status = types::ocpp::DataTransferStatus::UnknownVendorId;
}
return response;
}
} // namespace data_transfer
} // namespace module

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef DATA_TRANSFER_OCPP_DATA_TRANSFER_IMPL_HPP
#define DATA_TRANSFER_OCPP_DATA_TRANSFER_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/ocpp_data_transfer/Implementation.hpp>
#include "../OCPPExtensionExample.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace data_transfer {
struct Conf {};
class ocpp_data_transferImpl : public ocpp_data_transferImplBase {
public:
ocpp_data_transferImpl() = delete;
ocpp_data_transferImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<OCPPExtensionExample>& mod,
Conf& config) :
ocpp_data_transferImplBase(ev, "data_transfer"), 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 types::ocpp::DataTransferResponse handle_data_transfer(types::ocpp::DataTransferRequest& request) override;
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<OCPPExtensionExample>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
// 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 data_transfer
} // namespace module
#endif // DATA_TRANSFER_OCPP_DATA_TRANSFER_IMPL_HPP

View File

@@ -0,0 +1,25 @@
description: >-
This is an example module that shows how the OCPP module of EVerest could be extended using the DataTransfer functionality
and custom configuration keys
config:
keys_to_monitor:
description: Commad seperated list of keys that should be monitored
type: string
default: "HeartbeatInterval,SecurityProfile,ExampleConfigurationKey"
provides:
data_transfer:
description: OCPP data transfer
interface: ocpp_data_transfer
requires:
ocpp:
interface: ocpp
min_connections: 1
max_connections: 1
data_transfer:
interface: ocpp_data_transfer
min_connections: 1
max_connections: 1
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Piet Gömpel

View File

@@ -0,0 +1,16 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,74 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "TerminalCostAndPriceMessage.hpp"
namespace module {
void TerminalCostAndPriceMessage::init() {
this->r_session_cost->subscribe_tariff_message([](const types::session_cost::TariffMessage& message) {
for (const types::text_message::MessageContent& message : message.messages) {
EVLOG_info << "Charging price message"
<< (message.language.has_value() ? " (" + message.language.value() + ")" : "") << ": "
<< message.content;
}
});
this->r_session_cost->subscribe_session_cost([](const types::session_cost::SessionCost& session_cost) {
if (!session_cost.cost_chunks.has_value()) {
EVLOG_warning << "No session cost chunks provided in session cost.";
return;
}
uint32_t number_of_decimals = 0;
if (session_cost.currency.decimals.has_value()) {
if (session_cost.currency.decimals.value() < 0) {
EVLOG_warning << "Number of decimals for currency can not be negative.";
} else {
number_of_decimals = static_cast<uint32_t>(session_cost.currency.decimals.value());
}
}
EVLOG_info << "Session cost status for session id " << session_cost.session_id << ": "
<< session_status_to_string(session_cost.status);
for (const types::session_cost::SessionCostChunk& chunk : session_cost.cost_chunks.value()) {
if (chunk.cost.has_value()) {
EVLOG_info << "Session cost until now: "
<< static_cast<double>(chunk.cost.value().value) / (pow(10, number_of_decimals));
}
}
if (session_cost.charging_price.has_value()) {
for (const types::session_cost::ChargingPriceComponent& charging_price :
session_cost.charging_price.value()) {
std::string category;
double price = 0;
if (charging_price.category.has_value()) {
category = cost_category_to_string(charging_price.category.value());
}
if (charging_price.price.has_value()) {
int decimals = 0;
if (charging_price.price.value().currency.decimals.has_value()) {
decimals = charging_price.price.value().currency.decimals.value();
}
price = static_cast<double>(charging_price.price.value().value.value) / pow(10, decimals);
}
EVLOG_info << "Charging price for category " << category << ": " << price << std::endl;
}
}
if (session_cost.message.has_value()) {
for (const types::text_message::MessageContent& message : session_cost.message.value()) {
EVLOG_info << "Charging price message"
<< (message.language.has_value() ? " (" + message.language.value() + ")" : "") << ": "
<< message.content;
}
}
});
}
void TerminalCostAndPriceMessage::ready() {
}
} // namespace module

View File

@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef TERMINAL_COST_AND_PRICE_MESSAGE_HPP
#define TERMINAL_COST_AND_PRICE_MESSAGE_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for required interface implementations
#include <generated/interfaces/session_cost/Interface.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class TerminalCostAndPriceMessage : public Everest::ModuleBase {
public:
TerminalCostAndPriceMessage() = delete;
TerminalCostAndPriceMessage(const ModuleInfo& info, std::unique_ptr<session_costIntf> r_session_cost,
Conf& config) :
ModuleBase(info), r_session_cost(std::move(r_session_cost)), config(config){};
const std::unique_ptr<session_costIntf> r_session_cost;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // TERMINAL_COST_AND_PRICE_MESSAGE_HPP

View File

@@ -0,0 +1,10 @@
description: Example cost and price message module
requires:
session_cost:
interface: session_cost
min_connections: 1
max_connections: 1
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Maaike Zijderveld

View File

@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"display_message/display_messageImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "TerminalDisplayMessage.hpp"
namespace module {
void TerminalDisplayMessage::init() {
invoke_init(*p_display_message);
}
void TerminalDisplayMessage::ready() {
invoke_ready(*p_display_message);
}
} // namespace module

View File

@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef TERMINAL_DISPLAY_MESSAGE_HPP
#define TERMINAL_DISPLAY_MESSAGE_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/display_message/Implementation.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class TerminalDisplayMessage : public Everest::ModuleBase {
public:
TerminalDisplayMessage() = delete;
TerminalDisplayMessage(const ModuleInfo& info, std::unique_ptr<display_messageImplBase> p_display_message,
Conf& config) :
ModuleBase(info), p_display_message(std::move(p_display_message)), config(config){};
const std::unique_ptr<display_messageImplBase> p_display_message;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // TERMINAL_DISPLAY_MESSAGE_HPP

View File

@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "display_messageImpl.hpp"
namespace module {
namespace display_message {
void display_messageImpl::init() {
}
void display_messageImpl::ready() {
}
types::display_message::SetDisplayMessageResponse
display_messageImpl::handle_set_display_message(std::vector<types::display_message::DisplayMessage>& request) {
types::display_message::SetDisplayMessageResponse response;
if (request.empty()) {
response.status = types::display_message::DisplayMessageStatusEnum::Rejected;
response.status_info = "No request sent";
return response;
}
for (const types::display_message::DisplayMessage& message : request) {
EVLOG_info << "New display message"
<< (message.identifier_id.has_value() ? " for identifier id " + message.identifier_id.value() : "")
<< ": " << message.message.content;
}
response.status = types::display_message::DisplayMessageStatusEnum::Accepted;
return response;
}
types::display_message::GetDisplayMessageResponse
display_messageImpl::handle_get_display_messages(types::display_message::GetDisplayMessageRequest& request) {
EVLOG_info << "Get display messages request received"
<< (request.priority.has_value() ? " for display messages with priority " +
std::to_string(static_cast<int>(request.priority.value()))
: "")
<< (request.state.has_value()
? " for display messages with state " + std::to_string(static_cast<int>(request.state.value()))
: "");
if (request.id.has_value()) {
std::string ids;
for (const int32_t& id : request.id.value()) {
ids += std::to_string(id);
ids += " ";
}
EVLOG_info << "Get display messages for specific id's: " << ids;
}
types::display_message::GetDisplayMessageResponse response;
response.messages = std::vector<types::display_message::DisplayMessage>();
types::display_message::DisplayMessage test_message;
test_message.message.content = "This is a test message";
test_message.message.format = types::text_message::MessageFormat::UTF8;
test_message.message.language = "en";
response.messages->push_back(test_message);
types::display_message::DisplayMessage test_message_url;
test_message_url.message.content = "https://pionix.de";
test_message_url.message.format = types::text_message::MessageFormat::URI;
response.messages->push_back(test_message_url);
return response;
}
types::display_message::ClearDisplayMessageResponse
display_messageImpl::handle_clear_display_message(types::display_message::ClearDisplayMessageRequest& request) {
EVLOG_info << "Clear display message request received for id: " << request.id;
types::display_message::ClearDisplayMessageResponse response;
response.status = types::display_message::ClearMessageResponseEnum::Accepted;
response.status_info = "Yes it is done!";
return response;
}
} // namespace display_message
} // namespace module

View File

@@ -0,0 +1,67 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef DISPLAY_MESSAGE_DISPLAY_MESSAGE_IMPL_HPP
#define DISPLAY_MESSAGE_DISPLAY_MESSAGE_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/display_message/Implementation.hpp>
#include "../TerminalDisplayMessage.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace display_message {
struct Conf {};
class display_messageImpl : public display_messageImplBase {
public:
display_messageImpl() = delete;
display_messageImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<TerminalDisplayMessage>& mod,
Conf& config) :
display_messageImplBase(ev, "display_message"), 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 types::display_message::SetDisplayMessageResponse
handle_set_display_message(std::vector<types::display_message::DisplayMessage>& request) override;
virtual types::display_message::GetDisplayMessageResponse
handle_get_display_messages(types::display_message::GetDisplayMessageRequest& request) override;
virtual types::display_message::ClearDisplayMessageResponse
handle_clear_display_message(types::display_message::ClearDisplayMessageRequest& request) override;
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<TerminalDisplayMessage>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
// 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 display_message
} // namespace module
#endif // DISPLAY_MESSAGE_DISPLAY_MESSAGE_IMPL_HPP

View File

@@ -0,0 +1,9 @@
description: Example display message module
provides:
display_message:
description: module to show a message
interface: display_message
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Maaike Zijderveld

View File

@@ -0,0 +1 @@
Collection of examples modules in different programming languages

View File

@@ -0,0 +1 @@
target

View File

@@ -0,0 +1,2 @@
ev_add_module(RsExample)
ev_add_module(RsExampleUser)

View File

@@ -0,0 +1,37 @@
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@everest_crate_index//:defs.bzl", "all_crate_deps")
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
edition="2021",
build_script_env = {
# This is a path to the folder where interfaces and types are placed.
# We are guessing it here since bazel doesn't provide a good way
# to resolve a directoryname of filegroup.
"EVEREST_CORE_ROOT": "../../../../",
},
deps = all_crate_deps(build=True) + [
"//lib/everest/framework/everestrs/everestrs-build",
],
data= [
"//types:types",
"//interfaces:interfaces",
"manifest.yaml",
],
)
rust_binary(
name = "RsExample",
srcs = glob(["src/**/*.rs"]),
visibility = ["//visibility:public"],
edition = "2021",
deps = all_crate_deps() + [
"//lib/everest/framework/everestrs/everestrs",
"//lib/everest/framework/everestrs/everestrs:everestrs_sys",
"//lib/everest/framework/everestrs/everestrs:everestrs_bridge",
":build_script",
],
proc_macro_deps = all_crate_deps(proc_macro=True),
)

View File

@@ -0,0 +1,12 @@
[package]
name = "RsExample"
version = "0.1.0"
edition = "2021"
[dependencies]
everestrs = { workspace = true }
serde = { version = "1.0.200", features = ["derive"] }
serde_json = "1"
[build-dependencies]
everestrs-build = { workspace = true }

View File

@@ -0,0 +1,34 @@
description: Simple example module written in Rust
config:
some_string_config:
description: A module level string config.
type: string
default: Hello world
some_number_config:
description: A module level number config.
type: number
default: 42
provides:
foobar:
interface: example
description: This implements an example interface that uses multiple framework features
config:
some_bool_config:
description: An interface level bool config
type: boolean
default: true
some_integer_config:
description: An interface level integer config.
type: integer
default: 1234
my_store:
interface: kvs
description: This implements the kvs interface, mostly for testing multiple interfaces in one manifest
requires:
their_store:
interface: kvs
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Holger Rapp
enable_external_mqtt: false

View File

@@ -0,0 +1,89 @@
// EVerest expects binaries to be CamelCased, and Rust wants them to be snake_case. We yield to
// EVerest and shut up the compiler warning.
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
use generated::{
Context, ExampleServiceSubscriber, KvsClientSubscriber, KvsServiceSubscriber, Module,
ModulePublisher, OnReadySubscriber,
};
use std::sync::Arc;
use std::{thread, time};
use everestrs::serde_json;
pub struct OneClass {}
impl KvsServiceSubscriber for OneClass {
fn store(
&self,
context: &Context,
key: String,
value: serde_json::Value,
) -> ::everestrs::Result<()> {
context.publisher.their_store.store(key, value)
}
fn load(&self, context: &Context, key: String) -> ::everestrs::Result<serde_json::Value> {
context.publisher.their_store.load(key)
}
fn delete(&self, context: &Context, key: String) -> ::everestrs::Result<()> {
context.publisher.their_store.delete(key)
}
fn exists(&self, context: &Context, key: String) -> ::everestrs::Result<bool> {
context.publisher.their_store.exists(key)
}
}
impl ExampleServiceSubscriber for OneClass {
fn uses_something(&self, context: &Context, key: String) -> ::everestrs::Result<bool> {
if !context.publisher.their_store.exists(key.clone())? {
println!("IT SHOULD NOT AND DOES NOT EXIST");
}
let test_array = vec![1, 2, 3];
context
.publisher
.their_store
.store(key.clone(), test_array.clone().into())?;
let exi = context.publisher.their_store.exists(key.clone())?;
if exi {
println!("IT ACTUALLY EXISTS");
}
let ret: Vec<i32> = serde_json::from_value(context.publisher.their_store.load(key)?)
.expect("Wanted an array as return value");
println!("loaded array: {ret:?}, original array: {test_array:?}");
Ok(exi)
}
}
impl KvsClientSubscriber for OneClass {}
impl OnReadySubscriber for OneClass {
fn on_ready(&self, publishers: &ModulePublisher) {
// Ignore errors here.
let _ = publishers.foobar.max_current(125.);
}
}
#[everestrs::main]
fn main(module: &Module) {
let config = module.get_config();
println!("Received the config {config:?}");
let one_class = Arc::new(OneClass {});
let _publishers = module.start(
one_class.clone(),
one_class.clone(),
one_class.clone(),
one_class.clone(),
);
// Everest is driving execution in the background for us, nothing to do.
loop {
let dt = time::Duration::from_millis(250);
thread::sleep(dt);
}
}

View File

@@ -0,0 +1,34 @@
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@everest_crate_index//:defs.bzl", "all_crate_deps")
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
edition="2021",
build_script_env = {
"EVEREST_CORE_ROOT": "../../../../",
},
deps = all_crate_deps(build=True) + [
"//lib/everest/framework/everestrs/everestrs-build",
],
data= [
"//types:types",
"//interfaces:interfaces",
"manifest.yaml",
],
)
rust_binary(
name = "RsExampleUser",
srcs = glob(["src/**/*.rs"]),
visibility = ["//visibility:public"],
edition = "2021",
deps = all_crate_deps() + [
"//lib/everest/framework/everestrs/everestrs",
"//lib/everest/framework/everestrs/everestrs:everestrs_sys",
"//lib/everest/framework/everestrs/everestrs:everestrs_bridge",
":build_script",
],
proc_macro_deps = all_crate_deps(proc_macro=True),
)

View File

@@ -0,0 +1,12 @@
[package]
name = "RsExampleUser"
version = "0.1.0"
edition = "2021"
[dependencies]
everestrs = { workspace = true }
serde = { version = "1.0.200", features = ["derive"] }
serde_json = "1"
[build-dependencies]
everestrs-build = { workspace = true }

View File

@@ -0,0 +1,15 @@
description: Simple example module written in Rust and using the other example module
provides:
main:
interface: example_user
description: This implements the example_user interface
requires:
their_example:
interface: example
another_example:
interface: example
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Holger Rapp
enable_external_mqtt: false

View File

@@ -0,0 +1,88 @@
// EVerest expects binaries to be CamelCased, and Rust wants them to be snake_case. We yield to
// EVerest and shut up the compiler warning.
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
use std::sync::{Arc, Mutex};
use std::{thread, time};
use generated::{
Context, ExampleClientSubscriber, ExampleUserServiceSubscriber, Module, ModulePublisher,
OnReadySubscriber,
};
struct ExampleClient {
max_current: Mutex<Option<f64>>,
thread: Mutex<Option<thread::JoinHandle<()>>>,
}
impl ExampleClient {
fn new() -> Self {
Self {
max_current: Mutex::new(None),
thread: Mutex::new(None),
}
}
}
impl ExampleClientSubscriber for ExampleClient {
fn on_max_current(&self, context: &Context, value: f64) {
println!("Received the value {value}");
let _ = context
.publisher
.their_example
.uses_something("hello_there".to_string());
*self.max_current.lock().unwrap() = Some(value);
// Example where we start a thread with the publisher. The cloning is
// only done if the user wants to offload the publisher into a thread.
let clone = context.publisher.clone();
*self.thread.lock().unwrap() = Some(thread::spawn(move || {
let _ = clone.another_example.uses_something("foo".to_string());
}))
}
}
struct MainService {}
impl ExampleUserServiceSubscriber for MainService {}
struct OurModule {
their_example: Arc<ExampleClient>,
another_example: Arc<ExampleClient>,
min_current: Mutex<Option<f64>>,
}
impl OnReadySubscriber for OurModule {
fn on_ready(&self, _pub_impl: &ModulePublisher) {
let mut their_current = self.their_example.max_current.lock().unwrap();
let mut another_current = self.another_example.max_current.lock().unwrap();
*their_current = Some(1.);
*another_current = Some(2.);
// uses somehow both...
*self.min_current.lock().unwrap() = Some(1.);
}
}
#[everestrs::main]
fn main(module: &Module) {
let their_example = Arc::new(ExampleClient::new());
let another_example = Arc::new(ExampleClient::new());
let main_service = Arc::new(MainService {});
let our_module = Arc::new(OurModule {
their_example: their_example.clone(),
another_example: another_example.clone(),
min_current: Mutex::new(None),
});
let _publishers = module.start(
our_module.clone(),
main_service.clone(),
their_example.clone(),
another_example.clone(),
);
// Everest is driving execution in the background for us, nothing to do.
loop {
let dt = time::Duration::from_millis(250);
thread::sleep(dt);
}
}

View File

@@ -0,0 +1,5 @@
ev_add_module(ExampleErrorRaiser)
ev_add_module(ExampleErrorSubscriber)
ev_add_module(ExampleErrorGlobalSubscriber)
ev_add_module(PyExampleErrorRaiser)
ev_add_module(PyExampleErrorSubscriber)

View File

@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"example_global_subscriber/example_error_frameworkImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "ExampleErrorGlobalSubscriber.hpp"
namespace module {
void ExampleErrorGlobalSubscriber::init() {
invoke_init(*p_example_global_subscriber);
}
void ExampleErrorGlobalSubscriber::ready() {
invoke_ready(*p_example_global_subscriber);
}
} // namespace module

View File

@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP
#define EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/example_error_framework/Implementation.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class ExampleErrorGlobalSubscriber : public Everest::ModuleBase {
public:
ExampleErrorGlobalSubscriber() = delete;
ExampleErrorGlobalSubscriber(const ModuleInfo& info,
std::unique_ptr<example_error_frameworkImplBase> p_example_global_subscriber,
Conf& config) :
ModuleBase(info), p_example_global_subscriber(std::move(p_example_global_subscriber)), config(config){};
const std::unique_ptr<example_error_frameworkImplBase> p_example_global_subscriber;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // EXAMPLE_ERROR_GLOBAL_SUBSCRIBER_HPP

View File

@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "example_error_frameworkImpl.hpp"
namespace module {
namespace example_global_subscriber {
void example_error_frameworkImpl::init() {
Everest::error::ErrorCallback error_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error: " << error.type;
this->test_state_monitor();
};
Everest::error::ErrorCallback error_cleared_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error cleared: " << error.type;
this->test_state_monitor();
};
subscribe_global_all_errors(error_callback, error_cleared_callback);
}
void example_error_frameworkImpl::test_state_monitor() {
EVLOG_info << "Currently there are " << get_global_error_state_monitor()->get_active_errors().size()
<< " errors active.";
}
void example_error_frameworkImpl::ready() {
}
} // namespace example_global_subscriber
} // namespace module

View File

@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_GLOBAL_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
#define EXAMPLE_GLOBAL_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/example_error_framework/Implementation.hpp>
#include "../ExampleErrorGlobalSubscriber.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace example_global_subscriber {
struct Conf {};
class example_error_frameworkImpl : public example_error_frameworkImplBase {
public:
example_error_frameworkImpl() = delete;
example_error_frameworkImpl(Everest::ModuleAdapter* ev,
const Everest::PtrContainer<ExampleErrorGlobalSubscriber>& mod, Conf& config) :
example_error_frameworkImplBase(ev, "example_global_subscriber"), mod(mod), config(config){};
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
protected:
// no commands defined for this interface
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<ExampleErrorGlobalSubscriber>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
void test_state_monitor();
// 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 example_global_subscriber
} // namespace module
#endif // EXAMPLE_GLOBAL_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP

View File

@@ -0,0 +1,10 @@
description: Simple example module written in C++ to demonstrate error framework on global subscriber side
provides:
example_global_subscriber:
interface: example_error_framework
description: This implements the example interface
enable_global_errors: true
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Andreas Heinrich

View File

@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"example_raiser/example_error_frameworkImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "ExampleErrorRaiser.hpp"
namespace module {
void ExampleErrorRaiser::init() {
invoke_init(*p_example_raiser);
}
void ExampleErrorRaiser::ready() {
invoke_ready(*p_example_raiser);
}
} // namespace module

View File

@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_ERROR_RAISER_HPP
#define EXAMPLE_ERROR_RAISER_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/example_error_framework/Implementation.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class ExampleErrorRaiser : public Everest::ModuleBase {
public:
ExampleErrorRaiser() = delete;
ExampleErrorRaiser(const ModuleInfo& info, std::unique_ptr<example_error_frameworkImplBase> p_example_raiser,
Conf& config) :
ModuleBase(info), p_example_raiser(std::move(p_example_raiser)), config(config){};
const std::unique_ptr<example_error_frameworkImplBase> p_example_raiser;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // EXAMPLE_ERROR_RAISER_HPP

View File

@@ -0,0 +1,94 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "example_error_frameworkImpl.hpp"
#include <utils/error/error_factory.hpp>
#include <utils/error/error_state_monitor.hpp>
#include <vector>
using Error = Everest::error::Error;
using Condition = Everest::error::ErrorStateMonitor::StateCondition;
namespace module {
namespace example_raiser {
std::list<Condition> condition_0 = {Condition("example/ExampleErrorA", "some custom sub_type", true),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::list<Condition> condition_1 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", true),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::list<Condition> condition_2 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", true),
Condition("example/ExampleErrorD", "some custom sub_type", true)};
std::list<Condition> condition_3 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::vector<std::list<Condition>> conditions = {condition_0, condition_1, condition_2, condition_3};
void example_error_frameworkImpl::check_conditions() {
for (std::vector<std::list<Condition>>::size_type i = 0; i < conditions.size(); i++) {
if (this->error_state_monitor->is_condition_satisfied(conditions.at(i))) {
EVLOG_info << "Condition " << i << " satisfied";
} else {
EVLOG_info << "Condition " << i << " not satisfied";
}
}
}
void example_error_frameworkImpl::init() {
}
void example_error_frameworkImpl::ready() {
Error error_a = this->error_factory->create_error("example/ExampleErrorA", "some custom sub_type",
"This error is raised to test the error handling");
raise_error(error_a);
check_conditions();
std::this_thread::sleep_for(std::chrono::seconds(1));
clear_error("example/ExampleErrorA", "some custom sub_type");
std::this_thread::sleep_for(std::chrono::seconds(2));
Error error_b = this->error_factory->create_error("example/ExampleErrorB", "some custom sub_type",
"This error is raised to test the error handling",
Everest::error::Severity::High);
std::this_thread::sleep_for(std::chrono::seconds(1));
raise_error(error_b);
check_conditions();
std::this_thread::sleep_for(std::chrono::seconds(1));
clear_error("example/ExampleErrorB", "some custom sub_type");
std::this_thread::sleep_for(std::chrono::seconds(2));
Error error_c = this->error_factory->create_error("example/ExampleErrorC", "some custom sub_type",
"This error is raised to test the error handling",
Everest::error::Severity::Medium);
raise_error(error_c);
check_conditions();
std::this_thread::sleep_for(std::chrono::seconds(1));
Error error_d = this->error_factory->create_error("example/ExampleErrorD", "some custom sub_type",
"This error is raised to test the error handling",
Everest::error::Severity::Medium);
raise_error(error_d);
check_conditions();
std::this_thread::sleep_for(std::chrono::seconds(2));
clear_all_errors_of_impl();
check_conditions();
std::this_thread::sleep_for(std::chrono::seconds(2));
}
} // namespace example_raiser
} // namespace module

View File

@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_RAISER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
#define EXAMPLE_RAISER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/example_error_framework/Implementation.hpp>
#include "../ExampleErrorRaiser.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace example_raiser {
struct Conf {};
class example_error_frameworkImpl : public example_error_frameworkImplBase {
public:
example_error_frameworkImpl() = delete;
example_error_frameworkImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<ExampleErrorRaiser>& mod,
Conf& config) :
example_error_frameworkImplBase(ev, "example_raiser"), mod(mod), config(config){};
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
protected:
// no commands defined for this interface
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<ExampleErrorRaiser>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
void check_conditions();
// 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 example_raiser
} // namespace module
#endif // EXAMPLE_RAISER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP

View File

@@ -0,0 +1,9 @@
description: Simple example module written in C++ to demonstrate error handling on raiser side
provides:
example_raiser:
interface: example_error_framework
description: This implements an example interface
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Andreas Heinrich

View File

@@ -0,0 +1,21 @@
#
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT
# template version 3
#
# module setup:
# - ${MODULE_NAME}: module name
ev_setup_cpp_module()
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
# insert your custom targets and additional config variables here
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1
target_sources(${MODULE_NAME}
PRIVATE
"example_subscriber/example_error_frameworkImpl.cpp"
)
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "ExampleErrorSubscriber.hpp"
namespace module {
void ExampleErrorSubscriber::init() {
invoke_init(*p_example_subscriber);
}
void ExampleErrorSubscriber::ready() {
invoke_ready(*p_example_subscriber);
}
} // namespace module

View File

@@ -0,0 +1,67 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_ERROR_SUBSCRIBER_HPP
#define EXAMPLE_ERROR_SUBSCRIBER_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 2
//
#include "ld-ev.hpp"
// headers for provided interface implementations
#include <generated/interfaces/example_error_framework/Implementation.hpp>
// headers for required interface implementations
#include <generated/interfaces/example_error_framework/Interface.hpp>
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
namespace module {
struct Conf {};
class ExampleErrorSubscriber : public Everest::ModuleBase {
public:
ExampleErrorSubscriber() = delete;
ExampleErrorSubscriber(const ModuleInfo& info,
std::unique_ptr<example_error_frameworkImplBase> p_example_subscriber,
std::unique_ptr<example_error_frameworkIntf> r_example_raiser, Conf& config) :
ModuleBase(info),
p_example_subscriber(std::move(p_example_subscriber)),
r_example_raiser(std::move(r_example_raiser)),
config(config){};
const std::unique_ptr<example_error_frameworkImplBase> p_example_subscriber;
const std::unique_ptr<example_error_frameworkIntf> r_example_raiser;
const Conf& config;
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
// insert your public definitions here
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
protected:
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
// insert your protected definitions here
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1
private:
friend class LdEverest;
void init();
void ready();
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
// insert your private definitions here
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
// insert other definitions here
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1
} // namespace module
#endif // EXAMPLE_ERROR_SUBSCRIBER_HPP

View File

@@ -0,0 +1,66 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include "example_error_frameworkImpl.hpp"
#include <utils/error/error_factory.hpp>
#include <utils/error/error_state_monitor.hpp>
#include <vector>
using Condition = Everest::error::ErrorStateMonitor::StateCondition;
namespace module {
namespace example_subscriber {
std::list<Condition> condition_0 = {Condition("example/ExampleErrorA", "some custom sub_type", true),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::list<Condition> condition_1 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", true),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::list<Condition> condition_2 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", true),
Condition("example/ExampleErrorD", "some custom sub_type", true)};
std::list<Condition> condition_3 = {Condition("example/ExampleErrorA", "some custom sub_type", false),
Condition("example/ExampleErrorB", "some custom sub_type", false),
Condition("example/ExampleErrorC", "some custom sub_type", false),
Condition("example/ExampleErrorD", "some custom sub_type", false)};
std::vector<std::list<Condition>> conditions = {condition_0, condition_1, condition_2, condition_3};
void example_error_frameworkImpl::check_conditions() {
for (std::vector<std::list<Condition>>::size_type i = 0; i < conditions.size(); i++) {
if (this->mod->r_example_raiser->error_state_monitor->is_condition_satisfied(conditions.at(i))) {
EVLOG_info << "Condition " << i << " satisfied";
} else {
EVLOG_info << "Condition " << i << " not satisfied";
}
}
}
void example_error_frameworkImpl::init() {
Everest::error::ErrorCallback error_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error: " << error.type;
check_conditions();
};
Everest::error::ErrorCallback error_cleared_callback = [this](const Everest::error::Error& error) {
EVLOG_info << "received error cleared: " << error.type;
check_conditions();
};
mod->r_example_raiser->subscribe_error("example/ExampleErrorA", error_callback, error_cleared_callback);
mod->r_example_raiser->subscribe_all_errors(error_callback, error_cleared_callback);
}
void example_error_frameworkImpl::ready() {
check_conditions();
}
} // namespace example_subscriber
} // namespace module

View File

@@ -0,0 +1,61 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
#define EXAMPLE_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP
//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//
#include <generated/interfaces/example_error_framework/Implementation.hpp>
#include "../ExampleErrorSubscriber.hpp"
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
// insert your custom include headers here
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1
namespace module {
namespace example_subscriber {
struct Conf {};
class example_error_frameworkImpl : public example_error_frameworkImplBase {
public:
example_error_frameworkImpl() = delete;
example_error_frameworkImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<ExampleErrorSubscriber>& mod,
Conf& config) :
example_error_frameworkImplBase(ev, "example_subscriber"), mod(mod), config(config){};
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
protected:
// no commands defined for this interface
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
// insert your protected definitions here
// ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1
private:
const Everest::PtrContainer<ExampleErrorSubscriber>& mod;
const Conf& config;
virtual void init() override;
virtual void ready() override;
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
void check_conditions();
// 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 example_subscriber
} // namespace module
#endif // EXAMPLE_SUBSCRIBER_EXAMPLE_ERROR_FRAMEWORK_IMPL_HPP

View File

@@ -0,0 +1,12 @@
description: Simple example module written in C++ to demonstrate error framework on subscriber side
provides:
example_subscriber:
interface: example_error_framework
description: This implements the example interface
requires:
example_raiser:
interface: example_error_framework
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Andreas Heinrich

View File

@@ -0,0 +1,9 @@
description: Simple example module written in Python to demonstrate error handling on raiser side
provides:
example_raiser:
interface: example_error_framework
description: This implements an example interface
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Andreas Heinrich

View File

@@ -0,0 +1,108 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Pionix GmbH and Contributors to EVerest
from everest.framework import Module, RuntimeSession, log, error
import time, threading
condition_lists = [
{
"name": "Only A is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
},
{
"name": "Only B is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
},
{
"name": "Only C & D are active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", True),
],
},
{
"name": "No error is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
}
]
class PyExampleErrorRaiserModule():
def __init__(self) -> None:
self._session = RuntimeSession()
m = Module(self._session)
log.update_process_name(m.info.id)
self._ready_event = threading.Event()
self._setup = m.say_hello()
self._mod = m
self._mod.init_done(self._ready)
def _ready(self):
log.debug("ready!")
self._ready_event.set()
def check_conditions(self):
monitor = self._mod.get_error_state_monitor_impl("example_raiser")
for entry in condition_lists:
if monitor.is_condition_satisfied(entry["conditions"]):
log.info(f"Condition '{entry['name']}' is satisfied")
else:
log.info(f"Condition '{entry['name']}' is not satisfied")
def start_example(self):
while True:
self._ready_event.wait()
try:
error_factory = self._mod.get_error_factory("example_raiser")
error = error_factory.create_error("example/ExampleErrorA", "example sub type", "example error message")
self._mod.raise_error("example_raiser", error)
self.check_conditions()
time.sleep(1)
self._mod.clear_error("example_raiser", "example/ExampleErrorA", "example sub type")
self.check_conditions()
time.sleep(1)
error = error_factory.create_error("example/ExampleErrorB", "example sub type", "example error message")
self._mod.raise_error("example_raiser", error)
self.check_conditions()
time.sleep(1)
self._mod.clear_error("example_raiser", "example/ExampleErrorB", "example sub type")
self.check_conditions()
time.sleep(1)
error = error_factory.create_error("example/ExampleErrorC", "example sub type", "example error message")
self._mod.raise_error("example_raiser", error)
self.check_conditions()
time.sleep(1)
error = error_factory.create_error("example/ExampleErrorD", "example sub type", "example error message")
self._mod.raise_error("example_raiser", error)
self.check_conditions()
time.sleep(1)
self._mod.clear_all_errors_of_impl("example_raiser")
self.check_conditions()
time.sleep(1)
except KeyboardInterrupt:
log.debug("Example program terminated manually")
break
self._ready_event.clear()
py_example_error_raiser = PyExampleErrorRaiserModule()
py_example_error_raiser.start_example()

View File

@@ -0,0 +1,12 @@
description: Simple example module written in Python to demonstrate error framework on subscriber side
provides:
example_subscriber:
interface: example_error_framework
description: This implements the example interface
requires:
example_raiser:
interface: example_error_framework
metadata:
license: https://opensource.org/licenses/Apache-2.0
authors:
- Andreas Heinrich

View File

@@ -0,0 +1,107 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Pionix GmbH and Contributors to EVerest
from everest.framework import Module, RuntimeSession, log, error
import threading
condition_lists = [
{
"name": "Only A is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
},
{
"name": "Only B is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
},
{
"name": "Only C & D are active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", True),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", True),
],
},
{
"name": "No error is active",
"conditions": [
error.ErrorStateCondition("example/ExampleErrorA", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorB", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorC", "example sub type", False),
error.ErrorStateCondition("example/ExampleErrorD", "example sub type", False),
],
}
]
class PyExampleErrorSubscriberModule():
def __init__(self) -> None:
self._session = RuntimeSession()
m = Module(self._session)
log.update_process_name(m.info.id)
self._setup = m.say_hello()
self._ready_event = threading.Event()
self._req_example_raiser = self._setup.connections['example_raiser'][0]
m.subscribe_error(
self._req_example_raiser,
'example/ExampleErrorA',
self.handle_error,
self.handle_error_cleared
)
m.subscribe_all_errors(
self._req_example_raiser,
self.handle_error,
self.handle_error_cleared
)
self._mod = m
self._mod.init_done(self._ready)
def handle_error(self, error):
log.info("Received error: '" + error.type + "' '" + error.sub_type + "' '" + error.message + "'")
self.check_conditions()
def handle_error_cleared(self, error):
log.info("Received error cleared: '" + error.type + "' '" + error.sub_type + "' '" + error.message + "'")
self.check_conditions()
def _ready(self):
self._ready_event.set()
log.debug("ready!")
def start_example(self):
while True:
self._ready_event.wait()
try:
log.info("Example program started")
except KeyboardInterrupt:
log.debug("Example program terminated manually")
break
self._ready_event.clear()
def check_conditions(self):
monitor = self._mod.get_error_state_monitor_req(self._req_example_raiser)
for entry in condition_lists:
if monitor.is_condition_satisfied(entry["conditions"]):
log.info(f"Condition '{entry['name']}' is satisfied")
else:
log.info(f"Condition '{entry['name']}' is not satisfied")
log.info("")
log.info("")
py_example_error_subscriber = PyExampleErrorSubscriberModule()
py_example_error_subscriber.start_example()