WO2021115142A1 - Serial data encoding method and apparatus, and embedded device and communication system - Google Patents

Serial data encoding method and apparatus, and embedded device and communication system Download PDF

Info

Publication number
WO2021115142A1
WO2021115142A1 PCT/CN2020/132317 CN2020132317W WO2021115142A1 WO 2021115142 A1 WO2021115142 A1 WO 2021115142A1 CN 2020132317 W CN2020132317 W CN 2020132317W WO 2021115142 A1 WO2021115142 A1 WO 2021115142A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
split
serial port
transmission data
coded
Prior art date
Application number
PCT/CN2020/132317
Other languages
French (fr)
Chinese (zh)
Inventor
牛洪芳
Original Assignee
深圳市道通智能航空技术股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市道通智能航空技术股份有限公司 filed Critical 深圳市道通智能航空技术股份有限公司
Publication of WO2021115142A1 publication Critical patent/WO2021115142A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M13/00Coding, decoding or code conversion, for error detection or error correction; Coding theory basic assumptions; Coding bounds; Error probability evaluation methods; Channel models; Simulation or testing of codes
    • H03M13/65Purpose and implementation aspects
    • H03M13/6502Reduction of hardware complexity or efficient processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0002Serial port, e.g. RS232C

Definitions

  • the present invention relates to the field of coding communication, in particular to a serial data coding method, device, embedded device and communication system.
  • serial port data sent by the source device is communication data
  • its content includes Linux debugging command messages. This part of the message will be intercepted by the bottom layer of the destination device, making the serial port data reaching the application layer of the destination device incomplete, resulting in abnormal device communication.
  • the embodiments of the present invention aim to provide a serial port data encoding method, device, embedded device, and communication system, which can improve the reliability of device communication.
  • the embodiments of the present invention provide the following technical solutions:
  • an embodiment of the present invention provides a serial port data encoding method, including:
  • serial port data includes at least one message format segment
  • both the first split data and the second split data are less than or equal to the first preset Values, respectively adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission data, Therefore, neither the first split-coded transmission data and the second split-coded transmission data include character data.
  • the converting the serial port data of the target message format segment into the serial encoded data of the preset base includes:
  • the encoded serial port coded data is converted into hexadecimal serial port coded data.
  • the message format segment includes a frame header segment, a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment;
  • the target message The format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
  • the first preset value is 0x9999
  • the second preset value is 0x30.
  • adding the serial port coded data to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not include character data includes:
  • Each byte of the serial port coded data is respectively added with hexadecimal 0x30 to obtain coded transmission data, so that the coded transmission data does not include character data.
  • the method further includes:
  • the encoded transmission data is sent through the serial port.
  • the first splitting data and the second splitting data are respectively added to the second preset value of the preset base to obtain the first splitting coded transmission data and the second splitting data.
  • Split-encoded transmission data so that neither the first split-coded transmission data nor the second split-coded transmission data contains character-type data, including:
  • the method further includes:
  • the first split-coded transmission data and the second split-coded transmission data are sent through a serial port.
  • an embodiment of the present invention provides a serial port data encoding device, including:
  • An acquisition module for acquiring serial port data, where the serial port data includes at least one message format segment;
  • the conversion module is used to convert the serial port data of the target message format segment into the preset serial port code data
  • a judging module configured to judge whether the serial port coded data is less than or equal to the first preset value of the preset base
  • the first encoding module is configured to add the serial port encoding data to the second preset value of the preset base if the serial port encoding data is less than or equal to the first preset value of the preset base Obtain coded transmission data, so that the coded transmission data does not contain character data;
  • the second encoding module is configured to split the serial port encoding data into the first split data and the second split data if the serial port encoding data is greater than the first preset value of the preset base.
  • the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added to the preset value respectively.
  • the device further includes:
  • the first sending module is used to send the encoded transmission data through the serial port.
  • the device further includes:
  • the second sending module sends the first split-coded transmission data and the second split-coded transmission data through the serial port.
  • an embedded device including:
  • At least one processor and,
  • a memory communicatively connected with the at least one processor; wherein,
  • the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the method as described above.
  • an embodiment of the present invention provides a communication system, including:
  • At least two embedded devices as described above;
  • the upper computer communicates with the embedded device.
  • embodiments of the present invention also provide a non-volatile computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above The method described.
  • the serial data encoding method, device, embedded device, and communication system provided by the embodiments of the present invention can change the target message format by acquiring the serial port data.
  • the serial port data of the segment is converted into the serial code data of the preset hexadecimal, and it is judged whether the serial code data is less than or equal to the first preset value of the preset hexadecimal. If so, the serial code data is added to the second of the preset hexadecimal
  • the preset value is used to obtain the coded transmission data so that the coded transmission data does not contain character data.
  • the serial port coded data is split into the first split data and the second split data, the first split data and the second split data
  • the split data is less than or equal to the first preset value, and the first split data and the second split data are respectively added to the second preset value of the preset base to obtain the first split coded transmission data and the second split data.
  • Split-coded transmission data so that neither the first split-coded transmission data nor the second split-coded transmission data contains character-type data. Therefore, in the embodiment of the present invention, the encoded transmission data, the first split-coded transmission data, and the second split-coded transmission data do not contain character data, so that the serial port data reaching the application layer of the target device is complete, and the device communication is improved. Reliability.
  • the serial port coded data is added to the second preset value of the preset base to obtain the encoded transmission data, if not, then Split the serial port encoding data into the first split data and the second split data.
  • the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively The split data plus the second preset value of the preset hexadecimal number to obtain the first split-coded transmission data and the second split-coded transmission data, thereby limiting the encoded transmission data, the first split-coded transmission data, and the second split-coded transmission data.
  • the size of the encoded transmission data is divided to avoid data overflow, so that the serial port data reaching the application layer of the destination device is correct, and the reliability of device communication is further improved.
  • FIG. 1 is a schematic structural diagram of a communication system provided by an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a serial data encoding method provided by an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a method for encoding serial port data according to another embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a serial data encoding device provided by an embodiment of the present invention.
  • Fig. 5 is a device schematic diagram of a serial data encoding device provided by another embodiment of the present invention.
  • An embodiment of the present invention provides an embedded device that includes at least one processor and a memory communicatively connected to the at least one processor, wherein the memory stores the memory that can be executed by the at least one processor The instructions are executed by the at least one processor, so that the at least one processor can execute the serial data encoding method described in the following method embodiments.
  • the embedded device refers to a device or device including an embedded system.
  • An embedded system is a special computer system that is embedded in a controlled device and designed for a specific application. It is used to control, monitor or assist equipment, machinery or equipment used in factory operations. Unlike general-purpose computer systems such as personal computers, embedded systems usually perform predefined tasks with specific requirements.
  • an embedded operating system runs on the embedded system.
  • the embedded operating system is a kind of system software with a wide range of uses, which usually includes hardware-related underlying driver software, system kernel, device driver interface, communication protocol, graphical interface, standardized browser, and the like.
  • the embedded operating system is responsible for the allocation of all software and hardware resources of the embedded system, task scheduling, control and coordination of concurrent activities. It must reflect the characteristics of the system where it is located, and be able to achieve the functions required by the embedded system by loading and unloading certain modules.
  • Currently widely used operating systems in the embedded field include: embedded real-time operating systems C/OS-II, embedded Linux, Windows Embedded, VxWorks, etc., as well as Android, iOS, etc., which are used in smart phones and tablet computers.
  • processor and the memory may be connected by a bus or in other ways.
  • the memory can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as those corresponding to the serial data encoding method in the embodiment of the present invention
  • Program instructions/modules for example, the various modules shown in Fig. 4 or Fig. 5
  • the processor executes the serial data encoding method described in the following method embodiments by running non-volatile software programs, instructions, and modules stored in the memory.
  • the memory may include a storage program area and a storage data area, where the storage program area can store an operating system and an application program required by at least one function; the storage data area can store the use of the serial data encoding device according to the following device embodiments The created data, etc.
  • the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
  • the memory may optionally include a memory remotely arranged with respect to the processor, and these remote memories may be connected to the serial data encoding device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
  • the one or more modules are stored in the memory, and when executed by the one or more processors, the serial port data encoding method in any of the following method embodiments is executed, for example, the implementation of Figure 2 or Figure
  • the method steps shown in 3 realize the functions of each module and each unit in FIG. 4 or FIG. 5.
  • the embodiment of the present invention provides an embedded device, which improves the reliability of device communication by executing the serial data encoding method in the following method embodiment.
  • FIG. 1 is a schematic structural diagram of a communication system according to an embodiment of the present invention.
  • the communication system 100 includes at least two embedded devices and a host computer 20 as described above, and the host computer 20 is in communication connection with the embedded device.
  • the at least two embedded devices include embedded device A and embedded device B.
  • the embedded device A, the embedded device B, and the host computer 20 all include at least one serial port, and the serial port is used for device communication.
  • the embedded device A as the destination device, the embedded device B as the source device, and the host computer 20 as the debugging device as an example
  • the serial port function of the host computer 20 is prohibited, and the serial port of the embedded device A receives the serial port data sent by the embedded device B; when the host computer 20 debugs the embedded device A , Disable the serial port function of the embedded device B, and the serial port of the embedded device A receives the debugging instruction message sent by the host computer 20.
  • the embedded device A runs the embedded operating system, it means that the embedded device A starts the data communication function, and the serial port function of the host computer 20 is disabled; when the embedded device A receives all The debugging request of the host computer 20 triggers the prohibition of the serial port function of other embedded devices (the embedded device B), so that the embedded device A receives the debugging instruction message sent by the host computer 20. Therefore, by prohibiting the serial port functions of the other devices when the two devices are performing serial data communication, interference from the other devices is avoided, and the reliability of device communication is improved.
  • the embodiment of the present invention provides a communication system, which improves the reliability of device communication by running the serial port data encoding method in the following method embodiments in an embedded device.
  • Fig. 2 is a schematic flowchart of a method for encoding serial port data according to an embodiment of the present invention.
  • the serial data encoding method includes:
  • S10 Acquire serial port data, where the serial port data includes at least one message format segment.
  • the serial data encoding method can be applied to any two embedded devices that communicate with each other.
  • the method before the obtaining the serial port data, the method further includes: receiving a communication request; returning a response message according to the communication request to establish a communication connection between the source device and the destination device; receiving a success response message, It is forbidden to receive communication requests from other devices. Therefore, it is ensured that in any communication process, there are only two communication equipment objects, and the interference of other equipment is avoided.
  • serial port data is the data to be sent from the embedded source device
  • message format segments of the serial port data include frame header segment, message instruction segment, source device segment, destination device segment, frame sequence number segment, content length segment, Content segment and check code segment.
  • the frame header segment of the serial port data includes 1 byte, and the frame header is the start byte of the serial port data, starting with 0xFD;
  • the message command segment of the serial port data includes 1 byte , The message instruction indicates what this frame of serial port data specifically does;
  • the source device section of the serial port data includes 1 byte, the source device indicates the IP address of the source device of the serial port data;
  • the destination device section of the serial port data Including 1 byte, the destination device indicates the IP address of the destination device of the serial port data;
  • the frame sequence number field of the serial port data includes 1 byte, each time a frame of serial port data is sent, the frame sequence number is increased by 1, and is in 0x00- Circulate between 0xFF;
  • the content length section of the serial port data includes 2 bytes, and the content length indicates the actual length of this frame of serial port data;
  • the content section of the serial port data includes N bytes, where N ⁇ 1, the content
  • the bytes from the message command to the check code are not fixed and are not limited to the specific byte length disclosed in Table 1.
  • the message format of the serial port data is not limited to the specific message format disclosed in this embodiment, and can be changed according to the communication protocol on which the serial port data is based.
  • the converting the serial port data of the target message format segment into the serial code data of the preset base includes: using the BCD code to compare the serial port of the target message format segment
  • the data is encoded; the encoded serial port coded data is converted into hexadecimal serial port coded data.
  • the target message format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
  • the debug message command Since the random combination of the message command and the check code may appear the debug message command, for example,'cd','mkdir','*#$&,/', etc., it is necessary to change the message command to the word in the check code. Section encoding, so that the serial data sent through the serial port does not include the character data contained in the debugging message command, so that the normal communication serial data is different from the debugging command message sent by the host computer, and avoiding part of the data in the serial data sent through the serial port. It is intercepted as a debugging command message, causing the problem of incomplete communication data.
  • S30 Determine whether the serial port coded data is less than or equal to the first preset value of the preset base.
  • the first preset value is 0x9999
  • the second preset value is 0x30.
  • the said adding the serial port coded data to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not contain character data includes: adding each part of the serial port coded data One byte is respectively added with hexadecimal 0x30 to obtain the coded transmission data, so that the coded transmission data does not include character data.
  • the corresponding ASCII code includes symbols such as space, carriage return, line feed,'*#$&,/', these are debugging command messages . If you directly add 0x30 on the basis of the original protocol, you can avoid these symbols, but if the data content is greater than 0xCF, after adding 0x30, it must be greater than 0xFF, causing data overflow and content errors.
  • each byte of the serial port coded data before adding each byte of the serial port coded data to 0x30 in hexadecimal to obtain the coded transmission data, it is necessary to determine whether the serial port coded data is less than or equal to the first value of the preset number.
  • the preset value if the serial port coded data is less than or equal to the first preset value of the preset base, each byte of the serial port coded data after adding 0x30 in hexadecimal, will not exceed 0xFF, Then the encoded transmission data will not overflow and error, and the serial port data can be completely restored by decoding the encoded transmission data at the destination device.
  • the corresponding serial port coded data is less than 0x9999, add each byte of the serial port coded data to hexadecimal 0x30 to obtain the coded transmission data, and the range of the coded transmission data changes It becomes 0x30 ⁇ 0xc9c9, which avoids the ASCII code corresponding to data smaller than 0x30 and does not cause data overflow.
  • the encoded transmission data after encoding is shown in Table 2.
  • the encoded data is added to the second preset value of the preset base to obtain encoded transmission data, so that the encoded transmission data does not contain characters
  • the method further includes:
  • S50 If not, split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the first split data. Preset values, respectively adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission Data, so that neither the first split-coded transmission data and the second split-coded transmission data contain character-type data.
  • the first splitting data and the second splitting data are respectively added to the second preset value of the preset base to obtain the first splitting coded transmission data and the second splitting data.
  • the method further includes:
  • S70 Send the first split-coded transmission data and the second split-coded transmission data through the serial port.
  • the destination device decodes the first split-coded transmission data and the second split-coded transmission data
  • the decoded first split-coded transmission data and the second split are combined.
  • the serial port data can be completely restored.
  • the embodiment of the present invention provides a method for encoding serial port data.
  • the serial port data of the target message format segment is converted into serial port encoding data of a preset base, and it is judged whether the serial port encoding data is less than or equal to the preset base.
  • the embodiment of the present invention makes the coded transmission data, the first split-coded transmission data, and the second split-coded transmission data not contain character data, so that the serial port data reaching the application layer of the destination device is complete and improves Reliability of equipment communication.
  • the serial port coded data is less than or equal to the first preset value of the preset base, if it is, the serial port coded data is added to the second preset value of the preset base to obtain the encoded transmission data, if not, then Split the serial port encoding data into the first split data and the second split data.
  • the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively divided into the first split data and the second split data.
  • the size of the encoded transmission data is divided to avoid data overflow, so that the serial port data reaching the application layer of the destination device is correct, and the reliability of device communication is further improved.
  • FIG. 4 is a schematic diagram of a serial port data encoding device provided by an embodiment of the present invention.
  • the serial data encoding device 400 includes an acquisition module 401, a conversion module 402, a judgment module 403, a first encoding module 404, and a second encoding module 405.
  • the acquiring module 401 is configured to acquire serial port data, and the serial port data includes at least one message format segment.
  • the message format segment includes a frame header segment, a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
  • the conversion module 402 is used to convert the serial port data of the target message format segment into serial port coded data with a preset hexadecimal system.
  • the target message format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
  • the conversion module 402 includes a first encoding unit 4021 and a conversion unit 4022.
  • the first encoding unit 4021 is configured to use the BCD code to encode the serial port data in the target message format segment.
  • the conversion unit 4022 is configured to convert the encoded serial port code data into hexadecimal serial port code data.
  • the judging module 403 is used to judge whether the serial port coded data is less than or equal to the first preset value of the preset base.
  • the first encoding module 404 is configured to add the serial code data to the second preset value of the preset base if the serial port encoding data is less than or equal to the first preset value of the preset base. Set the value to obtain the coded transmission data so that the coded transmission data does not contain character data.
  • the first preset value is 0x9999
  • the second preset value is 0x30.
  • the first encoding module 404 includes a second encoding unit 4041.
  • the second encoding unit 4041 is used to add hexadecimal 0x30 to each byte of the serial port encoding data to obtain encoded transmission data, so that all The encoded transmission data does not contain character data.
  • the second encoding module 405 is configured to split the serial port encoding data into first split data and second split data if the serial port encoding data is greater than the first preset value of the preset base. , The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added to the preset value, respectively. Set the second preset value of the base to obtain the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data nor the second split-coded transmission data contains Character data.
  • the second encoding module 405 includes a splitting unit 4051 and a third encoding unit 4052.
  • the splitting unit 4051 is configured to split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the The first preset value.
  • the third encoding unit 4052 is configured to add hexadecimal 0x30 to each byte of the first split data and the second split data to obtain the first split encoded transmission data and the second split data.
  • the transmission data is divided-encoded, so that neither the first divided-coded transmission data nor the second divided-coded transmission data contains character data.
  • the serial data encoding device 500 includes the serial data encoding device 400 described in the foregoing embodiment. For similarities, please refer to the foregoing embodiments, which will not be repeated here. The difference is that the serial data encoding device 500 further includes a first sending module 501 and a second sending module 502.
  • the first sending module 501 is configured to send the encoded transmission data through a serial port.
  • the second sending module 502 sends the first split-coded transmission data and the second split-coded transmission data through a serial port.
  • the embodiment of the present invention provides a serial port data encoding device.
  • the serial port data is obtained through an acquisition module.
  • the conversion module converts the serial port data of the target message format segment into a preset serial port encoding data.
  • the judgment module determines whether the serial port encoding data is less than or It is equal to the first preset value of the preset base. If the serial port coded data is less than or equal to the first preset value of the preset base, the first encoding module adds the serial port coded data to the second preset of the preset base. Set the value to obtain the coded transmission data so that the coded transmission data does not contain character data.
  • the second coding module splits the serial port coded data into the first split data And the second split data, the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively added to the second
  • the preset value obtains the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data and the second split-coded transmission data contain character data. Therefore, the embodiments of the present invention improve the reliability of device communication.
  • the embodiment of the present invention provides a non-volatile computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, for example, executing the above
  • the described method steps in Fig. 2 or Fig. 3 realize the functions of the modules and units in Fig. 4 or Fig. 5.
  • the embodiment of the present invention provides a computer program product, which includes a calculation program stored on a non-volatile computer-readable storage medium.
  • the computer program includes program instructions.
  • the program instructions When the program instructions are executed by a computer, the The computer executes the serial port data encoding method in any of the foregoing method embodiments, for example, executes the method steps in FIG. 2 or FIG. 3 described above to realize the functions of the modules and units in FIG. 4 or FIG. 5.
  • the device embodiments described above are merely illustrative.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • each implementation manner can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware.
  • a person of ordinary skill in the art can understand that all or part of the processes in the methods of the foregoing embodiments can be implemented by instructing relevant hardware through a computer program.
  • the program can be stored in a computer readable storage medium, and the program can be stored in a computer readable storage medium. When executed, it may include the procedures of the above-mentioned method embodiments.
  • the storage medium may be a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Probability & Statistics with Applications (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)

