system/uorb: introduce CONFIG_UORB_FORMAT for format string control

Introduce a new CONFIG_UORB_FORMAT Kconfig option to control whether
uORB format strings are compiled in. UORB_LISTENER, UORB_GENERATOR,
and DEBUG_UORB all select UORB_FORMAT automatically, so format strings
are included when any of these features are enabled.

This replaces the previous approach of guarding format strings with
CONFIG_DEBUG_UORB, which prevented uorb_listener from displaying
sensor data when debug output was disabled.

Signed-off-by: hanzj <hanzjian@zepp.com>
This commit is contained in:
hanzj 2026-06-05 23:56:48 +08:00
parent c106a02b58
commit 8ccc4f43d7
44 changed files with 57 additions and 50 deletions

View file

@ -18,12 +18,18 @@ config UORB_STACKSIZE
int "stack size"
default DEFAULT_TASK_STACKSIZE
config UORB_FORMAT
bool "uorb format strings"
default n
config UORB_LISTENER
bool "uorb listener"
select UORB_FORMAT
default n
config UORB_GENERATOR
bool "uorb generator"
select UORB_FORMAT
default n
config UORB_TESTS
@ -46,6 +52,7 @@ endif # UORB_TESTS
config DEBUG_UORB
bool "uorb debug output"
select LIBC_PRINT_EXTENSION
select UORB_FORMAT
depends on LIBC_FLOATINGPOINT && SENSORS_USE_FLOAT
default n

View file

