A framing transmission method based on byte stream communication

By adopting a frame transfer method based on byte stream communication in byte stream communication, the highest bit of data per 7 bytes represents the frame transfer status, the problem of fast frame transfer in embedded applications is solved, and efficient and stable frame transfer is achieved.

CN119402573BActive Publication Date: 2025-04-18CHENGDU LIANGXIN INTEGRATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510000562.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2025-04-18
Estimated Expiration
2045-01-02

AI Technical Summary

Technical Problem

In byte flow communication, especially in embedded applications, it is impossible to quickly divide frames in fast and free communication situations, resulting in low transmission efficiency and high time complexity.

Method used

A frame transfer method based on byte stream communication is adopted. By means of the transmission buffer, encoding resource allocator, frame stream encoder, byte stream transmitter, byte stream receiver and frame stream decoder, the byte stream data is encoded and decoded, and the highest bit of every 7 byte data represents the frame transfer status, thereby realizing efficient frame transfer.

Benefits of technology

The transmission efficiency is improved to 87.5%, which is much higher than 50% of the ASCII plaintext transmission efficiency, and maintain stable and reliable frame partitioning under high frame rate transmission, reducing the dependence on the processor's additional hardware resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119402573B_ABST
    Figure CN119402573B_ABST
Patent Text Reader

Abstract

The present invention discloses a framing transmission method based on byte stream communication, comprising: a sending buffer transferring data attributes of byte stream data to a coding resource allocator; the coding resource allocator calculating the storage space required after coding based on the data attributes of the byte stream data; a frame stream encoder encoding the byte stream data based on the calculated storage space required after coding to obtain coded data, and then transmitting the coded data to a target end device through a byte stream transmitter; a byte stream receiver receiving the coded data of the target end device, a decoding resource allocator calculating the storage space required after decoding based on the data attributes of the coded data; a frame stream decoder decoding the coded data based on the calculated storage space required after decoding to obtain restored data, and storing the restored data in a receiving buffer. The present invention realizes fast framing transmission through a 1-byte 7-bit transmission mechanism, so that data can maintain stable and reliable framing under high frame rate transmission, thereby improving transmission efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of byte stream communication, and in particular to a frame transmission method based on byte stream communication. Background Art

[0002] At present, in embedded applications, serial communication is widely used, and communication protocols emerge in an endless stream, such as MODBUS, XMODE, and YMODE. These protocols have their own application directions and their own shortcomings, and most of these protocols use time slot framing or protocol framing, ASCII transmission, but it is difficult to accurately frame when facing fast transmission, and low transmission efficiency will also increase time complexity; and the use of idle interrupt framing (a type of time slot framing) in embedded chips makes the software more dependent on the hardware platform. In addition, when facing host computer communication, in addition to ASCII transmission, the host computer does not have a more stable and reliable framing method. Since the time accuracy of the host computer timer interrupt cannot reach the microsecond level, it cannot support high frame rate transmission when using time framing, and only relying on ASCII transmission can only transmit at a transmission efficiency of about 50%. Summary of the invention

[0003] The purpose of the present invention is to provide a frame transmission method based on byte stream communication, which mainly solves the problem that fast frame division cannot be performed in fast and free communication situations in byte stream communication, especially in embedded applications, which usually require the use of timeout mechanisms or communication protocols to solve the problem of packet division.

[0004] To achieve the above purpose, the technical solution adopted by the present invention is as follows:

[0005] A frame transmission method based on byte stream communication comprises the following steps:

[0006] S1, the sending buffer passes the data attributes of the byte stream data to the coding resource allocator;

[0007] S2, the coding resource allocator calculates the storage space required after coding based on the data attributes of the byte stream data;

[0008] S3, the frame stream encoder encodes the byte stream data based on the calculated storage space required after encoding to obtain encoded data, and then transmits the encoded data to the target end device through the byte stream transmitter;

[0009] S4, the byte stream receiver receives the encoded data of the target end device, and the decoding resource allocator calculates the storage space required after decoding based on the data attributes of the encoded data;

[0010] S5. The frame stream decoder decodes the encoded data based on the calculated storage space required after decoding to obtain restored data, and stores the restored data in a receiving buffer.

[0011] Further, in the encoding operation of S3: the highest-bit data in every 7 original byte data in a frame of byte stream data is encoded into 1 new byte data. Specifically: the highest-bit data in each original byte data is encoded to obtain an encoding result, then the highest-bit data of the current original byte data is cleared to obtain byte data A; 7 encoding results of every 7 original byte data are stored in an 8-bit space to generate 1 new byte data; all byte data A are combined into a frame of byte stream data A, and then all new byte data are sequentially combined after a frame of byte stream data A in the generation order to obtain encoded data.