Abstract

A serial data encoding method and apparatus, and an embedded device and a communication system. The serial data encoding method comprises: acquiring serial data, the serial data comprising at least one message format section (S10); converting serial data of a target message format section into serial encoded data of a preset system (S20); determining whether the serial encoded data is less than or equal to a first preset numerical value of the preset system (S30); if so, summating the serial encoded data and a second preset numerical value of the preset system to obtain encoded transmission data such that the encoded transmission data does not include character type data (S40); and if not, splitting the serial encoded data into first split data and second split data that are less than or equal to the first preset numerical value, and summating the first split data and the second preset numerical value of the preset system and summating the second split data and the second preset numerical value of the preset system respectively to obtain first split encoded transmission data and second split encoded transmission data such that the first split encoded transmission data and the second split encoded transmission data do not include character type data (S50). The method improves the reliability of device communication.

Description

一种串口数据编码方法、装置、嵌入式设备及通信系统Serial data coding method, device, embedded equipment and communication system 技术领域Technical field
本发明涉及编码通信领域,特别是涉及一种串口数据编码方法、装置、嵌入式设备及通信系统。The present invention relates to the field of coding communication, in particular to a serial data coding method, device, embedded device and communication system.
背景技术Background technique
当源设备发送的串口数据为通信数据时,其内容包括Linux调试指令消息,该部分消息会被目的设备的底层截取,使到达目的设备的应用层的串口数据不完整,导致了设备通信异常。When the serial port data sent by the source device is communication data, its content includes Linux debugging command messages. This part of the message will be intercepted by the bottom layer of the destination device, making the serial port data reaching the application layer of the destination device incomplete, resulting in abnormal device communication.
发明内容Summary of the invention
本发明实施例旨在提供一种串口数据编码方法、装置、嵌入式设备及通信系统,其能够提升设备通信的可靠性。The embodiments of the present invention aim to provide a serial port data encoding method, device, embedded device, and communication system, which can improve the reliability of device communication.
为解决上述技术问题,本发明实施例提供以下技术方案:To solve the above technical problems, the embodiments of the present invention provide the following technical solutions:
第一方面,本发明实施例提供了一种串口数据编码方法,包括:In the first aspect, an embodiment of the present invention provides a serial port data encoding method, including:
获取串口数据,所述串口数据包括至少一个报文格式段;Acquiring serial port data, where the serial port data includes at least one message format segment;
将目标报文格式段的串口数据转换为预设进制的串口编码数据;Convert the serial port data of the target message format segment to the preset serial port code data;
判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值;Judging whether the serial port coded data is less than or equal to the first preset value of the preset base;
若是,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据;If yes, add the serial port coded data to the second preset value of the preset base to obtain coded transmission data, so that the coded transmission data does not include character data;
若否,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包 含字符型数据。If not, split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the first preset Values, respectively adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission data, Therefore, neither the first split-coded transmission data and the second split-coded transmission data include character data.
在一些实施例中,当所述预设进制为16进制时,所述将目标报文格式段的串口数据转换为预设进制的串口编码数据,包括:In some embodiments, when the preset base is hexadecimal, the converting the serial port data of the target message format segment into the serial encoded data of the preset base includes:
利用BCD码对目标报文格式段的所述串口数据进行编码;Use the BCD code to encode the serial port data in the target message format section;
将编码后的所述串口编码数据转换为16进制的串口编码数据。The encoded serial port coded data is converted into hexadecimal serial port coded data.
在一些实施例中,所述报文格式段包括帧头段、消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段;所述目标报文格式段包括消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。In some embodiments, the message format segment includes a frame header segment, a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment; the target message The format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
在一些实施例中,所述第一预设数值为0x9999,所述第二预设数值为0x30。In some embodiments, the first preset value is 0x9999, and the second preset value is 0x30.
在一些实施例中,所述将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据,包括:In some embodiments, adding the serial port coded data to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not include character data, includes:
将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据,以使所述编码传输数据不包含字符型数据。Each byte of the serial port coded data is respectively added with hexadecimal 0x30 to obtain coded transmission data, so that the coded transmission data does not include character data.
在一些实施例中,所述方法还包括:In some embodiments, the method further includes:
将所述编码传输数据通过串口发送。The encoded transmission data is sent through the serial port.
在一些实施例中,所述分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据,包括:In some embodiments, the first splitting data and the second splitting data are respectively added to the second preset value of the preset base to obtain the first splitting coded transmission data and the second splitting data. Split-encoded transmission data so that neither the first split-coded transmission data nor the second split-coded transmission data contains character-type data, including:
将所述第一拆分数据和所述第二拆分数据的每一字节分别加上16进制的0x30获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。Add hexadecimal 0x30 to each byte of the first split data and the second split data to obtain the first split coded transmission data and the second split coded transmission data, so that the Neither the first split-coded transmission data nor the second split-coded transmission data contains character data.
在一些实施例中,所述方法还包括:In some embodiments, the method further includes:
将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。The first split-coded transmission data and the second split-coded transmission data are sent through a serial port.
第二方面,本发明实施例提供了一种串口数据编码装置,包括:In the second aspect, an embodiment of the present invention provides a serial port data encoding device, including:
获取模块,用于获取串口数据,所述串口数据包括至少一个报文格式段;An acquisition module for acquiring serial port data, where the serial port data includes at least one message format segment;
转换模块,用于将目标报文格式段的串口数据转换为预设进制的串口编码数据;The conversion module is used to convert the serial port data of the target message format segment into the preset serial port code data;
判断模块,用于判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值;A judging module, configured to judge whether the serial port coded data is less than or equal to the first preset value of the preset base;
第一编码模块,用于若所述串口编码数据小于或等于所述预设进制的第一预设数值,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据;The first encoding module is configured to add the serial port encoding data to the second preset value of the preset base if the serial port encoding data is less than or equal to the first preset value of the preset base Obtain coded transmission data, so that the coded transmission data does not contain character data;
第二编码模块,用于若所述串口编码数据大于所述预设进制的第一预设数值,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。The second encoding module is configured to split the serial port encoding data into the first split data and the second split data if the serial port encoding data is greater than the first preset value of the preset base. The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added to the preset value respectively. To obtain the first split-coded transmission data and the second split-coded transmission data, so that the first split-coded transmission data and the second split-coded transmission data do not contain character type data.
在一些实施例中,所述装置还包括:In some embodiments, the device further includes:
第一发送模块,用于将所述编码传输数据通过串口发送。The first sending module is used to send the encoded transmission data through the serial port.
在一些实施例中,所述装置还包括:In some embodiments, the device further includes:
第二发送模块,将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。The second sending module sends the first split-coded transmission data and the second split-coded transmission data through the serial port.
第三方面,本发明实施例提供了一种嵌入式设备,包括:In the third aspect, an embodiment of the present invention provides an embedded device, including:
至少一个处理器;以及,At least one processor; and,
与所述至少一个处理器通信连接的存储器;其中,A memory communicatively connected with the at least one processor; wherein,
所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行如上所述的方法。The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the method as described above.
第四方面,本发明实施例提供了一种通信系统,包括:In a fourth aspect, an embodiment of the present invention provides a communication system, including:
至少两个如上所述的嵌入式设备;At least two embedded devices as described above;
上位机,与所述嵌入式设备通信连接。The upper computer communicates with the embedded device.
第五方面,本发明实施例还提供了一种非易失性计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机能够执行如上所述的方法。In a fifth aspect, embodiments of the present invention also provide a non-volatile computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above The method described.
本发明实施例的有益效果是:区别于现有技术的情况下,本发明实施例提供的一种串口数据编码方法、装置、嵌入式设备及通信系统,通过获取串口数据,将目标报文格式段的串口数据转换为预设进制的串口编码数据,判断串口编码数据是否小于或等于预设进制的第一预设数值,若是,则将串口编码数据加上预设进制的第二预设数值获得编码传输数据,以使编码传输数据不包含字符型数据,若否,则将串口编码数据拆分成第一拆分数据和第二拆分数据,第一拆分数据和第二拆分数据均小于或等于第一预设数值,分别将第一拆分数据和第二拆分数据加上预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使第一拆分编码传输数据和第二拆分编码传输数据均不包含字符型数据。因此,本发明实施例通过使编码传输数据、第一拆分编码传输数据以及第二拆分编码传输数据不包含字符型数据,从而使到达目的设备的应用层的串口数据完整,提升了设备通信的可靠性。The beneficial effects of the embodiments of the present invention are: different from the prior art, the serial data encoding method, device, embedded device, and communication system provided by the embodiments of the present invention can change the target message format by acquiring the serial port data. The serial port data of the segment is converted into the serial code data of the preset hexadecimal, and it is judged whether the serial code data is less than or equal to the first preset value of the preset hexadecimal. If so, the serial code data is added to the second of the preset hexadecimal The preset value is used to obtain the coded transmission data so that the coded transmission data does not contain character data. If not, the serial port coded data is split into the first split data and the second split data, the first split data and the second split data The split data is less than or equal to the first preset value, and the first split data and the second split data are respectively added to the second preset value of the preset base to obtain the first split coded transmission data and the second split data. Split-coded transmission data, so that neither the first split-coded transmission data nor the second split-coded transmission data contains character-type data. Therefore, in the embodiment of the present invention, the encoded transmission data, the first split-coded transmission data, and the second split-coded transmission data do not contain character data, so that the serial port data reaching the application layer of the target device is complete, and the device communication is improved. Reliability.
另外,通过判断串口编码数据是否小于或等于预设进制的第一预设数值,若是,则将串口编码数据加上预设进制的第二预设数值获得编码传输数据,若否,则将串口编码数据拆分成第一拆分数据和第二拆分数据,第一拆分数据和第二拆分数据均小于或等于第一预设数值,分别将第一拆分数据和第二拆分数据加上预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,从而限制了编码传输数据、第一拆分编码传输数据以及第二拆分编码传输数据的大小,避免产生数据溢出,使到达目的设备的应用层的串口数据正确,进一步提升了设备通信的可靠性。In addition, by judging whether the serial port coded data is less than or equal to the first preset value of the preset base, if it is, the serial port coded data is added to the second preset value of the preset base to obtain the encoded transmission data, if not, then Split the serial port encoding data into the first split data and the second split data. The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively The split data plus the second preset value of the preset hexadecimal number to obtain the first split-coded transmission data and the second split-coded transmission data, thereby limiting the encoded transmission data, the first split-coded transmission data, and the second split-coded transmission data. The size of the encoded transmission data is divided to avoid data overflow, so that the serial port data reaching the application layer of the destination device is correct, and the reliability of device communication is further improved.
附图说明Description of the drawings
一个或多个实施例通过与之对应的附图中的图片进行示例性说明,这些示例性说明并不构成对实施例的限定,附图中具有相同参考数字标号的元件表示为类似的元件,除非有特别申明,附图中的图不构成比例限制。One or more embodiments are exemplified by the pictures in the corresponding drawings. These exemplified descriptions do not constitute a limitation on the embodiments. The elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the attached drawings do not constitute a scale limitation.
图1是本发明实施例提供的一种通信系统的结构示意图;FIG. 1 is a schematic structural diagram of a communication system provided by an embodiment of the present invention;
图2是本发明实施例提供的一种串口数据编码方法的流程示意图;2 is a schematic flowchart of a serial data encoding method provided by an embodiment of the present invention;
图3是本发明另一实施例提供的一种串口数据编码方法的流程示意图;3 is a schematic flowchart of a method for encoding serial port data according to another embodiment of the present invention;
图4是本发明实施例提供的一种串口数据编码装置的装置示意图;4 is a schematic diagram of a serial data encoding device provided by an embodiment of the present invention;
图5是本发明又一实施例提供的一种串口数据编码装置的装置示意图。Fig. 5 is a device schematic diagram of a serial data encoding device provided by another embodiment of the present invention.
具体实施方式Detailed ways
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments These are a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
此外,下面所描述的本发明各个实施方式中所涉及到的技术特征只要彼此之间未构成冲突就可以相互组合。In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
本发明实施例提供一种嵌入式设备,所述嵌入式设备包括至少一个处理器以及与所述至少一个处理器通信连接的存储器,其中,所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行如下述方法实施例所述的串口数据编码方法。An embodiment of the present invention provides an embedded device that includes at least one processor and a memory communicatively connected to the at least one processor, wherein the memory stores the memory that can be executed by the at least one processor The instructions are executed by the at least one processor, so that the at least one processor can execute the serial data encoding method described in the following method embodiments.
可以理解,所述嵌入式设备是指包括嵌入式系统的装置或设备。嵌入式系统是一种嵌入受控器件内部,为特定应用而设计的专用计算机系统,为控制、监视或辅助设备、机器或用于工厂运作的设备。与个人计 算机等通用的计算机系统不同,嵌入式系统通常执行的是带有特定要求的预先定义的任务。It can be understood that the embedded device refers to a device or device including an embedded system. An embedded system is a special computer system that is embedded in a controlled device and designed for a specific application. It is used to control, monitor or assist equipment, machinery or equipment used in factory operations. Unlike general-purpose computer systems such as personal computers, embedded systems usually perform predefined tasks with specific requirements.
其中,嵌入式系统上运行有嵌入式操作系统。所述嵌入式操作系统是一种用途广泛的系统软件,通常包括与硬件相关的底层驱动软件、系统内核、设备驱动接口、通信协议、图形界面、标准化浏览器等。嵌入式操作系统负责嵌入式系统的全部软、硬件资源的分配、任务调度,控制、协调并发活动。它必须体现其所在系统的特征,能够通过装卸某些模块来达到嵌入式系统所要求的功能。目前在嵌入式领域广泛使用的操作系统有:嵌入式实时操作系统C/OS-II、嵌入式Linux、Windows Embedded、VxWorks等,以及应用在智能手机和平板电脑的Android、iOS等。Among them, an embedded operating system runs on the embedded system. The embedded operating system is a kind of system software with a wide range of uses, which usually includes hardware-related underlying driver software, system kernel, device driver interface, communication protocol, graphical interface, standardized browser, and the like. The embedded operating system is responsible for the allocation of all software and hardware resources of the embedded system, task scheduling, control and coordination of concurrent activities. It must reflect the characteristics of the system where it is located, and be able to achieve the functions required by the embedded system by loading and unloading certain modules. Currently widely used operating systems in the embedded field include: embedded real-time operating systems C/OS-II, embedded Linux, Windows Embedded, VxWorks, etc., as well as Android, iOS, etc., which are used in smart phones and tablet computers.
其中,所述处理器和所述存储器可以通过总线或者其他方式连接。Wherein, the processor and the memory may be connected by a bus or in other ways.
所述存储器作为一种非易失性计算机可读存储介质,可用于存储非易失性软件程序、非易失性计算机可执行程序以及模块,如本发明实施例中的串口数据编码方法对应的程序指令/模块(例如,附图4或附图5所示的各个模块)。所述处理器通过运行存储在存储器中的非易失性软件程序、指令以及模块,从而执行下述方法实施例所述的串口数据编码方法。As a non-volatile computer-readable storage medium, the memory can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as those corresponding to the serial data encoding method in the embodiment of the present invention Program instructions/modules (for example, the various modules shown in Fig. 4 or Fig. 5). The processor executes the serial data encoding method described in the following method embodiments by running non-volatile software programs, instructions, and modules stored in the memory.
存储器可以包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需要的应用程序;存储数据区可存储根据下述装置实施例所述的串口数据编码装置的使用所创建的数据等。此外,存储器可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件。在一些实施例中,存储器可选包括相对于处理器远程设置的存储器,这些远程存储器可以通过网络连接至串口数据编码装置。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory may include a storage program area and a storage data area, where the storage program area can store an operating system and an application program required by at least one function; the storage data area can store the use of the serial data encoding device according to the following device embodiments The created data, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory may optionally include a memory remotely arranged with respect to the processor, and these remote memories may be connected to the serial data encoding device via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
所述一个或者多个模块存储在所述存储器中,当被所述一个或者多个处理器执行时,执行下述任意方法实施例中的串口数据编码方法,例如,执行附图2或附图3所示的方法步骤,实现附图4或附图5中的各 模块和各单元的功能。The one or more modules are stored in the memory, and when executed by the one or more processors, the serial port data encoding method in any of the following method embodiments is executed, for example, the implementation of Figure 2 or Figure The method steps shown in 3 realize the functions of each module and each unit in FIG. 4 or FIG. 5.
上述产品可执行本发明实施例所提供的方法,具备执行方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本发明实施例所提供的方法。The above-mentioned products can execute the methods provided in the embodiments of the present invention, and have corresponding functional modules and beneficial effects for executing the methods. For technical details that are not described in detail in this embodiment, refer to the method provided in the embodiment of the present invention.
本发明实施例提供了一种嵌入式设备,通过执行下述方法实施例中的串口数据编码方法,提升了设备通信的可靠性。The embodiment of the present invention provides an embedded device, which improves the reliability of device communication by executing the serial data encoding method in the following method embodiment.
请参阅图1,为本发明实施例提供的一种通信系统的结构示意图。如图1所示,所述通信系统100包括至少两个如上面描述的嵌入式设备和上位机20,所述上位机20与所述嵌入式设备通信连接。Please refer to FIG. 1, which is a schematic structural diagram of a communication system according to an embodiment of the present invention. As shown in FIG. 1, the communication system 100 includes at least two embedded devices and a host computer 20 as described above, and the host computer 20 is in communication connection with the embedded device.
以两个嵌入式设备为例,所述至少两个所述嵌入式设备包括嵌入式设备A和嵌入式设备B。其中,所述嵌入式设备A、所述嵌入式设备B以及所述上位机20均包括至少一个串口,所述串口用于设备通信。Taking two embedded devices as an example, the at least two embedded devices include embedded device A and embedded device B. Wherein, the embedded device A, the embedded device B, and the host computer 20 all include at least one serial port, and the serial port is used for device communication.
进一步的,以所述嵌入式设备A为目的设备、所述嵌入式设备B为源设备,所述上位机20为调试设备为例,当所述嵌入式设备A与所述嵌入式设备B进行数据通信时,禁止所述上位机20的串口功能,所述嵌入式设备A的串口接收所述嵌入式设备B发送的串口数据;当所述上位机20对所述嵌入式设备A进行调试时,禁止所述嵌入式设备B的串口功能,所述嵌入式设备A的串口接收所述上位机20发送的调试指令消息。Further, taking the embedded device A as the destination device, the embedded device B as the source device, and the host computer 20 as the debugging device as an example, when the embedded device A and the embedded device B perform During data communication, the serial port function of the host computer 20 is prohibited, and the serial port of the embedded device A receives the serial port data sent by the embedded device B; when the host computer 20 debugs the embedded device A , Disable the serial port function of the embedded device B, and the serial port of the embedded device A receives the debugging instruction message sent by the host computer 20.
具体的,当所述嵌入式设备A运行嵌入式操作系统,表示所述嵌入式设备A开启数据通信功能,则触发禁止所述上位机20的串口功能;当所述嵌入式设备A接收到所述上位机20的调试请求,则触发禁止其余嵌入式设备(所述嵌入式设备B)的串口功能,使所述嵌入式设备A接收所述上位机20发送的调试指令消息。因此,通过在两个设备进行串口数据通信时,禁止其余设备的串口功能,避免了其余设备的干扰,提升了设备通信的可靠性。Specifically, when the embedded device A runs the embedded operating system, it means that the embedded device A starts the data communication function, and the serial port function of the host computer 20 is disabled; when the embedded device A receives all The debugging request of the host computer 20 triggers the prohibition of the serial port function of other embedded devices (the embedded device B), so that the embedded device A receives the debugging instruction message sent by the host computer 20. Therefore, by prohibiting the serial port functions of the other devices when the two devices are performing serial data communication, interference from the other devices is avoided, and the reliability of device communication is improved.
本发明实施例提供了一种通信系统,通过在嵌入式设备中运行下述方法实施例中的串口数据编码方法,提升了设备通信的可靠性。The embodiment of the present invention provides a communication system, which improves the reliability of device communication by running the serial port data encoding method in the following method embodiments in an embedded device.
请参阅图2,为本发明实施例提供的一种串口数据编码方法的流程 示意图。如图2所示,所述串口数据编码方法包括:Refer to Fig. 2, which is a schematic flowchart of a method for encoding serial port data according to an embodiment of the present invention. As shown in Figure 2, the serial data encoding method includes:
S10:获取串口数据,所述串口数据包括至少一个报文格式段。S10: Acquire serial port data, where the serial port data includes at least one message format segment.
如前所述,所述串口数据编码方法可应用于任意两个互相通信的嵌入式设备。在一些实施例中,在所述获取串口数据之前,所述方法还包括:接收通信请求;根据所述通信请求,返回应答消息,以建立源设备和目的设备的通信连接;接收成功应答消息,禁止接收其余设备的通信请求。因此,确保了在任意一个通信过程中,有且仅有两个通信设备对象,避免了其余设备的干扰。As mentioned above, the serial data encoding method can be applied to any two embedded devices that communicate with each other. In some embodiments, before the obtaining the serial port data, the method further includes: receiving a communication request; returning a response message according to the communication request to establish a communication connection between the source device and the destination device; receiving a success response message, It is forbidden to receive communication requests from other devices. Therefore, it is ensured that in any communication process, there are only two communication equipment objects, and the interference of other equipment is avoided.
其中,所述串口数据为嵌入式源设备的待发送数据,所述串口数据的报文格式段包括帧头段、消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。Wherein, the serial port data is the data to be sent from the embedded source device, and the message format segments of the serial port data include frame header segment, message instruction segment, source device segment, destination device segment, frame sequence number segment, content length segment, Content segment and check code segment.
请参阅表1,为本实施例提供的其中一种串口数据的报文格式。如表1所示,所述串口数据的帧头段包括1个字节,帧头为所述串口数据的起始字节,以0xFD开始;所述串口数据的消息指令段包括1个字节,消息指令表示这一帧串口数据具体是做什么;所述串口数据的源设备段包括1个字节,源设备表示所述串口数据的源设备的IP地址;所述串口数据的目的设备段包括1个字节,目的设备表示所述串口数据的目的设备的IP地址;所述串口数据的帧序号段包括1个字节,每发送一帧串口数据,帧序号加1,并且在0x00-0xFF之间循环;所述串口数据的内容长度段包括2个字节,内容长度表示这一帧串口数据实际长度;所述串口数据的内容段包括N个字节,其中N≥1,内容表示所述串口数据所携带的数据;所述串口数据的校验码段包括1个字节,校验码表示所述串口数据从消息指令开始到内容结束的所有字节的校验和。Please refer to Table 1, which is one of the message formats of serial port data provided in this embodiment. As shown in Table 1, the frame header segment of the serial port data includes 1 byte, and the frame header is the start byte of the serial port data, starting with 0xFD; the message command segment of the serial port data includes 1 byte , The message instruction indicates what this frame of serial port data specifically does; the source device section of the serial port data includes 1 byte, the source device indicates the IP address of the source device of the serial port data; the destination device section of the serial port data Including 1 byte, the destination device indicates the IP address of the destination device of the serial port data; the frame sequence number field of the serial port data includes 1 byte, each time a frame of serial port data is sent, the frame sequence number is increased by 1, and is in 0x00- Circulate between 0xFF; the content length section of the serial port data includes 2 bytes, and the content length indicates the actual length of this frame of serial port data; the content section of the serial port data includes N bytes, where N≥1, the content indicates The data carried by the serial port data; the check code segment of the serial port data includes 1 byte, and the check code represents the checksum of all bytes of the serial port data from the start of the message instruction to the end of the content.
Figure PCTCN2020132317-appb-000001
Figure PCTCN2020132317-appb-000001
表1Table 1
可以理解,从消息指令到校验码的字节不固定,不限于表1所公开的具体字节长度。所述串口数据的报文格式不限于本实施例所公开的具 体报文格式,可根据所述串口数据所基于的通信协议变化。It can be understood that the bytes from the message command to the check code are not fixed and are not limited to the specific byte length disclosed in Table 1. The message format of the serial port data is not limited to the specific message format disclosed in this embodiment, and can be changed according to the communication protocol on which the serial port data is based.
S20:将目标报文格式段的串口数据转换为预设进制的串口编码数据。S20: Convert the serial port data of the target message format segment into the serial port coded data of the preset hexadecimal system.
当所述预设进制为16进制时,所述将目标报文格式段的串口数据转换为预设进制的串口编码数据,包括:利用BCD码对目标报文格式段的所述串口数据进行编码;将编码后的所述串口编码数据转换为16进制的串口编码数据。所述目标报文格式段包括消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。When the preset base is hexadecimal, the converting the serial port data of the target message format segment into the serial code data of the preset base includes: using the BCD code to compare the serial port of the target message format segment The data is encoded; the encoded serial port coded data is converted into hexadecimal serial port coded data. The target message format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
由于从消息指令到校验码随机组合就可能出现调试消息指令,例如,’cd’、’mkdir’、’*#$&,/’等,故而,需要对消息指令到校验码中的字节进行编码,使通过串口发送的串口数据不包括调试消息指令包含的字符型数据,使正常通信的串口数据区别于上位机发送的调试指令消息,避免通过串口发送的串口数据中的部分数据被当作调试指令消息而被截取,导致通信数据不完整的问题。Since the random combination of the message command and the check code may appear the debug message command, for example,'cd','mkdir','*#$&,/', etc., it is necessary to change the message command to the word in the check code. Section encoding, so that the serial data sent through the serial port does not include the character data contained in the debugging message command, so that the normal communication serial data is different from the debugging command message sent by the host computer, and avoiding part of the data in the serial data sent through the serial port. It is intercepted as a debugging command message, causing the problem of incomplete communication data.
S30:判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值。S30: Determine whether the serial port coded data is less than or equal to the first preset value of the preset base.
S40:若是,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据。S40: If yes, add the serial port coded data to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not include character data.
其中,所述第一预设数值为0x9999,所述第二预设数值为0x30。Wherein, the first preset value is 0x9999, and the second preset value is 0x30.
所述将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据,包括:将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据,以使所述编码传输数据不包含字符型数据。The said adding the serial port coded data to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not contain character data, includes: adding each part of the serial port coded data One byte is respectively added with hexadecimal 0x30 to obtain the coded transmission data, so that the coded transmission data does not include character data.
可以理解,16进制的所述串口编码数据的内容中的0x00-0x2F,对应的ASCII码包括了空格、回车、换行、’*#$&,/’等符号,这些都是调试指令消息。若在原始协议的基础上直接增加0x30,可以避免出现这些符号,但数据内容若大于0xCF,加上0x30之后必大于0xFF,导致数据溢出而内容出错。故而,在所述将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据之前,需判断所述串口编码数据 是否小于或等于所述预设进制的第一预设数值,若所述串口编码数据小于或等于所述预设进制的第一预设数值,所述串口编码数据的每一字节分别加上16进制的0x30之后均不超过0xFF,则所述编码传输数据不会溢出出错,在目的设备解码所述编码传输数据,可以完整还原所述串口数据。It can be understood that 0x00-0x2F in the content of the serial port coded data in hexadecimal notation, the corresponding ASCII code includes symbols such as space, carriage return, line feed,'*#$&,/', these are debugging command messages . If you directly add 0x30 on the basis of the original protocol, you can avoid these symbols, but if the data content is greater than 0xCF, after adding 0x30, it must be greater than 0xFF, causing data overflow and content errors. Therefore, before adding each byte of the serial port coded data to 0x30 in hexadecimal to obtain the coded transmission data, it is necessary to determine whether the serial port coded data is less than or equal to the first value of the preset number. The preset value, if the serial port coded data is less than or equal to the first preset value of the preset base, each byte of the serial port coded data after adding 0x30 in hexadecimal, will not exceed 0xFF, Then the encoded transmission data will not overflow and error, and the serial port data can be completely restored by decoding the encoded transmission data at the destination device.
对于不超过9999的数据,其对应的所述串口编码数据小于0x9999,将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据,所述编码传输数据的范围变成了0x30~0xc9c9,避免了小于0x30的数据对应的ASCII码并且不产生数据溢出,编码后的所述编码传输数据如表2所示。For data that does not exceed 9999, the corresponding serial port coded data is less than 0x9999, add each byte of the serial port coded data to hexadecimal 0x30 to obtain the coded transmission data, and the range of the coded transmission data changes It becomes 0x30~0xc9c9, which avoids the ASCII code corresponding to data smaller than 0x30 and does not cause data overflow. The encoded transmission data after encoding is shown in Table 2.
Figure PCTCN2020132317-appb-000002
Figure PCTCN2020132317-appb-000002
表2Table 2
请一并参阅图3,在一些实施例中,所述将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据之后,所述方法还包括:Please also refer to FIG. 3. In some embodiments, the encoded data is added to the second preset value of the preset base to obtain encoded transmission data, so that the encoded transmission data does not contain characters After the type data, the method further includes:
S60:将所述编码传输数据通过串口发送。S60: Send the encoded transmission data through the serial port.
S50:若否,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。S50: If not, split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the first split data. Preset values, respectively adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission Data, so that neither the first split-coded transmission data and the second split-coded transmission data contain character-type data.
所述分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均 不包含字符型数据,包括:将所述第一拆分数据和所述第二拆分数据的每一字节分别加上16进制的0x30获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。Adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission data, So that neither the first split-coded transmission data and the second split-coded transmission data include character data, including: dividing each word of the first split data and the second split data Sections are added with hexadecimal 0x30 to obtain the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data nor the second split-coded transmission data contains Character data.
在一些实施例中,所述分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据之后,所述方法还包括:In some embodiments, the first splitting data and the second splitting data are respectively added to the second preset value of the preset base to obtain the first splitting coded transmission data and the second splitting data. After splitting the encoded transmission data so that neither the first splitting encoded transmission data nor the second splitting encoded transmission data contains character data, the method further includes:
S70:将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。S70: Send the first split-coded transmission data and the second split-coded transmission data through the serial port.
可以理解,在目的设备对所述第一拆分编码传输数据和所述第二拆分编码传输数据进行解码之后,合并解码之后的所述第一拆分编码传输数据和所述第二拆分编码传输数据,可以完整还原所述串口数据。It can be understood that after the destination device decodes the first split-coded transmission data and the second split-coded transmission data, the decoded first split-coded transmission data and the second split are combined. By encoding the transmission data, the serial port data can be completely restored.
本发明实施例提供了一种串口数据编码方法,通过获取串口数据,将目标报文格式段的串口数据转换为预设进制的串口编码数据,判断串口编码数据是否小于或等于预设进制的第一预设数值,若是,则将串口编码数据加上预设进制的第二预设数值获得编码传输数据,以使编码传输数据不包含字符型数据,若否,则将串口编码数据拆分成第一拆分数据和第二拆分数据,第一拆分数据和第二拆分数据均小于或等于第一预设数值,分别将第一拆分数据和第二拆分数据加上预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使第一拆分编码传输数据和第二拆分编码传输数据均不包含字符型数据,因此,本发明实施例通过使编码传输数据、第一拆分编码传输数据以及第二拆分编码传输数据不包含字符型数据,从而使到达目的设备的应用层的串口数据完整,提升了设备通信的可靠性。The embodiment of the present invention provides a method for encoding serial port data. By acquiring serial port data, the serial port data of the target message format segment is converted into serial port encoding data of a preset base, and it is judged whether the serial port encoding data is less than or equal to the preset base. If yes, add the serial code data to the second preset value of the preset hexadecimal to obtain the coded transmission data, so that the coded transmission data does not contain character data, if not, the serial coded data Split into the first split data and the second split data, the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added respectively The second preset value of the above preset base is obtained to obtain the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data and the second split-coded transmission data contain character types Therefore, the embodiment of the present invention makes the coded transmission data, the first split-coded transmission data, and the second split-coded transmission data not contain character data, so that the serial port data reaching the application layer of the destination device is complete and improves Reliability of equipment communication.
另外,通过判断串口编码数据是否小于或等于预设进制的第一预设数值,若是,则将串口编码数据加上预设进制的第二预设数值获得编码传输数据,若否,则将串口编码数据拆分成第一拆分数据和第二拆分数据,第一拆分数据和第二拆分数据均小于或等于第一预设数值,分别将 第一拆分数据和第二拆分数据加上预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,从而限制了编码传输数据、第一拆分编码传输数据以及第二拆分编码传输数据的大小,避免产生数据溢出,使到达目的设备的应用层的串口数据正确,进一步提升了设备通信的可靠性。In addition, by judging whether the serial port coded data is less than or equal to the first preset value of the preset base, if it is, the serial port coded data is added to the second preset value of the preset base to obtain the encoded transmission data, if not, then Split the serial port encoding data into the first split data and the second split data. The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively divided into the first split data and the second split data. The split data plus the second preset value of the preset hexadecimal number to obtain the first split-coded transmission data and the second split-coded transmission data, thereby limiting the encoded transmission data, the first split-coded transmission data, and the second split-coded transmission data. The size of the encoded transmission data is divided to avoid data overflow, so that the serial port data reaching the application layer of the destination device is correct, and the reliability of device communication is further improved.
请参阅图4,为本发明实施例提供的一种串口数据编码装置的装置示意图。如图4所示,所述串口数据编码装置400包括获取模块401、转换模块402、判断模块403、第一编码模块404以及第二编码模块405。Please refer to FIG. 4, which is a schematic diagram of a serial port data encoding device provided by an embodiment of the present invention. As shown in FIG. 4, the serial data encoding device 400 includes an acquisition module 401, a conversion module 402, a judgment module 403, a first encoding module 404, and a second encoding module 405.
所述获取模块401用于获取串口数据,所述串口数据包括至少一个报文格式段。The acquiring module 401 is configured to acquire serial port data, and the serial port data includes at least one message format segment.
其中,所述报文格式段包括帧头段、消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。Wherein, the message format segment includes a frame header segment, a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
所述转换模块402用于将目标报文格式段的串口数据转换为预设进制的串口编码数据。The conversion module 402 is used to convert the serial port data of the target message format segment into serial port coded data with a preset hexadecimal system.
其中,所述目标报文格式段包括消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。Wherein, the target message format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a check code segment.
请一并参阅图5,当所述预设进制为16进制时,所述转换模块402包括第一编码单元4021和转换单元4022。Please also refer to FIG. 5, when the preset base is hexadecimal, the conversion module 402 includes a first encoding unit 4021 and a conversion unit 4022.
第一编码单元4021用于利用BCD码对目标报文格式段的所述串口数据进行编码。所述转换单元4022用于将编码后的所述串口编码数据转换为16进制的串口编码数据。The first encoding unit 4021 is configured to use the BCD code to encode the serial port data in the target message format segment. The conversion unit 4022 is configured to convert the encoded serial port code data into hexadecimal serial port code data.
所述判断模块403用于判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值。The judging module 403 is used to judge whether the serial port coded data is less than or equal to the first preset value of the preset base.
所述第一编码模块404用于若所述串口编码数据小于或等于所述预设进制的第一预设数值,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据。The first encoding module 404 is configured to add the serial code data to the second preset value of the preset base if the serial port encoding data is less than or equal to the first preset value of the preset base. Set the value to obtain the coded transmission data so that the coded transmission data does not contain character data.
其中,所述第一预设数值为0x9999,所述第二预设数值为0x30。Wherein, the first preset value is 0x9999, and the second preset value is 0x30.
所述第一编码模块404包括第二编码单元4041,所述第二编码单元 4041用于将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据,以使所述编码传输数据不包含字符型数据。The first encoding module 404 includes a second encoding unit 4041. The second encoding unit 4041 is used to add hexadecimal 0x30 to each byte of the serial port encoding data to obtain encoded transmission data, so that all The encoded transmission data does not contain character data.
所述第二编码模块405用于若所述串口编码数据大于所述预设进制的第一预设数值,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。The second encoding module 405 is configured to split the serial port encoding data into first split data and second split data if the serial port encoding data is greater than the first preset value of the preset base. , The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added to the preset value, respectively. Set the second preset value of the base to obtain the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data nor the second split-coded transmission data contains Character data.
所述第二编码模块405包括拆分单元4051和第三编码单元4052。The second encoding module 405 includes a splitting unit 4051 and a third encoding unit 4052.
所述拆分单元4051用于将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值。The splitting unit 4051 is configured to split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the The first preset value.
所述第三编码单元4052用于将所述第一拆分数据和所述第二拆分数据的每一字节分别加上16进制的0x30获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据中均不包含字符型数据。The third encoding unit 4052 is configured to add hexadecimal 0x30 to each byte of the first split data and the second split data to obtain the first split encoded transmission data and the second split data. The transmission data is divided-encoded, so that neither the first divided-coded transmission data nor the second divided-coded transmission data contains character data.
请再次参阅图5,所述串口数据编码装置500包括上述实施例所述的串口数据编码装置400,相同之处请参阅上述各个实施例,在此不一一赘述。区别在于,所述串口数据编码装置500还包括第一发送模块501和第二发送模块502。Please refer to FIG. 5 again. The serial data encoding device 500 includes the serial data encoding device 400 described in the foregoing embodiment. For similarities, please refer to the foregoing embodiments, which will not be repeated here. The difference is that the serial data encoding device 500 further includes a first sending module 501 and a second sending module 502.
所述第一发送模块501用于将所述编码传输数据通过串口发送。The first sending module 501 is configured to send the encoded transmission data through a serial port.
所述第二发送模块502将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。The second sending module 502 sends the first split-coded transmission data and the second split-coded transmission data through a serial port.
值得说明的是,上述装置内的模块之间的信息交互、执行过程等内容,由于与本发明的方法实施例基于同一构思,具体内容可参见本发明方法实施例中的叙述,此处不再赘述。It is worth noting that the information interaction and execution process between the modules in the above-mentioned device are based on the same concept as the method embodiment of the present invention. For specific content, please refer to the description in the method embodiment of the present invention, and will not be omitted here. Go into details.
本发明实施例提供一种串口数据编码装置,通过获取模块获取串口数据,转换模块将目标报文格式段的串口数据转换为预设进制的串口编 码数据,判断模块判断串口编码数据是否小于或等于预设进制的第一预设数值,若串口编码数据小于或等于预设进制的第一预设数值,第一编码模块将所述串口编码数据加上预设进制的第二预设数值获得编码传输数据,以使编码传输数据不包含字符型数据,若串口编码数据大于预设进制的第一预设数值,第二编码模块将串口编码数据拆分成第一拆分数据和第二拆分数据,第一拆分数据和第二拆分数据均小于或等于第一预设数值,分别将第一拆分数据和第二拆分数据加上预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使第一拆分编码传输数据和第二拆分编码传输数据均不包含字符型数据。因此,本发明实施例提升了设备通信的可靠性。The embodiment of the present invention provides a serial port data encoding device. The serial port data is obtained through an acquisition module. The conversion module converts the serial port data of the target message format segment into a preset serial port encoding data. The judgment module determines whether the serial port encoding data is less than or It is equal to the first preset value of the preset base. If the serial port coded data is less than or equal to the first preset value of the preset base, the first encoding module adds the serial port coded data to the second preset of the preset base. Set the value to obtain the coded transmission data so that the coded transmission data does not contain character data. If the serial port coded data is greater than the first preset value of the preset base, the second coding module splits the serial port coded data into the first split data And the second split data, the first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are respectively added to the second The preset value obtains the first split-coded transmission data and the second split-coded transmission data, so that neither the first split-coded transmission data and the second split-coded transmission data contain character data. Therefore, the embodiments of the present invention improve the reliability of device communication.
本发明实施例提供了一种非易失性计算机可读存储介质,所述计算机可读存储介质存储有计算机可执行指令,该计算机可执行指令被一个或多个处理器执行,例如,执行以上描述的附图2或附图3的方法步骤,实现附图4或附图5中的各模块和各单元的功能。The embodiment of the present invention provides a non-volatile computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, for example, executing the above The described method steps in Fig. 2 or Fig. 3 realize the functions of the modules and units in Fig. 4 or Fig. 5.
本发明实施例提供了一种计算机程序产品,包括存储在非易失性计算机可读存储介质上的计算程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,使所述计算机执行上述任意方法实施例中的串口数据编码方法,例如,执行以上描述的附图2或附图3的方法步骤,实现附图4或附图5中的各模块和各单元的功能。The embodiment of the present invention provides a computer program product, which includes a calculation program stored on a non-volatile computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the The computer executes the serial port data encoding method in any of the foregoing method embodiments, for example, executes the method steps in FIG. 2 or FIG. 3 described above to realize the functions of the modules and units in FIG. 4 or FIG. 5.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
通过以上的实施方式的描述,本领域普通技术人员可以清楚地了解到各实施方式可借助软件加通用硬件平台的方式来实现,当然也可以通过硬件。本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述 各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)或随机存储记忆体(Random Access Memory,RAM)等。Through the description of the above implementation manners, those of ordinary skill in the art can clearly understand that each implementation manner can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. A person of ordinary skill in the art can understand that all or part of the processes in the methods of the foregoing embodiments can be implemented by instructing relevant hardware through a computer program. The program can be stored in a computer readable storage medium, and the program can be stored in a computer readable storage medium. When executed, it may include the procedures of the above-mentioned method embodiments. Wherein, the storage medium may be a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;在本发明的思路下,以上实施例或者不同实施例中的技术特征之间也可以进行组合,步骤可以以任意顺序实现,并存在如上所述的本发明的不同方面的许多其它变化,为了简明,它们没有在细节中提供;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, not to limit them; under the idea of the present invention, the technical features of the above embodiments or different embodiments can also be combined. The steps can be implemented in any order, and there are many other variations of the different aspects of the present invention as described above. For the sake of brevity, they are not provided in the details; although the present invention has been described in detail with reference to the foregoing embodiments, it is common in the art The skilled person should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or equivalently replace some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the implementations of the present invention. Examples of the scope of technical solutions.

