Android GPS学习笔记(2)—重要结构体及接口

gps.h文件中定义了GPS底层相关的结构体和接口。

目录:hardware/libhardware/include/hardware/gps.h


1. 相关宏定义

  • 定位模式定义:GpsPositionMode

GPS定位模式分为:独立定位,MSB,MSA,其中独立定位表示只使用GPS芯片进行定位,MSB和MSA是AGPS定位的两种模式

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Requested operational mode for GPS operation. */  
  2. typedef uint32_t GpsPositionMode;  
  3. // IMPORTANT: Note that the following values must match  
  4. // constants in GpsLocationProvider.java.  
  5. /** Mode for running GPS standalone (no assistance). */  
  6. #define GPS_POSITION_MODE_STANDALONE    0  
  7. /** AGPS MS-Based mode. */  
  8. #define GPS_POSITION_MODE_MS_BASED      1  
  9. /** AGPS MS-Assisted mode. */  
  10. #define GPS_POSITION_MODE_MS_ASSISTED   2  
  • GPS工作模式定义:GpsPositionRecurrence

GPS工作模式分为周期定位和单次定位

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Requested recurrence mode for GPS operation. */  
  2. typedef uint32_t GpsPositionRecurrence;  
  3. // IMPORTANT: Note that the following values must match  
  4. // constants in GpsLocationProvider.java.  
  5. /** Receive GPS fixes on a recurring basis at a specified period. 周期性定位*/  
  6. #define GPS_POSITION_RECURRENCE_PERIODIC    0  
  7. /** Request a single shot GPS fix. 单次定位*/  
  8. #define GPS_POSITION_RECURRENCE_SINGLE      1  
  • GPS工作状态:GpsStatusValue

GPS工作状态分为:未知,正在定位,停止定位,启动未定义,未启动。

[java]  view plain copy
  1. <pre name="code" class="cpp">/** GPS status event values. */  
  2. typedef uint16_t GpsStatusValue;  
  3. // IMPORTANT: Note that the following values must match  
  4. // constants in GpsLocationProvider.java.  
  5. /** GPS status unknown. */  
  6. #define GPS_STATUS_NONE             0  
  7. /** GPS has begun navigating. */  
  8. #define GPS_STATUS_SESSION_BEGIN    1  
  9. /** GPS has stopped navigating. */  
  10. #define GPS_STATUS_SESSION_END      2  
  11. /** GPS has powered on but is not navigating. */  
  12. #define GPS_STATUS_ENGINE_ON        3  
  13. /** GPS is powered off. */  
  14. #define GPS_STATUS_ENGINE_OFF       4  
  • Location信息标志位

表明位置信息中哪些信息是可获得的

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Flags to indicate which values are valid in a GpsLocation. */  
  2. typedef uint16_t GpsLocationFlags;  
  3. // IMPORTANT: Note that the following values must match  
  4. // constants in GpsLocationProvider.java.  
  5. /** GpsLocation has valid latitude and longitude. */  
  6. #define GPS_LOCATION_HAS_LAT_LONG   0x0001  
  7. /** GpsLocation has valid altitude. */  
  8. #define GPS_LOCATION_HAS_ALTITUDE   0x0002  
  9. /** GpsLocation has valid speed. */  
  10. #define GPS_LOCATION_HAS_SPEED      0x0004  
  11. /** GpsLocation has valid bearing. */  
  12. #define GPS_LOCATION_HAS_BEARING    0x0008  
  13. /** GpsLocation has valid accuracy. */  
  14. #define GPS_LOCATION_HAS_ACCURACY   0x0010  
  • gps_set_capabilities 回调标志位

表示GPS芯片可以处理的能力

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Flags for the gps_set_capabilities callback. */  
  2.   
  3. /** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode. 
  4.     If this is not set, then the framework will use 1000ms for min_interval 
  5.     and will start and call start() and stop() to schedule the GPS. 
  6.  */  
  7. #define GPS_CAPABILITY_SCHEDULING       0x0000001  
  8. /** GPS supports MS-Based AGPS mode */  
  9. #define GPS_CAPABILITY_MSB              0x0000002  
  10. /** GPS supports MS-Assisted AGPS mode */  
  11. #define GPS_CAPABILITY_MSA              0x0000004  
  12. /** GPS supports single-shot fixes */  
  13. #define GPS_CAPABILITY_SINGLE_SHOT      0x0000008  
  14. /** GPS supports on demand time injection */  
  15. #define GPS_CAPABILITY_ON_DEMAND_TIME   0x0000010  
  16. /** GPS supports Geofencing  */  
  17. #define GPS_CAPABILITY_GEOFENCING       0x0000020  
  18. /** GPS supports Measurements */  
  19. #define GPS_CAPABILITY_MEASUREMENTS     0x0000040  
  20. /** GPS supports Navigation Messages */  
  21. #define GPS_CAPABILITY_NAV_MESSAGES     0x0000080  
  • 辅助数据

