Skip to content
Merged
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
35 changes: 13 additions & 22 deletions aimdb-codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub fn generate_main_rs(state: &ArchitectureState, binary_name: &str) -> Option<
.filter_map(|c| match c.protocol.as_str() {
"mqtt" => Some(quote! { use aimdb_mqtt_connector::MqttConnector; }),
"knx" => Some(quote! {
use aimdb_knx_connector::{Channels, KnxConnector};
use aimdb_knx_connector::KnxConnector;
use aimdb_tokio_adapter::net::{TokioDelay, TokioNet};
}),
"ws" => Some(quote! { use aimdb_websocket_connector::WebSocketConnector; }),
Expand All @@ -269,18 +269,13 @@ 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) },
// The adapter owns the socket and the clock; the channels are
// the binary's, in a block-scoped `static`.
// The adapter owns the socket and the clock.
"knx" => quote! {
{
static KNX_CHANNELS: Channels = Channels::new();
KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&#var_ident,
&KNX_CHANNELS,
)
}
KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&#var_ident,
)
},
"ws" => quote! {
WebSocketConnector::new()
Expand Down Expand Up @@ -1411,7 +1406,7 @@ pub fn generate_hub_main_rs(state: &ArchitectureState) -> String {
}
if has_knx {
v.push(quote! {
use aimdb_knx_connector::{Channels, KnxConnector};
use aimdb_knx_connector::KnxConnector;
use aimdb_tokio_adapter::net::{TokioDelay, TokioNet};
});
}
Expand Down Expand Up @@ -1456,15 +1451,11 @@ pub fn generate_hub_main_rs(state: &ArchitectureState) -> String {
}
if has_knx {
v.push(quote! {
.with_connector({
static KNX_CHANNELS: Channels = Channels::new();
KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&knx_gateway,
&KNX_CHANNELS,
)
})
.with_connector(KnxConnector::new(
TokioNet::udp(std::net::Ipv4Addr::UNSPECIFIED),
TokioDelay,
&knx_gateway,
))
});
}
if has_ws {
Expand Down
18 changes: 7 additions & 11 deletions aimdb-knx-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ default = ["aimdb-core/alloc"]
# feature here — which is what lets a third runtime (FreeRTOS/lwIP) use this
# crate with no edit to it.
#
# `embassy-sync` is not an Embassy dependency in the executor sense: it is
# no_std, no_alloc, and pulls no executor, and its `Channel` is this connector's
# public queue type (`Channels`) on every runtime.
# `embassy-sync` no longer backs a public type here (the connection task pulls
# from the record buffers directly); it is dropped together with the old
# connector SPI.
connector = [
"aimdb-core/alloc",
"aimdb-core/connector-session", # `pump_sink`/`pump_source`/`Source`/`Payload`
"aimdb-core/connector-session", # `DatagramBinder`/`Datagram`/`Delay`
"embassy-sync",
]

Expand All @@ -49,10 +49,9 @@ embassy-runtime = ["connector"]
# the **final binary** may choose one: a library enabling it would hand every
# downstream binary a duplicate-symbol link error with no way to opt out.
#
# So this stays off by default and out of `connector`/`std`. This crate's own
# tests get the impl through a dev-dependency; a std binary that instantiates a
# `CriticalSectionRawMutex` channel and has no other impl in its graph can
# either depend on `critical-section` with `features = ["std"]` directly (the
# So this stays off by default and out of `connector`/`std`. A std binary that
# instantiates a `CriticalSectionRawMutex` channel and has no other impl in its
# graph can either depend on `critical-section` with `features = ["std"]` directly (the
# documented way) or enable this feature. On Embassy the HAL (cortex-m /
# embassy-rp / ...) already provides one.
critical-section-std-impl = ["critical-section/std"]
Expand Down Expand Up @@ -92,9 +91,6 @@ heapless = { workspace = true }

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }
# Test binaries are binaries: selecting the impl here lets `CriticalSectionRawMutex`
# link for this crate's tests without imposing that choice on consumers.
critical-section = { version = "1.2", features = ["std"] }
tokio-test = "0.4"
aimdb-tokio-adapter = { path = "../aimdb-tokio-adapter", features = [
"tokio-runtime",
Expand Down
19 changes: 4 additions & 15 deletions aimdb-knx-connector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We're working with upstream to get these changes merged. Once published, the pat
## Quick Start (Tokio)

```rust
use aimdb_knx_connector::{Channels, KnxConnector};
use aimdb_knx_connector::KnxConnector;
use aimdb_tokio_adapter::net::{TokioDelay, TokioNet};
use aimdb_tokio_adapter::TokioAdapter;
use std::net::Ipv4Addr;
Expand All @@ -55,11 +55,6 @@ struct LightState {
is_on: bool,
}

// The connector's queues. `'static` because the connection task and the pumps
// are spawned as `'static` futures; a `StaticCell` supplies this on an MCU.
// One pair per connector — do not share it between two `KnxConnector`s.
static CHANNELS: Channels = Channels::new();

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = AimDbBuilder::new()
Expand All @@ -70,7 +65,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
TokioNet::udp(Ipv4Addr::UNSPECIFIED),
TokioDelay,
"knx://192.168.1.19:3671",
&CHANNELS,
))
.configure::<LightState>(|reg| {
reg.buffer(BufferCfg::SingleLatest)
Expand All @@ -96,14 +90,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

## Quick Start (Embassy)

The same constructor — only the binder and clock change, and the channels come
from a `static` instead of being sized at runtime:
The same constructor — only the binder and clock change:

```rust
use aimdb_embassy_adapter::net::{EmbassyDelay, EmbassyNet};
use aimdb_knx_connector::{Channels, KnxConnector};

static CHANNELS: Channels<32> = Channels::new();
use aimdb_knx_connector::KnxConnector;

let binder = EmbassyNet::udp(stack, rx_meta, rx_buf, tx_meta, tx_buf);

Expand All @@ -113,12 +104,10 @@ let builder = AimDbBuilder::new()
binder,
EmbassyDelay,
"knx://192.168.1.19:3671",
&CHANNELS,
));
```

Enable `features = ["connector"], default-features = false` — no
`critical-section-std-impl`, since the HAL already provides an impl. See
Enable `features = ["connector"], default-features = false`. See
`examples/embassy-knx-connector-demo/` for the full wiring.

## Group Address Format
Expand Down
Loading
Loading