Claims (14)

  1. 一种串口数据编码方法,其特征在于,包括:A serial data encoding method, characterized in that it comprises:
    获取串口数据,所述串口数据包括至少一个报文格式段;Acquiring serial port data, where the serial port data includes at least one message format segment;
    将目标报文格式段的串口数据转换为预设进制的串口编码数据;Convert the serial port data of the target message format segment to the preset serial port code data;
    判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值;Judging whether the serial port coded data is less than or equal to the first preset value of the preset base;
    若是,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据;If yes, add the serial port coded data to the second preset value of the preset base to obtain coded transmission data, so that the coded transmission data does not include character data;
    若否,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。If not, split the serial port coded data into first split data and second split data, and both the first split data and the second split data are less than or equal to the first preset Values, respectively adding the first split data and the second split data to the second preset value of the preset number to obtain the first split coded transmission data and the second split coded transmission data, Therefore, neither the first split-coded transmission data and the second split-coded transmission data include character data.
  2. 根据权利要求1所述的方法,其特征在于,当所述预设进制为16进制时,所述将目标报文格式段的串口数据转换为预设进制的串口编码数据,包括:The method according to claim 1, wherein when the preset base is hexadecimal, the converting serial port data of the target message format segment into serial code data of the preset base includes:
    利用BCD码对目标报文格式段的所述串口数据进行编码;Use the BCD code to encode the serial port data in the target message format section;
    将编码后的所述串口编码数据转换为16进制的串口编码数据。The encoded serial port coded data is converted into hexadecimal serial port coded data.
  3. 根据权利要求1或2所述的方法,其特征在于,所述报文格式段包括帧头段、消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段;所述目标报文格式段包括消息指令段、源设备段、目的设备段、帧序号段、内容长度段、内容段以及校验码段。The method according to claim 1 or 2, wherein the message format segment includes a frame header segment, a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a collation. Code verification segment; the target message format segment includes a message instruction segment, a source device segment, a destination device segment, a frame sequence number segment, a content length segment, a content segment, and a verification code segment.
  4. 根据权利要求2所述的方法,其特征在于,所述第一预设数值为0x9999,所述第二预设数值为0x30。The method according to claim 2, wherein the first preset value is 0x9999, and the second preset value is 0x30.
  5. 根据权利要求4所述的方法,其特征在于,所述将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据,包括:The method according to claim 4, wherein the serial coded data is added to the second preset value of the preset base to obtain the coded transmission data, so that the coded transmission data does not contain characters Type data, including:
    将所述串口编码数据的每一字节分别加上16进制的0x30获得编码传输数据,以使所述编码传输数据不包含字符型数据。Each byte of the serial port coded data is respectively added with hexadecimal 0x30 to obtain coded transmission data, so that the coded transmission data does not include character data.
  6. 根据权利要求5所述的方法,其特征在于,所述方法还包括:The method according to claim 5, wherein the method further comprises:
    将所述编码传输数据通过串口发送。The encoded transmission data is sent through the serial port.
  7. 根据权利要求4所述的方法,其特征在于,所述分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据,包括:The method according to claim 4, wherein the first split data and the second split data are respectively added to the second preset value of the preset number to obtain the first split data. Split-coded transmission data and second split-coded transmission data so that neither the first split-coded transmission data nor the second split-coded transmission data contains character-type data, including:
    将所述第一拆分数据和所述第二拆分数据的每一字节分别加上16进制的0x30获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。Add hexadecimal 0x30 to each byte of the first split data and the second split data to obtain the first split coded transmission data and the second split coded transmission data, so that the Neither the first split-coded transmission data nor the second split-coded transmission data contains character data.
  8. 根据权利要求7所述的方法,其特征在于,所述方法还包括:The method according to claim 7, wherein the method further comprises:
    将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。The first split-coded transmission data and the second split-coded transmission data are sent through a serial port.
  9. 一种串口数据编码装置,其特征在于,包括:A serial data encoding device, which is characterized in that it comprises:
    获取模块,用于获取串口数据,所述串口数据包括至少一个报文格式段;An acquisition module for acquiring serial port data, where the serial port data includes at least one message format segment;
    转换模块,用于将目标报文格式段的串口数据转换为预设进制的串口编码数据;The conversion module is used to convert the serial port data of the target message format segment into the preset serial port code data;
    判断模块,用于判断所述串口编码数据是否小于或等于所述预设进制的第一预设数值;A judging module, configured to judge whether the serial port coded data is less than or equal to the first preset value of the preset base;
    第一编码模块,用于若所述串口编码数据小于或等于所述预设进制的第一预设数值,则将所述串口编码数据加上所述预设进制的第二预设数值获得编码传输数据,以使所述编码传输数据不包含字符型数据;The first encoding module is configured to add the serial port encoding data to the second preset value of the preset base if the serial port encoding data is less than or equal to the first preset value of the preset base Obtain coded transmission data, so that the coded transmission data does not contain character data;
    第二编码模块,用于若所述串口编码数据大于所述预设进制的第一预设数值,则将所述串口编码数据拆分成第一拆分数据和第二拆分数据,所述第一拆分数据和所述第二拆分数据均小于或等于所述第一预设 数值,分别将所述第一拆分数据和所述第二拆分数据加上所述预设进制的第二预设数值获得第一拆分编码传输数据和第二拆分编码传输数据,以使所述第一拆分编码传输数据和所述第二拆分编码传输数据均不包含字符型数据。The second encoding module is configured to split the serial port encoding data into the first split data and the second split data if the serial port encoding data is greater than the first preset value of the preset base. The first split data and the second split data are both less than or equal to the first preset value, and the first split data and the second split data are added to the preset value respectively. To obtain the first split-coded transmission data and the second split-coded transmission data, so that the first split-coded transmission data and the second split-coded transmission data do not contain character type data.
  10. 根据权利要求9所述的装置,其特征在于,所述装置还包括:The device according to claim 9, wherein the device further comprises:
    第一发送模块,用于将所述编码传输数据通过串口发送。The first sending module is used to send the encoded transmission data through the serial port.
  11. 根据权利要求9所述的装置,其特征在于,所述装置还包括:The device according to claim 9, wherein the device further comprises:
    第二发送模块,将所述第一拆分编码传输数据和所述第二拆分编码传输数据通过串口发送。The second sending module sends the first split-coded transmission data and the second split-coded transmission data through the serial port.
  12. 一种嵌入式设备,其特征在于,包括:An embedded device, characterized in that it comprises:
    至少一个处理器;以及,At least one processor; and,
    与所述至少一个处理器通信连接的存储器;其中,A memory communicatively connected with the at least one processor; wherein,
    所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行如权利要求1-8任一项所述的方法。The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute any one of claims 1-8 Methods.
  13. 一种通信系统,其特征在于,包括:A communication system, characterized in that it comprises:
    至少两个如权利要求12所述的嵌入式设备;At least two embedded devices according to claim 12;
    上位机,与所述嵌入式设备通信连接。The upper computer communicates with the embedded device.
  14. 一种非易失性计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机能够执行如权利要求1-8任一项所述的方法。A non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute any one of claims 1-8. The method described in the item.
