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

Last change on this file since 468 was 455, checked in by Sanahuja Guillaume, 3 years ago

gcs: add compatibility with programs without nb_buffering

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