Method for improving serial data use certainty
By defining the data structures for sending and receiving data and the state machine control strategy, the problem of low data transmission reliability in serial communication is solved, the determinism of data use is improved, and the requirements of high-security systems are met.
Patent Information
- Application Number
- CN202211618755.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-15
- Publication Date
- 2026-01-16
- Estimated Expiration
- 2042-12-15
AI Technical Summary
Serial communication in aviation embedded systems suffers from low data transmission efficiency and weak anti-interference capability, resulting in low reliability and failing to meet the deterministic data usage requirements of high-security and high-reliability systems.
By defining data structures for sending and receiving, a state machine control strategy is used to receive packet data and perform verification and judgment to ensure data integrity and correctness.
It improves the reliability of serial communication and the determinism of data usage, meeting the data transmission requirements of high-security systems.
Smart Images

Figure CN116320046B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of airborne embedded software design, in particular to a method for improving serial port data use certainty. BACKGROUND
[0002] Serial port communication mode is a widely used communication mode in aviation embedded systems, which is used to realize communication between onboard computers or between computers and other devices. The sending and receiving data message format is transmitted bit by bit with each time a binary 0 or 1 as the minimum unit, which has the advantage of simple transmission protocol, and can realize communication between different devices without configuring complex protocol chips or sub-cards, only through serial port communication. And it is point-to-point communication, which saves transmission lines in remote communication, and only a few lines can exchange information between systems.
[0003] However, the serial port communication mode also has certain disadvantages, such as low data transmission efficiency, weak anti-interference ability, and electromagnetic interference encountered in long-distance transmission process will affect the bit of data, resulting in low reliability of data transmission. Since serial port transmission itself is a low-reliability transmission mode, simple communication protocol and communication lines cannot provide high security and high reliability data for high security systems. SUMMARY
[0004] In order to solve the problem of communication data invalidation and low communication reliability caused by the simplicity of the communication protocol and communication line in the serial port communication process, the present application designs a method for improving the certainty of serial port data use. The method defines the transmission and reception format of serial port data and data packet method to improve the reliability of serial port communication and achieve the purpose of high security system data use certainty requirement.
[0005] The technical scheme for achieving the purpose of the application is as follows: a method for improving the certainty of serial port data use, comprising the following steps:
[0006] S1, defining a sending data structure body and a receiving data structure body;
[0007] S2, according to the sending data structure body, packeting serial port data and sending to the receiving buffer;
[0008] S3, receiving the packeted serial port data based on the control strategy of state machine;
[0009] S4, judging the checksum of the received serial port data;
[0010] S5, when the checksum judgment result is correct, packeting the serial port data according to the receiving data structure body and uploading.
[0011] Further, the defined sending data structure in step S1 includes a first packet header, a second packet header, serial port data, a checksum, and a packet trailer; and the defined receiving data structure includes serial port data and frame count.
[0012] Further, in step S3, the serial port data received after packet assembly is based on a state machine control strategy, which includes:
[0013] S31, judging the data in the receiving buffer;
[0014] S32, if the data in the buffer is updated, then the serial port data is received according to the state machine control strategy;
[0015] S33, repeating S31-S32 until the serial port data received in S2 is complete.
[0016] Further, in step S31, the data in the receiving buffer is judged, which includes:
[0017] If the data in the buffer is not updated, then the serial port data received after packet assembly is waited for after the data is updated;
[0018] If the data in the buffer is updated, then the serial port data received after packet assembly is received.
[0019] Further, in step S32, if the data in the buffer is updated, then the serial port data is received according to the state machine control strategy, which includes:
[0020] S321, the state machine enters state A, and continuously judges the received data until the received data is equal to the first packet header, and then the state machine enters state B;
[0021] S322, when the state machine is in state B, the received data is continuously received and judged whether it is equal to the second packet header;
[0022] S323, if it is equal, then the state machine enters state C and the received data is continuously received;
[0023] S324, the received data is judged with the packet trailer, and if the received data is not equal to the packet trailer, then the serial port data is accumulated by 1;
[0024] S325, repeating S324 until the received data is equal to the packet trailer, and then the state machine enters state D;
[0025] S326, judging whether the received data is the complete packet data in S2.
[0026] Further, in step S322, when the state machine is in state B, the received data is continuously received and judged whether it is equal to the second packet header, which includes:
[0027] When the received data is not equal to the second header, it is determined whether the received data is equal to the first header.
[0028] If the received data is equal to the first header, the state machine continues to be in the B state, and the first data fault code value is added by 1.
[0029] If the received data is not equal to the first header, the state machine is updated to the A state, and the second data fault code value is added by 1.
[0030] Further, in the step S326, whether the received data is the whole data in the S2 is determined according to whether the length of the received data in the S325 is valid, and whether the first data fault code value and the second data fault code value are within the set threshold range.
[0031] Further, in the step S4, the judgment method of the checksum of the received serial port data is that: whether the checksum of the received packaged serial port data in the S3 is same as the checksum of the packaged serial port data in the S2 is calculated and judged, and then it is indicated that the received packaged serial port data in the S3 is valid.
[0032] Compared with the prior art, the method for improving the serial port data use certainty has the advantages that: the method for improving the serial port data use certainty solves the problems of low serial port data transmission reliability and low data use certainty in the traditional serial port communication process. BRIEF DESCRIPTION OF DRAWINGS
[0033] In order to more clearly illustrate the technical scheme in the embodiments of the present application, the drawings needed to be used in the embodiment description will be briefly introduced.
[0034] Figure 1 It is a flow chart of the method for improving the serial port data use certainty in the present application.
[0035] Figure 2 It is a flow chart of the serial port data sending in the specific embodiment.
[0036] Figure 3 It is a format of the sending data structure body in the specific embodiment.
[0037] Figure 4 It is a format of the receiving data structure body in the specific embodiment.
[0038] Figure 5 It is a control strategy schematic diagram of the state machine in the specific embodiment. DETAILED DESCRIPTION
[0039] The application will be further described in connection with the specific embodiments. The advantages and features of the application will become more apparent from the description. However, these embodiments are only exemplary and do not constitute any limitation on the scope of the application. Those skilled in the art should understand that the details and forms of the technical solutions of the application can be modified or replaced without departing from the spirit and scope of the application, and such modifications and replacements fall within the protection scope of the application.
[0040] Serial communication has a wide application in aviation embedded systems due to its simple communication protocol and link and low wiring cost, and is a commonly used communication method between onboard computers or between computers and other devices. However, the serial communication has the disadvantages of low data transmission efficiency and weak anti-interference ability. In the process of long-distance transmission, electromagnetic interference will affect the bit of data, resulting in low reliability of data transmission, which will not only affect the flight safety of the aircraft, but also cannot meet the requirement of high safety and high reliability system on high determinacy of used data.
[0041] On this basis, the application discloses a method for improving determinacy of serial port data, as shown in Figure 1 The method comprises the following steps:
[0042] S1, defining a sending data structure body and a receiving data structure body.
[0043] In this step, the sending data structure body is defined according to the requirement of meeting determinacy, including a first header, a second header, serial port data, a checksum, and a trailer.
[0044] In this step, the receiving data structure body is defined according to the requirement of meeting determinacy, including serial port data and frame count.
[0045] S2, according to the sending data structure body, packetizing serial port data and sending to a receiving buffer.
[0046] S3, receiving serial port data after packetization based on a state machine control strategy.
[0047] Specifically, the receiving serial port data after packetization based on the state machine control strategy comprises the following steps.
[0048] S31, receiving buffer data judgment, comprising:
[0049] If the data in the buffer is not updated, the receiving serial port data after packetization is waited until the data is updated.
[0050] If the data in the buffer is updated, the receiving serial port data after packetization is performed.
[0051] S32, when the data in the buffer is updated, the serial port data is received according to the state machine control strategy, comprising:
[0052] S33, repeating S31-S32 until receiving the serial port data of the group packet in S2.
[0053] Further, the data in the receiving buffer judgment in step S31 comprises:
[0054] S321, the state machine enters A state, continuously judges the received data until the received data is equal to the first packet header, updates the state machine to enter B state;
[0055] S322, when the state machine is in B state, continuously receives data and judges whether the received data is equal to the second packet header;
[0056] S323, if equal, updates the state machine to enter C state and continuously receives data;
[0057] S324, judges the received data and the packet tail, if the received data is not equal to the packet tail, then the received serial port data is accumulated by 1;
[0058] S325, repeating S324 until the received data is equal to the packet tail, then updates the state machine to enter D state;
[0059] S326, judges whether the received data is the whole packet data in S2.
[0060] In an optional embodiment, in step S322, when the state machine is in B state, continuously receives data and judges whether the received data is equal to the second packet header, comprising:
[0061] when the received data is not equal to the second packet header, judges whether the received data is equal to the first packet header;
[0062] if the received data is equal to the first packet header, the state machine continues to be in B state, and the first data fault code value is accumulated by 1;
[0063] if the received data is not equal to the first packet header, the state machine is updated to A state, and the second data fault code value is accumulated by 1.
[0064] In an optional embodiment, in step S326, the judgment basis of whether the received data is the whole packet data in S2 is that whether the received data length in S325 is valid, and whether the first data fault code value and the second data fault code value are within the set threshold range.
[0065] S4, judges the check sum of the received serial port data.
[0066] In this step, the judgment method of the check sum of the received serial port data is that: calculating and judging whether the check sum of the received group packet serial port data in S3 is same as the check sum of the serial port data after grouping in S2, then indicating that the received group packet serial port data in S3 is valid.
[0067] S5, when the result of the check sum judgment is correct, then the serial port data is packaged according to the received data structure and uploaded.
[0068] The core idea of the method for improving the certainty of serial port data use is: formulating a serial port data sending and receiving data format; packaging and sending the serial port data to be sent according to the established serial port data sending format; receiving the serial port data to be received according to the strategy of the state machine; when a complete data packet is received, checking and calculating the received data to ensure the correctness of the received data; packaging the correct serial port data according to the established serial port data receiving format and uploading it to the application program for use. Through the use of the above method, the problem of low data use safety and insufficient reliability in the traditional serial port communication process is solved, and the high safety system meets the requirement of high data certainty.
[0069] The method for improving the certainty of serial port data use will be described below through specific embodiments, referring to Figure 2 The method for improving the certainty of serial port data use includes:
[0070] Step 1: Formulate a serial port sending data structure definition and a receiving data structure definition that meet the certainty requirement.
[0071] In this specific embodiment, referring to Figure 3 , it is a specific structure of a sending data structure, including byte 1 storing a header 1; byte 2 storing a header 2; byte 3 to byte 3+n storing serial port data; byte 4+n storing a check sum; and byte 5+n storing a trailer. The setting of the double headers can improve the certainty of the serial port data in the packaging process. Only when the first header and the second header are both correctly received, the program will continue to receive meaningful data, otherwise the header will continue to be determined. The setting of the check sum can improve the certainty of the data in the transmission process. If the data is disturbed by electromagnetic interference during serial port transmission, the check sum verification will be incorrect, and the user will discard the entire data packet. The setting of the trailer can clearly define when the reception of the entire data packet ends, improving the certainty of the execution of the receiving program.
[0072] In this specific embodiment, referring to Figure 4 , it is a specific structure of a receiving data structure, including byte 1 to byte n storing serial port data; and byte 1+n storing a frame count. The receiving data structure definition omits the setting of the header and the trailer, as well as the check sum. Because the object defined by the receiving data structure is legal data that meets the certainty requirement and has been judged by the program, it can directly provide safe data for the upper application program, so the redundant data bits are discarded. The frame count is to facilitate the application program to judge whether the current receiving data structure object is updated.
[0073] Step 2: The serial port data to be sent is packaged and sent according to the defined sending data structure body definition.
[0074] The specific method of packaging and sending the serial port data is that the serial port data to be sent is packaged and sent according to the defined sending data structure body definition, the definitions of the first packet header, the second packet header and the packet tail conform to the requirements of the upper layer data transmission protocol, that is, the sender and the receiver can uniformly send and receive the serial port data according to the protocol requirements. The check sum setting also complies with the requirements of the upper layer data transmission protocol, and the sender and the receiver calculate according to a unified algorithm. The commonly used algorithm is to calculate the cumulative sum of the sending data from low to high (from data 1 to data n) in byte order, discard the useless data bits overflowing from the cumulative sum, and only keep the valid low 8-bit data as the check sum data.
[0075] Step 3: Determine whether the receiving buffer has data updates. If there is data update, execute step 4, if there is no data update, continue to wait for data update.
[0076] Specifically, if the receiving buffer has new data updates, the relevant serial port receiving register will indicate data updates, and the execution program only needs to read whether the corresponding bit of the serial port receiving register changes to determine whether the data is updated.
[0077] Step 4: Receive the serial port data according to the definition and execution sequence of the receiving state machine.
[0078] The control strategy of the state machine includes: Figure 5
[0079] Step 401: The current state machine is in state A, and it is determined whether the received data is equal to the packet header 1 (i.e. the first packet header). If equal, update the state machine to enter state B and enter step 402. If not equal, continue to receive data, and the state machine is in state A to execute step 401.
[0080] Step 402: The current state machine is in state B, and it is determined whether the received data is equal to the packet header 2 (i.e. the second packet header). If equal, update the state machine to enter state C and enter step 403. If not equal, it is determined whether the received data is equal to the packet header 1. If equal to the packet header 1, the current state machine continues to be in state B, the first data fault code is incremented by 1 and step 402 is continued. If not equal to the packet header 1, update the state machine to enter state A, the second data fault code is incremented by 1 and step 401 is executed.
[0081] Step 403: the current state machine is in state C, and it is determined whether the received data is equal to the packet tail. If they are equal, the state machine is updated to enter state D and step 404 is executed. If they are not equal, the current state machine continues to be in state C to receive data, the data is put into the local receiving buffer, and the length of the received data is accumulated by 1 to continue step 403.
[0082] Step 404: the current state machine is in state D, and the receiving program is exited.
[0083] Step 5: it is determined whether a complete packet of data is received. If the receiving is completed, step 6 is executed. If the receiving is not completed, step 3 is continued to be executed.
[0084] Specifically, it is determined whether a complete packet of data is received. The determination is based on whether the length of the received data is valid. If the transmitted serial port data is fixed-length data, that is, the length of the transmitted data is not changed each time, it is determined whether the length of the received data is equal to the value defined by the fixed length. If the transmitted serial port data is variable-length data, that is, the length of the transmitted data changes each time, it is determined whether the length of the received data is within the range of the minimum serial port data length and the maximum serial port data length. If it is within the range, it represents that the receiving is valid. The value or range of the valid data length should be clearly defined in the upper layer data transmission protocol.
[0085] Specifically, the first data fault code and the second data fault code are also within the specified threshold range. The first data fault code records the number of times of receiving repeated packet header 1. The second data fault code records the number of times of not continuously receiving packet header 1 and packet header 2.
[0086] Step 6: when a complete packet of data is received, the received data is checked and calculated to ensure the correctness of the received data.
[0087] Specifically, the received data is checked and calculated. Only the cumulative sum of the received data from low to high (from data 1 to data n) in byte order is calculated, and the packet header and the packet tail are not calculated. The method of the checksum calculation must be consistent with the method of the checksum calculation of the transmitted data.
[0088] Step 7: it is determined whether the checksum of the complete packet of data is correct. If the checksum is correct, step 8 is executed. If the checksum is incorrect, the complete packet of data is discarded, and step 3 is executed to receive data again.
[0089] Specifically, it is determined whether the checksum of the complete packet of data is correct. The determination method is whether the data checksum calculated in the last item is equal to the checksum of the transmitted data. If they are not equal, it represents that an error occurs in the transmission process, the complete packet of data is uncertain, and the packet data cannot be continuously used. The new packet of data should be received again.
[0090] Step 8: The correct serial port data is packaged according to the established received data structure definition, and uploaded to the application for use.
[0091] Specifically, the correct data is received and packaged, the frame count is updated, and the frame count is generally calculated cumulatively. The application uses the received data by determining the update of the frame count. At this time, the data has been verified and meets the application requirements, and does not pose an uncertain risk to high-security systems.
[0092] The above serial port data use certainty improvement method solves the problems of low serial port data transmission reliability and low data use certainty in the traditional serial port communication process.
[0093] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
[0094] In addition, it should be understood that although the present specification is described in terms of embodiments, not every embodiment contains only one independent technical solution. The description of the specification is only for the sake of clarity, and those skilled in the art should consider the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other embodiments that those skilled in the art can understand.
Claims
1. A method for improving serial data usage certainty, characterized in that, The method comprises the following steps: S1, defining a sending data structure and a receiving data structure, wherein the sending data structure comprises a first packet header, a second packet header, serial port data, a checksum, and a packet tail, and the receiving data structure comprises serial port data and frame count; S2, grouping and sending serial port data to a receiving buffer according to the sending data structure; S3, receiving the grouped serial port data based on a state machine control strategy, comprising: S321, the state machine enters state A, continuously judging the received data until the received data is equal to the first packet header, and updating the state machine to enter state B; S322, when the state machine is in state B, continuously receiving data and judging whether the received data is equal to the second packet header; S323, if yes, updating the state machine to enter state C and continuously receiving data; S324, judging the received data and the packet tail, if the received data is not equal to the packet tail, the received serial port data is added by 1; S325, repeating S324 until the received data is equal to the packet tail, and updating the state machine to enter state D; S326, judging whether the received data is the whole packet data in S2; In step S322, when the state machine is in state B, continuously receiving data and judging whether the received data is equal to the second packet header, comprising: when the received data is not equal to the second packet header, judging whether the received data is equal to the first packet header; if yes, the state machine continues to be in state B, and the first data fault code value is added by 1; if no, the state machine is updated to state A, and the second data fault code value is added by 1; In step S326, the judgment basis of whether the received data is the whole packet data in S2 is that whether the length of the received data in S325 is valid, and whether the first data fault code value and the second data fault code value are within a set threshold range; S4, judging the checksum of the received serial port data; S5, when the checksum judgment result is correct, grouping and uploading the serial port data according to the receiving data structure.
2. The method of improving serial data usage certainty according to claim 1, wherein, In step S3, the control strategy based on the state machine receives the grouped serial port data, comprising: S31, judging the data in the receiving buffer; S32, when the data in the buffer is updated, receiving the serial port data according to the control strategy of the state machine; S33, repeating S31-S32 until the grouped serial port data in S2 is received completely.
3. The method of claim 2, wherein: In step S31, the judgment of the data in the receiving buffer comprises: If the data in the buffer is not updated, waiting for data update and then receiving the grouped serial port data; If the data in the buffer is updated, receiving the grouped serial port data.
4. The method for improving serial data usage certainty according to claim 1, wherein: In step S4, the judgment method of the checksum of the received serial port data is that whether the checksum of the received grouped serial port data in S3 is the same as the checksum of the grouped serial port data in S2, which indicates that the received grouped serial port data in S3 is valid.
Citation Information
Patent Citations
Frame identifying method for serial data
CN102510323A
Serial port command analysis method based on finite state machine and annular queue
CN107302531A