Skip to content

Commit

Permalink
t push origin masterMerge branch 'JF002-pinetime-add-support-for-exte…
Browse files Browse the repository at this point in the history
…rnal-resource'
  • Loading branch information
piggz committed Sep 19, 2022
2 parents 63f2896 + 59a5c55 commit 1656e09
Show file tree
Hide file tree
Showing 12 changed files with 753 additions and 8 deletions.
8 changes: 7 additions & 1 deletion daemon/daemon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ WATCHFISH_FEATURES += music \
calendar
}

INCLUDEPATH += /usr/include/mkcal-qt5 /usr/include/KF5/KCalendarCore
INCLUDEPATH += /usr/include/mkcal-qt5 /usr/include/KF5/KCalendarCore /usr/include/KF5/KArchive

INCLUDEPATH += $$PWD/src/services/ \
$$PWD/src/operations/ \
Expand Down Expand Up @@ -111,11 +111,14 @@ SOURCES += \
src/devices/gtsdevice.cpp \
src/devices/gtsfirmwareinfo.cpp \
src/devices/pinetimejfdevice.cpp \
src/operations/adafruitblefsoperation.cpp \
src/operations/adafruitblefsworker.cpp \
src/operations/dfuoperation.cpp \
src/operations/dfuworker.cpp \
src/operations/updatefirmwareoperationnew.cpp \
src/operations/huamiupdatefirmwareoperation2020.cpp \
src/qaesencryption.cpp \
src/services/adafruitblefsservice.cpp \
src/services/currenttimeservice.cpp \
src/services/dfuservice.cpp \
src/services/infinitimemotionservice.cpp \
Expand Down Expand Up @@ -178,11 +181,14 @@ HEADERS += \
src/devices/gtsdevice.h \
src/devices/gtsfirmwareinfo.h \
src/devices/pinetimejfdevice.h \
src/operations/adafruitblefsoperation.h \
src/operations/adafruitblefsworker.h \
src/operations/dfuoperation.h \
src/operations/dfuworker.h \
src/operations/updatefirmwareoperationnew.h \
src/operations/huamiupdatefirmwareoperation2020.h \
src/qaesencryption.h \
src/services/adafruitblefsservice.h \
src/services/currenttimeservice.h \
src/services/dfuservice.h \
src/services/infinitimemotionservice.h \
Expand Down
8 changes: 8 additions & 0 deletions daemon/src/devices/infinitimefirmwareinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ void InfinitimeFirmwareInfo::determineFirmwareType()
qDebug() << "DFU file detected";
m_type = Firmware;
}
else if(root->entry("resources.json") != nullptr)
{
qDebug() << "Resource file detected";
m_type = Res_Compressed;
}
}
}
}
Expand All @@ -49,6 +54,9 @@ void InfinitimeFirmwareInfo::determineFirmwareVersion()
case Firmware:
m_version = "FW ()";
break;
case Res_Compressed:
m_version = "Ressource ()";
break;
default:
m_version = "unknown";
}
Expand Down
73 changes: 66 additions & 7 deletions daemon/src/devices/pinetimejfdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,39 @@
#include "hrmservice.h"
#include "infinitimemotionservice.h"
#include "infinitimeweatherservice.h"

#include "adafruitblefsservice.h"
#include <QtXml/QtXml>

namespace {
size_t GetMtuForCharacteristic(QString path, const char* characteristicUUID)
{
size_t transferMtu = 20;
QDBusInterface adapterIntro("org.bluez", path, "org.freedesktop.DBus.Introspectable", QDBusConnection::systemBus(), 0);
QDBusReply<QString> adapterXml = adapterIntro.call("Introspect");
QDomDocument adapterDoc;
adapterDoc.setContent(adapterXml.value());
QDomNodeList adapterNodes = adapterDoc.elementsByTagName("node");

for (int x = 0; x < adapterNodes.count(); x++)
{
QDomElement node = adapterNodes.at(x).toElement();
QString nodeName = node.attribute("name");
if (nodeName.startsWith("char")) {
QString nodePath = path + "/" + nodeName;
QDBusInterface characteristicInterface("org.bluez", nodePath, "org.bluez.GattCharacteristic1", QDBusConnection::systemBus(), 0);
QString currentCharacteristicUUID = characteristicInterface.property("UUID").toString();
if(currentCharacteristicUUID == characteristicUUID){
QDBusInterface mtuInterface("org.bluez", nodePath, "org.bluez.GattCharacteristic1", QDBusConnection::systemBus(), 0);
QString mtu = mtuInterface.property("MTU").toString();
transferMtu = mtu.toInt();
}

}
}
return transferMtu;
}
}

