2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2013-08-29 02:34:34 -03:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
2012-02-11 07:51:35 -04:00
|
|
|
/// @file AP_Param.h
|
|
|
|
/// @brief A system for managing and storing variables that are of
|
|
|
|
/// general interest to the system.
|
2015-12-23 13:25:02 -04:00
|
|
|
#pragma once
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
2016-03-31 18:43:36 -03:00
|
|
|
#include <cmath>
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2015-12-23 13:25:02 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2018-08-06 01:43:30 -03:00
|
|
|
#include <AP_HAL/utility/RingBuffer.h>
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <StorageManager/StorageManager.h>
|
2023-06-07 03:20:58 -03:00
|
|
|
#include <AP_Scripting/AP_Scripting_config.h>
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2024-01-14 20:34:05 -04:00
|
|
|
#include "AP_Param_config.h"
|
|
|
|
|
2015-12-23 13:25:02 -04:00
|
|
|
#include "float.h"
|
|
|
|
|
2012-11-20 06:35:22 -04:00
|
|
|
#define AP_MAX_NAME_SIZE 16
|
2015-12-27 16:22:32 -04:00
|
|
|
|
2018-01-24 00:42:09 -04:00
|
|
|
// optionally enable debug code for dumping keys
|
|
|
|
#define AP_PARAM_KEY_DUMP 0
|
|
|
|
|
2022-06-13 13:04:41 -03:00
|
|
|
#if defined(HAL_GCS_ENABLED)
|
|
|
|
#define AP_PARAM_DEFAULTS_ENABLED HAL_GCS_ENABLED
|
|
|
|
#else
|
|
|
|
#define AP_PARAM_DEFAULTS_ENABLED 1
|
|
|
|
#endif
|
|
|
|
|
2017-11-09 02:45:58 -04:00
|
|
|
/*
|
|
|
|
maximum size of embedded parameter file
|
|
|
|
*/
|
|
|
|
#ifndef AP_PARAM_MAX_EMBEDDED_PARAM
|
2024-01-14 20:34:05 -04:00
|
|
|
#if FORCE_APJ_DEFAULT_PARAMETERS
|
|
|
|
#if BOARD_FLASH_SIZE <= 1024
|
|
|
|
#define AP_PARAM_MAX_EMBEDDED_PARAM 1024
|
|
|
|
#else
|
|
|
|
#define AP_PARAM_MAX_EMBEDDED_PARAM 8192
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define AP_PARAM_MAX_EMBEDDED_PARAM 0
|
|
|
|
#endif
|
2017-11-09 02:45:58 -04:00
|
|
|
#endif
|
|
|
|
|
2022-01-07 01:25:38 -04:00
|
|
|
// allow for dynamically added tables when scripting enabled
|
2023-10-04 13:25:40 -03:00
|
|
|
#ifndef AP_PARAM_DYNAMIC_ENABLED
|
2022-01-07 01:25:38 -04:00
|
|
|
#define AP_PARAM_DYNAMIC_ENABLED AP_SCRIPTING_ENABLED
|
2023-10-04 13:25:40 -03:00
|
|
|
#endif
|
2022-01-07 01:25:38 -04:00
|
|
|
|
|
|
|
// maximum number of dynamically created tables (from scripts)
|
|
|
|
#ifndef AP_PARAM_MAX_DYNAMIC
|
|
|
|
#define AP_PARAM_MAX_DYNAMIC 10
|
|
|
|
#endif
|
|
|
|
#define AP_PARAM_DYNAMIC_KEY_BASE 300
|
|
|
|
|
2015-12-27 16:22:32 -04:00
|
|
|
/*
|
|
|
|
flags for variables in var_info and group tables
|
|
|
|
*/
|
2015-12-29 07:43:25 -04:00
|
|
|
|
|
|
|
// a nested offset is for subgroups that are not subclasses
|
2017-11-28 19:56:25 -04:00
|
|
|
#define AP_PARAM_FLAG_NESTED_OFFSET (1<<0)
|
2015-12-29 07:43:25 -04:00
|
|
|
|
|
|
|
// a pointer variable is for dynamically allocated objects
|
2017-11-28 19:56:25 -04:00
|
|
|
#define AP_PARAM_FLAG_POINTER (1<<1)
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2015-12-29 07:43:25 -04:00
|
|
|
// an enable variable allows a whole subtree of variables to be made
|
|
|
|
// invisible
|
2017-11-28 19:56:25 -04:00
|
|
|
#define AP_PARAM_FLAG_ENABLE (1<<2)
|
2015-12-29 07:43:25 -04:00
|
|
|
|
2016-03-17 22:33:16 -03:00
|
|
|
// don't shift index 0 to index 63. Use this when you know there will be
|
|
|
|
// no conflict with the parent
|
2020-12-15 23:51:17 -04:00
|
|
|
#define AP_PARAM_FLAG_NO_SHIFT (1<<3)
|
2016-03-17 22:33:16 -03:00
|
|
|
|
2017-02-27 02:39:12 -04:00
|
|
|
// the var_info is a pointer, allowing for dynamic definition of the var_info tree
|
2017-11-28 19:56:25 -04:00
|
|
|
#define AP_PARAM_FLAG_INFO_POINTER (1<<4)
|
|
|
|
|
2019-06-11 01:20:50 -03:00
|
|
|
// this parameter is visible to GCS via mavlink but should never be
|
|
|
|
// set by anything other than the ArduPilot code responsible for its
|
|
|
|
// use.
|
|
|
|
#define AP_PARAM_FLAG_INTERNAL_USE_ONLY (1<<5)
|
|
|
|
|
2021-08-31 19:26:01 -03:00
|
|
|
// hide parameter from param download
|
|
|
|
#define AP_PARAM_FLAG_HIDDEN (1<<6)
|
|
|
|
|
2022-12-29 22:14:05 -04:00
|
|
|
// Default value is a "pointer" actually its a offest from the base value, but the idea is the same
|
|
|
|
#define AP_PARAM_FLAG_DEFAULT_POINTER (1<<7)
|
|
|
|
|
2017-11-28 19:56:25 -04:00
|
|
|
// keep all flags before the FRAME tags
|
2017-02-27 02:39:12 -04:00
|
|
|
|
2017-02-07 19:45:20 -04:00
|
|
|
// vehicle and frame type flags, used to hide parameters when not
|
|
|
|
// relevent to a vehicle type. Use AP_Param::set_frame_type_flags() to
|
|
|
|
// enable parameters flagged in this way. frame type flags are stored
|
|
|
|
// in flags field, shifted by AP_PARAM_FRAME_TYPE_SHIFT.
|
2022-12-29 22:14:05 -04:00
|
|
|
#define AP_PARAM_FRAME_TYPE_SHIFT 8
|
2017-02-07 19:45:20 -04:00
|
|
|
|
|
|
|
// supported frame types for parameters
|
|
|
|
#define AP_PARAM_FRAME_COPTER (1<<0)
|
|
|
|
#define AP_PARAM_FRAME_ROVER (1<<1)
|
|
|
|
#define AP_PARAM_FRAME_PLANE (1<<2)
|
|
|
|
#define AP_PARAM_FRAME_SUB (1<<3)
|
|
|
|
#define AP_PARAM_FRAME_TRICOPTER (1<<4)
|
|
|
|
#define AP_PARAM_FRAME_HELI (1<<5)
|
2021-03-18 00:12:54 -03:00
|
|
|
#define AP_PARAM_FRAME_BLIMP (1<<6)
|
2017-02-07 19:45:20 -04:00
|
|
|
|
2012-03-11 17:30:09 -03:00
|
|
|
// a variant of offsetof() to work around C++ restrictions.
|
2012-02-11 07:51:35 -04:00
|
|
|
// this can only be used when the offset of a variable in a object
|
|
|
|
// is constant and known at compile time
|
2015-12-29 06:21:54 -04:00
|
|
|
#define AP_VAROFFSET(type, element) (((ptrdiff_t)(&((const type *)1)->element))-1)
|
2012-02-12 03:22:57 -04:00
|
|
|
|
|
|
|
// find the type of a variable given the class and element
|
2016-09-03 14:41:37 -03:00
|
|
|
#define AP_CLASSTYPE(clazz, element) ((uint8_t)(((const clazz *) 1)->element.vtype))
|
2012-02-12 03:22:57 -04:00
|
|
|
|
|
|
|
// declare a group var_info line
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_GROUPINFO_FLAGS(name, idx, clazz, element, def, flags) { name, AP_VAROFFSET(clazz, element), {def_value : def}, flags, idx, AP_CLASSTYPE(clazz, element)}
|
2015-12-29 07:43:25 -04:00
|
|
|
|
2017-02-07 19:45:20 -04:00
|
|
|
// declare a group var_info line with a frame type mask
|
|
|
|
#define AP_GROUPINFO_FRAME(name, idx, clazz, element, def, frame_flags) AP_GROUPINFO_FLAGS(name, idx, clazz, element, def, (frame_flags)<<AP_PARAM_FRAME_TYPE_SHIFT )
|
|
|
|
|
|
|
|
// declare a group var_info line with both flags and frame type mask
|
|
|
|
#define AP_GROUPINFO_FLAGS_FRAME(name, idx, clazz, element, def, flags, frame_flags) AP_GROUPINFO_FLAGS(name, idx, clazz, element, def, flags|((frame_flags)<<AP_PARAM_FRAME_TYPE_SHIFT) )
|
|
|
|
|
2022-12-29 22:14:05 -04:00
|
|
|
// declare a group var_info line with a default "pointer"
|
|
|
|
#define AP_GROUPINFO_FLAGS_DEFAULT_POINTER(name, idx, clazz, element, def) { name, AP_VAROFFSET(clazz, element), {def_value_offset : AP_VAROFFSET(clazz, element) - AP_VAROFFSET(clazz, def)}, AP_PARAM_FLAG_DEFAULT_POINTER, idx, AP_CLASSTYPE(clazz, element) }
|
|
|
|
|
2015-12-29 07:43:25 -04:00
|
|
|
// declare a group var_info line
|
2016-09-03 14:41:37 -03:00
|
|
|
#define AP_GROUPINFO(name, idx, clazz, element, def) AP_GROUPINFO_FLAGS(name, idx, clazz, element, def, 0)
|
2012-02-12 16:43:09 -04:00
|
|
|
|
2012-02-12 03:22:57 -04:00
|
|
|
// declare a nested group entry in a group var_info
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_NESTEDGROUPINFO(clazz, idx) { "", 0, { group_info : clazz::var_info }, 0, idx, AP_PARAM_GROUP }
|
2015-12-27 16:22:32 -04:00
|
|
|
|
|
|
|
// declare a subgroup entry in a group var_info. This is for having another arbitrary object as a member of the parameter list of
|
|
|
|
// an object
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_SUBGROUPINFO(element, name, idx, thisclazz, elclazz) { name, AP_VAROFFSET(thisclazz, element), { group_info : elclazz::var_info }, AP_PARAM_FLAG_NESTED_OFFSET, idx, AP_PARAM_GROUP }
|
2012-02-12 03:22:57 -04:00
|
|
|
|
2017-04-12 03:27:46 -03:00
|
|
|
// declare a second parameter table for the same object
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_SUBGROUPEXTENSION(name, idx, clazz, vinfo) { name, 0, { group_info : clazz::vinfo }, AP_PARAM_FLAG_NESTED_OFFSET, idx, AP_PARAM_GROUP }
|
2017-04-12 03:27:46 -03:00
|
|
|
|
2015-12-29 06:21:54 -04:00
|
|
|
// declare a pointer subgroup entry in a group var_info
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_SUBGROUPPTR(element, name, idx, thisclazz, elclazz) { name, AP_VAROFFSET(thisclazz, element), { group_info : elclazz::var_info }, AP_PARAM_FLAG_POINTER, idx, AP_PARAM_GROUP }
|
2015-12-29 06:21:54 -04:00
|
|
|
|
2017-02-27 02:39:12 -04:00
|
|
|
// declare a pointer subgroup entry in a group var_info with a pointer var_info
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_SUBGROUPVARPTR(element, name, idx, thisclazz, var_info) { name, AP_VAROFFSET(thisclazz, element), { group_info_ptr : &var_info }, AP_PARAM_FLAG_POINTER | AP_PARAM_FLAG_INFO_POINTER, idx, AP_PARAM_GROUP }
|
2017-02-27 02:39:12 -04:00
|
|
|
|
2023-01-03 21:39:14 -04:00
|
|
|
#define AP_GROUPEND { "", 0, { group_info : nullptr }, 0, 0xFF, AP_PARAM_NONE }
|
2023-01-10 08:29:54 -04:00
|
|
|
|
|
|
|
// Vehicle defines for info struct
|
|
|
|
#define GSCALAR(v, name, def) { name, &AP_PARAM_VEHICLE_NAME.g.v, {def_value : def}, 0, Parameters::k_param_ ## v, AP_PARAM_VEHICLE_NAME.g.v.vtype }
|
|
|
|
#define GARRAY(v, index, name, def) { name, &AP_PARAM_VEHICLE_NAME.g.v[index], {def_value : def}, 0, Parameters::k_param_ ## v ## index, AP_PARAM_VEHICLE_NAME.g.v[index].vtype }
|
|
|
|
#define ASCALAR(v, name, def) { name, (const void *)&AP_PARAM_VEHICLE_NAME.aparm.v, {def_value : def}, 0, Parameters::k_param_ ## v, AP_PARAM_VEHICLE_NAME.aparm.v.vtype }
|
|
|
|
#define GGROUP(v, name, class) { name, &AP_PARAM_VEHICLE_NAME.g.v, {group_info : class::var_info}, 0, Parameters::k_param_ ## v, AP_PARAM_GROUP }
|
|
|
|
#define GOBJECT(v, name, class) { name, (const void *)&AP_PARAM_VEHICLE_NAME.v, {group_info : class::var_info}, 0, Parameters::k_param_ ## v, AP_PARAM_GROUP }
|
|
|
|
#define GOBJECTPTR(v, name, class) { name, (const void *)&AP_PARAM_VEHICLE_NAME.v, {group_info : class::var_info}, AP_PARAM_FLAG_POINTER, Parameters::k_param_ ## v, AP_PARAM_GROUP }
|
|
|
|
#define GOBJECTVARPTR(v, name, var_info_ptr) { name, (const void *)&AP_PARAM_VEHICLE_NAME.v, {group_info_ptr : var_info_ptr}, AP_PARAM_FLAG_POINTER | AP_PARAM_FLAG_INFO_POINTER, Parameters::k_param_ ## v, AP_PARAM_GROUP }
|
|
|
|
#define GOBJECTN(v, pname, name, class) { name, (const void *)&AP_PARAM_VEHICLE_NAME.v, {group_info : class::var_info}, 0, Parameters::k_param_ ## pname, AP_PARAM_GROUP }
|
|
|
|
#define PARAM_VEHICLE_INFO { "", (const void *)&AP_PARAM_VEHICLE_NAME, {group_info : AP_Vehicle::var_info}, 0, Parameters::k_param_vehicle, AP_PARAM_GROUP }
|
|
|
|
#define AP_VAREND { "", nullptr, {group_info : nullptr }, 0, 0, AP_PARAM_NONE }
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
enum ap_var_type {
|
|
|
|
AP_PARAM_NONE = 0,
|
|
|
|
AP_PARAM_INT8,
|
|
|
|
AP_PARAM_INT16,
|
|
|
|
AP_PARAM_INT32,
|
|
|
|
AP_PARAM_FLOAT,
|
|
|
|
AP_PARAM_VECTOR3F,
|
|
|
|
AP_PARAM_GROUP
|
|
|
|
};
|
|
|
|
|
2015-12-27 16:22:32 -04:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Base class for variables.
|
|
|
|
///
|
|
|
|
/// Provides naming and lookup services for variables.
|
|
|
|
///
|
|
|
|
class AP_Param
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// the Info and GroupInfo structures are passed by the main
|
|
|
|
// program in setup() to give information on how variables are
|
|
|
|
// named and their location in memory
|
|
|
|
struct GroupInfo {
|
2016-03-17 23:03:18 -03:00
|
|
|
const char *name;
|
2015-12-29 06:21:54 -04:00
|
|
|
ptrdiff_t offset; // offset within the object
|
2012-08-06 22:00:43 -03:00
|
|
|
union {
|
|
|
|
const struct GroupInfo *group_info;
|
2017-02-27 02:39:12 -04:00
|
|
|
const struct GroupInfo **group_info_ptr; // when AP_PARAM_FLAG_INFO_POINTER is set in flags
|
2012-08-06 22:00:43 -03:00
|
|
|
const float def_value;
|
2022-12-29 22:14:05 -04:00
|
|
|
ptrdiff_t def_value_offset; // Default value offset from param object, when AP_PARAM_FLAG_DEFAULT_POINTER is set in flags
|
2012-08-06 22:00:43 -03:00
|
|
|
};
|
2017-02-07 19:45:20 -04:00
|
|
|
uint16_t flags;
|
2023-01-03 21:39:14 -04:00
|
|
|
uint8_t idx; // identifier within the group
|
|
|
|
uint8_t type; // AP_PARAM_*
|
2012-02-11 07:51:35 -04:00
|
|
|
};
|
|
|
|
struct Info {
|
2016-03-17 23:03:18 -03:00
|
|
|
const char *name;
|
2015-05-13 07:04:19 -03:00
|
|
|
const void *ptr; // pointer to the variable in memory
|
2012-08-06 22:00:43 -03:00
|
|
|
union {
|
|
|
|
const struct GroupInfo *group_info;
|
2017-02-27 02:39:12 -04:00
|
|
|
const struct GroupInfo **group_info_ptr; // when AP_PARAM_FLAG_INFO_POINTER is set in flags
|
2012-08-06 22:00:43 -03:00
|
|
|
const float def_value;
|
2022-12-29 22:14:05 -04:00
|
|
|
ptrdiff_t def_value_offset; // Default value offset from param object, when AP_PARAM_FLAG_DEFAULT_POINTER is set in flags
|
2012-08-06 22:00:43 -03:00
|
|
|
};
|
2017-02-07 19:45:20 -04:00
|
|
|
uint16_t flags;
|
2023-01-03 21:39:14 -04:00
|
|
|
uint16_t key; // k_param_*
|
|
|
|
uint8_t type; // AP_PARAM_*
|
2012-02-11 07:51:35 -04:00
|
|
|
};
|
2013-05-30 08:45:25 -03:00
|
|
|
struct ConversionInfo {
|
2015-12-30 17:27:22 -04:00
|
|
|
uint16_t old_key; // k_param_*
|
2017-01-10 02:48:36 -04:00
|
|
|
uint32_t old_group_element; // index in old object
|
2013-05-30 08:45:25 -03:00
|
|
|
enum ap_var_type type; // AP_PARAM_*
|
2016-03-17 23:03:18 -03:00
|
|
|
const char *new_name;
|
2013-05-30 08:45:25 -03:00
|
|
|
};
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2018-11-28 20:54:15 -04:00
|
|
|
// param default table element
|
|
|
|
struct defaults_table_struct {
|
|
|
|
const char *name; // parameter name
|
|
|
|
float value; // parameter value
|
|
|
|
};
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
// called once at startup to setup the _var_info[] table. This
|
|
|
|
// will also check the EEPROM header and re-initialise it if the
|
|
|
|
// wrong version is found
|
2012-12-13 18:58:23 -04:00
|
|
|
static bool setup();
|
|
|
|
|
|
|
|
// constructor with var_info
|
2014-08-13 01:43:19 -03:00
|
|
|
AP_Param(const struct Info *info)
|
|
|
|
{
|
2012-12-13 18:58:23 -04:00
|
|
|
_var_info = info;
|
|
|
|
uint16_t i;
|
2015-12-27 16:22:32 -04:00
|
|
|
for (i=0; info[i].type != AP_PARAM_NONE; i++) ;
|
2012-12-13 18:58:23 -04:00
|
|
|
_num_vars = i;
|
2022-01-07 01:25:38 -04:00
|
|
|
#if AP_PARAM_DYNAMIC_ENABLED
|
|
|
|
_num_vars_base = _num_vars;
|
|
|
|
#endif
|
2019-11-25 12:21:31 -04:00
|
|
|
if (_singleton != nullptr) {
|
|
|
|
AP_HAL::panic("AP_Param must be singleton");
|
|
|
|
}
|
|
|
|
_singleton = this;
|
2012-12-13 18:58:23 -04:00
|
|
|
}
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2012-12-12 17:40:42 -04:00
|
|
|
// empty constructor
|
|
|
|
AP_Param() {}
|
2012-08-06 22:00:43 -03:00
|
|
|
|
|
|
|
// a token used for first()/next() state
|
|
|
|
typedef struct {
|
2015-12-30 17:27:22 -04:00
|
|
|
uint32_t key : 9;
|
2021-01-21 01:57:19 -04:00
|
|
|
uint32_t idx : 4; // offset into array types
|
2012-08-17 03:17:46 -03:00
|
|
|
uint32_t group_element : 18;
|
2021-01-21 01:57:19 -04:00
|
|
|
uint32_t last_disabled : 1;
|
2012-08-06 22:00:43 -03:00
|
|
|
} ParamToken;
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2016-02-15 03:37:40 -04:00
|
|
|
// nesting structure for recursive call states
|
|
|
|
struct GroupNesting {
|
|
|
|
static const uint8_t numlevels = 2;
|
|
|
|
uint8_t level;
|
|
|
|
const struct GroupInfo *group_ret[numlevels];
|
|
|
|
};
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2012-02-17 00:12:48 -04:00
|
|
|
// return true if AP_Param has been initialised via setup()
|
|
|
|
static bool initialised(void);
|
|
|
|
|
2016-02-15 03:37:40 -04:00
|
|
|
// the 'group_id' of a element of a group is the 18 bit identifier
|
|
|
|
// used to distinguish between this element of the group and other
|
|
|
|
// elements of the same group. It is calculated using a bit shift per
|
|
|
|
// level of nesting, so the first level of nesting gets 6 bits the 2nd
|
|
|
|
// level gets the next 6 bits, and the 3rd level gets the last 6
|
|
|
|
// bits. This limits groups to having at most 64 elements.
|
2016-10-22 04:10:11 -03:00
|
|
|
static uint32_t group_id(const struct GroupInfo *grpinfo, uint32_t base, uint8_t i, uint8_t shift);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2012-08-17 03:17:46 -03:00
|
|
|
/// Copy the variable's name, prefixed by any containing group name, to a
|
|
|
|
/// buffer.
|
2012-02-11 07:51:35 -04:00
|
|
|
///
|
|
|
|
/// If the variable has no name, the buffer will contain an empty string.
|
|
|
|
///
|
|
|
|
/// Note that if the combination of names is larger than the buffer, the
|
|
|
|
/// result in the buffer will be truncated.
|
|
|
|
///
|
2013-01-08 18:45:02 -04:00
|
|
|
/// @param token token giving current variable
|
2012-02-11 07:51:35 -04:00
|
|
|
/// @param buffer The destination buffer
|
|
|
|
/// @param bufferSize Total size of the destination buffer.
|
|
|
|
///
|
2015-12-27 16:22:32 -04:00
|
|
|
void copy_name_info(const struct AP_Param::Info *info,
|
|
|
|
const struct GroupInfo *ginfo,
|
2016-02-15 03:37:40 -04:00
|
|
|
const struct GroupNesting &group_nesting,
|
2015-12-27 16:22:32 -04:00
|
|
|
uint8_t idx, char *buffer, size_t bufferSize, bool force_scalar=false) const;
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2015-10-06 19:08:59 -03:00
|
|
|
/// Copy the variable's name, prefixed by any containing group name, to a
|
|
|
|
/// buffer.
|
|
|
|
///
|
|
|
|
/// Uses token to look up AP_Param::Info for the variable
|
2013-04-19 04:46:40 -03:00
|
|
|
void copy_name_token(const ParamToken &token, char *buffer, size_t bufferSize, bool force_scalar=false) const;
|
2013-01-08 00:28:16 -04:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Find a variable by name.
|
|
|
|
///
|
|
|
|
/// If the variable has no name, it cannot be found by this interface.
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
2019-06-11 01:50:33 -03:00
|
|
|
/// @param flags If non-null will be filled with parameter flags
|
2016-10-30 02:24:21 -03:00
|
|
|
/// @return A pointer to the variable, or nullptr if
|
2012-02-11 07:51:35 -04:00
|
|
|
/// it does not exist.
|
|
|
|
///
|
2019-06-11 01:50:33 -03:00
|
|
|
static AP_Param * find(const char *name, enum ap_var_type *ptype, uint16_t *flags = nullptr);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2016-04-01 02:39:51 -03:00
|
|
|
/// set a default value by name
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
|
|
|
/// @param value The default value
|
|
|
|
/// @return true if the variable is found
|
|
|
|
static bool set_default_by_name(const char *name, float value);
|
2018-11-28 20:54:15 -04:00
|
|
|
|
|
|
|
/// set parameter defaults from a defaults_table_struct
|
|
|
|
///
|
|
|
|
/// @param table pointer to array of defaults_table_struct structures
|
|
|
|
/// @param count number of elements in table array
|
|
|
|
static void set_defaults_from_table(const struct defaults_table_struct *table, uint8_t count);
|
|
|
|
|
2017-10-20 15:10:09 -03:00
|
|
|
/// set a value by name
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
|
|
|
/// @param value The new value
|
|
|
|
/// @return true if the variable is found
|
|
|
|
static bool set_by_name(const char *name, float value);
|
2019-11-25 12:21:57 -04:00
|
|
|
|
|
|
|
/// gat a value by name, used by scripting
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
2020-08-10 01:48:03 -03:00
|
|
|
/// @param value A reference to the variable
|
2019-11-25 12:21:57 -04:00
|
|
|
/// @return true if the variable is found
|
|
|
|
static bool get(const char *name, float &value);
|
2017-10-20 15:10:09 -03:00
|
|
|
|
|
|
|
/// set and save a value by name
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
|
|
|
/// @param value The new value
|
|
|
|
/// @return true if the variable is found
|
|
|
|
static bool set_and_save_by_name(const char *name, float value);
|
2021-04-07 22:11:13 -03:00
|
|
|
static bool set_and_save_by_name_ifchanged(const char *name, float value);
|
2017-10-20 15:10:09 -03:00
|
|
|
|
2012-09-19 18:42:35 -03:00
|
|
|
/// Find a variable by index.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// @param idx The index of the variable
|
2016-10-30 02:24:21 -03:00
|
|
|
/// @return A pointer to the variable, or nullptr if
|
2012-09-19 18:42:35 -03:00
|
|
|
/// it does not exist.
|
|
|
|
///
|
2013-01-08 18:45:02 -04:00
|
|
|
static AP_Param * find_by_index(uint16_t idx, enum ap_var_type *ptype, ParamToken *token);
|
2012-09-19 18:42:35 -03:00
|
|
|
|
2020-05-10 11:04:03 -03:00
|
|
|
// by-name equivalent of find_by_index()
|
|
|
|
static AP_Param* find_by_name(const char* name, enum ap_var_type *ptype, ParamToken *token);
|
|
|
|
|
2015-12-29 06:21:54 -04:00
|
|
|
/// Find a variable by pointer
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// @param p Pointer to variable
|
2016-04-01 02:16:03 -03:00
|
|
|
/// @return key for variable
|
|
|
|
static bool find_key_by_pointer_group(const void *ptr, uint16_t vindex, const struct GroupInfo *group_info,
|
|
|
|
ptrdiff_t offset, uint16_t &key);
|
|
|
|
static bool find_key_by_pointer(const void *ptr, uint16_t &key);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2019-12-24 03:21:37 -04:00
|
|
|
/// Find key of top level group variable by pointer
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// @param p Pointer to variable
|
|
|
|
/// @return key for variable
|
|
|
|
static bool find_top_level_key_by_pointer(const void *ptr, uint16_t &key);
|
|
|
|
|
|
|
|
|
2012-12-13 18:58:23 -04:00
|
|
|
/// Find a object in the top level var_info table
|
|
|
|
///
|
|
|
|
/// If the variable has no name, it cannot be found by this interface.
|
|
|
|
///
|
|
|
|
/// @param name The full name of the variable to be found.
|
|
|
|
///
|
|
|
|
static AP_Param * find_object(const char *name);
|
|
|
|
|
2015-10-06 19:08:59 -03:00
|
|
|
/// Notify GCS of current parameter value
|
|
|
|
///
|
|
|
|
void notify() const;
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2018-08-06 01:43:30 -03:00
|
|
|
/// Save the current value of the variable to storage, synchronous API
|
2012-02-11 07:51:35 -04:00
|
|
|
///
|
2013-06-02 01:48:36 -03:00
|
|
|
/// @param force_save If true then force save even if default
|
|
|
|
///
|
2012-02-11 07:51:35 -04:00
|
|
|
/// @return True if the variable was saved successfully.
|
|
|
|
///
|
2021-04-08 02:35:54 -03:00
|
|
|
void save_sync(bool force_save, bool send_to_gcs);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2018-08-06 01:43:30 -03:00
|
|
|
/// flush all pending parameter saves
|
|
|
|
/// used on reboot
|
|
|
|
static void flush(void);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2018-08-06 01:43:30 -03:00
|
|
|
/// Save the current value of the variable to storage, async interface
|
|
|
|
///
|
|
|
|
/// @param force_save If true then force save even if default
|
|
|
|
///
|
|
|
|
void save(bool force_save=false);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Load the variable from EEPROM.
|
|
|
|
///
|
|
|
|
/// @return True if the variable was loaded successfully.
|
|
|
|
///
|
|
|
|
bool load(void);
|
|
|
|
|
|
|
|
/// Load all variables from EEPROM
|
|
|
|
///
|
|
|
|
/// This function performs a best-efforts attempt to load all
|
|
|
|
/// of the variables from EEPROM. If some fail to load, their
|
|
|
|
/// values will remain as they are.
|
|
|
|
///
|
|
|
|
/// @return False if any variable failed to load
|
|
|
|
///
|
2018-06-14 17:03:41 -03:00
|
|
|
static bool load_all();
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2019-08-27 00:30:51 -03:00
|
|
|
// returns storage space used:
|
|
|
|
static uint16_t storage_used() { return sentinal_offset; }
|
|
|
|
|
|
|
|
// returns storage space :
|
|
|
|
static uint16_t storage_size() { return _storage.size(); }
|
|
|
|
|
2017-01-09 05:52:36 -04:00
|
|
|
/// reoad the hal.util defaults file. Called after pointer parameters have been allocated
|
|
|
|
///
|
2018-06-26 12:54:36 -03:00
|
|
|
static void reload_defaults_file(bool last_pass);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2015-12-29 06:21:54 -04:00
|
|
|
static void load_object_from_eeprom(const void *object_pointer, const struct GroupInfo *group_info);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2012-08-17 03:17:46 -03:00
|
|
|
// set a AP_Param variable to a specified value
|
|
|
|
static void set_value(enum ap_var_type type, void *ptr, float def_value);
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2015-04-01 19:54:13 -03:00
|
|
|
/*
|
2015-08-10 04:25:29 -03:00
|
|
|
set a parameter to a float
|
2015-04-01 19:54:13 -03:00
|
|
|
*/
|
2015-08-10 04:25:29 -03:00
|
|
|
void set_float(float value, enum ap_var_type var_type);
|
2015-04-01 19:54:13 -03:00
|
|
|
|
2012-08-06 22:00:43 -03:00
|
|
|
// load default values for scalars in a group
|
2012-12-12 17:40:42 -04:00
|
|
|
static void setup_object_defaults(const void *object_pointer, const struct GroupInfo *group_info);
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2016-10-04 05:07:21 -03:00
|
|
|
// set a value directly in an object.
|
|
|
|
// return true if the name was found and set, else false.
|
|
|
|
// This should only be used by example code, not by mainline vehicle code
|
|
|
|
static bool set_object_value(const void *object_pointer,
|
|
|
|
const struct GroupInfo *group_info,
|
2014-07-20 20:37:41 -03:00
|
|
|
const char *name, float value);
|
|
|
|
|
2012-12-12 17:40:42 -04:00
|
|
|
// load default values for all scalars in the main sketch. This
|
|
|
|
// does not recurse into the sub-objects
|
2012-12-13 18:58:23 -04:00
|
|
|
static void setup_sketch_defaults(void);
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2016-12-30 19:49:43 -04:00
|
|
|
// find an old parameter and return it.
|
|
|
|
static bool find_old_parameter(const struct ConversionInfo *info, AP_Param *value);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2013-05-30 08:45:25 -03:00
|
|
|
// convert old vehicle parameters to new object parameters
|
2017-01-10 02:07:53 -04:00
|
|
|
static void convert_old_parameters(const struct ConversionInfo *conversion_table, uint8_t table_size, uint8_t flags=0);
|
2023-12-13 17:51:31 -04:00
|
|
|
// convert old vehicle parameters to new object parameters with scaling - assumes we use the same scaling factor for all values in the table
|
|
|
|
static void convert_old_parameters_scaled(const ConversionInfo *conversion_table, uint8_t table_size, float scaler, uint8_t flags);
|
2013-05-30 08:45:25 -03:00
|
|
|
|
2020-01-13 00:40:03 -04:00
|
|
|
/*
|
|
|
|
convert width of a parameter, allowing update to wider scalar
|
|
|
|
values without changing the parameter indexes. This will return
|
|
|
|
true if the parameter was converted from an old parameter value
|
|
|
|
*/
|
2023-12-13 17:51:31 -04:00
|
|
|
bool convert_parameter_width(ap_var_type old_ptype, float scale_factor=1.0);
|
|
|
|
bool convert_centi_parameter(ap_var_type old_ptype) {
|
|
|
|
return convert_parameter_width(old_ptype, 0.01f);
|
|
|
|
}
|
2020-01-13 00:40:03 -04:00
|
|
|
|
2016-02-16 22:29:47 -04:00
|
|
|
// convert a single parameter with scaling
|
2017-01-10 02:07:53 -04:00
|
|
|
enum {
|
|
|
|
CONVERT_FLAG_REVERSE=1, // handle _REV -> _REVERSED conversion
|
|
|
|
CONVERT_FLAG_FORCE=2 // store new value even if configured in eeprom already
|
|
|
|
};
|
|
|
|
static void convert_old_parameter(const struct ConversionInfo *info, float scaler, uint8_t flags=0);
|
2016-02-16 22:29:47 -04:00
|
|
|
|
2021-10-08 05:15:10 -03:00
|
|
|
// move all parameters from a class to a new location
|
|
|
|
// is_top_level: Is true if the class had its own top level key, param_key. It is false if the class was a subgroup
|
|
|
|
static void convert_class(uint16_t param_key, void *object_pointer,
|
|
|
|
const struct AP_Param::GroupInfo *group_info,
|
|
|
|
uint16_t old_index, uint16_t old_top_element, bool is_top_level);
|
|
|
|
|
2021-02-27 05:53:34 -04:00
|
|
|
/*
|
|
|
|
fetch a parameter value based on the index within a group. This
|
|
|
|
is used to find the old value of a parameter that has been
|
|
|
|
removed from an object.
|
|
|
|
*/
|
|
|
|
static bool get_param_by_index(void *obj_ptr, uint8_t idx, ap_var_type old_ptype, void *pvalue);
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Erase all variables in EEPROM.
|
|
|
|
///
|
2012-08-17 03:17:46 -03:00
|
|
|
static void erase_all(void);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2012-02-12 03:22:57 -04:00
|
|
|
/// Returns the first variable
|
|
|
|
///
|
2016-10-30 02:24:21 -03:00
|
|
|
/// @return The first variable in _var_info, or nullptr if
|
2012-02-12 03:22:57 -04:00
|
|
|
/// there are none.
|
|
|
|
///
|
2022-06-13 13:04:41 -03:00
|
|
|
static AP_Param * first(ParamToken *token, enum ap_var_type *ptype, float *default_val = nullptr);
|
2012-02-12 03:22:57 -04:00
|
|
|
|
|
|
|
/// Returns the next variable in _var_info, recursing into groups
|
|
|
|
/// as needed
|
2022-06-13 13:04:41 -03:00
|
|
|
static AP_Param * next(ParamToken *token, enum ap_var_type *ptype) { return next(token, ptype, false); }
|
|
|
|
static AP_Param * next(ParamToken *token, enum ap_var_type *ptype, bool skip_disabled, float *default_val = nullptr);
|
2012-02-12 03:22:57 -04:00
|
|
|
|
|
|
|
/// Returns the next scalar variable in _var_info, recursing into groups
|
|
|
|
/// as needed
|
2022-06-13 13:04:41 -03:00
|
|
|
static AP_Param * next_scalar(ParamToken *token, enum ap_var_type *ptype, float *default_val = nullptr);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2020-03-21 02:08:21 -03:00
|
|
|
/// get the size of a type in bytes
|
|
|
|
static uint8_t type_size(enum ap_var_type type);
|
|
|
|
|
2012-02-12 04:18:58 -04:00
|
|
|
/// cast a variable to a float given its type
|
2013-04-19 04:46:40 -03:00
|
|
|
float cast_to_float(enum ap_var_type type) const;
|
2012-02-12 04:18:58 -04:00
|
|
|
|
2014-01-30 22:07:41 -04:00
|
|
|
// check var table for consistency
|
2023-01-06 01:12:24 -04:00
|
|
|
static void check_var_info(void);
|
2014-01-30 22:07:41 -04:00
|
|
|
|
2015-10-21 23:57:05 -03:00
|
|
|
// return true if the parameter is configured
|
2019-08-19 07:05:33 -03:00
|
|
|
bool configured(void) const;
|
2015-10-21 23:57:05 -03:00
|
|
|
|
2019-08-19 07:05:33 -03:00
|
|
|
// return true if the parameter is read-only
|
|
|
|
bool is_read_only(void) const;
|
2020-05-10 11:04:03 -03:00
|
|
|
|
|
|
|
// return the persistent top level key for the ParamToken key
|
2022-01-07 01:25:38 -04:00
|
|
|
static uint16_t get_persistent_key(uint16_t key) { return var_info(key).key; }
|
2019-08-19 07:05:33 -03:00
|
|
|
|
2016-01-05 23:41:07 -04:00
|
|
|
// count of parameters in tree
|
|
|
|
static uint16_t count_parameters(void);
|
2016-10-25 18:32:10 -03:00
|
|
|
|
2020-04-18 19:36:37 -03:00
|
|
|
// invalidate parameter count
|
|
|
|
static void invalidate_count(void);
|
|
|
|
|
2016-10-25 18:32:10 -03:00
|
|
|
static void set_hide_disabled_groups(bool value) { _hide_disabled_groups = value; }
|
|
|
|
|
2017-02-07 19:45:20 -04:00
|
|
|
// set frame type flags. Used to unhide frame specific parameters
|
|
|
|
static void set_frame_type_flags(uint16_t flags_to_set) {
|
2020-04-18 20:24:54 -03:00
|
|
|
invalidate_count();
|
2017-02-07 19:45:20 -04:00
|
|
|
_frame_type_flags |= flags_to_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if a given frame type should be included
|
|
|
|
static bool check_frame_type(uint16_t flags);
|
2018-01-24 00:42:09 -04:00
|
|
|
|
|
|
|
#if AP_PARAM_KEY_DUMP
|
|
|
|
/// print the value of all variables
|
|
|
|
static void show_all(AP_HAL::BetterStream *port, bool showKeyValues=false);
|
|
|
|
|
|
|
|
/// print the value of one variable
|
|
|
|
static void show(const AP_Param *param,
|
|
|
|
const char *name,
|
|
|
|
enum ap_var_type ptype,
|
|
|
|
AP_HAL::BetterStream *port);
|
|
|
|
|
|
|
|
/// print the value of one variable
|
|
|
|
static void show(const AP_Param *param,
|
|
|
|
const ParamToken &token,
|
|
|
|
enum ap_var_type ptype,
|
|
|
|
AP_HAL::BetterStream *port);
|
|
|
|
#endif // AP_PARAM_KEY_DUMP
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2019-11-25 12:21:31 -04:00
|
|
|
static AP_Param *get_singleton() { return _singleton; }
|
|
|
|
|
2022-01-07 01:25:38 -04:00
|
|
|
#if AP_PARAM_DYNAMIC_ENABLED
|
|
|
|
// allow for dynamically added parameter tables from scripts
|
|
|
|
static bool add_table(uint8_t key, const char *prefix, uint8_t num_params);
|
|
|
|
static bool add_param(uint8_t key, uint8_t param_num, const char *pname, float default_value);
|
|
|
|
static bool load_int32(uint16_t key, uint32_t group_element, int32_t &value);
|
|
|
|
#endif
|
2022-06-13 13:04:41 -03:00
|
|
|
|
2022-09-13 06:26:41 -03:00
|
|
|
static bool load_defaults_file(const char *filename, bool last_pass);
|
|
|
|
|
2022-06-13 13:04:41 -03:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// store default value in linked list
|
2022-12-29 22:19:56 -04:00
|
|
|
static void add_default(AP_Param *ap, float v);
|
2022-06-13 13:04:41 -03:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
private:
|
2019-11-25 12:21:31 -04:00
|
|
|
static AP_Param *_singleton;
|
|
|
|
|
2012-02-12 03:22:57 -04:00
|
|
|
/// EEPROM header
|
|
|
|
///
|
|
|
|
/// This structure is placed at the head of the EEPROM to indicate
|
|
|
|
/// that the ROM is formatted for AP_Param.
|
|
|
|
///
|
|
|
|
struct EEPROM_header {
|
2012-08-17 03:17:46 -03:00
|
|
|
uint8_t magic[2];
|
|
|
|
uint8_t revision;
|
|
|
|
uint8_t spare;
|
2012-02-12 03:22:57 -04:00
|
|
|
};
|
2020-03-02 00:56:27 -04:00
|
|
|
static_assert(sizeof(struct EEPROM_header) == 4, "Bad EEPROM_header size!");
|
2012-02-12 03:22:57 -04:00
|
|
|
|
2019-08-27 00:30:51 -03:00
|
|
|
static uint16_t sentinal_offset;
|
|
|
|
|
2012-07-10 01:03:34 -03:00
|
|
|
/* This header is prepended to a variable stored in EEPROM.
|
2012-08-17 03:17:46 -03:00
|
|
|
* The meaning is as follows:
|
|
|
|
*
|
|
|
|
* - key: the k_param enum value from Parameter.h in the sketch
|
|
|
|
*
|
|
|
|
* - group_element: This is zero for top level parameters. For
|
|
|
|
* parameters stored within an object this is divided
|
|
|
|
* into 3 lots of 6 bits, allowing for three levels
|
|
|
|
* of object to be stored in the eeprom
|
|
|
|
*
|
|
|
|
* - type: the ap_var_type value for the variable
|
|
|
|
*/
|
2012-02-12 03:22:57 -04:00
|
|
|
struct Param_header {
|
2015-12-30 17:27:22 -04:00
|
|
|
// to get 9 bits for key we needed to split it into two parts to keep binary compatibility
|
|
|
|
uint32_t key_low : 8;
|
|
|
|
uint32_t type : 5;
|
|
|
|
uint32_t key_high : 1;
|
2012-08-17 03:17:46 -03:00
|
|
|
uint32_t group_element : 18;
|
2012-02-12 03:22:57 -04:00
|
|
|
};
|
2020-03-02 00:56:27 -04:00
|
|
|
static_assert(sizeof(struct Param_header) == 4, "Bad Param_header size!");
|
2012-02-12 03:22:57 -04:00
|
|
|
|
|
|
|
// number of bits in each level of nesting of groups
|
2012-08-17 03:17:46 -03:00
|
|
|
static const uint8_t _group_level_shift = 6;
|
|
|
|
static const uint8_t _group_bits = 18;
|
|
|
|
|
2015-12-30 17:27:22 -04:00
|
|
|
static const uint16_t _sentinal_key = 0x1FF;
|
|
|
|
static const uint8_t _sentinal_type = 0x1F;
|
2012-08-17 03:17:46 -03:00
|
|
|
static const uint8_t _sentinal_group = 0xFF;
|
|
|
|
|
2017-02-07 19:45:20 -04:00
|
|
|
static uint16_t _frame_type_flags;
|
|
|
|
|
2017-11-09 02:45:58 -04:00
|
|
|
/*
|
|
|
|
structure for built-in defaults file that can be modified using apj_tool.py
|
|
|
|
*/
|
2019-05-26 22:32:42 -03:00
|
|
|
#if AP_PARAM_MAX_EMBEDDED_PARAM > 0
|
2017-11-09 02:45:58 -04:00
|
|
|
struct PACKED param_defaults_struct {
|
|
|
|
char magic_str[8];
|
|
|
|
uint8_t param_magic[8];
|
|
|
|
uint16_t max_length;
|
|
|
|
volatile uint16_t length;
|
|
|
|
volatile char data[AP_PARAM_MAX_EMBEDDED_PARAM];
|
|
|
|
};
|
|
|
|
static const param_defaults_struct param_defaults_data;
|
2019-05-26 22:32:42 -03:00
|
|
|
#endif
|
2018-11-28 20:54:32 -04:00
|
|
|
|
|
|
|
|
2023-01-06 01:12:24 -04:00
|
|
|
static void check_group_info(const struct GroupInfo *group_info, uint16_t *total_size,
|
2014-11-09 17:09:08 -04:00
|
|
|
uint8_t max_bits, uint8_t prefix_length);
|
2015-12-30 17:27:22 -04:00
|
|
|
static bool duplicate_key(uint16_t vindex, uint16_t key);
|
2015-12-29 06:21:54 -04:00
|
|
|
|
2015-12-30 17:27:22 -04:00
|
|
|
static bool adjust_group_offset(uint16_t vindex, const struct GroupInfo &group_info, ptrdiff_t &new_offset);
|
2016-04-01 02:16:03 -03:00
|
|
|
static bool get_base(const struct Info &info, ptrdiff_t &base);
|
2015-12-29 06:21:54 -04:00
|
|
|
|
2017-02-27 02:39:12 -04:00
|
|
|
/// get group_info pointer based on flags
|
|
|
|
static const struct GroupInfo *get_group_info(const struct GroupInfo &ginfo);
|
|
|
|
|
|
|
|
/// get group_info pointer based on flags
|
|
|
|
static const struct GroupInfo *get_group_info(const struct Info &ginfo);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct Info * find_var_info_group(
|
|
|
|
const struct GroupInfo * group_info,
|
2015-12-30 17:27:22 -04:00
|
|
|
uint16_t vindex,
|
2016-02-15 03:37:40 -04:00
|
|
|
uint32_t group_base,
|
2012-08-17 03:17:46 -03:00
|
|
|
uint8_t group_shift,
|
2015-12-29 06:21:54 -04:00
|
|
|
ptrdiff_t group_offset,
|
2012-11-05 07:08:43 -04:00
|
|
|
uint32_t * group_element,
|
2015-12-27 16:22:32 -04:00
|
|
|
const struct GroupInfo * &group_ret,
|
2016-02-15 03:37:40 -04:00
|
|
|
struct GroupNesting &group_nesting,
|
2013-04-19 04:46:40 -03:00
|
|
|
uint8_t * idx) const;
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct Info * find_var_info(
|
2012-11-05 07:08:43 -04:00
|
|
|
uint32_t * group_element,
|
2015-12-27 16:22:32 -04:00
|
|
|
const struct GroupInfo * &group_ret,
|
2016-02-15 03:37:40 -04:00
|
|
|
struct GroupNesting &group_nesting,
|
2015-10-06 19:08:59 -03:00
|
|
|
uint8_t * idx) const;
|
2013-04-19 04:46:40 -03:00
|
|
|
const struct Info * find_var_info_token(const ParamToken &token,
|
2013-01-08 00:28:16 -04:00
|
|
|
uint32_t * group_element,
|
2015-12-27 16:22:32 -04:00
|
|
|
const struct GroupInfo * &group_ret,
|
2016-02-15 03:37:40 -04:00
|
|
|
struct GroupNesting &group_nesting,
|
2013-04-19 04:46:40 -03:00
|
|
|
uint8_t * idx) const;
|
2012-08-17 03:17:46 -03:00
|
|
|
static const struct Info * find_by_header_group(
|
|
|
|
struct Param_header phdr, void **ptr,
|
2015-12-30 17:27:22 -04:00
|
|
|
uint16_t vindex,
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct GroupInfo *group_info,
|
2016-10-22 04:10:11 -03:00
|
|
|
uint32_t group_base,
|
2015-12-27 16:22:32 -04:00
|
|
|
uint8_t group_shift,
|
2015-12-29 06:21:54 -04:00
|
|
|
ptrdiff_t group_offset);
|
2012-08-17 03:17:46 -03:00
|
|
|
static const struct Info * find_by_header(
|
|
|
|
struct Param_header phdr,
|
|
|
|
void **ptr);
|
|
|
|
void add_vector3f_suffix(
|
|
|
|
char *buffer,
|
|
|
|
size_t buffer_size,
|
2013-04-19 04:46:40 -03:00
|
|
|
uint8_t idx) const;
|
2012-08-17 03:17:46 -03:00
|
|
|
static AP_Param * find_group(
|
|
|
|
const char *name,
|
2015-12-30 17:27:22 -04:00
|
|
|
uint16_t vindex,
|
2015-12-29 06:21:54 -04:00
|
|
|
ptrdiff_t group_offset,
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct GroupInfo *group_info,
|
|
|
|
enum ap_var_type *ptype);
|
|
|
|
static void write_sentinal(uint16_t ofs);
|
2015-12-30 17:27:22 -04:00
|
|
|
static uint16_t get_key(const Param_header &phdr);
|
|
|
|
static void set_key(Param_header &phdr, uint16_t key);
|
|
|
|
static bool is_sentinal(const Param_header &phrd);
|
2013-05-30 08:45:25 -03:00
|
|
|
static bool scan(
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct Param_header *phdr,
|
|
|
|
uint16_t *pofs);
|
|
|
|
static void eeprom_write_check(
|
|
|
|
const void *ptr,
|
|
|
|
uint16_t ofs,
|
|
|
|
uint8_t size);
|
|
|
|
static AP_Param * next_group(
|
2021-01-21 01:57:19 -04:00
|
|
|
const uint16_t vindex,
|
2012-08-17 03:17:46 -03:00
|
|
|
const struct GroupInfo *group_info,
|
|
|
|
bool *found_current,
|
2021-01-21 01:57:19 -04:00
|
|
|
const uint32_t group_base,
|
|
|
|
const uint8_t group_shift,
|
|
|
|
const ptrdiff_t group_offset,
|
2012-08-17 03:17:46 -03:00
|
|
|
ParamToken *token,
|
2021-01-21 01:57:19 -04:00
|
|
|
enum ap_var_type *ptype,
|
2022-06-13 13:04:41 -03:00
|
|
|
bool skip_disabled,
|
|
|
|
float *default_val);
|
2012-08-17 03:17:46 -03:00
|
|
|
|
2015-04-01 22:24:45 -03:00
|
|
|
// find a default value given a pointer to a default value in flash
|
2022-12-29 22:14:05 -04:00
|
|
|
static float get_default_value(const AP_Param *object_ptr, const struct GroupInfo &info);
|
|
|
|
static float get_default_value(const AP_Param *object_ptr, const struct Info &info);
|
2015-04-01 22:24:45 -03:00
|
|
|
|
2019-08-19 07:05:33 -03:00
|
|
|
static bool parse_param_line(char *line, char **vname, float &value, bool &read_only);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2015-04-01 22:24:45 -03:00
|
|
|
/*
|
|
|
|
load a parameter defaults file. This happens as part of load_all()
|
|
|
|
*/
|
2018-06-14 17:03:41 -03:00
|
|
|
static bool count_defaults_in_file(const char *filename, uint16_t &num_defaults);
|
2024-01-17 22:35:43 -04:00
|
|
|
static bool count_param_defaults(const volatile char *ptr, int32_t length, uint16_t &count);
|
2023-08-19 18:32:34 -03:00
|
|
|
static bool read_param_defaults_file(const char *filename, bool last_pass, uint16_t &idx);
|
2017-11-09 02:45:58 -04:00
|
|
|
|
2024-01-17 22:35:43 -04:00
|
|
|
// load a defaults.parm using AP_FileSystem:
|
|
|
|
static void load_defaults_file_from_filesystem(const char *filename, bool lastpass);
|
|
|
|
// load an @ROMFS defaults.parm using ROMFS API:
|
|
|
|
static void load_defaults_file_from_romfs(const char *filename, bool lastpass);
|
|
|
|
|
|
|
|
// load defaults from supplied string:
|
|
|
|
static void load_param_defaults(const volatile char *ptr, int32_t length, bool last_pass);
|
|
|
|
|
2017-11-09 02:45:58 -04:00
|
|
|
/*
|
|
|
|
load defaults from embedded parameters
|
|
|
|
*/
|
2018-06-14 17:03:41 -03:00
|
|
|
static bool count_embedded_param_defaults(uint16_t &count);
|
2018-06-26 12:54:36 -03:00
|
|
|
static void load_embedded_param_defaults(bool last_pass);
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2022-05-17 18:09:47 -03:00
|
|
|
// return true if the parameter is configured in the defaults file
|
|
|
|
bool configured_in_defaults_file(bool &read_only) const;
|
|
|
|
|
|
|
|
// return true if the parameter is configured in EEPROM/FRAM
|
|
|
|
bool configured_in_storage(void) const;
|
|
|
|
|
2016-03-16 03:03:30 -03:00
|
|
|
// send a parameter to all GCS instances
|
|
|
|
void send_parameter(const char *name, enum ap_var_type param_header_type, uint8_t idx) const;
|
2018-11-28 20:54:32 -04:00
|
|
|
|
2014-08-13 01:43:19 -03:00
|
|
|
static StorageAccess _storage;
|
2021-01-12 19:10:27 -04:00
|
|
|
static StorageAccess _storage_bak;
|
2015-12-30 17:27:22 -04:00
|
|
|
static uint16_t _num_vars;
|
2016-01-05 23:41:07 -04:00
|
|
|
static uint16_t _parameter_count;
|
2020-04-18 20:24:54 -03:00
|
|
|
static uint16_t _count_marker;
|
|
|
|
static uint16_t _count_marker_done;
|
|
|
|
static HAL_Semaphore _count_sem;
|
2012-08-17 03:17:46 -03:00
|
|
|
static const struct Info * _var_info;
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2022-01-07 01:25:38 -04:00
|
|
|
#if AP_PARAM_DYNAMIC_ENABLED
|
|
|
|
// allow for a dynamically allocated var table
|
|
|
|
static uint16_t _num_vars_base;
|
|
|
|
static struct Info * _var_info_dynamic;
|
|
|
|
static const struct AP_Param::Info &var_info(uint16_t i) {
|
|
|
|
return i<_num_vars_base? _var_info[i] : _var_info_dynamic[i-_num_vars_base];
|
|
|
|
}
|
|
|
|
static uint8_t _dynamic_table_sizes[AP_PARAM_MAX_DYNAMIC];
|
|
|
|
#else
|
|
|
|
// simple static var table in flash
|
|
|
|
static const struct Info &var_info(uint16_t i) {
|
|
|
|
return _var_info[i];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-01 22:24:45 -03:00
|
|
|
/*
|
|
|
|
list of overridden values from load_defaults_file()
|
|
|
|
*/
|
|
|
|
struct param_override {
|
2017-01-22 06:42:54 -04:00
|
|
|
const AP_Param *object_ptr;
|
2015-04-01 22:24:45 -03:00
|
|
|
float value;
|
2019-08-19 07:05:33 -03:00
|
|
|
bool read_only; // param is marked @READONLY
|
2015-04-01 22:24:45 -03:00
|
|
|
};
|
|
|
|
static struct param_override *param_overrides;
|
|
|
|
static uint16_t num_param_overrides;
|
2023-08-19 18:32:34 -03:00
|
|
|
static uint16_t param_overrides_len;
|
2019-08-19 07:05:33 -03:00
|
|
|
static uint16_t num_read_only;
|
2015-04-01 22:24:45 -03:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
// values filled into the EEPROM header
|
2012-08-17 03:17:46 -03:00
|
|
|
static const uint8_t k_EEPROM_magic0 = 0x50;
|
|
|
|
static const uint8_t k_EEPROM_magic1 = 0x41; ///< "AP"
|
|
|
|
static const uint8_t k_EEPROM_revision = 6; ///< current format revision
|
2016-10-25 18:32:10 -03:00
|
|
|
|
|
|
|
static bool _hide_disabled_groups;
|
2018-08-06 01:43:30 -03:00
|
|
|
|
|
|
|
// support for background saving of parameters. We pack it to reduce memory for the
|
|
|
|
// queue
|
|
|
|
struct PACKED param_save {
|
|
|
|
AP_Param *param;
|
|
|
|
bool force_save;
|
|
|
|
};
|
2020-01-07 15:01:22 -04:00
|
|
|
static ObjectBuffer_TS<struct param_save> save_queue;
|
2018-08-06 01:43:30 -03:00
|
|
|
static bool registered_save_handler;
|
|
|
|
|
|
|
|
// background function for saving parameters
|
|
|
|
void save_io_handler(void);
|
2022-06-13 13:04:41 -03:00
|
|
|
|
|
|
|
// Store default values from add_default() calls in linked list
|
|
|
|
struct defaults_list {
|
|
|
|
AP_Param *ap;
|
|
|
|
float val;
|
|
|
|
defaults_list *next;
|
|
|
|
};
|
|
|
|
static defaults_list *default_list;
|
|
|
|
static void check_default(AP_Param *ap, float *default_value);
|
2012-02-11 07:51:35 -04:00
|
|
|
};
|
|
|
|
|
2019-11-25 12:21:31 -04:00
|
|
|
namespace AP {
|
|
|
|
AP_Param *param();
|
|
|
|
};
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Template class for scalar variables.
|
|
|
|
///
|
|
|
|
/// Objects of this type have a value, and can be treated in many ways as though they
|
|
|
|
/// were the value.
|
|
|
|
///
|
|
|
|
/// @tparam T The scalar type of the variable
|
|
|
|
/// @tparam PT The AP_PARAM_* type
|
|
|
|
///
|
|
|
|
template<typename T, ap_var_type PT>
|
|
|
|
class AP_ParamT : public AP_Param
|
|
|
|
{
|
|
|
|
public:
|
2012-08-17 03:17:46 -03:00
|
|
|
static const ap_var_type vtype = PT;
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
/// Value getter
|
|
|
|
///
|
2013-04-17 21:52:40 -03:00
|
|
|
const T &get(void) const {
|
2012-02-11 07:51:35 -04:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Value setter
|
|
|
|
///
|
2013-04-17 21:52:40 -03:00
|
|
|
void set(const T &v) {
|
2012-02-11 07:51:35 -04:00
|
|
|
_value = v;
|
|
|
|
}
|
2015-10-21 23:57:05 -03:00
|
|
|
|
2020-04-18 19:36:37 -03:00
|
|
|
// set a parameter that is an ENABLE param
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_enable(const T &v);
|
2020-04-18 19:36:37 -03:00
|
|
|
|
2015-10-21 23:57:05 -03:00
|
|
|
/// Sets if the parameter is unconfigured
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_default(const T &v);
|
2017-01-31 14:24:47 -04:00
|
|
|
|
2022-06-13 13:04:41 -03:00
|
|
|
/// Sets parameter and default
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_default(const T &v);
|
2022-06-13 13:04:41 -03:00
|
|
|
|
2015-10-06 19:08:59 -03:00
|
|
|
/// Value setter - set value, tell GCS
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_notify(const T &v);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
/// Combined set and save
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_save(const T &v);
|
2012-02-17 00:13:00 -04:00
|
|
|
|
|
|
|
/// Combined set and save, but only does the save if the value if
|
|
|
|
/// different from the current ram value, thus saving us a
|
|
|
|
/// scan(). This should only be used where we have not set() the
|
|
|
|
/// value separately, as otherwise the value in EEPROM won't be
|
|
|
|
/// updated correctly.
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_save_ifchanged(const T &v);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
/// Conversion to T returns a reference to the value.
|
|
|
|
///
|
|
|
|
/// This allows the class to be used in many situations where the value would be legal.
|
|
|
|
///
|
2013-04-17 21:52:40 -03:00
|
|
|
operator const T &() const {
|
2012-02-11 07:51:35 -04:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AP_ParamT types can implement AP_Param::cast_to_float
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
float cast_to_float(void) const;
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
T _value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Template class for non-scalar variables.
|
|
|
|
///
|
|
|
|
/// Objects of this type have a value, and can be treated in many ways as though they
|
|
|
|
/// were the value.
|
|
|
|
///
|
|
|
|
/// @tparam T The scalar type of the variable
|
|
|
|
/// @tparam PT AP_PARAM_* type
|
|
|
|
///
|
|
|
|
template<typename T, ap_var_type PT>
|
|
|
|
class AP_ParamV : public AP_Param
|
|
|
|
{
|
|
|
|
public:
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2012-08-17 03:17:46 -03:00
|
|
|
static const ap_var_type vtype = PT;
|
2012-02-11 07:51:35 -04:00
|
|
|
|
|
|
|
/// Value getter
|
|
|
|
///
|
2013-04-21 09:23:46 -03:00
|
|
|
const T &get(void) const {
|
2012-02-11 07:51:35 -04:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Value setter
|
|
|
|
///
|
2013-05-01 21:18:36 -03:00
|
|
|
void set(const T &v) {
|
2012-02-11 07:51:35 -04:00
|
|
|
_value = v;
|
|
|
|
}
|
|
|
|
|
2016-11-12 19:34:13 -04:00
|
|
|
/// Value setter - set value, tell GCS
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_notify(const T &v);
|
2016-11-12 19:34:13 -04:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Combined set and save
|
|
|
|
///
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_save(const T &v);
|
2012-02-11 07:51:35 -04:00
|
|
|
|
2020-08-26 16:10:51 -03:00
|
|
|
/// Combined set and save, but only does the save if the value is
|
|
|
|
/// different from the current ram value, thus saving us a
|
|
|
|
/// scan(). This should only be used where we have not set() the
|
|
|
|
/// value separately, as otherwise the value in EEPROM won't be
|
|
|
|
/// updated correctly.
|
2022-07-20 06:15:55 -03:00
|
|
|
void set_and_save_ifchanged(const T &v);
|
2020-08-26 16:10:51 -03:00
|
|
|
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Conversion to T returns a reference to the value.
|
|
|
|
///
|
|
|
|
/// This allows the class to be used in many situations where the value would be legal.
|
|
|
|
///
|
2013-04-21 09:23:46 -03:00
|
|
|
operator const T &() const {
|
2012-02-11 07:51:35 -04:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-08-17 03:17:46 -03:00
|
|
|
T _value;
|
2012-02-11 07:51:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Template class for array variables.
|
|
|
|
///
|
|
|
|
/// Objects created using this template behave like arrays of the type T,
|
|
|
|
/// but are stored like single variables.
|
|
|
|
///
|
|
|
|
/// @tparam T The scalar type of the variable
|
|
|
|
/// @tparam N number of elements
|
|
|
|
/// @tparam PT the AP_PARAM_* type
|
|
|
|
///
|
|
|
|
template<typename T, uint8_t N, ap_var_type PT>
|
|
|
|
class AP_ParamA : public AP_Param
|
|
|
|
{
|
|
|
|
public:
|
2012-08-06 22:00:43 -03:00
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
static const ap_var_type vtype = PT;
|
|
|
|
|
|
|
|
/// Array operator accesses members.
|
|
|
|
///
|
|
|
|
/// @note It would be nice to range-check i here, but then what would we return?
|
|
|
|
///
|
2013-05-01 21:18:36 -03:00
|
|
|
const T & operator[](uint8_t i) {
|
2012-02-11 07:51:35 -04:00
|
|
|
return _value[i];
|
|
|
|
}
|
|
|
|
|
2013-05-01 21:18:36 -03:00
|
|
|
const T & operator[](int8_t i) {
|
2013-01-01 22:54:03 -04:00
|
|
|
return _value[(uint8_t)i];
|
|
|
|
}
|
|
|
|
|
2012-02-11 07:51:35 -04:00
|
|
|
/// Value getter
|
|
|
|
///
|
|
|
|
/// @note Returns zero for index values out of range.
|
|
|
|
///
|
|
|
|
T get(uint8_t i) const {
|
|
|
|
if (i < N) {
|
|
|
|
return _value[i];
|
|
|
|
} else {
|
|
|
|
return (T)0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Value setter
|
|
|
|
///
|
|
|
|
/// @note Attempts to set an index out of range are discarded.
|
|
|
|
///
|
2013-05-01 21:18:36 -03:00
|
|
|
void set(uint8_t i, const T &v) {
|
2012-02-11 07:51:35 -04:00
|
|
|
if (i < N) {
|
|
|
|
_value[i] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T _value[N];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Convenience macro for defining instances of the AP_ParamT template.
|
|
|
|
///
|
2012-02-26 19:22:29 -04:00
|
|
|
// declare a scalar type
|
|
|
|
// _t is the base type
|
|
|
|
// _suffix is the suffix on the AP_* type name
|
|
|
|
// _pt is the enum ap_var_type type
|
2012-08-17 03:17:46 -03:00
|
|
|
#define AP_PARAMDEF(_t, _suffix, _pt) typedef AP_ParamT<_t, _pt> AP_ ## _suffix;
|
2012-02-11 07:51:35 -04:00
|
|
|
AP_PARAMDEF(float, Float, AP_PARAM_FLOAT); // defines AP_Float
|
|
|
|
AP_PARAMDEF(int8_t, Int8, AP_PARAM_INT8); // defines AP_Int8
|
|
|
|
AP_PARAMDEF(int16_t, Int16, AP_PARAM_INT16); // defines AP_Int16
|
|
|
|
AP_PARAMDEF(int32_t, Int32, AP_PARAM_INT32); // defines AP_Int32
|
|
|
|
|
2012-02-26 19:22:29 -04:00
|
|
|
// declare a non-scalar type
|
2012-02-17 19:00:26 -04:00
|
|
|
// this is used in AP_Math.h
|
2012-02-26 19:22:29 -04:00
|
|
|
// _t is the base type
|
|
|
|
// _suffix is the suffix on the AP_* type name
|
|
|
|
// _pt is the enum ap_var_type type
|
2012-08-17 03:17:46 -03:00
|
|
|
#define AP_PARAMDEFV(_t, _suffix, _pt) typedef AP_ParamV<_t, _pt> AP_ ## _suffix;
|
2020-11-30 23:06:22 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
template class for enum types based on AP_Int8
|
|
|
|
*/
|
|
|
|
template<typename eclass>
|
|
|
|
class AP_Enum : public AP_Int8
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
operator const eclass () const {
|
|
|
|
return (eclass)_value;
|
|
|
|
}
|
2023-04-11 05:42:31 -03:00
|
|
|
void set(eclass v) {
|
|
|
|
AP_Int8::set(int8_t(v));
|
|
|
|
}
|
2020-11-30 23:06:22 -04:00
|
|
|
};
|
2021-11-29 02:53:46 -04:00
|
|
|
|
|
|
|
template<typename eclass>
|
|
|
|
class AP_Enum16 : public AP_Int16
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
operator const eclass () const {
|
|
|
|
return (eclass)_value;
|
|
|
|
}
|
2023-04-11 05:42:31 -03:00
|
|
|
void set(eclass v) {
|
|
|
|
AP_Int16::set(int16_t(v));
|
|
|
|
}
|
2021-11-29 02:53:46 -04:00
|
|
|
};
|