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 @@ -1385,7 +1385,7 @@ else if(responseCommand==SAMPLING_RATE_RESPONSE) {
}
}
}
else if(getHardwareVersion()==HW_ID.SHIMMER_3){
else if(isShimmerGen3or3R()) {
byte[] bufferSR = readBytes(2, responseCommand); //read the sampling rate
if(bufferSR!=null){
setSamplingRateShimmer(convertSamplingRateBytesToFreq(bufferSR[0], bufferSR[1], getSamplingClockFreq()));
Expand Down Expand Up @@ -1430,11 +1430,14 @@ else if(responseCommand==FW_VERSION_RESPONSE){
}

else if(responseCommand==ALL_CALIBRATION_RESPONSE) {
if(getHardwareVersion()==HW_ID.SHIMMER_3){
if(isShimmerGen3or3R()) {
processAccelCalReadBytes();
processGyroCalReadBytes();
processMagCalReadBytes();
processLsm303dlhcAccelCalReadBytes();
if (getHardwareVersion() == HW_ID.SHIMMER_3R) {
//TODO added support for Shimmer3R alt accel and alt mag if needed but this has been replaced by calib dump
}
}
else { //Shimmer2R etc.
processAccelCalReadBytes();
Expand Down Expand Up @@ -2109,7 +2112,7 @@ else if(bytearray[1]==EXG_CHIP_INDEX.CHIP2.ordinal()){ //1 = CHIP 2
}
else if(currentCommand==SET_SENSORS_COMMAND) {
mEnabledSensors=tempEnabledSensors;
if(getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion()==HW_ID.SHIMMER_3R){
if(isShimmerGen3or3R()){
checkExgResolutionFromEnabledSensorsVar();
}
byteStack.clear(); // Always clear the packetStack after setting the sensors, this is to ensure a fresh start
Expand Down Expand Up @@ -2585,129 +2588,15 @@ private void initializeShimmer2R(){
}

private void initializeShimmer3R(){

setHardwareVersionAndCreateSensorMaps(HW_ID.SHIMMER_3R);
// initialise(HW_ID.SHIMMER_3);

setHaveAttemptedToReadConfig(true);

if(mSendProgressReport){
operationPrepare();
setBluetoothRadioState(BT_STATE.CONNECTING);
}

//readExpansionBoardID();

if (isBtCrcModeSupported()) {
writeBtCommsCrcMode(DEFAULT_BT_CRC_MODE_IF_SUPPORTED);
}

if (isSetupDeviceWhileConnecting()){
if(mFixedShimmerConfigMode!=null && mFixedShimmerConfigMode!=FIXED_SHIMMER_CONFIG_MODE.NONE){
boolean triggerConfig = setFixedConfigWhenConnecting();
if(triggerConfig){
writeConfigBytes(false);
}
}
else {
if(this.mUseInfoMemConfigMethod && getFirmwareVersionCode()>=6){
writeConfigBytes(false);
}
else {
if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 2)){
writeShimmerUserAssignedName(getShimmerUserAssignedName());
}
if(mSetupEXG){
writeEXGConfiguration();
mSetupEXG = false;
}
writeGSRRange(getGSRRange());
writeAccelRange(getAccelRange());
writeGyroRange(getGyroRange());
writeMagRange(getMagRange());
writeShimmerAndSensorsSamplingRate(getSamplingRateShimmer());
writeInternalExpPower(1);
// setContinuousSync(mContinousSync);
}
}
}

if(this.mUseInfoMemConfigMethod && getFirmwareVersionCode()>=6){
readConfigBytes();
readPressureCalibrationCoefficients();
}
else {
readSamplingRate();
readMagRange();
readAccelRange();
readGyroRange();
readAccelSamplingRate();
readCalibrationParameters("All");
readPressureCalibrationCoefficients();
readEXGConfigurations();
//enableLowPowerMag(mLowPowerMag);

readDerivedChannelBytes();

if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 2)){
readTrial();
readConfigTime();
readShimmerName();
readExperimentName();
}
}

readLEDCommand();

if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 2) ||
isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1)){
readStatusLogAndStream();
}

if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 9) ||
isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1)){
readBattery();
}

