diff --git a/daemon/daemon.pro b/daemon/daemon.pro index eaa11d2d..9e027ff2 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -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 \ @@ -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 \ diff --git a/daemon/src/devices/gtrdevice.cpp b/daemon/src/devices/gtrdevice.cpp index 9c31208a..8cecffdc 100644 --- a/daemon/src/devices/gtrdevice.cpp +++ b/daemon/src/devices/gtrdevice.cpp @@ -1,4 +1,5 @@ #include "gtrdevice.h" +#include "gtrfirmwareinfo.h" #include #include @@ -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; diff --git a/daemon/src/devices/gtrdevice.h b/daemon/src/devices/gtrdevice.h index e6b72c3f..0f2b8850 100644 --- a/daemon/src/devices/gtrdevice.h +++ b/daemon/src/devices/gtrdevice.h @@ -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(); diff --git a/daemon/src/devices/gtrfirmwareinfo.cpp b/daemon/src/devices/gtrfirmwareinfo.cpp new file mode 100644 index 00000000..c7a26d5d --- /dev/null +++ b/daemon/src/devices/gtrfirmwareinfo.cpp @@ -0,0 +1,122 @@ +#include "gtrfirmwareinfo.h" +#include + +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; +} diff --git a/daemon/src/devices/gtrfirmwareinfo.h b/daemon/src/devices/gtrfirmwareinfo.h new file mode 100644 index 00000000..2ec1eb6c --- /dev/null +++ b/daemon/src/devices/gtrfirmwareinfo.h @@ -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 m_crcMap; + +}; + +#endif // GTSFIRMWAREINFO_H