diff --git a/src/firmware.rs b/src/firmware.rs index fe8fad6..a3d707a 100644 --- a/src/firmware.rs +++ b/src/firmware.rs @@ -9,4 +9,4 @@ **************************************************************************************************/ pub(crate) static FIRMWARE: &[u8] = include_bytes!("firmware/v2"); -pub(crate) static FIRMWARE_VERSION: u16 = 0x0200; \ No newline at end of file +pub(crate) static FIRMWARE_VERSION: u16 = 0x0201; \ No newline at end of file diff --git a/src/firmware/v2 b/src/firmware/v2 index 6c2d3f2..71c43c5 100755 Binary files a/src/firmware/v2 and b/src/firmware/v2 differ 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; - } } - }