Skip to content

Commit

Permalink
fp-stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocolateLoverRaj committed Jun 5, 2024
1 parent 4bfb52f commit 2808fdb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions crosec/src/commands/fp_stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::ffi::c_int;

use bytemuck::{Pod, Zeroable};

use crate::{ec_command::ec_command_bytemuck, EcCmdResult};

use super::CrosEcCmd;

#[repr(C, packed)]
#[derive(Pod, Zeroable, Clone, Copy, Debug)]
pub struct EcResponseFpStats {
pub capture_time_us: u32,
pub matching_time_us: u32,
pub overall_time_us: u32,
pub overall_t0: OverallT0,
pub timestamps_invalid: u8,
pub template_matched: i8,
}

#[repr(C, packed)]
#[derive(Pod, Zeroable, Clone, Copy, Debug)]
pub struct OverallT0 {
pub lo: u32,
pub hi: u32,
}

pub fn fp_stats(fd: c_int) -> EcCmdResult<EcResponseFpStats> {
ec_command_bytemuck(CrosEcCmd::FpStats, 0, &(), fd)
}
2 changes: 2 additions & 0 deletions crosec/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ pub enum CrosEcCmd {
ConsoleSnapshot = 0x0097,
ConsoleRead = 0x0098,
FpInfo = 0x0403,
FpStats = 0x0407,
BatteryGetStatic = 0x0600,
}

pub mod board_version;
pub mod charge_control;
pub mod fp_info;
pub mod fp_stats;
pub mod get_chip_info;
pub mod get_cmd_versions;
pub mod get_features;
Expand Down
8 changes: 8 additions & 0 deletions ectool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::os::fd::AsRawFd;
use clap::{Parser, Subcommand, ValueEnum};
use color_eyre::eyre::Result;
use crosec::commands::fp_info::fp_info;
use crosec::commands::fp_stats::fp_stats;
use crosec::commands::get_protocol_info::get_protocol_info;
use num_traits::cast::FromPrimitive;

Expand Down Expand Up @@ -90,6 +91,7 @@ enum Commands {
command: Option<ChargeControlSubcommands>,
},
FpInfo,
FpStats,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -272,6 +274,12 @@ fn main() -> Result<()> {
let info = fp_info(fd)?;
println!("{info:#?}");
}
Commands::FpStats => {
let file = File::open(CROS_FP_PATH).unwrap();
let fd = file.as_raw_fd();
let stats = fp_stats(fd)?;
println!("{stats:#?}");
}
}

Ok(())
Expand Down

0 comments on commit 2808fdb

Please sign in to comment.