统GPS定位完全相同GPS接收器接收原始GPS信号解调并进行一定处理根据处理后的信息进行位置计算得到最终的位置坐标。
MS-Assisted方式中解调并处理后接下来过程如下图所示:5设备将处理后的GPS信息伪距信息通过蜂窝网络传输给AGPS位置服务器。
6AGPS服务器根据伪距信息并结合其他途径蜂窝基站定位、参考GPS定位等得到的辅助定位信息计算出最终的位置坐标返回给设备。
AGPS定位技术的实际应用情况因为AGPS需要网络支持因此目前使用该技术的大部分设备为手机。
1.目前大部分支持AGPS的手机采用一种纯软件的AGPS方案。
该方案基于MS-Based位置计算方式。
具体的方案为定期下载星历数据到手机中手机中的AGPS软件会根据星历信息计算出当前位置的可用卫星信 息从而提供给设备用于快速搜星。
用户可以选择通过WiFi、固网等免费网络定期更新星历数据从而避免使用蜂窝网络产生的数据流量费用。
当然由于星历信息可能存在延迟因此搜星时速度可能有所下降但是仍然会比传统GPS定位快很多倍。
该方案的优点是纯软件不需要专门的AGPS硬件几乎所有GPS手机都可以使用同时用户可以根据情况指定星历更新周期及更新方式控制或减免蜂窝网络数据流量。
2.部分运营商的AGPS方案中实施了在无GPS信号时自动切换到GSM蜂窝基站Cell-ID定位的措施从而一定程度上解决了室内定位的问题。
3.世界范围内一些AGPS芯片或相关服务已经广泛使用。
3.AGPS在Android中的实现原生的
Android源码中并没有AGPS的实现方式我们以PQXU2为例来观察AGPS的运作过程。
下面是HAL层头文件中关于AGPS定义的接口及回调函数。
/ Represents the status of AGPS. /typedef struct / set to sizeofAGpsStatus / size_t size AGpsType type AGpsStatusValue status AGpsStatus/ Callback with AGPS status information. Can only be called from a thread created by create_thread_cb. /typedef void agps_status_callbackAGpsStatus status/ Callback structure for the AGPS interface. /typedef struct agps_status_callback status_cb gps_create_thread create_thread_cb AgpsCallbacks/ Extended interface for AGPS support. /typedef struct / set to sizeofAGpsInterface / size_t size / Opens the AGPS interface and provides the callback routines to the implemenation 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下面是HAL实现层的AGPS代码。
static const AGpsInterface sLocEngAGpsInterface sizeofAGpsInterface loc_eng_agps_init loc_eng_agps_data_conn_open loc_eng_agps_data_conn_closed loc_eng_agps_data_conn_failed loc_eng_agps_set_serverstatic const void loc_eng_get_extensionconst char name if strcmpname GPS_XTRA_INTERFACE 0 return ampsLocEngXTRAInterface else if strcmpname AGPS_INTERFACE 0 return ampsLocEngAGpsInterface else if strcmpname GPS_NI_INTERFACE 0 return ampsLocEngNiInterface return NULL下面是JNI中的AGPS源码。
static const AGpsInterface GetAGpsInterfaceJNIEnv env jobject obj const GpsInterface interface GetGpsInterfaceenv obj if interface return NULL if sAGpsInterface sAGpsInterface const AGpsInterfaceinterface-gtget_extensionAGPS_INTERFACE if sAGpsInterface sAGpsInterface-gtinitampsAGpsCallbacks return sAGpsInterfaceAGpsCallbacks sAGpsCallbacks agps_status_callback create_thread_callbackstatic void agps_status_callbackAGpsStatus agps_status JNIEnv env AndroidRuntime::getJNIEnv env-gtCallVoidMethodmCallbacksObj method_reportAGpsStatus agps_status-gttype agps_status-gtstatus checkAndClearExceptionFromCallbackenv __FUNCTION__static pthread_t create_thread_callbackconst char name void startvoid void arg return pthread_tAndroidRuntime::createJavaThreadname start arg其实AndroidRuntime::createJavaThreadname start arg调用的是下面这个函数此函数在AGPS的HAL实现层中。
static void loc_eng_process_deferred_action void arg AGpsStatus status status.size sizeofstatus status.type AGPS_TYPE_SUPL LOGDquotloc_eng_process_deferred_action startednquot // make sure we do not run in background scheduling group set_sched_policygettid SP_FOREGROUND // disable the GPS lock LOGDquotSetting GPS privacy lock to RPC_LOC_LOCK_NONEnquot loc_eng_set_gps_lockRPC_LOC_LOCK_NONE while 1 GpsAidingData aiding_data_for_deletion GpsStatusValue engine_status rpc_loc_event_mask_type loc_event rpc_loc_event_payload_u_type loc_event_payload // Wait until we are signalled to do a deferred action or exit pthread_mutex_lockamploc_eng_data.deferred_action_mutex // If we have an event we should process it immediately // otherwise wait until we are signalled if loc_eng_data.deferred_action_flags 0 // do not hold a wake lock while waiting for an event... loc_eng_data.release_wakelock_cb pthread_cond_waitamploc_eng_data.deferred_action_cond amploc_eng_data.deferred_action_mutex // but after we are signalled reacquire the wake lock // until we are done processing the event. loc_eng_data.acquire_wakelock_cb if loc_eng_data.deferred_action_flags amp DEFERRED_ACTION_QUIT pthread_mutex_unlockamploc_eng_data.deferred_action_mutex break // copy anything we need before releasing the mutex loc_event loc_eng_data.loc_event if loc_event 0 memcpyamploc_event_payload amploc_eng_data.loc_event_payload sizeofloc_event_payload loc_eng_data.loc_event 0 int flags loc_eng_data.deferred_action_flags loc_eng_data.deferred_action_flags 0 engine_status loc_eng_data.agps_status aiding_data_for_deletion loc_eng_data.aiding_data_for_deletion status.status loc_eng_data.agps_status loc_eng_data.agps_status 0 // perform all actions after releasing the mutex to avoid blocking RPCs from the ARM9 pthread_mutex_unlockamploc_eng_data.deferred_action_mutex if loc_event 0 loc_eng_process_loc_eventloc_event amploc_event_payload // send_delete_aiding_data must be done when GPS engine is off if engine_status GPS_STATUS_SESSION_BEGIN ampamp aiding_data_for_deletion 0 loc_eng_delete_aiding_data_deferred_action if flags amp DEFERRED_ACTION_AGPS_DATA_SUCCESS DEFERRED_ACTION_AGPS_DATA_CLOSED DEFERRED_ACTION_AGPS_DATA_FAILED loc_eng_process_atl_deferred_actionflags pthread_mutex_lockamploc_eng_data.deferred_stop_mutex // work around problem with loc_eng_stop when AGPS requests are pending // we defer stopping the engine until the AGPS request is done loc_eng_data.agps_request_pending false if loc_eng_data.stop_request_pending LOGD quothandling deferred stopnquot if loc_stop_fixloc_eng_data.client_handle RPC_LOC_API_SUCCESS LOGD quotloc_stop_fix failednquot pthread_mutex_unlockamploc_eng_data.deferred_stop_mutex if status.status 0 ampamp loc_eng_data.agps_status_cb loc_eng_data.agps_status_cbampstatus // reenable the GPS lock LOGDquotSetting GPS privacy lock to RPC_LOC_LOCK_ALLnquot loc_eng_set_gps_lockRPC_LOC_LOCK_ALL LOGDquotloc_eng_process_deferred_action thread exitingnquot loc_eng_data.release_wakelock_cb loc_eng_data.deferred_action_thread 0static void loc_eng_process_loc_event rpc_loc_event_mask_type loc_event rpc_loc_event_payload_u_type loc_event_payload if loc_event amp RPC_LOC_EVENT_PARSED_POSITION_REPORT loc_eng_report_position amploc_event_payload-gtrpc_loc_event_payload_u_type_u.parsed_location_report if loc_event amp RPC_LOC_EVENT_SATELLITE_REPORT loc_eng_report_sv amploc_event_payload-gtrpc_loc_event_payload_u_type_u.gnss_report if loc_event amp RPC_LOC_EVENT_STATUS_REPORT loc_eng_report_status amploc_event_payload-gtrpc_loc_event_payload_u_type_u.status_report if loc_event amp RPC_LOC_EVENT_NMEA_POSITION_REPORT loc_eng_report_nmea amploc_event_payload-gtrpc_loc_event_payload_u_type_u.nmea_report // Android XTRA interface supports only XTRA download if loc_event amp RPC_LOC_EVENT_ASSISTANCE_DATA_REQUEST if loc_event_payload-gtrpc_loc_event_payload_u_type_u.assist_data_request.event RPC_LOC_ASSIST_DATA_PREDICTED_ORBITS_REQ LOGD quotloc_event_cb: xtra download requstquot // Call Registered callback if loc_eng_data.xtra_module_data.download_request_cb NULL loc_eng_data.xtra_module_data.download_request_cb if loc_event amp RPC_LOC_EVENT_IOCTL_REPORT // Process the received RPC_LOC_EVENT_IOCTL_REPORT void loc_eng_ioctl_process_cb loc_eng_data.client_handle amploc_event_payload-gtrpc_loc_event_payload_u_type_u.ioctl_report if loc_event amp RPC_LOC_EVENT_LOCATION_SERVER_REQUEST loc_eng_process_conn_request amploc_event_payload-gtrpc_loc_event_payload_u_type_u.loc_server_request loc_eng_ni_callbackloc_event loc_event_payloadif DEBUG_MOCK_NI 1 // DEBUG only if loc_event amp RPC_LOC_EVENT_STATUS_REPORT ampamp loc_event_payload-gtrpc_loc_event_payload_u_type_u.status_report. payload.rpc_loc_status_event_payload_u_type_u.engine_state RPC_LOC_ENGINE_STATE_OFF // Mock an NI request pthread_t th pthread_create ampth NULL mock_ni void client_handle endif / DEBUG_MOCK_NI 1 /调用这个函数向上层传递数据。
例如。
static void loc_eng_report_nmea const rpc_loc_nmea_report_s_type nmea_report_ptr if loc_eng_data.nmea_cb NULL struct timeval tv gettimeofdayamptv struct timezone NULL long long now tv.tv_sec 1000LL tv.tv_usec / 1000if AMSS_VERSION3200 loc_eng_data.nmea_cbnow nmea_report_ptr-gtnmea_sentences.nmea_sentences_val nmea_report_ptr-gtnmea_sentences.nmea_sentences_lenelse loc_eng_data.nmea_cbnow nmea_report_ptr-gtnmea_sentences nmea_report_ptr-gtlengthendif 下面是java中的代码参考GpsLocationProvider.java。
执行 reportNmea函数获得底层传递上来的NMEA数据。
/ called from native code to report NMEA data received / private void reportNmealong timestamp synchronizedmListeners int size mListeners.size if size gt 0 // dont bother creating the String if we have no listeners int length native_read_nmeamNmeaBuffer mNmeaBuffer.length String nmea new StringmNmeaBuffer 0 length for int i 0 i lt size i Listener listener mListeners.geti try listener.mListener.onNmeaReceivedtimestamp nmea catch RemoteException e Log.wTAG quotRemoteException in reportNmeaquot mListeners.removelistener // adjust for size of list changing size-- / called from native code to update AGPS status / private void reportAGpsStatusint type int status switch status case GPS_REQUEST_AGPS_DATA_CONN: if DEBUG Log.dTAG quotGPS_REQUEST_AGPS_DATA_CONNquot // Set mAGpsDataConnectionState before calling startUsingNetworkFeature // to avoid a race condition with handleUpdateNetworkState mAGpsDataConnectionState AGPS_DATA_CONNECTION_OPENING int result mConnMgr.startUsingNetworkFeature ConnectivityManager.TYPE_MOBILE Phone.FEATURE_ENABLE_SUPL if result Phone.APN_ALREADY_ACTIVE if DEBUG Log.dTAG quotPhone.APN_ALREADY_ACTIVEquot if mAGpsApn null native_agps_data_conn_openmAGpsApn .
上一篇:
MARS
下一篇:
HTML基础教程:学习掌握HTML 元素