implemented keep alive

This commit is contained in:
Dorian Zedler 2020-10-15 16:57:07 +02:00
parent ab169f404e
commit 1be53b8925
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 40 additions and 4 deletions

View file

@ -47,3 +47,8 @@ contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
}
ANDROID_ABIS = armeabi-v7a
contains(ANDROID_TARGET_ARCH,) {
ANDROID_ABIS = \
armeabi-v7a
}

View file

@ -1,13 +1,19 @@
#include "omobidisplaybackend.h"
#include "omobidisplaybackend.h"
OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
{
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->textSetsBuffer.clear();
this->displayBrightness = -1;
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::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
connect(this->ble, &QBluetoothLeUart::dataReceived, this, &OmobiDisplayBackend::handleBluetoothDataReceived);
@ -56,6 +62,11 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::Bluetooth
break;
}
}
if(state == QBluetoothLeUart::Connected)
this->keepAliveTimer->start();
else if(this->keepAliveTimer->isActive())
this->keepAliveTimer->stop();
}
void OmobiDisplayBackend::handleBluetoothDeviceConected() {
@ -72,10 +83,10 @@ void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
void OmobiDisplayBackend::handleDisplayTextModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) {
qDebug() << "Data changed: topLeft: " << topLeft << " bottomRight: " << bottomRight << " roles: " << roles;
qDebug() << "Data changed: topLeft: " << topLeft << " bottomRight: " << bottomRight << " roles: " << roles;
for(int role : roles)
this->updateDisplayTextSetParameter(topLeft.row(), role);
for(int role : roles)
this->updateDisplayTextSetParameter(topLeft.row(), role);
}
void OmobiDisplayBackend::handleDisplayTextModelRowsInserted(const QModelIndex &parent, int first, int last) {
@ -110,6 +121,14 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar
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){
qDebug() << "New data: \n" << qPrintable(s);
@ -124,6 +143,13 @@ void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt());
switch (header) {
case AuthorizeSessionCommand: {
break;
}
case KeepAliveCommand: {
break;
}
case GetAllTextSetsCommand: {
// indicates that all existing txt sets have been sent over after GetAllTextSetsCommand was called
if(status != Success)

View file

@ -2,6 +2,7 @@
#define OMOBIDISPLAYBACKEND_H
#include <QObject>
#include <QTimer>
#include <QJsonDocument>
#include <qbluetoothleuart.h>
@ -31,6 +32,8 @@ public:
private:
enum OmobiDisplayCommand {
AuthorizeSessionCommand = 0,
KeepAliveCommand = 1,
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
GetDisplayBrightnessCommand = 12,
@ -45,6 +48,7 @@ private:
OmobiDisplayAppState state;
QBluetoothLeUart *ble;
QTimer *keepAliveTimer;
OmobiDisplayTextModel* displayTextModel;
int waitingCommands;
QList<QMap<int, QVariant>> textSetsBuffer;
@ -68,6 +72,7 @@ private slots:
void handleDisplayTextModelRowsRemoved(const QModelIndex &parent, int first, int last);
void sendBluetoothCommand(OmobiDisplayCommand command, QVariant data = QVariant());
void sendBluetoothKeepAlive();
void handleBluetoothDataReceived(QString s);
void updateDisplayTextSetParameter(int index, int parameter);
void updateDisplayTextSetParameter(int index, int parameter, QString value);