From 5608febffa11ca576aacc197a50bd87f9ecce448 Mon Sep 17 00:00:00 2001 From: Adam Pigg Date: Thu, 28 Dec 2023 13:15:29 +0000 Subject: [PATCH] Implement download of Watchfaces for GTS2/GTR2 Use C++17 (1z in old Qt) to make static definitions inline --- daemon/daemon.pro | 2 +- daemon/src/devices/gtr2firmwareinfo.cpp | 2 +- daemon/src/devices/gts2firmwareinfo.cpp | 2 +- daemon/src/devices/gtsdevice.cpp | 6 ++- daemon/src/devices/huamifirmwareinfo.h | 40 ++++++++++--------- .../huamiupdatefirmwareoperation2020.cpp | 21 +++++++++- .../huamiupdatefirmwareoperation2020.h | 4 +- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/daemon/daemon.pro b/daemon/daemon.pro index 1e2699aa..eaa11d2d 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -16,7 +16,7 @@ LIBS += -Lqble/qble -L$$OUT_PWD/../lib -lamazfish -lz PKGCONFIG += dbus-1 PKGCONFIG += icu-uc icu-io icu-i18n # transliteration QT += positioning KDb3 network dbus KArchive -CONFIG += c++17 +CONFIG += c++17 c++1z equals(FLAVOR, "silica") { CONFIG += flavor_silica diff --git a/daemon/src/devices/gtr2firmwareinfo.cpp b/daemon/src/devices/gtr2firmwareinfo.cpp index 5dfd3072..e8881bdc 100644 --- a/daemon/src/devices/gtr2firmwareinfo.cpp +++ b/daemon/src/devices/gtr2firmwareinfo.cpp @@ -41,7 +41,7 @@ void Gtr2FirmwareInfo::determineFirmwareType() { // m_type = Firmware; // } - if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET_NEW) { + if ((m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(UIHH_HEADER)) && (m_bytes.at(4) == 0x01 || m_bytes.at(4) == 0x02)) || m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET_NEW) { m_type = Watchface; } if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(NEWFT_HEADER))) { diff --git a/daemon/src/devices/gts2firmwareinfo.cpp b/daemon/src/devices/gts2firmwareinfo.cpp index 653d2999..8e51a5f1 100644 --- a/daemon/src/devices/gts2firmwareinfo.cpp +++ b/daemon/src/devices/gts2firmwareinfo.cpp @@ -41,7 +41,7 @@ void Gts2FirmwareInfo::determineFirmwareType() { // m_type = Firmware; // } - if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET_NEW) { + if ((m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(UIHH_HEADER)) && (m_bytes.at(4) == 0x01 || m_bytes.at(4) == 0x02)) || m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET || m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(WATCHFACE_HEADER)) == COMPRESSED_RES_HEADER_OFFSET_NEW) { m_type = Watchface; } if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(NEWFT_HEADER))) { diff --git a/daemon/src/devices/gtsdevice.cpp b/daemon/src/devices/gtsdevice.cpp index f2e29706..403a3ee0 100644 --- a/daemon/src/devices/gtsdevice.cpp +++ b/daemon/src/devices/gtsdevice.cpp @@ -216,10 +216,12 @@ void GtsDevice::sendEventReminder(int id, const QDateTime &dt, const QString &ev void GtsDevice::prepareFirmwareDownload(const AbstractFirmwareInfo *info) { BipFirmwareService *fw = qobject_cast(service(BipFirmwareService::UUID_SERVICE_FIRMWARE)); - if (fw){ + MiBandService *mi = qobject_cast(service(MiBandService::UUID_SERVICE_MIBAND)); + + if (fw && mi){ QString revision = softwareRevision(); if (revision > "0.1.1.16") { - fw->prepareFirmwareDownload(info, new HuamiUpdateFirmwareOperation2020(info, fw)); + fw->prepareFirmwareDownload(info, new HuamiUpdateFirmwareOperation2020(info, fw, *mi)); } else { fw->prepareFirmwareDownload(info, new UpdateFirmwareOperationNew(info, fw)); } diff --git a/daemon/src/devices/huamifirmwareinfo.h b/daemon/src/devices/huamifirmwareinfo.h index e38654a3..acd76cda 100644 --- a/daemon/src/devices/huamifirmwareinfo.h +++ b/daemon/src/devices/huamifirmwareinfo.h @@ -8,69 +8,73 @@ class HuamiFirmwareInfo : public AbstractFirmwareInfo public: HuamiFirmwareInfo(); - const int FW_OFFSET = 0x3; - const int FONT_TYPE_OFFSET = 0x9; - const int COMPRESSED_RES_HEADER_OFFSET = 0x9; - const int COMPRESSED_RES_HEADER_OFFSET_NEW = 0xd; + static const int FW_OFFSET = 0x3; + static const int FONT_TYPE_OFFSET = 0x9; + static const int COMPRESSED_RES_HEADER_OFFSET = 0x9; + static const int COMPRESSED_RES_HEADER_OFFSET_NEW = 0xd; - const uint8_t RES_HEADER[5]{ // HMRES resources file (*.res) + static constexpr uint8_t RES_HEADER[5]{ // HMRES resources file (*.res) 0x48, 0x4d, 0x52, 0x45, 0x53 }; - const uint8_t NEWRES_HEADER[5] = { // NERES resources file (*.res) + static constexpr uint8_t NEWRES_HEADER[5] = { // NERES resources file (*.res) 0x4e, 0x45, 0x52, 0x45, 0x53 }; - const uint8_t WATCHFACE_HEADER[6] = { //HMDIAL watchface + static constexpr uint8_t WATCHFACE_HEADER[6] = { //HMDIAL watchface 0x48, 0x4d, 0x44, 0x49, 0x41, 0x4c }; - const uint8_t FT_HEADER[4] = { // HMZK font file (*.ft, *.ft.xx) + static constexpr uint8_t FT_HEADER[4] = { // HMZK font file (*.ft, *.ft.xx) 0x48, 0x4d, 0x5a, 0x4b }; - const uint8_t NEWFT_HEADER[4] = { // NEZK font file (*.ft, *.ft.xx) + static constexpr uint8_t NEWFT_HEADER[4] = { // NEZK font file (*.ft, *.ft.xx) 0x4e, 0x45, 0x5a, 0x4b }; - const uint8_t GPS_HEADER[16] = { + static constexpr uint8_t GPS_HEADER[16] = { 0xcb, 0x51, 0xc1, 0x30, 0x41, 0x9e, 0x5e, 0xd3, 0x51, 0x35, 0xdf, 0x66, 0xed, 0xd9, 0x5f, 0xa7 }; - const uint8_t GPS_HEADER2[16] = { + static constexpr uint8_t GPS_HEADER2[16] = { 0x10, 0x50, 0x26, 0x76, 0x8f, 0x4a, 0xa1, 0x49, 0xa7, 0x26, 0xd0, 0xe6, 0x4a, 0x21, 0x88, 0xd4 }; - const uint8_t GPS_HEADER3[16] = { + static constexpr uint8_t GPS_HEADER3[16] = { 0xeb, 0xfa, 0xc5, 0x89, 0xf0, 0x5c, 0x2e, 0xcc, 0xfa, 0xf3, 0x62, 0xeb, 0x92, 0xc6, 0xa1, 0xbb }; - const uint8_t GPS_HEADER4[16] = { + static constexpr uint8_t GPS_HEADER4[16] = { 0x0b, 0x61, 0x53, 0xed, 0x83, 0xac, 0x07, 0x21, 0x8c, 0x36, 0x2e, 0x8c, 0x9c, 0x08, 0x54, 0xa6 }; - const uint8_t GPS_ALMANAC_HEADER[5] = { // probably wrong + static constexpr uint8_t GPS_ALMANAC_HEADER[5] = { // probably wrong 0xa0, 0x80, 0x08, 0x00, 0x8b }; - const uint8_t GPS_CEP_HEADER[4]{ // probably wrong + static constexpr uint8_t GPS_CEP_HEADER[4]{ // probably wrong 0x2a, 0x12, 0xa0, 0x02 }; - const uint8_t AGPS_UIHH_HEADER[5]{ // probably wrong + static constexpr uint8_t UIHH_HEADER[4]{ // + 'U', 'I', 'H', 'H' + }; + + static constexpr uint8_t AGPS_UIHH_HEADER[5]{ // probably wrong 'U', 'I', 'H', 'H', 0x04 }; // this is the same as Cor - const uint8_t FW_HEADER[16] = { + static constexpr uint8_t FW_HEADER[16] = { 0x00, 0x98, 0x00, 0x20, 0xA5, 0x04, 0x00, 0x20, 0xAD, 0x04, 0x00, 0x20, 0xC5, 0x04, 0x00, 0x20 }; - const uint8_t FW_HEADER2[5] = { + static constexpr uint8_t FW_HEADER2[5] = { 0x20, 0x99, 0x12, 0x01, 0x08 //probably nonsense }; diff --git a/daemon/src/operations/huamiupdatefirmwareoperation2020.cpp b/daemon/src/operations/huamiupdatefirmwareoperation2020.cpp index 697552a6..f9957c3b 100644 --- a/daemon/src/operations/huamiupdatefirmwareoperation2020.cpp +++ b/daemon/src/operations/huamiupdatefirmwareoperation2020.cpp @@ -1,6 +1,7 @@ #include "huamiupdatefirmwareoperation2020.h" #include"typeconversion.h" #include "bipfirmwareservice.h" +#include "mibandservice.h" constexpr uint8_t HuamiUpdateFirmwareOperation2020::COMMAND_REQUEST_PARAMETERS; constexpr uint8_t HuamiUpdateFirmwareOperation2020::COMMAND_START_FILE; @@ -11,7 +12,7 @@ constexpr uint8_t HuamiUpdateFirmwareOperation2020::COMMAND_COMPLETE_TRANSFER; constexpr uint8_t HuamiUpdateFirmwareOperation2020::COMMAND_FINALIZE_UPDATE; -HuamiUpdateFirmwareOperation2020::HuamiUpdateFirmwareOperation2020(const AbstractFirmwareInfo *info, QBLEService *service) : UpdateFirmwareOperation(info, service) +HuamiUpdateFirmwareOperation2020::HuamiUpdateFirmwareOperation2020(const AbstractFirmwareInfo *info, QBLEService *service, QBLEService &mibandService) : UpdateFirmwareOperation(info, service), m_mibandService(mibandService) { qDebug() << Q_FUNC_INFO; } @@ -119,6 +120,24 @@ bool HuamiUpdateFirmwareOperation2020::sendFwInfo() int arraySize = 14; QByteArray bytes(arraySize, char(0x00)); + //Special command for watchface + if (m_info->type() == AbstractFirmwareInfo::Watchface) { + if (m_fwBytes.startsWith(UCHARARR_TO_BYTEARRAY(HuamiFirmwareInfo::UIHH_HEADER))) { + + uint8_t watchfaceConfig[10] = {0x39, 0x00, + sizeBytes[0], + sizeBytes[1], + sizeBytes[2], + sizeBytes[3], + m_fwBytes[18], + m_fwBytes[19], + m_fwBytes[20], + m_fwBytes[21] + }; + m_mibandService.writeValue(MiBandService::UUID_CHARACTERISTIC_MIBAND_CONFIGURATION, UCHARARR_TO_BYTEARRAY(watchfaceConfig)); + } + } + int i = 0; bytes[i++] = COMMAND_SEND_FIRMWARE_INFO; bytes[i++] = m_info->type(); diff --git a/daemon/src/operations/huamiupdatefirmwareoperation2020.h b/daemon/src/operations/huamiupdatefirmwareoperation2020.h index 9613f6d4..4238f9b6 100644 --- a/daemon/src/operations/huamiupdatefirmwareoperation2020.h +++ b/daemon/src/operations/huamiupdatefirmwareoperation2020.h @@ -6,7 +6,7 @@ class HuamiUpdateFirmwareOperation2020 : public UpdateFirmwareOperation { public: - HuamiUpdateFirmwareOperation2020(const AbstractFirmwareInfo *info, QBLEService *service); + HuamiUpdateFirmwareOperation2020(const AbstractFirmwareInfo *info, QBLEService *service, QBLEService &mibandService); bool handleMetaData(const QByteArray &meta) override; void start() override; @@ -29,6 +29,8 @@ class HuamiUpdateFirmwareOperation2020 : public UpdateFirmwareOperation void sendTransferComplete(); void sendFinalize(); + QBLEService &m_mibandService; + int mChunkLength = -1; };