# km003c-lib
Async USB communication and protocol parsing for the ChargerLAB POWER-Z
KM003C USB-C power analyzer.
The crate supports single-shot ADC measurements, authenticated AdcQueue
streaming at 2/10/50/1000 SPS, USB Power Delivery event capture, device
information, and recorded-packet parsing. Physical measurements use
[`uom`](https://docs.rs/uom) quantities throughout the Rust API.
Offline recordings are exposed as a catalog of typed `LogMetadata` entries.
`KM003C::download_offline_log()` selects the correct flash offset, validates
the final charge and energy accumulators, and returns typed `uom` samples.
Normal vendor initialization authenticates with the device HardwareID at
level 1. `KM003C::authenticate_calibration()` safely reads the firmware-selected
calibration credential and requests level 2 without writing device memory.
`KM003C::request_settings()` validates both persisted settings-block checksums
and exposes only firmware-confirmed fields semantically. Unknown bytes remain
available through the lossless raw block accessors; the API does not provide
settings writes.
Enable the optional `usbpd` feature to turn captured PD wire frames into typed
USB PD messages. `PdSessionDecoder` retains Source Capabilities state for
subsequent Request messages and reassembles chunked EPR Source Capabilities.
Firmware Type-C and protocol-engine traces are available separately as a typed
`PdTrace` containing `PdTraceStateEvent` and `PdTraceProtocolEvent` values.
Unknown codes remain available losslessly for firmware variants that have not
yet been reverse engineered.
```rust,no_run
use km003c_lib::uom::si::electric_potential::volt;
use km003c_lib::{DeviceConfig, KM003C};
# async fn read_voltage() -> Result<(), Box<dyn std::error::Error>> {
let mut device = KM003C::new(DeviceConfig::vendor()).await?;
let adc = device.request_adc_data().await?;
println!("VBUS: {:.3} V", adc.vbus.get::<volt>());
# Ok(())
# }
```
See the [project repository](https://github.com/okhsunrog/km003c-rs) for the
CLI tools, GUI monitor, USB permissions, Python bindings, and protocol
research links.
## License
Licensed under either the Apache License, Version 2.0 or the MIT license, at
your option.