当调用函数delete_aiding_data()函数时用来区分删除哪种辅助数据

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Flags used to specify which aiding data to delete 
  2.     when calling delete_aiding_data(). */  
  3. typedef uint16_t GpsAidingData;  
  4. // IMPORTANT: Note that the following values must match  
  5. // constants in GpsLocationProvider.java.  
  6. #define GPS_DELETE_EPHEMERIS        0x0001  
  7. #define GPS_DELETE_ALMANAC          0x0002  
  8. #define GPS_DELETE_POSITION         0x0004  
  9. #define GPS_DELETE_TIME             0x0008  
  10. #define GPS_DELETE_IONO             0x0010  
  11. #define GPS_DELETE_UTC              0x0020  
  12. #define GPS_DELETE_HEALTH           0x0040  
  13. #define GPS_DELETE_SVDIR            0x0080  
  14. #define GPS_DELETE_SVSTEER          0x0100  
  15. #define GPS_DELETE_SADATA           0x0200  
  16. #define GPS_DELETE_RTI              0x0400  
  17. #define GPS_DELETE_CELLDB_INFO      0x8000  
  18. #define GPS_DELETE_ALL              0xFFFF  
  • AGPS状态事件标志
[java]  view plain copy
  1. <pre name="code" class="cpp">/** AGPS status event values. */  
  2. typedef uint16_t AGpsStatusValue;  
  3. /** GPS requests data connection for AGPS. */  
  4. #define GPS_REQUEST_AGPS_DATA_CONN  1  
  5. /** GPS releases the AGPS data connection. */  
  6. #define GPS_RELEASE_AGPS_DATA_CONN  2  
  7. /** AGPS data connection initiated */  
  8. #define GPS_AGPS_DATA_CONNECTED     3  
  9. /** AGPS data connection completed */  
  10. #define GPS_AGPS_DATA_CONN_DONE     4  
  11. /** AGPS data connection failed */  
  12. #define GPS_AGPS_DATA_CONN_FAILED   5  
还有很多的宏定义在此不一一列举,在gps.h中有很好的解释。

2. 数据结构体

  • GpsLocation

GPS位置信息的结构体,包含经纬度、高度、速度、方位角等

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Represents a location. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsLocation) */  
  4.     size_t          size;  
  5.     /** Contains GpsLocationFlags bits. */  
  6.     uint16_t        flags;  
  7.     /** Represents latitude in degrees. */  
  8.     double          latitude;  
  9.     /** Represents longitude in degrees. */  
  10.     double          longitude;  
  11.     /** Represents altitude in meters above the WGS 84 reference 
  12.      * ellipsoid. */  
  13.     double          altitude;  
  14.     /** Represents speed in meters per second. */  
  15.     float           speed;  
  16.     /** Represents heading in degrees. */  
  17.     float           bearing;  
  18.     /** Represents expected accuracy in meters. */  
  19.     float           accuracy;  
  20.     /** Timestamp for the location fix. */  
  21.     GpsUtcTime      timestamp;  
  22. } GpsLocation;  
  • GpsStatus

GPS工作状态分为:未知,正在定位,停止定位,启动未定义,未启动。(见前文宏定义)

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Represents the status. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsStatus) */  
  4.     size_t          size;  
  5.     GpsStatusValue status;  
  6. } GpsStatus;  
  • GpsSvInfo

表示当前的卫星信息:卫星编号,信号强度,仰望角,方位角

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Represents SV information. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsSvInfo) */  
  4.     size_t          size;  
  5.     /** Pseudo-random number for the SV. */  
  6.     int     prn;  
  7.     /** Signal to noise ratio. */  
  8.     float   snr;  
  9.     /** Elevation of SV in degrees. */  
  10.     float   elevation;  
  11.     /** Azimuth of SV in degrees. */  
  12.     float   azimuth;  
  13. } GpsSvInfo;  
  • GpsSvStatus

表示卫星状态,包含了GpsSvInfo结构,可见卫星数,星历时间,年历时间,与用来定位的卫星构成的一个掩码

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Represents SV status. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsSvStatus) */  
  4.     size_t          size;  
  5.   
  6.     /** Number of SVs currently visible. */  
  7.     int         num_svs;  
  8.   
  9.     /** Contains an array of SV information. */  
  10.     GpsSvInfo   sv_list[GPS_MAX_SVS];  
  11.   
  12.     /** Represents a bit mask indicating which SVs 
  13.      * have ephemeris data. 
  14.      */  
  15.     uint32_t    ephemeris_mask;  
  16.   
  17.     /** Represents a bit mask indicating which SVs 
  18.      * have almanac data. 
  19.      */  
  20.     uint32_t    almanac_mask;  
  21.   
  22.     /** 
  23.      * Represents a bit mask indicating which SVs 
  24.      * were used for computing the most recent position fix. 
  25.      */  
  26.     uint32_t    used_in_fix_mask;  
  27. } GpsSvStatus;  
  • AGpsRefLocation

