Optimized GPS sensor and add gps satellite sensor.

Signed-off-by: buyuer <dingddding@163.com>
This commit is contained in:
buyuer 2021-11-17 10:04:50 +08:00 committed by Xiang Xiao
parent a799835ec6
commit fa90a3dfd4
4 changed files with 104 additions and 60 deletions

View File

@ -207,7 +207,7 @@ static inline void fakesensor_read_gps(FAR struct fakesensor_s *sensor)
gps.latitude /= 100.0f;
gps.longitude /= 100.0f;
gps.height = altitude;
gps.altitude = altitude;
sensor->lower.push_event(sensor->lower.priv, &gps,
sizeof(struct sensor_event_gps));

View File

@ -100,35 +100,36 @@ static int sensor_poll(FAR struct file *filep, FAR struct pollfd *fds,
static const struct sensor_info g_sensor_info[] =
{
{0, NULL},
{sizeof(struct sensor_event_accel), "accel"},
{sizeof(struct sensor_event_mag), "mag"},
{sizeof(struct sensor_event_gyro), "gyro"},
{sizeof(struct sensor_event_light), "light"},
{sizeof(struct sensor_event_baro), "baro"},
{sizeof(struct sensor_event_prox), "prox"},
{sizeof(struct sensor_event_humi), "humi"},
{sizeof(struct sensor_event_temp), "temp"},
{sizeof(struct sensor_event_rgb), "rgb"},
{sizeof(struct sensor_event_hall), "hall"},
{sizeof(struct sensor_event_ir), "ir"},
{sizeof(struct sensor_event_gps), "gps"},
{sizeof(struct sensor_event_uv), "uv"},
{sizeof(struct sensor_event_noise), "noise"},
{sizeof(struct sensor_event_pm25), "pm25"},
{sizeof(struct sensor_event_pm1p0), "pm1p0"},
{sizeof(struct sensor_event_pm10), "pm10"},
{sizeof(struct sensor_event_co2), "co2"},
{sizeof(struct sensor_event_hcho), "hcho"},
{sizeof(struct sensor_event_tvoc), "tvoc"},
{sizeof(struct sensor_event_ph), "ph"},
{sizeof(struct sensor_event_dust), "dust"},
{sizeof(struct sensor_event_hrate), "hrate"},
{sizeof(struct sensor_event_hbeat), "hbeat"},
{sizeof(struct sensor_event_ecg), "ecg"},
{sizeof(struct sensor_event_ppg), "ppg"},
{sizeof(struct sensor_event_impd), "impd"},
{sizeof(struct sensor_event_ots), "ots"},
{0, NULL},
{sizeof(struct sensor_event_accel), "accel"},
{sizeof(struct sensor_event_mag), "mag"},
{sizeof(struct sensor_event_gyro), "gyro"},
{sizeof(struct sensor_event_light), "light"},
{sizeof(struct sensor_event_baro), "baro"},
{sizeof(struct sensor_event_prox), "prox"},
{sizeof(struct sensor_event_humi), "humi"},
{sizeof(struct sensor_event_temp), "temp"},
{sizeof(struct sensor_event_rgb), "rgb"},
{sizeof(struct sensor_event_hall), "hall"},
{sizeof(struct sensor_event_ir), "ir"},
{sizeof(struct sensor_event_gps), "gps"},
{sizeof(struct sensor_event_uv), "uv"},
{sizeof(struct sensor_event_noise), "noise"},
{sizeof(struct sensor_event_pm25), "pm25"},
{sizeof(struct sensor_event_pm1p0), "pm1p0"},
{sizeof(struct sensor_event_pm10), "pm10"},
{sizeof(struct sensor_event_co2), "co2"},
{sizeof(struct sensor_event_hcho), "hcho"},
{sizeof(struct sensor_event_tvoc), "tvoc"},
{sizeof(struct sensor_event_ph), "ph"},
{sizeof(struct sensor_event_dust), "dust"},
{sizeof(struct sensor_event_hrate), "hrate"},
{sizeof(struct sensor_event_hbeat), "hbeat"},
{sizeof(struct sensor_event_ecg), "ecg"},
{sizeof(struct sensor_event_ppg), "ppg"},
{sizeof(struct sensor_event_impd), "impd"},
{sizeof(struct sensor_event_ots), "ots"},
{sizeof(struct sensor_event_gps_satellite), "gps_satellite"},
};
static const struct file_operations g_sensor_fops =

View File

@ -303,22 +303,15 @@ static void wtgahrs2_gps_data(FAR struct wtgahrs2_dev_s *rtdata,
{
case WTGAHRS2_GPS0_INFO:
rtdata->gps_mask |= WTGAHRS2_GPS0_MASK;
rtdata->gps.year = 2000 + buffer[0];
rtdata->gps.month = buffer[1];
rtdata->gps.day = buffer[2];
rtdata->gps.hour = buffer[3];
rtdata->gps.min = buffer[4];
rtdata->gps.sec = buffer[5];
rtdata->gps.msec = (buffer[7] << 8) | buffer[6];
break;
case WTGAHRS2_GPS1_INFO:
rtdata->gps_mask |= WTGAHRS2_GPS1_MASK;
rtdata->gps.longitude = (long)(buffer[3] << 8
rtdata->gps.longitude = (buffer[3] << 8
| buffer[2] << 8
| buffer[1] << 8
| buffer[0]) / 10000000.0f;
rtdata->gps.latitude = (long)(buffer[7] << 8
rtdata->gps.latitude = (buffer[7] << 8
| buffer[6] << 8
| buffer[5] << 8
| buffer[4]) / 10000000.0f;
@ -326,9 +319,8 @@ static void wtgahrs2_gps_data(FAR struct wtgahrs2_dev_s *rtdata,
case WTGAHRS2_GPS2_INFO:
rtdata->gps_mask |= WTGAHRS2_GPS2_MASK;
rtdata->gps.height = (short)(buffer[1] << 8 | buffer[0]) / 10.0f;
rtdata->gps.yaw = (short)(buffer[3] << 8 | buffer[2]) / 10.0f;
rtdata->gps.speed = (long)(buffer[7] << 8 | buffer[6] << 8
rtdata->gps.altitude = (float)(buffer[1] << 8 | buffer[0]) / 10.0f;
rtdata->gps.ground_speed = (float)(buffer[7] << 8 | buffer[6] << 8
| buffer[5] << 8 | buffer[4]) / 3600.0f;
break;
}
@ -337,13 +329,12 @@ static void wtgahrs2_gps_data(FAR struct wtgahrs2_dev_s *rtdata,
{
rtdata->gps_mask = 0;
lower->push_event(lower->priv, &rtdata->gps, sizeof(rtdata->gps));
sninfo("Time : %d/%d/%d-%d:%d:%d\n", rtdata->gps.year,
rtdata->gps.month, rtdata->gps.day, rtdata->gps.hour,
rtdata->gps.min, rtdata->gps.sec);
sninfo("Time : %llu utc_time: %llu\n",
rtdata->gps.timestamp, rtdata->gps.time_utc);
sninfo("GPS longitude : %fdegree, latitude:%fdegree\n",
rtdata->gps.longitude, rtdata->gps.latitude);
sninfo("GPS speed: %fm/s, yaw:%fdegrees, height:%fm \n",
rtdata->gps.speed, rtdata->gps.yaw, rtdata->gps.height);
sninfo("GPS speed: %fm/s, altitude: %fm \n",
rtdata->gps.ground_speed, rtdata->gps.altitude);
}
}

View File

@ -125,8 +125,9 @@
#define SENSOR_TYPE_IR 11
/* GPS
* A sensor of this type returns gps data. Include year, month, day,
* hour, minutes, seconds, altitude, longitude, latitude.
* A sensor of this type returns gps data. Include latitude, longitude,
* altitude, horizontal position accuracy, vertical position accuracy,
* horizontal dilution of precision, vertical dilution of precision...
*/
#define SENSOR_TYPE_GPS 12
@ -254,9 +255,15 @@
#define SENSOR_TYPE_OTS 28
/* Sensor of gps satellite
* A sensor of this type returns the gps satellite information.
*/
#define SENSOR_TYPE_GPS_SATELLITE 29
/* The total number of sensor */
#define SENSOR_TYPE_COUNT 29
#define SENSOR_TYPE_COUNT 30
/****************************************************************************
* Inline Functions
@ -364,19 +371,35 @@ struct sensor_event_ir /* Type: Infrared Ray */
struct sensor_event_gps /* Type: Gps */
{
int year; /* Time */
int month;
int day;
int hour;
int min;
int sec;
int msec;
uint64_t timestamp; /* Time since system start, Units is microseconds */
/* This is the timestamp which comes from the gps module. It might be
* unavailable right after cold start, indicated by a value of 0,
* Units is microseconds
*/
uint64_t time_utc;
float yaw; /* Unit is Si degrees */
float height; /* Unit is SI m */
float speed; /* Unit is m/s */
float latitude; /* Unit is degrees */
float longitude; /* Unit is degrees */
float altitude; /* Altitude above MSL(mean seal level), Unit is SI m */
float altitude_ellipsoid; /* Altitude bove Ellipsoid, Unit is SI m */
float eph; /* GPS horizontal position accuracy (metres) */
float epv; /* GPS vertical position accuracy (metres) */
float hdop; /* Horizontal dilution of precision */
float vdop; /* Vertical dilution of precision */
float ground_speed; /* GPS ground speed, Unit is m/s */
/* Course over ground (NOT heading, but direction of movement),
* Unit is Si degrees
*/
float course;
uint32_t satellites_used; /* Number of satellites used */
};
struct sensor_event_uv /* Type: Ultraviolet Light */
@ -477,6 +500,35 @@ struct sensor_event_ots /* Type: OTS */
int32_t y; /* Axis Y in counts */
};
struct sensor_event_gps_satellite
{
uint64_t timestamp; /* Time since system start, Units is microseconds */
uint32_t count; /* Total number of messages of satellites visible */
uint32_t satellites; /* Total number of satellites in view */
struct satellite
{
uint32_t svid; /* Space vehicle ID */
/* Elevation (0: right on top of receiver,
* 90: on the horizon) of satellite
*/
uint32_t elevation;
/* Direction of satellite, 0: 0 deg, 255: 360 deg. */
uint32_t azimuth;
/* dBHz, Signal to noise ratio of satellite C/N0, range 0..99,
* zero when not tracking this satellite
*/
uint32_t snr;
}
info[4];
};
/* The sensor lower half driver interface */
struct sensor_lowerhalf_s;