Android 2.3 GPS transplantation note (1)

Source: Internet
Author: User

Recently, the task is to adapt the product's GPS to the android2.3 source code. The general porting practice is: Read the gps scn data from the serial port, in the GPS hardware adapter layer (HAL) parse the data and report it to the framework layer. I have different task requirements. A serial port proxy is responsible for reading and writing operations on the serial port. GPS only needs to communicate with the serial port proxy to obtain the domestic data.

To sum up, GPS transplantation involves the following tasks:

(1) Implement the socket Process Communication Server in the serial port proxy, send the data read by the serial port Proxy from the serial port to the socket client, and send the data sent by the Socket Client to the serial port proxy to write to the serial port.

(2) Implement the socket Process Communication client in the GPS adaptation layer and communicate with the socket server in the serial port proxy.

(3) The GPS Adaptation Layer parses and reports the data that is read by the Socket Client.


Socket communication will not be discussed in detail in this article, mainly about GPS adaptation.

(1) first create the directory Hardware/libhardware/modules/GPS in the Android 2.3 source code, and copy the SDK/emulator/GPS/gps_qemu.c to the new directory.

(2) create an android. mk file with the following content:

LOCAL_PATH := $(call my-dir)ifneq ($(TARGET_PRODUCT),sim)# HAL module implemenation, not prelinked and stored in# hw/<GPS_HARDWARE_MODULE_ID>.<ro.hardware>.soinclude $(CLEAR_VARS)LOCAL_PRELINK_MODULE := falseLOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hwLOCAL_CFLAGS += -DQEMU_HARDWARELOCAL_SHARED_LIBRARIES := liblog libcutils libhardwareLOCAL_SRC_FILES := gps_qemu.c socket_msg.cLOCAL_MODULE := gps.defaultLOCAL_MODULE_TAGS := debuginclude $(BUILD_SHARED_LIBRARY)

Remember: The best local_module is GPS. Default. Otherwise, it is likely that the so dynamic library cannot be called on the upper layer.

(3) Modify gps_qemu.c, which mainly includes the following aspects:

1. Modify the gps_state_init function, delete the initialization code for communication with qemu, and then communicate with my socket server.

static voidgps_state_init( GpsState*  state, GpsCallbacks* callbacks ){    state->init       = 1;    state->control[0] = -1;    state->control[1] = -1;    state->fd         = -1;    /*state->fd = qemud_channel_open(QEMU_CHANNEL_NAME);    if (state->fd < 0) {        D("no gps emulation detected");        return;    }    D("gps emulation will read from '%s' qemud channel", QEMU_CHANNEL_NAME );*///initialize cache,and register callback function to handle messagesocket_cache_init(&state->cache,gps_msg_handle);    //Connect to socket server    if(gps_socket_connect(state) == 0){goto Fail;    }    if ( socketpair( AF_LOCAL, SOCK_STREAM, 0, state->control ) < 0 ) {        LOGE("could not create thread control socket pair: %s", strerror(errno));        goto Fail;    }    state->thread = callbacks->create_thread_cb( "gps_state_thread", gps_state_thread, state );    if ( !state->thread ) {        LOGE("could not create gps thread: %s", strerror(errno));        goto Fail;    }    state->callbacks = *callbacks;    D("gps initialized success!");//start gpsgps_state_start(state);    return;Fail:    gps_state_done( state );}

2. Modify the gps_state_thread function. When the socket server receives data, call our processing function for processing (mainly including parsing socket messages ).

else if (fd == gps_fd)                {                    //char  buff[32];                    unsigned char buff[32 + SOCKET_MSG_FORMAT_SIZE];                    D("gps fd event");                    for (;;) {                        int  nn, ret;                        ret = read( fd, buff, sizeof(buff) );                        if (ret < 0) {                            if (errno == EINTR)                                continue;                            if (errno != EWOULDBLOCK)                                LOGE("error while reading from gps daemon socket: %s:", strerror(errno));                            break;                        }                        //D("received %d bytes: %.*s", ret, ret, buff);gps_msg_recv(state,buff,ret,(void *)reader);/*                        for (nn = 0; nn < ret; nn++)                            nmea_reader_addc( reader, buff[nn] );*/                    }                    D("gps fd event end");                }

(3) Compile the module and package the sysem. IMG image file.

 mmm hardware/libhardware/modules/gps make snod

Tip: The generated GPS. default. so will eventually be in the out/target/product/generic/system/lib/HW directory, if the directory also has GPS. goldfish. so file, must first put GPS. goldfish. delete the so file, and then package the image file.

(4) The rest is the test...



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.