@ -49,7 +49,7 @@
#define ORB_TOP_WAIT_TIME 1000
#define ORB_DATA_DIR "/data/uorb/"
#if defined(CONFIG_DEBUG_UORB) && !defined(CONFIG_LIBC_FLOATINGPOINT)
#if defined(CONFIG_UORB_FORMAT) && !defined(CONFIG_LIBC_FLOATINGPOINT)
#error "Enable CONFIG_LIBC_FLOATINGPOINT, required to see debug output"
#endif
@ -551,7 +551,7 @@ static int listener_print(FAR const struct orb_metadata *meta, int fd)
int ret;
ret = orb_copy(meta, fd, buffer);
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
if (ret == OK && meta->o_format != NULL)
{
orb_info(meta->o_format, meta->o_name, buffer);
@ -774,7 +774,7 @@ static int listener_record(FAR const struct orb_metadata *meta, int fd,
int ret;
ret = orb_copy(meta, fd, buffer);
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
if (ret == OK && meta->o_format != NULL)
{
ret = orb_fprintf(file, meta->o_format, buffer);
@ -876,7 +876,7 @@ static void listener_monitor(FAR struct listen_list_s *objlist,
tmp->file = fopen(path, "w");
if (tmp->file != NULL)
{
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
fprintf(tmp->file, "%s,%d,%d,%s\n", tmp->object.meta->o_format,
tmp->object.meta->o_size, tmp->object.instance,
tmp->object.meta->o_name);
@ -1129,7 +1129,7 @@ int main(int argc, FAR char *argv[])
}
break;
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
case 's':
record = true;
break;

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_accel_format[] =
"timestamp:%" PRIu64 ",x:%hf,y:%hf,z:%hf,temperature:%hf";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_angle_format[] = "timestamp:%" PRIu64 ",angle:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_baro_format[] =
"timestamp:%" PRIu64 ",pressure:%hf,temperature:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_cap_format[] =
"timestamp:%" PRIu64 ",status:%" PRIu32 ",rawdata0:%" PRIu32 ","
"rawdata1:%" PRIu32 ",rawdata2:%" PRIu32 ",rawdata3:%" PRIu32 "";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_co2_format[] = "timestamp:%" PRIu64 ",co2:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_dust_format[] = "timestamp:%" PRIu64 ",dust:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ecg_format[] =
"timestamp:%" PRIu64 ",ecg:%hf,status:%" PRIx32 "";
#endif

View file

@ -28,7 +28,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_eng_format[] =
"timestamp:%" PRIu64 ",eng0:%hf,eng1:%hf,eng2:%hf,eng3:%hf,"
"status:0x%" PRIx32 "";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_force_format[] =
"timestamp:%" PRIu64 ",force:%hf,event:%" PRIi32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_gas_format[] =
"timestamp:%" PRIu64 ",gas_resistance:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_gesture_format[] =
"timestamp:%" PRIu64 ",event:%" PRIu32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
#define UORB_DEBUG_FORMAT_SENSOR_GNSS \
"timestamp:%" PRIu64 \
",time_utc:%" PRIu64 \

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_gyro_format[] =
"timestamp:%" PRIu64 ",x:%hf,y:%hf,z:%hf,temperature:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_hall_format[] =
"timestamp:%" PRIu64 ",hall:%" PRIi32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_hbeat_format[] =
"timestamp:%" PRIu64 ",heart beat:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_hcho_format[] = "timestamp:%" PRIu64 ",hcho:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_hrate_format[] = "timestamp:%" PRIu64 ",bpm:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_humi_format[] = "timestamp:%" PRIu64 ",humi:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_impd_format[] =
"timestamp:%" PRIu64 ",real:%hf,imaginary:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ir_format[] = "timestamp:%" PRIu64 ",ir:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_light_format[] =
"timestamp:%" PRIu64 ",light:%hf,ir:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_mag_format[] =
"timestamp:%" PRIu64 ",x:%hf,y:%hf,z:%hf,temperature:%hf,"
"status:%" PRId32 "";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_event_format[] =
"timestamp:%" PRIu64 ",event:%" PRIu32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_noise_format[] =
"timestamp:%" PRIu64 ",noise:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ots_format[] =
"timestamp:%" PRIu64 ",x:%" PRIi32 ",y:%" PRIi32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ph_format[] = "timestamp:%" PRIu64 ",ph:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_pm10_format[] = "timestamp:%" PRIu64 ",pm10:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_pm1p0_format[] = "timestamp:%" PRIu64 ",pm1p0:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_pm25_format[] = "timestamp:%" PRIu64 ",pm25:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_pose_6dof_format[] =
"timestamp:%" PRIu64 ",x:%hf,y:%hf,z:%hf,w:%hf,tx:%hf,ty:%hf,tz:%hf,"
"dx:%hf,dy:%hf,dz:%hf,dw:%hf,dtx:%hf,dty:%hf,dtz:%hf,number:%" PRIu64 "";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ppgd_format[] =
"timestamp:%" PRIu64 ",ppg0:%" PRIu32 ",ppg1:%" PRIu32 ","
"current:%" PRIu32 ",gain0:%hu,gain1:%hu";

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_ppgq_format[] =
"timestamp:%" PRIu64 ",ppg0:%" PRIu32 ",ppg1:%" PRIu32 ",ppg2:%" PRIu32 ","
"ppg3:%" PRIu32 ",current:%" PRIu32 ",gain0:%hu,gain1:%hu,gain2:%hu,"

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_prox_format[] =
"timestamp:%" PRIu64 ",proximity:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_rgb_format[] =
"timestamp:%" PRIu64 ",r:%hf,g:%hf,b:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_rotation_format[] =
"timestamp:%" PRIu64 ",x:%hf,y:%hf,z:%hf";
static const char sensor_orientation_format[] =

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_step_counter_format[] =
"timestamp:%" PRIu64 ",event:%" PRIu32 ",cadence:%" PRIu32 "";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_temp_format[] =
"timestamp:%" PRIu64 ",temperature:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_tvoc_format[] = "timestamp:%" PRIu64 ",tvoc:%hf";
#endif

View file

@ -30,7 +30,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char sensor_uv_format[] = "timestamp:%" PRIu64 ",uvi:%hf";
#endif

View file

@ -33,7 +33,7 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
static const char orb_test_format[] =
"timestamp:%" PRIu64 ",val:%" PRId32 "";
#endif

View file

@ -372,7 +372,7 @@ int orb_group_count(FAR const struct orb_metadata *meta)
return instance;
}
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
int orb_sscanf(FAR const char *buf, FAR const char *format, FAR void *data)
{
struct lib_meminstream_s meminstream;

View file

@ -57,7 +57,7 @@ struct orb_metadata
{
FAR const char *o_name; /* Unique object name */
uint16_t o_size; /* Object size */
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
FAR const char *o_format; /* Format string used for structure input and
* output.
*/
@ -165,7 +165,7 @@ struct orb_loop_s
# define uorbinfo uorbnone
#endif
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
# define uorbdebug(fmt, ...) syslog(LOG_INFO, fmt "\n", ##__VA_ARGS__)
#else
# define uorbdebug uorbnone
@ -207,7 +207,7 @@ struct orb_loop_s
* struct The structure the topic provides.
* cb The function pointer of output topic message.
*/
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
#define ORB_DEFINE(name, structure, format) \
const struct orb_metadata g_orb_##name = \
{ \
@ -898,7 +898,7 @@ int orb_group_count(FAR const struct orb_metadata *meta);
FAR const struct orb_metadata *orb_get_meta(FAR const char *name);
#ifdef CONFIG_DEBUG_UORB
#ifdef CONFIG_UORB_FORMAT
/****************************************************************************
* Name: orb_scanf
*