update examples (#9)

This commit is contained in:
tompzf
2026-04-07 09:11:36 +02:00
committed by GitHub
parent 07cf4f654b
commit 511c1dda51
16 changed files with 112 additions and 116 deletions

View File

@@ -5,6 +5,8 @@ Version = 100
Path = "module_example.sdv"
Class = "class_example"
Name = "object_name_example"
[Component.Parameters]
updatableValue = 13
Message = "It's me"
Id = 42
Pi = 3.1415926

View File

@@ -2,25 +2,28 @@
#include <support/component_impl.h>
#include <support/toml.h>
class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectControl
class DemoConfigurationComponent : public sdv::CSdvObject
{
public:
BEGIN_SDV_INTERFACE_MAP()
END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("Configuration_Example")
// Parameter map
BEGIN_SDV_PARAM_MAP()
SDV_PARAM_ENABLE_LOCKING() // optional, if the parameter should be updatable
SDV_PARAM_ENTRY(m_InitializedValue, "initializedValue", 7, "km/h", "Description for an initialized parameter.")
SDV_PARAM_ENTRY(m_UpdatableValue, "updatableValue", 7, "m/s", "Description for an updatable parameter.")
END_SDV_PARAM_MAP()
/**
* @brief initialize function to register, access the task timer interface from platform abstraction.
* After initialization 'CreateTimer' function is called to execute the task periodically.
* @param[in] rssObjectConfig An object configuration is currently not used by this demo component.
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
*/
virtual void Initialize([[maybe_unused]] const sdv::u8string& rssObjectConfig) override
virtual bool OnInitialize() override
{
try
{
sdv::toml::CTOMLParser config(rssObjectConfig.c_str());
sdv::toml::CTOMLParser config(GetObjectConfig());
sdv::toml::CNode messageNode = config.GetDirect("Message");
if (messageNode.GetType() == sdv::toml::ENodeType::node_string)
@@ -28,6 +31,12 @@ class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectCo
m_Message = static_cast<std::string>(messageNode.GetValue());
}
sdv::toml::CNode jsonNode = config.GetDirect("JSONConfig");
if (jsonNode.GetType() == sdv::toml::ENodeType::node_string)
{
m_JSONConfig = static_cast<std::string>(jsonNode.GetValue());
}
sdv::toml::CNode idNode = config.GetDirect("Id");
if (idNode.GetType() == sdv::toml::ENodeType::node_integer)
{
@@ -76,73 +85,43 @@ class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectCo
m_DirectTableA = static_cast<uint32_t>(table_a.GetValue());
m_DirectTableB = static_cast<float>(table_b.GetValue());
m_DirectTableC = static_cast<std::string>(table_c.GetValue());
}
catch (const sdv::toml::XTOMLParseException& e)
{
SDV_LOG_ERROR("Parsing error: ", e.what());
m_status = sdv::EObjectStatus::initialization_failure;
return;
return false;
}
PrintAllVariables();
m_status = sdv::EObjectStatus::initialized;
return true;
};
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual sdv::EObjectStatus GetStatus() const override
{
return m_status;
};
/**
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(/*in*/ sdv::EOperationMode eMode)
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_status == sdv::EObjectStatus::running || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::configuring;
break;
case sdv::EOperationMode::running:
if (m_status == sdv::EObjectStatus::configuring || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::running;
break;
default:
break;
}
}
/**
* @brief Shutdown function is to shutdown the execution of periodic task.
* Timer ID of the task is used to shutdown the specific task.
*/
virtual void Shutdown() override
{
m_status = sdv::EObjectStatus::destruction_pending;
}
virtual void OnShutdown() override
{}
/**
* @brief Print all global variables to console
*/
void PrintAllVariables()
void PrintAllVariables() const
{
std::cout << "\nValues parsed during initialization:\n" << std::endl;
std::cout << "string: " << m_Message.c_str() << std::endl;
std::cout << "integer: " << std::to_string(m_Id) << std::endl;
std::cout << "float: " << std::to_string(m_Pi) << std::endl;
std::cout << "bool: " << std::to_string(m_IsValid) << std::endl;
std::cout << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
std::cout << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
std::cout << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
std::cout << "array: ";
std::cout << "\n----------\nValues from the parameter map:" << std::endl;
std::cout << "Expected 7, got " << "initialized value - not changed, not in configuration file: " << std::to_string(m_InitializedValue) << std::endl;
std::cout << "Expected 13, got " << "updated value - changed, found in configuration file: " << std::to_string(m_UpdatableValue) << std::endl;
std::cout << "\n----------\nValues parsed during initialization:" << std::endl;
std::cout << "Expected 'It's me', got " << "string: " << m_Message.c_str() << std::endl;
std::cout << "multiline string: " << m_JSONConfig.c_str() << std::endl;
std::cout << "Expected 42, got " << "integer: " << std::to_string(m_Id) << std::endl;
std::cout << "Expected 3.141593, got " << "float: " << std::to_string(m_Pi) << std::endl;
std::cout << "Expected 1, got " << "bool: " << std::to_string(m_IsValid) << std::endl;
std::cout << "Expected 77, got " << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
std::cout << "Expected 1.200000, got " << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
std::cout << "Expected 'this is a string', got " << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
for (auto counter : m_Counters)
{
std::cout << std::to_string(counter) << ", ";
@@ -151,19 +130,20 @@ class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectCo
}
private:
std::atomic<sdv::EObjectStatus> m_status = {sdv::EObjectStatus::initialization_pending}; //!< To update the object status when it changes.
std::string m_Message = "";
int32_t m_Id = -1;
float m_Pi = 0.0;
bool m_IsValid = false;
std::vector<uint32_t> m_Counters;
uint32_t m_TableA = 0;
float m_TableB = 0.0;
std::string m_TableC = "";
uint32_t m_DirectTableA = 0;
float m_DirectTableB = 0.0;
std::string m_DirectTableC = "";
std::string m_Message { "" };
std::string m_JSONConfig { "" };
int32_t m_Id { -1 };
float m_Pi { 0.0 };
bool m_IsValid { false };
std::vector<uint32_t> m_Counters{};
uint32_t m_TableA { 0 };
float m_TableB { 0.0 };
std::string m_TableC { "" };
uint32_t m_DirectTableA { 0 };
float m_DirectTableB { 0.0 };
std::string m_DirectTableC { "" };
uint32_t m_InitializedValue { 0 };
uint32_t m_UpdatableValue { 0 };
};
DEFINE_SDV_OBJECT(DemoConfigurationComponent)

