Created
August 20, 2016 03:11
-
-
Save Julio-Guerra/b6529994f814771c825649bdb8d927c2 to your computer and use it in GitHub Desktop.
cdc_acm buffer read problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
: ${1?"missing argument 1: device node (e.g. /dev/ttyAMC0)"} | |
dev=$1 | |
stty -F $dev 9600 raw min 8 | |
# open the device once, with file descriptor 4 | |
exec 4<>$dev | |
# necessart sleep to avoid device problems | |
function cooldown() { | |
sleep 0.04 | |
} | |
function dump() { | |
hexdump -C | |
# newline | |
echo | |
} | |
function state() { | |
# state request | |
echo -ne "\xFF\x09\x00" >&4 | |
cooldown | |
# read the answer: exactly 8 bytes | |
# dd is used because it does not change the tty settings and | |
# does not expect only ascii. | |
dd bs=1 count=8 <&4 2>&- | dump | |
cooldown | |
} | |
while true; do | |
state | |
done | |
# close the file descriptor | |
exec 4>&- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running this with dynamic debugs enabled.
Pluging the device:
Changing the device state to observe the bug in an answer to a state request:
Running the script:
Stopping the script once the bug observed:
Script output (dump of a request result, observe the
01
shift):