@@ -473,7 +473,17 @@ public class BTStream {
473473
474474 public static final byte GET_PRESSURE_CALIBRATION_COEFFICIENTS_COMMAND = (byte ) 0xA7 ;//BMP390
475475 public static final byte PRESSURE_CALIBRATION_COEFFICIENTS_RESPONSE = (byte ) 0xA6 ;//BMP390
476-
476+
477+ /** The sensor ID byte in a PRESSURE_CALIBRATION_COEFFICIENTS_RESPONSE, which
478+ * is laid out as [0xA6][len = 1+n][sensorId][n coefficient bytes]
479+ * (log-and-stream-common Comms/shimmer_bt_uart.c). */
480+ public static final class PRESSURE_SENSOR_ID {
481+ public static final int BMP180 = 0 ;
482+ public static final int BMP280 = 1 ;
483+ public static final int BMP390 = 2 ;
484+ public static final int BMP581 = 3 ;
485+ }
486+
477487 public static final byte SET_PRESSURE_OVERSAMPLING_RATIO_COMMAND = (byte ) 0x52 ;
478488 public static final byte PRESSURE_OVERSAMPLING_RATIO_RESPONSE = (byte ) 0x53 ;
479489 public static final byte GET_PRESSURE_OVERSAMPLING_RATIO_COMMAND = (byte ) 0x54 ;
@@ -680,7 +690,13 @@ public String toString() {
680690 protected SensorMPU9X50 mSensorMpu9x50 = new SensorMPU9150 (this );
681691 // Shimmer3 - Pressure/Temperature
682692 public SensorBMPX80 mSensorBMPX80 = new SensorBMP180 (this );
683-
693+ /** The pressure sensor a Shimmer3R reported in-band in its
694+ * PRESSURE_CALIBRATION_COEFFICIENTS_RESPONSE (a {@link PRESSURE_SENSOR_ID}),
695+ * or null if it hasn't. When set it overrides the SR-number rule in
696+ * {@link #isSupportedBmp581()}. Cleared whenever the expansion board details
697+ * change, so each connection starts from the SR-number rule again. */
698+ protected Integer mPressureSensorIdInBand = null ;
699+
684700 // Shimmer3r - Mag
685701 private SensorLIS2MDL mSensorLIS2MDL = new SensorLIS2MDL (this );
686702 // Shimmer3r - Alt Mag
@@ -10823,31 +10839,50 @@ public static boolean isSupportedBmp280(ShimmerVerObject svo, ExpansionBoardDeta
1082310839 * SR number/revision and the firmware version that produces the new output
1082410840 * format.
1082510841 *
10826- * @return true if the connected Shimmer3R board revision and firmware version indicate BMP581 output support
10842+ * <p>
10843+ * If the Shimmer has reported its pressure sensor in-band (the sensor ID in
10844+ * its PRESSURE_CALIBRATION_COEFFICIENTS_RESPONSE, LogAndStream_Shimmer3R
10845+ * v1.01.007 onwards), that answer is used and overrides the SR-number rule
10846+ * in either direction. Otherwise, e.g. when the firmware NACKs the command
10847+ * or is too old to have it, the SR-number rule decides.
10848+ *
10849+ * @return true if the connected Shimmer3R reported a BMP581, or if its board revision and firmware version indicate BMP581 output support
1082710850 */
1082810851 public boolean isSupportedBmp581 () {
10852+ if (mPressureSensorIdInBand !=null && getHardwareVersion ()==HW_ID .SHIMMER_3R ){
10853+ return mPressureSensorIdInBand ==PRESSURE_SENSOR_ID .BMP581 ;
10854+ }
1082910855 return isSupportedBmp581 (getShimmerVerObject (), getExpansionBoardDetails ());
1083010856 }
1083110857
10858+ /** The SR-number rule alone, used when the Shimmer hasn't identified its
10859+ * pressure sensor in-band and for SD log files (whose header carries no
10860+ * sensor ID). It mirrors the firmware's own fallback,
10861+ * ShimBrd_isBmp581PresentPerSrNumber() in log-and-stream-common
10862+ * Boards/shimmer_boards.c, plus a firmware-version guard.
10863+ *
10864+ * @param svo the Shimmer's version details
10865+ * @param ebd the Shimmer's expansion board details
10866+ * @return true if a Shimmer3R with this board and firmware carries a BMP581
10867+ */
1083210868 public static boolean isSupportedBmp581 (ShimmerVerObject svo , ExpansionBoardDetails ebd ) {
1083310869 if (svo ==null || ebd ==null || svo .getHardwareVersion ()!=HW_ID .SHIMMER_3R ){
1083410870 return false ;
1083510871 }
1083610872
10837- // SR48 (GSR+): BMP581 spans two bands - 7.2..7.x AND 8.2 and above.
10838- // 7.0/7.1 and 8.0/8.1 are BMP390, so a single lexicographic ">=" can't
10839- // express it (8.0/8.1 fall between the two BMP581 bands).
10840- boolean sr48Bmp581 =
10841- (ebd .getExpansionBoardId ()==HW_ID_SR_CODES .EXP_BRD_GSR_UNIFIED
10842- && ebd .getExpansionBoardRev ()==7
10843- && ebd .getExpansionBoardRevSpecial ()>=2 ) // SR48 7.2..7.x
10844- || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_GSR_UNIFIED , 8 , 2 ); // SR48 8.2 and above
10845-
10873+ // Fitted models (">=" applies to both rev fields): SR31-11-2, SR38-4-2,
10874+ // SR47-8-2, SR48-7-2, SR48-8-2, SR49-4-2. SR48 (GSR+) has two BMP581
10875+ // bands, 7.2..7.x and 8.2 onwards: 8.0/8.1 went back to the BMP390, so
10876+ // the rev-7 band is ">= 7.2 and not >= 8.0". An unprogrammed card (board
10877+ // ID 0x00 or 0xFF) matches none of these IDs.
1084610878 boolean boardEligible =
10847- ebd .isSrNumberGte (HW_ID_SR_CODES .SHIMMER3 , 11 , 2 ) // SR31 >= 11.2
10848- || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_EXG_UNIFIED , 8 , 2 ) // SR47 >= 8.2
10849- || sr48Bmp581 // SR48 7.2..7.x and 8.2+
10850- || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_BR_AMP_UNIFIED , 4 , 2 ); // SR49 >= 4.2
10879+ ebd .isSrNumberGte (HW_ID_SR_CODES .SHIMMER3 , 11 , 2 ) // SR31 >= 11.2
10880+ || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_PROTO3_DELUXE , 4 , 2 ) // SR38 >= 4.2
10881+ || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_EXG_UNIFIED , 8 , 2 ) // SR47 >= 8.2
10882+ || (ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_GSR_UNIFIED , 7 , 2 )
10883+ && !ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_GSR_UNIFIED , 8 , 0 )) // SR48 7.2..7.x
10884+ || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_GSR_UNIFIED , 8 , 2 ) // SR48 >= 8.2
10885+ || ebd .isSrNumberGte (HW_ID_SR_CODES .EXP_BRD_BR_AMP_UNIFIED , 4 , 2 ); // SR49 >= 4.2
1085110886
1085210887 // Format guard: BMP581 (pre-compensated) output only exists from
1085310888 // LogAndStream_Shimmer3R v1.01.006 onwards.
@@ -10856,6 +10891,70 @@ public static boolean isSupportedBmp581(ShimmerVerObject svo, ExpansionBoardDeta
1085610891 return boardEligible && fwEligible ;
1085710892 }
1085810893
10894+ /** Records the pressure sensor a Shimmer3R reported in-band and, if the
10895+ * sensor class in use is not the one it names, rebuilds the sensor classes
10896+ * around the reported sensor. The rebuild is what would have happened had
10897+ * the sensor been known when the daughter card ID arrived: the config bytes,
10898+ * which the Shimmer sends before this response while connecting, are parsed
10899+ * again so the new sensor class picks up its settings (e.g. oversampling).
10900+ *
10901+ * @param pressureSensorId the sensor ID from the response, a {@link PRESSURE_SENSOR_ID}
10902+ */
10903+ public void setPressureSensorIdInBand (int pressureSensorId ) {
10904+ mPressureSensorIdInBand = pressureSensorId ;
10905+
10906+ if (isShimmerGen3R ()){
10907+ boolean bmp581InUse = mSensorBMPX80 .mSensorType ==SENSORS .BMP581 ;
10908+ if (bmp581InUse !=isSupportedBmp581 ()){
10909+ consolePrintLn ("Pressure sensor reported in-band (ID " + pressureSensorId + ") differs from the SR-number rule, switching to " + (isSupportedBmp581 ()? "BMP581" :"BMP390" ));
10910+ sensorAndConfigMapsCreate ();
10911+ if (mShimmerUsingConfigFromInfoMem && ConfigByteLayout .checkConfigBytesValid (mConfigBytes )){
10912+ configBytesParse (mConfigBytes , COMMUNICATION_TYPE .BLUETOOTH );
10913+ }
10914+ }
10915+ }
10916+ }
10917+
10918+ /**
10919+ * @return the pressure sensor the Shimmer reported in-band (a {@link PRESSURE_SENSOR_ID}), or null if it hasn't
10920+ */
10921+ public Integer getPressureSensorIdInBand () {
10922+ return mPressureSensorIdInBand ;
10923+ }
10924+
10925+ /**
10926+ * @param pressureSensorId a {@link PRESSURE_SENSOR_ID}
10927+ * @return the number of coefficient bytes that follow this sensor ID in a
10928+ * PRESSURE_CALIBRATION_COEFFICIENTS_RESPONSE, or -1 if the ID is unknown
10929+ */
10930+ public static int getPressureCalibCoefficientByteLength (int pressureSensorId ) {
10931+ switch (pressureSensorId ){
10932+ case PRESSURE_SENSOR_ID .BMP180 :
10933+ return 22 ;
10934+ case PRESSURE_SENSOR_ID .BMP280 :
10935+ return 24 ;
10936+ case PRESSURE_SENSOR_ID .BMP390 :
10937+ return 21 ;
10938+ case PRESSURE_SENSOR_ID .BMP581 :
10939+ return 0 ; // self-compensating, no coefficients
10940+ default :
10941+ return -1 ;
10942+ }
10943+ }
10944+
10945+ @ Override
10946+ public void setExpansionBoardDetails (ExpansionBoardDetails eBD ){
10947+ super .setExpansionBoardDetails (eBD );
10948+ // A different board may carry a different pressure sensor
10949+ mPressureSensorIdInBand = null ;
10950+ }
10951+
10952+ @ Override
10953+ public void clearExpansionBoardDetails (){
10954+ super .clearExpansionBoardDetails ();
10955+ mPressureSensorIdInBand = null ;
10956+ }
10957+
1085910958 /** Returns true if the Shimmer is using new sensors. These sensors are:
1086010959 * <li> Use BMP280 instead of BMP180 as barometer.
1086110960 * <li> Use MPU9250 instead of MPU9150 as IMU.
0 commit comments