if(getShimmerVerObject().isSupportedBtFwVerRequest()) {
readBtFwVersion();
}

// Only read calibration dump over bluetooth if the Shimmer is not
// docked as the Shimmer won't have access to the SD card
if(!isDocked()){
readCalibrationDump();
}

if(isSetupDeviceWhileConnecting()){
if(mFixedShimmerConfigMode!=null && mFixedShimmerConfigMode!=FIXED_SHIMMER_CONFIG_MODE.NONE){
writeEnabledSensors(mEnabledSensors); //this should always be the last command
} else {
//writeAccelRange(mDigitalAccelRange);
writeEnabledSensors(mSetEnabledSensors); //this should always be the last command
}
}
else {
inquiry();
}

if(mSendProgressReport){
// Just unlock instruction stack and leave logAndStream timer as
// this is handled in the next step, i.e., no need for
// operationStart() here
startOperation(BT_STATE.CONNECTING, getListofInstructions().size());

setInstructionStackLock(false);
}

startTimerReadStatus(); // if shimmer is using LogAndStream FW, read its status periodically
startTimerReadBattStatus(); // if shimmer is using LogAndStream FW, read its status periodically


initializeShimmer3or3R(HW_ID.SHIMMER_3R);
}

private void initializeShimmer3(){
setHardwareVersionAndCreateSensorMaps(HW_ID.SHIMMER_3);
initializeShimmer3or3R(HW_ID.SHIMMER_3);
}

