viva_camctl/
cmd_chunks.rs1use std::net::Ipv4Addr;
2use std::time::Duration;
3
4use anyhow::{Context, Result};
5use serde::Serialize;
6use tracing::info;
7
8use viva_gige::nic::IfaceSelector;
9
10use crate::common::{self, DEFAULT_DISCOVERY_TIMEOUT_MS};
11
12#[derive(Serialize)]
13struct ChunkStatus {
14 active: bool,
15 selectors: Vec<String>,
16}
17
18fn parse_selectors(csv: &str) -> Vec<String> {
19 csv.split(',')
20 .map(|entry| entry.trim())
21 .filter(|entry| !entry.is_empty())
22 .map(|entry| entry.to_string())
23 .collect()
24}
25
26pub async fn run(
27 ip: Option<Ipv4Addr>,
28 index: Option<usize>,
29 enable: bool,
30 selectors: String,
31 iface: Option<IfaceSelector>,
32 json: bool,
33) -> Result<()> {
34 let selected = parse_selectors(&selectors);
35 let timeout = Duration::from_millis(DEFAULT_DISCOVERY_TIMEOUT_MS);
36 let device = common::select_device(ip, index, iface.as_ref(), timeout).await?;
37 info!(ip = %device.ip, enable, "configuring chunk mode");
38 let mut camera = common::open_camera(&device)
39 .await
40 .context("open camera for chunk configuration")?;
41
42 let cfg: viva_genicam::ChunkConfig = viva_genicam::ChunkConfig {
43 selectors: selected.clone(),
44 active: enable,
45 };
46 camera
47 .configure_chunks(&cfg)
48 .context("enable/disable chunk selectors")?;
49
50 if json {
51 let status = ChunkStatus {
52 active: enable,
53 selectors: selected.clone(),
54 };
55 common::print_json(&status)?;
56 } else {
57 let summary = if selected.is_empty() {
58 "no selectors".to_string()
59 } else {
60 selected.join(", ")
61 };
62 println!(
63 "Chunk mode {} ({})",
64 if enable { "enabled" } else { "disabled" },
65 summary
66 );
67 }
68
69 Ok(())
70}