#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionSalir, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->actionConfiguraci_n, SIGNAL(triggered()), this, SLOT(configurar()));
this->IP_from_config = "192.168.1.190";
estadoReady();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::configurar()
{
Dialog config;
config.exec();
this->IP_from_config = config.IP_address;
}
void MainWindow::inicializando()
{
//Crear colas de comunicación con RRC
socket_client = new CClientSocket();
socket_client->open_socket(this->IP_from_config.toAscii(),"5858");
//Esperar mensaje "RRC Ready"
int num_bytes;
bool b_wait = true;
do
{
num_bytes = socket_client->read_socket();
if(num_bytes > 0)
{
char* aux_msg = socket_client->get_string_from_buffer(num_bytes);
std::string recv_msg(aux_msg,num_bytes);
if (recv_msg.compare("RRC Ready") == 0)
b_wait = false;
}
usleep(1);
}while( b_wait);
std::cout << "Received RRC Ready" << std::endl;
}
void MainWindow::on_button_Conectar_clicked()
{
inicializando();
estadoConectando();
//Send Request
std::string message = "Connection Request";
bool resul;
do{
resul = socket_client->write_socket(message);
usleep(1);
}while(!resul);
std::cout << "Sent Connection Request" << std::endl;
//Esperar mensaje "Connection Complete"
std::string recv_msg;
int num_b;
bool b_wait = true;
do
{
num_b = socket_client->read_socket();
if(num_b > 0)
{
recv_msg = socket_client->get_string_from_buffer(num_b);
if (recv_msg.compare("Connection Complete") == 0)
b_wait = false;
}
usleep(1);
}while( b_wait);
std::cout << "Received Connection Complete" << std::endl;
estadoConectado();
}
void MainWindow::estadoInicial()
{
//Labels
ui
->label
->setText
(QString::fromUtf8("Estado: Inicializando..."));
ui->label_2->setText("");
//Buttons
ui->button_Conectar->setVisible(false);
}
void MainWindow::estadoReady()
{
//Labels
ui
->label
->setText
(QString::fromUtf8("Estado: Preparado."));
ui->label_2->setText("");
//Buttons
ui->button_Conectar->setVisible(true);
}
void MainWindow::estadoConectando()
{
//Start connection
ui
->label
->setText
(QString::fromUtf8("Estado: Conectando..."));
ui->label_2->setText("");
//Update Buttons
ui->button_Conectar->setEnabled(false);
}
void MainWindow::estadoDesconectado()
{
//Labels
ui
->label
->setText
(QString::fromUtf8("Estado: No conectado."));
ui->label_2->setText("");
ui->button_Conectar->setEnabled(true);
}
void MainWindow::estadoConectado()
{
//Labels
ui
->label
->setText
(QString::fromUtf8("Estado: Conectado."));
ui->label_2->setText("");
//Buttons
ui->button_Conectar->setVisible(false);
}
Bookmarks