private void initializeShimmer3or3R(int hardwareVersion){
setHardwareVersionAndCreateSensorMaps(hardwareVersion);
// initialise(HW_ID.SHIMMER_3);

setHaveAttemptedToReadConfig(true);
Expand Down Expand Up @@ -2780,23 +2669,22 @@ private void initializeShimmer3(){

readLEDCommand();

if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 2) ||
isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1)){
if(getShimmerVerObject().isSupportedBtStatusRequest()) {
readStatusLogAndStream();
}

if(isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 9) ||
isThisVerCompatibleWith(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1)){

if(getShimmerVerObject().isSupportedBtBatteryRequest()) {
readBattery();
}

if(getShimmerVerObject().isSupportedBtFwVerRequest()) {
readBtFwVersion();
}

// Only read calibration dump over bluetooth if the Shimmer is not
// docked as the Shimmer won't have access to the SD card
if(!isDocked()){
//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.
if(hardwareVersion==HW_ID.SHIMMER_3R || !isDocked()){
readCalibrationDump();
}

Expand All @@ -2823,7 +2711,6 @@ private void initializeShimmer3(){

startTimerReadStatus(); // if shimmer is using LogAndStream FW, read its status periodically
startTimerReadBattStatus(); // if shimmer is using LogAndStream FW, read its status periodically

}

@Override
Expand Down Expand Up @@ -3414,7 +3301,7 @@ public void readPressureCalibrationCoefficients() {
writeInstruction(GET_BMP180_CALIBRATION_COEFFICIENTS_COMMAND);
}
}
}else if(getHardwareVersion()==HW_ID.SHIMMER_3R) {
} else if (getHardwareVersion() == HW_ID.SHIMMER_3R) {
writeInstruction(GET_PRESSURE_CALIBRATION_COEFFICIENTS_COMMAND);
}
}
Expand Down Expand Up @@ -3477,8 +3364,7 @@ public void readBtFwVersion() {
* @param rate it is a value between 0 and 255; 6 = 1152Hz, 77 = 102.56Hz, 255 = 31.25Hz
*/
public void writeGyroSamplingRate(int rate) {
if(getHardwareVersion()==HW_ID.SHIMMER_3
|| getHardwareVersion()==HW_ID.SHIMMER_3R){
if(isShimmerGen3or3R()){
mTempIntValue=rate;
writeInstruction(new byte[]{SET_MPU9150_SAMPLING_RATE_COMMAND, (byte)rate});
}
Expand Down Expand Up @@ -3521,7 +3407,7 @@ public void writeEnabledSensors(long enabledSensors) {
byte firstByte=(byte)(enabledSensors & 0xFF);

//write(new byte[]{SET_SENSORS_COMMAND,(byte) lowByte, highByte});
if(getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion()==HW_ID.SHIMMER_3R){
if(isShimmerGen3or3R()){
byte thirdByte=(byte)((enabledSensors & 0xFF0000)>>16);
writeInstruction(new byte[]{SET_SENSORS_COMMAND,(byte) firstByte,(byte) secondByte,(byte) thirdByte});
}
Expand Down Expand Up @@ -3628,20 +3514,17 @@ public void writeMagSamplingRate(int rate) {
* Used to retrieve the data rate of the Accelerometer on Shimmer 3
*/
public void readAccelSamplingRate() {
if(getHardwareVersion()!=HW_ID.SHIMMER_3){
}
else {
if(isShimmerGen3or3R()){
writeInstruction(GET_ACCEL_SAMPLING_RATE_COMMAND);
}
}
}

/**
* writeAccelSamplingRate(range) sets the AccelSamplingRate on the Shimmer (version 3) to the value of the input range. Note that when using writesamplingrate this value will be overwritten based on the lowpowerwraccel mode setting.
* @param rate it is a value between 1 and 7; 1 = 1 Hz; 2 = 10 Hz; 3 = 25 Hz; 4 = 50 Hz; 5 = 100 Hz; 6 = 200 Hz; 7 = 400 Hz
*/
public void writeAccelSamplingRate(int rate) {
if(getHardwareVersion()==HW_ID.SHIMMER_3
|| getHardwareVersion()==HW_ID.SHIMMER_3R){
if(isShimmerGen3or3R()){
mTempIntValue=rate;
writeInstruction(new byte[]{SET_ACCEL_SAMPLING_RATE_COMMAND, (byte)rate});
}
Expand Down Expand Up @@ -3993,7 +3876,7 @@ public void readGyroRange() {
* @param range is a numeric value defining the desired gyroscope range.
*/
public void writeGyroRange(int range) {
if(getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion()==HW_ID.SHIMMER_3R){
if(isShimmerGen3or3R()){
writeInstruction(new byte[]{SET_MPU9150_GYRO_RANGE_COMMAND, (byte)range});
setGyroRange((int)range);
}
Expand Down Expand Up @@ -4031,8 +3914,7 @@ public void writeShimmerAndSensorsSamplingRate(double rate) {
int samplingByteValue = (int) (1024/getSamplingRateShimmer()); //the equivalent hex setting
writeInstruction(new byte[]{SET_SAMPLING_RATE_COMMAND, (byte)Math.rint(samplingByteValue), 0x00});
}
else if(getHardwareVersion()==HW_ID.SHIMMER_3
|| getHardwareVersion()==HW_ID.SHIMMER_3R) {
else if(isShimmerGen3or3R()) {

writeMagSamplingRate(getMagRate());
try {
Expand Down Expand Up @@ -4309,7 +4191,7 @@ public void readGSRRange() {
* @param range numeric value defining the desired GSR range. Valid range settings are 0 (10kOhm to 56kOhm), 1 (56kOhm to 220kOhm), 2 (220kOhm to 680kOhm), 3 (680kOhm to 4.7MOhm) and 4 (Auto Range).
*/
public void writeGSRRange(int range) {
if(getHardwareVersion()==HW_ID.SHIMMER_3){
if(isShimmerGen3or3R()){
if(getFirmwareVersionCode()!=1 || getFirmwareVersionInternal() >4){
writeInstruction(new byte[]{SET_GSR_RANGE_COMMAND, (byte)range});
}
Expand Down Expand Up @@ -4394,7 +4276,7 @@ public void writeMagCalibrationParameters(byte[] calibrationParameters) {
}

public void writeWRAccelCalibrationParameters(byte[] calibrationParameters) {
if(getHardwareVersion()==HW_ID.SHIMMER_3){
if(isShimmerGen3or3R()){
cmdcalibrationParameters[0] = SET_LSM303DLHC_ACCEL_CALIBRATION_COMMAND;
System.arraycopy(calibrationParameters, 0, cmdcalibrationParameters, 1, 21);
writeInstruction(cmdcalibrationParameters);
Expand Down Expand Up @@ -5184,7 +5066,7 @@ else if((sensorToCheck & SENSOR_BATT) >0){
}
}

else if(getHardwareVersion()==HW_ID.SHIMMER_3){
else if(isShimmerGen3or3R()){

if((sensorToCheck & SENSOR_GSR) >0){
enabledSensors = disableBit(enabledSensors,SENSOR_INT_ADC_A1);
Expand Down Expand Up @@ -5262,7 +5144,7 @@ else if((sensorToCheck & SENSOR_INT_ADC_A14) >0){
//TODO: MN -> replace with sensormap conflict checks? unfinished for Shimmer2R
public boolean sensorConflictCheck(long enabledSensors){
boolean pass=true;
if(getHardwareVersion()!=HW_ID.SHIMMER_3){
if(getHardwareVersion()!=HW_ID.SHIMMER_3 && getHardwareVersion()!=HW_ID.SHIMMER_3R){
if(((enabledSensors & 0xFF)& SENSOR_GYRO) > 0){
if(((enabledSensors & 0xFF)& SENSOR_EMG) > 0){
pass=false;
Expand Down Expand Up @@ -5616,7 +5498,7 @@ private long generateSensorBitmapForHardwareControl(long enabledSensors){
}
hardwareSensorBitmap = enabledSensors;
}
else if(getHardwareVersion()==HW_ID.SHIMMER_3){
else if(isShimmerGen3or3R()){
if(((enabledSensors & 0xFF)& SENSOR_ACCEL) > 0){
hardwareSensorBitmap = hardwareSensorBitmap|Configuration.Shimmer3.SensorBitmap.SENSOR_A_ACCEL;
}
Expand Down Expand Up @@ -5693,7 +5575,7 @@ public void toggleLed() {
@Override
protected void checkBattery(){
if(mIsStreaming ){
if((getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion()==HW_ID.SHIMMER_3R) && getFirmwareVersionCode()==FW_ID.LOGANDSTREAM){
if((isShimmerGen3or3R()) && getFirmwareVersionCode()==FW_ID.LOGANDSTREAM){
if(!mWaitForAck) {
if(mVSenseBattMA.getMean()<mLowBattLimit*1000*0.8) {
if(mCurrentLEDStatus!=2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,11 @@ public boolean isShimmerGen3(){
public boolean isShimmerGen3R(){
return mShimmerVerObject.isShimmerGen3R();
}


public boolean isShimmerGen3or3R(){
return mShimmerVerObject.isShimmerGen3() || mShimmerVerObject.isShimmerGen3R();
}

public boolean isShimmerGen4(){
return mShimmerVerObject.isShimmerGen4();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 +730,17 @@ public String generateDebugString() {
return "HW_ID: " + getHardwareVersion() + "\tHardwareVersionParsed: " + getHardwareVersionParsed()
+ "\tFW_ID: " + getFirmwareIdentifier() + "\tFirmwareVersionParsed: " + getFirmwareVersionParsed();
}

public boolean isSupportedBtStatusRequest() {
return (mHardwareVersion==HW_ID.SHIMMER_3R
||compareVersions(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 2)
|| compareVersions(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1));
}

public boolean isSupportedBtBatteryRequest() {
return (mHardwareVersion==HW_ID.SHIMMER_3R
|| compareVersions(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 5, 9)
|| compareVersions(HW_ID.SHIMMER_3, FW_ID.BTSTREAM, 0, 8, 1));
}

}
Loading