-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de15769
commit fdca46f
Showing
16 changed files
with
418 additions
and
509 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
use clap::Parser; | ||
use up_client_mqtt5_rust::MqttConfig; | ||
use up_transport_zenoh::zenoh_config; | ||
|
||
#[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)] | ||
pub enum WhatAmIType { | ||
Peer, | ||
Client, | ||
Router, | ||
} | ||
|
||
#[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] | ||
pub struct ZenohArgs { | ||
#[arg(short, long)] | ||
/// A configuration file. | ||
config: Option<String>, | ||
#[arg(short, long)] | ||
/// The Zenoh session mode [default: peer]. | ||
mode: Option<WhatAmIType>, | ||
#[arg(short = 'e', long)] | ||
/// Endpoints to connect to. | ||
connect: Vec<String>, | ||
#[arg(short, long)] | ||
/// Endpoints to listen on. | ||
listen: Vec<String>, | ||
#[arg(long)] | ||
/// Disable the multicast-based scouting mechanism. | ||
no_multicast_scouting: bool, | ||
} | ||
|
||
#[allow(clippy::must_use_candidate, clippy::missing_panics_doc)] | ||
pub fn get_zenoh_config() -> zenoh_config::Config { | ||
let args = ZenohArgs::parse(); | ||
|
||
// Load the config from file path | ||
let mut zenoh_cfg = match &args.config { | ||
Some(path) => zenoh_config::Config::from_file(path).unwrap(), | ||
None => zenoh_config::Config::default(), | ||
}; | ||
|
||
// You can choose from Router, Peer, Client | ||
match args.mode { | ||
Some(WhatAmIType::Peer) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Peer)), | ||
Some(WhatAmIType::Client) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Client)), | ||
Some(WhatAmIType::Router) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Router)), | ||
None => Ok(None), | ||
} | ||
.unwrap(); | ||
|
||
// Set connection address | ||
if !args.connect.is_empty() { | ||
zenoh_cfg | ||
.connect | ||
.endpoints | ||
.set(args.connect.iter().map(|v| v.parse().unwrap()).collect()) | ||
.unwrap(); | ||
} | ||
|
||
// Set listener address | ||
if !args.listen.is_empty() { | ||
zenoh_cfg | ||
.listen | ||
.endpoints | ||
.set(args.listen.iter().map(|v| v.parse().unwrap()).collect()) | ||
.unwrap(); | ||
} | ||
|
||
// Set multicast configuration | ||
if args.no_multicast_scouting { | ||
zenoh_cfg | ||
.scouting | ||
.multicast | ||
.set_enabled(Some(false)) | ||
.unwrap(); | ||
} | ||
|
||
zenoh_cfg | ||
} | ||
|
||
pub fn get_mqtt_config() -> MqttConfig { | ||
// Todo: Once MqttConfig is serializable make this ocnfigurable via json5 like zenoh | ||
let ssl_options = None; | ||
|
||
MqttConfig { | ||
mqtt_protocol: up_client_mqtt5_rust::MqttProtocol::Mqtt, | ||
mqtt_port: 1883, | ||
mqtt_hostname: "localhost".to_string(), | ||
max_buffered_messages: 100, | ||
max_subscriptions: 100, | ||
session_expiry_interval: 3600, | ||
ssl_options: ssl_options, | ||
username: "user".to_string(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.