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

Introducing a new suggested serial flush procedure with a hard timeout about 5 times bigger than the default rx block to protect the driver against a infinite serial data stream.
Better handling of the debugging messages in the IO procedures.

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

El 29/03/16 a las 18:39, Dan Smith via chirp_devel escribió:
+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
You are right, I will patch it.
Will be good to mention in the error that the user must check about a buggy serial device or a serial GPS connected on that port?
73
participants (2)
-
Dan Smith
-
M.Sc. Pavel Milanes Costa