system/uorb: add resistance, conductivity, energy and charge topics.

Declare and define the uORB metadata for the resistance, conductivity,
energy and charge types, and register them in g_sensor_list[] so that
orb_get_meta() and uorb_listener can resolve them by name.

Signed-off-by: likun17 <likun17@xiaomi.com>
This commit is contained in:
likun17 2026-09-09 19:58:30 +08:00 committed by Xiang Xiao
parent b93c947608
commit d1b15db361
9 changed files with 325 additions and 0 deletions

View file

@ -0,0 +1,41 @@
/****************************************************************************
* apps/system/uorb/sensor/charge.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sensor/charge.h>
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef CONFIG_UORB_FORMAT
static const char sensor_charge_format[] =
"timestamp:%" PRIu64 ",charge:%" PRId64 "";
#endif
/****************************************************************************
* Public Data
****************************************************************************/
ORB_DEFINE(sensor_charge, struct sensor_charge,
sensor_charge_format);

View file

@ -0,0 +1,38 @@
/****************************************************************************
* apps/system/uorb/sensor/charge.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_SYSTEM_UORB_SENSOR_CHARGE_H
#define __APPS_SYSTEM_UORB_SENSOR_CHARGE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <uORB/uORB.h>
/****************************************************************************
* Public Data
****************************************************************************/
/* register this as object request broker structure */
ORB_DECLARE(sensor_charge);
#endif

View file

@ -0,0 +1,41 @@
/****************************************************************************
* apps/system/uorb/sensor/conductivity.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sensor/conductivity.h>
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef CONFIG_UORB_FORMAT
static const char sensor_conductivity_format[] =
"timestamp:%" PRIu64 ",conductivity:%hf";
#endif
/****************************************************************************
* Public Data
****************************************************************************/
ORB_DEFINE(sensor_conductivity, struct sensor_conductivity,
sensor_conductivity_format);

View file

@ -0,0 +1,38 @@
/****************************************************************************
* apps/system/uorb/sensor/conductivity.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_SYSTEM_UORB_SENSOR_CONDUCTIVITY_H
#define __APPS_SYSTEM_UORB_SENSOR_CONDUCTIVITY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <uORB/uORB.h>
/****************************************************************************
* Public Data
****************************************************************************/
/* register this as object request broker structure */
ORB_DECLARE(sensor_conductivity);
#endif

View file

@ -0,0 +1,41 @@
/****************************************************************************
* apps/system/uorb/sensor/energy.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sensor/energy.h>
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef CONFIG_UORB_FORMAT
static const char sensor_energy_format[] =
"timestamp:%" PRIu64 ",energy:%" PRId64 "";
#endif
/****************************************************************************
* Public Data
****************************************************************************/
ORB_DEFINE(sensor_energy, struct sensor_energy,
sensor_energy_format);

View file

@ -0,0 +1,38 @@
/****************************************************************************
* apps/system/uorb/sensor/energy.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_SYSTEM_UORB_SENSOR_ENERGY_H
#define __APPS_SYSTEM_UORB_SENSOR_ENERGY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <uORB/uORB.h>
/****************************************************************************
* Public Data
****************************************************************************/
/* register this as object request broker structure */
ORB_DECLARE(sensor_energy);
#endif

View file

@ -0,0 +1,41 @@
/****************************************************************************
* apps/system/uorb/sensor/resistance.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sensor/resistance.h>
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef CONFIG_UORB_FORMAT
static const char sensor_resistance_format[] =
"timestamp:%" PRIu64 ",resistance:%hf";
#endif
/****************************************************************************
* Public Data
****************************************************************************/
ORB_DEFINE(sensor_resistance, struct sensor_resistance,
sensor_resistance_format);

View file

@ -0,0 +1,38 @@
/****************************************************************************
* apps/system/uorb/sensor/resistance.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_SYSTEM_UORB_SENSOR_RESISTANCE_H
#define __APPS_SYSTEM_UORB_SENSOR_RESISTANCE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <uORB/uORB.h>
/****************************************************************************
* Public Data
****************************************************************************/
/* register this as object request broker structure */
ORB_DECLARE(sensor_resistance);
#endif

View file

@ -35,10 +35,13 @@
#include <sensor/angle.h>
#include <sensor/baro.h>
#include <sensor/cap.h>
#include <sensor/charge.h>
#include <sensor/co2.h>
#include <sensor/conductivity.h>
#include <sensor/current.h>
#include <sensor/dust.h>
#include <sensor/ecg.h>
#include <sensor/energy.h>
#include <sensor/eng.h>
#include <sensor/force.h>
#include <sensor/gas.h>
@ -66,6 +69,7 @@
#include <sensor/ppgd.h>
#include <sensor/ppgq.h>
#include <sensor/prox.h>
#include <sensor/resistance.h>
#include <sensor/rgb.h>
#include <sensor/rotation.h>
#include <sensor/step_counter.h>
@ -89,11 +93,14 @@ static FAR const struct orb_metadata *g_sensor_list[] =
ORB_ID(sensor_hinge_angle),
ORB_ID(sensor_baro),
ORB_ID(sensor_cap),
ORB_ID(sensor_charge),
ORB_ID(sensor_co2),
ORB_ID(sensor_conductivity),
ORB_ID(sensor_current),
ORB_ID(sensor_device_orientation),
ORB_ID(sensor_dust),
ORB_ID(sensor_ecg),
ORB_ID(sensor_energy),
ORB_ID(sensor_eng),
ORB_ID(sensor_force),
ORB_ID(sensor_gas),
@ -136,6 +143,7 @@ static FAR const struct orb_metadata *g_sensor_list[] =
ORB_ID(sensor_ppgd),
ORB_ID(sensor_ppgq),
ORB_ID(sensor_prox),
ORB_ID(sensor_resistance),
ORB_ID(sensor_rgb),
ORB_ID(sensor_rotation),
ORB_ID(sensor_significant_motion),
@ -173,6 +181,7 @@ FAR const struct orb_metadata *orb_get_meta(FAR const char *name)
for (i = 0; g_sensor_list[i]; i++)
{
size_t len = strlen(g_sensor_list[i]->o_name);
if ((!strncmp(g_sensor_list[i]->o_name, name, len))
&& (name[len] == '\0' || isdigit(name[len])))
{