Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public abstract class ShimmerBluetooth extends ShimmerObject implements Serializ
protected long mSetEnabledSensors = SENSOR_ACCEL; // Only used during the initialization process, see initialize();

private int mNumberofTXRetriesCount=1;
private static final int AUDIO_STATUS_LENGTH = 32;
private static final byte AUDIO_STATE_RECORDING = 2;
private final static int NUMBER_OF_TX_RETRIES_LIMIT = 0;
private class DUMMY_READ_WAIT_TIME_MS {
private final static int START = 50;
Expand Down Expand Up @@ -416,6 +418,8 @@ public enum SHIMMER_FEATURE {
aMap.put(GET_RWC_COMMAND, new BtCommandDetails(GET_RWC_COMMAND, "GET_RWC_COMMAND", RWC_RESPONSE));
aMap.put(GET_VBATT_COMMAND, new BtCommandDetails(GET_VBATT_COMMAND, "GET_VBATT_COMMAND", VBATT_RESPONSE));
aMap.put(GET_BT_FW_VERSION_STR_COMMAND, new BtCommandDetails(GET_BT_FW_VERSION_STR_COMMAND, "GET_BT_FW_VERSION_STR_COMMAND", BT_FW_VERSION_STR_RESPONSE));
aMap.put(GET_AUDIO_STATUS_COMMAND, new BtCommandDetails(GET_AUDIO_STATUS_COMMAND, "GET_AUDIO_STATUS_COMMAND", AUDIO_STATUS_RESPONSE));

aMap.put(GET_EVENT_CHANNEL_STATUS_COMMAND, new BtCommandDetails(GET_EVENT_CHANNEL_STATUS_COMMAND, "GET_EVENT_CHANNEL_STATUS_COMMAND", EVENT_CHANNEL_STATUS_RESPONSE));

mBtGetCommandMap = Collections.unmodifiableMap(aMap);
Expand Down Expand Up @@ -538,6 +542,8 @@ public enum SHIMMER_FEATURE {
aMap.put(RWC_RESPONSE, new BtCommandDetails(RWC_RESPONSE, "RWC_RESPONSE", 8));
aMap.put(VBATT_RESPONSE, new BtCommandDetails(VBATT_RESPONSE, "VBATT_RESPONSE", 3));
aMap.put(BT_FW_VERSION_STR_RESPONSE, new BtCommandDetails(BT_FW_VERSION_STR_RESPONSE, "BT_FW_VERSION_STR_RESPONSE", -1));
aMap.put(AUDIO_STATUS_RESPONSE, new BtCommandDetails(AUDIO_STATUS_RESPONSE, "AUDIO_STATUS_RESPONSE", AUDIO_STATUS_LENGTH));

aMap.put(EVENT_CHANNEL_STATUS_RESPONSE, new BtCommandDetails(EVENT_CHANNEL_STATUS_RESPONSE, "EVENT_CHANNEL_STATUS_RESPONSE", EventChannelStatus.LENGTH));

mBtResponseMap = Collections.unmodifiableMap(aMap);
Expand Down Expand Up @@ -2382,6 +2388,14 @@ else if(responseCommand==BT_FW_VERSION_STR_RESPONSE) {
}
}
}

else if(responseCommand==AUDIO_STATUS_RESPONSE) {
byte[] responseData = readBytes(AUDIO_STATUS_LENGTH, responseCommand);
if(responseData!=null) {
parseAudioStatus(responseData);
}
}


else if(responseCommand==EVENT_CHANNEL_STATUS_RESPONSE) {
byte[] responseData = readBytes(EventChannelStatus.LENGTH, responseCommand);
Expand Down Expand Up @@ -3070,9 +3084,16 @@ protected void parseStatusByte(byte[] statusByte){

if(statusByte.length > 1) {
setIsUsbPluggedIn(((statusByte[1] & (0x01 << 0)) > 0)? true:false);

consolePrintLn("\nStatus Response = \n" + UtilShimmer.byteToHexStringFormatted(statusByte[1])
+ "\t" + "IsUsbPluggedIn = " + isUsbPluggedIn());
// earlier firmware sends 0 in the audio bits
if(isSupportedAudioStatus()) {
setIsAudioRecording((statusByte[1] & (0x01 << 1)) > 0);
setIsAudioFault((statusByte[1] & (0x01 << 2)) > 0);
}

consolePrintLn("\nStatus Response = \n" + UtilShimmer.byteToHexStringFormatted(statusByte[1])
+ "\t" + "IsUsbPluggedIn = " + isUsbPluggedIn()
+ "\t" + "IsAudioRecording = " + isAudioRecording()
+ "\t" + "IsAudioFault = " + isAudioFault());

}

Expand All @@ -3096,6 +3117,11 @@ public boolean isSupportedSdInfoInStatus() {
public boolean isSupportedUSBPluggedInStatus() {
return isThisVerCompatibleWith(HW_ID.SHIMMER_3R, FW_ID.LOGANDSTREAM, 1,0, 24);
}

/** Status byte 1 bits 1-2, audio recording and audio fault: LogAndStream_Shimmer3R v1.01.026 or later */
public boolean isSupportedAudioStatus() {
return isVerCompatibleWithAnyOf(Configuration.Shimmer3.CompatibilityInfoForMaps.listOfCompatibleVersionInfoSoundLevel);
}

protected boolean isSupportedInStreamCmds() {
if((getFirmwareIdentifier()==FW_ID.LOGANDSTREAM
Expand Down Expand Up @@ -3327,6 +3353,10 @@ private void initializeShimmer3or3R(int hardwareVersion){
readBtFwVersion();
}

if(isAudioStatusToAsk()) {
readAudioStatus();
}

//TODO this could actually be causing a lot of misunderstanding and a disconnect between what the user thinks is set and what is actually set.
// Only read calibration dump over bluetooth if the Shimmer3 is not
// docked as the Shimmer3 won't have access to the SD card. The Shimmer3R does.
Expand Down Expand Up @@ -3622,6 +3652,19 @@ else if(mCurrentCommand==STOP_LOGGING_ONLY_COMMAND){
}


//firmware without audio leaves it unanswered, which says the unit records none
if(mCurrentCommand==GET_AUDIO_STATUS_COMMAND){
setIsAudioStatusAnswered(false);
mWaitForAck=false;
mWaitForResponse=false;

removeInstruction(0);
mTransactionCompleted = true;
setInstructionStackLock(false);

return;
}

if(mCurrentCommand==GET_FW_VERSION_COMMAND){
setShimmerVersionObjectAndCreateSensorMap(new ShimmerVerObject(HW_ID.SHIMMER_2R, FW_ID.BOILER_PLATE, 0, 1, 0));

Expand Down Expand Up @@ -4140,6 +4183,22 @@ public void readStatusLogAndStream(){
}
}

/** v1.01.025 development builds may record audio; later releases do by version, so are not asked */
public boolean isAudioStatusToAsk() {
return isVerCompatibleWithAnyOf(Configuration.Shimmer3.configOptionAudioMode.mListOfCompatibleVersionInfo) && !isSupportedAudioStatus();
}

public void readAudioStatus() {
writeInstruction(GET_AUDIO_STATUS_COMMAND);
}

/** AUDIO_STATUS_RESPONSE (log-and-stream-common SHIMMER3R_AUDIO.md §5): byte 2 the state, 2 recording; byte 3 the fault, 0 none */
protected void parseAudioStatus(byte[] audioStatus) {
setIsAudioStatusAnswered(true);
setIsAudioRecording(audioStatus[2] == AUDIO_STATE_RECORDING);
setIsAudioFault(audioStatus[3] != 0);
}

public void readBtFwVersion() {
if (getShimmerVerObject().isSupportedBtFwVerRequest()) {
writeInstruction(GET_BT_FW_VERSION_STR_COMMAND);
Expand Down Expand Up @@ -5343,8 +5402,8 @@ public void writeConfigBytes(boolean readBackAfter){
if(!isButtonLogModeKnown()){
skipIndexes.add(configByteLayoutCast.idxButtonLogMode);
}
// Byte 233 (DEV-99, DEV-1413) on a Shimmer3R, not read
// and the sound level not turned on
// Byte 233 (DEV-99, DEV-1413) on a Shimmer3R, neither read
// nor set (the sound level or the audio mode)
if(configByteLayoutCast.idxAudioConfig>0 && !isAudioConfigKnown()){
skipIndexes.add(configByteLayoutCast.idxAudioConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ public class GuiLabelConfig{
public static final String ENABLE_ERROR_LEDS_RTC = "RTC Error LEDs";
public static final String ENABLE_ERROR_LEDS_SD = "SD Error LEDs";
public static final String LOW_POWER_AUTOSTOP = "Low-power Autostop";
public static final String AUDIO_MODE = "Audio Mode";
/** Configuration byte 232 bits 0-2 (DEV-971), an Integer, see ButtonLogMode.BUTTON_MODE_* */
public static final String BUTTON_MODE = "Button Mode";
/** Configuration byte 232 bits 3-4 (DEV-971), an Integer, see ButtonLogMode.LOG_TRIGGERS_* */
Expand Down Expand Up @@ -2023,6 +2024,21 @@ public static class CompatibilityInfoForMaps{
ConfigOptionDetailsSensor.GUI_COMPONENT_TYPE.CHECKBOX,
Arrays.asList(new ShimmerVerObject(FW_ID.LOGANDSTREAM, 0, 9, 6),
new ShimmerVerObject(FW_ID.SDLOG, 0, 17, 3)));

/** What a Shimmer3R records from its microphone while logging to SD (DEV-99, config byte 233). */
public static final int AUDIO_MODE_OFF = 0;
public static final int AUDIO_MODE_FINGERPRINT = 1;
public static final int AUDIO_MODE_FINGERPRINT_AND_RAW = 2;
public static final int AUDIO_MODE_RAW = 3;
public static final String[] ListofAudioMode = {"Off", "Fingerprint only", "Fingerprint and raw audio", "Raw audio only"};
public static final Integer[] ListofAudioModeConfigValues = {AUDIO_MODE_OFF, AUDIO_MODE_FINGERPRINT, AUDIO_MODE_FINGERPRINT_AND_RAW, AUDIO_MODE_RAW};
public static final ConfigOptionDetailsSensor configOptionAudioMode = new ConfigOptionDetailsSensor(
Configuration.Shimmer3.GuiLabelConfig.AUDIO_MODE,
ShimmerDevice.DatabaseConfigHandle.AUDIO_MODE,
ListofAudioMode,
ListofAudioModeConfigValues,
ConfigOptionDetailsSensor.GUI_COMPONENT_TYPE.COMBOBOX,
Arrays.asList(new ShimmerVerObject(HW_ID.SHIMMER_3R, FW_ID.LOGANDSTREAM, 1, 1, 25)));

public static final Map<String, ConfigOptionDetailsSensor> mConfigOptionsMapRef;
static {
Expand Down Expand Up @@ -2296,6 +2312,7 @@ public static class CompatibilityInfoForMaps{
CompatibilityInfoForMaps.listOfCompatibleVersionInfoAnyExpBoardAndFw));

aMap.put(Configuration.Shimmer3.GuiLabelConfig.LOW_POWER_AUTOSTOP, configOptionLowPowerAutoStop);
aMap.put(Configuration.Shimmer3.GuiLabelConfig.AUDIO_MODE, configOptionAudioMode);

mConfigOptionsMapRef3r = Collections.unmodifiableMap(aMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public abstract class ShimmerDevice extends BasicProcessWithCallBack implements
protected boolean mIsInitialised = false;
private boolean mIsDocked = false;
private boolean mIsUsbPluggedIn = false;
/** Shimmer3R microphone, from the status: audio captured for the current log, and this session's audio failed or degraded */
private boolean mIsAudioRecording = false;
private boolean mIsAudioFault = false;
/** A v1.01.025 unit's answer to GET_AUDIO_STATUS: null until asked */
private Boolean mIsAudioStatusAnswered = null;
private boolean mIsDockCommsSuccessful = false;
public boolean mIsUsbDfuMode= false;
protected boolean mHaveAttemptedToReadConfig = false;
Expand Down Expand Up @@ -324,6 +329,7 @@ public static final class DatabaseConfigHandle{
public static final String TRIAL_ID = "Trial_Id";
public static final String N_SHIMMER = "NShimmer";
public static final String LOW_POWER_AUTOSTOP = "Low_Power_Autostop";
public static final String AUDIO_MODE = "Audio_Mode";

public static final String SHIMMER_VERSION = "Shimmer_Version";
public static final String FW_VERSION = "FW_ID";
Expand Down Expand Up @@ -1081,6 +1087,38 @@ public boolean isDocked() {
public boolean isUsbPluggedIn() {
return mIsUsbPluggedIn;
}

public void setIsAudioRecording(boolean isAudioRecording) {
mIsAudioRecording = isAudioRecording;
}

public boolean isAudioRecording() {
return mIsAudioRecording;
}

public void setIsAudioFault(boolean isAudioFault) {
mIsAudioFault = isAudioFault;
}

public boolean isAudioFault() {
return mIsAudioFault;
}

public void setIsAudioStatusAnswered(boolean isAnswered) {
mIsAudioStatusAnswered = isAnswered;
}

/**
* Whether this unit records audio: LogAndStream_Shimmer3R v1.01.026 or later by its version; a v1.01.025
* development build only once it has answered GET_AUDIO_STATUS (SHIMMER3R_AUDIO.md §5).
*/
public boolean isAudioSupported() {
if (isVerCompatibleWithAnyOf(Configuration.Shimmer3.CompatibilityInfoForMaps.listOfCompatibleVersionInfoSoundLevel)) {
return true;
}
return isVerCompatibleWithAnyOf(Configuration.Shimmer3.configOptionAudioMode.mListOfCompatibleVersionInfo)
&& Boolean.TRUE.equals(mIsAudioStatusAnswered);
}

public boolean isUsbDfuMode(){
return mIsUsbDfuMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ public static final class PRESSURE_SENSOR_ID {
public static final byte EVENT_CHANNEL_STATUS_RESPONSE = (byte) 0xBA;
/** An event channel record, [0x8A][0xBB][len][record][CRC-16], sent only to a host that opted in (DEV-971) */
public static final byte EVENT_RECORD_RESPONSE = (byte) 0xBB;

/** Shimmer3R audio (DEV-99): firmware without audio leaves it unanswered */
public static final byte GET_AUDIO_STATUS_COMMAND = (byte) 0xBC;
public static final byte AUDIO_STATUS_RESPONSE = (byte) 0xBD;

public static final int MAX_NUMBER_OF_SIGNALS = 77;//50; //used to be 11 but now 13 because of the SR30 + 8 for 3d orientation
public static final int MAX_INQUIRY_PACKET_SIZE = 47;
Expand Down Expand Up @@ -582,6 +586,9 @@ public String toString() {
private boolean isOverrideShowErrorLedsSd = false;
private int mShowErrorLedsSd = 0;
private boolean mLowBattAutoStop = false;
private int mAudioMode = Configuration.Shimmer3.AUDIO_MODE_OFF;
/** Only internal apps may switch raw audio on; any other app writes it off. */
private static boolean sIsRawAudioAllowed = false;

/** Configuration byte 232 as read from the Shimmer or set by the host (DEV-971), see {@link ButtonLogMode} */
private int mButtonLogMode = 0;
Expand Down Expand Up @@ -5033,6 +5040,7 @@ public void setDefaultShimmerConfiguration() {
setSingleTouch(false);
setTCXO(false);
setLowBattAutoStop(false);
setAudioMode(Configuration.Shimmer3.AUDIO_MODE_OFF);

setPacketSize(0);
mConfigByte0=0;
Expand Down Expand Up @@ -6276,6 +6284,34 @@ private boolean isLowBattAutoStop() {
return mLowBattAutoStop;
}

public void setAudioMode(int audioMode) {
mAudioMode = audioMode;
}

public int getAudioMode() {
return mAudioMode;
}

public static boolean isRawAudioMode(int audioMode) {
return audioMode == Configuration.Shimmer3.AUDIO_MODE_FINGERPRINT_AND_RAW || audioMode == Configuration.Shimmer3.AUDIO_MODE_RAW;
}

/** What a config write saves: a raw audio mode drops to Fingerprint only or Off unless raw audio is allowed. */
public int getAudioModeToWrite() {
if (sIsRawAudioAllowed || !isRawAudioMode(mAudioMode)) {
return mAudioMode;
}
return mAudioMode == Configuration.Shimmer3.AUDIO_MODE_FINGERPRINT_AND_RAW ? Configuration.Shimmer3.AUDIO_MODE_FINGERPRINT : Configuration.Shimmer3.AUDIO_MODE_OFF;
}

public static void setRawAudioAllowed(boolean isAllowed) {
sIsRawAudioAllowed = isAllowed;
}

public static boolean isRawAudioAllowed() {
return sIsRawAudioAllowed;
}

/**
* @return the mTrialNumberOfShimmers
*/
Expand Down Expand Up @@ -6776,12 +6812,12 @@ public boolean isButtonLogModeKnown() {

/**
* Whether the driver has the Shimmer3R's own byte 233, the microphone's
* configuration ({@link SensorSoundLevel#isAudioConfigKnown()}). True
* where there is no such byte.
* configuration ({@link SensorSoundLevel#isAudioConfigKnown(ShimmerDevice)}).
* True where there is no such byte.
*/
public boolean isAudioConfigKnown() {
AbstractSensor abstractSensor = getSensorClass(AbstractSensor.SENSORS.SOUND_LEVEL);
return !(abstractSensor instanceof SensorSoundLevel) || ((SensorSoundLevel) abstractSensor).isAudioConfigKnown();
return !(abstractSensor instanceof SensorSoundLevel) || ((SensorSoundLevel) abstractSensor).isAudioConfigKnown(this);
}

/**
Expand Down Expand Up @@ -9970,6 +10006,9 @@ public Object getConfigValueUsingConfigLabel(String identifier, String configLab
case(Configuration.Shimmer3.GuiLabelConfig.LOW_POWER_AUTOSTOP):
returnValue = isLowBattAutoStop();
break;
case(Configuration.Shimmer3.GuiLabelConfig.AUDIO_MODE):
returnValue = getAudioMode();
break;

case(Configuration.Shimmer3.GuiLabelConfig.BLUETOOTH_BAUD_RATE):
returnValue = getBluetoothBaudRate();
Expand Down Expand Up @@ -10147,6 +10186,9 @@ public Object setConfigValueUsingConfigLabel(String identifier, String configLab
case(Configuration.Shimmer3.GuiLabelConfig.LOW_POWER_AUTOSTOP):
setLowBattAutoStop((boolean)valueToSet);
break;
case(Configuration.Shimmer3.GuiLabelConfig.AUDIO_MODE):
setAudioMode(isVerCompatibleWithAnyOf(Configuration.Shimmer3.configOptionAudioMode.mListOfCompatibleVersionInfo) ? (int)valueToSet : Configuration.Shimmer3.AUDIO_MODE_OFF);
break;

case(Configuration.Shimmer3.GuiLabelConfig.BLUETOOTH_BAUD_RATE):
setBluetoothBaudRate((int)valueToSet);
Expand Down Expand Up @@ -10395,6 +10437,7 @@ public LinkedHashMap<String, Object> generateConfigMap(COMMUNICATION_TYPE commTy
configMapForDb.put(DatabaseConfigHandleShimmerObject.TRIAL_DURATION_MAXIMUM, (double) getTrialDurationMaximumInSecs());

configMapForDb.put(ShimmerDevice.DatabaseConfigHandle.LOW_POWER_AUTOSTOP, (double) (isLowBattAutoStop()? 1:0));
configMapForDb.put(ShimmerDevice.DatabaseConfigHandle.AUDIO_MODE, (double) getAudioMode());

//Now handled in the algorithm class in super
/**
Expand Down Expand Up @@ -10444,6 +10487,9 @@ public void parseConfigMap(ShimmerVerObject svo, LinkedHashMap<String, Object> m
if(mapOfConfigPerShimmer.containsKey(DatabaseConfigHandle.LOW_POWER_AUTOSTOP)){
setLowBattAutoStop(((Double) mapOfConfigPerShimmer.get(DatabaseConfigHandle.LOW_POWER_AUTOSTOP))>0? true:false);
}
if(mapOfConfigPerShimmer.containsKey(DatabaseConfigHandle.AUDIO_MODE)){
setAudioMode(((Double) mapOfConfigPerShimmer.get(DatabaseConfigHandle.AUDIO_MODE)).intValue());
}

//EXG Configuration
byte[] exg1Bytes = SensorEXG.parseExgConfigFromDb(mapOfConfigPerShimmer, EXG_CHIP_INDEX.CHIP1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public class ConfigByteLayoutShimmer3 extends ConfigByteLayout implements Serial
//as 0 when bit 7 is set, as it is in erased flash (0xFF).
public int idxAudioConfig = 0;
public int maskAudioModeAndGain = 0x0F;
public int maskAudioMode = 0x03;
public int bitShiftSoundLevel = 4;
public int maskSoundLevel = 0x01;
public int maskAudioConfigInvalid = 0x80;
Expand Down
Loading
Loading