Android系统Gps分析(一)【转】

本文转载自:http://blog.csdn.net/xnwyd/article/details/7198728

目录(?)[+]

1 GPS架构

2 GPS分析

2.1 头文件

头文件定义在:hardware/libhardware/include/hardware/gps.h,定义了GPS底层相关的结构体和接口

  • GpsLocation

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

[cpp]  view plain   copy
  1. /** 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  
  15.   
  16. /** Represents a location. */  
  17. typedef struct {  
  18.     /** set to sizeof(GpsLocation) */  
  19.     size_t          size;  
  20.     /** Contains GpsLocationFlags bits. */  
  21.     uint16_t        flags;  
  22.     /** Represents latitude in degrees. */  
  23.     double          latitude;  
  24.     /** Represents longitude in degrees. */  
  25.     double          longitude;  
  26.     /** Represents altitude in meters above the WGS 84 reference 
  27.      * ellipsoid. */  
  28.     double          altitude;  
  29.     /** Represents speed in meters per second. */  
  30.     float           speed;  
  31.     /** Represents heading in degrees. */  
  32.     float           bearing;  
  33.     /** Represents expected accuracy in meters. */  
  34.     float           accuracy;  
  35.     /** Timestamp for the location fix. */  
  36.     GpsUtcTime      timestamp;  
  37. } GpsLocation;  
  • GpsStatus

GPS状态包括5种状态,分别为未知,正在定位,停止定位,启动未定义,未启动。

[cpp]  view plain   copy
  1. /** 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. */AgpsCallbacks  
  14.   
  15. AgpsInterface  
  16. #define GPS_STATUS_ENGINE_OFF       4  
  17.   
  18. /** Represents the status. */  
  19. typedef struct {  
  20.     /** set to sizeof(GpsStatus) */  
  21.     size_t          size;  
  22.     GpsStatusValue status;  
  23. } GpsStatus;  
  • GpsSvInfo

GPS卫星信息,包含卫星编号,信号强度,卫星仰望角,方位角等。

[cpp]  view plain   copy
  1. /** 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

GPS卫星状态,包含可见卫星数和信息,星历时间,年历时间等。

[cpp]  view plain   copy
  1. /** 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;  
  • GpsCallbacks

回调函数定义

[cpp]  view plain   copy
  1. /** Callback with location information. 向上层传递GPS位置信息 
  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. /** Callback with SV status information. 向上层传递GPS卫星信息 
  12.  *  Can only be called from a thread created by create_thread_cb. 
  13.  */  
  14. typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);  
  15.   
  16. /** Callback for reporting NMEA sentences. 向上层传递MEMA数据 
  17.  *  Can only be called from a thread created by create_thread_cb. 
  18.  */  
  19. typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);  
  20.   
  21. /** Callback to inform framework of the GPS engine's capabilities.告知GPS模块可以实现的功能 
  22.  *  Capability parameter is a bit field of GPS_CAPABILITY_* flags. 
  23.  */  
  24. typedef void (* gps_set_capabilities)(uint32_t capabilities);  
  25.   
  26. /** Callback utility for acquiring the GPS wakelock.上锁,防止处理GPS事件时中止。 
  27.  *  This can be used to prevent the CPU from suspending while handling GPS events. 
  28.  */  
  29. typedef void (* gps_acquire_wakelock)();  
  30.   
  31. /** Callback utility for releasing the GPS wakelock. */释放锁  
  32. typedef void (* gps_release_wakelock)();  
  33.   
  34. /** Callback for creating a thread that can call into the Java framework code.等待上层请求 
  35.  *  This must be used to create any threads that report events up to the framework. 
  36.  */  
  37. typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);  
  38.   
  39. /** GPS callback structure. */  
  40. typedef struct {  
  41.     /** set to sizeof(GpsCallbacks) */  
  42.     size_t      size;  
  43.     gps_location_callback location_cb;  
  44.     gps_status_callback status_cb;  
  45.     gps_sv_status_callback sv_status_cb;  
  46.     gps_nmea_callback nmea_cb;  
  47.     gps_set_capabilities set_capabilities_cb;  
  48.     gps_acquire_wakelock acquire_wakelock_cb;  
  49.     gps_release_wakelock release_wakelock_cb;  
  50.     gps_create_thread create_thread_cb;  
  51. } GpsCallbacks;  
  • GpsInterface

GPS接口是最重要的结构体,上层是通过此接口与硬件适配层交互的。

[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 implemenation 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. 关闭GPS接口*/  
  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.     /**设置定位模式和GPS工作模式等 
  39.      * min_interval represents the time between fixes in milliseconds. 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式小庄老师

要是觉得不错,就给我点支持吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值