Merge #393
393: network: add some useful log messages r=ryan-summers a=jordens Co-authored-by: Robert Jördens <rj@quartiq.de>
This commit is contained in:
commit
ef9de6f10e
|
@ -271,6 +271,7 @@ impl DataStream {
|
|||
}
|
||||
|
||||
fn close(&mut self) {
|
||||
log::info!("Closing stream");
|
||||
// Note(unwrap): We guarantee that the socket is available above.
|
||||
let socket = self.socket.take().unwrap();
|
||||
self.stack.close(socket).unwrap();
|
||||
|
@ -281,17 +282,14 @@ impl DataStream {
|
|||
self.close();
|
||||
}
|
||||
|
||||
// If the remote address is unspecified, just close the existing socket.
|
||||
// If the remote address is unspecified, don't open a new socket.
|
||||
if remote.ip().is_unspecified() {
|
||||
if self.socket.is_some() {
|
||||
self.close();
|
||||
}
|
||||
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let mut socket = self.stack.socket().map_err(|_| ())?;
|
||||
|
||||
log::info!("Opening stream");
|
||||
// Note(unwrap): We only connect with a new socket, so it is guaranteed to not already be
|
||||
// bound.
|
||||
self.stack.connect(&mut socket, remote).unwrap();
|
||||
|
|
|
@ -80,6 +80,7 @@ where
|
|||
// If we're no longer subscribed to the settings topic, but we are connected to the broker,
|
||||
// resubscribe.
|
||||
if !self.subscribed && mqtt_connected {
|
||||
log::info!("MQTT connected, subscribing to settings");
|
||||
// Note(unwrap): We construct a string with two more characters than the prefix
|
||||
// strucutre, so we are guaranteed to have space for storage.
|
||||
let mut settings_topic: String<66> =
|
||||
|
@ -115,6 +116,8 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
log::info!("Settings update: `{}`", path);
|
||||
|
||||
let message: SettingsResponse = settings
|
||||
.string_set(path.split('/').peekable(), message)
|
||||
.map(|_| {
|
||||
|
@ -140,13 +143,13 @@ where
|
|||
Ok(_) if update => UpdateState::Updated,
|
||||
Ok(_) => UpdateState::NoChange,
|
||||
Err(minimq::Error::SessionReset) => {
|
||||
log::warn!("Settings MQTT session reset");
|
||||
self.subscribed = false;
|
||||
UpdateState::NoChange
|
||||
}
|
||||
Err(minimq::Error::Network(
|
||||
smoltcp_nal::NetworkError::NoIpAddress,
|
||||
)) => UpdateState::NoChange,
|
||||
|
||||
Err(error) => {
|
||||
log::info!("Unexpected error: {:?}", error);
|
||||
UpdateState::NoChange
|
||||
|
|
|
@ -45,12 +45,16 @@ impl NetworkProcessor {
|
|||
pub fn handle_link(&mut self) {
|
||||
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
|
||||
// stack.
|
||||
match self.phy.poll_link() {
|
||||
true => self.network_was_reset = false,
|
||||
|
||||
let link_up = self.phy.poll_link();
|
||||
match (link_up, self.network_was_reset) {
|
||||
(true, true) => {
|
||||
log::warn!("Network link UP");
|
||||
self.network_was_reset = false;
|
||||
}
|
||||
// Only reset the network stack once per link reconnection. This prevents us from
|
||||
// sending an excessive number of DHCP requests.
|
||||
false if !self.network_was_reset => {
|
||||
(false, false) => {
|
||||
log::warn!("Network link DOWN");
|
||||
self.network_was_reset = true;
|
||||
self.stack.lock(|stack| stack.handle_link_reset());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue