use super::opcode::{Sub, PTP_OC_CHDK};
use crate::ptp::{DataPhase, PtpSession};
use crate::Result;
impl PtpSession {
pub async fn chdk_temp_data(&mut self, data: &[u8]) -> Result<()> {
let resp = self
.command(
PTP_OC_CHDK,
&[Sub::TempData.as_u32(), 0],
DataPhase::Out(data),
)
.await?;
resp.ok()
}
pub async fn upload_file(&mut self, camera_path: &str, contents: &[u8]) -> Result<()> {
let path_bytes = camera_path.as_bytes();
let mut payload = Vec::with_capacity(4 + path_bytes.len() + contents.len());
payload.extend_from_slice(&(path_bytes.len() as u32).to_le_bytes());
payload.extend_from_slice(path_bytes);
payload.extend_from_slice(contents);
let resp = self
.command(
PTP_OC_CHDK,
&[Sub::UploadFile.as_u32()],
DataPhase::Out(&payload),
)
.await?;
resp.ok()
}
pub async fn download_file(&mut self, camera_path: &str) -> Result<Vec<u8>> {
self.chdk_temp_data(camera_path.as_bytes()).await?;
let resp = self
.command(
PTP_OC_CHDK,
&[Sub::DownloadFile.as_u32()],
DataPhase::In,
)
.await?;
resp.ok()?;
Ok(resp.data)
}
}