20 QBluetoothLocalDevice localAdapter;
21 QString localDeviceName;
23 rfcommServer =
new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol,
this);
26 if(localAdapter.isValid())
29 qInfo() <<
"Turning on Bluetooth device";
30 localAdapter.powerOn();
33 qInfo() <<
"Reading Bluetooth device name";
34 localDeviceName = localAdapter.name();
35 qInfo() <<
"Local adapter is named" << localDeviceName;
38 qInfo() <<
"Making Bluetooth device visible";
39 localAdapter.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
43 qWarning() <<
"Cannot bind application manager to" << localAdapter.address().toString();
48 qInfo() <<
"Listening to" << localAdapter.address().toString();
54 serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr(
"DENM BT forwarder"));
55 serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, tr(
"Forward DENM from and to Android"));
56 serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr(
"URCA"));
57 qInfo() <<
"Textual description set";
60 QBluetoothServiceInfo::Sequence classId;
61 static const QLatin1String serviceUuid(
"76931fac-9dab-2b36-9ccf-c248b87d6ae3");
64 classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
65 serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, classId);
67 classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid)));
69 serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
71 serviceInfo.setServiceUuid(QBluetoothUuid(serviceUuid));
72 qInfo() <<
"UUID set to" <<
serviceInfo.serviceUuid();
73 qInfo() <<
"ServicesClassInfo" <<
serviceInfo.serviceClassUuids();
76 QBluetoothServiceInfo::Sequence publicBrowse;
77 publicBrowse << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
78 serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, publicBrowse);
79 qInfo() <<
"BT discoverable";
82 QBluetoothServiceInfo::Sequence protocolDescriptorList;
83 QBluetoothServiceInfo::Sequence protocol;
84 protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
85 protocolDescriptorList.append(QVariant::fromValue(protocol));
87 protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
88 << QVariant::fromValue(quint8(
rfcommServer->serverPort()));
89 protocolDescriptorList.append(QVariant::fromValue(protocol));
90 serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList);
94 bool foo =
serviceInfo.registerService(localAdapter.address());
95 qInfo() <<
"Service registration" << foo;
107 qWarning() <<
"No connected Bluetooth device found";
120 qDebug() <<
"Application" <<
m_udpSocket->localPort();
130 qDebug() <<
"ApplicationUT" <<
m_utSocket->localPort();
139 qDebug() <<
"Deleting application management";
156 QBluetoothSocket *socket =
rfcommServer->nextPendingConnection();
160 qInfo() <<
"There is a new client connected" << socket->peerName();
169 QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender());
173 qInfo() <<
"Receiving data from BT";
174 QByteArray line = socket->readAll();
175 qInfo() << line.toHex() <<
"received from" << socket->peerName();
181 QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender());
185 qInfo() << socket->peerName() <<
"disconnected";
187 socket->deleteLater();
195 qInfo() <<
"I have to sent" << message.toHex() <<
"to BT / UT";
200 qInfo() <<
"Sending" << message.toHex() <<
"to" << socket->peerName();
202 qInfo() <<
"Sending" << msg.toHex() <<
"to BT";
203 size = socket->write(msg);
204 qInfo() << size <<
"Bytes sent to BT";
209 quint16 utPort =
getUtPort(message.at(0));
212 m_udpSocket->writeDatagram(message, QHostAddress::LocalHost, utPort);
213 qDebug() << message.toHex() <<
"sent to UT" << utPort;
216 qInfo() <<
"This message is not supposed to be sent to UT";
222 QUdpSocket *socket = qobject_cast<QUdpSocket*>(sender());
223 while(socket->hasPendingDatagrams())
225 qDebug() << socket->localPort() <<
"in readUdpSocket" << socket->state();
226 QNetworkDatagram datagram = socket->receiveDatagram();
227 qInfo() << datagram.data().toHex() <<
"received from facilities";
229 qInfo() <<
"readUdpSocket emit data";
237 switch (message.at(0))
254 QNetworkDatagram datagram =
m_utSocket->receiveDatagram();
256 qInfo() << datagram.data().toHex() <<
"received from UT";
263 QByteArray ret = message;
266 long unsigned int detectionTime;
273 if(denm->denm.management.validityDuration)
274 validity = *denm->denm.management.validityDuration;
276 qInfo() <<
"Transforming AppDENMIndication";
278 qInfo() << ret.toHex();
291 switch((
unsigned char)mt)
int upperTesterEventIndicationListenPort() const
upperTesterEventIndicationListenPort Port used to listen for event indication getter.
void clientConnected()
clientConnected Slot used when a new client is connected.
void sendMessageToBt(const QByteArray &message)
sendMessageToBt Slot used to send message through the Bluetooth socket.
asn_dec_rval_t uper_decode_complete(struct asn_codec_ctx_s *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const void *buffer, size_t size)
ParameterNetwork * m_network
void btMessageReceived(const QByteArray &message)
btMessageReceived Signal used when data come through the Bluetooth socket.
static QByteArray toBluetooth(DENM_t denm, quint32 validityDuration)
toBluetooth Encode an AppDenmIndication understable by the HMI.
QHash< QString, void * > hashMap
quint64 timestamp()
timestamp Timestamp getter.
QList< QBluetoothSocket * > clientSockets
QByteArray transformMessageToBT(const QByteArray &message)
transformMessageToBT Transform message from Facilities to send to the HMI.
void sendMessageToFac(const QByteArray &message)
sendMessageToFac Slot used to send message to the Facilities layer.
void udpMessageReceived(const QByteArray &message)
udpMessageReceived Signal used when data come through the UDP socket.
~ApplicationManagement()
~ApplicationManagement ApplicationManagement destructor
void readUdpSocket()
readUdpSocket Slot used when data come to the UDP socket.
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l)
quint16 internalPort(QString service)
internalPort Get the internal BTP port from service name.
QBluetoothServer * rfcommServer
void addPort(QString service, quint16 port)
addPort Add BTP port to the internal BTP ports from service name.
QBluetoothServiceInfo serviceInfo
void utMessageReceived(const QByteArray &message)
utMessageReceived Signal used when data come from the Uppertester.
int asn_fprint(FILE *stream, asn_TYPE_descriptor_t *td, const void *struct_ptr)
void clientDisconnected()
clientDisconnected Slot used when a client is disconnected.
quint16 getUtPort(const char mt)
getUtPort Get the UpperTester port from MessageType.
ApplicationManagement(Manager *man, bool bt, bool ut, bool app)
ApplicationManagement ApplicationManagement constructor.
void situationChanged()
situationChanged Slot used when GPS or CAN bus have a new value.
void readUtSocket()
readUtSocket Slot used when data come to the UpperTester socket.
ParameterUpperTester * m_ut
asn_TYPE_descriptor_t asn_DEF_DENM
void readBtSocket()
readBtSocket Slot used when data come to the Bluetooth socket.
Manager of the Application layer.