Skip to content

Commit

Permalink
Switched to output indications until firmware fix is in place.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayalfredprufrock committed Jul 3, 2018
1 parent 6195c0d commit 09fd3a8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/aurorasdk/app/SDKExampleActivity.java
Expand Up @@ -188,7 +188,7 @@ public void onWriteFileClick(View v) {
public void onReadFileClick(View v)
{
//queueCommand(new CommandSdFileRead("test.txt", null));
queueCommand(new CommandSdFileRead("sessions/2018-05-22@215852/session.txt"), null);
queueCommand(new CommandSdFileRead("sessions/2018-05-22@215852/session.txt"));
}

public void onLoadProfileClick(View v) {
Expand All @@ -203,7 +203,7 @@ public void onUnloadProfileClick(View v)

public void onUpdateProfileClick(View v){

queueCommand(new CommandSdFileRead("profiles/default.prof", null), (readCmd) -> {
queueCommand(new CommandSdFileRead("profiles/default.prof"), (readCmd) -> {

if (!readCmd.hasError()){

Expand Down
2 changes: 1 addition & 1 deletion aurorasdk/publish.gradle
@@ -1,7 +1,7 @@
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

version '1.0.0'
version '1.0.1'
group 'com.iwinks'

publishing {
Expand Down
41 changes: 1 addition & 40 deletions aurorasdk/src/main/java/com/aurorasdk/Aurora.java
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.bluetooth.BluetoothDevice;

import java.nio.ByteBuffer;
import java.util.EnumSet;
import java.util.List;

Expand Down Expand Up @@ -115,38 +114,6 @@ public void startScan(ScanListener scanListener){

setConnectionState(reconnecting ? ConnectionState.RECONNECTING : ConnectionState.SCANNING);
}


/*
if (connectionState == ConnectionState.IDLE || connectionState == ConnectionState.DISCONNECTED) {
scanResults.clear();
boolean reconnecting = (connectionState == ConnectionState.DISCONNECTED) && !explicitDisconnect;
setConnectionState(reconnecting ? ConnectionState.RECONNECTING : ConnectionState.SCANNING);
if (scanObservable == null) {
scanObservable = rxBleClient.scanBleDevices(
new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.build(),
new ScanFilter.Builder()
.setServiceUuid(Constants.DREAMBAND_SERVICE_UUID)
.build()
).observeOn(AndroidSchedulers.mainThread());
}
scanSubscription = scanObservable.subscribe(this::onScanResult, this::onScanError);
}
*/
}

public void startScan(){
Expand All @@ -165,13 +132,6 @@ public void stopScan(){

setConnectionState(ConnectionState.IDLE);
}

/*
if (scanSubscription != null && !scanSubscription.isUnsubscribed()) {
scanSubscription.unsubscribe();
}
*/
}


Expand Down Expand Up @@ -434,6 +394,7 @@ else if (statusByte == 0){

@Override
public void onCommandOutput(byte[] data){

commandProcessor.processCommandOutput(data);
}

Expand Down
8 changes: 4 additions & 4 deletions aurorasdk/src/main/java/com/aurorasdk/AuroraBleCallbacks.java
Expand Up @@ -20,13 +20,13 @@ default void onBonded(final BluetoothDevice device) {}

default void onServicesDiscovered(final BluetoothDevice device, final boolean optionalServicesFound) {}

public void onCommandStatusChange(byte status, byte infoByte);
void onCommandStatusChange(byte status, byte infoByte);

public void onCommandOutput(byte[] data);
void onCommandOutput(byte[] data);

public void onCommandResponse(String responseLine);
void onCommandResponse(String responseLine);

public void onAuroraEvent(int eventId, long flags);
void onAuroraEvent(int eventId, long flags);



Expand Down
Expand Up @@ -9,6 +9,8 @@
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ArrayBlockingQueue;

import no.nordicsemi.android.ble.BleManager;
Expand Down Expand Up @@ -47,8 +49,15 @@ protected Deque<Request> initGatt(final BluetoothGatt gatt) {

final LinkedList<Request> requests = new LinkedList<>();
requests.push(Request.newEnableIndicationsRequest(commandStatusChar));
requests.push(Request.newEnableNotificationsRequest(commandOutputChar));
//requests.push(Request.newEnableNotificationsRequest(commandOutputChar));
requests.push(Request.newEnableIndicationsRequest(commandOutputChar));
requests.push(Request.newEnableNotificationsRequest(eventChar));

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Request.newConnectionPriorityRequest(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
}


return requests;
}

Expand All @@ -61,7 +70,8 @@ public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {

commandStatusChar = service.getCharacteristic(Constants.COMMAND_STATUS_UUID.getUuid());
commandDataChar = service.getCharacteristic(Constants.COMMAND_DATA_UUID.getUuid());
commandOutputChar = service.getCharacteristic(Constants.COMMAND_OUTPUT_NOTIFIED_UUID.getUuid());
//commandOutputChar = service.getCharacteristic(Constants.COMMAND_OUTPUT_NOTIFIED_UUID.getUuid());
commandOutputChar = service.getCharacteristic(Constants.COMMAND_OUTPUT_INDICATED_UUID.getUuid());
eventChar = service.getCharacteristic(Constants.EVENT_NOTIFIED_UUID.getUuid());

return commandStatusChar != null && commandDataChar != null;
Expand Down
Expand Up @@ -18,7 +18,7 @@ class CommandResponseParser {
private final Map<String, String> responseObject = new HashMap<>();
private final List<Map<String, String>> responseTable = new ArrayList<>();
private final List<String> responseColumns = new ArrayList<>();
private final ByteArrayOutputStream responseOutput = new ByteArrayOutputStream(4096);
private final ByteArrayOutputStream responseOutput = new ByteArrayOutputStream(1024*256);

private boolean isTable;
private boolean hasOutput;
Expand Down
3 changes: 3 additions & 0 deletions aurorasdk/src/main/java/com/aurorasdk/CommandSdFileRead.java
Expand Up @@ -23,11 +23,14 @@ public CommandSdFileRead(String destination) {
this.destination = destination;
}


@Override
public void setResponseObject(Map<String, String> responseObject) throws Exception {

super.setResponseObject(responseObject);

if (this.hasError()) return;

try {

byte[] decompressedOutput = decompress(getResponseOutput());
Expand Down
45 changes: 37 additions & 8 deletions aurorasdk/src/main/java/com/aurorasdk/Logger.java
Expand Up @@ -10,30 +10,59 @@ public class Logger {
private static boolean debug;
private static final String tag = "AURORA";

public enum LogType {
DEBUG, WARNING, ERROR
};

static void setDebug(boolean debug){

Logger.debug = debug;
}

static void d(String message){

if (debug){
static private void LogShort(LogType type, String message) {

Log.d(tag, message);
switch (type) {
case DEBUG:
Log.d(tag, message);
break;
case WARNING:
Log.w(tag, message);
break;
case ERROR:
Log.e(tag, message);
break;
}
}

static void w(String message){
static void Log(LogType type, String message){

if (debug){
if (debug || type == LogType.ERROR) {

Log.w(tag, message);
if (message.length() > 4000) {

LogShort(type, message.substring(0, 4000));
Log(type, message.substring(4000));

} else {

LogShort(type, message);
}
}
}

static void d(String message){

Log(LogType.DEBUG, message);
}

static void w(String message){

Log(LogType.WARNING, message);
}

static void e(String message){

Log.e(tag, message);
Log(LogType.ERROR, message);
}

}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -11,7 +11,7 @@
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

libraryVersion = 1.0.0
libraryVersion = 1.0.1
libraryName = aurorasdk
libraryDescription = Official SDK for the Aurora Dreamband.
publishedGroupId = com.iwinks
Expand Down

0 comments on commit 09fd3a8

Please sign in to comment.