Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factory calib: add option to exclude mag to param SYS_FAC_CAL_MODE & exclude _PRIO params #21707

Merged
merged 2 commits into from
Jun 10, 2023
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
4 changes: 3 additions & 1 deletion src/lib/systemlib/system_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ PARAM_DEFINE_INT32(SYS_HAS_NUM_DIST, 0);
* Note: this is only supported on boards with a separate calibration storage
* /fs/mtd_caldata.
*
* @boolean
* @value 0 Disabled
* @value 1 All sensors
* @value 2 All sensors except mag
* @group System
*/
PARAM_DEFINE_INT32(SYS_FAC_CAL_MODE, 0);
Expand Down
39 changes: 37 additions & 2 deletions src/modules/commander/factory_calibration_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,53 @@

static const char *CALIBRATION_STORAGE = "/fs/mtd_caldata";

enum class FactoryCalibrationMode : uint32_t {
Disabled = 0,
AllSensors,
AllSensorsExceptMag,
};

static bool ends_with(const char *str, const char *suffix)
{
if (!str || !suffix) {
return false;
}

size_t len_str = strlen(str);
size_t len_suffix = strlen(suffix);

if (len_suffix > len_str) {
return false;
}

return strncmp(str + len_str - len_suffix, suffix, len_suffix) == 0;
}

static FactoryCalibrationMode factory_calibration_mode{FactoryCalibrationMode::Disabled};

static bool filter_calibration_params(param_t handle)
{
const char *name = param_name(handle);

if (factory_calibration_mode == FactoryCalibrationMode::AllSensorsExceptMag) {
if (strncmp(name, "CAL_MAG", 7) == 0) {
return false;
}
}

// filter all non-calibration params
return (strncmp(name, "CAL_", 4) == 0 && strncmp(name, "CAL_MAG_SIDES", 13) != 0) || strncmp(name, "TC_", 3) == 0;
return (strncmp(name, "CAL_", 4) == 0
&& strcmp(name, "CAL_MAG_SIDES") != 0
&& !ends_with(name, "_PRIO"))
|| strncmp(name, "TC_", 3) == 0;
}

FactoryCalibrationStorage::FactoryCalibrationStorage()
{
int32_t param = 0;
param_get(param_find("SYS_FAC_CAL_MODE"), &param);
_enabled = param == 1;
_enabled = param >= 1;
factory_calibration_mode = (FactoryCalibrationMode)param;
}

int FactoryCalibrationStorage::open()
Expand Down