From 440b77322b5432193f223befe0ae800e9acc5f68 Mon Sep 17 00:00:00 2001 From: David Meyer <10246856+davidjmeyer@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:12:29 -0800 Subject: [PATCH] Fix windows issue that caused incosistent sweeps when using only one or two channels (#10) * do not wait for data on unused channels * also store the request id in usb transmissions * update nScope firmware to v2.1 --- src/firmware/v2 | Bin 79004 -> 79028 bytes src/scope/data_requests.rs | 5 ++--- src/scope/run_loops/v2.rs | 37 +++++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/firmware/v2 b/src/firmware/v2 index 6c2d3f2189e0ac0f3b7d3ee9f8c9df7c939da818..71c43c581163d4ec240e44a9b470ab6cb2a5fd3d 100755 GIT binary patch delta 6386 zcmcIp4OCP|vhKQf1_lHHVMG{^`C()biNjxz5M>m(4x&M0j2caXaeYoU@kQ579$Axs z(L`NiL>m{CxY2ceipD66hM*y!#*HQt{~&5ySBx<@`m){;^xpY@b!UboyKndGJLjFp zId!|by1J^q>gv8dm-lS4gEm-52+BR!!gx@e zz`6fhlB0eMQZiCHQr>u|QjA6B=LRPKUH|7}{}=u;2K+zgSN$VlKsFr%S^WPL%#VT0 z{wL{^GXJB}KhgPD<8}6QFl=DdLuCp^p*X~rsT$c**1W%$R4ZB~2dUviEmK&>FoOoe zY&vyFPE@1QXc?v-d#^9;x+R3KrgX?!SW7htx_MU|rWTZ|iAz4d!qR$clu6FdIt=_Z zvA0Lgzv#p<9qW=8U$6mNp?$N0XvbBsbHBy0XPo7I)#JWGZWeOevQHuR1af5DXULT! zXByXr+(f!7VF^T2RiY~GIme<#;9n94bjx|SqZ4hib1QVqD@rPGu7eo(a}^dje~~_& zm@@L31MQcbMho8{w=M5;R)s4?5Tr4-Q!lc!3M9uJrybS-mucT~9#ef5?xA=9yAMpOAXWV1u{A)AI zc|zAE7ZgwPu=P+wYM$bza-%rlm5zvq$;ifYkoI*C@NauQ=($n(O=v-9edw+(&1;>a z(%31+s7b+)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89F;CZU_;PEXJix;8#5l1yiJY(P%CwS9 z*Li(aZ5QeO`W(>=3F?kI1*`-3MRSA-54S~_jo4<33U0tx%^5*pfKQq$f*=!)`WogX z4~@JP(|jlh%uv`N1wqF+ARYVD;0zo5-nX7Qz>{=;bHjKj%&NqA%t#g_<#ha)0SD^& u*gk>nhEo5(4rFz_#S(4D@Oa1#&Wmz^`uRS;>=Dd`8HxNmYJPAcEchROK_emn diff --git a/src/scope/data_requests.rs b/src/scope/data_requests.rs index fa8f4ae..bd7e135 100644 --- a/src/scope/data_requests.rs +++ b/src/scope/data_requests.rs @@ -232,17 +232,16 @@ impl ScopeCommand for DataRequest { impl DataRequest { pub(crate) fn handle_incoming_data(&self, usb_buf: &[u8; 64], channel: usize) { - let num_received = usb_buf[0] as usize; + let num_received = usb_buf[1] as usize; let mut num_parsed: usize = 0; while num_parsed < num_received { - let byte: usize = 1 + num_parsed / 2 * 3; + let byte: usize = 4 + num_parsed / 2 * 3; let adc_data = match num_parsed % 2 { 0 => usb_buf[byte] as u16 | ((usb_buf[byte + 1] & 0xF) as u16) << 8, 1 => usb_buf[byte + 1] as u16 >> 4 | (usb_buf[byte + 2] as u16) << 4, _ => panic!("Unexpected behavior of odd/even bitmask") }; - self.data_collator.write().unwrap()[channel].push_back(adc_data); num_parsed += 1; } diff --git a/src/scope/run_loops/v2.rs b/src/scope/run_loops/v2.rs index 62f17ea..94b0a88 100644 --- a/src/scope/run_loops/v2.rs +++ b/src/scope/run_loops/v2.rs @@ -32,6 +32,7 @@ impl crate::Nscope { if let Ok(()) = rq.stop_recv.try_recv() { // We have received a stop signal command_tx.send(Command::StopData).unwrap(); + trace!("Sent a stop command to request {}", id); } } } @@ -132,26 +133,30 @@ impl crate::Nscope { let mut received_ch_data = false; - for (ch, &ep) in [0x82u8, 0x83u8, 0x84u8, 0x85u8].iter().enumerate() { - let buf = &mut incoming_channel_buffers[ch]; - - match usb_device.read_bulk(ep, buf, Duration::from_millis(1)) - { - Err(rusb::Error::Timeout) => {} - Ok(_) => { - if let Some(request_id) = active_data_request { - if let Some(Command::RequestData(data_request)) = active_requests_map.get(&request_id) { - data_request.handle_incoming_data(buf, ch); - received_ch_data = true; + if let Some(request_id) = active_data_request { + if let Some(Command::RequestData(data_request)) = active_requests_map.get(&request_id) { + for (ch, &ep) in [0x82u8, 0x83u8, 0x84u8, 0x85u8].iter().enumerate() { + let buf = &mut incoming_channel_buffers[ch]; + if data_request.channels[ch].is_on { + match usb_device.read_bulk(ep, buf, Duration::from_millis(1)) + { + Err(rusb::Error::Timeout) => {} + Ok(_) => { + let received_request_id = buf[0]; + trace!("Received data for request {}, active request {}", received_request_id, request_id); + if received_request_id == request_id { + data_request.handle_incoming_data(buf, ch); + received_ch_data = true; + } + } + Err(error) => { + error!("USB read error: {:?}", error); + break 'communication; + } } } } - Err(error) => { - error!("USB read error: {:?}", error); - break 'communication; - } } - }