SingleReportTests refactoring

This commit is contained in:
myles-parfeniuk 2024-11-16 15:57:53 -08:00
parent cc925283e8
commit 4c1456da3b
3 changed files with 96 additions and 21 deletions

View File

@ -58,6 +58,12 @@ class BNO08xTestHelper
float magf_z;
BNO08xAccuracy magf_accuracy;
uint16_t raw_mems_gyro_x;
uint16_t raw_mems_gyro_y;
uint16_t raw_mems_gyro_z;
uint8_t tap_count;
} imu_report_data_t;
static void print_test_start_banner(const char* TEST_TAG)
@ -313,6 +319,23 @@ class BNO08xTestHelper
return new_data;
}
static bool raw_mems_gyro_data_is_default(imu_report_data_t* report_data, imu_report_data_t* prev_report_data)
{
bool new_data = false;
return new_data;
}
static bool tap_detector_data_is_default(imu_report_data_t* report_data, imu_report_data_t* prev_report_data)
{
bool new_data = false;
if (report_data->tap_count != prev_report_data->tap_count)
new_data = true;
return new_data;
}
static void update_report_data(imu_report_data_t* report_data, BNO08x* imu)
{
@ -327,6 +350,8 @@ class BNO08xTestHelper
imu->get_uncalibrated_gyro_velocity(report_data->uncalib_gyro_vel_x, report_data->uncalib_gyro_vel_y, report_data->uncalib_gyro_vel_z,
report_data->uncalib_gyro_drift_x, report_data->uncalib_gyro_drift_y, report_data->uncalib_gyro_drift_z);
imu->get_magf(report_data->magf_x, report_data->magf_y, report_data->magf_z, report_data->magf_accuracy);
imu->get_raw_mems_gyro(report_data->raw_mems_gyro_x, report_data->raw_mems_gyro_y, report_data->raw_mems_gyro_z);
report_data->tap_count = imu->get_tap_detector();
}
static void reset_all_imu_data_to_test_defaults(BNO08x* imu)

View File

