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

Last change on this file since 330 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
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5#include "DataPlot1D.h"
6#include "Layout.h"
7#include <QMouseEvent>
8#include <QMenu>
9#include <QGridLayout>
10#include <qendian.h>
11
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) {
16
17 setEnabled(enabled);
18 parent->addWidget(this, row, col);
19 visible_widget = this;
20}
21
22DataPlot1D::~DataPlot1D() {
23 visible_widget = NULL; // because otherwise xmlwidget will delete it
24}
25
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");
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);
41 } else {
42 fprintf(stderr,"MyDataPlot1D::addCurve unknown type %s\n",
43 type.toLocal8Bit().constData());
44 }
45 } else {
46 XmlSetup(dom);
47 }
48}
49
50bool DataPlot1D::eventFilter(QObject *o, QEvent *e) {
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 }
62
63 default:
64 break;
65 }
66 }
67 return Scope::eventFilter(o, e);
68}
69
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));
76
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 {
99 fprintf(stderr,"DataPlot1D::BufEvent unknown type %s\n",
100 datas_type.at(i).toLocal8Bit().constData());
101 }
102 }
103
104 step_s = period / 1000.;
105 plot(datas);
106 free(datas);
107}
108
109// context menu
110bool DataPlot1D::mouseEvent(QMouseEvent *event) {
111 if (event->button() == Qt::RightButton) {
112 QMenu *menu = new QMenu("nom", (QwtPlot *)this);
113 QAction *resetX, *resetY, *clear,*action;
114
115 resetX = menu->addAction("reset time view");
116 resetY = menu->addAction("reset y view");
117 menu->addSeparator();
118
119 appendmenu(menu);
120
121 menu->addSeparator();
122 clear = menu->addAction("clear graph");
123
124 action = execmenu((QwtPlot *)this, menu, event->globalPos());
125 delete menu;
126
127 if (action == resetX)
128 resetXView();
129 if (action == resetY)
130 resetYView();
131
132 if (action == clear)
133 clearCurves();
134
135 return true;
136 }
137 return false;
138}
Note: See TracBrowser for help on using the repository browser.