implemented keep alive
This commit is contained in:
parent
ab169f404e
commit
1be53b8925
3 changed files with 40 additions and 4 deletions
|
@ -47,3 +47,8 @@ contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ANDROID_ABIS = armeabi-v7a
|
ANDROID_ABIS = armeabi-v7a
|
||||||
|
|
||||||
|
contains(ANDROID_TARGET_ARCH,) {
|
||||||
|
ANDROID_ABIS = \
|
||||||
|
armeabi-v7a
|
||||||
|
}
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
|
OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->ble = new QBluetoothLeUart();
|
this->ble = new QBluetoothLeUart();
|
||||||
|
this->ble->setUUIDs("92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
|
||||||
this->displayTextModel = new OmobiDisplayTextModel(this);
|
this->displayTextModel = new OmobiDisplayTextModel(this);
|
||||||
this->textSetsBuffer.clear();
|
this->textSetsBuffer.clear();
|
||||||
this->displayBrightness = -1;
|
this->displayBrightness = -1;
|
||||||
this->waitingCommands = 0;
|
this->waitingCommands = 0;
|
||||||
|
|
||||||
|
this->keepAliveTimer = new QTimer(this);
|
||||||
|
this->keepAliveTimer->setInterval(5000);
|
||||||
|
this->keepAliveTimer->setSingleShot(false);
|
||||||
|
connect(this->keepAliveTimer, &QTimer::timeout, this, &OmobiDisplayBackend::sendBluetoothKeepAlive);
|
||||||
|
|
||||||
connect(this->ble, &QBluetoothLeUart::stateChanged, this, &OmobiDisplayBackend::handleBluetoothStateChange);
|
connect(this->ble, &QBluetoothLeUart::stateChanged, this, &OmobiDisplayBackend::handleBluetoothStateChange);
|
||||||
connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
|
connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
|
||||||
connect(this->ble, &QBluetoothLeUart::dataReceived, this, &OmobiDisplayBackend::handleBluetoothDataReceived);
|
connect(this->ble, &QBluetoothLeUart::dataReceived, this, &OmobiDisplayBackend::handleBluetoothDataReceived);
|
||||||
|
@ -56,6 +62,11 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::Bluetooth
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(state == QBluetoothLeUart::Connected)
|
||||||
|
this->keepAliveTimer->start();
|
||||||
|
else if(this->keepAliveTimer->isActive())
|
||||||
|
this->keepAliveTimer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OmobiDisplayBackend::handleBluetoothDeviceConected() {
|
void OmobiDisplayBackend::handleBluetoothDeviceConected() {
|
||||||
|
@ -110,6 +121,14 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar
|
||||||
this->ble->sendData(doc.toJson(QJsonDocument::Compact));
|
this->ble->sendData(doc.toJson(QJsonDocument::Compact));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OmobiDisplayBackend::sendBluetoothKeepAlive() {
|
||||||
|
QJsonDocument doc = QJsonDocument::fromVariant(QVariantMap{{"header", KeepAliveCommand}});
|
||||||
|
|
||||||
|
qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
|
this->ble->sendData(doc.toJson(QJsonDocument::Compact));
|
||||||
|
}
|
||||||
|
|
||||||
void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
|
void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
|
||||||
qDebug() << "New data: \n" << qPrintable(s);
|
qDebug() << "New data: \n" << qPrintable(s);
|
||||||
|
|
||||||
|
@ -124,6 +143,13 @@ void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
|
||||||
OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt());
|
OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt());
|
||||||
|
|
||||||
switch (header) {
|
switch (header) {
|
||||||
|
case AuthorizeSessionCommand: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KeepAliveCommand: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GetAllTextSetsCommand: {
|
case GetAllTextSetsCommand: {
|
||||||
// indicates that all existing txt sets have been sent over after GetAllTextSetsCommand was called
|
// indicates that all existing txt sets have been sent over after GetAllTextSetsCommand was called
|
||||||
if(status != Success)
|
if(status != Success)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define OMOBIDISPLAYBACKEND_H
|
#define OMOBIDISPLAYBACKEND_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
#include <qbluetoothleuart.h>
|
#include <qbluetoothleuart.h>
|
||||||
|
@ -31,6 +32,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum OmobiDisplayCommand {
|
enum OmobiDisplayCommand {
|
||||||
|
AuthorizeSessionCommand = 0,
|
||||||
|
KeepAliveCommand = 1,
|
||||||
GetAllTextSetsCommand = 10,
|
GetAllTextSetsCommand = 10,
|
||||||
GetTextSetParameterCommand = 11,
|
GetTextSetParameterCommand = 11,
|
||||||
GetDisplayBrightnessCommand = 12,
|
GetDisplayBrightnessCommand = 12,
|
||||||
|
@ -45,6 +48,7 @@ private:
|
||||||
|
|
||||||
OmobiDisplayAppState state;
|
OmobiDisplayAppState state;
|
||||||
QBluetoothLeUart *ble;
|
QBluetoothLeUart *ble;
|
||||||
|
QTimer *keepAliveTimer;
|
||||||
OmobiDisplayTextModel* displayTextModel;
|
OmobiDisplayTextModel* displayTextModel;
|
||||||
int waitingCommands;
|
int waitingCommands;
|
||||||
QList<QMap<int, QVariant>> textSetsBuffer;
|
QList<QMap<int, QVariant>> textSetsBuffer;
|
||||||
|
@ -68,6 +72,7 @@ private slots:
|
||||||
void handleDisplayTextModelRowsRemoved(const QModelIndex &parent, int first, int last);
|
void handleDisplayTextModelRowsRemoved(const QModelIndex &parent, int first, int last);
|
||||||
|
|
||||||
void sendBluetoothCommand(OmobiDisplayCommand command, QVariant data = QVariant());
|
void sendBluetoothCommand(OmobiDisplayCommand command, QVariant data = QVariant());
|
||||||
|
void sendBluetoothKeepAlive();
|
||||||
void handleBluetoothDataReceived(QString s);
|
void handleBluetoothDataReceived(QString s);
|
||||||
void updateDisplayTextSetParameter(int index, int parameter);
|
void updateDisplayTextSetParameter(int index, int parameter);
|
||||||
void updateDisplayTextSetParameter(int index, int parameter, QString value);
|
void updateDisplayTextSetParameter(int index, int parameter, QString value);
|
||||||
|
|
Loading…
Reference in a new issue