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: AttributeSetStartGraph
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
rate: GraphSampleRateStopGraph
Stop AdcQueue graph mode
Accept
Accept response
Reject
Reject response
NotReadable
NotReadable response - memory address not accessible
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
StreamingAuth
StreamingAuth command (0x4C) - authenticate for AdcQueue streaming
Fields
credential: AuthCredentialDevice 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
impl Packet
Sourcepub fn find_payload<'a, T: ?Sized>(
&'a self,
select: impl Fn(&'a PayloadData) -> Option<&'a T>,
) -> Option<&'a T>
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.
Sourcepub fn get_adc(&self) -> Option<&AdcDataSimple>
pub fn get_adc(&self) -> Option<&AdcDataSimple>
Get ADC data from the packet, if present.
Sourcepub fn get_adc_queue(&self) -> Option<&AdcQueueData>
pub fn get_adc_queue(&self) -> Option<&AdcQueueData>
Get AdcQueue data from the packet, if present.
Examples found in repository?
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}Sourcepub fn get_adc_queue_raw(&self) -> Option<&AdcQueueRawData>
pub fn get_adc_queue_raw(&self) -> Option<&AdcQueueRawData>
Get losslessly parsed AdcQueue data whose graph rate is unknown.
Sourcepub fn get_pd_status(&self) -> Option<&PdStatus>
pub fn get_pd_status(&self) -> Option<&PdStatus>
Get PD status from the packet, if present.
Sourcepub fn get_pd_events(&self) -> Option<&PdEventStream>
pub fn get_pd_events(&self) -> Option<&PdEventStream>
Get PD events from the packet, if present.
Sourcepub fn get_pd_trace(&self) -> Option<&PdTrace>
pub fn get_pd_trace(&self) -> Option<&PdTrace>
Get the internal PD state-machine trace, if present.
Sourcepub fn get_settings(&self) -> Option<&Settings>
pub fn get_settings(&self) -> Option<&Settings>
Get the read-only settings payload, if present.
Sourcepub fn get_log_metadata(&self) -> Option<&LogMetadataResponse>
pub fn get_log_metadata(&self) -> Option<&LogMetadataResponse>
Get the response to a LogMetadata request, if present.
Sourcepub fn has_payload(&self, attr: Attribute) -> bool
pub fn has_payload(&self, attr: Attribute) -> bool
Check if packet has a specific payload type
Source§impl Packet
impl Packet
Sourcepub fn from_raw_with_graph_rate(
raw_packet: RawPacket,
rate: GraphSampleRate,
) -> Result<Self, KMError>
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.