GPS机制分析(1)

1. android gps实现方案

整个流程图如下,

img

android 系统中高通定位方案架构图如下,

img

​ GPS Application(各种GPS定位的apk)都通过android系统的LocationManager对GPS进行打开/关闭/启动等操作。然后等待数据的上报。所以架构中有2个流程,由上往下的控制流,由下往上的数据流。

  1. GPS Application和LocationManagerService所在进程通过Binder机制进行跨进程调用。

  2. GpsLocationProvider和com_android_server_location_GpsLocationProvide以及com_android_server_location_GpsLocationProvide和gps.so库相互之间都是通过数据结构进行回调。其实, com_android_server_location_GpsLocationProvide只是Framework和HAL之间的一个桥梁。

  3. HAL的gps.so库和Modem通过高通的QMI机制进行数据传输,并且数据的格式是NMEA类型。

2. gps数据结构

​ \hardware\libhardware\include\hardware\gps.h,定义了GPS底层相关的结构体和接口;GpsLocation 包含经纬度海拔,速度,定位的精度等卫星信息;

typedef struct {
    size_t          size;
    uint16_t        flags;
    double          latitude;
    double          longitude;
    double          altitude;
    float           speed;
    float           bearing;
    float           accuracy;
    GpsUtcTime    timestamp;
} GpsLocation;

GpsStatus:GPS的状态;

typedef struct {
    size_t          size;
    GpsStatusValue status;
} GpsStatus;

status有未知、正在定位、停止定位、启动未定义、未启动五种状态,

typedef uint16_t GpsStatusValue;
#define GPS_STATUS_NONE             0
#define GPS_STATUS_SESSION_BEGIN    1
#define GPS_STATUS_SESSION_END      2
#define GPS_STATUS_ENGINE_ON        3
#define GPS_STATUS_ENGINE_OFF       4

GpsSvInfo 包含卫星ID、信噪比等信息,定义如下,

typedef struct {
    size_t          size;
    int     prn;
    float   snr;
    float   elevation;
    float   azimuth;
} GpsSvInfo;

GpsSvStatus 包含可视卫星数、星历时间、年历时间等信息;

typedef struct {
    size_t          size;
    int         num_svs;
    GpsSvInfo   sv_list[GPS_MAX_SVS];
    uint32_t    ephemeris_mask;
    uint32_t    almanac_mask;
    uint32_t    used_in_fix_mask;
} GpsSvStatus;

GpsCallbacks对应JNI的回调方法,

typedef struct {
    size_t      size;
    gps_location_callback location_cb;
    gps_status_callback status_cb;
    gps_sv_status_callback sv_status_cb;
    gps_nmea_callback nmea_cb;
    gps_set_capabilities set_capabilities_cb;
    gps_acquire_wakelock acquire_wakelock_cb;
    gps_release_wakelock release_wakelock_cb;
    gps_create_thread create_thread_cb;
    gps_request_utc_time request_utc_time_cb;
} GpsCallbacks;

GpsInterface:JNI层通过此接口与HAL进行交互;

typedef struct {
    size_t          size;
    int   (*init)( GpsCallbacks* callbacks );
    int   (*start)( void );
    int   (*stop)( void );
    void  (*cleanup)( void );
    int   (*inject_time)(GpsUtcTime time, int64_t timeReference,
                         int uncertainty);
    int  (*inject_location)(double latitude, double longitude, float accuracy);
    void  (*delete_aiding_data)(GpsAidingData flags);
    int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
            uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
    const void* (*get_extension)(const char* name);
} GpsInterface;

gps_device_t:GPS设备结构体,继承自hw_device_t,硬件适配接口,向上层提供了get_gps_interface接口;

struct gps_device_t {
    struct hw_device_t common;
    const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
};

小结:

  1. 介绍了android系统中gps的结构;

  2. 分析了gps中基本的数据结构以及含义。

猜你喜欢

转载自blog.csdn.net/Grekit_Sun/article/details/108509819
GPS
今日推荐