From 027ded4d4e108831c3d4d929497b29d0210d3ab8 Mon Sep 17 00:00:00 2001 From: likun17 Date: Fri, 1 Dec 2023 14:27:36 +0800 Subject: [PATCH] sensor:Add sensor gas log output. Signed-off-by: likun17 --- system/uorb/sensor/gas.c | 49 +++++++++++++++++++++++++++++++++++++ system/uorb/sensor/gas.h | 38 ++++++++++++++++++++++++++++ system/uorb/sensor/topics.c | 2 ++ 3 files changed, 89 insertions(+) create mode 100644 system/uorb/sensor/gas.c create mode 100644 system/uorb/sensor/gas.h diff --git a/system/uorb/sensor/gas.c b/system/uorb/sensor/gas.c new file mode 100644 index 000000000..6f5d65f71 --- /dev/null +++ b/system/uorb/sensor/gas.c @@ -0,0 +1,49 @@ +/**************************************************************************** + * apps/system/uorb/sensor/gas.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 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_DEBUG_UORB +static void print_sensor_gas_message(FAR const struct orb_metadata *meta, + FAR const void *buffer) +{ + FAR const struct sensor_gas *message = buffer; + const orb_abstime now = orb_absolute_time(); + + uorbinfo_raw("%s:\ttimestamp: %" PRIu64 " (%" PRIu64 " us ago) " + "value: %.4f", + meta->o_name, message->timestamp, now - message->timestamp, + message->gas_resistance); +} +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +ORB_DEFINE(sensor_gas, struct sensor_gas, print_sensor_gas_message); diff --git a/system/uorb/sensor/gas.h b/system/uorb/sensor/gas.h new file mode 100644 index 000000000..625150406 --- /dev/null +++ b/system/uorb/sensor/gas.h @@ -0,0 +1,38 @@ +/**************************************************************************** + * apps/system/uorb/sensor/gas.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_GAS_H +#define __APPS_SYSTEM_UORB_SENSOR_GAS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* register this as object request broker structure */ + +ORB_DECLARE(sensor_gas); + +#endif diff --git a/system/uorb/sensor/topics.c b/system/uorb/sensor/topics.c index 9d11ff961..846e32dab 100644 --- a/system/uorb/sensor/topics.c +++ b/system/uorb/sensor/topics.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,7 @@ static FAR const struct orb_metadata *g_sensor_list[] = ORB_ID(sensor_dust), ORB_ID(sensor_ecg), ORB_ID(sensor_force), + ORB_ID(sensor_gas), ORB_ID(sensor_gps), ORB_ID(sensor_gps_satellite), ORB_ID(sensor_gyro),