2022年androidGPS架构分析 .pdf
《2022年androidGPS架构分析 .pdf》由会员分享,可在线阅读,更多相关《2022年androidGPS架构分析 .pdf(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Android 系统 Gps分析1,GPS 架构:2,GPS 分析:2.1 头文件:头文件定 义在头文件定义在:hardware/libhardware/include/hardware/gps.h,定义了 GPS底层相关的结构体和接口:1,GpsLocation:GPS位置信息结构体,包含经度,纬度,高度,速度,方位角等.typedef struct /*set to sizeof(GpsLocation)*/size_t size;名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 23 页 -/*Contains GpsLocationFlags bits.*/uint16_t
2、 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
3、;/*Represents expected accuracy in meters.*/float accuracy;/*Timestamp for the location fix.*/GpsUtcTime timestamp;GpsLocation;2,GpsStatus:GPS状态包括5种状态,分别为未知,正在定位,停止定位,启动未定义,未启动。typedef struct /*set to sizeof(GpsStatus)*/size_t size;GpsStatusValue status;名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 23 页 -GpsStatus
4、;3,GpsSvInfo:GPS卫星信息,包含卫星编号,信号强度,卫星仰望角,方位角等。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;4,GpsSvStatus:GPS卫星状态
5、,包含可见卫星数和信息,星历时间,年历时间等。typedef struct /*set to sizeof(GpsSvStatus)*/size_t size;/*Number of SVs currently visible.*/int num_svs;/*Contains an array of SV information.*/名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 23 页 -GpsSvInfo sv_listGPS_MAX_SVS;/*Represents a bit mask indicating which SVs *have ephemeris data.
6、*/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;5,GpsCallbacks:/*Callback with location informa
7、tion.*Can only be called from a thread created by create_thread_cb.*/typedef void(*gps_location_callback)(GpsLocation*location);/向上层传递GPS位置信息名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 23 页 -/*Callback with status information.*Can only be called from a thread created by create_thread_cb.*/typedef void(*gps_statu
8、s_callback)(GpsStatus*status);/向上层传递GPS状态信息/*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);/向上层传递GPS卫星信息/*Callback for reporting NMEA sentences.*Can only be called from a thread created b
9、y create_thread_cb.*/typedef void(*gps_nmea_callback)(GpsUtcTime timestamp,const char*nmea,int length);/向上层传递NMEA数据/*Callback to inform framework of the GPS engines capabilities.*Capability parameter is a bit field of GPS_CAPABILITY_*flags.*/typedef void(*gps_set_capabilities)(uint32_t capabilities)
10、;/告知GPS模块可以实现的功能/*Callback utility for acquiring the GPS wakelock.名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 23 页 -*This can be used to prevent the CPU from suspending while handling GPS events.*/typedef void(*gps_acquire_wakelock)();/上锁,防止处理GPS时间时终止/*Callback utility for releasing the GPS wakelock.*/typedef vo
11、id(*gps_release_wakelock)();/释放锁/*Callback for creating a thread that can call into the Java framework code.*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);/等待上层请求/*GPS callback stru
12、cture.*/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;名师资料总结-精品资料欢迎下载-名师精心整理-第 6
13、 页,共 23 页 -gps_release_wakelock release_wakelock_cb;gps_create_thread create_thread_cb;GpsCallbacks;6,GpsInterface:GPS最重要的结构体,上层通过次接口与硬件适配层交互的。/*Represents the standard GPS interface.*/typedef struct /*set to sizeof(GpsInterface)*/size_t size;/*Opens the interface and provides the callback routines
14、*to the implemenation of this interface.*/int (*init)(GpsCallbacks*callbacks);/*Starts navigating.*/int (*start)(void);/启动定位 /*Stops navigating.*/int (*stop)(void);/取消定位 /*Closes the interface.*/void (*cleanup)(void);/关闭GPS接口名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 23 页 -/*Injects the current time.*/int (*inj
15、ect_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,flo
16、at 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
17、_accuracy represents the requested fix accuracy in meters.*preferred_time represents the requested time to first fix in milliseconds.*/名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 23 页 -int (*set_position_mode)(GpsPositionMode mode,GpsPositionRecurrence recurrence,uint32_t min_interval,uint32_t preferred_accuracy
18、,uint32_t preferred_time);/设置定位模式和GPS工作模式等 /*Get a pointer to extension information.*/const void*(*get_extension)(const char*name);/自定义的接口 GpsInterface;7,gps_device_t:GPS设备结构体,向上层提供了重要的get_gps_interface 接口struct gps_device_t struct hw_device_t common;/*Set the provided lights to the provided values.
19、*Returns:0 on succes,error code on failure.*/const GpsInterface*(*get_gps_interface)(struct gps_device_t*dev);2,2硬件适配层:broadcom GPS硬件适配层的源码位于:/home/ls/Broadcom21553/hardware/broadcom/gps/allPartners/deliverables/middleware_connectors/unix/Android/gps_jni目录下。在gps_lcsapi.c中,定义了gps设备模块实例:const struct h
20、w_module_t HAL_MODULE_INFO_SYM=名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 23 页 -.tag=HARDWARE_MODULE_TAG,.version_major=1,.version_minor=0,.id=GPS_HARDWARE_MODULE_ID,/JNI层从这个ID来调用HAL层接口 .name=lcsapi GPS Module,.author=Broadcom Corporation,.methods=&hw_module_methods,;这里的methods指向该文件中的hw_module_methods static st
21、ruct hw_module_methods_t hw_module_methods=.open=open_gps;再看open_gps.static int open_gps(const struct hw_module_t*module,char const*name,struct hw_device_t*device)LOGD(*%s*start!n,_func_);struct gps_device_t*gps_device=malloc(sizeof(struct gps_device_t);if(gps_device)memset(gps_device,0,sizeof(struc
22、t gps_device_t);gps_device-common.tag =HARDWARE_DEVICE_TAG;gps_device-common.version =0;名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 23 页 -gps_device-common.module =(struct hw_module_t*)module;gps_device-get_gps_interface=gps_get_hardware_interface;*device=(struct hw_device_t*)gps_device;return 0;return 1;LOGD(*
23、%s*done!n,_func_);此处可以看作是GPS设备的初始化函数,在使用设备前必须执行此函数。函数里面指定了hw_device_t 的module成员,以及gps_device_t的get_gps_interface成员。上层可以通过gps_device_t的get_gps_interface调用gps_get_hardware_interface。gps_get_hardware_interface的定义如下:#ifdef GPS_AS_MODULE const GpsInterface*gps_get_hardware_interface(struct gps_device_t*d
24、ev)#else const GpsInterface*gps_get_hardware_interface(void)#endif LOGD(*%s*start!n,_func_);return&_GpsInterface;LOGD(*%s*done!n,_func_);名师资料总结-精品资料欢迎下载-名师精心整理-第 11 页,共 23 页 -2,2,JNI适配层:源码位于:/home/ls/Broadcom21553/frameworks/base/services/jni/com_android_server_location_GpsLocationProvider.cpp 首先看注册
25、JNI方法的函数定义:int register_android_server_location_GpsLocationProvider(JNIEnv*env)return jniRegisterNativeMethods(env,com/android/server/location/GpsLocationProvider,sMethods,NELEM(sMethods);这个函数被同目录下的onload.cpp文件调用,调用地方在:extern C jint JNI_OnLoad(JavaVM*vm,void*reserved)JNIEnv*env=NULL;jint result=-1;i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年androidGPS架构分析 2022 androidGPS 架构 分析
限制150内