ITS
Fac2App.cpp
Go to the documentation of this file.
1 #include "include/Fac2App.h"
2 
3 #include <QThread>
4 Fac2App::Fac2App(QBluetoothSocket *bt, ParameterDENM *denm)
5 {
6  btSocket = bt;
7  udpSocket = new QUdpSocket;
8 
9  udpSocket->open(QIODevice::ReadOnly);
10 // host = denm->eventIndicationAddress();
11 // port = denm->eventIndicationPort();
12  udpSocket->bind(QHostAddress(host), port);
13 
14  QObject::connect(udpSocket, SIGNAL(readyRead()), this, SLOT(sendMessageToApplication()));
15 }
16 
18 {
19  int foo;
20  QObject::disconnect(udpSocket, SIGNAL(readyRead()), this, SLOT(sendMessageToApplication()));
21  do
22  {
23  udpSocket->waitForReadyRead(-1);
24  if(udpSocket->hasPendingDatagrams())
25  {
26  QNetworkDatagram datagram = udpSocket->receiveDatagram();
27  if(btSocket)
28  {
29  if(!btSocket->isOpen())
30  {
31  btSocket->open(QIODevice::ReadWrite);
32  qDebug() << "Opening btSocket";
33  }
34  foo = btSocket->write(datagram.data());
35  if(foo < 0)
36  qDebug() << "Can't send" << datagram.data().toHex() << "to" << btSocket->peerAddress().toString();
37  else
38  qDebug() << datagram.data().toHex() << "sent to" << btSocket->peerAddress().toString() << "(" << foo
39  << "/" << datagram.data().length() << "bytes ) by" << btSocket;
40  //QThread::msleep(1000);
41  }
42  else
43  qDebug() << "Can't send" << datagram.data().toHex() << ", no client connected";
44  }
45  else
46  qInfo() << "No datagram received in Fac2App";
47  }while(true);
48 }
49 
50 void Fac2App::newBTSocket(QBluetoothSocket *bt)
51 {
52  btSocket = bt;
53  qDebug() << "New btSocket in F2A";
54 }
QString host
Definition: Fac2App.h:24
QBluetoothSocket * btSocket
Definition: Fac2App.h:22
quint16 port
Definition: Fac2App.h:25
void sendMessageToApplication()
Definition: Fac2App.cpp:17
void newBTSocket(QBluetoothSocket *bt)
Definition: Fac2App.cpp:50
Fac2App(QBluetoothSocket *bt, ParameterDENM *denm)
Definition: Fac2App.cpp:4
QUdpSocket * udpSocket
Definition: Fac2App.h:23