Adding updated telemetry implementation
This commit is contained in:
parent
8144b3acf2
commit
0c6935587e
|
@ -169,21 +169,9 @@ const APP: () = {
|
||||||
#[idle(resources=[network], spawn=[settings_update])]
|
#[idle(resources=[network], spawn=[settings_update])]
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
// Update the smoltcp network stack.
|
match c.resources.network.lock(|net| net.update()) {
|
||||||
let poll_result = c
|
UpdateState::Updated => c.spawn.settings_update().unwrap(),
|
||||||
.resources
|
UpdateState::NoChange => cortex_m::asm::wfi(),
|
||||||
.network
|
|
||||||
.lock(|network| network.processor.update());
|
|
||||||
|
|
||||||
// Service the MQTT configuration client.
|
|
||||||
if c.resources
|
|
||||||
.network
|
|
||||||
.lock(|network| network.miniconf.update())
|
|
||||||
== UpdateState::Updated
|
|
||||||
{
|
|
||||||
c.spawn.settings_update().unwrap()
|
|
||||||
} else if poll_result == UpdateState::NoChange {
|
|
||||||
cortex_m::asm::wfi();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,21 +211,9 @@ const APP: () = {
|
||||||
#[idle(resources=[network], spawn=[settings_update])]
|
#[idle(resources=[network], spawn=[settings_update])]
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
// Update the smoltcp network stack.
|
match c.resources.network.lock(|net| net.update()) {
|
||||||
let poll_result = c
|
UpdateState::Updated => c.spawn.settings_update().unwrap(),
|
||||||
.resources
|
UpdateState::NoChange => cortex_m::asm::wfi(),
|
||||||
.network
|
|
||||||
.lock(|network| network.processor.update());
|
|
||||||
|
|
||||||
// Service the MQTT configuration client.
|
|
||||||
if c.resources
|
|
||||||
.network
|
|
||||||
.lock(|network| network.miniconf.update())
|
|
||||||
== UpdateState::Updated
|
|
||||||
{
|
|
||||||
c.spawn.settings_update().unwrap()
|
|
||||||
} else if poll_result == UpdateState::NoChange {
|
|
||||||
cortex_m::asm::wfi();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ use stm32h7xx_hal::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const NUM_SOCKETS: usize = 4;
|
||||||
|
|
||||||
|
use heapless::{consts, Vec};
|
||||||
use smoltcp_nal::smoltcp;
|
use smoltcp_nal::smoltcp;
|
||||||
|
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
|
@ -19,13 +22,13 @@ use super::{
|
||||||
|
|
||||||
pub struct NetStorage {
|
pub struct NetStorage {
|
||||||
pub ip_addrs: [smoltcp::wire::IpCidr; 1],
|
pub ip_addrs: [smoltcp::wire::IpCidr; 1],
|
||||||
pub sockets: [Option<smoltcp::socket::SocketSetItem<'static>>; 2],
|
pub sockets:
|
||||||
|
[Option<smoltcp::socket::SocketSetItem<'static>>; NUM_SOCKETS + 1],
|
||||||
|
pub socket_storage: [SocketStorage; NUM_SOCKETS],
|
||||||
pub neighbor_cache:
|
pub neighbor_cache:
|
||||||
[Option<(smoltcp::wire::IpAddress, smoltcp::iface::Neighbor)>; 8],
|
[Option<(smoltcp::wire::IpAddress, smoltcp::iface::Neighbor)>; 8],
|
||||||
pub routes_cache:
|
pub routes_cache:
|
||||||
[Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 8],
|
[Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 8],
|
||||||
pub tx_storage: [u8; 4096],
|
|
||||||
pub rx_storage: [u8; 4096],
|
|
||||||
|
|
||||||
pub dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata; 1],
|
pub dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata; 1],
|
||||||
pub dhcp_tx_metadata: [smoltcp::socket::RawPacketMetadata; 1],
|
pub dhcp_tx_metadata: [smoltcp::socket::RawPacketMetadata; 1],
|
||||||
|
@ -33,6 +36,21 @@ pub struct NetStorage {
|
||||||
pub dhcp_rx_storage: [u8; 600],
|
pub dhcp_rx_storage: [u8; 600],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct SocketStorage {
|
||||||
|
rx_storage: [u8; 4096],
|
||||||
|
tx_storage: [u8; 4096],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SocketStorage {
|
||||||
|
const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
rx_storage: [0; 4096],
|
||||||
|
tx_storage: [0; 4096],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl NetStorage {
|
impl NetStorage {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
NetStorage {
|
NetStorage {
|
||||||
|
@ -42,9 +60,8 @@ impl NetStorage {
|
||||||
)],
|
)],
|
||||||
neighbor_cache: [None; 8],
|
neighbor_cache: [None; 8],
|
||||||
routes_cache: [None; 8],
|
routes_cache: [None; 8],
|
||||||
sockets: [None, None],
|
sockets: [None, None, None, None, None],
|
||||||
tx_storage: [0; 4096],
|
socket_storage: [SocketStorage::new(); NUM_SOCKETS],
|
||||||
rx_storage: [0; 4096],
|
|
||||||
dhcp_tx_storage: [0; 600],
|
dhcp_tx_storage: [0; 600],
|
||||||
dhcp_rx_storage: [0; 600],
|
dhcp_rx_storage: [0; 600],
|
||||||
dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1],
|
dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1],
|
||||||
|
@ -572,19 +589,25 @@ pub fn setup(
|
||||||
let mut sockets =
|
let mut sockets =
|
||||||
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
||||||
|
|
||||||
let tcp_socket = {
|
let mut handles: Vec<smoltcp::socket::SocketHandle, consts::U64> =
|
||||||
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
Vec::new();
|
||||||
&mut store.rx_storage[..],
|
for storage in store.socket_storage.iter_mut() {
|
||||||
);
|
let tcp_socket = {
|
||||||
let tx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
||||||
&mut store.tx_storage[..],
|
&mut storage.rx_storage[..],
|
||||||
);
|
);
|
||||||
|
let tx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
||||||
|
&mut storage.tx_storage[..],
|
||||||
|
);
|
||||||
|
|
||||||
smoltcp::socket::TcpSocket::new(rx_buffer, tx_buffer)
|
smoltcp::socket::TcpSocket::new(rx_buffer, tx_buffer)
|
||||||
};
|
};
|
||||||
|
let handle = sockets.add(tcp_socket);
|
||||||
|
|
||||||
let handle = sockets.add(tcp_socket);
|
handles.push(handle).unwrap();
|
||||||
(sockets, [handle])
|
}
|
||||||
|
|
||||||
|
(sockets, handles)
|
||||||
};
|
};
|
||||||
|
|
||||||
let dhcp_client = {
|
let dhcp_client = {
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub const DDS_SYNC_CLK_DIV: u8 = 4;
|
||||||
// The number of ticks in the ADC sampling timer. The timer runs at 100MHz, so the step size is
|
// The number of ticks in the ADC sampling timer. The timer runs at 100MHz, so the step size is
|
||||||
// equal to 10ns per tick.
|
// equal to 10ns per tick.
|
||||||
// Currently, the sample rate is equal to: Fsample = 100/128 MHz ~ 800 KHz
|
// Currently, the sample rate is equal to: Fsample = 100/128 MHz ~ 800 KHz
|
||||||
pub const ADC_SAMPLE_TICKS_LOG2: u8 = 7;
|
pub const ADC_SAMPLE_TICKS_LOG2: u8 = 12;
|
||||||
pub const ADC_SAMPLE_TICKS: u16 = 1 << ADC_SAMPLE_TICKS_LOG2;
|
pub const ADC_SAMPLE_TICKS: u16 = 1 << ADC_SAMPLE_TICKS_LOG2;
|
||||||
|
|
||||||
// The desired ADC sample processing buffer size.
|
// The desired ADC sample processing buffer size.
|
||||||
|
@ -51,4 +51,4 @@ pub const SAMPLE_BUFFER_SIZE_LOG2: u8 = 3;
|
||||||
pub const SAMPLE_BUFFER_SIZE: usize = 1 << SAMPLE_BUFFER_SIZE_LOG2;
|
pub const SAMPLE_BUFFER_SIZE: usize = 1 << SAMPLE_BUFFER_SIZE_LOG2;
|
||||||
|
|
||||||
// The MQTT broker IPv4 address
|
// The MQTT broker IPv4 address
|
||||||
pub const MQTT_BROKER: [u8; 4] = [10, 34, 16, 10];
|
pub const MQTT_BROKER: [u8; 4] = [10, 35, 16, 10];
|
||||||
|
|
|
@ -80,6 +80,19 @@ where
|
||||||
telemetry,
|
telemetry,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self) -> UpdateState {
|
||||||
|
// Poll for incoming data.
|
||||||
|
let poll_result = self.processor.update();
|
||||||
|
|
||||||
|
// Update the MQTT clients.
|
||||||
|
self.telemetry.update();
|
||||||
|
|
||||||
|
match self.miniconf.update() {
|
||||||
|
UpdateState::Updated => UpdateState::Updated,
|
||||||
|
UpdateState::NoChange => poll_result,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_client_id(
|
fn get_client_id(
|
||||||
|
|
|
@ -86,4 +86,15 @@ impl<T: Serialize> TelemetryClient<T> {
|
||||||
.publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[])
|
.publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[])
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self) {
|
||||||
|
match self.mqtt.poll(|_client, _topic, _message, _properties| {}) {
|
||||||
|
Err(minimq::Error::Network(
|
||||||
|
smoltcp_nal::NetworkError::NoIpAddress,
|
||||||
|
)) => {}
|
||||||
|
|
||||||
|
Err(error) => log::info!("Unexpected error: {:?}", error),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue