⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Commit 6326cbe

Browse files
committed
Merge pull request #13 from darkjavi/master
Mejoras en la aplicacion movil
2 parents eea4989 + eb8b811 commit 6326cbe

File tree

16 files changed

+1178
-49
lines changed

16 files changed

+1178
-49
lines changed

Software/JarvisServer/common/gnodecomponentwidget.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QHBoxLayout>
55
#include "qimageselectionwidget.h"
66
#include <QColorDialog>
7+
#include <QLabel>
78

89
gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *parent) :
910
QGroupBox(parent), m_component(comp),
@@ -19,7 +20,8 @@ gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *p
1920
jarvisActions action = actions[i];
2021
//qDebug() << QString::number(int(action));
2122
QToolButton* b = new QToolButton(ui->actionsBox);
22-
ui->actionsBox->layout()->addWidget(b);
23+
QGridLayout* l = (QGridLayout*)ui->actionsBox->layout();
24+
l->addWidget(b,l->count()/2,l->count()%2);
2325
b->setText(QString::number(action,'f',0));
2426

2527
if (action == A_ENABLE){
@@ -78,48 +80,66 @@ gNodeComponentWidget::gNodeComponentWidget(sJarvisNodeComponent* comp,QWidget *p
7880
for(int i = 0 ; i < events.count() ; i++)
7981
{
8082
gBlinkWidget* w = new gBlinkWidget(ui->eventsBox);
81-
ui->eventsBox->layout()->addWidget(w);
83+
QLabel* label = new QLabel(ui->eventsBox);
84+
QGridLayout* l = (QGridLayout*)ui->eventsBox->layout();
85+
l->addWidget(label,i,0);
86+
l->addWidget(w,i,1);
87+
w->setMaximumHeight(50);
8288
if(events[i] == E_ACTIVATED)
8389
{
8490
connect(m_component,SIGNAL(activated()),w,SLOT(blink()));
91+
label->setText("Activated");
8592

8693
}else if(events[i] == E_DEACTIVATED)
8794
{
8895
connect(m_component,SIGNAL(deactivated()),w,SLOT(blink()));
96+
label->setText("Deactivated");
8997

9098
}else if(events[i] == E_ENABLED)
9199
{
92100
connect(m_component,SIGNAL(enabled()),w,SLOT(blink()));
101+
label->setText("Enabled");
93102

94103
}else if(events[i] == E_DISABLED)
95104
{
96105
connect(m_component,SIGNAL(disabled()),w,SLOT(blink()));
106+
label->setText("Disabled");
97107

98108
}else if(events[i] == E_RAW_READ)
99109
{
100110
connect(m_component,SIGNAL(rawRead()),w,SLOT(blink()));
101111
connect(m_component,SIGNAL(rawRead(QStringList)),w,SLOT(displayRead(QStringList)));
112+
label->setText("Raw");
102113

103114
}else if(events[i] == E_DATA_READ)
104115
{
105116
connect(m_component,SIGNAL(dataRead()),w,SLOT(blink()));
106117
connect(m_component,SIGNAL(dataRead(QStringList)),w,SLOT(displayRead(QStringList)));
118+
label->setText("Data");
107119

108120
}else if(events[i] == E_GLOBAL_POWERON)
109121
{
110122
connect(m_component,SIGNAL(globalPowerOn()),w,SLOT(blink()));
123+
label->setText("PowerOn");
111124

112125
}else if(events[i] == E_GLOBAL_SHUTDOWN)
113126
{
114127
connect(m_component,SIGNAL(globalShutDown()),w,SLOT(blink()));
128+
label->setText("PowerOff");
115129

116130
}else if(events[i] == E_COFFEE_MAKING)
117131
{
118132
connect(m_component,SIGNAL(coffeeMaking()),w,SLOT(blink()));
133+
label->setText("Coffee Making");
119134

120135
}else if(events[i] == E_COFFEE_MADE)
121136
{
122137
connect(m_component,SIGNAL(coffeeMade()),w,SLOT(blink()));
138+
label->setText("Cofee Made");
139+
}
140+
else
141+
{
142+
label->setText("Unknown");
123143
}
124144
//w->setMinimumSize(32,32);
125145
//w->setMaximumSize(32,32);

Software/JarvisServer/common/gnodecomponentwidget.ui

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>445</width>
10-
<height>95</height>
9+
<width>335</width>
10+
<height>93</height>
1111
</rect>
1212
</property>
1313
<property name="font">
1414
<font>
1515
<pointsize>8</pointsize>
16+
<weight>75</weight>
17+
<bold>true</bold>
1618
</font>
1719
</property>
1820
<property name="windowTitle">
@@ -56,7 +58,7 @@
5658
<property name="title">
5759
<string>Actions</string>
5860
</property>
59-
<layout class="QFormLayout" name="formLayout"/>
61+
<layout class="QGridLayout" name="gridLayout_2"/>
6062
</widget>
6163
</item>
6264
<item>

Software/JarvisServer/common/sjarvisnode.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sJarvisNode::sJarvisNode(QObject* parent) : QObject(parent)
99
connect(&m_tcpClient,SIGNAL(rx()),this,SIGNAL(rx()));
1010
connect(&m_pingTimer,SIGNAL(timeout()),this,SLOT(ping()));
1111
connect(&m_initTimer,SIGNAL(timeout()),this,SLOT(initDone()));
12+
connect(&m_initTimeout,SIGNAL(timeout()),this,SLOT(initTimeout()));
1213
//Slots del nodo tcp
1314
//connect(&m_tcpClient,SIGNAL(socket_rx(QByteArray)),this,SLOT(data_rx(QByteArray)));
1415
connect(this,SIGNAL(writeData(QByteArray)),&m_tcpClient,SLOT(socket_tx(QByteArray)));
@@ -104,6 +105,7 @@ void sJarvisNode::parsePacket(QString& packet)
104105
void sJarvisNode::parseComponent(QStringList args)
105106
{
106107
if(m_initDone) return;
108+
m_initTimer.start(200);
107109
m_components.append(new sJarvisNodeComponent(this,args));
108110
connect(this,SIGNAL(incomingEvent(QString,jarvisEvents,QStringList)),m_components.last(),SLOT(parseEvent(QString,jarvisEvents,QStringList)));
109111
emit newComponent(m_components.last());
@@ -187,6 +189,8 @@ void sJarvisNode::sendGetID()
187189

188190
void sJarvisNode::sendGetComponents()
189191
{
192+
deleteComponents();
193+
m_initDone = false;
190194
send(encodeNodeMsg(QStringList(QString(C_GETCOMPONENTS))));
191195
}
192196

@@ -240,7 +244,7 @@ void sJarvisNode::initNode()
240244
connect(&m_tcpClient,SIGNAL(socket_rx(QByteArray)),this,SLOT(validateClient(QByteArray)));
241245
send(encodeNodeMsg(QStringList(QString(M_JARVIS_GREETING))));
242246
// le damos un segundo para que reciba de vuelta la informacion, al cumplir el segundo se llama a la funcion initDone()
243-
m_initTimer.start(750);
247+
m_initTimeout.start(5000);
244248
}
245249

246250

@@ -284,6 +288,7 @@ void sJarvisNode::initDone()
284288
{
285289

286290
m_initTimer.stop();
291+
m_initTimeout.stop();
287292

288293
if(m_id.isEmpty() || m_components.isEmpty())
289294
{
@@ -302,6 +307,12 @@ void sJarvisNode::initDone()
302307
emit ready();
303308
}
304309

310+
void sJarvisNode::initTimeout()
311+
{
312+
closeTCP();
313+
m_initTimeout.stop();
314+
}
315+
305316
void sJarvisNode::socketDisconected()
306317
{
307318
disconnect(&m_tcpClient,SIGNAL(socket_rx(QByteArray)),this,SLOT(data_rx(QByteArray)));
@@ -343,3 +354,15 @@ void sJarvisNode::pollSensor(QString sen, int interval)
343354
else
344355
sendPollSensor(sen,interval);
345356
}
357+
358+
void sJarvisNode::stopPollingSensors()
359+
{
360+
sendStopPolling();
361+
}
362+
363+
void sJarvisNode::resetNode()
364+
{
365+
QStringList args;
366+
args.append(C_RESET);
367+
send(encodeNodeMsg(args));
368+
}

Software/JarvisServer/common/sjarvisnode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class sJarvisNode :public QObject
3838
QList<sJarvisNodeComponent*> m_components;
3939
QTimer m_pingTimer;
4040
QTimer m_initTimer;
41+
QTimer m_initTimeout;
4142
QTime m_keepAliveTimer;
4243
bool m_initDone;
4344
bool m_valid;
@@ -76,11 +77,15 @@ protected slots:
7677
void ping();
7778
void pong();
7879
void initDone();
80+
void initTimeout();
7981
void socketDisconected();
8082
void setUpdateInterval(int interval);
8183
public slots:
8284
void doAction(QString Component, jarvisActions action, QStringList args = QStringList());
8385
void pollSensor(QString sen = "ALL",int interval = -1);
86+
void stopPollingSensors();
87+
void resetNode();
88+
void getComponents() {sendGetComponents();}
8489

8590
};
8691

Software/JarvisServer/jarvisnodetestapp.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "jarvisnodetestapp.h"
22
#include "ui_jarvisnodetestapp.h"
3+
#include <QGridLayout>
34

45
jarvisNodeTestApp::jarvisNodeTestApp(sJarvisNode* node, QWidget *parent) :
56
QMainWindow(parent),
@@ -40,7 +41,8 @@ void jarvisNodeTestApp::connectNodeSignals(sJarvisNode* node)
4041
connect(node,SIGNAL(sensorReads(QVector<QString>,QVector<double>)),this,SLOT(sensorRead(QVector<QString>,QVector<double>)));
4142
connect(node,SIGNAL(ready()),this,SLOT(nodeConnected()));
4243
connect(node,SIGNAL(disconnected()),this,SLOT(nodeDisconnected()));
43-
connect(ui->sliderUpdateInterval,SIGNAL(sliderMoved(int)),m_node,SLOT(setUpdateInterval(int)));
44+
connect(ui->sliderUpdateInterval,SIGNAL(sliderMoved(int)),node,SLOT(setUpdateInterval(int)));
45+
connect(ui->btnReset,SIGNAL(clicked()),node,SLOT(resetNode()));
4446
}
4547

4648
sJarvisNode* jarvisNodeTestApp::newNode()
@@ -70,9 +72,12 @@ void jarvisNodeTestApp::nodeConnected()
7072
{
7173
sJarvisNodeComponent* ncomp = comps[i];
7274
gNodeComponentWidget* w = new gNodeComponentWidget(ncomp,ui->scrollComponents);
73-
ui->scrollComponentsContents->layout()->addWidget(w);
75+
QGridLayout* l = (QGridLayout*)ui->scrollComponentsContents->layout();
76+
l->addWidget(w);
77+
//l->addWidget(w,l->count()/2,l->count()%2);
7478
m_componentWidgets.append(w);
7579
}
80+
m_statusLabel.setText("Node connected!");
7681
}
7782

7883
void jarvisNodeTestApp::nodeDisconnected()
@@ -84,14 +89,17 @@ void jarvisNodeTestApp::nodeDisconnected()
8489
m_componentWidgets.clear();
8590
m_sensorsTimer.stop();
8691
ui->connectBtn->setChecked(false);
92+
m_statusLabel.setText("Node disconnected!");
8793
}
8894

8995
void jarvisNodeTestApp::on_connectBtn_clicked()
9096
{
9197
if(ui->connectBtn->isChecked())
9298
{
9399
int port = ui->editPort->text().toInt();
94-
qDebug() << "Connecting-" << ui->editIP->text() << ":" << QString::number(port);
100+
QString status;
101+
status += "Connecting-" + ui->editIP->text() + ":" + QString::number(port);
102+
m_statusLabel.setText(status);
95103
m_node->connectTCP(ui->editIP->text(),port);
96104
}
97105
else
@@ -110,6 +118,31 @@ void jarvisNodeTestApp::on_sendCmdBtn_clicked()
110118
m_node->send(ui->editCommand->text().toUtf8());
111119
}
112120

121+
void jarvisNodeTestApp::on_stopReadBtn_clicked()
122+
{
123+
m_node->stopPollingSensors();
124+
}
125+
126+
void jarvisNodeTestApp::on_btnGetComps_clicked()
127+
{
128+
for(int i = 0; i < m_componentWidgets.count() ; i++)
129+
{
130+
m_componentWidgets[i]->deleteLater();
131+
}
132+
m_componentWidgets.clear();
133+
m_node->getComponents();
134+
}
135+
136+
void jarvisNodeTestApp::on_btnClearGraphs_clicked()
137+
{
138+
for(int i = 0 ; i < m_graphs.count() ; i++)
139+
{
140+
m_graphs[i]->deleteLater();
141+
}
142+
m_graphInit = false;
143+
m_graphs.clear();
144+
}
145+
113146
void jarvisNodeTestApp::console_log(QByteArray data)
114147
{
115148
ui->editConsole->appendPlainText(data);
@@ -130,8 +163,9 @@ void jarvisNodeTestApp::eventLog(QString component, jarvisEvents event, QStringL
130163
ui->editEventlog->append(result);
131164
}
132165

166+
133167
void jarvisNodeTestApp::sensorRead(QVector<QString> fields,QVector<double> data)
134-
{
168+
{
135169
if(!m_graphInit)
136170
{
137171
for(int i = 0; i < fields.count() ; i++ )
@@ -142,7 +176,6 @@ void jarvisNodeTestApp::sensorRead(QVector<QString> fields,QVector<double> data)
142176
QVector<double> d;
143177
f.append(fields[i]);
144178
g->setFields(f);
145-
d.append(0);
146179
g->appendData(d);
147180
m_graphs.append(g);
148181
}

Software/JarvisServer/jarvisnodetestapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public slots:
4646
void on_readComponentsBtn_clicked();
4747
void on_connectBtn_clicked();
4848
void on_sendCmdBtn_clicked();
49+
void on_stopReadBtn_clicked();
50+
void on_btnGetComps_clicked();
51+
void on_btnClearGraphs_clicked();
4952
void console_log(QByteArray data);
5053
void eventLog(QString component,jarvisEvents event,QStringList args);
5154
void sensorRead(QVector<QString> fields,QVector<double> data);

0 commit comments

Comments
 (0)