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/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")] 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)?; 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; diff --git a/src/main.rs b/src/main.rs index 1ee8a39..8214b49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -260,5 +260,23 @@ fn do_camera_management( ); } } + + use neolink::bc::xml::VersionInfo; + if let Ok(VersionInfo { + firmwareVersion: firmware_version, + .. + }) = camera.version() + { + info!( + "{}: Camera reports firmware version {}", + camera_config.name, firmware_version + ); + } else { + info!( + "{}: Could not fetch version information", + camera_config.name + ); + } + Ok(()) }