定义AGPS相关的cell ID 和mac地址

[java]  view plain copy
  1. <pre name="code" class="cpp">/* 2G and 3G */  
  2. /* In 3G lac is discarded */  
  3. typedef struct {  
  4.     uint16_t type;  
  5.     uint16_t mcc;  
  6.     uint16_t mnc;  
  7.     uint16_t lac;  
  8.     uint32_t cid;  
  9. } AGpsRefLocationCellID;  
  10.   
  11. typedef struct {  
  12.     uint8_t mac[6];  
  13. } AGpsRefLocationMac;  
  14.   
  15. /** Represents ref locations */  
  16. typedef struct {  
  17.     uint16_t type;  
  18.     union {  
  19.         AGpsRefLocationCellID   cellID;  
  20.         AGpsRefLocationMac      mac;  
  21.     } u;  
  22. } AGpsRefLocation;  

3. 回调函数指针定义

[cpp]  view plain copy
  1. /** Callback with location information.告知上层位置信息 
  2.  *  Can only be called from a thread created by create_thread_cb. 
  3.  */  
  4. typedef void (* gps_location_callback)(GpsLocation* location);  
  5.   
  6. /** Callback with status information.GPS状态信息回调 
  7.  *  Can only be called from a thread created by create_thread_cb. 
  8.  */  
  9. typedef void (* gps_status_callback)(GpsStatus* status);  
  10.   
  11. /** 
  12.  * Callback with SV status information.卫星状态信息回调 
  13.  * Can only be called from a thread created by create_thread_cb. 
  14.  */  
  15. typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);  
  16.   
  17. /** Callback for reporting NMEA sentences.向上层传递NMEA信息 
  18.  *  Can only be called from a thread created by create_thread_cb. 
  19.  */  
  20. typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);  
  21.   
  22. /** Callback to inform framework of the GPS engine's capabilities. 
  23.  *  告知上层GPS可以实现的功能 
  24.  *Capability parameter is a bit field of GPS_CAPABILITY_* flags. 
  25.  */  
  26. typedef void (* gps_set_capabilities)(uint32_t capabilities);  
  27.   
  28. /** Callback utility for acquiring the GPS wakelock.GPS上锁,防止被suspend 
  29.  *  This can be used to prevent the CPU from suspending while handling GPS events. 
  30.  */  
  31. typedef void (* gps_acquire_wakelock)();  
  32.   
  33. /** Callback utility for releasing the GPS wakelock.释放锁 */  
  34. typedef void (* gps_release_wakelock)();  
  35.   
  36. /** Callback for requesting NTP time 回调请求NTP时间*/  
  37. typedef void (* gps_request_utc_time)();  
  38.   
  39. /** Callback for creating a thread that can call into the Java framework code. 
  40.  *  创建线程来响应framework层的请求 
  41.  *  This must be used to create any threads that report events up to the framework. 
  42.  */  
  43. typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);  


3. 接口结构体

  • GpsCallbacks

就是上文函数指针组成的结构体,是一组回调函数,函数的实现在JNI层:com_android_server_location_GpsLocationProvider.cpp,GOOGLE已经实现好,无需做(太大)修改

[cpp]  view plain copy
  1. /** GPS callback structure. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsCallbacks) */  
  4.     size_t      size;  
  5.     gps_location_callback location_cb;  
  6.     gps_status_callback status_cb;  
  7.     gps_sv_status_callback sv_status_cb;  
  8.     gps_nmea_callback nmea_cb;  
  9.     gps_set_capabilities set_capabilities_cb;  
  10.     gps_acquire_wakelock acquire_wakelock_cb;  
  11.     gps_release_wakelock release_wakelock_cb;  
  12.     gps_create_thread create_thread_cb;  
  13.     gps_request_utc_time request_utc_time_cb;  
  14. } GpsCallbacks;  
  • GpsInterface

GpsInterface接口是Android GPS 模块最重要的数据结构,它是底层驱动实现的接口,如果要porting到自己的板子上,就需要实现这些接口。

