Simplifying MQTT handling
This commit is contained in:
parent
36cc423f70
commit
f38e3b9608
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -203,7 +203,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_miniconf"
|
name = "derive_miniconf"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/quartiq/miniconf.git?branch=feature/mqtt-removal#6b6b9d7973ac5b4771c211c775c51f82d4a7727f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -416,10 +415,10 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "miniconf"
|
name = "miniconf"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/quartiq/miniconf.git?branch=feature/mqtt-removal#6b6b9d7973ac5b4771c211c775c51f82d4a7727f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_miniconf",
|
"derive_miniconf",
|
||||||
"heapless 0.6.1",
|
"heapless 0.6.1",
|
||||||
|
"minimq",
|
||||||
"serde",
|
"serde",
|
||||||
"serde-json-core",
|
"serde-json-core",
|
||||||
]
|
]
|
||||||
|
11
Cargo.toml
11
Cargo.toml
@ -44,7 +44,7 @@ paste = "1"
|
|||||||
dsp = { path = "dsp" }
|
dsp = { path = "dsp" }
|
||||||
ad9959 = { path = "ad9959" }
|
ad9959 = { path = "ad9959" }
|
||||||
generic-array = "0.14"
|
generic-array = "0.14"
|
||||||
miniconf = "0.1.0"
|
miniconf = { version = "0.1.0", features = ["minimq-support"] }
|
||||||
|
|
||||||
[dependencies.mcp23017]
|
[dependencies.mcp23017]
|
||||||
git = "https://github.com/mrd0ll4r/mcp23017.git"
|
git = "https://github.com/mrd0ll4r/mcp23017.git"
|
||||||
@ -55,8 +55,13 @@ features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"]
|
|||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
||||||
[patch.crates-io.miniconf]
|
[patch.crates-io.miniconf]
|
||||||
git = "https://github.com/quartiq/miniconf.git"
|
path = "../miniconf"
|
||||||
branch = "feature/mqtt-removal"
|
# git = "https://github.com/quartiq/miniconf.git"
|
||||||
|
# branch = "feature/mqtt-removal"
|
||||||
|
|
||||||
|
[patch.crates-io.minimq]
|
||||||
|
git = "https://github.com/quartiq/minimq.git"
|
||||||
|
rev = "933687c2e4b"
|
||||||
|
|
||||||
[dependencies.smoltcp-nal]
|
[dependencies.smoltcp-nal]
|
||||||
git = "https://github.com/quartiq/smoltcp-nal.git"
|
git = "https://github.com/quartiq/smoltcp-nal.git"
|
||||||
|
@ -116,31 +116,10 @@ where
|
|||||||
// Handle any MQTT traffic.
|
// Handle any MQTT traffic.
|
||||||
match self.mqtt.borrow_mut().poll(
|
match self.mqtt.borrow_mut().poll(
|
||||||
|client, topic, message, properties| {
|
|client, topic, message, properties| {
|
||||||
// Find correlation-data and response topics.
|
if let Some(response) = self.miniconf.borrow_mut().process(
|
||||||
let correlation_data = properties.iter().find_map(|prop| {
|
topic,
|
||||||
if let minimq::Property::CorrelationData(data) = prop {
|
miniconf::Message::from(message, properties),
|
||||||
Some(*data)
|
) {
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let response_topic = properties.iter().find_map(|prop| {
|
|
||||||
if let minimq::Property::ResponseTopic(topic) = prop {
|
|
||||||
Some(*topic)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let incoming = miniconf::Message {
|
|
||||||
data: message,
|
|
||||||
correlation_data,
|
|
||||||
response_topic,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(response) =
|
|
||||||
self.miniconf.borrow_mut().process(topic, incoming)
|
|
||||||
{
|
|
||||||
let mut response_properties: Vec<
|
let mut response_properties: Vec<
|
||||||
minimq::Property,
|
minimq::Property,
|
||||||
consts::U1,
|
consts::U1,
|
||||||
|
Loading…
Reference in New Issue
Block a user