android GPS HAL 回调函数实现
来源:互联网 发布:淘宝男款白衬衫 编辑:程序博客网 时间:2024/06/11 00:21
const struct hw_module_t HAL_MODULE_INFO_SYM = {.tag = HARDWARE_MODULE_TAG,.version_major = 1,.version_minor = 0,.id = GPS_HARDWARE_MODULE_ID,.name = "Goldfish GPS Module",.author = "The Android Open Source Project",.methods = &gps_module_methods,};
static struct hw_module_methods_t gps_module_methods = {.open = open_gps};
static int open_gps(const struct hw_module_t* module, char const* name,struct hw_device_t** device){struct gps_device_t *dev = malloc(sizeof(struct gps_device_t));memset(dev, 0, sizeof(*dev));D("%s: called\n", __FUNCTION__);dev->common.tag = HARDWARE_DEVICE_TAG;dev->common.version = 0;dev->common.module = (struct hw_module_t*)module;// dev->common.close = (int (*)(struct hw_device_t*))close_lights;dev->get_gps_interface = gps__get_gps_interface;*device = (struct hw_device_t*)dev;return 0;}
const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev){D("%s: called\n", __FUNCTION__);return &sepGpsInterface;}
static const GpsInterface sepGpsInterface = {sizeof(GpsInterface),sep_gps_init,sep_gps_start,sep_gps_stop,sep_gps_cleanup,sep_gps_inject_time,sep_gps_inject_location,sep_gps_delete_aiding_data,sep_gps_set_position_mode,sep_gps_get_extension,};
/** Represents the standard GPS interface. */
typedef struct {
size_t size;
int (*init)( GpsCallbacks* callbacks );
int (*start)( void );
int (*stop)( void );
void (*cleanup)( void );
int (*inject_time)(GpsUtcTime time, int64_t timeReference, int uncertainty);
int (*inject_location)(double latitude, double longitude, float accuracy);
void (*delete_aiding_data)(GpsAidingData flags);
int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time);
const void* (*get_extension)(const char* name);
} GpsInterface;
/** GPS callback structure. */typedef struct { /** set to sizeof(GpsCallbacks) */ size_t size; gps_location_callback location_cb; gps_status_callback status_cb; gps_sv_status_callback sv_status_cb; gps_nmea_callback nmea_cb; gps_set_capabilities set_capabilities_cb; gps_acquire_wakelock acquire_wakelock_cb; gps_release_wakelock release_wakelock_cb; gps_create_thread create_thread_cb;} GpsCallbacks;
static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj){ const GpsInterface* interface = GetGpsInterface(env, obj); if (!interface) return false; if (!sGpsDebugInterface) sGpsDebugInterface = (const GpsDebugInterface*)interface->get_extension(GPS_DEBUG_INTERFACE); return true;}
调用了GetGpsInterface去获取接口并初始化GPS
static const GpsInterface* GetGpsInterface(JNIEnv* env, jobject obj) { // this must be set before calling into the HAL library if (!mCallbacksObj) mCallbacksObj = env->NewGlobalRef(obj); if (!sGpsInterface) { sGpsInterface = get_gps_interface(); if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0) { sGpsInterface = NULL; return NULL; } } return sGpsInterface;}
GpsCallbacks sGpsCallbacks = {sizeof(GpsCallbacks),location_callback,status_callback,sv_status_callback,nmea_callback,set_capabilities_callback,acquire_wakelock_callback,release_wakelock_callback,create_thread_callback,};
static void location_callback(GpsLocation* location){JNIEnv* env = AndroidRuntime::getJNIEnv();env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags,(jdouble)location->latitude, (jdouble)location->longitude,(jdouble)location->altitude,(jfloat)location->speed, (jfloat)location->bearing,(jfloat)location->accuracy, (jlong)location->timestamp);checkAndClearExceptionFromCallback(env, __FUNCTION__);}
static void status_callback(GpsStatus* status){JNIEnv* env = AndroidRuntime::getJNIEnv();env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status);checkAndClearExceptionFromCallback(env, __FUNCTION__);}
static void sv_status_callback(GpsSvStatus* sv_status){JNIEnv* env = AndroidRuntime::getJNIEnv();memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus));env->CallVoidMethod(mCallbacksObj, method_reportSvStatus);checkAndClearExceptionFromCallback(env, __FUNCTION__);}
static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length){JNIEnv* env = AndroidRuntime::getJNIEnv();// The Java code will call back to read these values// We do this to avoid creating unnecessary String objectssNmeaString = nmea;sNmeaStringLength = length;env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);checkAndClearExceptionFromCallback(env, __FUNCTION__);}
static void set_capabilities_callback(uint32_t capabilities){LOGD("set_capabilities_callback: %ld\n", capabilities);JNIEnv* env = AndroidRuntime::getJNIEnv();env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities);checkAndClearExceptionFromCallback(env, __FUNCTION__);}
static void acquire_wakelock_callback(){acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);}static void release_wakelock_callback(){release_wake_lock(WAKE_LOCK_NAME);}static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg){return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg);}
- android GPS HAL 回调函数实现
- android GPS HAL 回调函数实现
- android GPS HAL 回调函数实现
- Android HAL原理实现& GPS HAL实现
- Android GPS学习笔记—HAL实现
- Android GPS HAL详解
- android gps hal
- Android实现自己的回调函数
- android 自定义控件实现回调函数
- 回调函数实现
- Android GPS学习笔记(4)—HAL实现
- android回调函数
- android回调函数
- Android回调函数
- android回调函数
- Understanding Android GPS HAL Driver
- android的GPS HAL架构
- android gps hal大概分析
- vm虚拟机linux磁盘空间不足,手动扩大(转)
- 详解MYSQL数据库密码的加密方式及破解方法(3)
- MTK充电报警
- MFC的自绘位图按钮
- 黑马程序员——高新技术
- android GPS HAL 回调函数实现
- 进项税和销项税
- boa.conf配置详细介绍
- UIView动画 今天项目里面用到,简单好用。
- 自己都能感觉到自己的心眼很小
- 源程序到最终可执行文件过程分析
- 控制UIScrollView中在首页不能手指向右滚动
- SSAS_定义和部署多维数据集
- TreeView默认展开所有节点