Skip to content

Commit 2a958d8

Browse files
authored
Merge pull request #163 from junchao98/master
Enhanced Plotting Protocol
2 parents 3f6acaf + 85e6d8f commit 2a958d8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

COMTool/plugins/graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ class Plugin(Plugin_Base):
7171
* $[line name],[x],[y]<,checksum>\\n
7272
* ''' + _('"$" means start of frame, end with "\\n" "," means separator') + ''',
7373
* ''' + _('checksum is optional, checksum is sum of all bytes in frame except ",checksum".') + '''
74+
* ''' + _('[x] is optional') + '''
7475
* ''' + _('e.g.') + '''
76+
* "$roll,2.0\\n"
7577
* "$roll,1.0,2.0\\n"
7678
* "$pitch,1.0,2.0\\r\\n"
7779
* "$pitch,1.0,2.0,179\\n" (179 = sum(b"$pitch,1.0,2.0") % 256)
7880
*/
7981
int plot_pack_ascii(uint8_t *buff, int buff_len, const char *name, float x, float y)
8082
{
8183
snprintf(buff, buff_len, "$%s,%f,%f", name, x, y);
84+
//snprintf(buff, buff_len, "$%s,%f", name, y);
8285
// add checksum
8386
int sum = 0;
8487
for (int i = 0; i < strlen(buff); i++)

COMTool/plugins/graph_widgets.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, parent=None, hintSignal=lambda type, title, msg: None, rmCall
4646
self.setLayout(self.layout)
4747
self.plotWin = pg.GraphicsLayoutWidget()
4848
self.plotWin.setMinimumHeight(200)
49+
self.default_x = 0;
4950
pg.setConfigOptions(antialias=True)
5051
rmBtn = QPushButton(_("Remove"))
5152
clearBtn = QPushButton(_("Clear"))
@@ -215,9 +216,11 @@ def decodeDataAscii(self, data: bytes):
215216
'''
216217
@data bytes, protocol:
217218
$[line name],[x],[y]<,checksum>\n
219+
or $[line name],[y]
218220
"$" means start of frame, "," means separator,
219221
checksum is optional, checksum is sum of all bytes in frame except ",checksum".
220222
e.g.
223+
"$roll,2.0\n"
221224
"$roll,1.0,2.0\n"
222225
"$pitch,1.0,2.0\r\n"
223226
"$pitch,1.0,2.0,179\n" , the 179 = sum(ord(c) for c in "$pitch,1.0,2.0") % 256
@@ -245,12 +248,17 @@ def decodeDataAscii(self, data: bytes):
245248
frame = self.rawData[1:idx] # pitch,1.0,2.0 pitch,1.0,2.0,179
246249
self.rawData = self.rawData[idx + 1:]
247250
items = frame.split(b",")
248-
if len(items) != 3 and len(items) != 4:
251+
if len(items) != 2 and len(items) != 3 and len(items) != 4:
249252
print("-- format error, frame item len(%s, should 3 or 4) error: %s" % (len(items), frame))
250253
return False, self.data
251254
try:
252-
x = float(items[1])
253-
y = float(items[2])
255+
if len(items) == 2:
256+
x = float(self.default_x)
257+
y = float(items[1])
258+
self.default_x += 1
259+
else:
260+
x = float(items[1])
261+
y = float(items[2])
254262
except Exception:
255263
print("-- x or y format error, frame: %s" % frame)
256264
return False, self.data

0 commit comments

Comments
 (0)