gps.h文件中定义了GPS底层相关的结构体和接口。
目录:hardware/libhardware/include/hardware/gps.h
1. 相关宏定义
- 定位模式定义:GpsPositionMode
GPS定位模式分为:独立定位,MSB,MSA,其中独立定位表示只使用GPS芯片进行定位,MSB和MSA是AGPS定位的两种模式
- <pre name="code" class="cpp">/** Requested operational mode for GPS operation. */
- typedef uint32_t GpsPositionMode;
- // IMPORTANT: Note that the following values must match
- // constants in GpsLocationProvider.java.
- /** Mode for running GPS standalone (no assistance). */
- #define GPS_POSITION_MODE_STANDALONE 0
- /** AGPS MS-Based mode. */
- #define GPS_POSITION_MODE_MS_BASED 1
- /** AGPS MS-Assisted mode. */
- #define GPS_POSITION_MODE_MS_ASSISTED 2
- GPS工作模式定义:GpsPositionRecurrence
GPS工作模式分为周期定位和单次定位
- <pre name="code" class="cpp">/** Requested recurrence mode for GPS operation. */
- typedef uint32_t GpsPositionRecurrence;
- // IMPORTANT: Note that the following values must match
- // constants in GpsLocationProvider.java.
- /** Receive GPS fixes on a recurring basis at a specified period. 周期性定位*/
- #define GPS_POSITION_RECURRENCE_PERIODIC 0
- /** Request a single shot GPS fix. 单次定位*/
- #define GPS_POSITION_RECURRENCE_SINGLE 1
- GPS工作状态:GpsStatusValue
GPS工作状态分为:未知,正在定位,停止定位,启动未定义,未启动。
- <pre name="code" class="cpp">/** GPS status event values. */
- typedef uint16_t GpsStatusValue;
- // IMPORTANT: Note that the following values must match
- // constants in GpsLocationProvider.java.
- /** GPS status unknown. */
- #define GPS_STATUS_NONE 0
- /** GPS has begun navigating. */
- #define GPS_STATUS_SESSION_BEGIN 1
- /** GPS has stopped navigating. */
- #define GPS_STATUS_SESSION_END 2
- /** GPS has powered on but is not navigating. */
- #define GPS_STATUS_ENGINE_ON 3
- /** GPS is powered off. */
- #define GPS_STATUS_ENGINE_OFF 4
- Location信息标志位
表明位置信息中哪些信息是可获得的
- <pre name="code" class="cpp">/** Flags to indicate which values are valid in a GpsLocation. */
- typedef uint16_t GpsLocationFlags;
- // IMPORTANT: Note that the following values must match
- // constants in GpsLocationProvider.java.
- /** GpsLocation has valid latitude and longitude. */
- #define GPS_LOCATION_HAS_LAT_LONG 0x0001
- /** GpsLocation has valid altitude. */
- #define GPS_LOCATION_HAS_ALTITUDE 0x0002
- /** GpsLocation has valid speed. */
- #define GPS_LOCATION_HAS_SPEED 0x0004
- /** GpsLocation has valid bearing. */
- #define GPS_LOCATION_HAS_BEARING 0x0008
- /** GpsLocation has valid accuracy. */
- #define GPS_LOCATION_HAS_ACCURACY 0x0010
- gps_set_capabilities 回调标志位
表示GPS芯片可以处理的能力
- <pre name="code" class="cpp">/** Flags for the gps_set_capabilities callback. */
- /** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
- If this is not set, then the framework will use 1000ms for min_interval
- and will start and call start() and stop() to schedule the GPS.
- */
- #define GPS_CAPABILITY_SCHEDULING 0x0000001
- /** GPS supports MS-Based AGPS mode */
- #define GPS_CAPABILITY_MSB 0x0000002
- /** GPS supports MS-Assisted AGPS mode */
- #define GPS_CAPABILITY_MSA 0x0000004
- /** GPS supports single-shot fixes */
- #define GPS_CAPABILITY_SINGLE_SHOT 0x0000008
- /** GPS supports on demand time injection */
- #define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010
- /** GPS supports Geofencing */
- #define GPS_CAPABILITY_GEOFENCING 0x0000020
- /** GPS supports Measurements */
- #define GPS_CAPABILITY_MEASUREMENTS 0x0000040
- /** GPS supports Navigation Messages */
- #define GPS_CAPABILITY_NAV_MESSAGES 0x0000080
- 辅助数据
当调用函数delete_aiding_data()函数时用来区分删除哪种辅助数据
- <pre name="code" class="cpp">/** Flags used to specify which aiding data to delete
- when calling delete_aiding_data(). */
- typedef uint16_t GpsAidingData;
- // IMPORTANT: Note that the following values must match
- // constants in GpsLocationProvider.java.
- #define GPS_DELETE_EPHEMERIS 0x0001
- #define GPS_DELETE_ALMANAC 0x0002
- #define GPS_DELETE_POSITION 0x0004
- #define GPS_DELETE_TIME 0x0008
- #define GPS_DELETE_IONO 0x0010
- #define GPS_DELETE_UTC 0x0020
- #define GPS_DELETE_HEALTH 0x0040
- #define GPS_DELETE_SVDIR 0x0080
- #define GPS_DELETE_SVSTEER 0x0100
- #define GPS_DELETE_SADATA 0x0200
- #define GPS_DELETE_RTI 0x0400
- #define GPS_DELETE_CELLDB_INFO 0x8000
- #define GPS_DELETE_ALL 0xFFFF
- AGPS状态事件标志
- <pre name="code" class="cpp">/** AGPS status event values. */
- typedef uint16_t AGpsStatusValue;
- /** GPS requests data connection for AGPS. */
- #define GPS_REQUEST_AGPS_DATA_CONN 1
- /** GPS releases the AGPS data connection. */
- #define GPS_RELEASE_AGPS_DATA_CONN 2
- /** AGPS data connection initiated */
- #define GPS_AGPS_DATA_CONNECTED 3
- /** AGPS data connection completed */
- #define GPS_AGPS_DATA_CONN_DONE 4
- /** AGPS data connection failed */
- #define GPS_AGPS_DATA_CONN_FAILED 5
2. 数据结构体
- GpsLocation
GPS位置信息的结构体,包含经纬度、高度、速度、方位角等
- <pre name="code" class="cpp">/** Represents a location. */
- typedef struct {
- /** set to sizeof(GpsLocation) */
- size_t size;
- /** Contains GpsLocationFlags bits. */
- uint16_t flags;
- /** Represents latitude in degrees. */
- double latitude;
- /** Represents longitude in degrees. */
- double longitude;
- /** Represents altitude in meters above the WGS 84 reference
- * ellipsoid. */
- double altitude;
- /** Represents speed in meters per second. */
- float speed;
- /** Represents heading in degrees. */
- float bearing;
- /** Represents expected accuracy in meters. */
- float accuracy;
- /** Timestamp for the location fix. */
- GpsUtcTime timestamp;
- } GpsLocation;
- GpsStatus
GPS工作状态分为:未知,正在定位,停止定位,启动未定义,未启动。(见前文宏定义)
- <pre name="code" class="cpp">/** Represents the status. */
- typedef struct {
- /** set to sizeof(GpsStatus) */
- size_t size;
- GpsStatusValue status;
- } GpsStatus;
- GpsSvInfo
表示当前的卫星信息:卫星编号,信号强度,仰望角,方位角
- <pre name="code" class="cpp">/** Represents SV information. */
- typedef struct {
- /** set to sizeof(GpsSvInfo) */
- size_t size;
- /** Pseudo-random number for the SV. */
- int prn;
- /** Signal to noise ratio. */
- float snr;
- /** Elevation of SV in degrees. */
- float elevation;
- /** Azimuth of SV in degrees. */
- float azimuth;
- } GpsSvInfo;
- GpsSvStatus
表示卫星状态,包含了GpsSvInfo结构,可见卫星数,星历时间,年历时间,与用来定位的卫星构成的一个掩码
- <pre name="code" class="cpp">/** Represents SV status. */
- typedef struct {
- /** set to sizeof(GpsSvStatus) */
- size_t size;
- /** Number of SVs currently visible. */
- int num_svs;
- /** Contains an array of SV information. */
- GpsSvInfo sv_list[GPS_MAX_SVS];
- /** Represents a bit mask indicating which SVs
- * have ephemeris data.
- */
- uint32_t ephemeris_mask;
- /** Represents a bit mask indicating which SVs
- * have almanac data.
- */
- uint32_t almanac_mask;
- /**
- * Represents a bit mask indicating which SVs
- * were used for computing the most recent position fix.
- */
- uint32_t used_in_fix_mask;
- } GpsSvStatus;
- AGpsRefLocation
定义AGPS相关的cell ID 和mac地址
- <pre name="code" class="cpp">/* 2G and 3G */
- /* In 3G lac is discarded */
- typedef struct {
- uint16_t type;
- uint16_t mcc;
- uint16_t mnc;
- uint16_t lac;
- uint32_t cid;
- } AGpsRefLocationCellID;
- typedef struct {
- uint8_t mac[6];
- } AGpsRefLocationMac;
- /** Represents ref locations */
- typedef struct {
- uint16_t type;
- union {
- AGpsRefLocationCellID cellID;
- AGpsRefLocationMac mac;
- } u;
- } AGpsRefLocation;
3. 回调函数指针定义
- /** Callback with location information.告知上层位置信息
- * Can only be called from a thread created by create_thread_cb.
- */
- typedef void (* gps_location_callback)(GpsLocation* location);
- /** Callback with status information.GPS状态信息回调
- * Can only be called from a thread created by create_thread_cb.
- */
- typedef void (* gps_status_callback)(GpsStatus* status);
- /**
- * Callback with SV status information.卫星状态信息回调
- * Can only be called from a thread created by create_thread_cb.
- */
- typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
- /** Callback for reporting NMEA sentences.向上层传递NMEA信息
- * Can only be called from a thread created by create_thread_cb.
- */
- typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
- /** Callback to inform framework of the GPS engine's capabilities.
- * 告知上层GPS可以实现的功能
- *Capability parameter is a bit field of GPS_CAPABILITY_* flags.
- */
- typedef void (* gps_set_capabilities)(uint32_t capabilities);
- /** Callback utility for acquiring the GPS wakelock.GPS上锁,防止被suspend
- * This can be used to prevent the CPU from suspending while handling GPS events.
- */
- typedef void (* gps_acquire_wakelock)();
- /** Callback utility for releasing the GPS wakelock.释放锁 */
- typedef void (* gps_release_wakelock)();
- /** Callback for requesting NTP time 回调请求NTP时间*/
- typedef void (* gps_request_utc_time)();
- /** Callback for creating a thread that can call into the Java framework code.
- * 创建线程来响应framework层的请求
- * This must be used to create any threads that report events up to the framework.
- */
- typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
3. 接口结构体
- GpsCallbacks
就是上文函数指针组成的结构体,是一组回调函数,函数的实现在JNI层:com_android_server_location_GpsLocationProvider.cpp,GOOGLE已经实现好,无需做(太大)修改
- /** GPS callback structure. */
- typedef struct {
- /** set to sizeof(GpsCallbacks) */
- 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
GpsInterface接口是Android GPS 模块最重要的数据结构,它是底层驱动实现的接口,如果要porting到自己的板子上,就需要实现这些接口。
- /** Represents the standard GPS interface. */
- typedef struct {
- /** set to sizeof(GpsInterface) */
- size_t size;
- /**
- * Opens the interface and provides the callback routines
- * to the implementation of this interface.
- */
- int (*init)( GpsCallbacks* callbacks );
- /** Starts navigating. 开始定位*/
- int (*start)( void );
- /** Stops navigating. 停止定位*/
- int (*stop)( void );
- /** Closes the interface. 关闭接口*/
- void (*cleanup)( void );
- /** Injects the current time. 注入当前时间*/
- int (*inject_time)(GpsUtcTime time, int64_t timeReference,
- int uncertainty);
- /** Injects current location from another location provider
- * (typically cell ID).注入位置信息
- * latitude and longitude are measured in degrees
- * expected accuracy is measured in meters
- */
- int (*inject_location)(double latitude, double longitude, float accuracy);
- /**
- * Specifies that the next call to start will not use the
- * information defined in the flags. GPS_DELETE_ALL is passed for
- * a cold start.删除辅助数据
- */
- void (*delete_aiding_data)(GpsAidingData flags);
- /**
- * min_interval represents the time between fixes in milliseconds.
- * preferred_accuracy represents the requested fix accuracy in meters.
- * preferred_time represents the requested time to first fix in milliseconds.
- * 设置定位模式
- */
- int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
- uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
- /** Get a pointer to extension information. 自行添加接口实现*/
- const void* (*get_extension)(const char* name);
- } GpsInterface;
- GpsXtraCallbacks
高通XTRA加速定位技术回调函数结构体
- <pre name="code" class="cpp">/** Callback structure for the XTRA interface. */
- typedef struct {
- gps_xtra_download_request download_request_cb;
- gps_create_thread create_thread_cb;
- } GpsXtraCallbacks;
- GpsXtraInterface
高通XTRA加速定位技术接口
- /** Extended interface for XTRA support. */
- typedef struct {
- /** set to sizeof(GpsXtraInterface) */
- size_t size;
- /**
- * Opens the XTRA interface and provides the callback routines
- * to the implementation of this interface.
- */
- int (*init)( GpsXtraCallbacks* callbacks );
- /** Injects XTRA data into the GPS. */
- int (*inject_xtra_data)( char* data, int length );
- } GpsXtraInterface;
- AGpsInterface
AGPS加速定位技术接口结构体
- <pre name="code" class="cpp">/** Extended interface for AGPS support. */
- typedef struct {
- /** set to sizeof(AGpsInterface_v1) */
- size_t size;
- /**
- * Opens the AGPS interface and provides the callback routines
- * to the implementation of this interface.
- */
- void (*init)( AGpsCallbacks* callbacks );
- /**
- * Notifies that a data connection is available and sets
- * the name of the APN to be used for SUPL.
- */
- int (*data_conn_open)( const char* apn );
- /**
- * Notifies that the AGPS data connection has been closed.
- */
- int (*data_conn_closed)();
- /**
- * Notifies that a data connection is not available for AGPS.
- */
- int (*data_conn_failed)();
- /**
- * Sets the hostname and port for the AGPS server.
- */
- int (*set_server)( AGpsType type, const char* hostname, int port );
- } AGpsInterface;
- GpsNiInterface
网络端发起的定位接口结构体
- /**
- * Extended interface for Network-initiated (NI) support.
- */
- typedef struct
- {
- /** set to sizeof(GpsNiInterface) */
- size_t size;
- /** Registers the callbacks for HAL to use. */
- void (*init) (GpsNiCallbacks *callbacks);
- /** Sends a response to HAL. */
- void (*respond) (int notif_id, GpsUserResponseType user_response);
- } GpsNiInterface;
- gps_device_t
定义描述GPS设备类型
- struct gps_device_t {
- struct hw_device_t common;
- /**
- * Set the provided lights to the provided values.
- *
- * Returns: 0 on succes, error code on failure.
- */
- const GpsInterface* (*get_gps_interface)(struct gps_device_t* dev);
- };
其他接口在此不再赘述。
原文:http://blog.csdn.net/dreamback1987/article/details/46558835