Android GPS架构分析

转载时请注明出处和作者

文章出处:http://danielwood.cublog.cn

作者:DanielWood

----------------------------------------------------------

看Android的GPS模块有两个月了吧,终于可以写点东西出来。首先来看看GPS模块的代码结构:

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:

frameworks/base/core/jni/android_location_GpsLocationProvider.cpp

JNI层只有一个文件,起到承上启下的作用。上层承接Framework,下层调用HAL层具体硬件抽象实现。

HAL:HardwareAbstractLayer硬件抽象层

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中。

/**RepresentsthestandardGPSinterface.*/

typedefstruct{

/**

*Openstheinterfaceandprovidesthecallbackroutines

*totheimplemenationofthisinterface.

*/

int(*init)(GpsCallbacks*callbacks);

/**Startsnavigating.*/

int(*start)(void);

/**Stopsnavigating.*/

int(*stop)(void);

/**Closestheinterface.*/

void(*cleanup)(void);

/**Injectsthecurrenttime.*/

int(*inject_time)(GpsUtcTimetime,int64_ttimeReference,

intuncertainty);

/**Injectscurrentlocationfromanotherlocationprovider

*(typicallycellID).

*latitudeandlongitudearemeasuredindegrees

*expectedaccuracyismeasuredinmeters

*/

int(*inject_location)(doublelatitude,doublelongitude,floataccuracy);

/**

*Specifiesthatthenextcalltostartwillnotusethe

*informationdefinedintheflags.GPS_DELETE_ALLispassedfor

*acoldstart.

*/

void(*delete_aiding_data)(GpsAidingDataflags);

/**

*fix_frequencyrepresentsthetimebetweenfixesinseconds.

*Setfix_frequencytozeroforasingle-shotfix.

*/

int(*set_position_mode)(GpsPositionModemode,intfix_frequency);

/**Getapointertoextensioninformation.*/

constvoid*(*get_extension)(constchar*name);

}GpsInterface;

2.GpsCallbacks回调函数

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

/**GPScallbackstructure.*/

typedefstruct{

gps_location_callbacklocation_cb;

gps_status_callbackstatus_cb;

gps_sv_status_callbacksv_status_cb;

gps_nmea_callbacknmea_cb;

}GpsCallbacks;

/**Callbackwithlocationinformation.*/

typedefvoid(*gps_location_callback)(GpsLocation*location);

/**Callbackwithstatusinformation.*/

typedefvoid(*gps_status_callback)(GpsStatus*status);

/**CallbackwithSVstatusinformation.*/

typedefvoid(*gps_sv_status_callback)(GpsSvStatus*sv_info);

/**CallbackforreportingNMEAsentences.*/

typedefvoid(*gps_nmea_callback)(GpsUtcTimetimestamp,constchar*nmea,intlength);

3.GpsLocation

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

/**Representsalocation.*/

typedefstruct{

/**ContainsGpsLocationFlagsbits.*/

uint16_tflags;

/**Representslatitudeindegrees.*/

doublelatitude;

/**Representslongitudeindegrees.*/

doublelongitude;

/**RepresentsaltitudeinmetersabovetheWGS84reference

*ellipsoid.*/

doublealtitude;

/**Representsspeedinmeterspersecond.*/

floatspeed;

/**Representsheadingindegrees.*/

floatbearing;

/**Representsexpectedaccuracyinmeters.*/

floataccuracy;

/**Timestampforthelocationfix.*/

GpsUtcTimetimestamp;

}GpsLocation;

相关推荐