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:
bors[bot] 2021-06-25 12:44:51 +00:00 committed by GitHub
commit ef9de6f10e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -271,6 +271,7 @@ impl DataStream {
} }
fn close(&mut self) { fn close(&mut self) {
log::info!("Closing stream");
// Note(unwrap): We guarantee that the socket is available above. // Note(unwrap): We guarantee that the socket is available above.
let socket = self.socket.take().unwrap(); let socket = self.socket.take().unwrap();
self.stack.close(socket).unwrap(); self.stack.close(socket).unwrap();
@ -281,17 +282,14 @@ impl DataStream {
self.close(); 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 remote.ip().is_unspecified() {
if self.socket.is_some() {
self.close();
}
return Err(()); return Err(());
} }
let mut socket = self.stack.socket().map_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 // Note(unwrap): We only connect with a new socket, so it is guaranteed to not already be
// bound. // bound.
self.stack.connect(&mut socket, remote).unwrap(); self.stack.connect(&mut socket, remote).unwrap();

View File

@ -80,6 +80,7 @@ where
// If we're no longer subscribed to the settings topic, but we are connected to the broker, // If we're no longer subscribed to the settings topic, but we are connected to the broker,
// resubscribe. // resubscribe.
if !self.subscribed && mqtt_connected { 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 // Note(unwrap): We construct a string with two more characters than the prefix
// strucutre, so we are guaranteed to have space for storage. // strucutre, so we are guaranteed to have space for storage.
let mut settings_topic: String<66> = let mut settings_topic: String<66> =
@ -115,6 +116,8 @@ where
} }
}; };
log::info!("Settings update: `{}`", path);
let message: SettingsResponse = settings let message: SettingsResponse = settings
.string_set(path.split('/').peekable(), message) .string_set(path.split('/').peekable(), message)
.map(|_| { .map(|_| {
@ -140,13 +143,13 @@ where
Ok(_) if update => UpdateState::Updated, Ok(_) if update => UpdateState::Updated,
Ok(_) => UpdateState::NoChange, Ok(_) => UpdateState::NoChange,
Err(minimq::Error::SessionReset) => { Err(minimq::Error::SessionReset) => {
log::warn!("Settings MQTT session reset");
self.subscribed = false; self.subscribed = false;
UpdateState::NoChange UpdateState::NoChange
} }
Err(minimq::Error::Network( Err(minimq::Error::Network(
smoltcp_nal::NetworkError::NoIpAddress, smoltcp_nal::NetworkError::NoIpAddress,
)) => UpdateState::NoChange, )) => UpdateState::NoChange,
Err(error) => { Err(error) => {
log::info!("Unexpected error: {:?}", error); log::info!("Unexpected error: {:?}", error);
UpdateState::NoChange UpdateState::NoChange

View File

@ -45,12 +45,16 @@ impl NetworkProcessor {
pub fn handle_link(&mut self) { pub fn handle_link(&mut self) {
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network // If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
// stack. // stack.
match self.phy.poll_link() { let link_up = self.phy.poll_link();
true => self.network_was_reset = false, 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 // Only reset the network stack once per link reconnection. This prevents us from
// sending an excessive number of DHCP requests. // 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.network_was_reset = true;
self.stack.lock(|stack| stack.handle_link_reset()); self.stack.lock(|stack| stack.handle_link_reset());
} }