You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
Sending a DX command (host->sensor) to a streaming sensor stops data acquisition. However, this doesn't happen instantaneously. Once the DX command is sent out, the host will still receive a few Data Block receipts before seeing the DX receipt.
Currently the sweep_device_stop_scanning uses the following technique:
Send DX command (host -> sensor)
Wait a while (5000 us), for any remaining Data Block receipts and the DX receipt to arrive (sensor -> host).
Flush the serial port.
Send another DX command (host -> sensor)
Read the DX receipt (sensor -> host) that returns as a response to step 4
This was really a temporary workaround and should be replaced by an actual check for the DX receipt among the incoming Data Block receipts. The initial reaction might be to assume we cannot reliably check for a DX receipt among incoming Data Block receipts because the bytes of a Data Block are variable. The fear is that they could theoretically take the appearance of a DX receipt. However, we can still reliably discern the two because:
While it is true that Data Block bytes 1-6 can take any form, byte 0 (sync/error byte) is limited to very specific error codes and is therefore controllable. We can guarantee that byte 0 will never look like the first byte of a DX receipt.
The sensor guarantees the transmission of complete Data Block receipts before sending a DX receipt. That is to say that a DX receipt will never come mid-Data Block.
The sensor guarantees that no Data Block receipts are transmitted after the DX receipt is transmitted.
Obviously we can't protect against data corruption with 100% reliability, but we can certainly protect against valid Data Block receipts being misinterpreted as a DX receipt.
In sweep_device_stop_scanning, we should do something along the lines of:
Send a DX command (host -> sensor)
Look at the incoming bytes, and discern if they belong to a Data Block receipt or a DX receipt.
In the case of a Data Block receipt, handle it... (as we would during scanning, or simply trash it). In the case of a DX receipt, we proceed as if we picked up from step 5 above.
Sending a
DXcommand (host->sensor) to a streaming sensor stops data acquisition. However, this doesn't happen instantaneously. Once theDXcommand is sent out, the host will still receive a fewData Blockreceipts before seeing theDXreceipt.Currently the
sweep_device_stop_scanninguses the following technique:DXcommand (host -> sensor)Data Blockreceipts and theDXreceipt to arrive (sensor -> host).DXcommand (host -> sensor)DXreceipt (sensor -> host) that returns as a response to step 4This was really a temporary workaround and should be replaced by an actual check for the
DXreceipt among the incomingData Blockreceipts. The initial reaction might be to assume we cannot reliably check for aDXreceipt among incomingData Blockreceipts because the bytes of aData Blockare variable. The fear is that they could theoretically take the appearance of aDXreceipt. However, we can still reliably discern the two because:Data Blockbytes 1-6 can take any form, byte 0 (sync/error byte) is limited to very specific error codes and is therefore controllable. We can guarantee that byte 0 will never look like the first byte of aDXreceipt.Data Blockreceipts before sending aDXreceipt. That is to say that aDXreceipt will never come mid-Data Block.Data Blockreceipts are transmitted after theDXreceipt is transmitted.Obviously we can't protect against data corruption with 100% reliability, but we can certainly protect against valid
Data Blockreceipts being misinterpreted as aDXreceipt.In
sweep_device_stop_scanning, we should do something along the lines of:DXcommand (host -> sensor)Data Blockreceipt or aDXreceipt.Data Blockreceipt, handle it... (as we would during scanning, or simply trash it). In the case of aDXreceipt, we proceed as if we picked up from step 5 above.