Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
cbb83bb
Android Studio 3.1.2
philips77 Apr 30, 2018
2397aa9
Switching to external BLE Library v2
philips77 Apr 30, 2018
831cae7
Migrating to BLE Library v2
philips77 Apr 30, 2018
0171229
Code cleanup, comments, warnings etc.
philips77 May 16, 2018
7df5d0f
Fix Mcu Mgr Transport to match BLE lib changes
philips77 May 16, 2018
5daf954
Refactoring in the sample app
philips77 May 16, 2018
3fd5622
Merge branch 'master' into ble_lib_v2
philips77 May 16, 2018
bc7530c
Reverting access modifiers
philips77 May 22, 2018
0ff0ad0
Merge branch 'master' into ble_lib_v2
philips77 May 25, 2018
aad01a2
Minor: code and comments cleanup
philips77 May 25, 2018
f02bf3f
Increasing polling interval to 7 sec + minor changes
philips77 May 31, 2018
db17eff
Improved packet length calculation
philips77 May 31, 2018
674b8bb
Refactoring, FirmwareUpgradeController added
philips77 May 31, 2018
02589b2
MTU fixed again
philips77 May 31, 2018
8c1678c
Documentation added
philips77 May 31, 2018
611a96e
Bug fix: looping with the same MTU fixed
philips77 May 31, 2018
dd7139c
Exceptions improved
philips77 May 31, 2018
5566ea5
BLE transport migrated to reflect BLE Lib changes, release method add…
philips77 May 31, 2018
fc62313
Merge branch 'master' into ble_lib_v2
philips77 May 31, 2018
d48e779
Licenses added
philips77 May 31, 2018
ffb3c92
Comments
philips77 Jun 4, 2018
e45b1aa
Response field made public
philips77 Jun 4, 2018
0859056
Resource files removed from the library
philips77 Jun 4, 2018
3a2849b
Annotations added, MTU moved to McuManager
philips77 Jun 7, 2018
557c4a5
MTU moved to McuManager: Image and FirmwareUpgradeManager updated,
philips77 Jun 7, 2018
c5726a6
Annotations added,
philips77 Jun 7, 2018
fae68e6
Warning hidden
philips77 Jun 7, 2018
93b265b
FsManager added
philips77 Jun 7, 2018
05fa965
Sample app rebuilt. FsManager not yet supported.
philips77 Jun 7, 2018
e54b655
Merge branch 'master' into ble_lib_v2
philips77 Jun 7, 2018
35b175f
Tabs to Spaces
philips77 Jun 8, 2018
de1e55a
Line wrapping
philips77 Jun 8, 2018
edc479a
Handling notification timeouts and disconnection
philips77 Jun 8, 2018
0834f66
Support for handling Bluetooth disabled event
philips77 Jun 11, 2018
650ac42
Bug fixed: cancelling upload
philips77 Jun 11, 2018
df995e0
Annotations added
philips77 Jun 12, 2018
18a57bf
Adding State and Connection observers
philips77 Jun 12, 2018
cf640b5
Android Studio 3.1.3
philips77 Jun 12, 2018
966cff2
State observers removed
philips77 Jun 12, 2018
b0db61c
Basic and Advanced views on Image tab,
philips77 Jun 12, 2018
eb11d03
Keeping only English resources
philips77 Jun 12, 2018
09ade08
Work indicator added
philips77 Jun 12, 2018
08bd013
Tabs to spaces
philips77 Jun 13, 2018
b45f77a
continueUpload -> continueTransfer
philips77 Jun 13, 2018
9ff4341
UI for FsManager, other bug fixes
philips77 Jun 13, 2018
b820ba8
Moving common code to base class
philips77 Jun 13, 2018
c3fe99c
Test file generation
philips77 Jun 13, 2018
0ba4f8b
Displaying graphical files as images
philips77 Jun 13, 2018
ec522ad
Destination added to Files Upload
philips77 Jun 14, 2018
cd1450f
New lines
philips77 Jun 14, 2018
3d38ca0
Comments
philips77 Jun 14, 2018
5bd1dee
Minor refactoring in EchoFragment
philips77 Jun 14, 2018
ea56a1f
Hello! as initial text for Echo
philips77 Jun 14, 2018
6c163fa
Saving recent file names
philips77 Jun 14, 2018
2547f72
Unused imports removed, warnings suppressed.
philips77 Jun 14, 2018
c4429cc
Bugs fixed: value validation added
philips77 Jun 14, 2018
b01a974
Bug fixed: Recreating MainActivity fails as BluetoothDevice wasn't sa…
philips77 Jun 14, 2018
8255423
Image Manager: Erase state command added
philips77 Jun 14, 2018
2cf5ed1
McuMgr responses comments.
philips77 Jun 14, 2018
e19da8f
Initially, move the cursor to the end.
philips77 Jun 14, 2018
9f2b622
Adjusting to library changes
philips77 Jun 18, 2018
ea355e2
BLE Library imported from jcenter
philips77 Jun 19, 2018
d68e8f9
Constraint-layout 1.1.2
philips77 Jun 19, 2018
7d748ee
License changed to Apache 2.0
philips77 Jun 19, 2018
9e308e6
Bug fixed: Ble Library must be available for the app.
philips77 Jun 19, 2018
02ed0d2
Bug fixed
philips77 Jun 19, 2018
1d106bf
Bug fix: confirm slot 0 in test mode
philips77 Jun 25, 2018
dfccd44
BLE Library v2.0-alpha2
philips77 Jun 26, 2018
020102e
BLE Library v2.0-alpha3
philips77 Jun 26, 2018
d692685
License of the Sample app changed to Apache 2.0
philips77 Jun 26, 2018
119412a
Zephyr icon fixed
philips77 Jun 26, 2018
845d292
Other device icons
philips77 Jun 27, 2018
f39e1f8
Feature: option to filter device list by UUID and RSSI.
philips77 Jun 27, 2018
bfa91e0
Info text updated
philips77 Jun 27, 2018
97009e7
Bug fixed: formatting stats fixed
philips77 Jun 28, 2018
411ec90
BLE Library version 2.0-alpha4
philips77 Jun 28, 2018
4d5ec54
Improved device filtering
philips77 Jun 28, 2018
6f7c8a3
Vector drawables set using scrCompat
philips77 Jun 28, 2018
d7e5e7a
Improved UI for smaller phones
philips77 Jun 28, 2018
65dfe3a
BLE Library version 2.0-alpha5
philips77 Jun 28, 2018
f15b89b
LogCat disabled
philips77 Jun 28, 2018
632f58d
Bug fixed: Buttons get invalid state after screen rotation during upload
philips77 Jun 29, 2018
96bc125
Bug fixed: Displaying long echos fixed
philips77 Jun 29, 2018
e7d79ef
Bug fixed: Scanning progress bar fixed on Lollipop
philips77 Jun 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}
Expand Down
3 changes: 3 additions & 0 deletions mcumgr-android-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ android {
}

