[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] | 11 | DataRemote::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] | 35 | DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); }
|
---|
[9] | 36 |
|
---|
[15] | 37 | void 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] | 62 | QAction *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 |
|
---|
| 98 | uint16_t DataRemote::RefreshRate_ms(void) {
|
---|
[15] | 99 | return (uint16_t)(qRound(refresh_rate * 1000.));
|
---|
[9] | 100 | }
|
---|
| 101 |
|
---|
[444] | 102 | uint16_t DataRemote::NbBuffering(void) {
|
---|
| 103 | return nb_buffering;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[15] | 106 | bool DataRemote::IsEnabled(void) { return auto_refresh; }
|
---|
[9] | 107 |
|
---|
[437] | 108 | void 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] | 118 | void 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] | 126 | void 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 | }
|
---|