GPS 研究一 (Android2.3)

(红字表示2.3的变化)
Framework:
1.frameworks/base/location/java/android/location
这里主要是用来被App调用的,API包是android.location。
2.frameworks/base/location/java/com/android/internal/location
这个目录是Framework对Location服务的内部实现。
3.framework/services/java/com/android/server
这个目录只有一个文件
|-- LocationManagerService.java
是Location服务对内部实现的一种封装。
JNI:
2.2
frameworks/base/core/jni/android_location_GpsLocationProvider.cpp
2.3
/framework/base/services/jni/com_android_server_location_GpsLocationProvider.cpp

JNI层只有一个文件,起到承上启下的作用。上层承接Framework,下层调用HAL层具体硬件抽象实现。
HAL:Hardware Abstract Layer 硬件抽象层
hardware/libhardware_legacy/gps
hardware/libhardware_legacy/include/hardware_legacy/gps.h
HAL层相当于一个linux应用程序接口,通过open,close等操作,操作硬件设备。Android的源代码只实现了模拟器的gps接口,具体在文件gps_qemu.c中。在2.2版本中提供了对QCOM公司的gps的实现,在以下目录:
/hardware/qcom
下面介绍几个重要的数据结构:

1. GpsInterface接口是gps模块中最重要的数据结构,它是底层驱动实现的接口,如果要porting到自己的板子上,就需要实现这些接口。该接口的定义在gps.h中,模拟器实现在gps_qemu.c中
  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. */  
  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.     int   (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,   
  44.             uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);   
  45.   
  46.     /** Get a pointer to extension information. */  
  47.     const void* (*get_extension)(const char* name);   
  48. } GpsInterface;  

2.GpsCallbacks回调函数

这个是回调函数结构体,定义也在gps.h中。它们的实现是在com_android_server_android_location_GpsLocationProvider.cpp中,google已经实现了,我们不需要做任何动作。

2.2

  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. } GpsCallbacks;  

2.3 中 多加入了 以下几个回调函数

 

  1. gps_set_capabilities set_capabilities_cb;   
  2. gps_acquire_wakelock acquire_wakelock_cb;   
  3. gps_release_wakelock release_wakelock_cb;   
  4. gps_create_thread create_thread_cb;  

 

 

3. GpsLocation

表示Locatin数据信息,底层驱动获得Location的raw信息,通常是nmea码,然后通过解析就得到了location信息。

其中Android2.3比android2.2多加入了 size 属性 以获取其大小。

  1. /** 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;  

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值