[0012] Further, in the 8-bit space, from left to right are low-order space 1, low-order space 2, low-order space 3, low-order space 4, low-order space 5, low-order space 6, and highest-order space in sequence; each of the 7 low-order spaces is used to store 1 encoding result, and the highest-order space is used to store a frame segmentation flag, and the frame segmentation flag is used to mark whether a frame of byte stream data has ended encoding.

[0013] Further, the frame segmentation flag is 0 or 1. When the frame segmentation flag is 0, it means that a frame of byte stream data has not ended encoding. When the frame segmentation flag is 1, it means that a frame of byte stream data has ended encoding.

[0014] Further, in the 8-bit space, the storage order of the encoding results is from low-order space 6 to low-order space 1 in sequence.

[0015] Further, the storage space required after encoding is obtained through a first piecewise function, specifically as follows:

[0016] If n≥7 and n is divisible by 7, ;

[0017] If 0 < n < 7, m = 1;

[0018] If n > 7 and n is not divisible by 7, ;

[0019] S = n + m;

[0020] n represents the data volume of the original byte data in a frame of byte stream data, m represents the data volume of the new byte data in the encoded data, S represents the storage space required after encoding. When S is a non-integer, S is rounded down.

[0021] Further, the storage space required after decoding is obtained through a second piecewise function, specifically as follows:

[0022] If a≥8 and a is divisible by 8, ;

[0023] When \(0 < a < 8\), \(Q=a - 1\);

[0024] When \(a>8\) and \(a\) is not divisible by \(8\), ;

[0025] \(a\) represents the data volume of the new byte data before decoding, and \(Q\) represents the storage space required after decoding. When \(Q\) is a non-integer, \(Q\) is rounded down.

[0026] Furthermore, in the decoding operation of S5: the new byte data in the encoded data is decoded in the order of generation of the new byte data. Specifically: the encoding results of the 7 low-order spaces in each new byte data are decoded in the storage order to obtain the decoding result, and each decoding result is written into the highest bit of the corresponding byte data A of a frame of byte stream data A to obtain the restored data.

[0027] Furthermore, when the frame splitting flag of the highest bit in the new byte data indicates that a frame of byte stream data has not ended encoding, decode the next new byte data; otherwise, end after completing the decoding of the current new byte data.

[0028] Compared with the prior art, the present invention has the following beneficial effects:

[0029] The present invention splits the 8-bit data of the byte data of the byte stream into 7-bit data, and at the same time encodes the data of the highest bit of every 7 byte data, that is, the 8th bit data of every 7 byte data, into 1 new byte data for transmission. The highest bit (the 8th bit) represents the transmission frame splitting state, which is stable and reliable. Especially when byte stream communication is performed between the host computer and the hardware device, it can keep the data stably framed under high frame rate transmission. And the transmission efficiency of the present invention is 87.5%, which is much higher than the 50% of the ASCII plaintext transmission efficiency.

[0030] Whether the transmission of the present invention is completed only needs to detect whether the highest bit of each byte data is set (frame splitting flag), so multi-packet transmission of one frame of data is allowed; the transmission speed of the present invention is fast, especially in computer-embedded device communication, supporting HEX high-speed communication; since non-extended ASCII code is also 7-bit transmission, the present invention is compatible with non-extended ASCII transmission, and at the same time the transmission is stable and reliable, does not require additional hardware resources of the processor, and only requires simple encoding and decoding to achieve accurate and efficient frame splitting. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 is a flowchart of the method of the present invention.

[0032] Figure 2 is a schematic diagram of a specific embodiment of the encoding of the present invention.

[0033] Figure 3 is a schematic diagram of a specific embodiment of the decoding of the present invention. DETAILED DESCRIPTION

[0034] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0035] like Figure 1 As shown, the present invention provides a frame transmission method based on byte stream communication, comprising the following steps:

[0036] S1, the sending buffer passes the data attributes of the byte stream data to the coding resource allocator;

[0037] S2, the coding resource allocator calculates the storage space required after coding based on the data attributes of the byte stream data;

[0038] S3, the frame stream encoder encodes the byte stream data based on the calculated storage space required after encoding to obtain encoded data, and then transmits the encoded data to the target end device through the byte stream transmitter;

