|
1 /** |
|
2 * DetailNode.cpp is part of bmsapp. |
|
3 * |
|
4 * bmsapp is free software: you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation, either version 3 of the License, or |
|
7 * (at your option) any later version. |
|
8 * |
|
9 * bmsapp is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #include "DetailNode.h" |
|
18 #include "ChartCarbonate.h" |
|
19 #include "../ui/ui_DetailNode.h" |
|
20 #include "global.h" |
|
21 #include "MainWindow.h" |
|
22 |
|
23 |
|
24 /* |
|
25 * Results are available via MySQL and websockets. Because we initialize using |
|
26 * MySQL we only use that for the results and up to date status. |
|
27 * Commands are send via websockets only. |
|
28 */ |
|
29 |
|
30 DetailNode::DetailNode(int id, QWidget *parent) : QDialog(parent), ui(new Ui::DetailNode) |
|
31 { |
|
32 QSqlQuery query; |
|
33 |
|
34 qDebug() << "DetailNode record:" << id; |
|
35 ui->setupUi(this); |
|
36 this->recno = id; |
|
37 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
|
38 setWindowTitle(tr("BMSapp - Details System")); |
|
39 |
|
40 connect(ui->rebootButton, SIGNAL(clicked()), this, SLOT(control_reboot())); |
|
41 connect(ui->rebirthButton, SIGNAL(clicked()), this, SLOT(control_rebirth())); |
|
42 connect(parent, SIGNAL(updateNode(QString)), this, SLOT(refreshNode(QString))); |
|
43 emit refreshTable(); |
|
44 } |
|
45 |
|
46 |
|
47 void DetailNode::refreshTable() |
|
48 { |
|
49 QSqlQuery query; |
|
50 |
|
51 qDebug() << "refreshTable node rec:" << this->recno; |
|
52 |
|
53 query.prepare("SELECT * FROM mon_nodes WHERE record = :recno"); |
|
54 query.bindValue(":recno", this->recno); |
|
55 query.exec(); |
|
56 if (query.next()) { |
|
57 |
|
58 _node = query.value("node").toString(); |
|
59 _group_id = query.value("group_id").toString(); |
|
60 _uuid = query.value("uuid").toString(); |
|
61 |
|
62 ui->uuidEdit->setText(_uuid); |
|
63 ui->systemEdit->setText(_node); |
|
64 ui->typeEdit->setText(_group_id); |
|
65 ui->firstEdit->setText(query.value("firstseen").toDateTime().toString("dd MMM yyyy HH:mm:ss")); |
|
66 ui->lastEdit->setText(query.value("lastseen").toDateTime().toString("dd MMM yyyy HH:mm:ss")); |
|
67 |
|
68 if (query.value("online").toInt()) { |
|
69 ui->statusEdit->setText(tr("Online")); |
|
70 ui->makerEdit->show(); |
|
71 ui->modelEdit->show(); |
|
72 ui->osEdit->show(); |
|
73 ui->fwEdit->show(); |
|
74 ui->makerLabel->show(); |
|
75 ui->modelLabel->show(); |
|
76 ui->osLabel->show(); |
|
77 ui->fwLabel->show(); |
|
78 ui->intervalLabel->show(); |
|
79 ui->intervalEdit->show(); |
|
80 ui->makerEdit->setText(query.value("hardwaremake").toString()); |
|
81 ui->modelEdit->setText(query.value("hardwaremodel").toString()); |
|
82 ui->osEdit->setText(query.value("os").toString()+QString(tr(" version: "))+query.value("os_version").toString()); |
|
83 ui->fwEdit->setText(query.value("firmware").toString()); |
|
84 ui->intervalEdit->setValue(query.value("up_interval").toInt()); |
|
85 |
|
86 if (query.value("temperature").toDouble() > 0) { |
|
87 ui->tempLabel->show(); |
|
88 ui->tempEdit->show(); |
|
89 ui->tempEdit->setValue(query.value("temperature").toDouble()); |
|
90 } else { |
|
91 ui->tempLabel->hide(); |
|
92 ui->tempEdit->hide(); |
|
93 } |
|
94 if (query.value("humidity").toDouble() > 0) { |
|
95 ui->humLabel->show(); |
|
96 ui->humEdit->show(); |
|
97 ui->humEdit->setValue(query.value("humidity").toDouble()); |
|
98 } else { |
|
99 ui->humLabel->hide(); |
|
100 ui->humEdit->hide(); |
|
101 } |
|
102 if (query.value("barometer").toDouble() > 0) { |
|
103 ui->baroLabel->show(); |
|
104 ui->baroEdit->show(); |
|
105 ui->baroEdit->setValue(query.value("barometer").toDouble()); |
|
106 } else { |
|
107 ui->baroLabel->hide(); |
|
108 ui->baroEdit->hide(); |
|
109 } |
|
110 |
|
111 ui->networkLabel->show(); |
|
112 ui->networkEdit->show(); |
|
113 ui->networkEdit->setText(query.value("net_ifname").toString()+" "+query.value("net_address").toString()); |
|
114 |
|
115 if (query.value("net_ssid").toString() != "") { |
|
116 ui->ssidLabel->show(); |
|
117 ui->ssidEdit->show(); |
|
118 ui->ssidEdit->setText(query.value("net_ssid").toString()); |
|
119 ui->rssiLabel->show(); |
|
120 ui->rssiEdit->show(); |
|
121 if (query.value("net_rssi").toInt() < 0) |
|
122 ui->rssiEdit->setValue(query.value("net_rssi").toInt()); |
|
123 } else { |
|
124 ui->ssidLabel->hide(); |
|
125 ui->ssidEdit->hide(); |
|
126 ui->rssiLabel->hide(); |
|
127 ui->rssiEdit->hide(); |
|
128 } |
|
129 |
|
130 } else { |
|
131 /* Offline */ |
|
132 ui->statusEdit->setText(tr("Offline")); |
|
133 |
|
134 ui->makerEdit->hide(); |
|
135 ui->modelEdit->hide(); |
|
136 ui->osEdit->hide(); |
|
137 ui->fwEdit->hide(); |
|
138 ui->makerLabel->hide(); |
|
139 ui->modelLabel->hide(); |
|
140 ui->osLabel->hide(); |
|
141 ui->fwLabel->hide(); |
|
142 ui->intervalLabel->hide(); |
|
143 ui->intervalEdit->hide(); |
|
144 |
|
145 ui->tempLabel->hide(); |
|
146 ui->tempEdit->hide(); |
|
147 ui->humLabel->hide(); |
|
148 ui->humEdit->hide(); |
|
149 ui->baroLabel->hide(); |
|
150 ui->baroEdit->hide(); |
|
151 |
|
152 ui->networkLabel->hide(); |
|
153 ui->networkEdit->hide(); |
|
154 ui->ssidLabel->hide(); |
|
155 ui->ssidEdit->hide(); |
|
156 ui->rssiLabel->hide(); |
|
157 ui->rssiEdit->hide(); |
|
158 } |
|
159 } |
|
160 |
|
161 } |
|
162 |
|
163 |
|
164 DetailNode::~DetailNode() |
|
165 { |
|
166 qDebug() << "DetailNode done"; |
|
167 delete ui; |
|
168 emit entry_changed(); |
|
169 } |
|
170 |
|
171 |
|
172 /* |
|
173 * Receive signals destined for all co2meters. |
|
174 * Check if the signal is for us. |
|
175 */ |
|
176 void DetailNode::refreshNode(QString data) |
|
177 { |
|
178 if (_node == data) { |
|
179 emit refreshTable(); |
|
180 } |
|
181 } |
|
182 |
|
183 |
|
184 void DetailNode::on_quitButton_clicked() |
|
185 { |
|
186 this->close(); |
|
187 this->setResult(1); |
|
188 } |
|
189 |
|
190 |
|
191 void DetailNode::control_reboot() |
|
192 { |
|
193 int rc = QMessageBox::warning(this, tr("Reboot application"), tr("Remote applicaation is running, really reboot?"), |
|
194 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
|
195 |
|
196 if (rc == QMessageBox::No) |
|
197 return; |
|
198 |
|
199 QString msg = QString("{\"node\":\""+_node+"\",\"group_id\":\""+_group_id+"\",\"control\":\"reboot\"}"); |
|
200 qDebug() << msg; |
|
201 webSocket->sendTextMessage(msg); |
|
202 } |
|
203 |
|
204 |
|
205 void DetailNode::control_rebirth() |
|
206 { |
|
207 QString msg = QString("{\"node\":\""+_node+"\",\"group_id\":\""+_group_id+"\",\"control\":\"rebirth\"}"); |
|
208 qDebug() << msg; |
|
209 webSocket->sendTextMessage(msg); |
|
210 } |
|
211 |
|
212 |