1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Amazfit Bip/Cor: parse and display firmware version for unknown versions

Unfortunately that does not work for the Mi Band 2 yet
This commit is contained in:
Andreas Shimokawa 2017-12-10 11:30:31 +01:00
parent d447829d6f
commit ff93122ddc
2 changed files with 40 additions and 6 deletions

View File

@ -17,6 +17,8 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -41,7 +43,11 @@ public abstract class HuamiFirmwareInfo {
private HuamiFirmwareType firmwareType = HuamiFirmwareType.FIRMWARE;
public String toVersion(int crc16) {
return getCrcMap().get(crc16);
String version = getCrcMap().get(crc16);
if (version == null) {
version = searchVersion(bytes);
}
return version;
}
public int[] getWhitelistedVersions() {
@ -52,12 +58,9 @@ public abstract class HuamiFirmwareInfo {
private byte[] bytes;
private String firmwareVersion;
public HuamiFirmwareInfo(byte[] bytes) {
this.bytes = bytes;
crc16 = CheckSums.getCRC16(bytes);
firmwareVersion = getCrcMap().get(crc16);
firmwareType = determineFirmwareType(bytes);
}
@ -98,4 +101,28 @@ public abstract class HuamiFirmwareInfo {
protected abstract Map<Integer, String> getCrcMap();
protected abstract HuamiFirmwareType determineFirmwareType(byte[] bytes);
protected String searchVersion(byte[] fwbytes) {
ByteBuffer buf = ByteBuffer.wrap(fwbytes);
buf.order(ByteOrder.BIG_ENDIAN);
while (buf.remaining() > 3) {
int word = buf.getInt();
if (word == 0x5625642e) {
word = buf.getInt();
if (word == 0x25642e25) {
word = buf.getInt();
if (word == 0x642e2564) {
word = buf.getInt();
if (word == 0x00000000) {
byte version[] = new byte[8];
buf.get(version);
return new String(version);
}
}
}
}
}
return null;
}
}

View File

@ -47,7 +47,8 @@ public class Mi2FirmwareInfo extends HuamiFirmwareInfo {
private static final int FW_HEADER_OFFSET = 0x150;
protected static Map<Integer,String> crcToVersion = new HashMap<>();
protected static Map<Integer, String> crcToVersion = new HashMap<>();
static {
// firmware
crcToVersion.put(41899, "1.0.0.39");
@ -55,7 +56,7 @@ public class Mi2FirmwareInfo extends HuamiFirmwareInfo {
crcToVersion.put(32450, "1.0.1.28");
crcToVersion.put(51770, "1.0.1.34");
crcToVersion.put(3929, "1.0.1.39");
crcToVersion.put(47364 , "1.0.1.54");
crcToVersion.put(47364, "1.0.1.54");
// fonts
crcToVersion.put(45624, "Font");
@ -84,4 +85,10 @@ public class Mi2FirmwareInfo extends HuamiFirmwareInfo {
protected Map<Integer, String> getCrcMap() {
return crcToVersion;
}
@Override
protected String searchVersion(byte[] fwbytes) {
// does not work for Mi Band 2
return null;
}
}