driver/sensors: Support GNSS Geofence

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2024-06-28 20:47:52 +08:00 committed by Xiang Xiao
parent bf83b3fafc
commit ffac2a314b
3 changed files with 124 additions and 2 deletions

View File

@ -45,7 +45,8 @@
#define GNSS_SATELLITE_IDX 1
#define GNSS_MEASUREMENT_IDX 2
#define GNSS_CLOCK_IDX 3
#define GNSS_MAX_IDX 4
#define GNSS_GEOFENCE 4
#define GNSS_MAX_IDX 5
#define GNSS_PARSE_BUFFERSIZE 256
@ -655,6 +656,11 @@ static void gnss_push_event(FAR void *priv, FAR const void *data,
lower = &upper->dev[GNSS_CLOCK_IDX].lower;
lower->push_event(lower->priv, data, bytes);
}
else if (type == SENSOR_TYPE_GNSS_GEOFENCE)
{
lower = &upper->dev[GNSS_GEOFENCE].lower;
lower->push_event(lower->priv, data, bytes);
}
nxmutex_unlock(&upper->lock);
}
@ -760,6 +766,19 @@ int gnss_register(FAR struct gnss_lowerhalf_s *lower, int devno,
goto gnss_clock_err;
}
/* GNSS Geofence */
dev = &upper->dev[GNSS_GEOFENCE];
dev->lower.ops = &g_gnss_sensor_ops;
dev->lower.type = SENSOR_TYPE_GNSS_GEOFENCE;
dev->lower.nbuffer = nbuffer;
dev->upper = upper;
ret = sensor_register(&dev->lower, devno);
if (ret < 0)
{
goto gnss_geofence_err;
}
ret = circbuf_init(&upper->buffer, NULL,
CONFIG_SENSORS_GNSS_RECV_BUFFERSIZE);
if (ret < 0)
@ -779,6 +798,8 @@ int gnss_register(FAR struct gnss_lowerhalf_s *lower, int devno,
driver_err:
circbuf_uninit(&upper->buffer);
circ_err:
sensor_unregister(&upper->dev[GNSS_GEOFENCE].lower, devno);
gnss_geofence_err:
sensor_unregister(&upper->dev[GNSS_CLOCK_IDX].lower, devno);
gnss_clock_err:
sensor_unregister(&upper->dev[GNSS_MEASUREMENT_IDX].lower, devno);
@ -816,6 +837,7 @@ void gnss_unregister(FAR struct gnss_lowerhalf_s *lower, int devno)
sensor_unregister(&upper->dev[GNSS_SATELLITE_IDX].lower, devno);
sensor_unregister(&upper->dev[GNSS_MEASUREMENT_IDX].lower, devno);
sensor_unregister(&upper->dev[GNSS_CLOCK_IDX].lower, devno);
sensor_unregister(&upper->dev[GNSS_GEOFENCE].lower, devno);
snprintf(path, PATH_MAX, GNSS_PATH_FMT, devno);
unregister_driver(path);
nxsem_destroy(&upper->buffersem);

View File

@ -195,6 +195,7 @@ static const struct sensor_meta_s g_sensor_meta[] =
{sizeof(struct sensor_gnss_satellite), "gnss_satellite"},
{sizeof(struct sensor_gnss_measurement), "gnss_measurement"},
{sizeof(struct sensor_gnss_clock), "gnss_clock"},
{sizeof(struct sensor_gnss_geofence_event), "gnss_geofence"},
};
static const struct file_operations g_sensor_fops =

View File