[cpp]  view plain copy
  1. /** Represents the standard GPS interface. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsInterface) */  
  4.     size_t          size;  
  5.     /** 
  6.      * Opens the interface and provides the callback routines 
  7.      * to the implementation of this interface. 
  8.      */  
  9.     int   (*init)( GpsCallbacks* callbacks );  
  10.   
  11.     /** Starts navigating. 开始定位*/  
  12.     int   (*start)( void );  
  13.   
  14.     /** Stops navigating. 停止定位*/  
  15.     int   (*stop)( void );  
  16.   
  17.     /** Closes the interface. 关闭接口*/  
  18.     void  (*cleanup)( void );  
  19.   
  20.     /** Injects the current time. 注入当前时间*/  
  21.     int   (*inject_time)(GpsUtcTime time, int64_t timeReference,  
  22.                          int uncertainty);  
  23.   
  24.     /** Injects current location from another location provider 
  25.      *  (typically cell ID).注入位置信息 
  26.      *  latitude and longitude are measured in degrees 
  27.      *  expected accuracy is measured in meters 
  28.      */  
  29.     int  (*inject_location)(double latitude, double longitude, float accuracy);  
  30.   
  31.     /** 
  32.      * Specifies that the next call to start will not use the 
  33.      * information defined in the flags. GPS_DELETE_ALL is passed for 
  34.      * a cold start.删除辅助数据 
  35.      */  
  36.     void  (*delete_aiding_data)(GpsAidingData flags);  
  37.   
  38.     /** 
  39.      * min_interval represents the time between fixes in milliseconds. 
  40.      * preferred_accuracy represents the requested fix accuracy in meters. 
  41.      * preferred_time represents the requested time to first fix in milliseconds. 
  42.      * 设置定位模式 
  43.      */  
  44.     int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,  
  45.             uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);  
  46.   
  47.     /** Get a pointer to extension information. 自行添加接口实现*/  
  48.     const void* (*get_extension)(const char* name);  
  49. } GpsInterface;  
  • GpsXtraCallbacks

高通XTRA加速定位技术回调函数结构体

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Callback structure for the XTRA interface. */  
  2. typedef struct {  
  3.     gps_xtra_download_request download_request_cb;  
  4.     gps_create_thread create_thread_cb;  
  5. } GpsXtraCallbacks;  
  • GpsXtraInterface

高通XTRA加速定位技术接口

[cpp]  view plain copy
  1. /** Extended interface for XTRA support. */  
  2. typedef struct {  
  3.     /** set to sizeof(GpsXtraInterface) */  
  4.     size_t          size;  
  5.     /** 
  6.      * Opens the XTRA interface and provides the callback routines 
  7.      * to the implementation of this interface. 
  8.      */  
  9.     int  (*init)( GpsXtraCallbacks* callbacks );  
  10.     /** Injects XTRA data into the GPS. */  
  11.     int  (*inject_xtra_data)( char* data, int length );  
  12. } GpsXtraInterface;  
  • AGpsInterface

AGPS加速定位技术接口结构体

[java]  view plain copy
  1. <pre name="code" class="cpp">/** Extended interface for AGPS support. */  
  2. typedef struct {  
  3.     /** set to sizeof(AGpsInterface_v1) */  
  4.     size_t          size;  
  5.   
  6.     /** 
  7.      * Opens the AGPS interface and provides the callback routines 
  8.      * to the implementation of this interface. 
  9.      */  
  10.     void  (*init)( AGpsCallbacks* callbacks );  
  11.     /** 
  12.      * Notifies that a data connection is available and sets 
  13.      * the name of the APN to be used for SUPL. 
  14.      */  
  15.     int  (*data_conn_open)( const char* apn );  
  16.     /** 
  17.      * Notifies that the AGPS data connection has been closed. 
  18.      */  
  19.     int  (*data_conn_closed)();  
  20.     /** 
  21.      * Notifies that a data connection is not available for AGPS. 
  22.      */  
  23.     int  (*data_conn_failed)();  
  24.     /** 
  25.      * Sets the hostname and port for the AGPS server. 
  26.      */  
  27.     int  (*set_server)( AGpsType type, const char* hostname, int port );  
  28. } AGpsInterface;  
  • GpsNiInterface

网络端发起的定位接口结构体

[cpp]  view plain copy
  1. /** 
  2.  * Extended interface for Network-initiated (NI) support. 
  3.  */  
  4. typedef struct  
  5. {  
  6.     /** set to sizeof(GpsNiInterface) */  
  7.     size_t          size;  
  8.   
  9.    /** Registers the callbacks for HAL to use. */  
  10.    void (*init) (GpsNiCallbacks *callbacks);  
  11.   
  12.    /** Sends a response to HAL. */  
  13.    void (*respond) (int notif_id, GpsUserResponseType user_response);  
  14. } GpsNiInterface;  
  • gps_device_t

定义描述GPS设备类型

[cpp]  view plain copy
  1. struct gps_device_t {  
  2.     struct hw_device_t common;  
  3.   
  4.     /** 
  5.      * Set the provided lights to the provided values. 
  6.      * 
  7.      * Returns: 0 on succes, error code on failure. 
  8.      */  
  9.     const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);  
  10. };  

其他接口在此不再赘述。


原文:http://blog.csdn.net/dreamback1987/article/details/46558835

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值