Skip to content

Commit

Permalink
v3.4.6 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed May 9, 2018
1 parent 03dae0d commit e5e3506
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 03 11:31:01 PST 2017
#Wed Apr 18 15:11:05 PDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 18
targetSdkVersion 27
versionCode 55
versionName "3.4.0"
versionCode 56
versionName "3.4.6"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -223,8 +224,8 @@ void disconnected(int status) {
if (disconnectTaskSrc == null || disconnectTaskSrc.getTask().isCompleted()) {
dcHandler.onUnexpectedDisconnect(status);
} else {
disconnectTaskSrc.setResult(null);
dcHandler.onDisconnect();
disconnectTaskSrc.setResult(null);
}
}
}
Expand Down Expand Up @@ -283,22 +284,26 @@ public Task<File> downloadFileAsync(final String srcUrl, final String dest) {
urlConn.set((HttpURLConnection) fileUrl.openConnection());
InputStream ins = urlConn.get().getInputStream();

File firmwareDir = new File(getFilesDir(), DOWNLOAD_DIR_NAME);
if (!firmwareDir.exists()) {
firmwareDir.mkdir();
}
int code = urlConn.get().getResponseCode();
if (code == HttpURLConnection.HTTP_OK) {
File firmwareDir = new File(getFilesDir(), DOWNLOAD_DIR_NAME);
if (!firmwareDir.exists()) {
firmwareDir.mkdir();
}

File location = new File(firmwareDir, dest);
FileOutputStream fos = new FileOutputStream(location);
File location = new File(firmwareDir, dest);
FileOutputStream fos = new FileOutputStream(location);

byte data[] = new byte[1024];
int count;
while ((count = ins.read(data)) != -1) {
fos.write(data, 0, count);
}
fos.close();
byte data[] = new byte[1024];
int count;
while ((count = ins.read(data)) != -1) {
fos.write(data, 0, count);
}
fos.close();

return location;
return location;
}
throw new IOException(String.format("Could not retrieve resource (response = %d, msg = %s)", code, urlConn.get().getResponseMessage()));
}).continueWithTask(ignored -> {
if (urlConn.get() != null) {
urlConn.get().disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ static String createUri(DataTypeBase dataType) {
return "bosch-motion";
case TAP_INTERRUPT:
return "bosch-tap";
case PACKED_ACC_DATA:
return "acceleration";
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static String createUri(DataTypeBase dataType) {
return "mma8452q-tap";
case MOVEMENT_VALUE:
return "mma8452q-movement";
case PACKED_ACC_DATA:
return "acceleration";
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static String createUri(DataTypeBase dataType) {
switch (dataType.eventConfig[1]) {
case DATA:
return dataType.attributes.length() > 2 ? "angular-velocity" : String.format(Locale.US, "angular-velocity[%d]", (dataType.attributes.offset >> 1));
case PACKED_DATA:
return "angular-velocity";
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class JseMetaWearBoard implements MetaWearBoard {

private static final long RELEASE_INFO_TTL = 1800000L;
private static final byte READ_INFO_REGISTER= Util.setRead((byte) 0x0);
private final static String FIRMWARE_BUILD= "vanilla", LOG_TAG = "metawear";
private final static String FIRMWARE_BUILD= "vanilla", LOG_TAG = "metawear", RELEASES_URL = "https://mbientlab.com/releases";
private final static String BOARD_INFO= "com.mbientlab.metawear.impl.JseMetaWearBoard.BOARD_INFO",
BOARD_STATE = "com.mbientlab.metawear.impl.JseMetaWearBoard.BOARD_STATE";

Expand Down Expand Up @@ -375,6 +375,14 @@ public void onUnexpectedDisconnect(int status) {
});
}

public String getFirmware() {
return persist.boardInfo.firmware.toString();
}

public String getModelNumber() {
return persist.boardInfo.modelNumber;
}

@Override
public Model getModel() {
if (persist.boardInfo.modelNumber == null) {
Expand Down Expand Up @@ -503,7 +511,8 @@ private String buildFirmwareFileName(Pair<Version, String> latest) {
}

private Task<File> downloadFirmware(Pair<Version, String> latest) {
String dlUrl = String.format(Locale.US, "https://releases.mbientlab.com/metawear/%s/%s/%s/%s/%s",
String dlUrl = String.format(Locale.US, "%s/metawear/%s/%s/%s/%s/%s",
RELEASES_URL,
persist.boardInfo.hardwareRevision,
persist.boardInfo.modelNumber,
FIRMWARE_BUILD, latest.first.toString(), latest.second
Expand All @@ -518,7 +527,7 @@ public Task<File> downloadFirmwareAsync(final String version) {
if (version == null) {
File info1Json = io.findDownloadedFile("info1.json");
if (!info1Json.exists() || info1Json.lastModified() < Calendar.getInstance().getTimeInMillis() - RELEASE_INFO_TTL) {
return io.downloadFileAsync("https://releases.mbientlab.com/metawear/info1.json", "info1.json")
return io.downloadFileAsync(String.format(Locale.US, "%s/metawear/info1.json", RELEASES_URL), "info1.json")
.onSuccessTask(task -> downloadFirmware(findRelease(task.getResult())));
} else {
try {
Expand Down Expand Up @@ -600,6 +609,27 @@ private Pair<Version, String> findRelease(File releaseInfo) throws JSONException
throw new IllegalStateException("No information available for this board");
}

public void loadBoardAttributes() throws IOException, ClassNotFoundException {
if (persist.boardInfo == null) {
InputStream ins = io.localRetrieve(BOARD_INFO);
if (ins != null) {
ObjectInputStream ois = new ObjectInputStream(ins);
BoardInfo boardInfoState = (BoardInfo) ois.readObject();

if (boardInfoState != null) {
persist.boardInfo = boardInfoState;
for (ModuleInfo it : boardInfoState.moduleInfo.values()) {
instantiateModule(it);
}
} else {
persist.boardInfo = new BoardInfo();
}
} else {
persist.boardInfo = new BoardInfo();
}
}
}

private Task<Queue<ModuleInfo>> discoverModules(Collection<Constant.Module> ignore) {
final Queue<ModuleInfo> info = new LinkedList<>();
final Queue<Constant.Module> modules = new LinkedList<>();
Expand Down Expand Up @@ -640,24 +670,7 @@ public Task<Void> connectAsync() {
return Task.cancelled();
}

if (persist.boardInfo == null) {
InputStream ins = io.localRetrieve(BOARD_INFO);
if (ins != null) {
ObjectInputStream ois = new ObjectInputStream(ins);
BoardInfo boardInfoState = (BoardInfo) ois.readObject();

if (boardInfoState != null) {
persist.boardInfo = boardInfoState;
for (ModuleInfo it : boardInfoState.moduleInfo.values()) {
instantiateModule(it);
}
} else {
persist.boardInfo = new BoardInfo();
}
} else {
persist.boardInfo = new BoardInfo();
}
}
loadBoardAttributes();

return gatt.readCharacteristicAsync(DeviceInformationService.FIRMWARE_REVISION);
}).onSuccessTask(task -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ static String createUri(DataTypeBase dataType) {
switch (dataType.eventConfig[1]) {
case MAG_DATA:
return dataType.attributes.length() > 2 ? "magnetic-field" : String.format(Locale.US, "magnetic-field[%d]", (dataType.attributes.offset >> 1));
case PACKED_MAG_DATA:
return "magnetic-field";
default:
return null;
}
Expand Down

0 comments on commit e5e3506

Please sign in to comment.