2020-10-20 05:31:13 +02:00
|
|
|
/****************************************************************************
|
2021-01-13 14:43:07 +01:00
|
|
|
* apps/testing/sensortest/sensortest.c
|
2020-10-20 05:31:13 +02:00
|
|
|
*
|
|
|
|
* 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 <nuttx/config.h>
|
2023-03-06 22:17:52 +01:00
|
|
|
|
2020-11-16 06:14:53 +01:00
|
|
|
#include <inttypes.h>
|
2020-10-20 05:31:13 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
2023-03-06 22:17:52 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
2023-08-15 19:12:50 +02:00
|
|
|
#include <sys/param.h>
|
2023-03-06 22:17:52 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <nuttx/sensors/sensor.h>
|
2020-10-20 05:31:13 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-08 07:49:41 +02:00
|
|
|
#define DEVNAME_FMT "/dev/uorb/sensor_%s"
|
2020-10-20 05:31:13 +02:00
|
|
|
#define DEVNAME_MAX 64
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
typedef void (*data_print)(FAR const char *buffer, FAR const char *name);
|
2022-08-14 04:41:46 +02:00
|
|
|
|
2020-10-20 05:31:13 +02:00
|
|
|
struct sensor_info
|
|
|
|
{
|
|
|
|
data_print print;
|
|
|
|
const uint8_t esize;
|
|
|
|
FAR const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void print_vec3(FAR const char *buffer, FAR const char *name);
|
|
|
|
static void print_valf3(FAR const char *buffer, FAR const char *name);
|
|
|
|
static void print_valf2(FAR const char *buffer, FAR const char *name);
|
|
|
|
static void print_valf(FAR const char *buffer, FAR const char *name);
|
|
|
|
static void print_valb(FAR const char *buffer, FAR const char *name);
|
2021-11-17 03:16:36 +01:00
|
|
|
static void print_vali2(FAR const char *buffer, FAR const char *name);
|
2022-09-28 05:06:27 +02:00
|
|
|
static void print_ecg(FAR const char *buffer, FAR const char *name);
|
2023-02-27 07:38:59 +01:00
|
|
|
static void print_force(FAR const char *buffer, FAR const char *name);
|
2022-01-06 08:17:46 +01:00
|
|
|
static void print_ppgd(FAR const char *buffer, FAR const char *name);
|
|
|
|
static void print_ppgq(FAR const char *buffer, FAR const char *name);
|
2022-03-02 09:22:16 +01:00
|
|
|
static void print_cap(FAR const char *buffer, FAR const char *name);
|
2020-10-20 05:31:13 +02:00
|
|
|
static void print_gps(FAR const char *buffer, FAR const char *name);
|
2021-11-17 03:16:36 +01:00
|
|
|
static void print_gps_satellite(FAR const char *buffer,
|
|
|
|
FAR const char *name);
|
2020-10-20 05:31:13 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool g_should_exit = false;
|
|
|
|
|
|
|
|
static const struct sensor_info g_sensor_info[] =
|
|
|
|
{
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_vec3, sizeof(struct sensor_accel), "accel"},
|
|
|
|
{print_valf2, sizeof(struct sensor_baro), "baro"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_cap, sizeof(struct sensor_cap), "cap"},
|
|
|
|
{print_valf, sizeof(struct sensor_co2), "co2"},
|
|
|
|
{print_valf, sizeof(struct sensor_dust), "dust"},
|
2022-09-28 05:06:27 +02:00
|
|
|
{print_ecg, sizeof(struct sensor_ecg), "ecg"},
|
2023-02-27 07:38:59 +01:00
|
|
|
{print_force, sizeof(struct sensor_force), "force"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_gps, sizeof(struct sensor_gps), "gps"},
|
|
|
|
{print_gps_satellite,
|
|
|
|
sizeof(struct sensor_gps_satellite), "gps_satellite"},
|
|
|
|
{print_vec3, sizeof(struct sensor_gyro), "gyro"},
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_valb, sizeof(struct sensor_hall), "hall"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_valf, sizeof(struct sensor_hbeat), "hbeat"},
|
|
|
|
{print_valf, sizeof(struct sensor_hcho), "hcho"},
|
|
|
|
{print_valf, sizeof(struct sensor_hrate), "hrate"},
|
|
|
|
{print_valf, sizeof(struct sensor_humi), "humi"},
|
|
|
|
{print_valf2, sizeof(struct sensor_impd), "impd"},
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_valf, sizeof(struct sensor_ir), "ir"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_valf, sizeof(struct sensor_light), "light"},
|
|
|
|
{print_vec3, sizeof(struct sensor_mag), "mag"},
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_valf, sizeof(struct sensor_noise), "noise"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_vali2, sizeof(struct sensor_ots), "ots"},
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_valf, sizeof(struct sensor_ph), "ph"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_valf, sizeof(struct sensor_pm10), "pm10"},
|
|
|
|
{print_valf, sizeof(struct sensor_pm1p0), "pm1p0"},
|
|
|
|
{print_valf, sizeof(struct sensor_pm25), "pm25"},
|
2022-07-25 06:08:38 +02:00
|
|
|
{print_ppgd, sizeof(struct sensor_ppgd), "ppgd"},
|
|
|
|
{print_ppgq, sizeof(struct sensor_ppgq), "ppgq"},
|
2022-08-14 04:47:44 +02:00
|
|
|
{print_valf, sizeof(struct sensor_prox), "prox"},
|
|
|
|
{print_valf3, sizeof(struct sensor_rgb), "rgb"},
|
|
|
|
{print_valf, sizeof(struct sensor_temp), "temp"},
|
|
|
|
{print_valf, sizeof(struct sensor_tvoc), "tvoc"},
|
|
|
|
{print_valf, sizeof(struct sensor_uv), "uv"}
|
2020-10-20 05:31:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void print_vec3(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_accel *event = (FAR struct sensor_accel *)buffer;
|
2020-11-16 06:14:53 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " x:%.2f y:%.2f z:%.2f, "
|
|
|
|
"temperature:%.2f\n",
|
2020-10-20 05:31:13 +02:00
|
|
|
name, event->timestamp, event->x, event->y,
|
|
|
|
event->z, event->temperature);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_valb(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_hall *event = (FAR struct sensor_hall *)buffer;
|
2022-09-06 05:27:14 +02:00
|
|
|
printf("%s: timestamp:%" PRIu64 " value:%" PRIi32 "\n",
|
2020-10-20 05:31:13 +02:00
|
|
|
name, event->timestamp, event->hall);
|
|
|
|
}
|
|
|
|
|
2021-11-17 03:16:36 +01:00
|
|
|
static void print_vali2(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_ots *event = (FAR struct sensor_ots *)buffer;
|
2021-11-17 03:16:36 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " value1:% " PRIi32 " value2:% " PRIi32
|
|
|
|
"\n", name, event->timestamp, event->x, event->y);
|
|
|
|
}
|
|
|
|
|
2020-10-20 05:31:13 +02:00
|
|
|
static void print_valf(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_prox *event = (FAR struct sensor_prox *)buffer;
|
2020-11-16 06:14:53 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " value:%.2f\n",
|
2020-10-20 05:31:13 +02:00
|
|
|
name, event->timestamp, event->proximity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_valf2(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_baro *event = (FAR struct sensor_baro *)buffer;
|
2020-11-16 09:34:28 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " value1:%.2f value2:%.2f\n",
|
2020-10-20 05:31:13 +02:00
|
|
|
name, event->timestamp, event->pressure, event->temperature);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_valf3(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_rgb *event = (FAR struct sensor_rgb *)buffer;
|
2020-11-16 06:14:53 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " value1:%.2f value2:%.2f, value3:%.2f\n",
|
2020-10-20 05:31:13 +02:00
|
|
|
name, event->timestamp, event->r, event->g, event->b);
|
|
|
|
}
|
|
|
|
|
2022-09-28 05:06:27 +02:00
|
|
|
static void print_ecg(const char *buffer, const char *name)
|
|
|
|
{
|
2023-02-02 16:01:07 +01:00
|
|
|
struct sensor_ecg *event = (struct sensor_ecg *)buffer;
|
2023-02-02 18:53:38 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " ecg:%.4f status:%" PRIu32,
|
|
|
|
name, event->timestamp, event->ecg, event->status);
|
2022-09-28 05:06:27 +02:00
|
|
|
}
|
|
|
|
|
2023-02-27 07:38:59 +01:00
|
|
|
static void print_force(const char *buffer, const char *name)
|
|
|
|
{
|
|
|
|
FAR struct sensor_force *event = (FAR struct sensor_force *)buffer;
|
|
|
|
|
|
|
|
printf("%s: timestamp:%" PRIu64 " value:%.2f event:%" PRIi32 "\n",
|
|
|
|
name, event->timestamp, event->force, event->event);
|
|
|
|
}
|
|
|
|
|
2022-01-06 08:17:46 +01:00
|
|
|
static void print_ppgd(const char *buffer, const char *name)
|
2021-11-17 03:16:36 +01:00
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_ppgd *event = (FAR struct sensor_ppgd *)buffer;
|
2022-01-06 08:17:46 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " ppg1:%" PRIu32 " ppg2:%" PRIu32 " "
|
|
|
|
"current:%" PRIu32 " gain1:%" PRIu16 " gain2:%" PRIu16 "\n",
|
|
|
|
name, event->timestamp, event->ppg[0], event->ppg[1],
|
|
|
|
event->current, event->gain[0], event->gain[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ppgq(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_ppgq *event = (FAR struct sensor_ppgq *)buffer;
|
2022-01-06 08:17:46 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " ppg1:%" PRIu32 " ppg2:%" PRIu32 " "
|
|
|
|
"ppg3:%" PRIu32 " ppg4:%" PRIu32 " current:%" PRIu32 " "
|
|
|
|
"gain1:%" PRIu16 " gain2:%" PRIu16 " gain3:%" PRIu16 " "
|
|
|
|
"gain4:%" PRIu16 "\n",
|
|
|
|
name, event->timestamp, event->ppg[0], event->ppg[1], event->ppg[2],
|
|
|
|
event->ppg[3], event->current, event->gain[0], event->gain[1],
|
|
|
|
event->gain[2], event->gain[3]);
|
2021-11-17 03:16:36 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 09:22:16 +01:00
|
|
|
static void print_cap(FAR const char *buffer, FAR const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_cap *event = (FAR struct sensor_cap *)buffer;
|
2022-03-02 09:22:16 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " status:%" PRIu32 " "
|
|
|
|
"rawdata0:%" PRIu32 " rawdata1:%" PRIu32 " rawdata2:%" PRIu32 " "
|
|
|
|
"rawdata3:%" PRIu32 "\n",
|
|
|
|
name, event->timestamp, event->status, event->rawdata[0],
|
|
|
|
event->rawdata[1], event->rawdata[2], event->rawdata[3]);
|
|
|
|
}
|
|
|
|
|
2020-10-20 05:31:13 +02:00
|
|
|
static void print_gps(const char *buffer, const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR struct sensor_gps *event = (FAR struct sensor_gps *)buffer;
|
2020-10-20 05:31:13 +02:00
|
|
|
|
testing/sensortest: Fix printf format warning
sensortest.c: In function 'print_gps':
Error: sensortest.c:169:29: error: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
169 | printf("%s: timestamp: %llu time_utc: %llu latitude: %f longitude: %f "
| ~~~^
| |
| long long unsigned int
| %lu
......
172 | " %u\n", name, event->timestamp, event->time_utc, event->latitude,
| ~~~~~~~~~~~~~~~~
| |
| uint64_t {aka long unsigned int}
Error: sensortest.c:169:44: error: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
169 | printf("%s: timestamp: %llu time_utc: %llu latitude: %f longitude: %f "
| ~~~^
| |
| long long unsigned int
| %lu
......
172 | " %u\n", name, event->timestamp, event->time_utc, event->latitude,
| ~~~~~~~~~~~~~~~
| |
| uint64_t {aka long unsigned int}
sensortest.c: In function 'print_gps_satellite':
Error: sensortest.c:183:29: error: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'uint64_t' {aka 'long unsigned int'} [-Werror=format=]
183 | printf("%s: timestamp: %llu count: %u satellites: %u", name,
| ~~~^
| |
| long long unsigned int
| %lu
184 | event->timestamp, event->count, event->satellites);
| ~~~~~~~~~~~~~~~~
| |
| uint64_t {aka long unsigned int}
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-17 16:37:41 +01:00
|
|
|
printf("%s: timestamp:%" PRIu64 " time_utc: %" PRIu64 " latitude: %f "
|
|
|
|
"longitude: %f altitude: %f altitude_ellipsoid: %f eph: %f epv: %f "
|
testing/sensortest: Fix printf format warning
sensortest.c: In function 'print_valu':
Error: sensortest.c:161:10: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
161 | printf("%s: timestamp:%" PRIu64 " value:%u\n",
| ^~~~~~~~~~~~~~~~~
162 | name, event->timestamp, event->ppg);
| ~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:161:44: note: format string is defined here
161 | printf("%s: timestamp:%" PRIu64 " value:%u\n",
| ~^
| |
| unsigned int
| %lu
sensortest.c: In function 'print_gps':
Error: sensortest.c:169:10: error: format '%u' expects argument of type 'unsigned int', but argument 15 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
169 | printf("%s: timestamp:%" PRIu64 " time_utc: %" PRIu64 " latitude: %f "
| ^~~~~~~~~~~~~~~~~
......
175 | event->ground_speed, event->course, event->satellites_used);
| ~~~~~~~~~~~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:172:13: note: format string is defined here
172 | " %u\n", name, event->timestamp, event->time_utc, event->latitude,
| ~^
| |
| unsigned int
| %lu
sensortest.c: In function 'print_gps_satellite':
Error: sensortest.c:183:10: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ^~~~~~~~~~~~~~~~~~
184 | event->timestamp, event->count, event->satellites);
| ~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:183:46: note: format string is defined here
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ~^
| |
| unsigned int
| %lu
Error: sensortest.c:183:10: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ^~~~~~~~~~~~~~~~~~
184 | event->timestamp, event->count, event->satellites);
| ~~~~~~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:183:61: note: format string is defined here
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ~^
| |
| unsigned int
| %lu
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-18 15:40:17 +01:00
|
|
|
"hdop: %f vdop: %f ground_speed: %f course: %f satellites_used: %"
|
|
|
|
PRIu32 "\n",
|
|
|
|
name, event->timestamp, event->time_utc, event->latitude,
|
2021-11-17 03:16:36 +01:00
|
|
|
event->longitude, event->altitude, event->altitude_ellipsoid,
|
|
|
|
event->eph, event->epv, event->hdop, event->vdop,
|
|
|
|
event->ground_speed, event->course, event->satellites_used);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_gps_satellite(FAR const char *buffer, FAR const char *name)
|
|
|
|
{
|
2022-08-14 04:41:46 +02:00
|
|
|
FAR FAR struct sensor_gps_satellite *event =
|
|
|
|
(FAR struct sensor_gps_satellite *)buffer;
|
2021-11-17 03:16:36 +01:00
|
|
|
|
testing/sensortest: Fix printf format warning
sensortest.c: In function 'print_valu':
Error: sensortest.c:161:10: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
161 | printf("%s: timestamp:%" PRIu64 " value:%u\n",
| ^~~~~~~~~~~~~~~~~
162 | name, event->timestamp, event->ppg);
| ~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:161:44: note: format string is defined here
161 | printf("%s: timestamp:%" PRIu64 " value:%u\n",
| ~^
| |
| unsigned int
| %lu
sensortest.c: In function 'print_gps':
Error: sensortest.c:169:10: error: format '%u' expects argument of type 'unsigned int', but argument 15 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
169 | printf("%s: timestamp:%" PRIu64 " time_utc: %" PRIu64 " latitude: %f "
| ^~~~~~~~~~~~~~~~~
......
175 | event->ground_speed, event->course, event->satellites_used);
| ~~~~~~~~~~~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:172:13: note: format string is defined here
172 | " %u\n", name, event->timestamp, event->time_utc, event->latitude,
| ~^
| |
| unsigned int
| %lu
sensortest.c: In function 'print_gps_satellite':
Error: sensortest.c:183:10: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ^~~~~~~~~~~~~~~~~~
184 | event->timestamp, event->count, event->satellites);
| ~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:183:46: note: format string is defined here
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ~^
| |
| unsigned int
| %lu
Error: sensortest.c:183:10: error: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ^~~~~~~~~~~~~~~~~~
184 | event->timestamp, event->count, event->satellites);
| ~~~~~~~~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
sensortest.c:183:61: note: format string is defined here
183 | printf("%s: timestamp: %" PRIu64 " count: %u satellites: %u", name,
| ~^
| |
| unsigned int
| %lu
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-18 15:40:17 +01:00
|
|
|
printf("%s: timestamp: %" PRIu64 " count: %" PRIu32
|
|
|
|
" satellites: %" PRIu32 "\n",
|
|
|
|
name, event->timestamp, event->count, event->satellites);
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2020-12-09 05:36:46 +01:00
|
|
|
printf("sensortest [arguments...] <command>\n");
|
2021-08-26 14:36:43 +02:00
|
|
|
printf("\t[-h ] sensortest commands help\n");
|
2020-10-20 05:31:13 +02:00
|
|
|
printf("\t[-i <val>] The output data period of sensor in us\n");
|
|
|
|
printf("\t default: 1000000\n");
|
|
|
|
printf("\t[-b <val>] The maximum report latency of sensor in us\n");
|
|
|
|
printf("\t default: 0\n");
|
2021-08-26 14:36:43 +02:00
|
|
|
printf("\t[-n <val>] The number of output data\n");
|
2020-12-09 05:36:46 +01:00
|
|
|
printf("\t default: 0\n");
|
|
|
|
|
|
|
|
printf(" Commands:\n");
|
2022-08-08 07:49:41 +02:00
|
|
|
printf("\t<sensor_node_name> ex, accel0(/dev/uorb/sensor_accel0)\n");
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_handler(int signo)
|
|
|
|
{
|
|
|
|
g_should_exit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* sensortest_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
|
|
|
unsigned int interval = 1000000;
|
2020-12-09 05:36:46 +01:00
|
|
|
unsigned int received = 0;
|
2020-10-20 05:31:13 +02:00
|
|
|
unsigned int latency = 0;
|
2020-12-09 05:36:46 +01:00
|
|
|
unsigned int count = 0;
|
2020-10-20 05:31:13 +02:00
|
|
|
char devname[PATH_MAX];
|
|
|
|
struct pollfd fds;
|
|
|
|
FAR char *buffer;
|
|
|
|
FAR char *name;
|
|
|
|
int len = 0;
|
|
|
|
int fd;
|
|
|
|
int idx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc <= 1)
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (signal(SIGINT, exit_handler) == SIG_ERR)
|
|
|
|
{
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_should_exit = false;
|
2020-12-09 05:36:46 +01:00
|
|
|
while ((ret = getopt(argc, argv, "i:b:n:h")) != EOF)
|
2020-10-20 05:31:13 +02:00
|
|
|
{
|
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case 'i':
|
2020-12-09 05:36:46 +01:00
|
|
|
interval = strtoul(optarg, NULL, 0);
|
2020-10-20 05:31:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
2020-12-09 05:36:46 +01:00
|
|
|
latency = strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
count = strtoul(optarg, NULL, 0);
|
2020-10-20 05:31:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
2021-02-02 04:55:43 +01:00
|
|
|
goto name_err;
|
2020-12-09 05:36:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
|
|
|
name = argv[optind];
|
2023-08-15 19:12:50 +02:00
|
|
|
for (idx = 0; idx < nitems(g_sensor_info); idx++)
|
2020-12-09 05:36:46 +01:00
|
|
|
{
|
|
|
|
if (!strncmp(name, g_sensor_info[idx].name,
|
|
|
|
strlen(g_sensor_info[idx].name)))
|
|
|
|
{
|
|
|
|
len = g_sensor_info[idx].esize;
|
|
|
|
buffer = calloc(1, len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
{
|
2021-08-26 14:36:43 +02:00
|
|
|
printf("The sensor node name:%s is invalid\n", name);
|
2020-12-09 05:36:46 +01:00
|
|
|
usage();
|
2021-02-02 04:55:43 +01:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto name_err;
|
2020-12-09 05:36:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
{
|
2021-02-02 04:55:43 +01:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto name_err;
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-09 05:36:46 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
2021-02-02 04:55:43 +01:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto name_err;
|
2020-12-09 05:36:46 +01:00
|
|
|
}
|
2020-10-20 05:31:13 +02:00
|
|
|
|
|
|
|
snprintf(devname, PATH_MAX, DEVNAME_FMT, name);
|
|
|
|
fd = open(devname, O_RDONLY | O_NONBLOCK);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
ret = -errno;
|
|
|
|
printf("Failed to open device:%s, ret:%s\n",
|
|
|
|
devname, strerror(errno));
|
2020-12-09 05:36:46 +01:00
|
|
|
goto open_err;
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
|
2022-07-29 11:47:04 +02:00
|
|
|
ret = ioctl(fd, SNIOC_SET_INTERVAL, interval);
|
2020-10-20 05:31:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -errno;
|
2021-07-20 11:13:47 +02:00
|
|
|
if (ret != -ENOTSUP)
|
2020-11-11 09:09:55 +01:00
|
|
|
{
|
2021-06-28 05:04:44 +02:00
|
|
|
printf("Failed to set interval for sensor:%s, ret:%s\n",
|
2020-11-11 09:09:55 +01:00
|
|
|
devname, strerror(errno));
|
|
|
|
goto ctl_err;
|
|
|
|
}
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
|
2022-07-29 11:47:04 +02:00
|
|
|
ret = ioctl(fd, SNIOC_BATCH, latency);
|
2020-10-20 05:31:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -errno;
|
2021-07-20 11:13:47 +02:00
|
|
|
if (ret != -ENOTSUP)
|
2020-11-11 09:09:55 +01:00
|
|
|
{
|
2021-06-28 05:04:44 +02:00
|
|
|
printf("Failed to batch for sensor:%s, ret:%s\n",
|
|
|
|
devname, strerror(errno));
|
2020-11-11 09:09:55 +01:00
|
|
|
goto ctl_err;
|
|
|
|
}
|
2020-10-20 05:31:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("SensorTest: Test %s with interval(%uus), latency(%uus)\n",
|
|
|
|
devname, interval, latency);
|
|
|
|
|
|
|
|
fds.fd = fd;
|
|
|
|
fds.events = POLLIN;
|
|
|
|
|
2020-12-09 05:36:46 +01:00
|
|
|
while ((!count || received < count) && !g_should_exit)
|
2020-10-20 05:31:13 +02:00
|
|
|
{
|
|
|
|
if (poll(&fds, 1, -1) > 0)
|
|
|
|
{
|
|
|
|
if (read(fd, buffer, len) >= len)
|
|
|
|
{
|
2020-12-09 05:36:46 +01:00
|
|
|
received++;
|
2020-10-20 05:31:13 +02:00
|
|
|
g_sensor_info[idx].print(buffer, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 05:36:46 +01:00
|
|
|
printf("SensorTest: Received message: %s, number:%d/%d\n",
|
|
|
|
name, received, count);
|
|
|
|
|
2020-10-20 05:31:13 +02:00
|
|
|
ctl_err:
|
|
|
|
close(fd);
|
2020-12-09 05:36:46 +01:00
|
|
|
open_err:
|
2020-10-20 05:31:13 +02:00
|
|
|
free(buffer);
|
2021-02-02 04:55:43 +01:00
|
|
|
name_err:
|
|
|
|
optind = 0;
|
2020-10-20 05:31:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|