mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 07:41:36 +08:00
px4_cli: Added px4_get_parameter_value function overload for float type
This commit is contained in:
@@ -50,3 +50,15 @@
|
|||||||
* @return 0 on success, -errno otherwise
|
* @return 0 on success, -errno otherwise
|
||||||
*/
|
*/
|
||||||
int px4_get_parameter_value(const char *option, int &value);
|
int px4_get_parameter_value(const char *option, int &value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a CLI argument to a float. There are 2 valid formats:
|
||||||
|
* - 'p:<param_name>'
|
||||||
|
* in this case the parameter is loaded from an integer parameter
|
||||||
|
* - <float>
|
||||||
|
* a floating-point value, so just a string to float conversion is done
|
||||||
|
* @param option CLI argument
|
||||||
|
* @param value returned value
|
||||||
|
* @return 0 on success, -errno otherwise
|
||||||
|
*/
|
||||||
|
int px4_get_parameter_value(const char *option, float &value);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ int px4_get_parameter_value(const char *option, int &value)
|
|||||||
if (param_handle != PARAM_INVALID) {
|
if (param_handle != PARAM_INVALID) {
|
||||||
|
|
||||||
if (param_type(param_handle) != PARAM_TYPE_INT32) {
|
if (param_type(param_handle) != PARAM_TYPE_INT32) {
|
||||||
|
PX4_ERR("Type of param '%s' is different from INT32", param_name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,3 +88,48 @@ int px4_get_parameter_value(const char *option, int &value)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int px4_get_parameter_value(const char *option, float &value)
|
||||||
|
{
|
||||||
|
value = 0;
|
||||||
|
|
||||||
|
/* check if this is a param name */
|
||||||
|
if (strncmp("p:", option, 2) == 0) {
|
||||||
|
|
||||||
|
const char *param_name = option + 2;
|
||||||
|
|
||||||
|
/* user wants to use a param name */
|
||||||
|
param_t param_handle = param_find(param_name);
|
||||||
|
|
||||||
|
if (param_handle != PARAM_INVALID) {
|
||||||
|
|
||||||
|
if (param_type(param_handle) != PARAM_TYPE_FLOAT) {
|
||||||
|
PX4_ERR("Type of param '%s' is different from FLOAT", param_name);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
float pwm_parm;
|
||||||
|
int ret = param_get(param_handle, &pwm_parm);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = pwm_parm;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
PX4_ERR("param name '%s' not found", param_name);
|
||||||
|
return -ENXIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
char *ep;
|
||||||
|
value = strtof(option, &ep);
|
||||||
|
|
||||||
|
if (*ep != '\0') {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user