Skip to content

Commit

Permalink
Fix windows issue that caused incosistent sweeps when using only one …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
davidjmeyer authored Jan 29, 2024
1 parent 456bcd3 commit 440b773
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
Binary file modified src/firmware/v2
Binary file not shown.
5 changes: 2 additions & 3 deletions src/scope/data_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 21 additions & 16 deletions src/scope/run_loops/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
}

}


Expand Down

0 comments on commit 440b773

Please sign in to comment.