TI平台使用SIRF GPS
2.Android HAL的实现
(1)制作libgps.so库
google提供的方法
Android.mk:
LOCAL_SRC_FILES:= main.c //指定库的源码
LOCAL_MODULE := libgps //指定库的名称
include $(BUILD_SHARED_LIBRARY) //指定编译成.so库
(2)修改BoardConfig.mk
添加BOARD_GPS_LIBRARIES := libgps
由于hardware/libhardware_legacy/gps/Android.mk中指定LOCAL_SHARED_LIBRARIES
ifneq ($(BOARD_GPS_LIBRARIES),)
LOCAL_CFLAGS += -DHAVE_GPS_HARDWARE
LOCAL_SHARED_LIBRARIES += $(BOARD_GPS_LIBRARIES)
endif
(3)修改hardware/libhardware_legacy/gps/gps.cpp
- static void
- gps_find_hardware( void )
- {
- sGpsInterface = gps_get_hardware_interface();
- if (!sGpsInterface)
- LOGD("no GPS hardware on this device\n");
- }
gps_get_hardware_interface()在libgps.so源码中实现
(4)实现libgps.so源码main.c
(可参考hardware/libhardware_legacy/gps/gps_qemu.c)
- static const GpsInterface sirfGpsInterface = {
- sirf_gps_init,
- sirf_gps_start,
- sirf_gps_stop,
- sirf_gps_cleanup,
- sirf_gps_inject_time,
- sirf_gps_inject_location,
- sirf_gps_delete_aiding_data,
- sirf_gps_set_position_mode,
- sirf_gps_get_extension,
- };
- const GpsInterface* gps_get_hardware_interface()
- {
- return &sirfGpsInterface;
- }
下面将介绍下需要修改的函数,其他函数都可以仿照gps_qemu.c
sirf_gps_start()函数中添加SiRF_Start();
sirf_gps_stop()函数中添加SiRF_Stop();
sirf_gps_init()函数中调用gps_state_init,作用是创建socket通信和gps_state_thread线程;
gps_state_init()函数中需要根据具体的GPS模块实现state->fd = channel_open();
gps_state_thread()函数中去掉两句nmea_reader_set_callback调用;
nmea_reader_parse()函数添加callbacks.nmea_cb和callbacks.location_cb:
- if (r->pos < 9) {
- D("Too short. discarded.");
- return;
- }
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- _gps_state->callbacks.nmea_cb(tv.tv_sec*1000+tv.tv_usec/1000, r->in, r->pos);
- }
- nmea_tokenizer_init(tzer, r->in, r->in + r->pos);
- if (_gps_state->callbacks.location_cb) {
- _gps_state->callbacks.location_cb( &r->fix );
- r->fix.flags = 0;
- }
- else {
- D("no callback, keeping data until needed !");
- }
(5)NMEA数据上报
Android本身的GPS读取NMEA信息机制是调用read函数读取串口信息并解析上报,但SIRF提供了SiRF_Output函数用于底层与应用层的数据上报,GPS工作后会有线程不停调用SiRF_Output,因此只要在SiRF_Output函数中添加:
- NmeaReader reader[1];
- nmea_reader_init( reader );
- for (nn = 0; nn < sizeof(buf); nn++)
- nmea_reader_addc( reader, buf[nn] );
现在GPS可以上报GGA、GSA、RMC等数据(GSA数据需添加nmea_reader_parse函数中关于GSA数据解析)
后面还会继续研究GSA等数据的解析上报...期待o ^-^
阅读(18889) | 评论(24) | 转发(1) |