PCT/CN2020/132317 2019-12-13 2020-11-27 Serial data encoding method and apparatus, and embedded device and communication system WO2021115142A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911285150.0A CN110958024B (en) 2019-12-13 2019-12-13 Method and device for encoding serial data, embedded equipment and communication system
CN201911285150.0 2019-12-13

Publications (1)

Publication Number Publication Date
WO2021115142A1 true WO2021115142A1 (en) 2021-06-17

Family

ID=69981667

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/132317 WO2021115142A1 (en) 2019-12-13 2020-11-27 Serial data encoding method and apparatus, and embedded device and communication system

Country Status (2)

Country Link
CN (1) CN110958024B (en)
WO (1) WO2021115142A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110958024B (en) * 2019-12-13 2024-01-19 深圳市道通智能航空技术股份有限公司 Method and device for encoding serial data, embedded equipment and communication system
CN112861475A (en) * 2020-11-03 2021-05-28 深圳市和讯华谷信息技术有限公司 Encoding and decoding processing method, device, equipment and storage medium
CN113099271A (en) * 2021-04-08 2021-07-09 天津天地伟业智能安全防范科技有限公司 Video auxiliary information encoding and decoding methods and electronic equipment
CN113162803B (en) * 2021-04-15 2022-12-23 浪潮思科网络科技有限公司 Serial port control method, device and medium based on dichotomy
CN114189554B (en) * 2021-11-17 2023-09-15 中国兵器工业计算机应用技术研究所 Information interaction method, device and readable storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101135987A (en) * 2007-06-20 2008-03-05 中兴通讯股份有限公司 Method for acquiring serial interface incoming data
CN105005059A (en) * 2015-06-26 2015-10-28 泰斗微电子科技有限公司 Transmission method for original observed quantity data in ANDROID terminal, and corresponding terminal
CN105591716A (en) * 2014-12-26 2016-05-18 青岛海信日立空调系统有限公司 Serial data communication method, devices and systems based on single carrier
CN105701053A (en) * 2014-11-24 2016-06-22 中兴通讯股份有限公司 Method and device for transmitting and receiving serial data
CN109376108A (en) * 2018-10-18 2019-02-22 郑州云海信息技术有限公司 Data transmission method, equipment, transmitting terminal and receiving end based on serial communication
WO2019147413A1 (en) * 2018-01-29 2019-08-01 Microsoft Technology Licensing, Llc Face synthesis
CN110958024A (en) * 2019-12-13 2020-04-03 深圳市道通智能航空技术有限公司 Serial port data encoding method and device, embedded device and communication system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105450232A (en) * 2014-08-28 2016-03-30 华为技术有限公司 Encoding method, decoding method, encoding device and decoding device
CN105634674A (en) * 2016-01-12 2016-06-01 青岛海信移动通信技术股份有限公司 Short message processing method and device
CN109739821A (en) * 2018-12-18 2019-05-10 中国科学院计算机网络信息中心 Daily record data bedding storage method, apparatus and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101135987A (en) * 2007-06-20 2008-03-05 中兴通讯股份有限公司 Method for acquiring serial interface incoming data
CN105701053A (en) * 2014-11-24 2016-06-22 中兴通讯股份有限公司 Method and device for transmitting and receiving serial data
CN105591716A (en) * 2014-12-26 2016-05-18 青岛海信日立空调系统有限公司 Serial data communication method, devices and systems based on single carrier
CN105005059A (en) * 2015-06-26 2015-10-28 泰斗微电子科技有限公司 Transmission method for original observed quantity data in ANDROID terminal, and corresponding terminal
WO2019147413A1 (en) * 2018-01-29 2019-08-01 Microsoft Technology Licensing, Llc Face synthesis
CN109376108A (en) * 2018-10-18 2019-02-22 郑州云海信息技术有限公司 Data transmission method, equipment, transmitting terminal and receiving end based on serial communication
CN110958024A (en) * 2019-12-13 2020-04-03 深圳市道通智能航空技术有限公司 Serial port data encoding method and device, embedded device and communication system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
ANONYMOUS: "Solution for Transferring English Alphabet in Serial Communication", 3 April 2013 (2013-04-03), pages 1 - 3, XP009528690, Retrieved from the Internet <URL:http://www.myexceptions.net/hardware/194958.html> *

