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 Mi1SFirmwareInfoFW2 extends AbstractMi1SFirmwareInfo {
|
2016-03-20 23:41:57 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(Mi1SFirmwareInfoFW2.class);
|
2016-03-20 01:05:23 +01:00
|
|
|
|
|
|
|
Mi1SFirmwareInfoFW2(@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[26] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[27] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[28] & 255) << 8
|
|
|
|
| (wholeFirmwareBytes[29] & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-20 15:00:05 +01:00
|
|
|
public int getFirmwareLength() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return (wholeFirmwareBytes[30] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[31] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[32] & 255) << 8
|
|
|
|
| (wholeFirmwareBytes[33] & 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isGenerallySupportedFirmware() {
|
|
|
|
try {
|
|
|
|
int majorVersion = getFirmwareVersionMajor();
|
2016-03-20 23:41:57 +01:00
|
|
|
if (majorVersion == 1) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
LOG.warn("Only major version 1 is supported for 1S fw2: " + majorVersion);
|
|
|
|
}
|
|
|
|
} catch (IllegalArgumentException ex) {
|
|
|
|
LOG.warn("not supported 1S firmware 2: " + ex.getLocalizedMessage(), ex);
|
2016-03-20 01:05:23 +01:00
|
|
|
}
|
2016-03-20 23:41:57 +01:00
|
|
|
return false;
|
2016-03-20 01:05:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-20 15:00:05 +01:00
|
|
|
public int getFirmwareVersion() {
|
2016-03-20 01:05:23 +01:00
|
|
|
return (wholeFirmwareBytes[22] & 255) << 24
|
|
|
|
| (wholeFirmwareBytes[23] & 255) << 16
|
|
|
|
| (wholeFirmwareBytes[24] & 255) << 8
|
|
|
|
| wholeFirmwareBytes[25] & 255;
|
|
|
|
}
|
|
|
|
}
|