chore: clean up restore payload generation

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-10-15 08:41:37 +01:00
parent 913ca06512
commit 2e9fb61762
3 changed files with 10 additions and 17 deletions

1
Cargo.lock generated
View File

@@ -237,6 +237,7 @@ name = "fujicli"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"byteorder",
"clap", "clap",
"libptp", "libptp",
"log", "log",

View File

@@ -15,6 +15,7 @@ codegen-units = 1
[dependencies] [dependencies]
anyhow = "1.0.100" anyhow = "1.0.100"
byteorder = "1.5.0"
clap = { version = "4.5.48", features = ["derive", "wrap_help"] } clap = { version = "4.5.48", features = ["derive", "wrap_help"] }
libptp = "0.6.5" libptp = "0.6.5"
log = "0.4.28" log = "0.4.28"

View File

@@ -1,10 +1,12 @@
use std::{ use std::{
fmt, fmt,
io::Cursor,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
time::Duration, time::Duration,
}; };
use anyhow::bail; use anyhow::bail;
use byteorder::{LittleEndian, WriteBytesExt};
use libptp::{DeviceInfo, StandardCommandCode}; use libptp::{DeviceInfo, StandardCommandCode};
use log::{debug, error}; use log::{debug, error};
use rusb::{DeviceDescriptor, GlobalContext}; use rusb::{DeviceDescriptor, GlobalContext};
@@ -280,29 +282,18 @@ pub trait CameraImpl {
debug!("Preparing ObjectInfo header for backup"); debug!("Preparing ObjectInfo header for backup");
let mut obj_info = vec![0u8; 1088]; let mut obj_info = vec![0u8; 1088];
let mut offset = 0;
let padding0: u32 = 0x0; let mut cursor = Cursor::new(&mut obj_info[..]);
let object_format: u16 = 0x5000; cursor.write_u32::<LittleEndian>(0x0)?;
let padding1: u16 = 0x0; cursor.write_u16::<LittleEndian>(0x5000)?;
cursor.write_u16::<LittleEndian>(0x0)?;
obj_info[offset..offset + size_of::<u32>()].copy_from_slice(&padding0.to_le_bytes()); cursor.write_u32::<LittleEndian>(u32::try_from(buffer.len())?)?;
offset += size_of::<u32>();
obj_info[offset..offset + size_of::<u16>()].copy_from_slice(&object_format.to_le_bytes());
offset += size_of::<u16>();
obj_info[offset..offset + size_of::<u16>()].copy_from_slice(&padding1.to_le_bytes());
offset += size_of::<u16>();
obj_info[offset..offset + size_of::<u32>()]
.copy_from_slice(&u32::try_from(buffer.len())?.to_le_bytes());
let param0: u32 = 0x0;
let param1: u32 = 0x0;
debug!("Sending ObjectInfo for backup"); debug!("Sending ObjectInfo for backup");
ptp.command( ptp.command(
libptp::StandardCommandCode::SendObjectInfo, libptp::StandardCommandCode::SendObjectInfo,
&[param0, param1], &[0x0, 0x0],
Some(&obj_info), Some(&obj_info),
Some(TIMEOUT), Some(TIMEOUT),
)?; )?;