[0039] S4, the byte stream receiver receives the encoded data of the target end device, and the decoding resource allocator calculates the storage space required after decoding based on the data attributes of the encoded data;

[0040] S5. The frame stream decoder decodes the encoded data based on the calculated storage space required after decoding to obtain restored data, and stores the restored data in a receiving buffer.

[0041] The present invention re-encodes the highest bit of byte stream data, and the data stream is transmitted with the lower 7 bits. During decoding, only the highest bit data needs to be restored, so that the data can maintain stable and reliable framing under high frame rate transmission and the transmission efficiency is improved.

[0042] In the encoding operation of S3 described in the present invention: the highest bit data in every 7 original byte data in a frame of byte stream data is encoded into 1 new byte data, and each byte data (BYTE) of the byte stream data consists of 8 bits, that is, 8-bit data. For this reason, the present invention encodes the highest bit data in each original byte data, that is, the 8th bit data, to obtain an encoding result, and then clears the highest bit data of the current original byte data to obtain byte data A; then the 7 encoding results of every 7 original byte data are stored in an 8-bit space to generate 1 new byte data; all byte data A are spliced ​​into a frame of byte stream data A, and then all new byte data are sequentially spliced ​​into a frame of byte stream data A in the order of generation to obtain encoded data. The present invention splits the 8-bit data of the byte data of the byte stream data into 7-bit data, and at the same time encodes the highest bit data of every 7 bytes of data, that is, the 8th bit data of every 7 bytes of data into 1 new byte data for transmission, that is, the encoding is only for the highest bit of the original byte data, so the lower 7 bits of the original byte data remain unchanged, and the highest bit data of the current original byte data is cleared, that is, the highest bit only represents the transmission framing state, which shows that the transmission efficiency = 7 / 8 = 87.5%. The process of obtaining the encoding result by encoding can be achieved by the existing encoding algorithm.

[0043] Preferably, in the 8-bit space, from left to right, there are low-order space 1, low-order space 2, low-order space 3, low-order space 4, low-order space 5, low-order space 6 and the highest-order space; each of the 7 low-order spaces is used to store 1 encoding result, and the highest-order space is used to store a framing identifier, and the framing identifier is used to mark whether the encoding of a frame of byte stream data has been completed. The framing identifier is 0 or 1. When the framing identifier is 0, it indicates that the encoding of a frame of byte stream data has not been completed. When the framing identifier is 1, it indicates that the encoding of a frame of byte stream data has been completed. Each byte data of the byte stream data is split into 7 bits of data, and the 8th bit of data is cleared, that is, it is displayed as 0, which is the same as the framing identifier being 0, indicating that the encoding of a frame of byte stream data has not been completed. The framing identifier of a new byte data generated at the end of a frame of byte stream data is 1, indicating that the encoding of the frame of byte stream data has been completed, and can also serve as an end prompt for subsequent decoding.

[0044] Preferably, in the 8-bit space, the order of the encoding results is from low-order space 6 to low-order space 1. The encoding results are stored in sequence from low-order space 6 to low-order space 1, and then shifted to the low-order space 6 of the next new byte data to continue storing until all encoding results are stored.

[0045] Figure 2 A specific embodiment of the encoding is:

[0046] One frame of byte stream data contains n byte data, BYTE1, BYTE2, ..., BYTEn-1, BYTEn. Encode the highest bit data of BYTE1~BYTE7, that is, the data of the rightmost bit (b7 bit), to obtain the encoding result. Here, x represents valid data, which may be 0 or 1, so it is not listed in detail. And the data of the 7 lower bits (b6~b0 bits) remains unchanged. Similarly, x represents valid data, which may be 0 or 1, so it is not listed in detail. Store the encoding results of the highest bit data of BYTE1~BYTE7 into the 7 lower bit spaces of the new byte data BYTEn+1 in sequence, that is, b6~b0 bits. Since the subsequent encoding is not completed, the highest bit space, that is, b7 bit, is recorded as 0. At the same time, clear the highest bit data of BYTE1~BYTE7 to 0, that is, record it as 0. Similarly, perform the above operations on BYTE8~BYTEn. Since BYTEn is the last byte data of the byte stream data, for this reason, the highest bit space of the new byte data BYTES corresponding to BYTEn, that is, b7 bit, is recorded as 1, indicating that the current byte stream data has been encoded. Finally, arrange BYTEn+1~BYTES after BYTEn of BYTE1~BYTEn, that is, BYTE1, BYTE2, ..., BYTEn, BYTEn+1, BYTEn+2, ..., BYTES-1, BYTES.

