Simplifying MQTT handling

This commit is contained in:
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]] [[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",
] ]

View File

@ -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"

View File

@ -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,