GPS data processing - zero basis JAVA

Title Content:

NMEA-0183 protocol is to establish a unified BTCM (Maritime Radio Technical Committee) standard in different GPS (Global Positioning System) navigation equipment. It is a set of communication agreement formulated by the National Marine Electronics Association of the United States. According to the standard specification of NMEA-0183 protocol, GPS receiver transmits the position, speed and other information to PC, PDA and other equipment through serial port.

Most GPS receivers and NMEA-0183 software are compatible with the most common GPS receiver protocol or GPS data processing software.

NMEA-0183 protocol defines many statements, but the commonly used or most compatible statements are only G P G G A , GPGGA, GPGGA,GPGSA, G P G S V , GPGSV, GPGSV,GPRMC, G P V T G , GPVTG, GPVTG, GPGLL, etc.

The format of the $GPRMC statement is as follows:

$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,A*50

The whole statement here is a text line, in which each field is separated by a comma "," and the size (length) of each field is different. The example here is only a possibility, and it cannot be considered that the size of the field is the same as that of the above example sentence.

Field 0: $GPRMC, statement ID, indicating that the statement is Recommended Minimum Specific GPS/TRANSIT Data (RMC)

Field 1: UTC time, hhmmss SSS format

Field 2: status, A = positioned, V = not positioned

Field 3: latitude ddmm Mmmm, degree division format (if the leading digits are insufficient, supplement 0)

Field 4: latitude N (north latitude) or S (south latitude)

Field 5: longitude dddmm Mmmm, degree division format (if the leading digits are insufficient, supplement 0)

Field 6: longitude E e (east longitude) or W (west longitude)

Field 7: speed, Knots

Field 8: azimuth, degrees

Field 9: UTC date, DDMMYY format

Field 10: magnetic declination, (000 - 180) degrees (if the leading digits are insufficient, supplement 0)

Field 11: magnetic declination direction, E = east, W = west

Field 16: check value

Here, "" is the checksum identifier, and the two digits after it are the checksum, which represents the hexadecimal value of the XOR value of all characters between "$" and "" (excluding these two characters). The checksum of the above example sentence is 50 in hexadecimal, that is, 80 in decimal.

Tip: the function of the operator is XOR. The value after the operation of all characters between $and * (the first character and the second character are XOR, the result is XOR with the third character, and so on) the result after the remainder of 65536 should be equal to the value of the two hexadecimal digits after * otherwise, it indicates that an error occurred in the transmission of this statement. Note that capital letters A-F will appear in this hexadecimal value. In addition, if you need, you can use integer ParseInt (s) obtains the integer number expressed by it from the String variable s; And integer ParseInt (s, 16) gets the hexadecimal number it expresses from the String variable s

Now, your program will read in a series of GPS outputs, including $GPRMC and other statements. At the end of the data, there is a separate line

END

Indicates the end of the data.

Your program needs to find out G P R M C language sentence , meter count school Check and , look for Out his in school Check just Indeed , and And word paragraph 2 surface show already set position of language sentence , from in meter count Out Time between , change count become north Beijing Time between . one second number according to in meeting package contain many strip GPRMC statement, calculate the checksum, find out that the checksum is correct, and field 2 represents the positioned statement, calculate the time from it, and convert it into Beijing time. Multiple entries will be included in one data GPRMC statement, calculate the checksum, find out that the checksum is correct, and field 2 represents the positioned statement, calculate the time from it, and convert it into Beijing time. Multiple GPRMC statements will be included in one data, and the Beijing time obtained by the last statement will be output as the result.

Your program must read a valid $GPRMC statement.

Input format:

Multiple GPS statements, each ending with a carriage return line feed. The last line is the three capital letters of END.

Output format:

6-digit time, expressed as:

hh:mm:ss

Where, hh is a two digit hour, and if it is less than two digits, 0 shall be filled in front of it; mm is a two digit minute. If it is less than two digits, fill 0 in front; ss is a two digit second. When it is less than two digits, it is preceded by 0.

Input sample:

$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,A*50

END

Output example:

