source: flair-src/trunk/tools/FlairGCS/src/DataPlot1D.cpp@ 276

Last change on this file since 276 was 269, checked in by Sanahuja Guillaume, 6 years ago

flairgcs:
speed up processing time when receiving datas from uav
triger watchdog while receiving datas from uav
(avoids connection lost in uav)

File size: 3.8 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include "DataPlot1D.h"
6#include "Layout.h"
7#include <QMouseEvent>
8#include <QMenu>
9#include <QGridLayout>
10#include <qendian.h>
11
[15]12DataPlot1D::DataPlot1D(Layout *parent, int row, int col, QString title,
13 float ymin, float ymax, bool enabled, int period)
14 : ScopeFixedStep(title, ymin, ymax, period / 1000.),
15 DataRemote(title, "DataPlot1D", parent, enabled, period) {
[9]16
[15]17 setEnabled(enabled);
18 parent->addWidget(this, row, col);
19 visible_widget = this;
[9]20}
21
22DataPlot1D::~DataPlot1D() {
[15]23 visible_widget = NULL; // because otherwise xmlwidget will delete it
[9]24}
25
[269]26void DataPlot1D::XmlEvent(QDomElement *dom) {
27 if (dom->attribute("curve") != "") {
28 QString type = dom->attribute("type");
29 int r = dom->attribute("r").toInt();
30 int g = dom->attribute("g").toInt();
31 int b = dom->attribute("b").toInt();
32 QString name = dom->attribute("curve");
[15]33 addCurve(QPen(QColor(r, g, b, 255)), name);
34 datas_type.append(type);
35 if (type == "float") {
36 receivesize += sizeof(float);
37 } else if (type == "int8_t") {
38 receivesize += sizeof(int8_t);
39 } else if (type == "int16_t") {
40 receivesize += sizeof(int16_t);
[9]41 } else {
[244]42 fprintf(stderr,"MyDataPlot1D::addCurve unknown type %s\n",
[15]43 type.toLocal8Bit().constData());
[9]44 }
[15]45 } else {
46 XmlSetup(dom);
47 }
[9]48}
49
50bool DataPlot1D::eventFilter(QObject *o, QEvent *e) {
[15]51 if (o == canvas()) {
52 switch (e->type()) {
53 case QEvent::Resize: {
54 // resolution bug taille widgets:
55 setMaximumHeight(parentWidget()->height() /
56 ((QGridLayout *)(parentWidget()->layout()))->rowCount());
57 break;
58 }
59 case QEvent::MouseButtonPress: {
60 return mouseEvent((QMouseEvent *)e);
61 }
[9]62
[15]63 default:
64 break;
[9]65 }
[15]66 }
67 return Scope::eventFilter(o, e);
[9]68}
69
[15]70void DataPlot1D::BufEvent(char **buf, int *buf_size, uint16_t period,
71 bool big_endian) {
72 setEnabled(IsEnabled());
73 if (IsEnabled() == false || RefreshRate_ms() != period)
74 return;
75 double *datas = (double *)malloc(datas_type.count() * sizeof(double));
[9]76
[15]77 for (int i = 0; i < datas_type.count(); i++) {
78 if (datas_type.at(i) == "float") {
79 uint32_t data_raw;
80 float *data = (float *)&data_raw;
81 memcpy((void *)&data_raw, *buf, sizeof(uint32_t));
82 *buf += sizeof(uint32_t);
83 if (big_endian == true)
84 data_raw = qFromBigEndian(data_raw);
85 datas[i] = *data;
86 } else if (datas_type.at(i) == "int8_t") {
87 int8_t data;
88 memcpy((void *)&data, *buf, sizeof(data));
89 *buf += sizeof(data);
90 datas[i] = data;
91 } else if (datas_type.at(i) == "int16_t") {
92 int16_t data;
93 memcpy((void *)&data, *buf, sizeof(data));
94 *buf += sizeof(data);
95 if (big_endian == true)
96 data = qFromBigEndian(data);
97 datas[i] = data;
98 } else {
[244]99 fprintf(stderr,"DataPlot1D::BufEvent unknown type %s\n",
[15]100 datas_type.at(i).toLocal8Bit().constData());
[9]101 }
[15]102 }
[9]103
[15]104 step_s = period / 1000.;
105 plot(datas);
[222]106 free(datas);
[9]107}
108
[15]109// context menu
[9]110bool DataPlot1D::mouseEvent(QMouseEvent *event) {
[15]111 if (event->button() == Qt::RightButton) {
112 QMenu *menu = new QMenu("nom", (QwtPlot *)this);
[222]113 QAction *resetX, *resetY, *clear,*action;
[9]114
[222]115 resetX = menu->addAction("reset time view");
116 resetY = menu->addAction("reset y view");
[15]117 menu->addSeparator();
[9]118
[15]119 appendmenu(menu);
[222]120
121 menu->addSeparator();
122 clear = menu->addAction("clear graph");
123
124 action = execmenu((QwtPlot *)this, menu, event->globalPos());
[15]125 delete menu;
[9]126
[222]127 if (action == resetX)
[15]128 resetXView();
[222]129 if (action == resetY)
[15]130 resetYView();
[222]131
132 if (action == clear)
133 clearCurves();
[9]134
[15]135 return true;
136 }
137 return false;
[9]138}
Note: See TracBrowser for help on using the repository browser.