Skip to content

Commit 0b772cb

Browse files
Add the possibility to use a custom advertise format
add the possibility to set a different mtu length, and change the connection interval Add Opus codec support Add Predictive mantenance feature support Improve FFT Feature
1 parent 8a53d41 commit 0b772cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3333
-1153
lines changed

BlueSTExample/src/main/java/com/st/BlueSTSDK/Example/NodeContainerFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void onResume() {
196196
public void onPause() {
197197

198198
//dismiss the dialog if we are showing it
199-
if (mConnectionWait.isShowing()) {
199+
if (mConnectionWait!=null && mConnectionWait.isShowing()) {
200200
mConnectionWait.dismiss();
201201
}//if
202202

BlueSTSDK/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ android {
1010
targetSdkVersion rootProject.ext.targetSdkVersion
1111
versionCode 1
1212
versionName "1.0"
13+
consumerProguardFiles 'proguard-rules.pro'
1314

15+
ndk {
16+
moduleName "opusUser"
17+
}
18+
19+
sourceSets.main {
20+
jniLibs.srcDir 'src/main/jniLibs'
21+
jni.srcDirs = [] //disable automatic ndk-build call
22+
}
1423
}
1524

1625
buildTypes {

BlueSTSDK/src/main/java/com/st/BlueSTSDK/Debug.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import android.os.HandlerThread;
3232
import android.support.annotation.NonNull;
3333
import android.support.annotation.Nullable;
34-
import android.support.v7.app.ActionBar;
35-
import android.util.Log;
3634

3735
import com.st.BlueSTSDK.Utils.BLENodeDefines;
3836

@@ -72,6 +70,8 @@ public class Debug {
7270
*/
7371
private final CopyOnWriteArrayList<DebugOutputListener> mListener = new CopyOnWriteArrayList<>();
7472

73+
private static final Charset CHARSET = Charset.forName("ISO-8859-1"); //ACII
74+
7575
/**
7676
* Max size of string to sent in the input char
7777
*/
@@ -107,7 +107,7 @@ private void initHandler(){
107107
* @return number of char sent in Terminal standard characteristic
108108
*/
109109
public int write(String message) {
110-
return write(message.getBytes());
110+
return write(stringToByte(message));
111111
}
112112

113113
/**
@@ -177,9 +177,12 @@ public void setDebugOutputListener(@NonNull DebugOutputListener listener) {
177177
addDebugOutputListener(listener);
178178
}
179179

180-
private String encodeMessageString(byte[] value){
181-
//convert to standard ascii characters
182-
return new String(value, Charset.forName("ISO-8859-1"));
180+
public static String byteToString(byte[] value){
181+
return new String(value, CHARSET);
182+
}
183+
184+
public static byte[] stringToByte(String str){
185+
return str.getBytes(CHARSET);
183186
}
184187

185188
/**
@@ -192,7 +195,7 @@ void receiveCharacteristicsUpdate(final BluetoothGattCharacteristic characterist
192195
if (mListener.isEmpty())
193196
return;
194197
UUID charUuid = characteristic.getUuid();
195-
final String msg = encodeMessageString(characteristic.getValue());
198+
final String msg = byteToString(characteristic.getValue());
196199
if (charUuid.equals(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID)) {
197200
// mListener.onStdErrReceived(Debug.this, characteristic.getStringValue(0));
198201
mNotifyThread.post(new Runnable() {
@@ -229,7 +232,7 @@ void receiveCharacteristicsWriteUpdate(final BluetoothGattCharacteristic charact
229232
UUID charUuid = characteristic.getUuid();
230233

231234
if (charUuid.equals(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID)) {
232-
final String str = encodeMessageString(data);
235+
final String str = byteToString(data);
233236
if(str.length()>MAX_STRING_SIZE_TO_SENT) {
234237
mNotifyThread.post(new Runnable() {
235238
@Override
@@ -273,15 +276,15 @@ public interface DebugOutputListener {
273276
* @param debug object that send the message
274277
* @param message message that someone write in the debug console
275278
*/
276-
void onStdOutReceived(Debug debug, String message);
279+
void onStdOutReceived(@NonNull Debug debug,@NonNull String message);
277280

278281
/**
279282
* a new message appear on the standard error
280283
*
281284
* @param debug object that send the message
282285
* @param message message that someone write in the error console
283286
*/
284-
void onStdErrReceived(Debug debug, String message);
287+
void onStdErrReceived(@NonNull Debug debug,@NonNull String message);
285288

286289
/**
287290
* call when a message is send to the debug console
@@ -290,7 +293,7 @@ public interface DebugOutputListener {
290293
* @param message message that someone write in the debug console
291294
* @param writeResult true if the message is correctly send
292295
*/
293-
void onStdInSent(Debug debug, String message, boolean writeResult);
296+
void onStdInSent(@NonNull Debug debug,@NonNull String message, boolean writeResult);
294297

295298
}//DebugOutputListener
296299

BlueSTSDK/src/main/java/com/st/BlueSTSDK/Feature.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ protected static boolean hasValidIndex(Sample s, int index){
119119
return (index >=0 && (s != null) && (s.data.length > index) && (s.data[index]!=null));
120120
}
121121

122+
/**
123+
* extract a float number from the sample
124+
* @param s sample that contains the data
125+
* @param i data index
126+
* @return value or nan if the value is not present
127+
*/
128+
protected static float getFloatFromIndex(Sample s, int i){
129+
if(hasValidIndex(s,i)){
130+
return s.data[i].floatValue();
131+
}
132+
return Float.NaN;
133+
}
134+
122135
/**
123136
* build a new disabled feature, that doesn't need to be initialized in the node side
124137
*
@@ -494,7 +507,7 @@ public interface FeatureListener {
494507
* @param sample new data received from the feature
495508
*/
496509
@WorkerThread
497-
void onUpdate( Feature f, Sample sample);
510+
void onUpdate(@NonNull Feature f,@Nullable Sample sample);
498511

499512
}//FeatureListener
500513

Original file line numberDiff line numberDiff line change
@@ -1,67 +1,98 @@
1-
/*******************************************************************************
2-
* COPYRIGHT(c) 2015 STMicroelectronics
3-
*
4-
* Redistribution and use in source and binary forms, with or without modification,
5-
* are permitted provided that the following conditions are met:
6-
* 1. Redistributions of source code must retain the above copyright notice,
7-
* this list of conditions and the following disclaimer.
8-
* 2. Redistributions in binary form must reproduce the above copyright notice,
9-
* this list of conditions and the following disclaimer in the documentation
10-
* and/or other materials provided with the distribution.
11-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
12-
* may be used to endorse or promote products derived from this software
13-
* without specific prior written permission.
14-
*
15-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25-
*
26-
******************************************************************************/
27-
package com.st.BlueSTSDK.Utils;
28-
29-
import com.st.BlueSTSDK.Feature;
30-
import com.st.BlueSTSDK.Features.FeatureAudioADPCMSync;
31-
32-
/**
33-
* Class containing the sync data needed in a ADPCM stream decoding
34-
*
35-
* @author STMicroelectronics - Central Labs.
36-
* @version 1.0
37-
*/
38-
public class BVAudioSyncManager {
39-
40-
private boolean intra_flag=false;
41-
private short adpcm_index_in=0;
42-
private int adpcm_predsample_in=0;
43-
44-
public boolean isIntra() {
45-
return intra_flag;
46-
}
47-
48-
public short getAdpcm_index_in() {
49-
return adpcm_index_in;
50-
}
51-
52-
public int getAdpcm_predsample_in() {
53-
return adpcm_predsample_in;
54-
}
55-
56-
public void reinitResetFlag(){
57-
intra_flag = false;
58-
}
59-
60-
public void setSyncParams(Feature.Sample sample){
61-
synchronized (this) {
62-
adpcm_index_in = FeatureAudioADPCMSync.getIndex(sample);
63-
adpcm_predsample_in = FeatureAudioADPCMSync.getPredictedSample(sample);
64-
intra_flag = true;
65-
}
66-
}
67-
}
1+
/*******************************************************************************
2+
* COPYRIGHT(c) 2015 STMicroelectronics
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
* 1. Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* 2. Redistributions in binary form must reproduce the above copyright notice,
9+
* this list of conditions and the following disclaimer in the documentation
10+
* and/or other materials provided with the distribution.
11+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
12+
* may be used to endorse or promote products derived from this software
13+
* without specific prior written permission.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*
26+
******************************************************************************/
27+
package com.st.BlueSTSDK.Features.Audio.ADPCM;
28+
29+
import com.st.BlueSTSDK.Feature;
30+
import com.st.BlueSTSDK.Features.Audio.AudioCodecManager;
31+
32+
/**
33+
* Class containing the sync data needed in a ADPCM stream decoding
34+
*
35+
* @author STMicroelectronics - Central Labs.
36+
* @version 1.0
37+
*/
38+
public class ADPCMManager implements AudioCodecManager {
39+
40+
private static final String CODEC_NAME = "ADPCM";
41+
private static final int SAMPLING_FREQ = 8000;
42+
private static final short CHANNELS = 1;
43+
44+
/** index where you can find adpcm index value/description */
45+
public static final int ADPCM_INDEX_INDEX = 0;
46+
/** index where you can find adpcm predsample value/description*/
47+
public static final int ADPCM_PREDSAMPLE_INDEX = 1;
48+
49+
private boolean intra_flag=false;
50+
private short adpcm_index_in=0;
51+
private int adpcm_predsample_in=0;
52+
53+
public boolean isIntra() {
54+
return intra_flag;
55+
}
56+
57+
public short getAdpcm_index_in() {
58+
return adpcm_index_in;
59+
}
60+
61+
public int getAdpcm_predsample_in() {
62+
return adpcm_predsample_in;
63+
}
64+
65+
@Override
66+
public void reinit(){
67+
intra_flag = false;
68+
}
69+
70+
@Override
71+
public String getCodecName() {
72+
return CODEC_NAME;
73+
}
74+
75+
@Override
76+
public int getSamplingFreq() {
77+
return SAMPLING_FREQ;
78+
}
79+
80+
@Override
81+
public short getChannels() {
82+
return CHANNELS;
83+
}
84+
85+
@Override
86+
public boolean isAudioEnabled() {
87+
return true;
88+
}
89+
90+
@Override
91+
public void updateParams(Feature.Sample sample){
92+
synchronized (this) {
93+
adpcm_index_in = FeatureAudioADPCMSync.getIndex(sample);
94+
adpcm_predsample_in = FeatureAudioADPCMSync.getPredictedSample(sample);
95+
intra_flag = true;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)