View File

@@ -18,6 +18,13 @@ public:
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("Configuration_Example")
// Parameter map
BEGIN_SDV_PARAM_MAP()
SDV_PARAM_ENABLE_LOCKING() // Parameters will be protected against writing when locked (e.g. after initialization).
SDV_PARAM_ENTRY(m_InitializedValue, "initializedValue", 7, "km/h", "Description for an initialized parameter.")
SDV_PARAM_ENTRY(m_UpdatableValue, "updatableValue", 7, "m/s", "Description for an updatable parameter.")
END_SDV_PARAM_MAP()
/**
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
@@ -113,16 +120,19 @@ public:
*/
void PrintAllVariables() const
{
std::cout << "\nValues parsed during initialization:" << std::endl;
std::cout << "string: " << m_Message.c_str() << std::endl;
std::cout << "\n----------\nValues from the parameter map:" << std::endl;
std::cout << "Expect 7, got " << "initialized value - not changed because not in configuration file: " << std::to_string(m_InitializedValue) << std::endl;
std::cout << "Expect 13, got " << "updated value - changed, found in configuration file: " << std::to_string(m_UpdatableValue) << std::endl;
std::cout << "\n----------\nValues parsed in OnInitialize():" << std::endl;
std::cout << "Expect 'It's me', got " << "string: " << m_Message.c_str() << std::endl;
std::cout << "multiline string: " << m_JSONConfig.c_str() << std::endl;
std::cout << "integer: " << std::to_string(m_Id) << std::endl;
std::cout << "float: " << std::to_string(m_Pi) << std::endl;
std::cout << "bool: " << std::to_string(m_IsValid) << std::endl;
std::cout << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
std::cout << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
std::cout << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
std::cout << "array: ";
std::cout << "Expect 42, got " << "integer: " << std::to_string(m_Id) << std::endl;
std::cout << "Expect 3.141593, got " << "float: " << std::to_string(m_Pi) << std::endl;
std::cout << "Expect 1, got " << "bool: " << std::to_string(m_IsValid) << std::endl;
std::cout << "Expect 77, got " << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
std::cout << "Expect 1.200000, got " << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
std::cout << "Expect 'this is a string', got " << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
std::cout << "Expect 1, 2, 3, 5, 7, 11, 13, 17,\n got ";
for (auto counter : m_Counters)
{
std::cout << std::to_string(counter) << ", ";
@@ -143,6 +153,8 @@ public:
uint32_t m_DirectTableA { 0 };
float m_DirectTableB { 0.0 };
std::string m_DirectTableC { "" };
uint32_t m_InitializedValue { 0 };
uint32_t m_UpdatableValue { 0 };
};
DEFINE_SDV_OBJECT(DemoConfigurationComponent)

View File

@@ -5,6 +5,7 @@ Version = 100
Path = "configuration_component_example.sdv"
Class = "Configuration_Example"
[Component.Parameters]
updatableValue = 13
Message = "It's me"
### the following is a valid JSON structure in a muliline string
JSONConfig = """{

View File

@@ -57,11 +57,11 @@ extern "C" int main()
//run for 10 seconds - in that time task timer callbacks in the module get triggered
uint32_t counter = 10;
std::chrono::seconds sleepDurtaion (1);
std::chrono::seconds sleepDuration (1);
while (counter-- > 0)
{
std::cout << "counter: " << std::to_string(counter) << std::endl;
std::this_thread::sleep_for(sleepDurtaion);
std::this_thread::sleep_for(sleepDuration);
}
appcontrol.Shutdown();

View File

@@ -125,14 +125,14 @@ bool CConsole::PrepareDataConsumers()
auto deviceServiceSpeed = sdv::core::GetObject("Vehicle.Speed_Device").GetInterface<vss::Vehicle::SpeedDevice::IVSS_ReadSpeed>();
if (deviceServiceSpeed)
{
PrintValue(g_sDeviceServiceSpeed, "Vehicle Speed RX", m_PlatformSpeed, "km/h [ Output of Platform Abstraction, not accessible by application ] ");
PrintValue(g_sDeviceServiceSpeed, "Vehicle Speed RX", m_SpeedPlatform, "km/h [ Output of Platform Abstraction, not accessible by application ] ");
deviceServiceSpeed->RegisterSpeedEvent(dynamic_cast<vss::Vehicle::SpeedDevice::IVSS_WriteSpeed_Event*> (this));
}
auto basicServiceSpeed = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
if (basicServiceSpeed)
{
PrintValue(g_sBasicServiceSpeed, "Vehicle Speed RX", m_BasicSpeed, "km/h [ Output of Speed Sensor Service, accessible by application ] ");
PrintValue(g_sBasicServiceSpeed, "Vehicle Speed RX", m_SpeedbasicService, "km/h [ Output of Speed Sensor Service, accessible by application ] ");
basicServiceSpeed->RegisterOnSignalChangeOfVehicleSpeed(dynamic_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
}
@@ -141,19 +141,19 @@ bool CConsole::PrepareDataConsumers()
void CConsole::WriteSpeed( float value)
{
if (m_PlatformSpeed != value)
if (m_SpeedPlatform != value)
{
m_PlatformSpeed = value;
PrintValue(g_sDeviceServiceSpeed, "Vehicle Speed RX", m_PlatformSpeed, "km/h [ Output of Platform Abstraction, not accessible by application ] ");
m_SpeedPlatform = value;
PrintValue(g_sDeviceServiceSpeed, "Vehicle Speed RX", m_SpeedPlatform, "km/h [ Output of Platform Abstraction, not accessible by application ] ");
}
}
void CConsole::SetSpeed( float value)
{
if (m_BasicSpeed != value)
if (m_SpeedbasicService != value)
{
m_BasicSpeed= value;
PrintValue(g_sBasicServiceSpeed, "Vehicle Speed RX", m_BasicSpeed, "km/h [ Output of Speed Sensor Service, accessible by application ] ");
m_SpeedbasicService = value;
PrintValue(g_sBasicServiceSpeed, "Vehicle Speed RX", m_SpeedbasicService, "km/h [ Output of Speed Sensor Service, accessible by application ] ");
}
}

View File

@@ -162,8 +162,8 @@ private:
sdv::core::CSignal m_SignalSpeed; ///< Signal to subscribe to the speed signal in dispatch service
float m_SpeedDataLink = 0.0; ///< Data Link value, either km/h or m/s
float m_PlatformSpeed = 0.0; ///< Generalized Speed
float m_BasicSpeed = 0.0; ///< Generalized Speed
float m_SpeedPlatform = 0.0; ///< Generalized Speed after platform abstraction
float m_SpeedbasicService = 0.0; ///< Generalized Speed can be used by vehicle function components
#ifdef _WIN32
DWORD m_dwConsoleOutMode = 0u; ///< The console mode before switching on ANSI support.

View File

@@ -43,12 +43,12 @@ bool CAbstractionControl::IsSDVFrameworkEnvironmentSet()
return false;
}
bool CAbstractionControl::Initialize(bool bSimulate)
bool CAbstractionControl::Initialize(bool bInputDataInKmh)
{
if (m_bInitialized)
return true;
m_bSimulate = bSimulate;
m_bInputDataInKmh = bInputDataInKmh;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
@@ -62,7 +62,7 @@ bool CAbstractionControl::Initialize(bool bSimulate)
bool bResult = LoadConfigFile("Load dispatch service: ", "data_dispatch_vehicle_abstraction.toml");
bResult &= LoadConfigFile("Load task_timer_vehicle: ", "task_timer_vehicle.toml");
if (bSimulate)
if (m_bInputDataInKmh)
{
bResult &= LoadConfigFile("Load can_com_simulation_vehicle_abstraction_kmh: ", "can_com_simulation_vehicle_abstraction_kmh.toml");
bResult &= LoadConfigFile("Load data_link_vehicle_abstraction: ", "data_link_vehicle_abstraction.toml");

View File

@@ -22,10 +22,10 @@ public:
/**
* @brief Start and initialize the application control and load
* platform abstraction components and basic services
* @param[in] bSimulate If signals should be simulated or CAN input signals should be used
* @param[in] bInputDataInKmh If input speed data is in km/h
* @return Return true on success otherwise false
*/
bool Initialize(bool bSimulate);
bool Initialize(bool bInputDataInKmh);
/**
* @brief After initialization/configuration the system mode needs to be set to running mode
@@ -56,5 +56,5 @@ private:
sdv::app::CAppControl m_appcontrol; ///< App-control of SDV V-API.
bool m_bInitialized = false; ///< Set when initialized.
bool m_bSimulate = false;
bool m_bInputDataInKmh = false; ///< true if the input data is in km/h
};

View File

@@ -81,7 +81,7 @@ module sdv
external = 20, ///< External application. Component isolation in client mode.
isolated = 30, ///< Isolated application. Component isolation in client mode.
main = 100, ///< Main application. Component isolation in server mode.
essential = 5, ///< Bare minunum configuration. Local services loaded only. Additional configurations can be
essential = 5, ///< Bare minimum configuration. Local services loaded only. Additional configurations can be
///< loaded.
maintenance = 80, ///< Maintenance application. Component isolation in client mode. Access to maintenance interfaces
///< only.

View File

@@ -95,7 +95,7 @@ module sdv
};
/**
* @brief Interface to send CAN messagee.
* @brief Interface to send CAN message.
*/
local interface ISend
{

View File

@@ -320,7 +320,7 @@ module sdv
exception XFailedToCompose : XSysExcept
{
/** Description */
const char _description[] = "Faled to compose an installation package.";
const char _description[] = "Failed to compose an installation package.";
u8string ssInstallName; ///< Name of the installation to compose.
};

View File

@@ -64,7 +64,7 @@ module sdv
* @post Use AsyncConnect to initiate the connection.
* @param[in] ssConnectString Reference to the string containing the channel connection parameters returned by the
* ICreateEndpoint::CreateEndpoint function or a TOML configuration that is provider specific and describes clearly the
* access to a running channel. This configuriration is identical (or similar) to the configuration supplied to the
* access to a running channel. This configuration is identical (or similar) to the configuration supplied to the
* ICreateEndpoint::CreateEndpoint function.
* @return Pointer to IInterfaceAccess interface of the connection object or NULL when the object cannot be created.
*/
@@ -138,7 +138,7 @@ module sdv
void UnregisterStateEventCallback(in uint64 uiCookie);
/**
* @brief Get the current state of the IPC conection.
* @brief Get the current state of the IPC connection.
* @return Returns connection state.
*/
EConnectState GetConnectState() const;

View File

@@ -65,7 +65,7 @@ module sdv
/**
* @brief Wait for a process to finalize.
* @param[in] tProcessID The process ID to wait for.
* @param[in] uiWaitMs Maximum time to wait in ms. Could be 0xffffffff to wait indefintely.
* @param[in] uiWaitMs Maximum time to wait in ms. Could be 0xffffffff to wait indefinitely.
* @return Returns 'true' when the process was terminated (or isn't running), 'false' when still running and a timeout
* has occurred.
*/

View File

@@ -150,7 +150,7 @@ public:
virtual void UnregisterStateEventCallback(/*in*/ uint64_t uiCookie) override;
/**
* @brief Get the current state of the IPC conection. Overload of sdv::ipc::IConnect::GetConnectState.
* @brief Get the current state of the IPC connection. Overload of sdv::ipc::IConnect::GetConnectState.
* @return Returns connection state.
*/
virtual sdv::ipc::EConnectState GetConnectState() const override;

View File

@@ -252,6 +252,7 @@ Class = "DataDispatchService"
[[Component]]
Path = "can_com_silkit.sdv"
Class = "CAN_Com_SilKit"
[Component.Parameters]
DebugInfo = true
SyncMode = true
CanSilKitChannel = "CAN1"