Faster livedata transmission
This commit is contained in:
@@ -1,31 +1,20 @@
|
|||||||
#include "devicehandler.h"
|
#include "devicehandler.h"
|
||||||
#include "deviceinfo.h"
|
|
||||||
|
// Qt includes
|
||||||
#include <QtEndian>
|
#include <QtEndian>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "deviceinfo.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const QBluetoothUuid bobbycarServiceUuid{QUuid::fromString(QStringLiteral("0335e46c-f355-4ce6-8076-017de08cee98"))};
|
const QBluetoothUuid bobbycarServiceUuid{QUuid::fromString(QStringLiteral("0335e46c-f355-4ce6-8076-017de08cee98"))};
|
||||||
|
|
||||||
const QBluetoothUuid frontVoltageCharacUuid{QUuid::fromString(QStringLiteral("a48321ea-329f-4eab-a401-30e247211524"))};
|
const QBluetoothUuid livestatsCharacUuid{QUuid::fromString(QStringLiteral("a48321ea-329f-4eab-a401-30e247211524"))};
|
||||||
const QBluetoothUuid backVoltageCharacUuid{QUuid::fromString(QStringLiteral("4201def0-a264-43e6-946b-6b2d9612dfed"))};
|
const QBluetoothUuid remotecontrolCharacUuid{QUuid::fromString(QStringLiteral("4201def0-a264-43e6-946b-6b2d9612dfed"))};
|
||||||
|
|
||||||
const QBluetoothUuid frontTemperatureCharacUuid{QUuid::fromString(QStringLiteral("4799e23f-6448-4786-900b-b5c3f3c17a9c"))};
|
|
||||||
const QBluetoothUuid backTemperatureCharacUuid{QUuid::fromString(QStringLiteral("3c32b7bb-8d9b-4055-8ea0-5b6764111024"))};
|
|
||||||
|
|
||||||
const QBluetoothUuid frontLeftErrorCharacUuid{QUuid::fromString(QStringLiteral("f84b3a9b-1b2c-4075-acbe-016a2166976c"))};
|
|
||||||
const QBluetoothUuid frontRightErrorCharacUuid{QUuid::fromString(QStringLiteral("eed4b709-5a65-4a5b-8e07-512f9661533d"))};
|
|
||||||
const QBluetoothUuid backLeftErrorCharacUuid{QUuid::fromString(QStringLiteral("89d143f5-9ae2-4f7e-9235-643a3a7e21df"))};
|
|
||||||
const QBluetoothUuid backRightErrorCharacUuid{QUuid::fromString(QStringLiteral("0fb377f1-7527-4966-aaf0-8bd56f2ddd3f"))};
|
|
||||||
|
|
||||||
const QBluetoothUuid frontLeftSpeedCharacUuid{QUuid::fromString(QStringLiteral("c6f959e8-0ec3-4bdd-88ad-6ad993fc81e9"))};
|
|
||||||
const QBluetoothUuid frontRightSpeedCharacUuid{QUuid::fromString(QStringLiteral("ce53f135-8f20-4b80-abb9-31da81d62716"))};
|
|
||||||
const QBluetoothUuid backLeftSpeedCharacUuid{QUuid::fromString(QStringLiteral("9a1dd1fe-3f14-4af1-bc5e-3f70edcae54b"))};
|
|
||||||
const QBluetoothUuid backRightSpeedCharacUuid{QUuid::fromString(QStringLiteral("7de1a823-682e-438f-9201-3a80c3911f1a"))};
|
|
||||||
|
|
||||||
const QBluetoothUuid frontLeftDcLinkCharacUuid{QUuid::fromString(QStringLiteral("f404416f-2a77-41c6-a35f-7d10ec38376d"))};
|
|
||||||
const QBluetoothUuid frontRightDcLinkCharacUuid{QUuid::fromString(QStringLiteral("452dd012-3f12-428c-8746-40c6b6c73c40"))};
|
|
||||||
const QBluetoothUuid backLeftDcLinkCharacUuid{QUuid::fromString(QStringLiteral("9dc455a3-718e-4d62-b0e7-1c0cb2a8bbd3"))};
|
|
||||||
const QBluetoothUuid backRightDcLinkCharacUuid{QUuid::fromString(QStringLiteral("90a66506-1d78-4ba2-b074-e1153fbf5216"))};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceHandler::DeviceHandler(QObject *parent) :
|
DeviceHandler::DeviceHandler(QObject *parent) :
|
||||||
@@ -60,15 +49,16 @@ void DeviceHandler::setDevice(DeviceInfo *device)
|
|||||||
m_currentDevice = device;
|
m_currentDevice = device;
|
||||||
|
|
||||||
// Disconnect and delete old connection
|
// Disconnect and delete old connection
|
||||||
if (m_control) {
|
if (m_control)
|
||||||
|
{
|
||||||
m_control->disconnectFromDevice();
|
m_control->disconnectFromDevice();
|
||||||
delete m_control;
|
delete m_control;
|
||||||
m_control = nullptr;
|
m_control = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new controller and connect it if device available
|
// Create new controller and connect it if device available
|
||||||
if (m_currentDevice) {
|
if (m_currentDevice)
|
||||||
|
{
|
||||||
// Make connections
|
// Make connections
|
||||||
//! [Connect-Signals-1]
|
//! [Connect-Signals-1]
|
||||||
m_control = QLowEnergyController::createCentral(m_currentDevice->getDevice(), this);
|
m_control = QLowEnergyController::createCentral(m_currentDevice->getDevice(), this);
|
||||||
@@ -101,7 +91,8 @@ void DeviceHandler::setDevice(DeviceInfo *device)
|
|||||||
|
|
||||||
void DeviceHandler::serviceDiscovered(const QBluetoothUuid &gatt)
|
void DeviceHandler::serviceDiscovered(const QBluetoothUuid &gatt)
|
||||||
{
|
{
|
||||||
if (gatt == bobbycarServiceUuid) {
|
if (gatt == bobbycarServiceUuid)
|
||||||
|
{
|
||||||
setInfo("Bobbycar service discovered. Waiting for service scan to be done...");
|
setInfo("Bobbycar service discovered. Waiting for service scan to be done...");
|
||||||
m_foundBobbycarService = true;
|
m_foundBobbycarService = true;
|
||||||
}
|
}
|
||||||
@@ -112,7 +103,8 @@ void DeviceHandler::serviceScanDone()
|
|||||||
setInfo("Service scan done.");
|
setInfo("Service scan done.");
|
||||||
|
|
||||||
// Delete old service if available
|
// Delete old service if available
|
||||||
if (m_service) {
|
if (m_service)
|
||||||
|
{
|
||||||
delete m_service;
|
delete m_service;
|
||||||
m_service = nullptr;
|
m_service = nullptr;
|
||||||
}
|
}
|
||||||
@@ -121,12 +113,15 @@ void DeviceHandler::serviceScanDone()
|
|||||||
if (m_foundBobbycarService)
|
if (m_foundBobbycarService)
|
||||||
m_service = m_control->createServiceObject(bobbycarServiceUuid, this);
|
m_service = m_control->createServiceObject(bobbycarServiceUuid, this);
|
||||||
|
|
||||||
if (m_service) {
|
if (m_service)
|
||||||
|
{
|
||||||
connect(m_service, &QLowEnergyService::stateChanged, this, &DeviceHandler::serviceStateChanged);
|
connect(m_service, &QLowEnergyService::stateChanged, this, &DeviceHandler::serviceStateChanged);
|
||||||
connect(m_service, &QLowEnergyService::characteristicChanged, this, &DeviceHandler::updateBobbycarValue);
|
connect(m_service, &QLowEnergyService::characteristicChanged, this, &DeviceHandler::updateBobbycarValue);
|
||||||
connect(m_service, &QLowEnergyService::descriptorWritten, this, &DeviceHandler::confirmedDescriptorWrite);
|
connect(m_service, &QLowEnergyService::descriptorWritten, this, &DeviceHandler::confirmedDescriptorWrite);
|
||||||
m_service->discoverDetails();
|
m_service->discoverDetails();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
setError("Bobbycar Service not found.");
|
setError("Bobbycar Service not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,38 +131,10 @@ void logAddr(const QBluetoothUuid &uuid)
|
|||||||
{
|
{
|
||||||
if (uuid == bobbycarServiceUuid)
|
if (uuid == bobbycarServiceUuid)
|
||||||
qDebug() << "bobbycarServiceUuid";
|
qDebug() << "bobbycarServiceUuid";
|
||||||
else if (uuid == frontVoltageCharacUuid)
|
else if (uuid == livestatsCharacUuid)
|
||||||
qDebug() << "frontVoltageCharacUuid";
|
qDebug() << "livestatsCharacUuid";
|
||||||
else if (uuid == backVoltageCharacUuid)
|
else if (uuid == remotecontrolCharacUuid)
|
||||||
qDebug() << "backVoltageCharacUuid";
|
qDebug() << "remotecontrolCharacUuid";
|
||||||
else if (uuid == frontTemperatureCharacUuid)
|
|
||||||
qDebug() << "frontTemperatureCharacUuid";
|
|
||||||
else if (uuid == backTemperatureCharacUuid)
|
|
||||||
qDebug() << "backTemperatureCharacUuid";
|
|
||||||
else if (uuid == frontLeftErrorCharacUuid)
|
|
||||||
qDebug() << "frontLeftErrorCharacUuid";
|
|
||||||
else if (uuid == frontRightErrorCharacUuid)
|
|
||||||
qDebug() << "frontRightErrorCharacUuid";
|
|
||||||
else if (uuid == backLeftErrorCharacUuid)
|
|
||||||
qDebug() << "backLeftErrorCharacUuid";
|
|
||||||
else if (uuid == backRightErrorCharacUuid)
|
|
||||||
qDebug() << "backRightErrorCharacUuid";
|
|
||||||
else if (uuid == frontLeftSpeedCharacUuid)
|
|
||||||
qDebug() << "frontLeftSpeedCharacUuid";
|
|
||||||
else if (uuid == frontRightSpeedCharacUuid)
|
|
||||||
qDebug() << "frontRightSpeedCharacUuid";
|
|
||||||
else if (uuid == backLeftSpeedCharacUuid)
|
|
||||||
qDebug() << "backLeftSpeedCharacUuid";
|
|
||||||
else if (uuid == backRightSpeedCharacUuid)
|
|
||||||
qDebug() << "backRightSpeedCharacUuid";
|
|
||||||
else if (uuid == frontLeftDcLinkCharacUuid)
|
|
||||||
qDebug() << "frontLeftDcLinkCharacUuid";
|
|
||||||
else if (uuid == frontRightDcLinkCharacUuid)
|
|
||||||
qDebug() << "frontRightDcLinkCharacUuid";
|
|
||||||
else if (uuid == backLeftDcLinkCharacUuid)
|
|
||||||
qDebug() << "backLeftDcLinkCharacUuid";
|
|
||||||
else if (uuid == backRightDcLinkCharacUuid)
|
|
||||||
qDebug() << "backRightDcLinkCharacUuid";
|
|
||||||
else
|
else
|
||||||
qDebug() << "unknown uuid" << uuid;
|
qDebug() << "unknown uuid" << uuid;
|
||||||
}
|
}
|
||||||
@@ -183,195 +150,15 @@ void DeviceHandler::serviceStateChanged(QLowEnergyService::ServiceState s)
|
|||||||
{
|
{
|
||||||
setInfo(tr("Service discovered."));
|
setInfo(tr("Service discovered."));
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontVoltageCharacUuid); hrChar.isValid())
|
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(livestatsCharacUuid); hrChar.isValid())
|
||||||
{
|
{
|
||||||
m_notificationDescFrontVoltage = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
m_notificationDescLivestats = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
||||||
if (m_notificationDescFrontVoltage.isValid())
|
if (m_notificationDescLivestats.isValid())
|
||||||
m_service->writeDescriptor(m_notificationDescFrontVoltage, QByteArray::fromHex("0100"));
|
m_service->writeDescriptor(m_notificationDescLivestats, QByteArray::fromHex("0100"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setError("frontVoltageCharacUuid not found.");
|
setError("livestatsCharacUuid not found.");
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backVoltageCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackVoltage = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackVoltage.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackVoltage, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backVoltageCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontTemperatureCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontTemperature = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontTemperature.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontTemperature, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontTemperatureCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backTemperatureCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackTemperature = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackTemperature.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackTemperature, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backTemperatureCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontLeftErrorCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontLeftError = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontLeftError.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftError, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontLeftErrorCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontRightErrorCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontRightError = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontRightError.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightError, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontRightErrorCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backLeftErrorCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackLeftError = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackLeftError.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftError, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backLeftErrorCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backRightErrorCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackRightError = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackRightError.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightError, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backRightErrorCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontLeftSpeedCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontLeftSpeed = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontLeftSpeed.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftSpeed, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontLeftSpeedCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontRightSpeedCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontRightSpeed = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontRightSpeed.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightSpeed, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontRightSpeedCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backLeftSpeedCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackLeftSpeed = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackLeftSpeed.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftSpeed, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backLeftSpeedCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backRightSpeedCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackRightSpeed = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackRightSpeed.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightSpeed, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backRightSpeedCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontLeftDcLinkCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontLeftDcLink = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontLeftDcLink.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftDcLink, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontLeftDcLinkCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(frontRightDcLinkCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescFrontRightDcLink = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescFrontRightDcLink.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightDcLink, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("frontRightDcLinkCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backLeftDcLinkCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackLeftDcLink = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackLeftDcLink.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftDcLink, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backLeftDcLinkCharacUuid not found.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const QLowEnergyCharacteristic hrChar = m_service->characteristic(backRightDcLinkCharacUuid); hrChar.isValid())
|
|
||||||
{
|
|
||||||
m_notificationDescBackRightDcLink = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
|
|
||||||
if (m_notificationDescBackRightDcLink.isValid())
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightDcLink, QByteArray::fromHex("0100"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setError("backRightDcLinkCharacUuid not found.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,198 +177,68 @@ void DeviceHandler::updateBobbycarValue(const QLowEnergyCharacteristic &c, const
|
|||||||
//qDebug() << "updateBobbycarValue";
|
//qDebug() << "updateBobbycarValue";
|
||||||
//logAddr(c.uuid());
|
//logAddr(c.uuid());
|
||||||
|
|
||||||
if (c.uuid() == frontVoltageCharacUuid)
|
if (c.uuid() == livestatsCharacUuid)
|
||||||
{
|
{
|
||||||
bool ok;
|
QJsonParseError error;
|
||||||
float val = value.toFloat(&ok);
|
QJsonDocument doc = QJsonDocument::fromJson(value, &error);
|
||||||
if (ok)
|
if (error.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
m_frontVoltage = val;
|
qWarning() << "could not parse livestats" << error.errorString();
|
||||||
emit frontVoltageChanged();
|
return;
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontVoltage" << value;
|
const QJsonObject &obj = doc.object();
|
||||||
}
|
|
||||||
else if (c.uuid() == backVoltageCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
{
|
||||||
m_backVoltage = val;
|
const QJsonArray &arr = obj.value("v").toArray();
|
||||||
|
m_frontVoltage = arr.at(0).toDouble();
|
||||||
|
emit frontVoltageChanged();
|
||||||
|
m_backVoltage = arr.at(1).toDouble();
|
||||||
emit backVoltageChanged();
|
emit backVoltageChanged();
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backVoltage" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontTemperatureCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
{
|
||||||
m_frontTemperature = val;
|
const QJsonArray &arr = obj.value("t").toArray();
|
||||||
|
m_frontTemperature = arr.at(0).toDouble();
|
||||||
emit frontTemperatureChanged();
|
emit frontTemperatureChanged();
|
||||||
}
|
m_backTemperature = arr.at(1).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontTemperature" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backTemperatureCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backTemperature = val;
|
|
||||||
emit backTemperatureChanged();
|
emit backTemperatureChanged();
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backTemperature" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontLeftErrorCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
uint8_t val = value.toShort(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
{
|
||||||
m_frontLeftError = val;
|
const QJsonArray &arr = obj.value("e").toArray();
|
||||||
|
m_frontLeftError = arr.at(0).toInt();
|
||||||
emit frontLeftErrorChanged();
|
emit frontLeftErrorChanged();
|
||||||
}
|
m_frontRightError = arr.at(1).toInt();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontLeftError" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontRightErrorCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
uint8_t val = value.toShort(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_frontRightError = val;
|
|
||||||
emit frontRightErrorChanged();
|
emit frontRightErrorChanged();
|
||||||
}
|
m_backLeftError = arr.at(2).toInt();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontRightError" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backLeftErrorCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
uint8_t val = value.toShort(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backLeftError = val;
|
|
||||||
emit backLeftErrorChanged();
|
emit backLeftErrorChanged();
|
||||||
}
|
m_backRightError = arr.at(3).toInt();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backLeftError" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backRightErrorCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
uint8_t val = value.toShort(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backRightError = val;
|
|
||||||
emit backRightErrorChanged();
|
emit backRightErrorChanged();
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backRightError" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontLeftSpeedCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
{
|
||||||
m_frontLeftSpeed = val;
|
const QJsonArray &arr = obj.value("s").toArray();
|
||||||
|
m_frontLeftSpeed = arr.at(0).toDouble();
|
||||||
emit frontLeftSpeedChanged();
|
emit frontLeftSpeedChanged();
|
||||||
}
|
m_frontRightSpeed = arr.at(1).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontLeftSpeed" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontRightSpeedCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_frontRightSpeed = val;
|
|
||||||
emit frontRightSpeedChanged();
|
emit frontRightSpeedChanged();
|
||||||
}
|
m_backLeftSpeed = arr.at(2).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontRightSpeed" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backLeftSpeedCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backLeftSpeed = val;
|
|
||||||
emit backLeftSpeedChanged();
|
emit backLeftSpeedChanged();
|
||||||
}
|
m_backRightSpeed = arr.at(3).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backLeftSpeed" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backRightSpeedCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backRightSpeed = val;
|
|
||||||
emit backRightSpeedChanged();
|
emit backRightSpeedChanged();
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backRightSpeed" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontLeftDcLinkCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
{
|
||||||
m_frontLeftDcLink = val;
|
const QJsonArray &arr = obj.value("a").toArray();
|
||||||
|
m_frontLeftDcLink = arr.at(0).toDouble();
|
||||||
emit frontLeftDcLinkChanged();
|
emit frontLeftDcLinkChanged();
|
||||||
}
|
m_frontRightDcLink = arr.at(1).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontLeftDcLink" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == frontRightDcLinkCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_frontRightDcLink = val;
|
|
||||||
emit frontRightDcLinkChanged();
|
emit frontRightDcLinkChanged();
|
||||||
}
|
m_backLeftDcLink = arr.at(2).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse frontRightDcLink" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backLeftDcLinkCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backLeftDcLink = val;
|
|
||||||
emit backLeftDcLinkChanged();
|
emit backLeftDcLinkChanged();
|
||||||
}
|
m_backRightDcLink = arr.at(3).toDouble();
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backLeftDcLink" << value;
|
|
||||||
}
|
|
||||||
else if (c.uuid() == backRightDcLinkCharacUuid)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
float val = value.toFloat(&ok);
|
|
||||||
if (ok)
|
|
||||||
{
|
|
||||||
m_backRightDcLink = val;
|
|
||||||
emit backRightDcLinkChanged();
|
emit backRightDcLinkChanged();
|
||||||
}
|
}
|
||||||
else if (!value.isEmpty())
|
|
||||||
qWarning() << "could not parse backRightDcLink" << value;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
qWarning() << "unknown uuid" << c.uuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandler::confirmedDescriptorWrite(const QLowEnergyDescriptor &d, const QByteArray &value)
|
void DeviceHandler::confirmedDescriptorWrite(const QLowEnergyDescriptor &d, const QByteArray &value)
|
||||||
@@ -589,38 +246,8 @@ void DeviceHandler::confirmedDescriptorWrite(const QLowEnergyDescriptor &d, cons
|
|||||||
qDebug() << "confirmedDescriptorWrite" << d.uuid() << value;
|
qDebug() << "confirmedDescriptorWrite" << d.uuid() << value;
|
||||||
if (d.isValid() && value == QByteArray::fromHex("0000"))
|
if (d.isValid() && value == QByteArray::fromHex("0000"))
|
||||||
{
|
{
|
||||||
if (d == m_notificationDescFrontVoltage)
|
if (d == m_notificationDescLivestats)
|
||||||
m_notificationDescFrontVoltage = {};
|
m_notificationDescLivestats = {};
|
||||||
if (d == m_notificationDescBackVoltage)
|
|
||||||
m_notificationDescBackVoltage = {};
|
|
||||||
if (d == m_notificationDescFrontTemperature)
|
|
||||||
m_notificationDescFrontTemperature = {};
|
|
||||||
if (d == m_notificationDescBackTemperature)
|
|
||||||
m_notificationDescBackTemperature = {};
|
|
||||||
if (d == m_notificationDescFrontLeftError)
|
|
||||||
m_notificationDescFrontLeftError = {};
|
|
||||||
if (d == m_notificationDescFrontRightError)
|
|
||||||
m_notificationDescFrontRightError = {};
|
|
||||||
if (d == m_notificationDescBackLeftError)
|
|
||||||
m_notificationDescBackLeftError = {};
|
|
||||||
if (d == m_notificationDescBackRightError)
|
|
||||||
m_notificationDescBackRightError = {};
|
|
||||||
if (d == m_notificationDescFrontLeftSpeed)
|
|
||||||
m_notificationDescFrontLeftSpeed = {};
|
|
||||||
if (d == m_notificationDescFrontRightSpeed)
|
|
||||||
m_notificationDescFrontRightSpeed = {};
|
|
||||||
if (d == m_notificationDescBackLeftSpeed)
|
|
||||||
m_notificationDescBackLeftSpeed = {};
|
|
||||||
if (d == m_notificationDescBackRightSpeed)
|
|
||||||
m_notificationDescBackRightSpeed = {};
|
|
||||||
if (d == m_notificationDescFrontLeftDcLink)
|
|
||||||
m_notificationDescFrontLeftDcLink = {};
|
|
||||||
if (d == m_notificationDescFrontRightDcLink)
|
|
||||||
m_notificationDescFrontRightDcLink = {};
|
|
||||||
if (d == m_notificationDescBackLeftDcLink)
|
|
||||||
m_notificationDescBackLeftDcLink = {};
|
|
||||||
if (d == m_notificationDescBackRightDcLink)
|
|
||||||
m_notificationDescBackRightDcLink = {};
|
|
||||||
|
|
||||||
disconnectInternal();
|
disconnectInternal();
|
||||||
}
|
}
|
||||||
@@ -633,38 +260,8 @@ void DeviceHandler::disconnectService()
|
|||||||
//disable notifications
|
//disable notifications
|
||||||
if (m_service)
|
if (m_service)
|
||||||
{
|
{
|
||||||
if (m_notificationDescFrontVoltage.isValid() && m_notificationDescFrontVoltage.value() == QByteArray::fromHex("0100"))
|
if (m_notificationDescLivestats.isValid() && m_notificationDescLivestats.value() == QByteArray::fromHex("0100"))
|
||||||
m_service->writeDescriptor(m_notificationDescFrontVoltage, QByteArray::fromHex("0000"));
|
m_service->writeDescriptor(m_notificationDescLivestats, QByteArray::fromHex("0000"));
|
||||||
if (m_notificationDescBackVoltage.isValid() && m_notificationDescBackVoltage.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackVoltage, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontTemperature.isValid() && m_notificationDescFrontTemperature.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontTemperature, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackTemperature.isValid() && m_notificationDescBackTemperature.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackTemperature, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontLeftError.isValid() && m_notificationDescFrontLeftError.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftError, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontRightError.isValid() && m_notificationDescFrontRightError.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightError, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackLeftError.isValid() && m_notificationDescBackLeftError.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftError, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackRightError.isValid() && m_notificationDescBackRightError.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightError, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontLeftSpeed.isValid() && m_notificationDescFrontLeftSpeed.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftSpeed, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontRightSpeed.isValid() && m_notificationDescFrontRightSpeed.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightSpeed, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackLeftSpeed.isValid() && m_notificationDescBackLeftSpeed.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftSpeed, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackRightSpeed.isValid() && m_notificationDescBackRightSpeed.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightSpeed, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontLeftDcLink.isValid() && m_notificationDescFrontLeftDcLink.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontLeftDcLink, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescFrontRightDcLink.isValid() && m_notificationDescFrontRightDcLink.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescFrontRightDcLink, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackLeftDcLink.isValid() && m_notificationDescBackLeftDcLink.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackLeftDcLink, QByteArray::fromHex("0000"));
|
|
||||||
if (m_notificationDescBackRightDcLink.isValid() && m_notificationDescBackRightDcLink.value() == QByteArray::fromHex("0100"))
|
|
||||||
m_service->writeDescriptor(m_notificationDescBackRightDcLink, QByteArray::fromHex("0000"));
|
|
||||||
|
|
||||||
disconnectInternal();
|
disconnectInternal();
|
||||||
}
|
}
|
||||||
@@ -672,22 +269,7 @@ void DeviceHandler::disconnectService()
|
|||||||
|
|
||||||
void DeviceHandler::disconnectInternal()
|
void DeviceHandler::disconnectInternal()
|
||||||
{
|
{
|
||||||
if (!m_notificationDescFrontVoltage.isValid() &&
|
if (!m_notificationDescLivestats.isValid())
|
||||||
!m_notificationDescBackVoltage.isValid() &&
|
|
||||||
!m_notificationDescFrontTemperature.isValid() &&
|
|
||||||
!m_notificationDescBackTemperature.isValid() &&
|
|
||||||
!m_notificationDescFrontLeftError.isValid() &&
|
|
||||||
!m_notificationDescFrontRightError.isValid() &&
|
|
||||||
!m_notificationDescBackLeftError.isValid() &&
|
|
||||||
!m_notificationDescBackRightError.isValid() &&
|
|
||||||
!m_notificationDescFrontLeftSpeed.isValid() &&
|
|
||||||
!m_notificationDescFrontRightSpeed.isValid() &&
|
|
||||||
!m_notificationDescBackLeftSpeed.isValid() &&
|
|
||||||
!m_notificationDescBackRightSpeed.isValid() &&
|
|
||||||
!m_notificationDescFrontLeftDcLink.isValid() &&
|
|
||||||
!m_notificationDescFrontRightDcLink.isValid() &&
|
|
||||||
!m_notificationDescBackLeftDcLink.isValid() &&
|
|
||||||
!m_notificationDescBackRightDcLink.isValid())
|
|
||||||
{
|
{
|
||||||
//disabled notifications -> assume disconnect intent
|
//disabled notifications -> assume disconnect intent
|
||||||
if (m_control)
|
if (m_control)
|
||||||
|
@@ -107,22 +107,7 @@ private:
|
|||||||
QLowEnergyController::RemoteAddressType m_addressType = QLowEnergyController::PublicAddress;
|
QLowEnergyController::RemoteAddressType m_addressType = QLowEnergyController::PublicAddress;
|
||||||
QLowEnergyController *m_control = nullptr;
|
QLowEnergyController *m_control = nullptr;
|
||||||
QLowEnergyService *m_service = nullptr;
|
QLowEnergyService *m_service = nullptr;
|
||||||
QLowEnergyDescriptor m_notificationDescFrontVoltage;
|
QLowEnergyDescriptor m_notificationDescLivestats;
|
||||||
QLowEnergyDescriptor m_notificationDescBackVoltage;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontTemperature;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackTemperature;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontLeftError;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontRightError;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackLeftError;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackRightError;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontLeftSpeed;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontRightSpeed;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackLeftSpeed;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackRightSpeed;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontLeftDcLink;
|
|
||||||
QLowEnergyDescriptor m_notificationDescFrontRightDcLink;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackLeftDcLink;
|
|
||||||
QLowEnergyDescriptor m_notificationDescBackRightDcLink;
|
|
||||||
DeviceInfo *m_currentDevice{};
|
DeviceInfo *m_currentDevice{};
|
||||||
|
|
||||||
bool m_foundBobbycarService{};
|
bool m_foundBobbycarService{};
|
||||||
|
Reference in New Issue
Block a user