Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions COMTool/plugins/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ class Plugin(Plugin_Base):
* $[line name],[x],[y]<,checksum>\\n
* ''' + _('"$" means start of frame, end with "\\n" "," means separator') + ''',
* ''' + _('checksum is optional, checksum is sum of all bytes in frame except ",checksum".') + '''
* ''' + _('[x] is optional') + '''
* ''' + _('e.g.') + '''
* "$roll,2.0\\n"
* "$roll,1.0,2.0\\n"
* "$pitch,1.0,2.0\\r\\n"
* "$pitch,1.0,2.0,179\\n" (179 = sum(b"$pitch,1.0,2.0") % 256)
*/
int plot_pack_ascii(uint8_t *buff, int buff_len, const char *name, float x, float y)
{
snprintf(buff, buff_len, "$%s,%f,%f", name, x, y);
//snprintf(buff, buff_len, "$%s,%f", name, y);
// add checksum
int sum = 0;
for (int i = 0; i < strlen(buff); i++)
Expand Down
14 changes: 11 additions & 3 deletions COMTool/plugins/graph_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, parent=None, hintSignal=lambda type, title, msg: None, rmCall
self.setLayout(self.layout)
self.plotWin = pg.GraphicsLayoutWidget()
self.plotWin.setMinimumHeight(200)
self.default_x = 0;
pg.setConfigOptions(antialias=True)
rmBtn = QPushButton(_("Remove"))
clearBtn = QPushButton(_("Clear"))
Expand Down Expand Up @@ -215,9 +216,11 @@ def decodeDataAscii(self, data: bytes):
'''
@data bytes, protocol:
$[line name],[x],[y]<,checksum>\n
or $[line name],[y]
"$" means start of frame, "," means separator,
checksum is optional, checksum is sum of all bytes in frame except ",checksum".
e.g.
"$roll,2.0\n"
"$roll,1.0,2.0\n"
"$pitch,1.0,2.0\r\n"
"$pitch,1.0,2.0,179\n" , the 179 = sum(ord(c) for c in "$pitch,1.0,2.0") % 256
Expand Down Expand Up @@ -245,12 +248,17 @@ def decodeDataAscii(self, data: bytes):
frame = self.rawData[1:idx] # pitch,1.0,2.0 pitch,1.0,2.0,179
self.rawData = self.rawData[idx + 1:]
items = frame.split(b",")
if len(items) != 3 and len(items) != 4:
if len(items) != 2 and len(items) != 3 and len(items) != 4:
print("-- format error, frame item len(%s, should 3 or 4) error: %s" % (len(items), frame))
return False, self.data
try:
x = float(items[1])
y = float(items[2])
if len(items) == 2:
x = float(self.default_x)
y = float(items[1])
self.default_x += 1
else:
x = float(items[1])
y = float(items[2])
except Exception:
print("-- x or y format error, frame: %s" % frame)
return False, self.data
Expand Down