A baud rate and message protocol adaptive method and device
By adjusting the baud rate and message protocol type of the GPS module through software, the problem of adaptive function failure of the GPS module caused by inconsistent hardware design is solved, and the flexibility of the adaptive baud rate and message protocol is realized.
Patent Information
- Application Number
- CN202111479625.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-06
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2041-12-06
AI Technical Summary
In the prior art, the serial port hardware design of GPS module manufacturers and customers must be consistent, otherwise the adaptive baud rate function of GPS module cannot be realized.
The default baud rate and message protocol type of the GPS module are determined through software methods, and adjusted according to the target baud rate and message protocol type. The target message to be sent is sent to adjust the baud rate and message protocol type of the GPS module. , realize adaptive functions.
The adaptive baud rate and adaptive message protocol of the GPS module can be realized without consistent hardware design, improving flexibility and adaptability.
Smart Images

Figure CN114189316B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a baud rate and message protocol self-adaptation method and device. Background Art
[0002] Through the serial port hardware design and development of GPS module manufacturers and GPS module customers, the baud rate adaptation of the GPS module is realized by hardware design. For example, through circuit design, the pins of the communication serial port are connected to a logic high level or a logic low level through a resistor to adjust the communication baud rate of the GPS module.
[0003] In the prior art, the serial port hardware designs of the GPS module manufacturer and the GPS module customer need to be consistent. If they are not consistent, the adaptive baud rate function of the GPS module cannot be used. Summary of the invention
[0004] In view of this, the present invention provides a baud rate and message protocol adaptive method and device to solve the problem in the prior art that the serial port hardware design of the GPS module manufacturer and the GPS module customer must be consistent. If they are not consistent, the adaptive baud rate function of the GPS module cannot be used. The specific solution is as follows:
[0005] A baud rate and message protocol self-adaptation method is applied to a control terminal, the method comprising:
[0006] Determine the default baud rate and default message protocol type of the GPS module;
[0007] Comparing the default baud rate with the target baud rate, and comparing the default message protocol type with the target message protocol type;
[0008] When at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, the baud rate and the message protocol type in the message to be sent are adjusted to the target baud rate and the target message protocol type to obtain a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types;
[0009] The target message to be sent is sent to the GPS module, and the baud rate of the control terminal is adjusted to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type.
[0010] In the above method, optionally, the control terminal includes: a UART port, and determining the default baud rate and default message protocol type of the GPS module includes:
[0011] Modifying the baud rate of the UART port to a first bit rate, wherein the first baud rate is selected in sequence based on each baud rate in the candidate baud rate table or is selected in sequence from each selected baud rate in ascending or descending order;
[0012] Calling a function interface for modifying the baud rate change of the UART port, receiving message data sent by the GPS module based on the first baud rate in the function interface, performing data analysis on the message data, and determining the default baud rate of the GPS module based on the analysis result;
[0013] Based on the function interface, the output result of the data analysis is obtained, and based on the output result, the default message protocol type of the GPS module is determined.
[0014] The above method, optionally, determines the default baud rate of the GPS module based on the analysis result, including:
[0015] If the data and message protocol type sent by the GPS module are parsed within a preset time, the first baud rate is the default baud rate;
[0016] If the data sent by the GPS module and the message protocol type to which the message belongs are not parsed within the preset time, it is determined that the baud rate of the UART port does not match the baud rate of the GPS module port, and the baud rate of the UART port is continuously modified to a second baud rate, wherein the selection principle of the second baud rate is the same as that of the first baud rate, until the data sent by the GPS module is parsed, and the second baud rate is the default baud rate.
[0017] The above method, optionally, determines the default message protocol type of the GPS module based on the output result, including:
[0018] Obtaining a return value in the output result;
[0019] The default message protocol type of the GPS module is determined based on the return value.
[0020] The above method, optionally, determines the default message protocol type of the GPS module based on the return value, including:
[0021] When the data in NMEA format is parsed, the return value takes a first value, and based on the first value, the default message protocol type is determined to be the NMEA protocol;
[0022] When the data in UBX format is parsed, the return value takes a second value, and the default message protocol type is determined to be the UBX protocol based on the second value;
[0023] When both the data in UBX format and the data in NMEA format are parsed, the return value takes a third value, and the default message protocol type is determined to be the UBX protocol and the NMEA protocol based on the third value;
[0024] In the case that neither the data in the UBX format nor the data in the NMEA format is obtained, the return value takes a fourth value, and the baud rate mismatch is determined based on the fourth value.
[0025] The above method may optionally adjust the baud rate and the message protocol type in the message to be sent to the target baud rate and the target message protocol type to obtain the target message to be sent, including:
[0026] Obtain a first flag bit and a second flag bit in the message to be sent, wherein the first flag bit is used to identify the baud rate, and the second flag bit is used to identify the message protocol type;
[0027] Setting the first flag bit to a target baud rate;
[0028] The second flag bit is set to the target message protocol type to obtain the target message to be sent.
[0029] The above method may optionally further include:
[0030] If an abnormal situation is detected, an automatic correction program is started, and a target baud rate and a target message protocol type of the GPS module are reconfigured;
[0031] The abnormal conditions include: the baud rate of the UART port is modified, or the baud rate and message protocol type of the GPS module are modified, or the message data sent by the GPS module cannot be correctly received.
[0032] The above method may optionally include:
[0033] Determine the current message protocol type and current baud rate of the GPS module;
[0034] The current message protocol type and the current baud rate are configured as the target baud rate and target message protocol type of the GPS module.
[0035] A baud rate and message protocol adaptive device, applied to a control terminal, comprising:
[0036] A determination module is used to determine the default baud rate and default message protocol type of the GPS module;
[0037] A comparison module, used for comparing the default baud rate with the target baud rate, and comparing the default message protocol type with the target message protocol type;
[0038] An adjustment module, used for adjusting the baud rate and the message protocol type in the message to be sent to the target baud rate and the target message protocol type when at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, so as to obtain a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types;
[0039] A sending and adjustment module is used to send the target message to be sent to the GPS module, and at the same time adjust the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type.
[0040] In the above device, optionally, the control terminal includes: a UART port, and the determination module includes:
[0041] a modifying unit, configured to modify the baud rate of the UART port to a first bit rate, wherein the first baud rate is selected in sequence based on each baud rate in the candidate baud rate table or is selected in sequence from each selected baud rate in ascending or descending order;
[0042] A first judgment unit is used to call a function interface for modifying the baud rate change of the UART port, receive message data sent by the GPS module based on the first baud rate in the function interface, perform data analysis on the message data, and judge the default baud rate of the GPS module based on the analysis result;
[0043] The second judgment unit is used to obtain the output result of the data analysis based on the function interface, and judge the default message protocol type of the GPS module based on the output result.
[0044] Compared with the prior art, the present invention has the following advantages:
[0045] The invention discloses a baud rate and message protocol self-adaptation method and device, which determine the default baud rate and default message protocol type of a GPS module; compare the default baud rate with the target baud rate and the default message protocol type with the target message protocol type; when at least one of the comparison results is different, adjust the baud rate and message protocol type in the message to be sent to the target baud rate and target message protocol type to obtain the target message to be sent; send the target message to be sent to the GPS module, and adjust the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and adjusts the default message protocol type to the target message protocol type. The above process realizes the self-adaptation baud rate and the self-adaptation message protocol based on software, and is no longer limited to the serial port hardware design to keep consistent. Even if it is inconsistent, the self-adaptation baud rate and the self-adaptation message protocol can be realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A flow chart of a method for adaptive baud rate and adaptive message protocol disclosed in an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a UBX protocol message format disclosed in the prior art;
[0049] Figure 3 The present invention discloses a block diagram of a device structure of an adaptive baud rate and an adaptive message protocol according to an embodiment of the present application. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0052] The present invention discloses a method and device for adaptive baud rate and adaptive message protocol, which are applied in the process of realizing adaptive baud rate and adaptive message protocol of GPS module based on software, wherein the GPS module is a transceiver, which can receive satellite time, positioning and other messages, and send them to the corresponding UART port through the GPS port, and the GPS module can also be set through the UART port. In the prior art, the baud rate adaptation of the GPS module is realized in a hardware design manner through the serial port hardware design and development of the GPS module manufacturer and the GPS module customer. For example, through circuit design, the pins of the communication serial port are respectively connected to a logic high level or a logic low level through a resistor to adjust the communication baud rate of the GPS module, but the serial port hardware design of the GPS module manufacturer and the GPS module customer needs to be consistent. If it is not consistent, it is impossible to use the adaptive baud rate function of the GPS module. Based on the above problems, the present invention provides a method for adaptive baud rate and adaptive message protocol, which is applied to a control terminal. The execution flow of the method is as follows: Figure 1 As shown, the steps include:
[0053] S101, determining the default baud rate and default message protocol type of the GPS module;
[0054] In an embodiment of the present invention, the control terminal may be a controller, a processor, a CPU, etc. The specific existence form of the control terminal is not limited in the embodiment of the present invention. The control terminal includes a UART port, wherein the UART port is used to connect to the transceiver port of the GPS module. The method is used to realize the interaction between the control terminal and the GPS module. First, it is necessary to confirm the default baud rate and the default message type of the GPS module, wherein the default baud rate and the default message type may be set in the firmware of the GPS module itself, or may be saved in the last setting or implemented by other preferred setting methods. In the embodiment of the present invention, the determination form of the default baud rate and the default message type is not limited.
[0055] For the default baud rate, generally support 9600, 115200, 230400 and 460800 baud rates, preferably, the above baud rates can be pre-stored in the alternative baud rate table. For the default message type, the embodiment of the present invention generally supports UBX protocol and NMEA protocol or other preferred protocols.
[0056] For the UBX protocol message format, Figure 2 As shown, the BX protocol is composed of hexadecimal data, the frame header is 0xB50x62, followed by its own Class id and Message id, and then Length is the two-byte message length, which only includes Payload, and the bytes are low-endian. Payload is the output GPS data, and CK_A and CK_B are both one-byte check bits.
[0057] NMEA protocol is a standard format developed by the National Marine Electronics Association for marine electronic equipment. It is a set of standard information that defines the output of the receiver. There are several different formats, each of which is an independent and related ASCII format. The comma-separated data stream has a length ranging from 30-100 characters. It is usually selected for output at intervals per second. The most commonly used format is "GGA", which includes the positioning time, latitude, longitude, altitude, number of satellites used for positioning, DOP value, differential state and correction period, etc. Others include speed, tracking, date, etc. NMEA has actually become the most common data output format for all GPS receivers, and it is also used in most software packages that interface with GPS receivers. For example, the NMEA-0183 protocol defines a lot of statements, but the commonly used or most compatible statements are only $GPGGA, $GPGSA, $GPGSV, $GPRMC, $GPVTG, $GPGLL, etc. The message format is in the form of a string.
[0058] Further, the process of determining the default baud rate and default message protocol type of the GPS module is as follows:
[0059] First, by configuring the message type and baud rate of the GPS module, the message type can be UBX format and NMEA format or other preferred formats. Preferably, the embodiment of the present invention takes the message type as UBX format and NMEA format as an example for explanation. The baud rate can be pre-stored in the alternative baud rate table, and the baud rate of the UATR port is modified to the first baud rate through the software program. Preferably, the first baud rate can be selected in sequence based on the various baud rates in the alternative baud rate table or selected in sequence from the various selected baud rates in ascending or descending order or other preferred selection methods. In the embodiment of the present invention, the specific selection method is not limited. After the modification is completed, the function interface for modifying the baud rate of the UART port is called, the data of the GPS module is received based on the function interface, and the message data is parsed, and the default baud rate of the GPS module is judged based on the parsing result. Due to the serial software design, the baud rate of the UART port is modified with a delay of a period of time, for example 500ms, and then the function interface for receiving the message of the GPS module can be called to receive the message of the GPS module. If the reception is successful, data parsing is performed, and the parsing process is as follows: function interfaces for the above two protocols are written in advance based on the UBX protocol and the NMEA protocol, wherein the specific writing method is not limited in the embodiment of the present invention, and the message protocol type to which the above message belongs is parsed based on the above function interface, and the corresponding default message protocol type is obtained after parsing, indicating that the first baud rate is the default baud rate.
[0060] Furthermore, when the data and message protocol type of the GPS module cannot be parsed after a preset period of time, it is determined that the baud rate of the UART port does not match the baud rate of the GPS module port, and the baud rate of the UART port is further modified to a second baud rate, wherein the selection principle of the second baud rate is the same as that of the first baud rate, until the data sent by the GPS module can be parsed.
[0061] Since the GPS module sends data to the UART all the time after power-on, the data received by the UART port can be parsed all the time after power-on. At this time, the default message protocol type of the GPS module can be determined according to the parsing situation, and the default baud rate of the GPS module port at this time can be determined according to the baud rate of the current UART port. For example: on the basis of adopting the UBX protocol and the NMEA protocol, a function interface that can be parsed for the two protocols is written according to the characteristics of the protocol to determine the protocol type. The function interface can determine which protocol the message data of the GPS module adopts. If only data in the NMEA format can be parsed, it means that the message data is sent in the NMEA protocol, and the function interface returns a first value. Preferably, the first value is 0. If only data in the UBX format can be parsed, it means that the message data is sent in the UBX protocol. The function interface returns a second value. Preferably, the second value is 1. If both UBX format data and NMEA format data can be parsed, it means that the message data is sent in the UBX protocol. The function interface returns a third data. Preferably, the third value is 2. If neither of the two data is parsed, it means that the baud rates do not match, and the function interface returns a fourth value. Preferably, the fourth interface takes a value of -1.
[0062] For the above process, the function interface determines whether the baud rate is correct based on the return value after a period of time until the correct baud rate is matched. At the same time, the return value can also be used to determine which protocol or protocols the GPS module is sending at this time. In other words, at this time, the default message protocol type and default baud rate currently supported by the GPS module are already known. At this time, the baud rate of the UART port is consistent with the baud rate of the GPS module, so normal communication is possible.
[0063] S102, comparing the default baud rate with the target baud rate, and comparing the default message protocol type with the target message protocol type;
[0064] In an embodiment of the present invention, the target baud rate and the target message protocol type are the baud rate and message protocol type that the user wishes to adopt. It is necessary to determine whether the default baud rate is the same as the target baud rate, and at the same time determine whether the default message protocol type is the same as the target message protocol type. The default baud rate is compared with the target baud rate, and at the same time, the default message protocol type is compared with the target message protocol type to obtain a comparison result.
[0065] S103, when at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, adjusting the baud rate and the message protocol type in the message to be sent to the target baud rate and the target message protocol type, and obtaining a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types;
[0066] In an embodiment of the present invention, when at least one of the comparison results is different, a message to be sent is obtained, and according to the default message protocol type, the flag bits corresponding to the baud rate and the message protocol type in the message to be sent are adjusted to the target baud rate and the target message protocol type to obtain a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to the different default message protocol types. In an embodiment of the present invention, the UBX-CFG-PRT message is used as an example for explanation, and the UBX-CFG-PRT message can modify the baud rate and the supported protocol type of the GPS module. The baud rate and the supported protocol type of the GPS module can be modified by filling the payload.
[0067] The Payload format is shown in Table 1, where baudRate corresponds to the first flag bit of the baud rate, and outProtoMask corresponds to the second flag bit of the message protocol type.
[0068]
[0069] S104, sending the target message to be sent to the GPS module, and adjusting the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type.
[0070] In an embodiment of the present invention, the target message to be sent after modification can be sent to the GPS module through the tx end of the UART port, and the baud rate of the control terminal is adjusted to the target baud rate. When the target message to be sent is received in the GPS module, the target baud rate and target message protocol type of the target message to be sent are obtained, the default baud rate is adjusted to the target baud rate, and the default message protocol type is adjusted to the target message protocol type.
[0071] The present invention discloses a method and device for adaptive baud rate and adaptive message protocol, which determine the default baud rate and default message protocol type of a GPS module; compare the default baud rate with the target baud rate and the default message protocol type with the target message protocol type; when at least one of the comparison results is different, adjust the baud rate and message protocol type in the message to be sent to the target baud rate and target message protocol type to obtain the target message to be sent; send the target message to be sent to the GPS module, and adjust the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and adjusts the default message protocol type to the target message protocol type. The above process realizes adaptive baud rate and adaptive message protocol based on software, and is no longer limited to the consistency of serial port hardware design. Even if it is inconsistent, adaptive baud rate and adaptive message protocol can be realized.
[0072] In an embodiment of the present invention, during operation, due to abnormal circumstances, such as: user erroneous operation, modifying the baud rate of the UART port, or other programs accidentally modifying the baud rate of the UART port, etc., the baud rate or message protocol of the GPS module is modified, or the UART baud rate is modified, resulting in the inability to correctly receive the message sent by the GPS module, the target baud rate and target message protocol type of the GPS module can be reconfigured through an automatic correction program, wherein the processing process of the automatic correction program includes: determining the current message protocol type and the current baud rate of the GPS module; configuring the current message protocol type and the current baud rate as the target baud rate and target message protocol type of the GPS module, wherein the specific configuration process is the same as the process described in S101-S104, and will not be repeated here.
[0073] In the embodiment of the present invention, the above method can ignore the default baud rate setting of the system UART. It can also ignore the default baud rate and default message protocol of the GPS module. It can solve many problems and complexities caused by different default baud rates of the system serial port, different default message protocols of the GPS module and different baud rates of the GPS module by default.
[0074] Based on the above method for adaptive baud rate and adaptive message protocol, an embodiment of the present invention further provides an apparatus for adaptive baud rate and adaptive message protocol, which is applied to a control terminal. The structural block diagram of the apparatus is shown in FIG. Figure 3 As shown, the device comprises:
[0075] A determination module 201 , a comparison module 202 , an adjustment module 203 and a sending and adjustment module 204 .
[0076] in,
[0077] The determination module 201 is used to determine the default baud rate and default message protocol type of the GPS module;
[0078] The comparison module 202 is used to compare the default baud rate with the target baud rate, and compare the default message protocol type with the target message protocol type;
[0079] The adjustment module 203 is used to adjust the baud rate and the message protocol type in the message to be sent to the target baud rate and the target message protocol type when at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, so as to obtain the target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types;
[0080] The sending and adjusting module 204 is used to send the target message to be sent to the GPS module, and at the same time adjust the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type.
[0081] The invention discloses a device for adaptive baud rate and adaptive message protocol, which determines the default baud rate and default message protocol type of a GPS module; compares the default baud rate with the target baud rate and the default message protocol type with the target message protocol type; when at least one of the comparison results is different, adjusts the baud rate and message protocol type in the message to be sent to the target baud rate and the target message protocol type to obtain the target message to be sent; sends the target message to be sent to the GPS module, and adjusts the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts its corresponding default baud rate to the target baud rate based on the target message to be sent, and adjusts the default message protocol type to the target message protocol type. The above process realizes adaptive baud rate and adaptive message protocol based on software, and is no longer limited to the consistency of serial port hardware design. Even if it is inconsistent, adaptive baud rate and adaptive message protocol can be realized.
[0082] In the embodiment of the present invention, the control terminal includes: a UART port, and the determination module 201 includes:
[0083] Modification unit 205 , receiving unit 206 and determination unit 207 .
[0084] in,
[0085] The modifying unit 205 is used to modify the baud rate of the UART port to a first bit rate, wherein the first baud rate is selected in sequence based on each baud rate in the candidate baud rate table or is selected in sequence from each selected baud rate in ascending or descending order;
[0086] The first judgment unit 206 is used to call a function interface for modifying the baud rate change of the UART port, receive the message data sent by the GPS module based on the first baud rate in the function interface, perform data analysis on the message data, and judge the default baud rate of the GPS module based on the analysis result;
[0087] The second judgment unit 207 is used to obtain the output result of the data analysis based on the function interface, and judge the default message protocol type of the GPS module based on the output result.
[0088] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0089] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0090] For the convenience of description, the above device is described as being divided into various units according to their functions. Of course, when implementing the present invention, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0091] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present invention can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present invention or certain parts of the embodiments.
[0092] The above is a detailed introduction to the baud rate and message protocol adaptive method and device provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A baud rate and message protocol adaptive method, characterized in that: Applied to a control terminal, the method comprises: Determine the default baud rate and default message protocol type of the GPS module; Comparing the default baud rate with the target baud rate, and comparing the default message protocol type with the target message protocol type; When at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, the baud rate and the message protocol type in the message to be sent are adjusted to the target baud rate and the target message protocol type to obtain a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types; Sending the target message to be sent to the GPS module, and adjusting the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts the corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type; The control terminal includes: a UART port, which determines the default baud rate and default message protocol type of the GPS module, including: Modifying the baud rate of the UART port to a first baud rate, wherein the first baud rate is selected in sequence based on each baud rate in the candidate baud rate table or is selected in sequence from each selected baud rate in ascending or descending order; Calling a function interface for modifying the baud rate change of the UART port, receiving message data sent by the GPS module based on the first baud rate in the function interface, performing data analysis on the message data, and determining the default baud rate of the GPS module based on the analysis result; Based on the function interface, obtaining the output result of the data analysis, and based on the output result, determining the default message protocol type of the GPS module; The default baud rate of the GPS module is determined based on the analysis result, including: If the data and message protocol type sent by the GPS module are parsed within a preset time, the first baud rate is the default baud rate; If the data sent by the GPS module and the message protocol type to which the message belongs are not parsed within the preset time, it is determined that the baud rate of the UART port does not match the baud rate of the GPS module port, and the baud rate of the UART port is continuously modified to a second baud rate, wherein the selection principle of the second baud rate is the same as that of the first baud rate, until the data sent by the GPS module is parsed, and the second baud rate is the default baud rate.
2. The method according to claim 1, characterized in that: Based on the output result, determining the default message protocol type of the GPS module includes: Obtaining a return value in the output result; The default message protocol type of the GPS module is determined based on the return value.
3. The method according to claim 2, characterized in that Determining the default message protocol type of the GPS module based on the return value includes: When the data in NMEA format is parsed, the return value takes a first value, and based on the first value, the default message protocol type is determined to be the NMEA protocol; When the data in UBX format is parsed, the return value takes a second value, and based on the second value, the default message protocol type is determined to be the UBX protocol; In the case where both the data in UBX format and the data in NMEA format are parsed, the return value takes a third value, and the default message protocol type is determined to be the UBX protocol and the NMEA protocol based on the third value; In the case that neither the data in the UBX format nor the data in the NMEA format is obtained, the return value takes a fourth value, and the baud rate mismatch is determined based on the fourth value.
4. The method according to any one of claims 1 to 3, characterized in that: The baud rate and the message protocol type in the message to be sent are adjusted to the target baud rate and the target message protocol type, and the target message to be sent is obtained, including: Obtain a first flag bit and a second flag bit in the message to be sent, wherein the first flag bit is used to identify the baud rate, and the second flag bit is used to identify the message protocol type; Setting the first flag bit to a target baud rate; The second flag bit is set to the target message protocol type to obtain the target message to be sent.
5. The method according to any one of claims 1 to 3, characterized in that: Also includes: If an abnormal situation is detected, an automatic correction program is started, and a target baud rate and a target message protocol type of the GPS module are reconfigured; The abnormal conditions include: the baud rate of the UART port is modified, or the baud rate and message protocol type of the GPS module are modified, or the message data sent by the GPS module cannot be correctly received.
6. The method according to claim 5, characterized in that Starts the automatic calibration procedure, including: Determine the current message protocol type and current baud rate of the GPS module; The current message protocol type and the current baud rate are configured as the target baud rate and target message protocol type of the GPS module.
7. A baud rate and message protocol adaptive device, characterized in that: Applied to a control terminal, the device comprises: A determination module is used to determine the default baud rate and default message protocol type of the GPS module; A comparison module, used for comparing the default baud rate with the target baud rate, and comparing the default message protocol type with the target message protocol type; An adjustment module, used for adjusting the baud rate and the message protocol type in the message to be sent to the target baud rate and the target message protocol type when at least one of the comparison results of the default baud rate and the target baud rate and the default message protocol and the target message protocol is different, so as to obtain a target message to be sent, wherein the flag bits corresponding to the baud rate and the message protocol type in the target message to be sent are different according to different default message protocol types; A sending and adjusting module, used for sending the target message to be sent to the GPS module, and adjusting the baud rate of the control terminal to the target baud rate, so that the GPS module adjusts the corresponding default baud rate to the target baud rate based on the target message to be sent, and the default message protocol type is adjusted to the target message protocol type; The control terminal includes: a UART port, and the determination module includes: a modifying unit, configured to modify the baud rate of the UART port to a first baud rate, wherein the first baud rate is selected in sequence based on each baud rate in the candidate baud rate table or is selected in sequence from each selected baud rate in ascending or descending order; A first judgment unit is used to call a function interface for modifying the baud rate change of the UART port, receive message data sent by the GPS module based on the first baud rate in the function interface, perform data analysis on the message data, and judge the default baud rate of the GPS module based on the analysis result; A second judgment unit is used to obtain an output result of the data analysis based on the function interface, and judge the default message protocol type of the GPS module based on the output result; The first determination unit determines the default baud rate of the GPS module based on the analysis result, including: If the data and message protocol type sent by the GPS module are parsed within a preset time, the first baud rate is the default baud rate; If the data sent by the GPS module and the message protocol type to which the message belongs are not parsed within the preset time, it is determined that the baud rate of the UART port does not match the baud rate of the GPS module port, and the baud rate of the UART port is continuously modified to a second baud rate, wherein the selection principle of the second baud rate is the same as that of the first baud rate, until the data sent by the GPS module is parsed, and the second baud rate is the default baud rate.
