Skip to content

Commit

Permalink
Implement download of Watchfaces for GTS2/GTR2
Browse files Browse the repository at this point in the history
Use C++17 (1z in old Qt) to make static definitions inline
  • Loading branch information
piggz committed Dec 28, 2023
1 parent 8315131 commit 5608feb
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion daemon/daemon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/devices/gtr2firmwareinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/devices/gts2firmwareinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
6 changes: 4 additions & 2 deletions daemon/src/devices/gtsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BipFirmwareService*>(service(BipFirmwareService::UUID_SERVICE_FIRMWARE));
if (fw){
MiBandService *mi = qobject_cast<MiBandService*>(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));
}
Expand Down
40 changes: 22 additions & 18 deletions daemon/src/devices/huamifirmwareinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
21 changes: 20 additions & 1 deletion daemon/src/operations/huamiupdatefirmwareoperation2020.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion daemon/src/operations/huamiupdatefirmwareoperation2020.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +29,8 @@ class HuamiUpdateFirmwareOperation2020 : public UpdateFirmwareOperation
void sendTransferComplete();
void sendFinalize();

QBLEService &m_mibandService;

int mChunkLength = -1;
};

Expand Down

0 comments on commit 5608feb

Please sign in to comment.