Transplantation and Analysis of Android-Based Vehicle Navigation-andorid GPS Hal (by liukun321)

Source: Internet
Author: User

Control: Samsung arm Cortex-A8 (s5pv210)

GPS: Ublox-6M

System: Android 2.3.1

Kernel: linux2.6.35

Bootloader:
U-boot for tiny210 ver4.0

Development Board: tiny210v1 sdk2 (512 M ddr2ram SLC nandflash 256 m)

The review is over. It's only by the end of June that we have time to sit down and learn something. This should be the last gadgets of the undergraduate course. The foreplay is shortened, so you can get started with things.

Because the friendly driver only provides the GPS driver module and does not have the source code, and the tested friendly driver does not completely parse the key data of GPS, the upper-layer application can only obtain the longitude and latitude, precision, UTC time. In this way, you can only search for Google Maps. Baidu maps provides positioning functions similar to this. Hal cannot return satellite status data (number of visible satellites, number of available satellites, and signal strength), leading to the inability to use professional GPS navigation software. The source code provided below is modified based on gps_qemu.c to resolve key GPS data and support navigation software such as Kay lide and Dao Tong. The following will begin from the GPS NMEA-0183 protocol to Android GPS Hal transplantation and module compilation load a brief introduction to how Android car navigator "made. The following source code (theoretically support all output NMEA-0183 format data serial port and USB
GPS ).

Download source code: Android GPS Hal for Ublox-6M (download link has been updated, modify part of the source code content and MK files)

I purchased 100 pieces of GPS module on X Bao, which is hard GPS, that is, the NMEA data is directly output on the serial port. So the first thing to do is to understand the NMEA data structure.

Example of standard NMEA-0183 data analysis (4 common data)

$ Information type, XXX,

Each line starts with $, followed by the information type, followed by data, separated by commas

Information type:

Gpgsv: Visible satellite information

Gpgll: Location Information

Uplmc: Minimum recommended positioning information

Gpvtg: Ground speed information

Gpgga: GPS Positioning Information

Gpgsa: current satellite information

 

$ Gpgga, 012440.00, 3202.1798, N, 11849.0763, E, 2.7, 40.2, 0.5, M, * 6f ..
1 time: 01 + 8 = 09:24, 40.00 seconds
2 latitude: 32 degrees 02.1798 points north latitude
3 longitude: longitude 118 degrees 49.0763 minutes
4 positioning: 1 = (positioning SPS mode) 0 = (uncertain)
5 applied satellites: 05
6 hdop: 2.7 meters
7. Altitude: 40.2
8 altitude units: M = (meters)
9 WGS84 level division: 0.5
10 WGS84 level division unit M (meters)
11
12 check bits: 6f

$ Gprs mc, 013946.00, A, 3202.1855, N, 11849.0769, E, 0.05, 218.30, 111105, 4.5, W, A * 20 ..
01 Time 01: 39 minutes 46.00 seconds
02 positioning status A = available v = warning (unavailable)
03 latitude: north latitude (n) 32 degrees 02.1855 points
04 longitude: longitude (e) 118 degrees 49.0769 points
05 relative displacement speed: 0.05 knots
06 relative displacement direction: 218.30 degrees
07 date: October 11, November 05 (day, day, month, year)
08
09
10 checkpoint

$ Gpgsa, A, 2.6, 2.5, 20, 1.0, * 35 ..
01 mode 2: A = automatic M = manual
02 Mode 1: 1 = undetermined 2 = 2D positioning 3 = 3D Positioning
03 satellite No.: 01 to 32
04 pdop-Position Precision dilution: (2.6) 0.5 -- 99.9
05 hdop-horizontal longitude dilution: (2.6) 0.5 -- 99.9
06 vdop-vertical longitude dilution: (1.0) 0.5 -- 99.9 07 test position 35

$ Gpgsv, 62,160, 23,189, 23,049, 24,150, 35*78 ..
01 total number of satellites receiving signals in the sky
02 total number of satellites positioned
03 total number of satellites in the sky
04 (,) is the satellite number 01-32, the satellite elevation angle is-90 degrees, the satellite azimuth angle is 000-359 degrees, the signal noise ratio is similar to 00-99db (,) (, 32) (, 35)
05 checksum checkbit * 78

