Skip to content

Commit

Permalink
fix dbg plugin receive log show and tx count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Aug 31, 2022
1 parent 49676cb commit a72636c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions COMTool/plugins/dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def onInit(self, config):
for k in default:
if not k in self.config:
self.config[k] = default[k]
self.lastShowTail = ''
self.justSent = False # sent data before received data flag

def onWidgetMain(self, parent):
self.mainWidget = QSplitter(Qt.Vertical)
Expand Down Expand Up @@ -567,17 +569,17 @@ def sendData(self, data_bytes = None):
isHexStr, sendStr, sendStrsColored = self.bytes2String(data, not self.config["receiveAscii"], encoding=self.configGlobal["encoding"])
if isHexStr:
sendStr = sendStr.upper()
sendStrsColored= sendStr
head += "[HEX] "
if self.config["useCRLF"]:
head = "\r\n" + head
else:
head = "\n" + head
if head.strip() != '=>':
head = '{}: '.format(head.rstrip())
self.receiveUpdateSignal.emit(head, [sendStrsColored], self.configGlobal["encoding"])
self.receiveUpdateSignal.emit(head, [sendStr], self.configGlobal["encoding"])
self.sendRecord.insert(0, head + sendStr)
self.send(data_bytes=data, callback = self.onSent)
self.justSent = True # flag for receive thread
if data_bytes:
data = str(data_bytes)
else:
Expand Down Expand Up @@ -788,13 +790,15 @@ def receiveDataProcess(self):
buffer += new
self.receivedData = []
# timeout, add new line
if time.time() - timeLastReceive> self.config["receiveAutoLindefeedTime"]:
# self.justSent means just sent data, need show head
if time.time() - timeLastReceive > self.config["receiveAutoLindefeedTime"] / 1000 or self.justSent:
if self.config["showTimestamp"] or self.config["receiveAutoLinefeed"]:
if self.config["useCRLF"]:
head += "\r\n"
else:
head += "\n"
new_line = True
self.justSent = False
data = ""
# have data in buffer
if len(buffer) > 0:
Expand All @@ -808,11 +812,19 @@ def receiveDataProcess(self):
# show as string, and don't need to render color
elif not self.config["color"]:
data = buffer.decode(encoding=self.configGlobal["encoding"], errors="ignore")
# self.lastShowTail for separated \r\n, prevent show two linefeed
# if last msg endswith "\r", and this msg startswith "\n", don't show "\n", if you have different thought, add issue to github
if self.lastShowTail == "\r" and data[0] == "\n":
data = data[1:]
colorData = data
buffer = b''
if data and data[-1] == "\r":
self.lastShowTail = data[-1]
else:
self.lastShowTail = ""
# show as string, and need to render color, wait for \n or until timeout to ensure color flag in buffer
else:
if time.time() - timeLastReceive > self.config["receiveAutoLindefeedTime"] or b'\n' in buffer:
if time.time() - timeLastReceive > self.config["receiveAutoLindefeedTime"] / 1000 or b'\n' in buffer:
data, colorData, remain = self.getColoredText(buffer, self.configGlobal["encoding"])
buffer = remain
# add time receive head
Expand Down
2 changes: 1 addition & 1 deletion COMTool/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

major = 3
minor = 1
dev = 2
dev = 3

__version__ = "{}.{}.{}".format(major, minor, dev)

Expand Down

0 comments on commit a72636c

Please sign in to comment.