_第1张图片" src="https://img.it610.com/image/info5/7e0351a6f96546dca81ecf4a4255ac55.png" width="768" height="942" style="width:664px; height:926px;border:1px solid black;">
_第2张图片" src="https://img.it610.com/image/info5/6871f0e58ca14663bc515084775d8dfb.jpg" width="650" height="415" style="width:612px; height:471px;border:1px solid black;">
--------------------------------------------------------- 首先来看看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\base\services\java\com\android\server
这个目录只有一个文件 |-- LocationManagerService.java
是Location服务对内部实现的一种封装。
JNI:
frameworks/base/core/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中。
/** Represents the standard GPS interface. */ typedefstruct{ /** * Opens the interface and provides the callback routines * 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); /** Injects the current time. */ int(*inject_time)(GpsUtcTimetime,int64_ttimeReference, intuncertainty); /** 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)(doublelatitude,doublelongitude,floataccuracy); /** * 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); /** * fix_frequency represents the time between fixes in seconds. * Set fix_frequency to zero for a single-shot fix. */ int(*set_position_mode)(GpsPositionMode mode,intfix_frequency); /** Get a pointer to extension information. */ constvoid*(*get_extension)(constchar*name); }GpsInterface; |
2. GpsCallbacks回调函数
这个是回调函数结构体,定义也在gps.h中。它们的实现是在com_android_server_location_GpsLocationProvider.cpp中,google已经实现了,我们不需要做任何动作。
/** GPS callback structure. */ typedefstruct{ gps_location_callback location_cb; gps_status_callback status_cb; gps_sv_status_callback sv_status_cb; gps_nmea_callback nmea_cb; }GpsCallbacks; /** Callback with location information. */ typedefvoid(*gps_location_callback)(GpsLocation*location); /** Callback with status information. */ typedefvoid(*gps_status_callback)(GpsStatus*status); /** Callback with SV status information. */ typedefvoid(*gps_sv_status_callback)(GpsSvStatus*sv_info); /** Callback for reporting NMEA sentences. */ typedefvoid(*gps_nmea_callback)(GpsUtcTime timestamp,constchar*nmea,intlength); |
3.GpsLocation
表示Locatin数据信息,底层驱动获得Location的raw信息,通常是nmea码,然后通过解析就得到了location信息。
/** Represents a location. */ typedefstruct{ /** Contains GpsLocationFlags bits. */ uint16_tflags; /** Represents latitude in degrees. */ doublelatitude; /** Represents longitude in degrees. */ doublelongitude; /** Represents altitude in meters above the WGS 84 reference * ellipsoid. */ doublealtitude; /** Represents speed in meters per second. */ floatspeed; /** Represents heading in degrees. */ floatbearing; /** Represents expected accuracy in meters. */ floataccuracy; /** Timestamp for the location fix. */ GpsUtcTime timestamp; }GpsLocation; |
- 浅谈Java中Collections.sort对List排序的两种方法
- python list.sort()根据多个关键字排序的方法实现
- 实现简单的Android的播放视频功能
- Android中实现日期时间选择器(DatePicker和TimePicker)
- android之实现底部TabHost
- Android(安卓)泛型使用
- Android语音识别功能使用总结
- Android电话拨号器实现方法
- Android:实现类似RadioButton自动换行及单选效果
随机推荐
-
android brightness control
-
Android判断是否安装某个应用
-
Android CoordinatorLayout的使用——实
-
android中表格绘图
-
android 隐藏输入法
-
android进度条对话框小例子
-
Android传感器使用
-
Android PromptDialog example
-
Android Popupwindow 点击外部消失的实现
-
Android根据URL下载文件保存到SD卡