Disclosure of Invention
The invention provides a method, a device, equipment and a storage medium for avoiding protocol frame header collision, which solve the problems of low data transmission efficiency, high processing complexity, long processing delay, insufficient robustness and stiff bitmap design in the prior art.
In order to achieve the above purpose, the invention adopts the following technical scheme:
in a first aspect, the present invention provides a method for avoiding collision of protocol frame headers, applied to a transmitting end of data communication, the method comprising:
the method comprises the steps of detecting conflict data in an original data frame, and replacing the conflict data by using replacement data to obtain a first data frame, wherein the conflict data are the rest data blocks which are the same as frame header bytes except data blocks corresponding to the frame header in the original data frame;
Determining the conflict rate of the original data frame according to the number of the conflict data and the total data block quantity of the original data frame;
Dynamically selecting a single-layer bitmap structure or a multi-layer bitmap structure according to the conflict rate to generate bitmap marks for representing positions of all conflict data, wherein the single-layer bitmap structure directly marks the positions of the conflict data in the original data frame;
adding a corresponding level identifier to the head of the bitmap mark, and adding a check bit to the tail of the bitmap mark to obtain a complete bitmap;
and adding the complete bitmap at the tail of the first data frame to obtain a second data frame.
In one possible implementation manner, the bitmap annotation comprises a single-layer bitmap annotation and a multi-layer bitmap annotation, wherein the single-layer bitmap structure or the multi-layer bitmap structure is dynamically selected according to the conflict rate, and the bitmap annotation used for representing the position of all conflict data is generated specifically comprises:
When the conflict rate is smaller than a first threshold value, selecting a single-layer bitmap structure, and marking whether each data block corresponding to the original data frame is conflict data or not by each bit of marking data of the single-layer bitmap structure to obtain a single-layer mark;
and selecting a multi-layer bitmap structure when the conflict rate is greater than or equal to the first threshold value, marking the position of conflict data in the layer by utilizing each bit of each layer of marking data by using the hierarchical structure, and generating a multi-layer mark.
In one possible implementation manner, the multi-layer bitmap structure comprises a two-layer bitmap structure and a three-layer bitmap structure, and the multi-layer bitmap structure is selected when the conflict rate is greater than or equal to the first threshold value, specifically comprising:
When the conflict rate is greater than or equal to the first threshold value and is smaller than a second threshold value, selecting the two-level graph structure;
and selecting the three-layer bitmap structure when the conflict rate is greater than or equal to the second threshold.
In one possible implementation manner, when the two-layer bitmap structure is selected, the marking data comprises first-layer marking data and second-layer marking data, the generated multi-layer marking is a two-layer marking, and the positions of conflict data in the layer are marked by each bit of each layer marking data to generate the multi-layer marking, which specifically comprises:
Marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a two-layer graph structure;
And marking whether each data block in the data segment containing the conflict data is the conflict data or not by each bit of second-layer marking data of the two-layer graph structure to obtain the two-layer marking.
In one possible implementation manner, when the three-layer bitmap structure is selected, the marking data comprises a first layer marking data, a second layer marking data and a third layer marking data, the generated multi-layer marking is a three-layer marking, and the position of conflict data in the layer is marked by each bit of each layer marking data to generate the multi-layer marking, which specifically comprises:
marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a three-layer bitmap structure, wherein each original data frame comprises a plurality of data segments, each data segment comprises a plurality of data small segments, and each data small segment comprises a plurality of data blocks;
marking whether each data segment in the data segments containing the conflict data contains the conflict data or not by each bit of the second layer marking data of the three-layer bitmap structure;
And marking whether each data block in the data small section containing the conflict data is the conflict data or not by each bit of third layer marking data of the three-layer bitmap structure to obtain three-layer marking.
In one possible implementation manner, the collision rate of the original data frame is determined according to the number of the collision data and the total data block amount of the original data frame, which is specifically:
and calculating the ratio of the number of the conflict data to the total data block quantity of the original data frame to obtain the conflict rate of the original data frame.
In a second aspect, the present invention provides a method for avoiding collision of protocol frame headers, applied to a receiving end of data communication, the method comprising:
The method comprises the steps of receiving a second data frame comprising a first data frame and a complete bitmap, wherein the first data frame is a data frame obtained by replacing conflict data in an original data frame by using replacement data, the conflict data are data blocks which are the same as the bytes of a frame head except the data blocks corresponding to the frame head in the original data frame, and the complete bitmap comprises a hierarchy identifier, a bitmap mark and a check bit which are sequentially arranged;
Determining a data analysis mode to be a single-layer analysis mode corresponding to a single-layer bitmap structure or a multi-layer analysis mode corresponding to a multi-layer bitmap structure according to the level identification, wherein the single-layer bitmap structure directly marks the position of conflict data in the original data frame;
According to the determined data analysis mode, the conflict position of conflict data in an original data frame is obtained by combining the bitmap annotation analysis;
Replacing the data block corresponding to the conflict position in the first data frame with the frame header byte to obtain a restored original data frame;
and outputting the restored original data frame after determining that the check bit accords with preset check data.
In a third aspect, the present invention provides an apparatus for avoiding collision of protocol frame headers, applied to a transmitting end of data communication, the apparatus comprising:
The device comprises a detection processing module, a data processing module and a data processing module, wherein the detection processing module is used for detecting conflict data in an original data frame and replacing the conflict data by using replacement data to obtain a first data frame;
a conflict frequency calculation module, configured to determine a conflict rate of the original data frame according to the number of conflict data and the total data block amount of the original data frame;
The system comprises a first bitmap generation module, a first bitmap generation module and a second bitmap generation module, wherein the first bitmap generation module is used for dynamically selecting a single-layer bitmap structure or a multi-layer bitmap structure according to the conflict rate to generate bitmap marks for representing positions of all conflict data;
the second bitmap generation module adds a corresponding level identifier to the head of the bitmap label, and adds a check bit to the tail of the bitmap label to obtain a complete bitmap;
And the data bitmap synthesis module is used for adding the complete bitmap at the tail end of the first data frame to obtain a second data frame.
In one possible implementation, the bitmap annotation comprises a single-layer bitmap annotation and a multi-layer bitmap annotation, and the first bitmap generation module is specifically configured to execute:
When the conflict rate is smaller than a first threshold value, selecting a single-layer bitmap structure, and marking whether each data block corresponding to the original data frame is conflict data or not by each bit of marking data of the single-layer bitmap structure to obtain a single-layer mark;
and selecting a multi-layer bitmap structure when the conflict rate is greater than or equal to the first threshold value, marking the position of conflict data in the layer by utilizing each bit of each layer of marking data by using the hierarchical structure, and generating a multi-layer mark.
In one possible implementation, the multi-layer bitmap structure includes a two-layer bitmap structure and a three-layer bitmap structure, and when the conflict rate is greater than or equal to the first threshold, the first bitmap generation module is specifically configured to perform:
When the conflict rate is greater than or equal to the first threshold value and is smaller than a second threshold value, selecting the two-level graph structure;
and selecting the three-layer bitmap structure when the conflict rate is greater than or equal to the second threshold.
In one possible implementation manner, when the two-layer bitmap structure is selected, the marking data comprises first-layer marking data and second-layer marking data, the generated multi-layer marking is a two-layer marking, and when each bit of each-layer marking data is used for marking the position of conflict data in the layer, the first bitmap generation module is specifically configured to execute:
Marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a two-layer graph structure;
And marking whether each data block in the data segment containing the conflict data is the conflict data or not by each bit of second-layer marking data of the two-layer graph structure to obtain the two-layer marking.
In one possible implementation manner, when the three-layer bitmap structure is selected, the marking data comprises first-layer marking data, second-layer marking data and third-layer marking data, the generated multi-layer marking is a three-layer marking, and when each bit of each layer marking data is utilized to mark the position of conflict data in the layer, the first bitmap generation module is specifically configured to execute:
marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a three-layer bitmap structure, wherein each original data frame comprises a plurality of data segments, each data segment comprises a plurality of data small segments, and each data small segment comprises a plurality of data blocks;
marking whether each data segment in the data segments containing the conflict data contains the conflict data or not by each bit of the second layer marking data of the three-layer bitmap structure;
And marking whether each data block in the data small section containing the conflict data is the conflict data or not by each bit of third layer marking data of the three-layer bitmap structure to obtain three-layer marking.
In one possible implementation, the collision frequency calculation module is specifically configured to perform:
and calculating the ratio of the number of the conflict data to the total data block quantity of the original data frame to obtain the conflict rate of the original data frame.
In a fourth aspect, the present invention provides an electronic device, including a processor and a memory, where the memory stores at least one instruction, at least one program, a set of codes, or a set of instructions, where the at least one instruction, the at least one program, the set of codes, or the set of instructions are loaded and executed by the processor to implement a method for protocol header collision avoidance as described in any of the preceding claims.
In a fifth aspect, the present invention provides a computer readable storage medium having stored therein at least one instruction, at least one program, a set of codes, or a set of instructions, the at least one instruction, the at least one program, the set of codes, or the set of instructions being loaded and executed by a processor to implement the method for protocol header collision avoidance as described in any of the preceding claims.
In practical application, the method for avoiding the collision of the protocol frame header detects collision data identical to frame header bytes in an original data frame to be transmitted at a transmitting end of data communication, replaces the collision data with pre-designed replacement data to obtain a first data frame, determines a collision rate according to the collision data and the data quantity of the original data frame, dynamically selects a single-layer bitmap structure or a multi-layer bitmap structure according to the size of the collision rate to generate bitmap marks for representing the positions of the collision data in the original data frame, adds a hierarchical mark at the header of the bit map, adds a check bit at the end to obtain a complete bitmap, finally splices the complete bitmap to the end of the first data frame to obtain a second data frame, and efficiently restores the original data frame by a receiving end according to the complete bitmap. The invention replaces the conflict data in the original data frame by the replacement data, marks the replacement position of the conflict data by the complete bitmap, wherein the generation of the bitmap can dynamically select a proper bitmap structure according to the frequency of the conflict data, namely, the invention effectively improves the data transmission rate, reduces the complexity and delay of data processing and improves the reliability and flexibility of data transmission by the intelligent multi-layer bitmap design scheme of dynamic division, context sensing and self-adaptive threshold adjustment.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "first" and "second" are used below for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the embodiments of the present disclosure, unless otherwise indicated, the meaning of "a plurality" is two or more. In addition, the use of "based on" or "according to" is intended to be open and inclusive in that a process, step, calculation, or other action "based on" or "according to" one or more of the stated conditions or values may in practice be based on additional conditions or beyond the stated values.
In the prior art, the key of the private protocol fault-tolerant processing method based on serial communication disclosed in the patent with the publication number CN114337915A is that a data transmitting end identifies a byte sequence identical to a frame header in a data area or a cyclic redundancy check code, the identified byte sequence is called a pseudo frame header, the pseudo frame header is replaced by predefined replacement data to obtain a second data frame, a single-layer bitmap is used for marking a replacement position in the frame header check data, for example, the position of the replacement data is represented by 1, the positions of the rest data are represented by 0, and a receiving end restores the pseudo frame header according to the frame header check data.
Although the above processing method can prevent erroneous judgment of the frame header in a specific scene, there are also problems of low transmission efficiency, high processing complexity, long processing delay, insufficient robustness, stiff bitmap design, and the like.
Wherein, the low transmission efficiency means that the frame header check data filled with bits or bytes increases the extra data amount and reduces the bandwidth utilization. That is, the length of the data packet is further increased by adding the replacement data and the single-layer bitmap structure, especially when the frame header data collision is frequent, the bit-by-bit marking mode of the single-layer bitmap has lower transmission efficiency in the long data packet transmission process, and the more serious the influence on the transmission efficiency is.
The high processing complexity means that the sending end needs to monitor and replace data in real time, and the receiving end needs to decode and restore, thus increasing the calculation burden. That is, the bit-by-bit marking of the single-layer bitmap is more computationally burdensome to monitor, replace, and decode during long packet transmission.
A longer processing delay means that the padding, replacement and decoding process introduces additional processing time, which is not suitable for low delay scenario applications.
The lack of robustness means that filling information or checking data in a noise channel may be lost due to transmission errors, so that the data packet recovery fails, and the problem of misjudgment or tampering of the bitmap itself cannot be solved in the prior art.
The stiffness of the bitmap design refers to that in the data transmission process, only a fixed single-layer bitmap structure is used, and the bitmap structure cannot be adjusted according to the characteristics of the data packet or the channel condition, so that the signal transmission is not efficient in a high-collision or low-collision scene.
In order to solve the problems of low data transmission efficiency, high processing complexity, long processing delay, insufficient robustness and stiff bitmap design existing in the prior art, the embodiment of the invention provides a method, a device, equipment and a storage medium for avoiding protocol frame header collision.
As shown in fig. 1, in one embodiment of the present invention, a method for avoiding collision of protocol frame header is provided, and the method is applied to a transmitting end of data communication, where the data communication modes include serial communication, network communication, local area network communication, wireless communication, industrial communication, and the like;
The method comprises the following steps:
and 101, detecting conflict data in an original data frame, and replacing the conflict data by using replacement data to obtain a first data frame.
The conflict data are the data blocks which are the same as the frame header bytes except the data blocks corresponding to the frame header in the original data frame.
Specifically, the original data frame refers to a data packet to be transmitted, where the data packet includes a frame header byte. In step 101, byte content of each data block in the original data frame is detected in turn, and after collision data identical to the frame header byte is detected, the collision data is replaced by predefined replacement data, so as to obtain a first data frame. For example, the frame header data is AA 55, the predefined replacement data is AB 54, and after collision data is detected, the AB 54 is used for replacing the AA 55.
Step 102, determining the collision rate of the original data frame according to the number of the collision data and the total data block quantity of the original data frame.
Where the collision rate refers to the percentage of the number of collision data to the total number of data blocks of the original data frame.
In order to improve flexibility and adaptability of a communication protocol while solving the problem of frame header misjudgment, a data transmission scene may be divided according to a collision rate, for example, the data transmission scene may be divided into two scenes of high collision and low collision, or the data transmission scene may be divided into three scenes of high collision, medium collision and low collision. And further different bitmap structures are designed for different conflict scenes.
And 103, dynamically selecting a single-layer bitmap structure or a multi-layer bitmap structure according to the size of the conflict rate, and generating bitmap labels for representing the positions of all conflict data.
Wherein the single-layer bitmap structure directly marks the position of the conflicting data in the original data frame.
The original data frame is divided layer by layer in the multi-layer bitmap structure, and the positions of the conflict data in each layer are marked sequentially by using the hierarchical structure.
Specifically, the single-layer bitmap structure is suitable for a scene with sparse conflict, directly marks whether each data block of the original data frame is conflict data, and is simple and efficient.
The multi-layer bitmap structure divides the original data frame into multiple layers layer by layer according to the actual demands of users, and adopts a layering marking mode to mark the position of conflict data in each layer of the original data frame, thereby realizing the optimization of bitmap length. The number of layers of the multi-layer bitmap structure can be designed according to the conflict rate, and when the conflict rate is high, the number of layers of the multi-layer bitmap structure can be properly increased. That is, the multi-layer bitmap structure is suitable for a scene in the collision set, and the data segments in the collision set are marked first through the hierarchical structure, and then specific positions of the collision data are marked in the marked data segments, so that the total length of the bitmap is shortened.
Specifically, the frequency of occurrence of the conflict data is reflected by the size of the conflict rate, and the larger the conflict rate is, the more frequently the conflict data is. In the actual data transmission process, a single-layer bitmap structure or a multi-layer bitmap structure is dynamically selected according to the size of the conflict rate to generate bitmap annotation, so that the best transmission efficiency can be realized under different conflict scenes.
And 104, adding a corresponding level identifier to the head of the obtained bitmap mark, and adding a check bit to the tail of the bitmap mark to obtain a complete bitmap.
Specifically, the hierarchy identifier is used for distinguishing bitmap structures corresponding to the bitmap labels, and the bitmap structures of different hierarchies correspond to different hierarchy identifiers.
Specifically, the bitmap structures corresponding to the bitmap labels are distinguished by using the 2-bit hierarchical labels, for example, a single-layer bitmap structure, a two-layer bitmap structure and a three-layer bitmap structure are respectively represented by 00, 01 and 10.
The check bit is mainly used for data check at the data receiving end, and accuracy of data transmission is improved.
And 105, adding the complete bitmap at the end of the first data frame to obtain a second data frame.
Specifically, the complete bitmap is spliced at the end of the first data frame, and the obtained second data is subjected to data transmission.
In practical application, the method for avoiding the collision of the protocol frame header detects collision data identical to frame header bytes in an original data frame to be transmitted at a transmitting end of data communication, replaces the collision data with pre-designed replacement data to obtain a first data frame, determines a collision rate according to the collision data and the data quantity of the original data frame, dynamically selects a single-layer bitmap structure or a multi-layer bitmap structure according to the size of the collision rate to generate bitmap marks for representing the positions of the collision data in the original data frame, adds a hierarchical mark at the header of the bit map, adds a check bit at the end to obtain a complete bitmap, finally splices the complete bitmap to the end of the first data frame to obtain a second data frame, and efficiently restores the original data frame by a receiving end according to the complete bitmap.
The invention replaces the conflict data in the original data frame by the replacement data, marks the replacement position of the conflict data by the complete bitmap, wherein the generation of the bitmap can dynamically select the proper bitmap structure according to the frequency of the conflict data.
In other words, the intelligent multi-layer bitmap design scheme of dynamic division, context sensing and self-adaptive threshold adjustment effectively improves the data transmission rate, reduces the complexity and processing delay of data processing, and improves the reliability and flexibility of data transmission.
Further, bitmap annotations include single-layer bitmap annotations and multi-layer bitmap annotations. In step 103, dynamically selecting a single-layer bitmap structure or a multi-layer bitmap structure according to the size of the conflict rate, and generating bitmap labels for representing positions of all conflict data, which specifically includes:
Step 1031, selecting a single-layer bitmap structure when the collision rate is smaller than a first threshold value, and marking whether each data block corresponding to the original data frame is collision data or not by each bit of marking data of the single-layer bitmap structure to obtain a single-layer mark.
Specifically, a low-conflict scene with a conflict rate smaller than a first threshold value is selected, a single-layer bitmap structure is selected in a conflict sparse scene, the length of the marked data is equal to the total number of data blocks of the original data frame, each bit of the marked data sequentially corresponds to one data block of the original data frame, and the numerical value of each bit of the marked data is used for indicating whether the corresponding data block is conflict data or not. For example, when a data block of the original data frame is collision data, the flag data bit corresponding to the data block is represented by 1, otherwise, the flag data bit is represented by 0.
Step 1032, selecting a multi-layer bitmap structure when the collision rate is greater than or equal to the first threshold, using the hierarchical structure, marking the position of the collision data within the layer with each bit of the marking data of each layer, and generating a multi-layer marking.
Specifically, a conflict rate is greater than or equal to a first threshold value as a conflict set scene, a multi-layer bitmap structure is selected in the scene, and bitmap length and analysis efficiency are optimized according to the conflict characteristics of data. The number of layers of the marking data is the same as that of the multi-layer bitmap structure, the number of bits of each layer of marking data is the same as that of the segments of the data in the layer, and for each layer of marking data, the numerical value of each bit of the marking data in the layer is used for representing whether the corresponding data segment comprises conflict data or not. For example, for a layer of tag data, if a data segment in the layer contains collision data, the tag data bit corresponding to the data segment is denoted by 1, otherwise, 0 is denoted.
Further, the multi-layer bitmap structure includes a two-layer bitmap structure and a three-layer bitmap structure. Selecting the multi-layer bitmap structure when the conflict rate is greater than or equal to a first threshold value, specifically comprising:
And selecting the two-level bitmap structure when the conflict rate is greater than or equal to the first threshold value and is simultaneously smaller than the second threshold value.
And selecting a three-layer bitmap structure when the conflict rate is greater than or equal to a second threshold.
Specifically, the magnitudes of the first threshold and the second threshold can be adjusted according to the user requirement.
In the embodiment of the invention, the first threshold value is 5%, and the second threshold value is 15%.
When the conflict rate is less than 5%, a single-layer bitmap structure is selected, when the conflict rate is less than or equal to 5% and less than or equal to 15%, a two-layer bitmap structure in the multi-layer bitmap structure is selected, and when the conflict rate is more than or equal to 15%, a three-layer bitmap structure in the multi-layer bitmap structure is selected.
In the present embodiment, each data block is exemplified by 1 byte, and bitmap designs under different conflict scenarios are as follows
Table 1 shows:
Table 1 bitmap design table for low, medium, and high conflict scenarios
As can be seen from table 1, in the low-collision scenario with the collision rate of <5%, the length of the marking data is equal to the number of data blocks through the single-layer bitmap structure, each bit of the marking data corresponds to one data block, and the total length of the generated bitmap marking is fixed.
In a medium conflict scene with a conflict rate of less than or equal to 5 percent and less than 15 percent, marking a data segment containing conflict data by the first layer of marking data of a double-layer bitmap structure, marking the specific position of the conflict data in the marked data segment by the second layer of marking data, and optimizing the bitmap length.
In a high conflict scene with the conflict rate more than or equal to 15%, marking a data segment containing conflict data through a first layer of marking data of a three-layer bitmap structure, marking the position of a data segment containing conflict data in the marked data segment through a second layer of marking data, marking the position of the conflict data in the marked data segment through a third layer of marking data, and balancing the bitmap length and the analysis complexity.
Further, when the two-layer graph structure is selected, the marking data comprise first-layer marking data and second-layer marking data, and the generated multi-layer marking is a two-layer marking.
Marking the position of conflict data in the layer by each bit of each layer of marking data to generate a multi-layer mark, which specifically comprises the following steps:
each bit of the first layer marking data of the two-layer bitmap structure is used for marking whether each data segment in the original data frame contains conflict data.
Wherein each original data frame comprises a plurality of data segments, and each data segment comprises a plurality of data blocks.
And marking whether each data block in the data segment containing the conflict data is the conflict data or not by each bit of second-layer marking data of the two-layer graph structure to obtain the two-layer marking.
Specifically, the conflict rate is larger than or equal to a first threshold value and smaller than a second threshold value at the same time, and a two-level chart structure is adopted in the conflict scene.
The length of the first layer of marking data is the same as the length of the data segments, each bit of the first layer of marking data sequentially corresponds to one data segment, the numerical value of each bit of the first layer of marking data is used for representing whether the corresponding data segment contains conflict data, if so, the corresponding data segment is represented by 1, and otherwise, the corresponding data segment is represented by 0.
The length of the second layer of marking data is equal to the total amount of the data blocks in the data segment containing the conflict data, each bit of the second layer of marking data sequentially corresponds to one data block in the data segment containing the conflict data, the numerical value of each bit of the second layer of marking data is used for representing whether the corresponding data block is the conflict data, if the corresponding data block is the conflict data, the corresponding data block is represented by 1, and otherwise, the corresponding data block is represented by 0.
Further, when the three-layer bitmap structure is selected, the marking data comprises a first layer marking data, a second layer marking data and a third layer marking data, and the generated multi-layer marking is a three-layer marking.
Marking the position of conflict data in the layer by each bit of each layer of marking data to generate a multi-layer mark, which specifically comprises the following steps:
each data segment in the original data frame is marked with each bit of the first layer marking data of the three-layer bitmap structure to determine whether the data segment contains conflicting data.
Wherein each original data frame comprises a plurality of data segments, each data segment comprises a plurality of data small segments, and each data small segment comprises a plurality of data blocks.
Each bit of the second layer marking data of the three-layer bitmap structure is used for marking whether each data small segment in the data segments containing the conflict data contains the conflict data.
And marking whether each data block in the data small section containing the conflict data is the conflict data or not by each bit of third layer marking data of the three-layer bitmap structure to obtain three-layer marking.
Specifically, a high conflict scene with a conflict rate greater than a second threshold value is adopted, and a three-layer bitmap structure is adopted in the conflict scene.
The length of the first layer of marking data is the same as the length of the data segments, each bit of the first layer of marking data sequentially corresponds to one data segment, the numerical value of each bit of the first layer of marking data is used for representing whether the corresponding data segment contains conflict data, if so, the corresponding data segment is represented by 1, and otherwise, the corresponding data segment is represented by 0.
The length of the second layer of marked data is equal to the total amount of the data segments in the data segment containing the conflict data, each bit of the second layer of marked data sequentially corresponds to one data segment in the data segment containing the conflict data, the numerical value of each bit of the second layer of marked data is used for representing whether the corresponding data segment contains the conflict data, if so, the corresponding data segment is represented by 1, and otherwise, the corresponding data segment is represented by 0.
The length of the third layer of marked data is equal to the total amount of data blocks in the data small section containing the conflict data, each bit of the third layer of marked data sequentially corresponds to one data block in the data small section containing the conflict data, the value of each bit of the third layer of marked data is used for indicating whether the corresponding data block is the conflict data, if so, the corresponding data block is indicated by 1, and otherwise, the corresponding data block is indicated by 0.
In the embodiment of the present invention, it is assumed that a packet has a length of 64 bytes, where the frame header data is AA 55, and occupies 2 bytes, and the remaining 62 bytes are data portions. The size of each data block is defined as 2 bytes, so the data portion contains 31 data blocks.
The number of conflict data in 31 data blocks of the data part is detected, the conflict rate is determined according to the number of the conflict data and the total number of the data blocks, and the data transmission scenes are divided into a low conflict scene, a medium conflict scene and a high conflict scene according to the size of the conflict rate.
In the first scenario, it is assumed that the number of conflicting data is 1, and the position of the conflicting data is the 5 th data block.
According to the ratio of the number of conflict data to the total number of data blocks, the conflict rate of the first scene is calculated to be less than 5%, therefore, the first scene is a low-conflict scene, a single-layer bitmap structure is used, 31 data blocks are represented through 31 bits, 4 bytes are occupied (the insufficient bits are filled with 0), and the bitmap generated by the first scene is marked as 00001000 00000000 00000000 00000000 and indicates that the 5 th data block is conflict data.
And using 00 to represent a single-layer bitmap structure, wherein the check bit adopts parity check, when the number of 1 in the bitmap marking is odd, the check bit is 1, and when the number of 1 in the bitmap marking is even, the check bit is 0.
Thus, the full bitmap of the first scene is 00 00001000 00000000 00000000 000000001.
In the second scenario, the number of conflicting data is assumed to be 3, and the positions of the conflicting data are 2 nd, 5 th and 10 th data blocks.
And according to the ratio of the number of the conflict data to the total number of the data blocks, calculating the conflict rate of the second scene of 5 percent to less than or equal to 15 percent. Thus, the second scenario is a medium collision scenario, using a two-level bitmap structure, the first layer of which divides 31 data blocks into 4 data segments, 8 data blocks per segment (7 of the last segment), and marks the data segments containing collision data using 4 bits, and the second layer generates an 8-bit bitmap for each data segment containing collision data, marking the specific location of collision data.
The first layer bitmap of the second scene is 1100, indicating that the first data segment and the second data segment contain conflicting data. The first data segment (1 st to 8 th data block) of the second layer is marked with bitmap 01001000, which indicates that the 2 nd data block and the 5 th data block are conflict data, and the second data segment (1 st to 8 th data block) of the second layer is marked with bitmap 01000000, which indicates that the 10 th data block is conflict data.
A 01 is used to represent a two-level bitmap structure and a check bit is used to check the entire bitmap, which in this embodiment is assumed to be 1.
Thus, the full bitmap of the first scene is 01 1100 01001000 01000000 1.
In the third scenario, the number of conflicting data is assumed to be 10, and the positions of the conflicting data are 1 st, 3 rd, 5 th, 7 th, 9 th, 11 th, 13 th, 15 th, 17 th, and 19 th data blocks.
And according to the ratio of the number of the conflict data to the total number of the data blocks, calculating the third scene conflict rate not less than 15%. Therefore, the third scenario is a high-conflict scenario, using a three-layer bitmap structure, the first layer of which divides 31 data blocks into 2 data segments, 16 data blocks per segment (15 last segments) and marks the data segments containing conflict data using 2 bits, the second layer divides the data segments containing conflict data into 4 data segments, 4 data blocks per segment and marks the data segments containing conflict data using 4 bits, and the third layer generates a 4-bit bitmap for the data segments containing conflict data, marking the specific positions of conflict data.
The first layer bitmap of the second scene is 11, which indicates that 2 data segments each contain conflicting data. The first data segment (1 st to 16 th data block) marking bitmap of the second layer is 1111, which indicates that all the data segments of the first data segment contain conflict data, and the second data segment (17 th to 31 th data block) marking bitmap of the second layer is 1000, which indicates that only the first data segment of the second data segment contains conflict data. The first data small section (1 st to 4 th data blocks) of the first data section of the third layer is marked with bitmaps of 1010, the 1 st data block and the 3 rd data block are the conflict data, the second data small section (5 th to 8 th data blocks) of the first data section of the third layer is marked with bitmaps of 1010, the 5 th data block and the 7 th data block are the conflict data, the third data small section (9 th to 12 th data blocks) of the first data section of the third layer is marked with bitmaps of 1010, the 9 th data block and the 11 th data block are the conflict data, the fourth data small section (13 th to 16 th data blocks) of the first data section of the third layer is marked with bitmaps of 1010, the 13 th data block and the 15 th data block are the conflict data, and the first data small section (17 th to 20 th data blocks) of the second data section of the third layer is marked with bitmaps of 1010, the 17 th data block and the 19 th data block are the conflict data.
A three-layer bitmap structure is denoted by 10 and a check bit is used to check the entire bitmap, which in this embodiment is assumed to be 0.
Thus, the full bitmap of the third scene is 10 11 1111 1000 1010 1010 1010 1010 10100.
The specific values and structures of the bitmaps in the three scenarios are shown in table 2:
TABLE 2 bitmap concrete values and Structure Table for Low Conflict, medium Conflict and high Conflict scenes
As can be seen from Table 2, the invention dynamically adjusts the bitmap level by utilizing the conflict rate, uses a single-layer bitmap in a low-conflict scene, is simple and direct, adopts a two-layer bitmap in a medium-conflict scene to reduce the bitmap length, and adopts a three-layer bitmap in a high-conflict scene to further optimize the bitmap representation efficiency.
Further, in step 102, the collision rate of the original data frame is determined according to the number of the collision data and the total data block of the original data frame, specifically:
and calculating the ratio of the number of the conflict data to the total data block of the original data frame to obtain the conflict rate of the original data frame.
As shown in fig. 2, in another embodiment of the present invention, a method for avoiding collision of protocol frame header is provided, and the method is applied to a receiving end of data communication, and includes:
Step 201, a second data frame comprising a first data frame and a full bitmap is received.
The first data frame is a data frame after replacing conflict data in the original data frame by using replacement data.
The conflict data are the data blocks which are the same as the frame header bytes except the data blocks corresponding to the frame header in the original data frame.
The complete bitmap comprises a hierarchy identifier, a bitmap label and check bits which are sequentially arranged.
Step 202, determining that the data analysis mode is a single-layer analysis mode corresponding to the single-layer bitmap structure or a multi-layer analysis mode corresponding to the multi-layer bitmap structure according to the hierarchy identification.
Wherein the single-layer bitmap structure directly marks the position of the conflicting data in the original data frame.
The original data frame is divided layer by layer in the multi-layer bitmap structure, and the positions of the conflict data in each layer are marked sequentially by using the hierarchical structure.
And 203, according to the determined data analysis mode, combining bitmap annotation analysis to obtain the conflict position of the conflict data in the original data frame.
Wherein the bitmap annotation is generated based on a single-layer bitmap structure or a multi-layer bitmap structure.
And 204, replacing the data block corresponding to the conflict position in the first data frame with the frame header byte to obtain the restored original data frame.
Step 205, after determining that the check bit accords with the preset check data, outputting the restored original data frame.
In the embodiment of the invention, after receiving the second data frame, the receiving end disassembles the second data frame into the first data frame and the complete bitmap.
And secondly, reading the level identification of the complete bitmap header, and determining the bitmap structure according to the level identification. For example, the 2-bit fixed bitmap structure of the header of the complete bitmap is read, and when the read level identifiers are 00, 01 and 10 respectively, the corresponding bitmap structures are a single-layer bitmap structure, a two-layer bitmap structure and a three-layer bitmap structure respectively.
And thirdly, analyzing the bitmap labels of the complete bitmap according to the data analysis mode corresponding to the identified bitmap structure, and determining the position of conflict data.
For example, when the identified bitmap structure is a single-layer bitmap structure, the bitmap annotation is directly read, and the position of the conflict data is determined according to the position of 1 in the bitmap annotation.
When the identified bitmap structure is a two-layer bitmap structure, analyzing the first layer data of the bitmap label to determine a data segment containing conflict data, and analyzing the second layer data of the bitmap label to determine the position of the conflict data in the corresponding data segment.
When the identified bitmap structure is a three-layer bitmap structure, analyzing first-layer data of the bitmap label to determine a data segment containing conflict data, analyzing second-layer data of the bitmap label to determine a data segment where the conflict data in the data segment are located, and finally analyzing third-layer data of the bitmap label to determine the position of the conflict data in the corresponding data segment.
And then, restoring the replacement byte into a frame header byte according to the determined position of the conflict data, namely the position marked as 1 in the bit icon, and obtaining a restored original data frame.
And finally, carrying out data verification on the restored original data frame by combining with the check bit of the complete bitmap, and when the check bit accords with preset check data, considering that the restored original data frame is identical to the original data frame sent by the sending end, and outputting the restored original data frame, otherwise, considering that the restored original data frame is not identical to the original data frame sent by the sending end, and requesting the sending end to carry out data retransmission.
The invention provides a method for avoiding the collision of the frame heads of the communication protocol, which is efficient, simple, convenient and reliable, and has the advantages of high transmission efficiency, low delay, high reliability and flexible bitmap design.
The transmission efficiency is high, and the bitmap occupies fewer bytes, so that the data transmission overhead is obviously reduced.
The low delay is particularly characterized by simple replacement and restoration operation and short processing time, and is suitable for high-speed communication scenes.
The high reliability is embodied in that the bitmap is prevented from being identical with the frame header by constraining the bitmap value, so that the risk of misjudgment is further reduced.
The bitmap design is flexible and specific in that each bit of the bitmap can correspond to data blocks (such as 2 bytes or 4 bytes) with different lengths, and the size of the compressed bitmap is flexibly adjusted according to the length of the frame header.
In still another embodiment of the present invention, as shown in fig. 3, there is provided an apparatus for avoiding collision of protocol frame headers, applied to a transmitting end of data communication, the apparatus comprising:
The detection processing module 301 is configured to detect collision data in an original data frame, and replace the collision data with replacement data to obtain a first data frame, where the collision data is a data block in the original data frame that is the same as a frame header byte except a data block corresponding to the frame header;
a collision frequency calculation module 302, configured to determine a collision rate of the original data frame according to the number of the collision data and the total data block of the original data frame;
A first bitmap generation module 303, configured to dynamically select a single-layer bitmap structure or a multi-layer bitmap structure according to the size of the collision rate, and generate bitmap labels for representing positions of all the collision data;
The second bitmap generation module 304 adds a corresponding level identifier to the head of the bitmap label, and adds a check bit to the tail of the bitmap label to obtain a complete bitmap;
A data bitmap synthesis module 305, configured to add the complete bitmap at the end of the first data frame, to obtain a second data frame.
Further, in the case that the bitmap annotation includes a single-layer bitmap annotation and a multi-layer bitmap annotation, the first bitmap generation module 303 is specifically configured to execute:
When the conflict rate is smaller than a first threshold value, selecting a single-layer bitmap structure, and marking whether each data block corresponding to the original data frame is conflict data or not by each bit of marking data of the single-layer bitmap structure to obtain a single-layer mark;
and selecting a multi-layer bitmap structure when the conflict rate is greater than or equal to the first threshold value, marking the position of conflict data in the layer by utilizing each bit of each layer of marking data by using the hierarchical structure, and generating a multi-layer mark.
Further, the multi-layer bitmap structure includes a two-layer bitmap structure and a three-layer bitmap structure, and when the multi-layer bitmap structure is selected when the conflict rate is greater than or equal to the first threshold, the first bitmap generation module 303 is specifically configured to perform:
When the conflict rate is greater than or equal to the first threshold value and is smaller than a second threshold value, selecting the two-level graph structure;
and selecting the three-layer bitmap structure when the conflict rate is greater than or equal to the second threshold.
Further, when the two-layer bitmap structure is selected, the marking data includes a first layer marking data and a second layer marking data, the generated multi-layer marking is a two-layer marking, and when each bit of each layer marking data is used to mark the position of the conflict data in the layer, the first bitmap generating module 303 is specifically configured to execute:
Marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a two-layer graph structure;
And marking whether each data block in the data segment containing the conflict data is the conflict data or not by each bit of second-layer marking data of the two-layer graph structure to obtain the two-layer marking.
Further, when the three-layer bitmap structure is selected, the marking data includes a first layer marking data, a second layer marking data and a third layer marking data, the generated multi-layer marking is a three-layer marking, and when each bit of each layer marking data is used to mark the position of the conflict data in the layer, the first bitmap generating module 303 is specifically configured to execute:
marking whether each data segment in the original data frame contains conflict data or not by each bit of first-layer marking data of a three-layer bitmap structure, wherein each original data frame comprises a plurality of data segments, each data segment comprises a plurality of data small segments, and each data small segment comprises a plurality of data blocks;
marking whether each data segment in the data segments containing the conflict data contains the conflict data or not by each bit of the second layer marking data of the three-layer bitmap structure;
And marking whether each data block in the data small section containing the conflict data is the conflict data or not by each bit of third layer marking data of the three-layer bitmap structure to obtain three-layer marking.
Further, the collision frequency calculation module 302 is specifically configured to perform:
and calculating the ratio of the number of the conflict data to the total data block quantity of the original data frame to obtain the conflict rate of the original data frame.
The device for avoiding the protocol frame header conflict provided by the embodiment of the invention is used for executing the method for avoiding the protocol frame header conflict, so that the same effect as the method for avoiding the protocol frame header conflict can be achieved.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
The embodiment of the invention also provides electronic equipment, which comprises a processor and a memory, wherein at least one instruction, at least one section of program, a code set or an instruction set is stored in the memory, and the at least one instruction, the at least one section of program, the code set or the instruction set is loaded and executed by the processor to realize the method for avoiding the protocol frame header collision in the embodiment of the invention.
The embodiment of the invention also provides a computer readable storage medium, wherein at least one instruction, at least one section of program, code set or instruction set is stored in the storage medium, and the at least one instruction, the at least one section of program, the code set or the instruction set is loaded and executed by a processor to realize the method for avoiding the protocol frame header collision in the embodiment of the invention.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions in accordance with embodiments of the present invention are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.) means from one website, computer, server, or data center. Computer readable storage media can be any available media that can be accessed by a computer or data storage devices, such as servers, data centers, etc., that contain an integration of one or more available media. Usable media may be magnetic media (e.g., floppy disks, hard disks, magnetic tape), optical media (e.g., DVD), or semiconductor media (e.g., solid state disk Solid STATE DISK (SSD)), among others.
The foregoing is merely illustrative of specific embodiments of the present invention, and the scope of the present invention is not limited thereto, but any changes or substitutions within the technical scope of the present invention should be covered by the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.