Add talk to neolink_core
This commit is contained in:
6 files changed
+230
-2
No files matched your search
@@ -20,6 +20,10 @@ pub const MSG_ID_PING: u32 = 93;
|
||||
pub const MSG_ID_GET_GENERAL: u32 = 104;
|
||||
/// Setting general system info (clock mostly) messages have this ID
|
||||
pub const MSG_ID_SET_GENERAL: u32 = 105;
|
||||
/// Will send the talk config for talk back data to follow this msg
|
||||
pub const MSG_ID_TALKCONFIG: u32 = 201;
|
||||
/// Used to send talk back binary data
|
||||
pub const MSG_ID_TALK: u32 = 202;
|
||||
/// Getting the LED status is done with this ID
|
||||
pub const MSG_ID_GET_LED_STATUS: u32 = 208;
|
||||
/// Setting the LED status is done with this ID
|
||||
|
||||
@@ -60,6 +60,9 @@ pub struct BcXml {
|
||||
/// Received as part of the LEDState info request
|
||||
#[yaserde(rename = "LedState")]
|
||||
pub led_state: Option<LedState>,
|
||||
/// Sent as part of the TalkConfig to prepare the camera for audio talk-back
|
||||
#[yaserde(rename = "TalkConfig")]
|
||||
pub talk_config: Option<TalkConfig>,
|
||||
}
|
||||
|
||||
impl BcXml {
|
||||
@@ -285,7 +288,7 @@ pub struct LedState {
|
||||
pub version: String,
|
||||
/// Channel ID of camera to get/set its LED state
|
||||
#[yaserde(rename = "channelId")]
|
||||
pub channel_id: u32,
|
||||
pub channel_id: u8,
|
||||
/// LED Version, observed value is "2". Should be None when setting the LedState
|
||||
#[yaserde(rename = "ledVersion")]
|
||||
pub led_version: Option<u32>,
|
||||
@@ -296,6 +299,49 @@ pub struct LedState {
|
||||
pub light_state: String,
|
||||
}
|
||||
|
||||
/// TalkConfig xml
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct TalkConfig {
|
||||
/// XML Version
|
||||
#[yaserde(attribute)]
|
||||
pub version: String,
|
||||
/// Channel ID of camera to set the TalkConfig
|
||||
#[yaserde(rename = "channelId")]
|
||||
pub channel_id: u8,
|
||||
/// Duplex known values `"FDX"`
|
||||
pub duplex: String,
|
||||
/// audioStreamMode known values `"followVideoStream"`
|
||||
#[yaserde(rename = "audioStreamMode")]
|
||||
pub audio_stream_mode: String,
|
||||
/// AudioConfig contans the details of the audio to follow
|
||||
pub audio_config: AudioConfig,
|
||||
}
|
||||
|
||||
/// audioConfig xml
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
#[yaserde(rename = "audioConfig")]
|
||||
pub struct AudioConfig {
|
||||
/// Audio type known values are `"adpcm"`
|
||||
///
|
||||
/// Do not expect camera to support anything else.
|
||||
#[yaserde(rename = "audioType")]
|
||||
pub audio_type: String,
|
||||
/// Audio sample rate known values are `16000`
|
||||
#[yaserde(rename = "sampleRate")]
|
||||
pub sample_rate: u16,
|
||||
/// Precision of data known vaues are `16` (i.e. 16bit)
|
||||
#[yaserde(rename = "samplePrecision")]
|
||||
pub sample_precision: u16,
|
||||
/// Number of audio samples this should be twice the block size for adpcm
|
||||
#[yaserde(rename = "lengthPerEncoder")]
|
||||
pub length_per_encoder: u16,
|
||||
/// Sound track is the number of tracks known values are `"mono"`
|
||||
///
|
||||
/// Do not expect camera to support anything else
|
||||
#[yaserde(rename = "soundTrack")]
|
||||
pub soundTrack: String,
|
||||
}
|
||||
|
||||
/// Convience function to return the xml version used throughout the library
|
||||
pub fn xml_ver() -> String {
|
||||
"1.1".to_string()
|
||||
|
||||
@@ -17,6 +17,7 @@ mod logout;
|
||||
mod ping;
|
||||
mod reboot;
|
||||
mod stream;
|
||||
mod talk;
|
||||
mod time;
|
||||
mod version;
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
use super::{BcCamera, Error, Result, RX_TIMEOUT};
|
||||
use crate::{bc::model::*, bc::xml::*, bcmedia::model::*};
|
||||
|
||||
impl BcCamera {
|
||||
///
|
||||
/// Send sound to the camera
|
||||
///
|
||||
/// long description
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// * `adpcm` - Data must be adpcm in DVI-4 format
|
||||
///
|
||||
/// * `block_size` - is block-align used to encode the adpcm
|
||||
///
|
||||
/// * `sample_rate` - sample rate of the audio
|
||||
///
|
||||
///
|
||||
pub fn talk(&self, adpcm: &[u8], block_size: u16, sample_rate: u16) -> Result<()> {
|
||||
let connection = self.connection.as_ref().expect("Must be connected to ping");
|
||||
|
||||
let sub = connection.subscribe(MSG_ID_TALKCONFIG)?;
|
||||
|
||||
let talk_config = TalkConfig {
|
||||
channel_id: self.channel_id,
|
||||
duplex: "FDX".to_string(),
|
||||
audio_stream_mode: "followVideoStream".to_string(),
|
||||
audio_config: AudioConfig {
|
||||
audio_type: "adpcm".to_string(),
|
||||
sample_rate,
|
||||
sample_precision: 16,
|
||||
length_per_encoder: block_size * 2,
|
||||
soundTrack: "mono".to_string(),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let msg = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_TALKCONFIG,
|
||||
channel_id: self.channel_id,
|
||||
msg_num: self.new_message_num(),
|
||||
stream_type: 0,
|
||||
response_code: 0,
|
||||
class: 0x6414,
|
||||
},
|
||||
body: BcBody::ModernMsg(ModernMsg {
|
||||
extension: Some(Extension {
|
||||
channel_id: Some(self.channel_id),
|
||||
..Default::default()
|
||||
}),
|
||||
payload: Some(BcPayloads::BcXml(BcXml {
|
||||
talk_config: Some(talk_config),
|
||||
..Default::default()
|
||||
})),
|
||||
}),
|
||||
};
|
||||
|
||||
sub.send(msg)?;
|
||||
let msg = sub.rx.recv_timeout(RX_TIMEOUT)?;
|
||||
|
||||
if let BcMeta {
|
||||
response_code: 200, ..
|
||||
} = msg.meta
|
||||
{
|
||||
} else {
|
||||
return Err(Error::UnintelligibleReply {
|
||||
reply: msg,
|
||||
why: "The camera did not except the TalkConfig xml",
|
||||
});
|
||||
}
|
||||
|
||||
let full_block_size = block_size + 4; // Block size + predictor state
|
||||
let sub = connection.subscribe(MSG_ID_TALK)?;
|
||||
|
||||
for bytes in adpcm.chunks(full_block_size as usize) {
|
||||
let bcmedia_adpcm = BcMedia::Adpcm(BcMediaAdpcm {
|
||||
data: bytes.to_vec(),
|
||||
});
|
||||
let bcmedia_adpcm_data = bcmedia_adpcm.serialize(vec![])?;
|
||||
|
||||
let msg = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_TALK,
|
||||
channel_id: self.channel_id,
|
||||
msg_num: self.new_message_num(),
|
||||
stream_type: 0,
|
||||
response_code: 0,
|
||||
class: 0x6414,
|
||||
},
|
||||
body: BcBody::ModernMsg(ModernMsg {
|
||||
extension: Some(Extension {
|
||||
channel_id: Some(self.channel_id),
|
||||
binary_data: Some(1),
|
||||
..Default::default()
|
||||
}),
|
||||
payload: Some(BcPayloads::Binary(bcmedia_adpcm_data)),
|
||||
}),
|
||||
};
|
||||
|
||||
sub.send(msg)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl BcMedia {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn serialize<W: Write>(&self, buf: W) -> Result<W, Error> {
|
||||
let (buf, _) = match &self {
|
||||
BcMedia::InfoV1(payload) => gen(bcmedia_info_v1(payload), buf)?,
|
||||
|
||||
@@ -2087,6 +2087,78 @@ a PR to improve it.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 201: `<TalkConfig>`
|
||||
|
||||
- Client
|
||||
|
||||
- Header
|
||||
|
||||
| Magic | Message ID | Message Length | Encryption Offset | Status Code | Message Class | Binary Offset |
|
||||
|--------------|--------------|----------------|-------------------|-------------------|---------------|---------------|
|
||||
| 0a bc de f0 | 00 00 00 c9 | 00 00 01 f2 | 12 00 00 00 | 00 00 | 64 14 | 00 00 00 68 |
|
||||
|
||||
- Body
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<channelId>0</channelId>
|
||||
</Extension>
|
||||
```
|
||||
|
||||
- Binary
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<TalkConfig version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<duplex>FDX</duplex>
|
||||
<audioStreamMode>followVideoStream</audioStreamMode>
|
||||
<audioConfig>
|
||||
<audioType>adpcm</audioType>
|
||||
<sampleRate>16000</sampleRate>
|
||||
<samplePrecision>16</samplePrecision>
|
||||
<lengthPerEncoder>1024</lengthPerEncoder>
|
||||
<soundTrack>mono</soundTrack>
|
||||
</audioConfig>
|
||||
</TalkConfig>
|
||||
</body>
|
||||
```
|
||||
|
||||
- Camera
|
||||
|
||||
- Header
|
||||
|
||||
| Magic | Message ID | Message Length | Encryption Offset | Status Code | Message Class | Binary Offset |
|
||||
|--------------|--------------|----------------|-------------------|-------------------|---------------|---------------|
|
||||
| 0a bc de f0 | 00 00 00 c9 | 00 00 00 00 | 12 00 00 00 | c8 00 | 00 00 | 00 00 00 00 |
|
||||
|
||||
- 202: `Talk`
|
||||
|
||||
- Client
|
||||
|
||||
- Header
|
||||
|
||||
| Magic | Message ID | Message Length | Encryption Offset | Status Code | Message Class | Binary Offset |
|
||||
|--------------|--------------|----------------|-------------------|-------------------|---------------|---------------|
|
||||
| 0a bc de f0 | 00 00 00 ca | 00 00 08 c3 | 00 00 00 00 | 00 00 | 64 14 | 00 00 00 83 |
|
||||
|
||||
- Body
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Extension version="1.1">
|
||||
<binaryData>1</binaryData>
|
||||
<channelId>0</channelId>
|
||||
</Extension>
|
||||
```
|
||||
|
||||
- Binary
|
||||
|
||||
Binary data contains media-packets of adpcm data
|
||||
|
||||
|
||||
**Notes**: No reply from camera. After this the client keeps sending this packet with binary in the BcMedia encoded packets of adpcm data
|
||||
|
||||
- 208: `<LedState>`
|
||||
|
||||
- Client
|
||||
|
||||
Reference in new issue
Block a user