Skip to main content

Packet

Enum Packet 

Source
pub enum Packet {
Show 15 variants DataResponse { payloads: Vec<PayloadData>, }, GetData { attributes: AttributeSet, }, StartGraph { rate: GraphSampleRate, }, StopGraph, Accept { id: u8, }, Reject { id: u8, }, NotReadable { id: u8, }, Connect, Disconnect, EnablePdMonitor, DisablePdMonitor, MemoryRead { address: u32, size: u32, }, StreamingAuth { credential: AuthCredential, }, StreamingAuthResponse(StreamingAuthResult), Generic(RawPacket),
}

Variants§

§

DataResponse

Data response with parsed payload data

Fields

§payloads: Vec<PayloadData>
§

GetData

Request data with attribute set

Fields

§attributes: AttributeSet
§

StartGraph

Start AdcQueue graph mode with sample rate.

CtrlHeader places the logical rate index (0=2SPS, 1=10SPS, 2=50SPS, 3=1000SPS) in the wire header, producing byte 2 values 0, 2, 4, and 6 respectively. A header carrying an index outside that range parses as Packet::Generic rather than being coerced into a known rate.

Fields

§

StopGraph

Stop AdcQueue graph mode

§

Accept

Accept response

Fields

§id: u8
§

Reject

Reject response

Fields

§id: u8
§

NotReadable

NotReadable response - memory address not accessible

Fields

§id: u8
§

Connect

Connect command

§

Disconnect

Disconnect command

§

EnablePdMonitor

Enable PD monitor/sniffer

§

DisablePdMonitor

Disable PD monitor/sniffer

§

MemoryRead

MemoryRead command (0x44) - read device memory with encrypted payload

Fields

§address: u32

Memory address to read from

§size: u32

Number of bytes to read

§

StreamingAuth

StreamingAuth command (0x4C) - authenticate for AdcQueue streaming

Fields

§credential: AuthCredential

Device or calibration credential to authenticate with

§

StreamingAuthResponse(StreamingAuthResult)

StreamingAuth response (0x4C) - authentication result

§

Generic(RawPacket)

Generic packet for types we haven’t specifically implemented yet

Implementations§

Source§

impl Packet

Source

pub fn find_payload<'a, T: ?Sized>( &'a self, select: impl Fn(&'a PayloadData) -> Option<&'a T>, ) -> Option<&'a T>

Return the first payload for which select yields a value.

Only Packet::DataResponse carries payloads; every other variant yields None.

Source

pub fn get_adc(&self) -> Option<&AdcDataSimple>

Get ADC data from the packet, if present.

Source

pub fn get_adc_queue(&self) -> Option<&AdcQueueData>

Get AdcQueue data from the packet, if present.

Examples found in repository?
examples/calibration_auth.rs (line 23)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let initial_level = device.state().map(|state| state.auth_level).unwrap_or(0);
9    println!("Initial authentication level: {initial_level}");
10
11    let result = device.authenticate_calibration().await?;
12    println!(
13        "Calibration authentication level: {} (attribute 0x{:04x})",
14        result.auth_level, result.attribute
15    );
16
17    device.start_graph_mode(GraphSampleRate::Sps50).await?;
18    tokio::time::sleep(Duration::from_millis(200)).await;
19    let response = device.request_data(AttributeSet::single(Attribute::AdcQueue)).await;
20    device.stop_graph_mode().await?;
21
22    let response = response?;
23    let samples = response.get_adc_queue().map(|queue| queue.samples.len()).unwrap_or(0);
24    println!("AdcQueue samples received after level-2 auth: {samples}");
25
26    Ok(())
27}
Source

pub fn get_adc_queue_raw(&self) -> Option<&AdcQueueRawData>

Get losslessly parsed AdcQueue data whose graph rate is unknown.

Source

pub fn get_pd_status(&self) -> Option<&PdStatus>

Get PD status from the packet, if present.

Source

pub fn get_pd_events(&self) -> Option<&PdEventStream>

Get PD events from the packet, if present.

Source

pub fn get_pd_trace(&self) -> Option<&PdTrace>

Get the internal PD state-machine trace, if present.

Source

pub fn get_settings(&self) -> Option<&Settings>

Get the read-only settings payload, if present.

Source

pub fn get_log_metadata(&self) -> Option<&LogMetadataResponse>

Get the response to a LogMetadata request, if present.

Source

pub fn has_payload(&self, attr: Attribute) -> bool

Check if packet has a specific payload type

Source§

impl Packet

Source

pub fn from_raw_with_graph_rate( raw_packet: RawPacket, rate: GraphSampleRate, ) -> Result<Self, KMError>

Parse a raw packet using the configured AdcQueue graph rate.

Live device users should supply the rate used with StartGraph because auxiliary AdcQueue voltage fields use rate-dependent units.

Source§

impl Packet

Source

pub fn to_raw_packet(self, id: u8) -> Result<RawPacket, KMError>

Convert a high-level packet to a raw packet with the given transaction ID

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Packet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Packet

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Packet

Source§

impl TryFrom<RawPacket> for Packet

Source§

type Error = KMError

The type returned in the event of a conversion error.
Source§

fn try_from(raw_packet: RawPacket) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more