From e00ed786acbad9f149f2ca4d35b6af29cd5a3c87 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 20 Dec 2020 01:16:18 -0600 Subject: [PATCH 1/5] bc: add VersionInfo --- src/bc/xml.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bc/xml.rs b/src/bc/xml.rs index 727ae68..7c46dc0 100644 --- a/src/bc/xml.rs +++ b/src/bc/xml.rs @@ -35,6 +35,8 @@ pub struct BcXml { pub login_net: Option, #[yaserde(rename = "DeviceInfo")] pub device_info: Option, + #[yaserde(rename = "VersionInfo")] + pub version_info: Option, #[yaserde(rename = "Preview")] pub preview: Option, #[yaserde(rename = "SystemGeneral")] @@ -103,6 +105,17 @@ pub struct DeviceInfo { pub resolution: Resolution, } +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct VersionInfo { + pub name: String, + pub serialNumber: String, + pub buildDay: String, + pub hardwareVersion: String, + pub cfgVersion: String, + pub firmwareVersion: String, + pub detail: String, +} + #[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] pub struct Resolution { #[yaserde(rename = "resolutionName")] From ce8c2d3648d85a9e36ba220ddd510a610471d4da Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 20 Dec 2020 01:17:33 -0600 Subject: [PATCH 2/5] BcCamera: add a version() function for VersionInfo --- src/bc/model.rs | 1 + src/bc_protocol.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/bc/model.rs b/src/bc/model.rs index 9ddc4e8..bedea12 100644 --- a/src/bc/model.rs +++ b/src/bc/model.rs @@ -5,6 +5,7 @@ pub(super) const MAGIC_HEADER: u32 = 0xabcdef0; pub const MSG_ID_LOGIN: u32 = 1; pub const MSG_ID_VIDEO: u32 = 3; +pub const MSG_ID_VERSION: u32 = 80; pub const MSG_ID_PING: u32 = 93; pub const MSG_ID_GET_GENERAL: u32 = 104; pub const MSG_ID_SET_GENERAL: u32 = 105; diff --git a/src/bc_protocol.rs b/src/bc_protocol.rs index ec5e737..0ca9222 100644 --- a/src/bc_protocol.rs +++ b/src/bc_protocol.rs @@ -250,6 +250,51 @@ impl BcCamera { Ok(()) } + pub fn version(&self) -> Result { + let connection = self + .connection + .as_ref() + .expect("Must be connected to get version info"); + let sub_version = connection.subscribe(MSG_ID_VERSION)?; + + let version = Bc { + meta: BcMeta { + msg_id: MSG_ID_VERSION, + client_idx: 0, + encrypted: true, + class: 0x6414, + }, + body: BcBody::ModernMsg(ModernMsg { + ..Default::default() + }), + }; + + sub_version.send(version)?; + + let modern_reply = sub_version.rx.recv_timeout(RX_TIMEOUT)?; + let version_info; + match modern_reply.body { + BcBody::ModernMsg(ModernMsg { + xml: + Some(BcXml { + version_info: Some(info), + .. + }), + .. + }) => { + version_info = info; + } + _ => { + return Err(Error::UnintelligibleReply { + reply: modern_reply, + why: "Expected a VersionInfo message", + }) + } + } + + Ok(version_info) + } + pub fn ping(&self) -> Result<()> { let connection = self.connection.as_ref().expect("Must be connected to ping"); let sub_ping = connection.subscribe(MSG_ID_PING)?; From 6a432b30ad46786a408164e9058386e580f50870 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sun, 20 Dec 2020 01:19:20 -0600 Subject: [PATCH 3/5] main: report camera firmware version --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.rs b/src/main.rs index 1ee8a39..a80ad38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -260,5 +260,20 @@ fn do_camera_management( ); } } + + let version_info = camera.version(); + if version_info.is_ok() { + info!( + "{}: Camera reports firmware version {}", + camera_config.name, + version_info.unwrap().firmwareVersion + ); + } else { + info!( + "{}: Could not fetch version information", + camera_config.name + ); + } + Ok(()) } From a91979d2b6b442b9afe10227c7e9e4eb507fb985 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Sun, 20 Dec 2020 19:37:49 -0600 Subject: [PATCH 4/5] Allow older version of Rust to build adpcm --- src/bc_protocol/adpcm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bc_protocol/adpcm.rs b/src/bc_protocol/adpcm.rs index e8b8793..a42b0cd 100644 --- a/src/bc_protocol/adpcm.rs +++ b/src/bc_protocol/adpcm.rs @@ -225,7 +225,7 @@ pub fn adpcm_to_pcm(bytes: &[u8]) -> Result, Error> { // Some formats e.g. OKI are not in the full PCM range of values // To convert we must scale it to the i16 range // We also cast to i16 at this point ready for the conversion to u8 bytes of the output - let scaled_sample = (sample as i32 * (i16::MAX as i32) + let scaled_sample = (sample as i32 * (std::i16::MAX as i32) / (context.max_sample_size - 1) as i32) as i16; From ae86407483f7cf07c5a30b2b13491d0084bb4a3c Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Sun, 20 Dec 2020 19:54:31 -0600 Subject: [PATCH 5/5] Don't unwrap while checking camera version --- src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index a80ad38..8214b49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,12 +261,15 @@ fn do_camera_management( } } - let version_info = camera.version(); - if version_info.is_ok() { + use neolink::bc::xml::VersionInfo; + if let Ok(VersionInfo { + firmwareVersion: firmware_version, + .. + }) = camera.version() + { info!( "{}: Camera reports firmware version {}", - camera_config.name, - version_info.unwrap().firmwareVersion + camera_config.name, firmware_version ); } else { info!(