[0047] After BYTEn of BYTE1~BYTEn, that is, BYTE1, BYTE2, ..., BYTEn, BYTEn+1, BYTEn+2, ..., BYTES-1, BYTES.

[0048] Before encoding, all bit data from BYTEn+1 to BYTES is in the all-0 state, and the highest bit of BYTE1~BYTEn is x (valid data). After encoding, the highest bit data of BYTE1~BYTEn is encoded and stored in the 7 lower bit spaces of BYTEn+1~BYTES, and then the highest bit of BYTE1~BYTEn is cleared, that is, x is changed to 0.

[0049] The storage space required after encoding in the present invention is obtained through the first piecewise function, specifically as follows:

[0050] If n≥7 and n is divisible by 7, ;

[0051] If 0 < n < 7, m = 1;

[0052] If n > 7 and n is not divisible by 7, ;

[0053] S = n + m;

[0054] Let \(n\) represent the data volume of the original byte data in a frame of byte stream data, \(m\) represent the data volume of the new byte data in the encoded data, and \(S\) represent the storage space required after encoding. When \(S\) is a non-integer, \(S\) is rounded down. The data volume of the original byte data in a frame of byte stream data is a data attribute of the byte stream data and is obtained through the transfer of the send buffer. The storage space required after encoding provides a suitable memory space for temporarily storing the encoded data after a frame of data is encoded and performs preprocessing before encoding, that is, first clears the storage space.

[0055] In (1) of the first piecewise function, when the data volume of the original byte data is exactly divisible by 7, the data volume of the new byte data is an integer. At this time, the 7 low-order spaces of each new byte data store the encoding results; in (2) and (3) of the first piecewise function, the data volume of the original byte data is not divisible by 7, and some low-order spaces of the last new byte data do not store the encoding results. At this time, the state of the unused space can be arbitrary.

[0056] The storage space required after decoding of the present invention is obtained through the second piecewise function, specifically as follows:

[0057] If \(a\geq8\) and \(a\) is divisible by 8, ;

[0058] If \(0 < a < 8\), then \(Q=a - 1\);

[0059] If \(a>8\) and \(a\) is not divisible by 8, ;

[0060] Let \(a\) represent the data volume of the new byte data before decoding, and \(Q\) represent the storage space required after decoding. When \(Q\) is a non-integer, \(Q\) is rounded down.

[0061] For the data to be decoded, the highest bit of the last byte data, that is, the new byte data, must be 1, and the highest bits of the remaining byte data must be 0. Since the storage space required after decoding is \(Q\) bytes (that is, the data length before encoding), and the highest bits of the first \(Q\) byte data must be 0, the length of the data to be decoded is \(S\). Then there are \(S - Q\) bytes of data that are new data generated due to encoding, and their low 7 bits are all valid data. Therefore, it is necessary to restore all these valid data to the highest bits of \(Q\) bytes according to the encoding rules. Therefore, The data of the units digit needs to be restored to the highest bits of \(Q\) bytes. Therefore, .

[0062] In the decoding operation of S5: the new byte data in the encoded data are decoded in sequence according to the generation order of the new byte data, specifically: the encoding results of the 7 low-order spaces in each new byte data are decoded in sequence according to the storage order to obtain the decoding results, and each decoding result is written into the highest bit of the byte data A corresponding to a frame of byte stream data A to obtain the restored data.

[0063] Preferably, when the highest-order framing mark in the new byte data indicates that one frame of byte stream data has not been encoded, the next new byte data is decoded; otherwise, the decoding ends after the current new byte data is decoded.

[0064] Figure 3 A specific example of decoding:

[0065] The data to be decoded includes multiple byte data, BYTE1, BYTE2, ..., BYTEQ-1, BYTEQn, BYTEQ+1, BYTEQ+2, ..., BYTE a, wherein BYTEQ+1, BYTEQ+2, ..., BYTE a are new byte data generated after encoding and are generated in sequence. Therefore, decoding is performed from the first new byte data generated, and decoding is performed from the 7 low-order spaces (bits b6 to b0) of BYTEQ+1 in sequence, and each decoding result is written into the highest bit (bit b7) of BYTE1 to BYTE7; repeat the above operation, and similarly, perform the above operation on BYTEBYTEQ+2 to BYTE a. Since BYTE a is the last new byte stream data generated, and its highest bit (bit b7) is 1, decoding ends after BYTE a is decoded.

