diff --git a/examples/rust/mini-adas/BUILD.bazel b/examples/rust/mini-adas/BUILD.bazel index dbd911a..12254ed 100644 --- a/examples/rust/mini-adas/BUILD.bazel +++ b/examples/rust/mini-adas/BUILD.bazel @@ -97,7 +97,7 @@ rust_binary( ], data = [ "etc/logging.json", - "etc/mw_com_config.json", + "etc/mw_com_config_100.json", ], env = { "MW_LOG_CONFIG_FILE": "examples/rust/mini-adas/etc/logging.json", @@ -149,7 +149,8 @@ rust_binary( ], data = [ "etc/logging.json", - "etc/mw_com_config.json", + "etc/mw_com_config_101.json", + "etc/mw_com_config_102.json", ], env = { "MW_LOG_CONFIG_FILE": "examples/rust/mini-adas/etc/logging.json", diff --git a/examples/rust/mini-adas/etc/mw_com_config.json b/examples/rust/mini-adas/etc/mw_com_config_100.json similarity index 99% rename from examples/rust/mini-adas/etc/mw_com_config.json rename to examples/rust/mini-adas/etc/mw_com_config_100.json index b521e9a..6906f60 100644 --- a/examples/rust/mini-adas/etc/mw_com_config.json +++ b/examples/rust/mini-adas/etc/mw_com_config_100.json @@ -1,4 +1,7 @@ { + "global": { + "applicationID": 4000 + }, "serviceTypes": [ { "serviceTypeName": "/feo/com/CameraInterface", diff --git a/examples/rust/mini-adas/etc/mw_com_config_101.json b/examples/rust/mini-adas/etc/mw_com_config_101.json new file mode 100644 index 0000000..eaf6c1c --- /dev/null +++ b/examples/rust/mini-adas/etc/mw_com_config_101.json @@ -0,0 +1,264 @@ +{ + "global": { + "applicationID": 4001 + }, + "serviceTypes": [ + { + "serviceTypeName": "/feo/com/CameraInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6432, + "events": [ + { + "eventName": "image", + "eventId": 1 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/RadarInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6433, + "events": [ + { + "eventName": "scan", + "eventId": 2 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/NeuralNetInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6434, + "events": [ + { + "eventName": "scene", + "eventId": 3 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/BrakeControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6435, + "events": [ + { + "eventName": "brake_instruction", + "eventId": 4 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/SteeringControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6436, + "events": [ + { + "eventName": "steering", + "eventId": 5 + } + ] + } + ] + } + ], + "serviceInstances": [ + { + "instanceSpecifier": "/feo/com/MiniAdasCamera", + "serviceTypeName": "/feo/com/CameraInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 1, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "image", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasRadar", + "serviceTypeName": "/feo/com/RadarInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 2, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "scan", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasNeuralNet", + "serviceTypeName": "/feo/com/NeuralNetInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 3, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "scene", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasBrakeController", + "serviceTypeName": "/feo/com/BrakeControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 4, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "brake_instruction", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasSteeringController", + "serviceTypeName": "/feo/com/SteeringControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 5, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "steering", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + } + ] +} diff --git a/examples/rust/mini-adas/etc/mw_com_config_102.json b/examples/rust/mini-adas/etc/mw_com_config_102.json new file mode 100644 index 0000000..7e92ad3 --- /dev/null +++ b/examples/rust/mini-adas/etc/mw_com_config_102.json @@ -0,0 +1,264 @@ +{ + "global": { + "applicationID": 4002 + }, + "serviceTypes": [ + { + "serviceTypeName": "/feo/com/CameraInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6432, + "events": [ + { + "eventName": "image", + "eventId": 1 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/RadarInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6433, + "events": [ + { + "eventName": "scan", + "eventId": 2 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/NeuralNetInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6434, + "events": [ + { + "eventName": "scene", + "eventId": 3 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/BrakeControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6435, + "events": [ + { + "eventName": "brake_instruction", + "eventId": 4 + } + ] + } + ] + }, + { + "serviceTypeName": "/feo/com/SteeringControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "bindings": [ + { + "binding": "SHM", + "serviceId": 6436, + "events": [ + { + "eventName": "steering", + "eventId": 5 + } + ] + } + ] + } + ], + "serviceInstances": [ + { + "instanceSpecifier": "/feo/com/MiniAdasCamera", + "serviceTypeName": "/feo/com/CameraInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 1, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "image", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasRadar", + "serviceTypeName": "/feo/com/RadarInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 2, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "scan", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasNeuralNet", + "serviceTypeName": "/feo/com/NeuralNetInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 3, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "scene", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasBrakeController", + "serviceTypeName": "/feo/com/BrakeControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 4, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "brake_instruction", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + }, + { + "instanceSpecifier": "/feo/com/MiniAdasSteeringController", + "serviceTypeName": "/feo/com/SteeringControllerInterface", + "version": { + "major": 1, + "minor": 0 + }, + "instances": [ + { + "instanceId": 5, + "allowedConsumer": { + "QM": [ + 0 + ] + }, + "allowedProvider": { + "QM": [ + 0 + ] + }, + "asil-level": "QM", + "binding": "SHM", + "events": [ + { + "eventName": "steering", + "numberOfSampleSlots": 10, + "maxSubscribers": 3 + } + ] + } + ] + } + ] +} diff --git a/examples/rust/mini-adas/src/bin/adas_primary.rs b/examples/rust/mini-adas/src/bin/adas_primary.rs index 0221929..a7033a5 100644 --- a/examples/rust/mini-adas/src/bin/adas_primary.rs +++ b/examples/rust/mini-adas/src/bin/adas_primary.rs @@ -16,7 +16,7 @@ use feo::agent::com_init::initialize_com_primary; use feo::ids::AgentId; use feo_time::Duration; #[cfg(feature = "com_mw")] -use mini_adas::config::mw_com_runtime; +use mini_adas::config::init_mw_com_runtime; #[cfg(not(feature = "com_mw"))] use mini_adas::config::{agent_assignments_ids, topic_dependencies, COM_BACKEND, MAX_ADDITIONAL_SUBSCRIBERS}; use score_log::{error, info, LevelFilter}; @@ -53,7 +53,7 @@ fn main() { // Initialize MW COM #[cfg(feature = "com_mw")] - mw_com_runtime(); + init_mw_com_runtime(AGENT_ID); // Setup and run primary cfg::Primary::new(config) diff --git a/examples/rust/mini-adas/src/bin/adas_secondary.rs b/examples/rust/mini-adas/src/bin/adas_secondary.rs index 6a0d4be..51228b6 100644 --- a/examples/rust/mini-adas/src/bin/adas_secondary.rs +++ b/examples/rust/mini-adas/src/bin/adas_secondary.rs @@ -15,6 +15,8 @@ use feo::agent::com_init::initialize_com_secondary; #[cfg(not(feature = "com_mw"))] use feo::ids::ActivityId; +#[cfg(feature = "com_mw")] +use mini_adas::config::init_mw_com_runtime; #[cfg(not(feature = "com_mw"))] use mini_adas::config::{agent_assignments_ids, topic_dependencies, COM_BACKEND}; use score_log::{info, LevelFilter}; @@ -65,6 +67,10 @@ fn main() { .copied() .collect(); + // Initialize MW COM + #[cfg(feature = "com_mw")] + init_mw_com_runtime(params.agent_id); + // Initialize topics. Do not drop. #[cfg(not(feature = "com_mw"))] let _topic_guards = initialize_com_secondary(COM_BACKEND, topic_dependencies(), &local_activities); @@ -107,6 +113,10 @@ fn main() { .copied() .collect(); + // Initialize MW COM + #[cfg(feature = "com_mw")] + init_mw_com_runtime(params.agent_id); + // Initialize topics. Do not drop. #[cfg(not(feature = "com_mw"))] let _topic_guards = initialize_com_secondary(COM_BACKEND, topic_dependencies(), &local_activities); @@ -152,6 +162,10 @@ fn main() { .copied() .collect(); + // Initialize MW COM + #[cfg(feature = "com_mw")] + init_mw_com_runtime(params.agent_id); + // Initialize topics. Do not drop. #[cfg(not(feature = "com_mw"))] let _topic_guards = initialize_com_secondary(COM_BACKEND, topic_dependencies(), &local_activities); diff --git a/examples/rust/mini-adas/src/config.rs b/examples/rust/mini-adas/src/config.rs index 99e09a3..ad98301 100644 --- a/examples/rust/mini-adas/src/config.rs +++ b/examples/rust/mini-adas/src/config.rs @@ -26,6 +26,8 @@ use feo_com::interface::ComBackend; use mini_adas_gen::{BrakeInstruction, CameraImage, RadarScan, Scene, Steering}; use std::collections::HashMap; use std::path::{Path, PathBuf}; +#[cfg(feature = "com_mw")] +use std::sync::OnceLock; pub type WorkerAssignment = (WorkerId, Vec<(ActivityId, Box)>); @@ -50,14 +52,23 @@ pub const TOPIC_RADAR_FRONT: &str = "/feo/com/MiniAdasRadar"; pub const MAX_ADDITIONAL_SUBSCRIBERS: usize = 2; #[cfg(feature = "com_mw")] -pub fn mw_com_runtime() -> &'static LolaRuntimeImpl { - use std::sync::LazyLock; - static RUNTIME: LazyLock = LazyLock::new(|| { +static MW_COM_RUNTIME: OnceLock = OnceLock::new(); + +#[cfg(feature = "com_mw")] +pub fn init_mw_com_runtime(agent_id: AgentId) -> &'static LolaRuntimeImpl { + MW_COM_RUNTIME.get_or_init(|| { let mut lola_runtime_builder = LolaRuntimeBuilderImpl::new(); - lola_runtime_builder.load_config(&PathBuf::from("./examples/rust/mini-adas/etc/mw_com_config.json")); + lola_runtime_builder.load_config(&PathBuf::from(format!( + "./examples/rust/mini-adas/etc/mw_com_config_{}.json", + agent_id.id() + ))); lola_runtime_builder.build().unwrap() - }); - &RUNTIME + }) +} + +#[cfg(feature = "com_mw")] +pub fn mw_com_runtime() -> &'static LolaRuntimeImpl { + MW_COM_RUNTIME.get().unwrap() } pub fn socket_paths() -> (PathBuf, PathBuf) {