2017-08-25 11:25:01 +02:00
|
|
|
/* Copyright (C) 2016-2017 Andreas Shimokawa, Carsten Pfeiffer
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2016-12-11 02:10:07 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2017-10-24 22:01:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
|
2017-10-21 22:50:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
|
2016-12-11 02:10:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
|
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
public class Mi2FirmwareInfo extends HuamiFirmwareInfo {
|
2016-12-11 02:10:07 +01:00
|
|
|
private static final byte[] FW_HEADER = new byte[]{
|
|
|
|
(byte) 0xa3,
|
|
|
|
(byte) 0x68,
|
|
|
|
(byte) 0x04,
|
|
|
|
(byte) 0x3b,
|
|
|
|
(byte) 0x02,
|
|
|
|
(byte) 0xdb,
|
|
|
|
(byte) 0xc8,
|
|
|
|
(byte) 0x58,
|
|
|
|
(byte) 0xd0,
|
|
|
|
(byte) 0x50,
|
|
|
|
(byte) 0xfa,
|
|
|
|
(byte) 0xe7,
|
|
|
|
(byte) 0x0c,
|
|
|
|
(byte) 0x34,
|
|
|
|
(byte) 0xf3,
|
|
|
|
(byte) 0xe7,
|
|
|
|
};
|
2017-03-07 23:20:59 +01:00
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
private static final int FW_HEADER_OFFSET = 0x150;
|
|
|
|
|
2017-08-25 00:21:47 +02:00
|
|
|
protected static Map<Integer,String> crcToVersion = new HashMap<>();
|
2016-12-11 02:10:07 +01:00
|
|
|
static {
|
2017-03-14 22:40:17 +01:00
|
|
|
// firmware
|
2016-12-11 02:10:07 +01:00
|
|
|
crcToVersion.put(41899, "1.0.0.39");
|
2017-03-14 22:40:17 +01:00
|
|
|
crcToVersion.put(49197, "1.0.0.53");
|
2017-03-15 00:26:39 +01:00
|
|
|
crcToVersion.put(32450, "1.0.1.28");
|
2017-03-14 22:40:17 +01:00
|
|
|
crcToVersion.put(51770, "1.0.1.34");
|
|
|
|
crcToVersion.put(3929, "1.0.1.39");
|
2017-11-11 20:55:16 +01:00
|
|
|
crcToVersion.put(47364 , "1.0.1.54");
|
2017-03-14 22:40:17 +01:00
|
|
|
|
|
|
|
// fonts
|
|
|
|
crcToVersion.put(45624, "Font");
|
|
|
|
crcToVersion.put(6377, "Font (En)");
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Mi2FirmwareInfo(byte[] bytes) {
|
2017-10-24 22:01:25 +02:00
|
|
|
super(bytes);
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
|
|
|
|
2017-10-21 22:50:28 +02:00
|
|
|
protected HuamiFirmwareType determineFirmwareType(byte[] bytes) {
|
2017-10-24 22:01:25 +02:00
|
|
|
if (ArrayUtils.startsWith(bytes, HuamiFirmwareInfo.FT_HEADER)) {
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.FONT;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
|
|
|
if (ArrayUtils.equals(bytes, FW_HEADER, FW_HEADER_OFFSET)) {
|
|
|
|
// TODO: this is certainly not a correct validation, but it works for now
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.FIRMWARE;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
2017-10-21 22:50:28 +02:00
|
|
|
return HuamiFirmwareType.INVALID;
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGenerallyCompatibleWith(GBDevice device) {
|
|
|
|
return isHeaderValid() && device.getType() == DeviceType.MIBAND2;
|
|
|
|
}
|
|
|
|
|
2017-10-24 22:01:25 +02:00
|
|
|
protected Map<Integer, String> getCrcMap() {
|
|
|
|
return crcToVersion;
|
2017-03-07 23:20:59 +01:00
|
|
|
}
|
2016-12-11 02:10:07 +01:00
|
|
|
}
|