mirror of
https://github.com/apache/nuttx.git
synced 2026-05-10 15:30:25 +08:00
drivers/sensors/fakesensor: Remove GNSS dependency
This commit removes the dependency of the fakesensor API on `SENSORS_GNSS`. All of the logic for handling fake GNSS sensors is conditionally compiled only if GNSS features are enabled. Other fake sensors can be used without GNSS logic being included in the build. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
This commit is contained in:
@@ -74,7 +74,6 @@ config SENSORS_WTGAHRS2
|
||||
|
||||
config SENSORS_FAKESENSOR
|
||||
bool "Fake Sensor Support"
|
||||
depends on SENSORS_GNSS
|
||||
default n
|
||||
---help---
|
||||
Simulate physical sensor by reading data from csv file.
|
||||
|
||||
@@ -39,10 +39,13 @@
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/sensors/fakesensor.h>
|
||||
#include <nuttx/sensors/sensor.h>
|
||||
#include <nuttx/sensors/gnss.h>
|
||||
#include <nuttx/signal.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
#include <nuttx/sensors/gnss.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -52,7 +55,9 @@ struct fakesensor_s
|
||||
union
|
||||
{
|
||||
struct sensor_lowerhalf_s lower;
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
struct gnss_lowerhalf_s gnss;
|
||||
#endif
|
||||
};
|
||||
|
||||
int type;
|
||||
@@ -77,14 +82,17 @@ static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
FAR uint32_t *latency_us);
|
||||
static void fakesensor_push_event(FAR struct fakesensor_s *sensor,
|
||||
uint64_t event_timestamp);
|
||||
static int fakesensor_thread(int argc, char** argv);
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
static int fakegnss_activate(FAR struct gnss_lowerhalf_s *lower,
|
||||
FAR struct file *filep, bool sw);
|
||||
static int fakegnss_set_interval(FAR struct gnss_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
FAR uint32_t *period_us);
|
||||
static void fakesensor_push_event(FAR struct fakesensor_s *sensor,
|
||||
uint64_t event_timestamp);
|
||||
static int fakesensor_thread(int argc, char** argv);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -97,11 +105,13 @@ static struct sensor_ops_s g_fakesensor_ops =
|
||||
.batch = fakesensor_batch,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
static struct gnss_ops_s g_fakegnss_ops =
|
||||
{
|
||||
.activate = fakegnss_activate,
|
||||
.set_interval = fakegnss_set_interval,
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -211,6 +221,7 @@ static inline void fakesensor_read_baro(FAR struct fakesensor_s *sensor,
|
||||
sizeof(struct sensor_baro));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
static inline void fakesensor_read_gnss(FAR struct fakesensor_s *sensor)
|
||||
{
|
||||
char raw[150];
|
||||
@@ -227,6 +238,7 @@ static inline void fakesensor_read_gnss(FAR struct fakesensor_s *sensor)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep, bool enable)
|
||||
@@ -249,11 +261,13 @@ static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
static int fakegnss_activate(FAR struct gnss_lowerhalf_s *lower,
|
||||
FAR struct file *filep, bool enable)
|
||||
{
|
||||
return fakesensor_activate((FAR void *)lower, filep, enable);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
@@ -265,12 +279,14 @@ static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
static int fakegnss_set_interval(FAR struct gnss_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
FAR uint32_t *period_us)
|
||||
{
|
||||
return fakesensor_set_interval((FAR void *)lower, filep, period_us);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
|
||||
FAR struct file *filep,
|
||||
@@ -313,10 +329,12 @@ void fakesensor_push_event(FAR struct fakesensor_s *sensor,
|
||||
fakesensor_read_baro(sensor, event_timestamp);
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
case SENSOR_TYPE_GNSS:
|
||||
case SENSOR_TYPE_GNSS_SATELLITE:
|
||||
fakesensor_read_gnss(sensor);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
snerr("fakesensor: unsupported type sensor type\n");
|
||||
@@ -420,6 +438,7 @@ int fakesensor_init(int type, FAR const char *file_name,
|
||||
FAR struct fakesensor_s *sensor;
|
||||
FAR char *argv[2];
|
||||
char arg1[32];
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
uint32_t nbuffer[] = {
|
||||
[SENSOR_GNSS_IDX_GNSS] = batch_number,
|
||||
[SENSOR_GNSS_IDX_GNSS_SATELLITE] = batch_number,
|
||||
@@ -427,6 +446,7 @@ int fakesensor_init(int type, FAR const char *file_name,
|
||||
[SENSOR_GNSS_IDX_GNSS_CLOCK] = batch_number,
|
||||
[SENSOR_GNSS_IDX_GNSS_GEOFENCE] = batch_number,
|
||||
};
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
|
||||
@@ -460,12 +480,14 @@ int fakesensor_init(int type, FAR const char *file_name,
|
||||
|
||||
/* Register sensor */
|
||||
|
||||
#ifdef CONFIG_SENSORS_GNSS
|
||||
if (type == SENSOR_TYPE_GNSS || type == SENSOR_TYPE_GNSS_SATELLITE)
|
||||
{
|
||||
sensor->gnss.ops = &g_fakegnss_ops;
|
||||
gnss_register(&sensor->gnss, devno, nbuffer, nitems(nbuffer));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sensor->lower.type = type;
|
||||
sensor->lower.ops = &g_fakesensor_ops;
|
||||
|
||||
Reference in New Issue
Block a user