Merge branch 'master' into rj/itcm

This commit is contained in:
Robert Jördens 2021-05-27 18:22:22 +02:00 committed by GitHub
commit 441c81d135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 54 deletions

68
Cargo.lock generated
View File

@ -38,10 +38,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9a69a963b70ddacfcd382524f72a4576f359af9334b3bf48a79566590bb8bfa"
dependencies = [
"bitrate",
"cortex-m 0.7.2",
"cortex-m 0.6.7",
"embedded-hal",
]
[[package]]
name = "atomic-polyfill"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30302dda7a66f8c55932ebf208f7def840743ff64d495e9ceffcd97c18f11d39"
dependencies = [
"cortex-m 0.7.2",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -237,11 +246,11 @@ dependencies = [
[[package]]
name = "embedded-nal"
version = "0.1.0"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae46eb1b02de5a76d9d0ea21d657ff5b0ad2cc47f3a7723608227b1dd1b3eb18"
checksum = "db9efecb57ab54fa918730f2874d7d37647169c50fa1357fecb81abee840b113"
dependencies = [
"heapless 0.5.6",
"heapless 0.7.1",
"nb 1.0.0",
"no-std-net",
]
@ -314,24 +323,21 @@ dependencies = [
"byteorder",
]
[[package]]
name = "hash32"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67"
dependencies = [
"byteorder",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "heapless"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1"
dependencies = [
"as-slice",
"generic-array 0.13.3",
"hash32",
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.6.1"
@ -340,11 +346,22 @@ checksum = "634bd4d29cbf24424d0a4bfcbf80c6960129dc24424752a7d1d1390607023422"
dependencies = [
"as-slice",
"generic-array 0.14.4",
"hash32",
"hash32 0.1.1",
"serde",
"stable_deref_trait",
]
[[package]]
name = "heapless"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7ee8a997d259962217f40279f34201fdf06e669bafa69d7c1f4c7ff1893b5f6"
dependencies = [
"atomic-polyfill",
"hash32 0.2.1",
"stable_deref_trait",
]
[[package]]
name = "indexmap"
version = "1.6.2"
@ -388,7 +405,7 @@ dependencies = [
[[package]]
name = "mcp23017"
version = "0.1.1"
source = "git+https://github.com/mrd0ll4r/mcp23017.git?rev=61933f857a#61933f857abe5a837800493a5f58e91a3c9435ec"
source = "git+https://github.com/lucazulian/mcp23017.git?rev=523d71d#523d71dcb11fc0ea4bd9385ef2527ae7a7eee987"
dependencies = [
"embedded-hal",
]
@ -406,13 +423,12 @@ dependencies = [
[[package]]
name = "minimq"
version = "0.2.0"
source = "git+https://github.com/quartiq/minimq.git?rev=d2ec3e8#d2ec3e8351fa403ea96defd98c0b4410cbaa18a4"
source = "git+https://github.com/quartiq/minimq.git?rev=dbdbec0#dbdbec0b77d2e134dc6c025018a82c14cbdfbe34"
dependencies = [
"bit_field",
"embedded-nal",
"enum-iterator",
"generic-array 0.14.4",
"heapless 0.6.1",
"heapless 0.7.1",
]
[[package]]
@ -451,9 +467,9 @@ dependencies = [
[[package]]
name = "no-std-net"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2178127478ae4ee9be7180bc9c3bffb6354dd7238400db567102f98c413a9f35"
checksum = "1bcece43b12349917e096cddfa66107277f123e6c96a5aea78711dc601a47152"
[[package]]
name = "num"
@ -736,10 +752,10 @@ dependencies = [
[[package]]
name = "smoltcp-nal"
version = "0.1.0"
source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=4a1711c#4a1711c54cdf79f5ee8c1c99a1e8984f5944270c"
source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=5e56576#5e56576fbbc594f0a0e1df9222a20eb35c8e7511"
dependencies = [
"embedded-nal",
"heapless 0.6.1",
"heapless 0.7.1",
"nanorand",
"smoltcp",
]
@ -785,7 +801,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b672c837e0ee8158ecc7fce0f9a948dd0693a9c588338e728d14b73307a0b7d"
dependencies = [
"bare-metal 0.2.5",
"cortex-m 0.7.2",
"cortex-m 0.6.7",
"cortex-m-rt",
"vcell",
]

View File

@ -53,8 +53,8 @@ rev = "70b0eb5"
# rewrite
[dependencies.mcp23017]
git = "https://github.com/mrd0ll4r/mcp23017.git"
rev = "61933f857a"
git = "https://github.com/lucazulian/mcp23017.git"
rev = "523d71d"
[dependencies.stm32h7xx-hal]
features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"]
@ -71,11 +71,11 @@ rev = "c6f2b28"
[dependencies.smoltcp-nal]
git = "https://github.com/quartiq/smoltcp-nal.git"
rev = "4a1711c"
rev = "5e56576"
[dependencies.minimq]
git = "https://github.com/quartiq/minimq.git"
rev = "d2ec3e8"
rev = "dbdbec0"
[features]
nightly = ["cortex-m/inline-asm", "dsp/nightly"]

View File

@ -13,7 +13,7 @@ use hardware::{
DigitalInput0, DigitalInput1, InputPin, SystemTimer, AFE0, AFE1,
};
use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState};
use net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer};
const SCALE: f32 = i16::MAX as _;
@ -173,8 +173,11 @@ const APP: () = {
fn idle(mut c: idle::Context) -> ! {
loop {
match c.resources.network.lock(|net| net.update()) {
UpdateState::Updated => c.spawn.settings_update().unwrap(),
UpdateState::NoChange => cortex_m::asm::wfi(),
NetworkState::SettingsChanged => {
c.spawn.settings_update().unwrap()
}
NetworkState::Updated => {}
NetworkState::NoChange => cortex_m::asm::wfi(),
}
}
}

View File

@ -17,7 +17,7 @@ use stabilizer::hardware::{
};
use miniconf::Miniconf;
use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState};
use net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer};
// A constant sinusoid to send on the DAC output.
// Full-scale gives a +/- 10.24V amplitude waveform. Scale it down to give +/- 1V.
@ -250,8 +250,11 @@ const APP: () = {
fn idle(mut c: idle::Context) -> ! {
loop {
match c.resources.network.lock(|net| net.update()) {
UpdateState::Updated => c.spawn.settings_update().unwrap(),
UpdateState::NoChange => cortex_m::asm::wfi(),
NetworkState::SettingsChanged => {
c.spawn.settings_update().unwrap()
}
NetworkState::Updated => {}
NetworkState::NoChange => cortex_m::asm::wfi(),
}
}
}

View File

@ -21,7 +21,7 @@ where
S: miniconf::Miniconf + Default + Clone,
{
default_response_topic: String<consts::U128>,
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>,
mqtt: minimq::Minimq<NetworkReference, 256>,
settings: S,
subscribed: bool,
settings_prefix: String<consts::U64>,
@ -39,8 +39,7 @@ where
/// * `prefix` - The MQTT device prefix to use for this device.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
.unwrap();
minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();
let mut response_topic: String<consts::U128> = String::from(prefix);
response_topic.push_str("/log").unwrap();
@ -62,7 +61,7 @@ where
/// # Returns
/// An option containing an action that should be completed as a result of network servicing.
pub fn update(&mut self) -> UpdateState {
let mqtt_connected = match self.mqtt.is_connected() {
let mqtt_connected = match self.mqtt.client.is_connected() {
Ok(connected) => connected,
Err(minimq::Error::Network(
smoltcp_nal::NetworkError::NoIpAddress,
@ -88,7 +87,7 @@ where
// We do not currently handle or process potential subscription failures. Instead, this
// failure will be logged through the stabilizer logging interface.
self.mqtt.subscribe(&settings_topic, &[]).unwrap();
self.mqtt.client.subscribe(&settings_topic, &[]).unwrap();
self.subscribed = true;
}

View File

@ -33,6 +33,12 @@ pub enum UpdateState {
Updated,
}
#[derive(Copy, Clone, PartialEq)]
pub enum NetworkState {
SettingsChanged,
Updated,
NoChange,
}
/// A structure of Stabilizer's default network users.
pub struct NetworkUsers<S: Default + Clone + Miniconf, T: Serialize> {
pub miniconf: MiniconfClient<S>,
@ -98,15 +104,18 @@ where
///
/// # Returns
/// An indication if any of the network users indicated a state change.
pub fn update(&mut self) -> UpdateState {
pub fn update(&mut self) -> NetworkState {
// Poll for incoming data.
let poll_result = self.processor.update();
let poll_result = match self.processor.update() {
UpdateState::NoChange => NetworkState::NoChange,
UpdateState::Updated => NetworkState::Updated,
};
// Update the MQTT clients.
self.telemetry.update();
match self.miniconf.update() {
UpdateState::Updated => UpdateState::Updated,
UpdateState::Updated => NetworkState::SettingsChanged,
UpdateState::NoChange => poll_result,
}
}

View File

@ -47,25 +47,25 @@ impl<'a, S> NetworkStackProxy<'a, S> {
// proxy structure.
macro_rules! forward {
($func:ident($($v:ident: $IT:ty),*) -> $T:ty) => {
fn $func(&self, $($v: $IT),*) -> $T {
fn $func(&mut self, $($v: $IT),*) -> $T {
self.mutex.lock(|stack| stack.$func($($v),*))
}
}
}
// Implement a TCP stack for the proxy if the underlying network stack implements it.
impl<'a, S> embedded_nal::TcpStack for NetworkStackProxy<'a, S>
impl<'a, S> embedded_nal::TcpClientStack for NetworkStackProxy<'a, S>
where
S: embedded_nal::TcpStack,
S: embedded_nal::TcpClientStack,
{
type TcpSocket = S::TcpSocket;
type Error = S::Error;
forward! {open(mode: embedded_nal::Mode) -> Result<S::TcpSocket, S::Error>}
forward! {connect(socket: S::TcpSocket, remote: embedded_nal::SocketAddr) -> Result<S::TcpSocket, S::Error>}
forward! {socket() -> Result<S::TcpSocket, S::Error>}
forward! {connect(socket: &mut S::TcpSocket, remote: embedded_nal::SocketAddr) -> embedded_nal::nb::Result<(), S::Error>}
forward! {is_connected(socket: &S::TcpSocket) -> Result<bool, S::Error>}
forward! {write(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {read(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {send(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {receive(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result<usize, S::Error>}
forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>}
}

View File

@ -21,7 +21,7 @@ use crate::hardware::{
/// The telemetry client for reporting telemetry data over MQTT.
pub struct TelemetryClient<T: Serialize> {
mqtt: minimq::MqttClient<minimq::consts::U256, NetworkReference>,
mqtt: minimq::Minimq<NetworkReference, 256>,
telemetry_topic: String<consts::U128>,
_telemetry: core::marker::PhantomData<T>,
}
@ -97,8 +97,7 @@ impl<T: Serialize> TelemetryClient<T> {
/// A new telemetry client.
pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self {
let mqtt =
minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack)
.unwrap();
minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap();
let mut telemetry_topic: String<consts::U128> = String::from(prefix);
telemetry_topic.push_str("/telemetry").unwrap();
@ -122,6 +121,7 @@ impl<T: Serialize> TelemetryClient<T> {
let telemetry: Vec<u8, consts::U256> =
serde_json_core::to_vec(telemetry).unwrap();
self.mqtt
.client
.publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[])
.ok();
}