提交 c01adb03 authored 作者: Serhij S's avatar Serhij S

auto name for connection

上级 9311e1af
......@@ -38,9 +38,10 @@ eva-common = { version = "0.3.49", features = ["events", "payload", "common-payl
eva-sdk = { version = "0.3.45", features = ["controller"], optional = true }
busrt = { version = "0.4.9", features = ["rpc", "ipc"], optional = true }
tokio = { version = "1.36.0", optional = true }
hostname = { version = "0.3.1", optional = true }
[features]
eapi = ["eva-common", "eva-sdk", "busrt", "tokio"]
eapi = ["eva-common", "eva-sdk", "busrt", "tokio", "hostname"]
modbus = ["rmodbus"]
openssl-vendored = ["busrt/openssl-vendored", "eva-common/openssl-vendored"]
full = ["eapi", "modbus"]
......
......@@ -87,7 +87,9 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
context.variables().write().fan = val != 0;
Ok(())
});
let eapi = EAPI::new("fieldbus.host1.plc.test", eapi_config);
// this creates a connector instance with the name `fieldbus.HOSTNAME.plc`. To use a custom
// name, use `EAPI::new` instead.
let eapi = EAPI::new_program(eapi_config);
let mut controller = Controller::<Message, Variables>::new();
controller.register_signals(Duration::from_secs(5))?;
controller.spawn_worker(Worker1 { eapi: eapi.clone() })?;
......
......@@ -213,6 +213,24 @@ where
Err(RpcError::params(None))
}
}
"info" => {
if payload.is_empty() {
#[derive(Serialize)]
struct Payload {
author: &'static str,
description: &'static str,
version: &'static str,
}
let payload = Payload {
author: env!("CARGO_PKG_AUTHORS"),
description: env!("CARGO_PKG_DESCRIPTION"),
version: env!("CARGO_PKG_VERSION"),
};
Ok(Some(pack(&payload)?))
} else {
Err(RpcError::params(None))
}
}
"action" | "run" => {
if payload.is_empty() {
return Err(RpcError::params(None));
......@@ -296,6 +314,18 @@ where
D: DataDeliveryPolicy + Clone + Send + Sync + 'static,
V: Send + Sync + 'static,
{
/// creates a new EAPI connector instance with the name, automatically formatted as
/// `fieldbus.HOSTNAME.program`
pub fn new_program(config: EAPIConfig<D, V>) -> Self {
Self::new(
format!(
"fieldbus.{}.program",
hostname::get().unwrap().to_string_lossy()
),
config,
)
}
/// creates a new EAPI connector instance with the given name
pub fn new<N: fmt::Display>(name: N, mut config: EAPIConfig<D, V>) -> Self {
let (tx, rx) =
pchannel_async::bounded(config.queue_size.unwrap_or(busrt::DEFAULT_QUEUE_SIZE));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论