Skip to content

Commit

Permalink
Add the possibility to use a custom advertise format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GiovanniVisentiniST committed Mar 26, 2019
1 parent 8a53d41 commit 0b772cb
Show file tree
Hide file tree
Showing 52 changed files with 3,333 additions and 1,153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void onResume() {
public void onPause() {

//dismiss the dialog if we are showing it
if (mConnectionWait.isShowing()) {
if (mConnectionWait!=null && mConnectionWait.isShowing()) {
mConnectionWait.dismiss();
}//if

Expand Down
9 changes: 9 additions & 0 deletions BlueSTSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
consumerProguardFiles 'proguard-rules.pro'

ndk {
moduleName "opusUser"
}

sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}

buildTypes {
Expand Down
25 changes: 14 additions & 11 deletions BlueSTSDK/src/main/java/com/st/BlueSTSDK/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.util.Log;

import com.st.BlueSTSDK.Utils.BLENodeDefines;

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

private static final Charset CHARSET = Charset.forName("ISO-8859-1"); //ACII

/**
* Max size of string to sent in the input char
*/
Expand Down Expand Up @@ -107,7 +107,7 @@ private void initHandler(){
* @return number of char sent in Terminal standard characteristic
*/
public int write(String message) {
return write(message.getBytes());
return write(stringToByte(message));
}

/**
Expand Down Expand Up @@ -177,9 +177,12 @@ public void setDebugOutputListener(@NonNull DebugOutputListener listener) {
addDebugOutputListener(listener);
}

private String encodeMessageString(byte[] value){
//convert to standard ascii characters
return new String(value, Charset.forName("ISO-8859-1"));
public static String byteToString(byte[] value){
return new String(value, CHARSET);
}

public static byte[] stringToByte(String str){
return str.getBytes(CHARSET);
}

/**
Expand All @@ -192,7 +195,7 @@ void receiveCharacteristicsUpdate(final BluetoothGattCharacteristic characterist
if (mListener.isEmpty())
return;
UUID charUuid = characteristic.getUuid();
final String msg = encodeMessageString(characteristic.getValue());
final String msg = byteToString(characteristic.getValue());
if (charUuid.equals(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID)) {
// mListener.onStdErrReceived(Debug.this, characteristic.getStringValue(0));
mNotifyThread.post(new Runnable() {
Expand Down Expand Up @@ -229,7 +232,7 @@ void receiveCharacteristicsWriteUpdate(final BluetoothGattCharacteristic charact
UUID charUuid = characteristic.getUuid();

if (charUuid.equals(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID)) {
final String str = encodeMessageString(data);
final String str = byteToString(data);
if(str.length()>MAX_STRING_SIZE_TO_SENT) {
mNotifyThread.post(new Runnable() {
@Override
Expand Down Expand Up @@ -273,15 +276,15 @@ public interface DebugOutputListener {
* @param debug object that send the message
* @param message message that someone write in the debug console
*/
void onStdOutReceived(Debug debug, String message);
void onStdOutReceived(@NonNull Debug debug,@NonNull String message);

/**
* a new message appear on the standard error
*
* @param debug object that send the message
* @param message message that someone write in the error console
*/
void onStdErrReceived(Debug debug, String message);
void onStdErrReceived(@NonNull Debug debug,@NonNull String message);

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

}//DebugOutputListener

Expand Down
15 changes: 14 additions & 1 deletion BlueSTSDK/src/main/java/com/st/BlueSTSDK/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ protected static boolean hasValidIndex(Sample s, int index){
return (index >=0 && (s != null) && (s.data.length > index) && (s.data[index]!=null));
}

/**
* extract a float number from the sample
* @param s sample that contains the data
* @param i data index
* @return value or nan if the value is not present
*/
protected static float getFloatFromIndex(Sample s, int i){
if(hasValidIndex(s,i)){
return s.data[i].floatValue();
}
return Float.NaN;
}

/**
* build a new disabled feature, that doesn't need to be initialized in the node side
*
Expand Down Expand Up @@ -494,7 +507,7 @@ public interface FeatureListener {
* @param sample new data received from the feature
*/
@WorkerThread
void onUpdate( Feature f, Sample sample);
void onUpdate(@NonNull Feature f,@Nullable Sample sample);

}//FeatureListener

Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,98 @@
/*******************************************************************************
* COPYRIGHT(c) 2015 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
package com.st.BlueSTSDK.Utils;

import com.st.BlueSTSDK.Feature;
import com.st.BlueSTSDK.Features.FeatureAudioADPCMSync;

/**
* Class containing the sync data needed in a ADPCM stream decoding
*
* @author STMicroelectronics - Central Labs.
* @version 1.0
*/
public class BVAudioSyncManager {

private boolean intra_flag=false;
private short adpcm_index_in=0;
private int adpcm_predsample_in=0;

public boolean isIntra() {
return intra_flag;
}

public short getAdpcm_index_in() {
return adpcm_index_in;
}

public int getAdpcm_predsample_in() {
return adpcm_predsample_in;
}

public void reinitResetFlag(){
intra_flag = false;
}

public void setSyncParams(Feature.Sample sample){
synchronized (this) {
adpcm_index_in = FeatureAudioADPCMSync.getIndex(sample);
adpcm_predsample_in = FeatureAudioADPCMSync.getPredictedSample(sample);
intra_flag = true;
}
}
}
/*******************************************************************************
* COPYRIGHT(c) 2015 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
package com.st.BlueSTSDK.Features.Audio.ADPCM;

import com.st.BlueSTSDK.Feature;
import com.st.BlueSTSDK.Features.Audio.AudioCodecManager;

/**
* Class containing the sync data needed in a ADPCM stream decoding
*
* @author STMicroelectronics - Central Labs.
* @version 1.0
*/
public class ADPCMManager implements AudioCodecManager {

private static final String CODEC_NAME = "ADPCM";
private static final int SAMPLING_FREQ = 8000;
private static final short CHANNELS = 1;

/** index where you can find adpcm index value/description */
public static final int ADPCM_INDEX_INDEX = 0;
/** index where you can find adpcm predsample value/description*/
public static final int ADPCM_PREDSAMPLE_INDEX = 1;

private boolean intra_flag=false;
private short adpcm_index_in=0;
private int adpcm_predsample_in=0;

public boolean isIntra() {
return intra_flag;
}

public short getAdpcm_index_in() {
return adpcm_index_in;
}

public int getAdpcm_predsample_in() {
return adpcm_predsample_in;
}

@Override
public void reinit(){
intra_flag = false;
}

@Override
public String getCodecName() {
return CODEC_NAME;
}

@Override
public int getSamplingFreq() {
return SAMPLING_FREQ;
}

@Override
public short getChannels() {
return CHANNELS;
}

@Override
public boolean isAudioEnabled() {
return true;
}

@Override
public void updateParams(Feature.Sample sample){
synchronized (this) {
adpcm_index_in = FeatureAudioADPCMSync.getIndex(sample);
adpcm_predsample_in = FeatureAudioADPCMSync.getPredictedSample(sample);
intra_flag = true;
}
}
}
Loading

0 comments on commit 0b772cb

Please sign in to comment.