PinetimeJFDevice::PinetimeJFDevice(const QString &pairedName, QObject *parent) : AbstractDevice(pairedName, parent)
{
qDebug() << "PinetimeJFDevice:: " << pairedName;
Expand Down Expand Up @@ -122,6 +152,9 @@ void PinetimeJFDevice::parseServices()
addService(InfiniTimeMotionService::UUID_SERVICE_MOTION, new InfiniTimeMotionService(path, this));
} else if (uuid == InfiniTimeWeatherService::UUID_SERVICE_WEATHER && !service(InfiniTimeWeatherService::UUID_SERVICE_WEATHER)) {
addService(InfiniTimeWeatherService::UUID_SERVICE_WEATHER, new InfiniTimeWeatherService(path, this));
} else if (uuid == AdafruitBleFsService::UUID_SERVICE_FS && !service(AdafruitBleFsService::UUID_SERVICE_FS)) {
size_t transferMtu = GetMtuForCharacteristic(path, AdafruitBleFsService::UUID_CHARACTERISTIC_FS_TRANSFER);
addService(AdafruitBleFsService::UUID_SERVICE_FS, new AdafruitBleFsService(path, this, transferMtu));
} else if ( !service(uuid)) {
addService(uuid, new QBLEService(uuid, path, this));
}
Expand Down Expand Up @@ -176,6 +209,11 @@ void PinetimeJFDevice::initialise()
//motion->enableNotification(InfiniTimeMotionService::UUID_CHARACTERISTIC_MOTION_MOTION);
connect(motion, &InfiniTimeMotionService::informationChanged, this, &AbstractDevice::informationChanged, Qt::UniqueConnection);
}

AdafruitBleFsService *bleFs = qobject_cast<AdafruitBleFsService*>(service(AdafruitBleFsService::UUID_SERVICE_FS));
if (bleFs) {
connect(bleFs, &AdafruitBleFsService::downloadProgress, this, &PinetimeJFDevice::downloadProgress, Qt::UniqueConnection);
}
}

void PinetimeJFDevice::onPropertiesChanged(QString interface, QVariantMap map, QStringList list)
Expand Down Expand Up @@ -247,18 +285,39 @@ void PinetimeJFDevice::setMusicStatus(bool playing, const QString &title, const

void PinetimeJFDevice::prepareFirmwareDownload(const AbstractFirmwareInfo *info)
{
DfuService *fw = qobject_cast<DfuService*>(service(DfuService::UUID_SERVICE_DFU));
if (fw){
fw->prepareFirmwareDownload(info);
firmwareType = info->type();
if(info->type() == AbstractFirmwareInfo::Type::Firmware) {
DfuService *fw = qobject_cast<DfuService*>(service(DfuService::UUID_SERVICE_DFU));
if (fw){
fw->prepareFirmwareDownload(info);
}
} else if (info->type() == AbstractFirmwareInfo::Type::Res_Compressed) {
AdafruitBleFsService* s = qobject_cast<AdafruitBleFsService*>(service(AdafruitBleFsService::UUID_SERVICE_FS));
if(s) {
s->prepareDownload(new AdafruitBleFsOperation(s, info));
}
}
}

void PinetimeJFDevice::startDownload()
{
qDebug() << Q_FUNC_INFO;
DfuService *fw = qobject_cast<DfuService*>(service(DfuService::UUID_SERVICE_DFU));
if (fw){
fw->startDownload();

if(firmwareType == AbstractFirmwareInfo::Type::Firmware)
{
DfuService *fw = qobject_cast<DfuService*>(service(DfuService::UUID_SERVICE_DFU));
if (fw)
{
fw->startDownload();
}
}
else if(firmwareType == AbstractFirmwareInfo::Type::Res_Compressed)
{
AdafruitBleFsService* s = qobject_cast<AdafruitBleFsService*>(service(AdafruitBleFsService::UUID_SERVICE_FS));
if(s)
{
s->updateFiles();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions daemon/src/devices/pinetimejfdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PinetimeJFDevice : public AbstractDevice
void parseServices();
void initialise();
Q_SLOT void serviceEvent(const QString &characteristic, uint8_t event);
AbstractFirmwareInfo::Type firmwareType;

};

Expand Down
Loading

0 comments on commit 1656e09

Please sign in to comment.