After learning about NMEA data, we need to transplant GPS Hal. On the Android platform, we need to transplant the GPS content under the JNI layer, that is, the HAL Hardware Abstraction Layer just mentioned. The GPS hardware abstraction layer is not complex, including initialization of serial devices (or USB-to-serial devices), creation of GPS threads, NMEA Data Reading, parsing, and information callback. This provides a small amount of reference information in the android source code, that is, the gps_qemu.c file under the Android-2.3.1/SDK/emulator/GPS/directory. It needs to be used by us, and a lot of modifications and upgrades are required. For GPS
Hal's design first we need to understand several structures in the android source code (the structure content will not be posted, you can refer to the source code), respectively:

Gpslocation; gpsstatus; gpsinterface; gpscallbacks; gpsstate; nmeareader;
There are several important definitions of the GPS status:

# Define gps_status_none 0 // Unknown Status
# Define gps_status_session_begin 1 // navigation started
# Define gps_status_session_end 2 // stop navigation
# Define gps_status_engine_on 3 // powered but no navigation
# Define gps_status_engine_off 4 // No power-on status

How is GPS enabled and initialized:

See the figure below:

The changes to gps_qemu.c are different lines of source code (too much content ). Here we will only briefly describe the name and function of the function to be modified. For details about the modification, refer to the source code provided in the above link.

1. Modify the static int nmea_tokenizer_init (nmeatokenizer * t, const char * P, const char * End) function.

If (q> P) {-------- "if (q> = P) {// solve the bug that the white-space data cannot be read.
If (count <max_nmea_tokens ){
T-> tokens [count]. P = P;
T-> tokens [count]. End = Q;
Count + = 1;
}
}

2. Modify the following functions in sequence. For details, refer to the source code.

Static void nmea_reader_init (nmeareader * r)

Static void nmea_reader_set_callback (nmeareader * r, gps_location_callback CB)

Static void nmea_reader_parse (nmeareader * r) // callback of key information

Static void * gps_state_thread (void * Arg)

Static void gps_state_init (gpsstate * State) // initialize the serial port

 

3. Modify the nmeareader definition and add new members.

Typedef struct {
Int Pos;
Int overflow;
Int utc_year;
Int utc_mon;
Int utc_day;
Int utc_diff;
Gpslocation fix;
//********************************
Gpssvstatus sv_status;

Int sv_status_changed;
# Ifdef ublox_6m
Gpscallbacks callback;
 
# Else
//*********************************
Gps_location_callback callback;
# Endif
Char in [nmea_max_size + 1];
} Nmeareader;

3. Add the new function static int nmea_reader_update_accuracy (nmeareader * r, Token accuracy)

Used to parse GPS Positioning Accuracy information.

 

4. Add the 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>. So
Include $ (clear_vars)
Local_prelink_module: = false
Local_module_path: = $ (target_out_shared_libraries)/HW
Local_cflags + =-dqemu_hardware
Local_shared_libraries: = liblog libcutils libhardware
Local_src_files: = gps_qemu.c
Local_module: = GPS. Default
Local_module_tags: = ENG
Include $ (build_shared_library)
# Endif

5. Run gps_qemu.c Android. mk CP to the GPS directory (you can create a directory of any names) and cp gps to the compiled Android source code.

6. Compile. Because my target board is tiny210, execute the following commands in the android source code directory in sequence:

$ Source code directory/build/envsetup. Sh
$ Export target_product = full_mini210 // modify the directory of your own development board to the location generated by the target.
$ Mmm./GPS

After compilation, GPS is generated in the out/target/product/smdkv210/system/lib/HW/directory. default. so library, cp gps. default. so to the system/lib/HW/directory of the file system, generate. install the IMG image on the Development Board.

7. Install Kay lide on the Development Board and install the map package.

8. Boot Test

Use gps_test_plus_1.2.1 and Kay lide to test GPS respectively.

Figure:

1. gps_test_plus_1.2.1 test, satellite information Overview

 

2. Visible satellite, available satellite distribution test

3. Basic positioning information

4. GPS Satellite Timing Test

5. Test altitude and speed

6. Kay lide navigation test

7. Test basic GPS information

8. Location Testing

9. Ublox-6M Module

10.

 

 

 

Related Article

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.