10:48:13
Code 1

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int verifynum; //Initialization check value
        int verifynume_65536; //Define XOR value after remainder
        String input_data; //Initialize input string
        char input_char[]; //Define string array
        String time =null; // Initialization time, used to intercept time
        int hh = 0;
        int mm = 0;
        int ss = 0;
        int i;
        do {
            input_data = in.nextLine();  //Get input
            if (input_data.startsWith("$GPRMC") && input_data.charAt(18) == 'A') {
                input_char = input_data.toCharArray(); //Determine whether it complies with GPRMC and has been located
                 
                for (verifynum = input_char[1], i=2; input_char[i]!='*'; i++) {
                    verifynum ^= input_char[i]; //Calculate XOR value
                }
                verifynume_65536 = verifynum%65536; //XOR remainder
                if (verifynume_65536 == Integer.parseInt(input_data.substring(input_data.length()-2,input_data.length()),16)) {
                    time = input_data.substring(7,13); //If the XOR value is equal to the last two bits of the input string after hexadecimal conversion to an integer, the extraction time
                }
            }
        }while(input_data.equals("END") == false);
         
         
        hh = Integer.parseInt(time.substring(0, 2));
        mm = Integer.parseInt(time.substring(2, 4));
        ss = Integer.parseInt(time.substring(4, 6));
        hh = hh+8;
        hh = hh % 24;
        System.out.printf("%02d:%02d:%02d", hh, mm, ss);
    }
}

Code 1

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int count = 0;
		String[] GPS_data = new String[20];
		do
		{
			int cal = 0;
			String input_data = in.nextLine();	
		if (input_data.substring(1, 5).equals("GPRMC") && input_data.charAt(18) == 'A')
		{
			for (int j=1; j<GPS_data[count].length()-3; j++)
			{
				cal ^= GPS_data[count].charAt(j);
			}
			cal %= 65536;
			if (Integer.parseInt(input_data.substring(input_data.indexOf('*')+1),16) == cal)
			{
				GPS_data[count] = input_data;
			}
			count++;
		}
		}while(!in.nextLine().equals("END"));
		in.close();
		String[] data_split = new String[20];
		data_split = GPS_data[GPS_data.length-1].split(",");
		int hh = Integer.parseInt(data_split[1].substring(0, 2));
		String mm = data_split[1].substring(2, 4);
		String ss = data_split[1].substring(4, 6);
		hh = (hh+8)%24;
		if (hh<18)
			System.out.print(0);
		System.out.println(hh+":"+mm+":"+ss);
	}
}

Code 2

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] arry = new String[10];
		int m=0;
		do
		{
			arry[m] = in.nextLine();
			m++;
			
		}while (!in.nextLine().equals("END"));
		in.close();
		List<String> list = new ArrayList<String>();
		int verify = 0;
		for (int i=0; i<arry.length; i++)
		{
			if (arry[i].contains("GPRMC") && arry[i].split(",")[2].equals("A"))
			{
				for (int j = arry[i].indexOf("$")+1; j<arry[i].indexOf("*"); j++)
				{
					verify ^= arry[i].charAt(j);
				}
				verify = verify%65536;
				if (verify == Integer.parseInt((arry[i].substring(arry[i].indexOf("*")+1, arry[i].indexOf("*")+3)),16))
				{
					String[] temp = arry[i].split(",");
					list.add(temp[1]);
				}
			}
		}
		if (list.size() != 0)
		{
			int time = Integer.parseInt(list.get(list.size()-1));
			time = time + 8;
			if (time > 23)
				time = time - 24;
			System.out.print(time+":"+time+":"+time);
		}
	}
}

Code 3

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] GPS_data = new String[17];
		String input_data;
		String time = null;
		do {
			input_data = in.nextLine();
			if (input_data == "END") {
				break;
			}
			GPS_data = input_data.split(",");
			String ID = GPS_data[0];
			String status = GPS_data[2];
			String verifynum = GPS_data[16].substring(2);
			int sum = 0;
			if (ID == "$GPRMC" && status == "A") {
				for (int j=1; input_data.charAt(j) != '*'; j++) {
					sum ^= input_data.charAt(j);
				}
				sum = sum%65536;
				if (sum == Integer.parseInt(verifynum,16)) {
					time = GPS_data[1];
				}
			}	
		}while(true);
		
		int hh = Integer.parseInt(time.substring(0, 2));
		int mm = Integer.parseInt(time.substring(2, 4));
		int ss = Integer.parseInt(time.substring(4, 6));
		hh = (hh+8);
		hh = hh % 24;
		System.out.printf("%02d:%02d:%02d",hh,mm,ss);
	}
}

Tags: Java

Posted by michaellunsford on Wed, 11 May 2022 00:34:23 +0300