Also Published As

Publication number Publication date
CN110958024A (en) 2020-04-03
CN110958024B (en) 2024-01-19

Similar Documents

Publication Publication Date Title
WO2021115142A1 (en) Serial data encoding method and apparatus, and embedded device and communication system
US9639485B2 (en) Method and apparatus for transmitting data in android platform based terminal device
CN107926075B (en) System and method for supporting data communication in heterogeneous environment
WO2018157588A1 (en) Firmware burning method, system, computer device and storage medium
US20170351723A1 (en) Managing data format of data received from devices in an internet of things network
CN109033328B (en) Access request processing method, device, equipment and readable storage medium
CN113990354B (en) Audio control method, device, equipment and storage medium based on Linux
US20150128155A1 (en) Method, system, module, and storage medium for automatic adaptation of hardware encoding and decoding
CN107404418B (en) Internet product testing method, device, equipment and storage medium
CN104268229A (en) Resource obtaining method and device based on multi-process browser
WO2019153492A1 (en) Method for realizing web and native function interaction, and electronic apparatus and readable storage medium
US20160321092A1 (en) Computer system and method for accessing virtual machine
CN112667442A (en) Control method, device and equipment based on nonvolatile memory device starting system
US20160266912A1 (en) External devices, electronic devices, methods for starting external devices, and methods for data processing
US10740218B2 (en) Method and device for determining usage log
CN108965295B (en) File compression and combination method and related device
US10698695B2 (en) Method for intel platform detection of parameters in Flash Rom
CN116095064A (en) File downloading method, computer equipment and storage medium
CN108021459B (en) Method and device for sending dotting logs across processes
CN115794690A (en) Processing method and device based on external equipment in server
WO2018133828A1 (en) Data processing method and device utilized in client terminal
CN111158783B (en) Environment variable modification method, device and equipment and readable storage medium
CN104407846B (en) Information processing method and device
CN113961162A (en) Screen projection control method, screen projection sending end, screen projection receiving end and screen projection system
CN112861475A (en) Encoding and decoding processing method, device, equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20897691

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20897691

Country of ref document: EP

Kind code of ref document: A1