Simplifying MQTT handling

master
Ryan Summers 2021-04-22 15:57:24 +02:00
parent 36cc423f70
commit f38e3b9608
3 changed files with 13 additions and 30 deletions

3
Cargo.lock generated
View File

@ -203,7 +203,6 @@ dependencies = [
[[package]]
name = "derive_miniconf"
version = "0.1.0"
source = "git+https://github.com/quartiq/miniconf.git?branch=feature/mqtt-removal#6b6b9d7973ac5b4771c211c775c51f82d4a7727f"
dependencies = [
"proc-macro2",
"quote",
@ -416,10 +415,10 @@ dependencies = [
[[package]]
name = "miniconf"
version = "0.1.0"
source = "git+https://github.com/quartiq/miniconf.git?branch=feature/mqtt-removal#6b6b9d7973ac5b4771c211c775c51f82d4a7727f"
dependencies = [
"derive_miniconf",
"heapless 0.6.1",
"minimq",
"serde",
"serde-json-core",
]

View File

@ -44,7 +44,7 @@ paste = "1"
dsp = { path = "dsp" }
ad9959 = { path = "ad9959" }
generic-array = "0.14"
miniconf = "0.1.0"
miniconf = { version = "0.1.0", features = ["minimq-support"] }
[dependencies.mcp23017]
git = "https://github.com/mrd0ll4r/mcp23017.git"
@ -55,8 +55,13 @@ features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"]
version = "0.9.0"
[patch.crates-io.miniconf]
git = "https://github.com/quartiq/miniconf.git"
branch = "feature/mqtt-removal"
path = "../miniconf"
# 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]
git = "https://github.com/quartiq/smoltcp-nal.git"

View File

@ -116,31 +116,10 @@ where
// Handle any MQTT traffic.
match self.mqtt.borrow_mut().poll(
|client, topic, message, properties| {
// Find correlation-data and response topics.
let correlation_data = properties.iter().find_map(|prop| {
if let minimq::Property::CorrelationData(data) = prop {
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)
{
if let Some(response) = self.miniconf.borrow_mut().process(
topic,
miniconf::Message::from(message, properties),
) {
let mut response_properties: Vec<
minimq::Property,
consts::U1,