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

Last change on this file was 455, checked in by Sanahuja Guillaume, 14 months ago

gcs: add compatibility with programs without nb_buffering

File size: 3.7 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 "ConnectionLayout.h"
10
11DataRemote::DataRemote(QString name, QString type, XmlWidget *parent,
12 bool enabled, uint16_t period, uint16_t nb_buffering)
13 : XmlWidget(name, type, parent) {
14 auto_refresh = enabled;
15 is_logging = true;
16 receivesize = 0;
17 refresh_rate = (double)period / 1000.;
18
19 //flair programs without nb buffering have nb_buffering=0, set it to 1 for compatibility
20 if(nb_buffering==0) {
21 this->nb_buffering=1;
22 nbBufferingCompatible=false;
23 } else {
24 this->nb_buffering=nb_buffering;
25 nbBufferingCompatible=true;
26 }
27
28
29 connectionLayout()->addDataRemote(this);
30
31 // pour ne pas faire de doublons qd on change la periode
32 SetIsExpandable(true);
33}
34
35DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
36
37void DataRemote::appendmenu(QMenu *menu) {
38 menu->addSeparator();
39
40 SetAutoRefresh = menu->addAction("auto refresh");
41 SetAutoRefresh->setCheckable(true);
42 SetAutoRefresh->setChecked(auto_refresh);
43
44 setRefreshRate = menu->addAction(QString("set refresh rate (%1ms)")
45 .arg((uint16_t)(qRound(refresh_rate * 1000))));
46 setRefreshRate->setEnabled(auto_refresh);
47
48 //flair programs without nb buffering have nb_buffering=0
49 if(nbBufferingCompatible) {
50 menu->addSeparator();
51 setNbBuffering = menu->addAction(QString("set nb buffering (%1)").arg(nb_buffering));
52 }
53
54/* menu->addSeparator();
55
56 log = menu->addAction("log");
57 log->setCheckable(true);
58 log->setChecked(is_logging);
59 */
60}
61
62QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) {
63 QAction *action;
64
65 action = menu->exec(point);
66 if(action==NULL) return action;//setNbBuffering can also be null if in compatibility mode
67
68 if (action == SetAutoRefresh) {
69 SendPeriod(RefreshRate_ms(), SetAutoRefresh->isChecked());
70 }
71
72 if (action == setRefreshRate) {
73 bool ok;
74
75 uint16_t time = QInputDialog::getInt(
76 parent, "Set refresh rate ", "Value (ms):",
77 (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok);
78 if (ok && time != qRound(refresh_rate * 1000)) {
79 // refresh_rate=time/1000.;
80 SendPeriod(time, SetAutoRefresh->isChecked());
81 }
82 }
83
84 if (action == setNbBuffering) {
85 bool ok;
86
87 uint16_t nb_buffering = QInputDialog::getInt(
88 parent, "Set nb buffering ", "Value :",
89 this->nb_buffering, 1, 65535, 10, &ok);
90 if (ok && nb_buffering !=this->nb_buffering) {
91 SendNbBuffering(nb_buffering);
92 }
93 }
94
95 return action;
96}
97
98uint16_t DataRemote::RefreshRate_ms(void) {
99 return (uint16_t)(qRound(refresh_rate * 1000.));
100}
101
102uint16_t DataRemote::NbBuffering(void) {
103 return nb_buffering;
104}
105
106bool DataRemote::IsEnabled(void) { return auto_refresh; }
107
108void DataRemote::SendPeriod(uint16_t period, bool auto_refresh) {
109 RemoveAllAttributes();
110
111 SetAttribute("period", period);
112 SetAttribute("enabled", auto_refresh);
113 connectionLayout()->XmlToSend(XmlDoc());
114 RemoveAttribute("period");
115 RemoveAttribute("enabled");
116}
117
118void DataRemote::SendNbBuffering(uint16_t nb_buffering) {
119 RemoveAllAttributes();
120
121 SetAttribute("nb_buf", nb_buffering);
122 connectionLayout()->XmlToSend(XmlDoc());
123 RemoveAttribute("nb_buf");
124}
125
126void DataRemote::XmlSetup(QDomElement *dom) {
127 refresh_rate = dom->attribute("period").toUShort() / 1000.;
128 if(nbBufferingCompatible) nb_buffering = dom->attribute("nb_buf").toUShort();
129
130 if (dom->attribute("enabled") == "1")
131 auto_refresh = true;
132 else
133 auto_refresh = false;
134}
Note: See TracBrowser for help on using the repository browser.