CfgMgr::Set

Description

Sets parameters. You can set a single parameter by parameter name or set multiple parameters by namespace.

Prototype

uint32_t CfgMgr::Set(const std::string &kParam, const T &value, const bool isSync = false, const bool isPersist = false, const std::string &srv = "")

Function Security Level

ASIL-D

Parameters

Parameter

Input/Output

Description

kParam

Input

Key, which is a parameter name or namespace, for example, /ros/use_sim_time or /ros. Starting with a slash (/) is not mandatory.

value

Input

Used to receive the value of a parameter. You can specify the parameter type. For details about the supported types, see "Usage".

isSync

Input

Whether synchronous invocation (waiting for persistent files to be flushed to drives) is required. The default value is false (asynchronous invocation).

isPersist

Input

Whether persistence is required. The default value is false (persistence not required).

srv

Input

Parameter group, which corresponds to resource file and the value of group in yaml_path.yaml Configuration Example. srv is not mandatory during parameter modification. However, permission check is required. When adding a parameter, you need to specify a parameter group. If you do not set srv, a parameter is added to the default parameter group.

Returns

The return value is of the uint32_t type. If the operation is successful, CFGMGR_SUCCESS is returned. If the operation fails, an error code is returned.

Usage

  • If a parameter does not exist, add it. If a parameter exists, modify it.
  • Non-template functions should overload for various types. The value type can be std::string, double, float, int, bool, std::vector<std::string>, std::vector<double>, std::vector<float>, std::vector<int>, std::vector<bool>, std::map<std::string, std::string>, std::map<std::string, double>, std::map<std::string, float>, std::map<std::string, int>, std::map<std::string, bool>, and const char* (processed as a string).
  • When you set a parameter by parameter namespace, the value must be of the map type, indicating a key-value pair.

Precautions

  • The key must be less than 128 bytes. (For the map type, the actual key is the sum of the input parameter kParam and the first value. The actual key must be less than 128 bytes. Ensure that the parameters under the actual key belong to the same group.) A single value must be less than 256 bytes.
  • The number of parameters set at a time cannot exceed 128 bytes. (For the map type, the size of the map is equal to the number of parameters.) If the number of parameters exceeds the limits, the operation may fail.
  • If parameter setting fails, determine whether to report the fault or perform other operations.
  • The interface may return a failure message for several reasons, including the absence of permissions, data transmission failure, and the key or value exceeding the length threshold.