Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 52 additions & 8 deletions aimdb-codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ pub fn generate_main_rs(state: &ArchitectureState, binary_name: &str) -> Option<
.iter()
.filter_map(|c| match c.protocol.as_str() {
"mqtt" => Some(quote! { use aimdb_mqtt_connector::MqttConnector; }),
"knx" => Some(quote! { use aimdb_knx_connector::KnxConnector; }),
"knx" => Some(quote! {
use aimdb_knx_connector::{Channels, KnxConnector};
use aimdb_tokio_adapter::net::{TokioDelay, TokioNet};
}),
"ws" => Some(quote! { use aimdb_websocket_connector::WebSocketConnector; }),
_ => None,
})
Expand All @@ -266,7 +269,19 @@ pub fn generate_main_rs(state: &ArchitectureState, binary_name: &str) -> Option<
let default = &c.default;
let ctor: TokenStream = match c.protocol.as_str() {
"mqtt" => quote! { MqttConnector::new(&#var_ident) },
"knx" => quote! { KnxConnector::new(&#var_ident) },
// The adapter owns the socket and the clock; the channels are
// the binary's, in a block-scoped `static`.
"knx" => quote! {
{
static KNX_CHANNELS: Channels = Channels::new();
KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&#var_ident,
&KNX_CHANNELS,
)
}
},
"ws" => quote! {
WebSocketConnector::new()
.bind(#var_ident.parse::<std::net::SocketAddr>()
Expand Down Expand Up @@ -474,6 +489,12 @@ pub fn generate_binary_cargo_toml(state: &ArchitectureState, binary_name: &str)
let has_knx = bin.external_connectors.iter().any(|c| c.protocol == "knx");
let has_ws = bin.external_connectors.iter().any(|c| c.protocol == "ws");

let tokio_adapter_features = if has_knx {
"[\"tokio-runtime\", \"net\"]"
} else {
"[\"tokio-runtime\"]"
};

let mut optional_connector_deps = String::new();
if has_mqtt {
optional_connector_deps.push_str(
Expand All @@ -482,7 +503,9 @@ pub fn generate_binary_cargo_toml(state: &ArchitectureState, binary_name: &str)
}
if has_knx {
optional_connector_deps.push_str(
"aimdb-knx-connector = { version = \"0.5\", features = [\"tokio-runtime\"] }\n",
"# critical-section-std-impl: the KNX channels need an impl, and only \
the binary may pick one.\n\
aimdb-knx-connector = { version = \"0.5\", features = [\"tokio-runtime\", \"critical-section-std-impl\"] }\n",
);
}
if has_ws {
Expand All @@ -506,7 +529,7 @@ path = \"src/main.rs\"\n\
[dependencies]\n\
{common_crate_dep} = {{ path = \"../{common_crate_name}\" }}\n\
aimdb-core = {{ version = \"0.5\" }}\n\
aimdb-tokio-adapter = {{ version = \"0.5\", features = [\"tokio-runtime\"] }}\n\
aimdb-tokio-adapter = {{ version = \"0.5\", features = {tokio_adapter_features} }}\n\
{optional_connector_deps}\
tokio = {{ version = \"1\", features = [\"full\"] }}\n\
tracing = \"0.1\"\n\
Expand Down Expand Up @@ -1303,6 +1326,12 @@ pub fn generate_hub_cargo_toml(state: &ArchitectureState) -> String {
.iter()
.any(|r| r.connectors.iter().any(|c| c.protocol == "ws"));

let tokio_adapter_features = if has_knx {
"[\"tokio-runtime\", \"net\"]"
} else {
"[\"tokio-runtime\"]"
};

let mut connector_deps = String::new();
if has_mqtt {
connector_deps.push_str(
Expand All @@ -1311,7 +1340,9 @@ pub fn generate_hub_cargo_toml(state: &ArchitectureState) -> String {
}
if has_knx {
connector_deps.push_str(
"aimdb-knx-connector = { version = \"0.5\", features = [\"tokio-runtime\"] }\n",
"# critical-section-std-impl: the KNX channels need an impl, and only \
the binary may pick one.\n\
aimdb-knx-connector = { version = \"0.5\", features = [\"tokio-runtime\", \"critical-section-std-impl\"] }\n",
);
}
if has_ws {
Expand All @@ -1338,7 +1369,7 @@ path = \"src/main.rs\"\n\
{common_crate_name} = {{ path = \"../{common_crate_name}\" }}\n\
aimdb-core = {{ version = \"0.5\" }}\n\
aimdb-data-contracts = {{ version = \"0.5\", features = [\"linkable\"] }}\n\
aimdb-tokio-adapter = {{ version = \"0.5\", features = [\"tokio-runtime\"] }}\n\
aimdb-tokio-adapter = {{ version = \"0.5\", features = {tokio_adapter_features} }}\n\
{connector_deps}\
tokio = {{ version = \"1\", features = [\"full\"] }}\n\
tracing = \"0.1\"\n\
Expand Down Expand Up @@ -1379,7 +1410,10 @@ pub fn generate_hub_main_rs(state: &ArchitectureState) -> String {
v.push(quote! { use aimdb_mqtt_connector::MqttConnector; });
}
if has_knx {
v.push(quote! { use aimdb_knx_connector::KnxConnector; });
v.push(quote! {
use aimdb_knx_connector::{Channels, KnxConnector};
use aimdb_tokio_adapter::net::{TokioDelay, TokioNet};
});
}
if has_ws {
v.push(quote! { use aimdb_websocket_connector::WebSocketConnector; });
Expand Down Expand Up @@ -1421,7 +1455,17 @@ pub fn generate_hub_main_rs(state: &ArchitectureState) -> String {
v.push(quote! { .with_connector(MqttConnector::new(&mqtt_url)) });
}
if has_knx {
v.push(quote! { .with_connector(KnxConnector::new(&knx_gateway)) });
v.push(quote! {
.with_connector({
static KNX_CHANNELS: Channels = Channels::new();
KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&knx_gateway,
&KNX_CHANNELS,
)
})
});
}
if has_ws {
v.push(quote! { .with_connector(WebSocketConnector::new().bind(ws_bind).path("/ws")) });
Expand Down
1 change: 1 addition & 0 deletions aimdb-embassy-adapter/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ impl Datagram for EmbassyUdpSocket {
}

/// Binds [`EmbassyUdpSocket`]s over one caller-owned socket.
#[derive(Clone)]
pub struct EmbassyUdpBinder {
stack: Stack<'static>,
slot: Arc<UdpSlot>,
Expand Down
10 changes: 10 additions & 0 deletions aimdb-knx-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **One connector for both runtimes (breaking).**
`KnxConnector::new(binder, delay, url, &CHANNELS)` is generic over core's
`DatagramBinder` and `Delay`: a host passes `TokioNet::udp(..)`/`TokioDelay`
where an MCU passes `EmbassyNet::udp(..)`/`EmbassyDelay`. One constructor, no
runtime named in this crate's API, and no `aimdb-tokio-adapter` dependency —
the adapter stays a dev-dependency, as design 052 §8 calls for.
`with_command_queue_size` becomes the const generic `N` — an
`embassy_sync::Channel` is sized at compile time. `tokio_client` and
`embassy_client` are deleted with the `Tokio*`/`Embassy*` aliases, and
`aimdb-codegen` emits the same call with the Tokio transports.
- **`tokio-runtime` gains `embassy-sync`; `embassy-futures` is unconditional.**
Both are executor-independent, so one channel and select type serves either
runtime.
Expand Down
24 changes: 3 additions & 21 deletions aimdb-knx-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ categories = ["network-programming", "embedded", "asynchronous"]
[features]
default = ["aimdb-core/alloc"]
std = ["aimdb-core/std", "knx-pico/std", "thiserror"]
tokio-runtime = [
"std",
"tokio",
"uuid",
"async-stream",
"futures-util",
"embassy-sync",
]
# The protocol is sans-io and the transports come from an adapter, so the host
# leg adds only `std` and the executor-independent channel type.
tokio-runtime = ["std", "embassy-sync"]

# Selects `critical-section`'s std implementation.
#
Expand Down Expand Up @@ -73,19 +68,6 @@ knx-pico = { package = "aimdb-knx-pico", version = "0.3.1", default-features = f
# Error handling (std only)
thiserror = { workspace = true, optional = true }

# UUID generation for client IDs (std only)
uuid = { version = "1.0", features = ["v4"], optional = true }

# Tokio runtime dependencies (std)
tokio = { workspace = true, optional = true, features = [
"sync",
"time",
"net",
] }
async-stream = { version = "0.3", optional = true }
futures-util = { version = "0.3", optional = true, default-features = false, features = [
"alloc",
] }
futures-core = { version = "0.3", default-features = false }

# Embassy runtime dependencies (no_std)
Expand Down
Loading
Loading