[0066] In summary, the present invention realizes fast frame transmission through the mechanism of 1 byte 7 bits transmission, which has the characteristics of increasing the space complexity to a certain extent but reducing the time complexity to a certain extent. Therefore, whether the transmission of each frame of data is completed can be directly checked by checking whether the highest bit of each byte data is set (framing flag).

[0067] Finally, it should be noted that the above embodiments are only preferred embodiments of the present invention to illustrate the technical solutions of the present invention, rather than limiting them, and certainly not limiting the patent scope of the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention. In other words, any changes or modifications made to the main design concept and spirit of the present invention that have no substantive significance, and the technical problems they solve are still consistent with the present invention, should be included in the protection scope of the present invention. In addition, the direct or indirect application of the technical solutions of the present invention in other related technical fields is also included in the patent protection scope of the present invention.

Claims

1. A frame transmission method based on byte stream communication, characterized in that: It includes the following steps: S1. The sending buffer transfers the data attributes of the byte stream data to the encoding resource allocator; S2. The encoding resource allocator calculates the storage space required after encoding based on the data attributes of the byte stream data; S3. The frame stream encoder encodes the byte stream data based on the calculated storage space required after encoding to obtain encoded data, and then transmits the encoded data to the target device through the byte stream sender; S4. The byte stream receiver receives the encoded data of the target device, and the decoding resource allocator calculates the storage space required after decoding based on the data attributes of the encoded data; S5. The frame stream decoder decodes the encoded data based on the calculated storage space required after decoding to obtain restored data, and stores the restored data in the receiving buffer; In the encoding operation of S3: The highest-bit data in every 7 original byte data in one frame of byte stream data is encoded into 1 new byte data. Specifically: The highest-bit data in each original byte data is encoded to obtain an encoding result, and then the highest-bit data of the current original byte data is cleared to obtain byte data A; The 7 encoding results of every 7 original byte data are stored in an 8-bit space to generate 1 new byte data; All byte data A are combined into one frame of byte stream data A', and then all new byte data are sequentially combined after one frame of byte stream data A' in the generation order to obtain the encoded data; In the 8-bit space, from left to right are low-order space 1, low-order space 2, low-order space 3, low-order space 4, low-order space 5, low-order space 6, low-order space 7, and the highest-order space; Each of the 7 low-order spaces is used to store 1 encoding result, and the highest-order space is used to store a frame segmentation flag, and the frame segmentation flag is used to mark whether one frame of byte stream data has ended encoding; The storage space required after encoding is obtained through a first piecewise function, specifically as follows: If n ≥ 7 and n is divisible by 7, ; If 0 < n < 7, then m = 1; If n>7 and n is not divisible by 7, ; S = n + m; n represents the data volume of the original byte data in one frame of byte stream data, m represents the data volume of the new byte data in the encoded data, S represents the storage space required after encoding, and when S is a non-integer, S is rounded down; The storage space required after decoding is obtained through a second piecewise function, specifically as follows: If a ≥ 8 and a is divisible by 8, ; If 0 < a < 8, then Q = a - 1; If a>8 and a is not divisible by 8, ; a represents the data volume of the new byte data before decoding, Q represents the storage space required after decoding, and when Q is a non-integer, Q is rounded down; In the decoding operation of S5: The new byte data in the encoded data are decoded sequentially in the generation order of the new byte data. Specifically: The encoding results in the 7 low-order spaces of each new byte data are decoded sequentially in the storage order to obtain decoding results, and each decoding result is written into the highest bit of the corresponding byte data A in one frame of byte stream data A' to obtain the restored data.

2. A frame transmission method based on byte stream communication according to claim 1, characterized in that: The frame segmentation flag is 0 or 1. When the frame segmentation flag is 0, it means that one frame of byte stream data has not ended encoding. When the frame segmentation flag is 1, it means that one frame of byte stream data has ended encoding.

3. A frame transmission method based on byte stream communication according to claim 1, characterized in that: In the 8-bit space, the storage order of the encoding results is from low-order space 7 to low-order space 1 in sequence.

4. A frame transmission method based on byte stream communication according to claim 1, characterized in that: When the highest-order framing mark in the new byte data indicates that one frame of byte stream data has not been encoded, the next new byte data is decoded; otherwise, the process ends after the current new byte data is decoded.

Citation Information

Patent Citations

  • Video data processing method and electronic equipment

    CN103517027A

  • Data packet transmission method and device, electronic equipment and storage medium

    CN115225710A