手机版

android gps 代码 分析(3)

发布时间:2021-06-08   来源:未知    
字号:

android

location_callback,

status_callback,

sv_status_callback,

};

//并且打开串口,注册sGpsCallbacks

qemu_gps_init(GpsCallbacks* callbacks)

----> GpsState* s = _gps_state;

----> gps_state_init(s);

----> s->callbacks = *callbacks;

//打开串口,创建线程

gps_state_init( GpsState* state )

-----> state->fd = qemu_channel_open_gps

-----> pthread_create( &state->thread, NULL, gps_state_thread, state )

static void location_callback(GpsLocation* location)

{

pthread_mutex_lock(&sEventMutex);

sPendingCallbacks |= kLocation;

memcpy(&sGpsLocation, location, sizeof(sGpsLocation));

pthread_cond_signal(&sEventCond); //同步西面的函数

pthread_mutex_unlock(&sEventMutex);

}

//下面这个函数就是由上层的 java调用的,并且等待底层的硬件发送数据,其中由EventCond同步

static void android_location_GpsLocationProvider_wait_for_event(JNIEnv* env, jobject obj) {

pthread_mutex_lock(&sEventMutex);

pthread_cond_wait(&sEventCond, &sEventMutex);

// copy and clear the callback flags

int pendingCallbacks = sPendingCallbacks;

sPendingCallbacks = 0;

// copy everything and unlock the mutex before calling into Java code to avoid the possibility // of timeouts in the GPS engine.

memcpy(&sGpsLocationCopy, &sGpsLocation, sizeof(sGpsLocationCopy));

memcpy(&sGpsStatusCopy, &sGpsStatus, sizeof(sGpsStatusCopy));

memcpy(&sGpsSvStatusCopy, &sGpsSvStatus, sizeof(sGpsSvStatusCopy));

pthread_mutex_unlock(&sEventMutex);

if (pendingCallbacks & kLocation) {

env->CallVoidMethod(obj, method_reportLocation, sGpsLocationCopy.flags,

(jdouble)titude, (jdouble)sGpsLocationCopy.longitude, (jdouble)sGpsLocationCopy.altitude,

(jfloat)sGpsLocationCopy.speed, (jfloat)sGpsLocationCopy.bearing,

(jfloat)sGpsLocationCopy.accuracy, (jlong)sGpsLocationCopy.timestamp); }

android gps 代码 分析(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)