[chirp_devel] [PATCH][BTECH] New serial flush and better debug messages, fixes #3015

Dan Smith
Tue Mar 29 15:39:05 PDT 2016


> diff -r e591072d4a4b -r ebd86169e22a chirp/drivers/btech.py
> --- a/chirp/drivers/btech.py    Mon Mar 28 00:34:50 2016 -0400
> +++ b/chirp/drivers/btech.py    Mon Mar 28 01:16:54 2016 -0400
> @@ -172,6 +172,28 @@
>  MSTRING = "\x55\x20\x15\x09\x20\x45\x4d\x02"
>  
>  
> +def _clean_buffer(radio):
> +    """Cleaning the read serial buffer, hard timeout to survive an infinite
> +    data stream"""
> +
> +    # WARNING: every time we call this we touch the serialTimeout, this is
> +    # to optimize the flushing
> +    radio.pipe.setTimeout(0.1)
> +    dump = "1"
> +    datacount = 0
> +
> +    try:
> +        while len(dump) > 0:
> +            dump = radio.pipe.read(100)
> +            datacount += len(dump)
> +            if  datacount > 320:  # 5 times bigger than a normal rx block
> +                # hard limit to survive a infinite serial data stream
> +                break

Don't you want to raise if this happens? This will silently return if we
read enough junk, the input will not be clean, and our caller will die,
right? I'm sure it's handled there too, but I think you should raise
here for clarity.

--Dan



More information about the chirp_devel mailing list