Reception of GPS positioning information

zhaozj2021-02-16  49

Location information

Usually the GPS positioning information receiving system is mainly composed of a GPS receiving antenna, a frequency converter, a signal channel, a microprocessor, a memory, and a power supply. Since the GPS positioning information is less, multi-RS-232 serial port transmits positioning information (NEMA0183 statement) from the GPS receiver to the computer for information extraction processing. There are several ways to read data from the serial port, where it is programmed directly with the Win32 API function. The hardware port is not allowed to control the hardware port under Windows. All ports are treated as "file", so they need to open the serial port before listening to the serial port, and perform related parameter configurations for the serial port, and perform related parameter configuration: m_hcom = CreateFile ("COM1", Generic_Read | Generic_Write, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); File: // Open COM1 Port Commmask in asynchronous mode; File: // Add or modify events reported by Windows List setupcomm (m_hcom, readbufflen / * read buffer * /, WriteBuflen / * write buffer * /); // Initialization communication device parameter // Clear buffer information purgecomm (m_hcom, purge_txabort | purge_rxabort | purge_txclear | purge_rxclear); // I / O setting CommTimeOuts.ReadIntervalTimeout = MAXDWORD; file: // receiving two consecutive bytes maximum time interval CommTimeOuts.ReadTotalTimeoutMultiplier = 0; file: // for each byte received average allowable time CommTimeOuts.ReadTotalTimeoutConstant = 0; file: // reception time constant SetCommTimeouts (m_hCom, & CommTimeOuts); file: // Get and set the serial port GetCommState (m_hCom, & dcb); dcb.BaudRate = CBR_4800; dcb.ByteSize = 8; dcb.Parity = ODDPARITY; dcb.StopBits = ONESTOPBIT ; Setcommstate (M_HCOM, & DCB);

After successful opening and seting the communication port, the polling serial port and event trigger can be taken to receive the data, and this article takes a reception process in the event trigger mode in which the efficiency is relatively high, by waiting for the occurrence of the EV_RXCHAR event to start readfile. GPS positioning function completes receiving the information: while (true) {WaitCommEvent (m_hCom, & dwEvtMask, NULL); if (dwEvtMask & EV_RXCHAR == EV_RXCHAR) if (ComStat.cbInQue> 0) ReadFile (m_hCom, m_readbuf, ComStat.cbInQue, & nLength, & Olread);

Extract data

The GPS receiver will continue to transfer the received and calculated GPS navigation positioning information to the computer through the serial port as long as it is in the working state. The previous code is only responsible for receiving data from the serial port and placing it in a cache, which is a long string byte stream in the caching before further processing, which cannot be utilized before the classification extraction. Therefore, it is necessary to extract the information of each field from the cache paragraph stream via the program, and the positioning information data that is converted to the actual significance can be used. Similar to other communication protocols, the information extraction of GPS must first clarify its frame structure, and then the extraction of each positioning information is completed according to its structure. For the Garmin GPS antenna board used herein, the data sent to the computer is mainly composed of frame head, frame end, and intra data, depending on the data frame, the frame head is not the same, mainly "$ GPGGA", "$ GPGSA, "$ GPGSV", and "$ GPRMC", etc.. These frame headers identify the compositional structure of subsequent intra data, each frame, and the end of the frame, the end of the frame, and the end of the frame. For usual cases, our positioning data, such as latitude and longitude, speed, time, etc., can be obtained from the "$ GPRMC" frame, the structure of the frame and the respective fields, as follows: $ GPRMC, <1>, <2> , <3>, <7>, <8>, <9>, <10>, <11> * hh

<1> Greenwich Time in the current location, format HHMMSS

<2> State, A is a valid location, V is a non-effective receive warning, namely the number of satellites above the current antenna point of less than 3.

<3> latitude, format is ddmm.mmmm

<4> indicates the north and south hemisphere, N is the northern hemisphere, S is the south hemisphere

<5> The stage, format is dddmm.mmmm

<6> Mandarin Hemisphere, E is the East Hemisphere, W is the Western Hemisphere

<7> The speed of the ground is 0.0 to 999.9

<8> Azimuth, range from 000.0 to 359.9 degrees

<9> Date, format is ddmmyy

<10> Diomagnetic change, from 000.0 to 180.0 degrees

<11> Genomagnetic change direction, E or W

As for several other frame formats, in addition to special purposes, it is not commonly used. Although the receiver also sends a variety of data frames to the host, it is generally only the judgment of the frame when processing. GPRMC "frame performs data extraction processing. If the situation is special, you need to get data from other frames, and the processing method is also totally similar. Since each data segment is divided by a comma, it is generally determined whether it is a frame header when the cache data is processed, and the number of the category is performed after the category of the frame. The count is to determine which positioning navigation parameter is currently being processed and processed accordingly. Below is the main code for unfraction processing of data in the cache data, this article only cares about time (date and time) and geographic coordinates (via, latitude): for (int i = 0; i

The desired information has now been extracted, namely, time, date, and latitude latitude, respectively, saved in the CString type variable m_stime, m_data, m_spositiony, and m_spositionx. In practical applications, it is often necessary to perform further arithmetic processing as needed, such as the time information obtained from the GPS receiver is GMN, so it is necessary to add 8 hours to my country for 8 hours. Moreover, the WGS-84 coordinate system used by GPS is also different from the coordinate system adopted by my country, and sometimes it is also converted. These transforms must be completed by numerical operations, so you need to convert the previously acquired characters variables to a valued variable, this part of the work can be placed in detecting the frame completion ::: strcpy (buf, m_stime); str.format "% C% C", BUF [0], BUF [1]); gpsparam [m_nnumber] .M_NHOUR = (ATOI (STR) 8)% 24; file: // Extract hour and converted to 24 hours Beijing Time File: // BUF 2nd, 3 bytes is minutes, 4, 5 bytes are seconds, extraction methods are the same ... :: strcpy (buf, m_sdate); str.format ("% C% C", BUF [ 0], buf [1]); file: // Extract the month File: // BUF 2nd, 3 bytes to the day, 4, 5 bytes as the year, extraction method is the same ... :: strcpy (buf, m_spositiony " Str.Format ("% C% C", BUF [0], BUF [1]); PositionValue = ATOI (STR); str.format ("% C% C% C% C% C% C% C% C% C% C) , BUF [2], BUF [3], BUF [4], BUF [5], BUF [6], BUF [7], BUF [8]); gpsparam [m_nnumber] .m_dpositiony = positionvalue * 60 atof (STR); File: // Extract the latitude ... :: strcpy (buf, m_spositionx); if (m_spositionx.getlength () == 10) File: // long length of 90 degrees (e.g., 125 degrees) {STR. Format ("% C% C% C", BUF [0], BUF [1], BUF [2]); PositionValue = ATOI (STR); str.format ("% C% C% C% C% C%) C% C, BUF [3], BUF [4], BUF [5], BUF [6], BUF [7], BUF [8], BUF [7], BUF [8], BUF [9]); gpsparam [m_nnnumber] .m_dpositionx = positionValue * 60 ATOF (STR); file: // Extracts the longitude (minute)} if (m_spositionx.getlength () == 9) File: // SME does not exceed 90 degrees (eg, East 89 degrees) {file: / / Treatment method is the same as above, only the 0th, 1 byte of the buf is the number of degrees, and 2 to 9 are scores. This is to this, and the time and latitude and longitude information have been extracted into each variable in the GPS structure array GPSPARAM, subsequent processing and high-level decisions can be processed according to the data stored in this structure.

转载请注明原文地址:https://www.9cbs.com/read-21714.html

New Post(0)