Skip to content

Commit

Permalink
added mtu set to android api
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkki Silvola committed Apr 17, 2020
1 parent 9485c13 commit 3c16267
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Notice PolarBleApi.ALL_FEATURES are enabled
api = PolarBleApiDefaultImpl.defaultImplementation(this, PolarBleApi.ALL_FEATURES);
api.setPolarFilter(false);
api.setMtu(140);

final Button broadcast = this.findViewById(R.id.broadcast_button);
final Button connect = this.findViewById(R.id.connect_button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.bluetooth.le.ScanFilter;
import android.support.annotation.IntDef;
import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.util.Pair;

Expand Down Expand Up @@ -102,6 +103,8 @@ public interface BlePowerStateChangedCallback {
*/
abstract public Flowable<BleDeviceSession> search(boolean fetchKnownDevices);

abstract public void setMtu(@IntRange(from = 70, to = 512) int mtu);

/**
* As java does not support destructor/RAII, Client/App should call this whenever the application is being destroyed
*/
Expand All @@ -123,9 +126,9 @@ public interface BlePowerStateChangedCallback {
/**
* Deprecated use setDeviceSessionStateChangedCallback instead
*
* Produces: onNext: When a device session state has changed, Note use pair.second to check the state (see BleDeviceSession.DeviceSessionState)<BR>
* onError: should not be produced<BR>
* onCompleted: This is never propagated, NOTE to get completed event configure observable with some end rule e.g. take(1), takeUntil() etc...<BR>
* Produces: onNext: When a device session state has changed, Note use pair.second to check the state (see BleDeviceSession.DeviceSessionState) <BR>
* onError: should not be produced <BR>
* onCompleted: If stream is further configured <BR>
* @param session, a specific session or null = monitor all sessions
* @return Observable stream
*/
Expand All @@ -149,7 +152,7 @@ public interface BleDeviceSessionStateChangedCallback {
abstract public void setDeviceSessionStateChangedCallback(@Nullable BleDeviceSessionStateChangedCallback changedCallback);

/**
* aquires disconnection establishment directly without Observable returned
* aquires disconnection directly without Observable returned
* @param session device
*/
abstract public void closeSessionDirect(BleDeviceSession session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public enum PmdControlPointResponseCode {
ERROR_INVALID_STATE(6),
ERROR_INVALID_RESOLUTION(7),
ERROR_INVALID_SAMPLE_RATE(8),
ERROR_INVALID_RANGE(9);
ERROR_INVALID_RANGE(9),
ERROR_INVALID_MTU(10);

private int numVal;
PmdControlPointResponseCode(int numVal) {
Expand All @@ -183,9 +184,11 @@ public PmdControlPointResponse(byte[] data) {
opCode = PmdControlPointCommand.values()[data[1]];
measurementType = data[2];
status = PmdControlPointResponseCode.values()[data[3]];
more = data.length > 4 && data[4] != 0;
if (data.length > 5) {
parameters.write(data, 5, data.length - 5);
if (status == PmdControlPointResponseCode.SUCCESS) {
more = data.length > 4 && data[4] != 0;
if (data.length > 5) {
parameters.write(data, 5, data.length - 5);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public void run() {
});
}

@Override
public void setMtu(int mtu) {
gattCallback.setPolarMaxMtu(mtu);
}

@Override
public void shutDown(){
super.shutDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class BDGattCallback extends BluetoothGattCallback {

private final static String TAG = BDGattCallback.class.getSimpleName();
private final static int POLAR_MAX_MTU = 512;
private int POLAR_MAX_MTU = 512;

private ConnectionHandler connectionHandler;
private BDDeviceList sessions;
Expand All @@ -38,6 +38,10 @@ class BDGattCallback extends BluetoothGattCallback {
this.sessions = sessions;
}

void setPolarMaxMtu(int mtu) {
POLAR_MAX_MTU = mtu;
}

@Override
public void onConnectionStateChange(final BluetoothGatt gatt, int status, int newState) {
final BDDeviceSessionImpl smartPolarDeviceSession = sessions.getSession(gatt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.androidcommunications.polar.enpoints.ble.common;

import android.content.Context;
import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.util.Pair;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © 2019 Polar Electro Oy. All rights reserved.
package polar.com.sdk.api;

import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
import android.util.Pair;
Expand Down Expand Up @@ -103,6 +104,13 @@ protected PolarBleApi(final int features) {
this.features = features;
}

/**
* set mtu to lower than default(232 is the default for polar devices, minimum for H10 is 70 and for OH1 is 140)
* to minimize latency
* @param mtu value between 64-512 to be set
*/
public abstract void setMtu(@IntRange(from = 70, to = 512) int mtu);

/**
* Must be called when application is destroyed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ protected void enableAndroidScanFilter() {
}
}

@Override
public void setMtu(int mtu) {
listener.setMtu(mtu);
}

@Override
public void shutDown() {
listener.shutDown();
Expand Down

0 comments on commit 3c16267

Please sign in to comment.