Skip to content

Commit e3610c9

Browse files
opcliChris Li
andauthored
Fix issue "RX Serial not found", missing bootloader (ExpressLRS#717)
I hit an issue on mnibus f4, the ExpressLRS-Configurator can't flash the elrs binary due to not able to detect bootloader. The issue is cause by in correct parsing of the delimiter when a line is broken into two separate serial reads. This code in question is: r = buf + data[:offset] It should be: r = (buf + data)[:offset] I also notice duplicated code to handle one read vs more than one read of a line. I clean up and unify the duplicated code. With this change, I verify the elrs firmware can be upload correctly. Co-authored-by: Chris Li <chris@mini>
1 parent e820af5 commit e3610c9

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

src/python/SerialHelper.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ def read_line(self, timeout=None):
3333
if timeout is None or timeout <= 0.:
3434
timeout = self.timeout
3535
buf = self.buf
36+
def has_delimiter():
37+
for d in self.delimiters:
38+
if d in buf:
39+
return True
40+
41+
start = time.time()
42+
while not has_delimiter() and ((time.time() - start) < timeout):
43+
i = max(0, min(2048, self.serial.in_waiting))
44+
data = self.serial.read(i)
45+
if not data:
46+
continue
47+
48+
buf.extend(data)
49+
3650
for delimiter in self.delimiters:
3751
i = buf.find(delimiter)
3852
if i >= 0:
@@ -41,21 +55,7 @@ def read_line(self, timeout=None):
4155
self.buf = buf[offset:]
4256
return self.__convert_to_str(r)
4357

44-
start = time.time()
45-
while ((time.time() - start) < timeout):
46-
i = max(0, min(2048, self.serial.in_waiting))
47-
data = self.serial.read(i)
48-
if not data:
49-
continue
50-
for delimiter in self.delimiters:
51-
i = bytearray(buf + data).find(delimiter)
52-
if i >= 0:
53-
offset = i+len(delimiter)
54-
r = buf + data[:offset]
55-
self.buf = bytearray(data[offset:])
56-
return self.__convert_to_str(r)
57-
# No match
58-
buf.extend(data)
58+
# No match
5959

6060
# Timeout, reset buffer and return empty string
6161
#print("TIMEOUT! Got:\n>>>>>>\n{}\n<<<<<<\n".format(buf))

0 commit comments

Comments
 (0)