Skip to content

Commit 70020ee

Browse files
committed
Add basic manufacturing test tooling
1 parent 25f5bf3 commit 70020ee

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

examples/rpc.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ fn format_node(node: hid_io_core::common_capnp::destination::Reader<'_>) -> Stri
6565
)
6666
}
6767

68-
struct KeyboardSubscriberImpl;
68+
#[derive(Default)]
69+
pub struct KeyboardSubscriberImpl {
70+
pub hall_effect_switch_data: Vec<u16>,
71+
}
6972

7073
impl keyboard_capnp::keyboard::subscriber::Server for KeyboardSubscriberImpl {
7174
fn update(
@@ -87,6 +90,33 @@ impl keyboard_capnp::keyboard::subscriber::Server for KeyboardSubscriberImpl {
8790
let res = res.unwrap();
8891
println!("{}:{} => ", res.get_cmd(), res.get_arg());
8992
match res.get_cmd() {
93+
1 => match res.get_arg() {
94+
2 | 3 => {
95+
// LED short/open test
96+
let mut pos: usize = 0;
97+
let data = res.get_data().unwrap();
98+
loop {
99+
let chipid = data.get(pos as u32);
100+
pos += 1;
101+
let buffer_len = data.get(pos as u32);
102+
pos += 1;
103+
let buffer =
104+
&data.as_slice().unwrap()[pos..pos + buffer_len as usize];
105+
pos += buffer_len as usize;
106+
println!("ChipId: {} {}", chipid, buffer_len);
107+
for byte in buffer {
108+
print!("{:02x} ", byte);
109+
}
110+
println!();
111+
if pos >= data.len().try_into().unwrap() {
112+
break;
113+
}
114+
}
115+
}
116+
_ => {
117+
println!("Manufacturing command {} not implemented", res.get_arg())
118+
}
119+
},
90120
3 => match res.get_arg() {
91121
2 => {
92122
let split = res.get_data().unwrap().len() / 2 / 6;
@@ -95,7 +125,13 @@ impl keyboard_capnp::keyboard::subscriber::Server for KeyboardSubscriberImpl {
95125
for byte in res.get_data().unwrap() {
96126
tmp.push(byte);
97127
if tmp.len() == 2 {
98-
print!("{:>4} ", u16::from_le_bytes([tmp[0], tmp[1]]));
128+
// Check if header (strobe) or sense data
129+
if pos % 7 == 0 {
130+
print!("{:>4} ", tmp[0]);
131+
} else {
132+
let data = u16::from_le_bytes([tmp[0], tmp[1]]);
133+
print!("{:>4} ", data);
134+
}
99135
tmp.clear();
100136
pos += 1;
101137
if pos % split == 0 {
@@ -290,7 +326,7 @@ async fn try_main() -> Result<(), ::capnp::Error> {
290326
serial = device.get_serial().unwrap().to_string();
291327

292328
// Build subscription callback
293-
let subscription = capnp_rpc::new_client(KeyboardSubscriberImpl);
329+
let subscription = capnp_rpc::new_client(KeyboardSubscriberImpl::default());
294330

295331
// Subscribe to cli messages
296332
let subscribe_req = {

examples/tool.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ async fn try_main() -> Result<(), ::capnp::Error> {
558558
println!("Sent (str): '{}'", String::from_utf8_lossy(data_cmd));
559559
println!("Recv (str): '{}'", String::from_utf8_lossy(data_ack));
560560
assert_eq!(data_cmd, data_ack, "Sent does not equal received!");
561+
562+
// Wait for any Manufacturing Test Data packets
563+
// TODO - Only wait if argument is set
564+
// - Build subscription for Manufacturing Test Data packets
565+
// - Wait for Manufacturing Test Data packets
561566
}
562567
}
563568
_ => {

hid-io-protocol/src/commands/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,7 @@ pub trait Commands<
23432343
}
23442344

23452345
buf.done = true;
2346+
trace!("h0051_manufacturingres: {:?} - {:?}", data, buf);
23462347

23472348
self.tx_packetbuffer_send(&mut buf)
23482349
}
@@ -2384,7 +2385,7 @@ pub trait Commands<
23842385
raw: u16::from_le_bytes(buf.data[2..4].try_into().unwrap()),
23852386
};
23862387
let data: Vec<u8, HSUB4> = if buf.data.len() > 4 {
2387-
Vec::from_slice(&buf.data[5..]).unwrap()
2388+
Vec::from_slice(&buf.data[4..]).unwrap()
23882389
} else {
23892390
Vec::new()
23902391
};

hid-io-protocol/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ impl<const H: usize> HidIoPacketBuffer<H> {
641641
match ptype {
642642
HidIoPacketType::Continued | HidIoPacketType::NaContinued => {}
643643
_ => {
644-
warn!("Dropping. Invalid packet type (non-HidIoPacketType::Continued) on a already initialized buffer: {} {}", ptype, self.data.is_empty());
645-
return Ok(packet_len);
644+
warn!("Dropping buffer. Invalid packet type (non-HidIoPacketType::Continued) on a already initialized buffer: {} {}", ptype, self.data.is_empty());
645+
self.clear();
646+
return self.decode_packet(packet_data);
646647
}
647648
}
648649
}

src/device/hidapi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ async fn processing(mailbox: mailbox::Mailbox) {
287287
// Attempt to synchronize device (sync packet)
288288
if let Err(e) = device.send_sync() {
289289
// Could not open device (likely removed, or in use)
290+
uids.write().unwrap().remove(&uid);
290291
warn!("Failed to sync device - {}", e);
291292
} else {
292293
// Setup device controller (handles communication and protocol conversion

0 commit comments

Comments
 (0)