Skip to content

Commit

Permalink
Blind implement file download for original GTR
Browse files Browse the repository at this point in the history
Should at least support GPS and Watchface

Fixes #250
  • Loading branch information
piggz committed Dec 28, 2023
1 parent 1988a6a commit 946bd94
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
2 changes: 2 additions & 0 deletions daemon/daemon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ SOURCES += \
src/devices/gtr2device.cpp \
src/devices/gtr2firmwareinfo.cpp \
src/devices/gtrdevice.cpp \
src/devices/gtrfirmwareinfo.cpp \
src/devices/gts2device.cpp \
src/devices/gts2firmwareinfo.cpp \
src/devices/huamidevice.cpp \
Expand Down Expand Up @@ -181,6 +182,7 @@ HEADERS += \
src/devices/gtr2device.h \
src/devices/gtr2firmwareinfo.h \
src/devices/gtrdevice.h \
src/devices/gtrfirmwareinfo.h \
src/devices/gts2device.h \
src/devices/gts2firmwareinfo.h \
src/devices/huamidevice.h \
Expand Down
6 changes: 6 additions & 0 deletions daemon/src/devices/gtrdevice.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "gtrdevice.h"
#include "gtrfirmwareinfo.h"
#include <QtXml/QtXml>
#include <QTimer>

Expand All @@ -18,6 +19,11 @@ bool GtrDevice::is47mm(const QString &version) const
return version >= "1.0.0.00" && version < "1.6.0.00";
}

AbstractFirmwareInfo *GtrDevice::firmwareInfo(const QByteArray &bytes)
{
return new GtrFirmwareInfo(bytes);
}

void GtrDevice::initialise()
{
qDebug() << Q_FUNC_INFO;
Expand Down
2 changes: 2 additions & 0 deletions daemon/src/devices/gtrdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class GtrDevice : public GtsDevice
explicit GtrDevice(const QString &pairedName, QObject *parent = nullptr);
QString deviceType() const override;

virtual AbstractFirmwareInfo *firmwareInfo(const QByteArray &bytes) override;

protected:
void initialise() override;
void parseServices();
Expand Down
122 changes: 122 additions & 0 deletions daemon/src/devices/gtrfirmwareinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "gtrfirmwareinfo.h"
#include <QDebug>

GtrFirmwareInfo::GtrFirmwareInfo(const QByteArray &bytes)
{
m_bytes = bytes;

calculateCRC16();
calculateCRC32();
determineFirmwareType();
determineFirmwareVersion();

//qDebug() << mBytes;
qDebug() << m_type << m_version << m_crc16 << m_crc32;
}

void GtrFirmwareInfo::determineFirmwareType() {
qDebug() << "Determining firmware type";
m_type = Invalid;

if (m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(NEWRES_HEADER)) == COMPRESSED_RES_HEADER_OFFSET_NEW) {
m_type = Res_Compressed;
}
if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(GPS_HEADER)) || m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(GPS_HEADER2)) || m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(GPS_HEADER3)) || m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(GPS_HEADER4))) {
m_type = GPS;
}
if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(GPS_ALMANAC_HEADER))) {
m_type = GPS_ALMANAC;
}
if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(AGPS_UIHH_HEADER))) {
m_type = GPS_UIHH;
}
if (m_bytes.indexOf(UCHARARR_TO_BYTEARRAY(FW_HEADER2)) == FW_OFFSET) {
m_version = m_crcMap[m_crc16];
qDebug() << "Version:" << m_version << "CRC:" << m_crc16;
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) {
m_type = Watchface;
}
if (m_bytes.startsWith(UCHARARR_TO_BYTEARRAY(NEWFT_HEADER))) {
if (m_bytes.at(10) == 0x01) {
m_type = Font;
} else if (m_bytes.at(10) == 0x02) {
m_type = Font_Latin;
}
}
}

bool GtrFirmwareInfo::supportedOnDevice(const QString &device) const
{
qDebug() << "Checking if device suppoerted: " << device;
return device == "Amazfit GTR" && m_type != Invalid && !m_version.contains("unknown");
}

void GtrFirmwareInfo::determineFirmwareVersion()
{
QString version = m_crcMap[m_crc16];

if (!version.isEmpty()) {
switch (m_type) {
case Firmware:
version = "FW " + version;
break;
case Res:
version = "RES " + version;
break;
case Res_Compressed:
version = "RES_COMPRESSED " + version;
break;
case Font:
version = "FONT " + version;
break;
case Font_Latin:
version = "FONT LATIN " + version;
break;
case GPS:
version = "GPS " + version;
break;
default:
version = "Invalid";
}
} else {
switch (m_type) {
case Firmware:
version = "FW (unknown)";
break;
case Res:
version = "RES (unknown)";
break;
case Res_Compressed:
version = "RES_COMPRESSED (unknown)";
break;
case Font:
version = "FONT (unknown)";
break;
case Font_Latin:
version = "FONT LATIN (unknown)";
break;
case GPS:
version = "GPS (unknown)";
break;
case GPS_CEP:
version = "CEP";
break;
case GPS_UIHH:
version = "GPS_UIHH";
break;
case GPS_ALMANAC:
version = "ALM";
break;
case Watchface:
version = "Watchface";
break;
default:
version = "(unknown)";
}
}

m_version = version;
}
21 changes: 21 additions & 0 deletions daemon/src/devices/gtrfirmwareinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef GTRFIRMWAREINFO_H
#define GTRFIRMWAREINFO_H

#include "huamifirmwareinfo.h"

class GtrFirmwareInfo : public HuamiFirmwareInfo
{
public:
explicit GtrFirmwareInfo(const QByteArray &bytes);

virtual bool supportedOnDevice(const QString &device) const override;

private:
void determineFirmwareType();
void determineFirmwareVersion();

QMap<uint16_t, QString> m_crcMap;

};

#endif // GTSFIRMWAREINFO_H

0 comments on commit 946bd94

Please sign in to comment.