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文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219