android gps 代码 分析(3)
发布时间:2021-06-08
发布时间: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); }
上一篇:刑法学复习题及答案
下一篇:液压钻机的液压系统设计