source: flair-src/trunk/tools/FlairGCS/src/DataRemote.cpp@ 388

Last change on this file since 388 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: 2.5 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 "DataRemote.h"
6#include <QMenu>
7#include <QInputDialog>
8#include <QtXml>
9#include "Manager.h"
10#include "ConnectionLayout.h"
11
12DataRemote::DataRemote(QString name, QString type, XmlWidget *parent,
13 bool enabled, int period)
14 : XmlWidget(name, type, parent) {
15 auto_refresh = enabled;
16 is_logging = true;
17 receivesize = 0;
18 refresh_rate = (double)period / 1000.;
19
20 connectionLayout()->addDataRemote(this);
21
22 // pour ne pas faire de doublons qd on change la periode
23 SetIsExpandable(true);
24}
25
26DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
27
28void DataRemote::appendmenu(QMenu *menu) {
29 menu->addSeparator();
30
31 autoRefresh = menu->addAction("auto refresh");
32 autoRefresh->setCheckable(true);
33 autoRefresh->setChecked(auto_refresh);
34
35 setRefreshRate = menu->addAction(QString("set refresh rate (%1ms)")
36 .arg((uint16_t)(qRound(refresh_rate * 1000))));
37 setRefreshRate->setEnabled(auto_refresh);
38/* menu->addSeparator();
39
40 log = menu->addAction("log");
41 log->setCheckable(true);
42 log->setChecked(is_logging);
43 */
44}
45
46QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
47 QAction *action;
48
49 action = menu->exec(point);
50
51 // auto_refresh=b->isChecked();
52
53 if (action == autoRefresh) {
54 SendPeriod(RefreshRate_ms(), autoRefresh->isChecked());
55 }
56
57 if (action == setRefreshRate) {
58 bool ok;
59
60 uint16_t time = QInputDialog::getInt(
61 parent, "Set refresh rate ", "Value (ms):",
62 (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
63 if (ok == true && time != qRound(refresh_rate * 1000)) {
64 // refresh_rate=time/1000.;
65 SendPeriod(time, autoRefresh->isChecked());
66 }
67 }
68
69 return action;
70}
71
72uint16_t DataRemote::RefreshRate_ms(void) {
73 return (uint16_t)(qRound(refresh_rate * 1000.));
74}
75
76bool DataRemote::IsEnabled(void) { return auto_refresh; }
77
78void DataRemote::SendPeriod(int period, bool auto_refresh) {
79 RemoveAllAttributes();
80
81 SetAttribute("period", period);
82 SetAttribute("enabled", auto_refresh);
83 connectionLayout()->XmlToSend(XmlDoc());
84 RemoveAttribute("period");
85 RemoveAttribute("enabled");
86}
87
88int DataRemote::ReceiveSize(void) { return receivesize; }
89
90void DataRemote::XmlSetup(QDomElement *dom) {
91 refresh_rate = dom->attribute("period").toInt() / 1000.;
92 if (dom->attribute("enabled") == "1")
93 auto_refresh = true;
94 else
95 auto_refresh = false;
96}
Note: See TracBrowser for help on using the repository browser.