dependencies {
// Import the BLE Library
api 'no.nordicsemi.android:ble:2.0-alpha5'

implementation fileTree(include: ['*.jar'], dir: 'libs')

// Test
Expand Down
239 changes: 145 additions & 94 deletions mcumgr-android-lib/src/main/java/io/runtime/mcumgr/McuManager.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@

package io.runtime.mcumgr;

import android.support.annotation.NonNull;

import io.runtime.mcumgr.exception.McuMgrException;
import io.runtime.mcumgr.response.McuMgrResponse;

/**
* Callback for asynchronous Newt Manager commands.
* Callback for asynchronous Mcu Manager commands.
*/
public interface McuMgrCallback<T extends McuMgrResponse> {
/**
* Newt Manager has received a response.
* Mcu Manager has received a response.
*
* @param response the response
* @param response the response.
*/
void onResponse(T response);
void onResponse(@NonNull T response);

/**
* Newt Manager has encountered a transport error while sending the command.
* Mcu Manager has encountered a transport error while sending the command.
*
* @param error the error
* @param error the error.
*/
void onError(McuMgrException error);
void onError(@NonNull McuMgrException error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,53 @@

package io.runtime.mcumgr;

import android.support.annotation.NonNull;

/**
* Almost all requests are responded to with an Mcu Manager return code in the response payload.
* This value determines whether the request has been successful (rc = 0) or has failed (rc != 0).
*
* <p>
* This return code is not supposed to be very descriptive and the actual error reason must be
* determined based on the request and error code. Since McuManager errors are vague and often the
* same error code could be caused by different reasons, the best way to debug errors here is
* step through the handler on the device to determine the cause.
*/
public enum McuMgrErrorCode {
/**
* Success
* Success.
*/
OK(0),
/**
* Unknown error
* Unknown error.
*/
UNKNOWN(1),
/**
* The device has encountered an error due to running out of memory
* The device has encountered an error due to running out of memory.
*/
NO_MEMORY(2),
/**
* The request header/payload is malformed or payload values are incorrect
* The request header/payload is malformed or payload values are incorrect.
*/
IN_VALUE(3),
/**
* Timeout error
* Timeout error.
*/
TIMEOUT(4),
/**
* No entry was found for the request. This commonly means that the command group has not been
* enabled on the device, although the exact meaning
* enabled on the device, although the exact meaning.
*/
NO_ENTRY(5),
/**
* The device is not currently in a state to handle the request
* The device is not currently in a state to handle the request.
*/
BAD_STATE(6),
/**
* The response is too large
* The response is too large.
*/
TOO_LARGE(7),
/**
* Command is not supported
* Command is not supported.
*/
NOT_SUPPORTED(8),
PER_USER(256);
Expand All @@ -67,9 +69,10 @@ public int value() {

@Override
public String toString() {
return "McuMgrError: " + super.toString() + "(" + mCode + ")";
return super.toString() + " (" + mCode + ")";
}

@NonNull
public static McuMgrErrorCode valueOf(int error) {
switch (error) {
case 0:
Expand All @@ -93,7 +96,7 @@ public static McuMgrErrorCode valueOf(int error) {
case 256:
return PER_USER;
default:
return null;
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package io.runtime.mcumgr;

import android.support.annotation.NonNull;

import io.runtime.mcumgr.util.ByteUtil;
import io.runtime.mcumgr.util.Endian;

Expand All @@ -15,8 +17,8 @@
* fields for optional values such as flags and sequence numbers. This class is used to parse
* and build headers.
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class McuMgrHeader {

public final static int HEADER_LENGTH = 8;

private int mOp;
Expand Down Expand Up @@ -87,31 +89,39 @@ public void setCommandId(int commandId) {
this.mCommandId = commandId;
}

@Override
public String toString() {
return "Header (Op: " + mOp + ", Flags: " + mFlags + ", Len: " + mLen + ", Group: " + mGroupId + ", Seq: " + mSequenceNum + ", Command: " + mCommandId + ")";
}

public static McuMgrHeader fromBytes(byte[] header) {
if (header == null || header.length != HEADER_LENGTH) {
return null;
}
int op = ByteUtil.unsignedByteArrayToInt(header, 0, 1, Endian.BIG);
int flags = ByteUtil.unsignedByteArrayToInt(header, 1, 1, Endian.BIG);
int len = ByteUtil.unsignedByteArrayToInt(header, 2, 2, Endian.BIG);
int groupId = ByteUtil.unsignedByteArrayToInt(header, 4, 2, Endian.BIG);
int op = ByteUtil.unsignedByteArrayToInt(header, 0, 1, Endian.BIG);
int flags = ByteUtil.unsignedByteArrayToInt(header, 1, 1, Endian.BIG);
int len = ByteUtil.unsignedByteArrayToInt(header, 2, 2, Endian.BIG);
int groupId = ByteUtil.unsignedByteArrayToInt(header, 4, 2, Endian.BIG);
int sequenceNum = ByteUtil.unsignedByteArrayToInt(header, 6, 1, Endian.BIG);
int commandId = ByteUtil.unsignedByteArrayToInt(header, 7, 1, Endian.BIG);
int commandId = ByteUtil.unsignedByteArrayToInt(header, 7, 1, Endian.BIG);
return new McuMgrHeader(op, flags, len, groupId, sequenceNum, commandId);
}

/**
* Builds a new manager header.
*
* @param op the operation for this packet: NMGR_WRITE, NMGR_WRITE_RSP, NMGR_READ, NMGR_READ_RSP
* @param flags newt manager flags
* @param len the length (this field is NOT required for all default newt manager commands)
* @param op the operation for this packet: ({@link McuManager#OP_READ OP_READ},
* {@link McuManager#OP_READ_RSP OP_READ_RSP}, {@link McuManager#OP_WRITE OP_WRITE},
* {@link McuManager#OP_WRITE_RSP OP_WRITE_RSP}).
* @param flags newt manager flags.
* @param len the length (this field is NOT required for all default newt manager commands).
* @param group the newt manager command group. Some groups such as GROUP_IMAGE must also
* specify a subcommand ID.
* @param sequence the newt manager sequence number
* @param id the subcommand ID for certain groups
* @return the built newt manager header
* specify a sub-command ID.
* @param sequence the newt manager sequence number.
* @param id the sub-command ID for certain groups.
* @return The built newt manager header.
*/
@NonNull
public static byte[] build(int op, int flags, int len, int group, int sequence, int id) {
return new byte[]{
(byte) op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package io.runtime.mcumgr;

import android.support.annotation.NonNull;

import io.runtime.mcumgr.exception.McuMgrException;
import io.runtime.mcumgr.response.McuMgrResponse;

Expand All @@ -18,33 +20,72 @@
*/
public interface McuMgrTransport {

interface ConnectionObserver {
/**
* A method called when the connection to the device has been established.
*/
void onConnected();

/**
* A method called when the connection to the device has been lost.
*/
void onDisconnected();
}

/**
* Gets the scheme for this transport (see {@link McuMgrScheme}).
* @return the transport's scheme
*
* @return The transport's scheme.
*/
@NonNull
McuMgrScheme getScheme();

/**
* Send a synchronous Mcu Manager request. This method implementation should block until a
* response has been received or a error has occurred.
* @param payload the request packet data to send to the device
* @param responseType the response type
* @param <T> the response type
* @return the response
*
* @param payload the request packet data to send to the device.
* @param responseType the response type.
* @param <T> the response type.
* @return The response.
* @throws McuMgrException thrown on error. Set the cause of the error if caused by a different
* type of exception.
* type of exception.
*/
<T extends McuMgrResponse> T send(byte[] payload, Class<T> responseType) throws McuMgrException;
@NonNull
<T extends McuMgrResponse> T send(@NonNull byte[] payload, @NonNull Class<T> responseType)
throws McuMgrException;

/**
* Send an asynchronous Mcu Manager request. This method should not be blocked. When the
* response has been received or an error occurs, the appropriate method of the callback should
* be called.
* @param payload the request packet data to send to the device
* @param responseType the response type
* @param callback the callback to call on response or error
* @param <T> the response type
*
* @param payload the request packet data to send to the device.
* @param responseType the response type.
* @param callback the callback to call on response or error.
* @param <T> the response type.
*/
<T extends McuMgrResponse> void send(@NonNull byte[] payload, @NonNull Class<T> responseType,
@NonNull McuMgrCallback<T> callback);

/**
* Releases the transport connection. When the connection is already closed this method does
* nothing.
*/
void release();

/**
* Adds the connection observer. An observer will be notified whenever the connected device
* gets connected or disconnected.
*
* @param observer the observer.
*/
void addObserver(@NonNull ConnectionObserver observer);

/**
* Removes previously registered observer.
*
* @param observer the observer.
*/
<T extends McuMgrResponse> void send(byte[] payload, Class<T> responseType,
McuMgrCallback<T> callback);
void removeObserver(@NonNull ConnectionObserver observer);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/*
* Copyright (c) 2017-2018 Runtime Inc.
* Copyright (c) 2018, Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/

package io.runtime.mcumgr.ble;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;

import io.runtime.mcumgr.ble.manager.BleManagerCallbacks;
import no.nordicsemi.android.ble.BleManagerCallbacks;

/**
* <b>DO NOT PERFORM ANY BLOCKING OPERATIONS INSIDE THESE CALLBACKS!</b>
Expand All @@ -19,27 +17,7 @@
* <p>
* Callbacks from {@link McuMgrBleTransport}.
*/
public class McuMgrBleCallbacks implements BleManagerCallbacks {
public void onCharacteristicRead(BluetoothDevice device, BluetoothGattCharacteristic characteristic) {
}

public void onCharacteristicWrite(BluetoothDevice device, BluetoothGattCharacteristic characteristic) {
}

public void onDescriptorRead(BluetoothDevice device, BluetoothGattDescriptor descriptor) {
}

public void onDescriptorWrite(BluetoothDevice device, BluetoothGattDescriptor descriptor) {
}

public void onCharacteristicNotified(BluetoothDevice device, BluetoothGattCharacteristic characteristic) {
}

public void onCharacteristicIndicated(BluetoothDevice device, BluetoothGattCharacteristic characteristic) {
}

public void onMtuChanged(int mtu) {
}
public class McuMgrBleCallbacksStub implements BleManagerCallbacks {

@Override
public void onDeviceConnecting(BluetoothDevice device) {
Expand All @@ -58,7 +36,7 @@ public void onDeviceDisconnected(BluetoothDevice device) {
}

@Override
public void onLinklossOccur(BluetoothDevice device) {
public void onLinkLossOccurred(BluetoothDevice device) {
}

@Override
Expand All @@ -82,6 +60,10 @@ public void onBatteryValueReceived(BluetoothDevice device, int value) {
public void onBondingRequired(BluetoothDevice device) {
}

@Override
public void onBondingFailed(BluetoothDevice device) {
}

@Override
public void onBonded(BluetoothDevice device) {
}
Expand Down
Loading