2018-02-26 14:27:32 +01:00
|
|
|
/* Copyright (C) 2016-2018 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-03-20 01:05:23 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
|
|
|
|
|
2016-03-20 23:41:57 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2016-03-20 01:05:23 +01:00
|
|
|
/**
|
|
|
|
* FW1 is Mi Band firmware
|
|
|
|
* FW2 is heartrate firmware
|
|
|
|
*/
|
|
|
|
public class Mi1SFirmwareInfoFW1 extends AbstractMi1SFirmwareInfo {
|
2016-03-20 23:41:57 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW1.class);
|
2016-03-20 01:05:23 +01:00
|
|
|
private static final int MI1S_FW_BASE_OFFSET = 1092;
|
|
|
|
|
|
|
|
Mi1SFirmwareInfoFW1(@NonNull byte[] wholeFirmwareBytes) {
|
|
|
|
super(wholeFirmwareBytes);
|
|
|
|
}
|
|
|
|
|
2016-03-21 23:41:37 +01:00
|
|
|
@Override
|
|
|
|
protected boolean isHeaderValid() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-20 01:05:23 +01:00
|
|
|
@Override
|
2016-03-20 15:00:05 +01:00
|
|
|
public int getFirmwareOffset() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return (wholeFirmwareBytes[12] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[13] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[14] & 255) << 8
|
|
|
|
| (wholeFirmwareBytes[15] & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-20 15:00:05 +01:00
|
|
|
public int getFirmwareLength() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return (wholeFirmwareBytes[16] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[17] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[18] & 255) << 8
|
|
|
|
| (wholeFirmwareBytes[19] & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-20 15:00:05 +01:00
|
|
|
public int getFirmwareVersion() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return (wholeFirmwareBytes[8] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[9] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[10] & 255) << 8
|
|
|
|
| wholeFirmwareBytes[11] & 255;
|
|
|
|
}
|
|
|
|
|
2016-03-20 15:00:05 +01:00
|
|
|
@Override
|
2016-03-20 01:05:23 +01:00
|
|
|
protected boolean isGenerallySupportedFirmware() {
|
|
|
|
try {
|
|
|
|
int majorVersion = getFirmwareVersionMajor();
|
2016-03-20 23:41:57 +01:00
|
|
|
if (majorVersion == 4) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
LOG.warn("Only major version 4 is supported for 1S fw1: " + majorVersion);
|
|
|
|
}
|
|
|
|
} catch (IllegalArgumentException ex) {
|
|
|
|
LOG.warn("not supported 1S firmware 1: " + ex.getLocalizedMessage(), ex);
|
2016-03-20 01:05:23 +01:00
|
|
|
}
|
2016-03-20 23:41:57 +01:00
|
|
|
return false;
|
2016-03-20 15:00:05 +01:00
|
|
|
}
|
2016-03-20 01:05:23 +01:00
|
|
|
}
|