From e6321f36d7448e8cd058bbfaa444912bf8aec2e1 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Sun, 28 Apr 2024 11:38:39 +0700 Subject: [PATCH] Mode debug prints for error code 400 --- crates/core/src/bc_protocol/abilityinfo.rs | 5 ++++- crates/core/src/bc_protocol/errors.rs | 9 +++++++-- crates/core/src/bc_protocol/floodlight.rs | 10 ++++++++-- crates/core/src/bc_protocol/ledstate.rs | 5 ++++- crates/core/src/bc_protocol/link.rs | 5 ++++- crates/core/src/bc_protocol/pirstate.rs | 15 ++++++++++++--- crates/core/src/bc_protocol/ptz.rs | 5 ++++- crates/core/src/bc_protocol/pushinfo.rs | 5 ++++- crates/core/src/bc_protocol/services.rs | 15 ++++++++++++--- crates/core/src/bc_protocol/siren.rs | 5 ++++- crates/core/src/bc_protocol/snap.rs | 10 ++++++++-- crates/core/src/bc_protocol/stream.rs | 10 ++++++++-- crates/core/src/bc_protocol/stream_info.rs | 5 ++++- crates/core/src/bc_protocol/support.rs | 5 ++++- crates/core/src/bc_protocol/time.rs | 5 ++++- crates/core/src/bc_protocol/uid.rs | 5 ++++- crates/core/src/bc_protocol/version.rs | 7 ++++--- src/common/instance.rs | 8 +++++--- src/mqtt/mod.rs | 4 ++-- 19 files changed, 106 insertions(+), 32 deletions(-) diff --git a/crates/core/src/bc_protocol/abilityinfo.rs b/crates/core/src/bc_protocol/abilityinfo.rs index 4bd750a..40115b3 100644 --- a/crates/core/src/bc_protocol/abilityinfo.rs +++ b/crates/core/src/bc_protocol/abilityinfo.rs @@ -30,7 +30,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/errors.rs b/crates/core/src/bc_protocol/errors.rs index 56e7323..6f18f3f 100644 --- a/crates/core/src/bc_protocol/errors.rs +++ b/crates/core/src/bc_protocol/errors.rs @@ -45,8 +45,13 @@ pub enum Error { }, /// Raised when the camera responds with a status code over than OK - #[error("Camera responded with Service Unavaliable: {0}")] - CameraServiceUnavailable(u16), + #[error("Camera responded with Service Unavaliable: Msg of type {id} returned code {code}")] + CameraServiceUnavailable { + /// The message ID + id: u32, + // The return code this is usually 200 for OK and 400 for not yet ready and 500 for camera cannot comply or understand + code: u16, + }, /// Raised when the camera responds with a status code over than OK during login #[error("Camera responded with Err during login")] diff --git a/crates/core/src/bc_protocol/floodlight.rs b/crates/core/src/bc_protocol/floodlight.rs index 661091e..6ccea20 100644 --- a/crates/core/src/bc_protocol/floodlight.rs +++ b/crates/core/src/bc_protocol/floodlight.rs @@ -129,7 +129,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { @@ -181,7 +184,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } Ok(()) diff --git a/crates/core/src/bc_protocol/ledstate.rs b/crates/core/src/bc_protocol/ledstate.rs index f013302..f2ec09f 100644 --- a/crates/core/src/bc_protocol/ledstate.rs +++ b/crates/core/src/bc_protocol/ledstate.rs @@ -29,7 +29,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/link.rs b/crates/core/src/bc_protocol/link.rs index 10db6ff..7d885a8 100644 --- a/crates/core/src/bc_protocol/link.rs +++ b/crates/core/src/bc_protocol/link.rs @@ -27,7 +27,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/pirstate.rs b/crates/core/src/bc_protocol/pirstate.rs index a238723..20f9a6d 100644 --- a/crates/core/src/bc_protocol/pirstate.rs +++ b/crates/core/src/bc_protocol/pirstate.rs @@ -39,10 +39,16 @@ impl BcCamera { reties += 1; continue; } else { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } } else if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } else { // Valid message with response_code == 200 if let BcBody::ModernMsg(ModernMsg { @@ -101,7 +107,10 @@ impl BcCamera { { let msg = reply?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcMeta { diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index 7ebbdc0..8d3657b 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -317,7 +317,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/pushinfo.rs b/crates/core/src/bc_protocol/pushinfo.rs index 9b9d46e..a0c6441 100644 --- a/crates/core/src/bc_protocol/pushinfo.rs +++ b/crates/core/src/bc_protocol/pushinfo.rs @@ -64,7 +64,10 @@ impl BcCamera { sub.send(msg).await?; let msg = sub.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } Ok(()) diff --git a/crates/core/src/bc_protocol/services.rs b/crates/core/src/bc_protocol/services.rs index d6b2dce..25f78c6 100644 --- a/crates/core/src/bc_protocol/services.rs +++ b/crates/core/src/bc_protocol/services.rs @@ -34,7 +34,10 @@ impl BcCamera { { let msg = reply?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcMeta { @@ -90,10 +93,16 @@ impl BcCamera { reties += 1; continue; } else { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } } else if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } else { // Valid message with response_code == 200 if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/siren.rs b/crates/core/src/bc_protocol/siren.rs index 06c0fa3..d36f36f 100644 --- a/crates/core/src/bc_protocol/siren.rs +++ b/crates/core/src/bc_protocol/siren.rs @@ -39,7 +39,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } Ok(()) diff --git a/crates/core/src/bc_protocol/snap.rs b/crates/core/src/bc_protocol/snap.rs index 958f142..cdbef78 100644 --- a/crates/core/src/bc_protocol/snap.rs +++ b/crates/core/src/bc_protocol/snap.rs @@ -41,7 +41,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { @@ -132,7 +135,10 @@ impl BcCamera { } } else { // anything else is an error - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } // let binary_stream = sub_get.payload_stream(); diff --git a/crates/core/src/bc_protocol/stream.rs b/crates/core/src/bc_protocol/stream.rs index b4c5f2c..240a759 100644 --- a/crates/core/src/bc_protocol/stream.rs +++ b/crates/core/src/bc_protocol/stream.rs @@ -255,7 +255,10 @@ impl BcCamera { msg_id: MSG_ID_VIDEO_STOP, .. } = msg.meta { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable{ + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } } } => v, @@ -336,7 +339,10 @@ impl BcCamera { let reply = sub_video.recv().await?; if reply.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(reply.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: reply.meta.msg_id, + code: reply.meta.response_code, + }); } Ok(()) diff --git a/crates/core/src/bc_protocol/stream_info.rs b/crates/core/src/bc_protocol/stream_info.rs index 0abc60d..c3798a9 100644 --- a/crates/core/src/bc_protocol/stream_info.rs +++ b/crates/core/src/bc_protocol/stream_info.rs @@ -27,7 +27,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/support.rs b/crates/core/src/bc_protocol/support.rs index 5adf6cf..490f0fb 100644 --- a/crates/core/src/bc_protocol/support.rs +++ b/crates/core/src/bc_protocol/support.rs @@ -26,7 +26,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/time.rs b/crates/core/src/bc_protocol/time.rs index ae64db7..a7c94e6 100644 --- a/crates/core/src/bc_protocol/time.rs +++ b/crates/core/src/bc_protocol/time.rs @@ -33,7 +33,10 @@ impl BcCamera { sub_get_general.send(get).await?; let msg = sub_get_general.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/uid.rs b/crates/core/src/bc_protocol/uid.rs index 252047d..5087178 100644 --- a/crates/core/src/bc_protocol/uid.rs +++ b/crates/core/src/bc_protocol/uid.rs @@ -25,7 +25,10 @@ impl BcCamera { sub_get.send(get).await?; let msg = sub_get.recv().await?; if msg.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable(msg.meta.response_code)); + return Err(Error::CameraServiceUnavailable { + id: msg.meta.msg_id, + code: msg.meta.response_code, + }); } if let BcBody::ModernMsg(ModernMsg { diff --git a/crates/core/src/bc_protocol/version.rs b/crates/core/src/bc_protocol/version.rs index 5e33670..d56fb9b 100644 --- a/crates/core/src/bc_protocol/version.rs +++ b/crates/core/src/bc_protocol/version.rs @@ -27,9 +27,10 @@ impl BcCamera { let modern_reply = sub_version.recv().await?; if modern_reply.meta.response_code != 200 { - return Err(Error::CameraServiceUnavailable( - modern_reply.meta.response_code, - )); + return Err(Error::CameraServiceUnavailable { + id: modern_reply.meta.msg_id, + code: modern_reply.meta.response_code, + }); } let version_info; match modern_reply.body { diff --git a/src/common/instance.rs b/src/common/instance.rs index 4bde74e..0c02b80 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -120,15 +120,17 @@ impl NeoInstance { if let Some(cam) = camera.clone() { let cam_ref = cam.as_ref(); let mut r = Err(anyhow!("No run")); - for _ in 0..5 { + for i in 0..5 { r = task(cam_ref).await; if let Err(e) = &r { - log::trace!("- Task Result: {e:?}"); + log::debug!("- Task Error: {e:?}"); } - if let Err(Some(neolink_core::Error::CameraServiceUnavailable(400))) = r.as_ref().map_err(|e| e.downcast_ref::()) { + if let Err(Some(e @ neolink_core::Error::CameraServiceUnavailable{code: 400, ..})) = r.as_ref().map_err(|e| e.downcast_ref::()) { // Retryable without a reconnect // Usually occurs when camera is starting up // or the connection is initialising + log::debug!("Got a 400 code for {e:?} retry {i}/5, "); + sleep(Duration::from_secs(1)).await; continue; } else { diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 915548e..2d28b8d 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -458,7 +458,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R }).await; let image = match image { Err(e) => match e.downcast::() { - Ok(neolink_core::Error::CameraServiceUnavailable(_)) => { + Ok(neolink_core::Error::CameraServiceUnavailable{..}) => { log::debug!("Image not supported"); futures::future::pending().await }, @@ -502,7 +502,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R }).await; let xml = match xml { Err(e) => match e.downcast::() { - Ok(neolink_core::Error::CameraServiceUnavailable(_)) => { + Ok(neolink_core::Error::CameraServiceUnavailable{..}) => { log::debug!("Battery not supported"); futures::future::pending().await },