@ -3196,9 +3196,7 @@ float BNO08x::get_integrated_gyro_velocity_Z()
*/
uint8_t BNO08x::get_tap_detector()
{
uint8_t previous_tap_detector = tap_detector;
tap_detector = 0; // Reset so user code sees exactly one tap
return (previous_tap_detector);
return tap_detector;
}
/**

View File

@ -46,7 +46,7 @@ TEST_CASE("Enable Incorrect Report", "[SingleReportEnableDisable]")
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff,
"Rx Data Trial %d Success: AngularAccelDefaults: aX: %.2lf accel aY: %.2lf accel aZ: "
"No Rx Data Trial %d Success: AngularAccelDefaults: aX: %.2lf accel aY: %.2lf accel aZ: "
"%.2lf Accuracy %s",
(i + 1), report_data.accel_x, report_data.accel_y, report_data.accel_z,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.accel_accuracy));
@ -130,7 +130,10 @@ TEST_CASE("Enable/Disable Rotation Vector", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff, "No Rx Data Trial %d Success: QuatDefaults: I: %.2lf J: %.2lf K: %.2lf real: %.2lf Accuracy: %s", (i + 1),
report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.quat_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -211,7 +214,10 @@ TEST_CASE("Enable/Disable Game Rotation Vector", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff, "No Rx Data Trial %d Success: QuatDefaults: I: %.2lf J: %.2lf K: %.2lf real: %.2lf Accuracy: %s", (i + 1),
report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.quat_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -292,7 +298,10 @@ TEST_CASE("Enable/Disable ARVR Stabilized Rotation Vector", "[SingleReportEnable
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff, "No Rx Data Trial %d Success: QuatDefaults: I: %.2lf J: %.2lf K: %.2lf real: %.2lf Accuracy: %s", (i + 1),
report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.quat_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -373,7 +382,10 @@ TEST_CASE("Enable/Disable ARVR Stabilized Game Rotation Vector", "[SingleReportE
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff, "No Rx Data Trial %d Success: QuatDefaults: I: %.2lf J: %.2lf K: %.2lf real: %.2lf Accuracy: %s", (i + 1),
report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.quat_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -386,9 +398,9 @@ TEST_CASE("Enable/Disable ARVR Stabilized Game Rotation Vector", "[SingleReportE
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
}
TEST_CASE("Enable/Disable Gyro Integrated Roation Vector", "[SingleReportEnableDisable]")
TEST_CASE("Enable/Disable Gyro Integrated Rotation Vector", "[SingleReportEnableDisable]")
{
const constexpr char* TEST_TAG = "Enable/Disable Gyro Integrated Roation Vector";
const constexpr char* TEST_TAG = "Enable/Disable Gyro Integrated Rotation Vector";
BNO08x* imu = nullptr;
BNO08xTestHelper::imu_report_data_t report_data;
BNO08xTestHelper::imu_report_data_t prev_report_data;
@ -424,11 +436,13 @@ TEST_CASE("Enable/Disable Gyro Integrated Roation Vector", "[SingleReportEnableD
TEST_ASSERT_EQUAL(true, new_data);
sprintf(msg_buff,
"Rx Data Trial %d Success: Quat: I: %.2lf J: %.2lf K: %.2lf real: %.2lf gyro vel X: %.2lf gyro vel Y: %.2lf gyro vel "
"Rx Data Trial %d Success: GyroIntegratedRotVector: I: %.2lf J: %.2lf K: %.2lf real: %.2lf gyro vel X: %.2lf gyro vel Y: %.2lf gyro "
"vel "
"Z: "
"%.2lf ",
(i + 1), report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real, report_data.integrated_gyro_vel_x,
report_data.integrated_gyro_vel_y, report_data.integrated_gyro_vel_z);
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -457,7 +471,14 @@ TEST_CASE("Enable/Disable Gyro Integrated Roation Vector", "[SingleReportEnableD
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: GyroIntegratedRotVectorDefaults: I: %.2lf J: %.2lf K: %.2lf real: %.2lf gyro vel X: %.2lf gyro vel Y: "
"%.2lf gyro vel "
"Z: "
"%.2lf ",
(i + 1), report_data.quat_I, report_data.quat_J, report_data.quat_K, report_data.quat_real, report_data.integrated_gyro_vel_x,
report_data.integrated_gyro_vel_y, report_data.integrated_gyro_vel_z);
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -508,7 +529,7 @@ TEST_CASE("Enable/Disable Uncalibrated Gyro", "[SingleReportEnableDisable]")
TEST_ASSERT_EQUAL(true, new_data);
sprintf(msg_buff,
"Rx Data Trial %d Success: Uncalib Gyro: vX: %.2lf vY: %.2lf vZ: %.2lf driftX: %.2lf driftY: %.2lf driftZ: "
"Rx Data Trial %d Success: UncalibratedGyro: vX: %.2lf vY: %.2lf vZ: %.2lf driftX: %.2lf driftY: %.2lf driftZ: "
"%.2lf",
(i + 1), report_data.uncalib_gyro_vel_x, report_data.uncalib_gyro_vel_y, report_data.uncalib_gyro_vel_z,
report_data.uncalib_gyro_drift_x, report_data.uncalib_gyro_drift_y, report_data.uncalib_gyro_drift_z);
@ -541,7 +562,12 @@ TEST_CASE("Enable/Disable Uncalibrated Gyro", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: UncalibratedGyroDefaults: vX: %.2lf vY: %.2lf vZ: %.2lf driftX: %.2lf driftY: %.2lf driftZ: "
"%.2lf",
(i + 1), report_data.uncalib_gyro_vel_x, report_data.uncalib_gyro_vel_y, report_data.uncalib_gyro_vel_z,
report_data.uncalib_gyro_drift_x, report_data.uncalib_gyro_drift_y, report_data.uncalib_gyro_drift_z);
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -592,9 +618,10 @@ TEST_CASE("Enable/Disable Calibrated Gyro", "[SingleReportEnableDisable]")
TEST_ASSERT_EQUAL(true, new_data);
sprintf(msg_buff,
"Rx Data Trial %d Success: Calibrated Gyro: vX: %.2lf vY: %.2lf vZ: "
"Rx Data Trial %d Success: CalibratedGyro: vX: %.2lf vY: %.2lf vZ: "
"%.2lf",
(i + 1), report_data.calib_gyro_vel_x, report_data.calib_gyro_vel_y, report_data.calib_gyro_vel_z);
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -623,7 +650,11 @@ TEST_CASE("Enable/Disable Calibrated Gyro", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: CalibratedGyroDefaults: vX: %.2lf vY: %.2lf vZ: "
"%.2lf",
(i + 1), report_data.calib_gyro_vel_x, report_data.calib_gyro_vel_y, report_data.calib_gyro_vel_z);
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -707,7 +738,12 @@ TEST_CASE("Enable/Disable Accelerometer", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: AngularAccelDefaults: aX: %.2lf accel aY: %.2lf accel aZ: "
"%.2lf Accuracy %s",
(i + 1), report_data.accel_x, report_data.accel_y, report_data.accel_z,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.accel_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -791,7 +827,12 @@ TEST_CASE("Enable/Disable Linear Accelerometer", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: LinearAccelDefaults: laX: %.2lf laY: %.2lf laZ: "
"%.2lf Accuracy: %s",
(i + 1), report_data.lin_accel_x, report_data.lin_accel_y, report_data.lin_accel_z,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.lin_accel_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -875,7 +916,12 @@ TEST_CASE("Enable/Disable Gravity", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: GravityDefaults: gX: %.2lf gY: %.2lf gZ: "
"%.2lf Accuracy: %s",
(i + 1), report_data.grav_x, report_data.grav_y, report_data.grav_z,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.grav_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -959,7 +1005,12 @@ TEST_CASE("Enable/Disable Magnetometer", "[SingleReportEnableDisable]")
// assert that no new data from respective report has been received
TEST_ASSERT_NOT_EQUAL(true, new_data);
sprintf(msg_buff, "No Rx Data Trial %d Success", (i + 1));
sprintf(msg_buff,
"No Rx Data Trial %d Success: MagfDefaults: mX: %.2lf mY: %.2lf mZ: "
"%.2lf Accuracy: %s",
(i + 1), report_data.magf_x, report_data.magf_y, report_data.magf_z,
BNO08xTestHelper::BNO08xAccuracy_to_str(report_data.magf_accuracy));
BNO08xTestHelper::print_test_msg(TEST_TAG, msg_buff);
// reset all data used in report test
@ -971,3 +1022,4 @@ TEST_CASE("Enable/Disable Magnetometer", "[SingleReportEnableDisable]")
BNO08xTestHelper::print_test_end_banner(TEST_TAG);
}