Add methods to get current zoom and its limits
This commit is contained in:
5 files changed
+121
-13
No files matched your search
@@ -77,8 +77,10 @@ pub const MSG_ID_FLOODLIGHT_MANUAL: u32 = 288;
|
||||
pub const MSG_ID_FLOODLIGHT_TASKS_WRITE: u32 = 290;
|
||||
/// Floodlight status report from the camera
|
||||
pub const MSG_ID_FLOODLIGHT_STATUS_LIST: u32 = 291;
|
||||
/// Used for camera Zoom
|
||||
pub const MSG_ID_ZOOM_FOCUS: u32 = 295;
|
||||
/// Used for camera Zoom read
|
||||
pub const MSG_ID_GET_ZOOM_FOCUS: u32 = 294;
|
||||
/// Used for camera Zoom write
|
||||
pub const MSG_ID_SET_ZOOM_FOCUS: u32 = 295;
|
||||
/// Get the floodlight task xml
|
||||
pub const MSG_ID_FLOODLIGHT_TASKS_READ: u32 = 438;
|
||||
|
||||
|
||||
@@ -984,11 +984,29 @@ pub struct StartZoomFocus {
|
||||
/// Channel ID
|
||||
#[yaserde(rename = "channelId")]
|
||||
pub channel_id: u8,
|
||||
/// Command: Observed values: zoomPos
|
||||
pub command: String,
|
||||
/// Target Position: Observed Values: 2994, 2508, 2888, 3089, 3194, 3163
|
||||
/// Command: Observed values: zoomPos. (Write Only)
|
||||
pub command: Option<String>,
|
||||
/// Target Position: Observed Values: 2994, 2508, 2888, 3089, 3194, 3163. (Write Only)
|
||||
#[yaserde(rename = "movePos")]
|
||||
pub move_pos: u32,
|
||||
pub move_pos: Option<u32>,
|
||||
/// Max, min and current zoom. (Read Only)
|
||||
pub zoom: Option<HelperPosition>,
|
||||
/// Max, min and current focus. (Read Only)
|
||||
pub focus: Option<HelperPosition>,
|
||||
}
|
||||
|
||||
/// Helper for Max, Min, Curr pos of zoom/focus
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct HelperPosition {
|
||||
/// Max value
|
||||
#[yaserde(rename = "maxPos")]
|
||||
pub maxPos: u32,
|
||||
/// Min value
|
||||
#[yaserde(rename = "minPos")]
|
||||
pub minPos: u32,
|
||||
/// Curr value
|
||||
#[yaserde(rename = "curPos")]
|
||||
pub curPos: u32,
|
||||
}
|
||||
|
||||
/// Support xml
|
||||
|
||||
@@ -237,15 +237,23 @@ impl BcCamera {
|
||||
}
|
||||
|
||||
/// The camera will zoom to a given zoom amount.
|
||||
/// Not sure what the units for this are. Or how to get the min/max values
|
||||
pub async fn zoom_to(&self, zoom_pos: u32) -> Result<()> {
|
||||
/// Not sure what the units for this are, seems to be 1000 is 1x and 2000 is 2x
|
||||
pub async fn zoom_to(&self, in_zoom_pos: u32) -> Result<()> {
|
||||
let current = self.get_zoom().await?;
|
||||
let zoom_pos;
|
||||
if let Some(zoom) = current.zoom {
|
||||
zoom_pos = in_zoom_pos.clamp(zoom.minPos, zoom.maxPos);
|
||||
} else {
|
||||
zoom_pos = in_zoom_pos;
|
||||
}
|
||||
|
||||
self.has_ability_rw("control").await?;
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_set = connection.subscribe(MSG_ID_ZOOM_FOCUS, msg_num).await?;
|
||||
let mut sub_set = connection.subscribe(MSG_ID_SET_ZOOM_FOCUS, msg_num).await?;
|
||||
let send = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_ZOOM_FOCUS,
|
||||
msg_id: MSG_ID_SET_ZOOM_FOCUS,
|
||||
channel_id: self.channel_id,
|
||||
msg_num,
|
||||
response_code: 0,
|
||||
@@ -262,8 +270,9 @@ impl BcCamera {
|
||||
start_zoom_focus: Some(StartZoomFocus {
|
||||
version: xml_ver(),
|
||||
channel_id: self.channel_id,
|
||||
command: "zoomPos".to_string(),
|
||||
move_pos: zoom_pos,
|
||||
command: Some("zoomPos".to_string()),
|
||||
move_pos: Some(zoom_pos),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
@@ -286,4 +295,52 @@ impl BcCamera {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the zoom xml, that has current min and max zoom values
|
||||
pub async fn get_zoom(&self) -> Result<StartZoomFocus> {
|
||||
self.has_ability_ro("control").await?;
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_get = connection.subscribe(MSG_ID_GET_ZOOM_FOCUS, msg_num).await?;
|
||||
let get = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_GET_ZOOM_FOCUS,
|
||||
channel_id: self.channel_id,
|
||||
msg_num,
|
||||
response_code: 0,
|
||||
stream_type: 0,
|
||||
class: 0x6414,
|
||||
},
|
||||
body: BcBody::ModernMsg(ModernMsg {
|
||||
extension: Some(Extension {
|
||||
channel_id: Some(self.channel_id),
|
||||
..Default::default()
|
||||
}),
|
||||
payload: None,
|
||||
}),
|
||||
};
|
||||
|
||||
sub_get.send(get).await?;
|
||||
let msg = sub_get.recv().await?;
|
||||
if msg.meta.response_code != 200 {
|
||||
return Err(Error::CameraServiceUnavaliable(msg.meta.response_code));
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
payload:
|
||||
Some(BcPayloads::BcXml(BcXml {
|
||||
start_zoom_focus: Some(xml),
|
||||
..
|
||||
})),
|
||||
..
|
||||
}) = msg.body
|
||||
{
|
||||
Ok(xml)
|
||||
} else {
|
||||
Err(Error::UnintelligibleReply {
|
||||
reply: std::sync::Arc::new(Box::new(msg)),
|
||||
why: "Expected StartZoomFocus xml but it was not recieved",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,8 @@ local message_types = {
|
||||
[273]="<alarmVideoInfo>",
|
||||
[274]="<findAlarmVideo>",
|
||||
[291]="<FloodlightStatusList>",
|
||||
[294]="<StartZoomFocus> (read)",
|
||||
[295]="<StartZoomFocus> (write)",
|
||||
[299]="<AiCfg>",
|
||||
[319]="<timelapseCfg>",
|
||||
[342]="<AiDetectCfg>",
|
||||
|
||||
+30
-1
@@ -2968,7 +2968,36 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 295: `<StartZoomFocus>`
|
||||
- 294: `<StartZoomFocus>` (Read)
|
||||
|
||||
- Client: Standard header and channel extension
|
||||
|
||||
- Camera:
|
||||
|
||||
Usual header and Extension XML with channel
|
||||
|
||||
- Payload:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<PtzZoomFocus version="1.1">
|
||||
<channelId>1</channelId>
|
||||
<zoom>
|
||||
<maxPos>6000</maxPos>
|
||||
<minPos>1000</minPos>
|
||||
<curPos>2501</curPos>
|
||||
</zoom>
|
||||
<focus>
|
||||
<maxPos>100</maxPos>
|
||||
<minPos>1</minPos>
|
||||
<curPos>51</curPos>
|
||||
</focus>
|
||||
</PtzZoomFocus>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 295: `<StartZoomFocus>` (Write)
|
||||
|
||||
- Client
|
||||
|
||||
|
||||
Reference in new issue
Block a user