@ -313,9 +313,13 @@
#define SENSOR_TYPE_GNSS_CLOCK 36
/* GNSS Geofence */
#define SENSOR_TYPE_GNSS_GEOFENCE 37
/* The total number of sensor */
#define SENSOR_TYPE_COUNT 37
#define SENSOR_TYPE_COUNT 38
/* The additional sensor open flags */
@ -376,6 +380,40 @@
#define SENSOR_GNSS_MEASUREMENT_STATE_TOW_KNOWN (1 << 14)
#define SENSOR_GNSS_MEASUREMENT_STATE_GLO_TOD_KNOWN (1 << 15)
/* SENSOR_GNSS_GEOFENCE_TRANS_*:
* struct sensor_gnss_geofence_event -> transition
* Ref: android-14-release/hardware/libhardware/include/hardware/gnss-base.h
*/
#define SENSOR_GNSS_GEOFENCE_TRANS_ENTERED (1 << 0)
#define SENSOR_GNSS_GEOFENCE_TRANS_EXITED (1 << 1)
#define SENSOR_GNSS_GEOFENCE_TRANS_UNCERTAIN (1 << 2)
/* SENSOR_GNSS_GEOFENCE_STATUS_*:
* struct sensor_gnss_geofence_event -> status
* Ref: android-14-release/hardware/libhardware/include/hardware/gnss-base.h
*/
#define SENSOR_GNSS_GEOFENCE_STATUS_UNAVAILABLE (1 << 0)
#define SENSOR_GNSS_GEOFENCE_STATUS_AVAILABLE (1 << 1)
#define SENSOR_GNSS_GEOFENCE_STATUS_OPERATION_SUCCESS (0)
#define SENSOR_GNSS_GEOFENCE_STATUS_ERROR_TOO_MANY_GEOFENCES (-100)
#define SENSOR_GNSS_GEOFENCE_STATUS_ERROR_ID_EXISTS (-101)
#define SENSOR_GNSS_GEOFENCE_STATUS_ERROR_ID_UNKNOWN (-102)
#define SENSOR_GNSS_GEOFENCE_STATUS_ERROR_INVALID_TRANSITION (-103)
#define SENSOR_GNSS_GEOFENCE_STATUS_ERROR_GENERIC (-149)
/* SENSOR_GNSS_GEOFENCE_TYPE_*:
* `type` of `struct sensor_gnss_geofence_param` and
* `struct sensor_gnss_geofence_event`
*/
#define SENSOR_GNSS_GEOFENCE_TYPE_TRANSITION (1 << 0)
#define SENSOR_GNSS_GEOFENCE_TYPE_STATUS (1 << 1)
#define SENSOR_GNSS_GEOFENCE_TYPE_ADD (1 << 2)
#define SENSOR_GNSS_GEOFENCE_TYPE_REMOVE (1 << 3)
#define SENSOR_GNSS_GEOFENCE_TYPE_PAUSE (1 << 4)
#define SENSOR_GNSS_GEOFENCE_TYPE_RESUME (1 << 5)
/****************************************************************************
* Public Types
****************************************************************************/
@ -925,4 +963,65 @@ struct sensor_gnss_measurement
uint32_t snr;
};
/* GNSS Geofence parameters */
struct sensor_gnss_geofence_param
{
/* Type of events
* Available: see SENSOR_GNSS_GEOFENCE_TYPE_VALID_PARAM.
*
* Mandatory:
* |Fields \ Type |ADD |REMOVE |PAUSE |RESUME |
* |--------------|:--:|:-----:|:----:|:-----:|
* |geofence_id | v | v | v | v |
* |transition | v | | | v |
* |latitude | v | | | |
* |longitude | v | | | |
* |radius_meters | v | | | |
*/
int32_t type;
int32_t geofence_id;
float latitude;
float longitude;
float radius_meters;
/* Which transitions to monitor.
* Available: see SENSOR_GNSS_GEOFENCE_TRANS_*.
*/
int32_t transition;
};
/* GNSS Geofence events */
struct sensor_gnss_geofence_event
{
/* Type of events
* Fields below are optional according to this `type`,
* Available: see SENSOR_GNSS_GEOFENCE_TYPE_VALID_EVENT.
*
* Mandatory:
* |Fields \ Type |TRANSITION |STATUS |ADD |REMOVE |PAUSE |RESUME |
* |--------------|:---------:|:-----:|:--:|:-----:|:----:|:-----:|
* |geofence_id | v | | v | v | v | v |
* |transition | v | | | | | |
* |location | v | v | | | | |
* |timestamp | v | | | | | |
* |status | | v | v | v | v | v |
*/
int32_t type;
int32_t geofence_id; /* Id of the geofence. */
struct sensor_gnss location; /* Location. */
/* Milliseconds when the transition was detected since January 1, 1970 */
int64_t timestamp;
int32_t status; /* Status of Geofence operation/event. */
int32_t transition; /* See SENSOR_GNSS_GEOFENCE_TRANS_*. */
};
#endif /* __INCLUDE_NUTTX_SENSORS_SENSOR_H */