Skip to content

Commit

Permalink
add multi wave support
Browse files Browse the repository at this point in the history
  • Loading branch information
XIVN1987 committed Jun 2, 2020
1 parent 13e060c commit 1a11add
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ to run software, you need python 3.6, pyqt5 and pyqtchart
wave show:
![](https://github.com/XIVN1987/JRTTView/blob/master/截屏.gif)

data format for wave show:
+ 1 wave: 11, 22, 33,
+ 2 wave: 11 22, 33 44, 55 66,
+ 3 wave: 11 22 33, 44 55 66, 77 88 99,
+ 4 wave: 11 22 33 44, 55 66 77 88, 99 11 22 33,

input:
![](https://github.com/XIVN1987/JRTTView/blob/master/截屏.jpg)
56 changes: 38 additions & 18 deletions RTTView.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from PyQt5.QtChart import QChart, QChartView, QLineSeries, QLegend


N_CURVES = 4

class RingBuffer(ctypes.Structure):
_fields_ = [
('sName', ctypes.c_uint), # ctypes.POINTER(ctypes.c_char),64位Python中 ctypes.POINTER 是64位的,与目标芯片不符
Expand Down Expand Up @@ -55,6 +57,8 @@ def __init__(self, parent=None):
self.tmrRTT.setInterval(10)
self.tmrRTT.timeout.connect(self.on_tmrRTT_timeout)
self.tmrRTT.start()

self.tmrRTT_Cnt = 0

def initSetting(self):
if not os.path.exists('setting.ini'):
Expand All @@ -72,21 +76,16 @@ def initSetting(self):
self.linDLL.setText(self.conf.get('J-Link', 'dllpath'))

def initQwtPlot(self):
self.PlotData = [0]*1000
self.PlotData = [[0]*1000 for i in range(N_CURVES)]
self.PlotPoint = [[QtCore.QPointF(j, 0) for j in range(1000)] for i in range(N_CURVES)]

self.PlotChart = QChart()
self.PlotChart.legend().hide()

self.ChartView = QChartView(self.PlotChart)
self.ChartView.setVisible(False)
self.vLayout.insertWidget(0, self.ChartView)

self.PlotCurve = QLineSeries()
self.PlotCurve.setColor(Qt.red)
self.PlotChart.addSeries(self.PlotCurve)

self.PlotChart.createDefaultAxes()
self.PlotChart.axisX().setLabelFormat('%d')
self.PlotCurve = [QLineSeries() for i in range(N_CURVES)]

@pyqtSlot()
def on_btnOpen_clicked(self):
Expand Down Expand Up @@ -180,19 +179,40 @@ def on_tmrRTT_timeout(self):
else:
if self.rcvbuff.rfind(b',') == -1: return

d = [int(x) for x in self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(b',')]
for x in d:
self.PlotData.pop(0)
self.PlotData.append(x)

points = [QtCore.QPoint(i, v) for i, v in enumerate(self.PlotData)]

self.PlotCurve.replace(points)
self.PlotChart.axisX().setMax(len(self.PlotData))
self.PlotChart.axisY().setRange(min(self.PlotData), max(self.PlotData))
d = self.rcvbuff[0:self.rcvbuff.rfind(b',')].split(b',') # [b'12', b'34'] or [b'12 34', b'56 78']
d = [[float(x) for x in X.strip().split()] for X in d] # [[12], [34]] or [[12, 34], [56, 78]]
for arr in d:
for i, x in enumerate(arr):
if i == N_CURVES: break

self.PlotData[i].pop(0)
self.PlotData[i].append(x)
self.PlotPoint[i].pop(0)
self.PlotPoint[i].append(QtCore.QPointF(999, x))

self.rcvbuff = self.rcvbuff[self.rcvbuff.rfind(b',')+1:]

self.tmrRTT_Cnt += 1
if self.tmrRTT_Cnt % 4 == 0:
if len(d[-1]) != len(self.PlotChart.series()):
for series in self.PlotChart.series():
self.PlotChart.removeSeries(series)
for i in range(min(len(d[-1]), N_CURVES)):
self.PlotCurve[i].setName(f'Curve {i+1}')
self.PlotChart.addSeries(self.PlotCurve[i])
self.PlotChart.createDefaultAxes()

for i in range(len(self.PlotChart.series())):
for j, point in enumerate(self.PlotPoint[i]):
point.setX(j)

self.PlotCurve[i].replace(self.PlotPoint[i])

miny = min([min(d) for d in self.PlotData])
maxy = max([max(d) for d in self.PlotData])
self.PlotChart.axisY().setRange(miny, maxy)
self.PlotChart.axisX().setRange(0000, 1000)

except Exception as e:
self.rcvbuff = b''
print(str(e)) # 波形显示模式下 txtMain 不可见,因此错误信息不能显示在其上
Expand Down
2 changes: 1 addition & 1 deletion setting.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[J-Link]
dllpath = C:/Program/Segger/JLink_V502g/bin_x64/JLink_x64.dll
dllpath = D:/Program/Segger/JLink_V502k/bin_x64/JLink_x64.dll

[Memory]
startaddr = 0x20000000
Expand Down

0 comments on commit 1a11add

Please sign in to comment.