Data coding method and system, intelligent terminal and storage medium
By identifying the type of data to be encoded and determining the encoding estimate length, the problem of low encoding efficiency in the power scheduling automation system is solved, and fast encoding and efficient data transmission is achieved.
Patent Information
- Application Number
- CN202411259601.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-03-21
AI Technical Summary
In the power scheduling automation system, how to quickly encode big data when the client and server transmit data, improve encoding efficiency and data transmission efficiency.
By obtaining the data to be encoded and identifying its data type, the encoded estimation length is determined according to the data type, including the estimation rules of the basic type and complex type, and finally the data encoding is encoded based on the encoded estimation length.
It realizes fast encoding of big data, improves encoding efficiency and data transmission efficiency, and can quickly determine whether the data to be encoded needs to be processed by frames.
Smart Images

Figure CN119675821A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data communication technology, and in particular to a data encoding method, system, intelligent terminal and storage medium. Background Art
[0002] With the continuous development of the power system, the power dispatching automation system is gradually moving towards intelligence. Data message interaction is carried out in the master station / plant station or client / server structure system of the power dispatching system. Both the client / server ends must serialize and deserialize the network byte stream of the data to be transmitted according to certain agreed rules. This process is generally called the encoding and decoding process.
[0003] When the client and server are transmitting data, how to quickly encode the transmitted big data and improve the encoding efficiency and data transmission efficiency is a problem that needs to be considered at present. Summary of the invention
[0004] The embodiments of the present application provide a data encoding method, system, intelligent terminal and storage medium, which can quickly encode the transmitted big data and improve the encoding efficiency and data transmission efficiency.
[0005] In a first aspect, an embodiment of the present application provides a data encoding method, including:
[0006] Acquire data to be encoded, and identify the data type of the data to be encoded;
[0007] If the data type of the data to be encoded is a basic type, determining the encoding estimation length of the data to be encoded according to a basic type estimation rule;
[0008] If the data type of the data to be encoded is a complex type, obtaining the number and data type of data items in the data to be encoded, and determining the estimated encoding length of the data to be encoded according to the number and data type of the data items;
[0009] Data encoding is performed based on the encoding estimation length of the data to be encoded.
[0010] In a possible implementation manner of the first aspect, the basic type includes a fixed-length type and a non-fixed-length type, and if the data type of the to-be-encoded data is the basic type, determining the encoding estimation length of the to-be-encoded data according to the basic type estimation rule includes:
[0011] If the data type of the data to be encoded is a fixed-length type, determining the estimated encoding length of the data to be encoded according to the encoding length comparison table;
[0012] If the data type of the data to be encoded is a non-fixed-length type, the encoding estimation length of the data to be encoded is determined according to the estimation factor corresponding to the non-fixed-length type.
[0013] In a possible implementation manner of the first aspect, the non-fixed-length type includes a first non-fixed-length type, and the estimation factor includes a default value; if the data type of the to-be-encoded data is a non-fixed-length type, determining the encoding estimation length of the to-be-encoded data according to the estimation factor corresponding to the non-fixed-length type, includes:
[0014] When the data type of the to-be-encoded data is a first non-fixed-length type, obtaining a default value corresponding to the first non-fixed-length type;
[0015] Comparing the data value of the to-be-encoded data with the default value;
[0016] If the value of the data to be encoded is equal to the default value, the estimated encoding length of the data to be encoded is zero;
[0017] If the data value of the data to be encoded is not equal to the default value, the encoding estimated length of the data to be encoded is determined according to the first non-fixed-length type and the default value.
[0018] In a possible implementation manner of the first aspect, the non-fixed-length type includes a second non-fixed-length type, and the estimation factor includes a range constraint; if the data type of the to-be-encoded data is a non-fixed-length type, determining the encoding estimation length of the to-be-encoded data according to the estimation factor corresponding to the non-fixed-length type, includes:
[0019] When the data type of the data to be encoded is a second non-fixed-length type, determining whether the data to be encoded has a value range constraint;
[0020] If there is a value range constraint, determining the estimated encoding length of the data to be encoded according to the encoding length comparison table;
[0021] If the value range constraint does not exist, the estimated encoding length of the data to be encoded is determined according to the second non-fixed-length type.
[0022] In a possible implementation manner of the first aspect, determining the estimated encoding length of the data to be encoded according to the number and data type of the data items includes:
[0023] When the data type of the data item is a complex type, estimating the length of the leading redundancy and the length of the number of data items in the data to be encoded according to the number of the data items;
[0024] Acquire the number and data type of sub-item data in the data item, and determine the estimated encoding length of the data item according to the number and data type of the sub-item data;
[0025] The estimated coding length of the data to be encoded is determined according to the cumulative result of the estimated coding length of each data item in the data to be encoded, the leading redundant length and the length of the number of data items.
[0026] In a possible implementation manner of the first aspect, after determining the estimated encoding length of the data item, the method further includes:
[0027] comparing the estimated encoded length of the data item with a preset data item length threshold;
[0028] If the estimated encoding length of the data item is less than the preset data item length threshold, continue to determine the estimated encoding length of the next data item;
[0029] If the estimated coding length of the data item is greater than or equal to the preset data item length threshold, before continuing to determine the estimated coding length of the next data item, a previous data item of the data item is framed, and the frame mark is used to identify the frame position.
[0030] In a possible implementation manner of the first aspect, the performing data encoding based on the encoding estimation length of the data to be encoded includes:
[0031] If the estimated encoding length of the data to be encoded is greater than the preset encoding length, performing frame processing on the data to be encoded according to the frame marking of the data item in the data to be encoded to obtain frame data of the data to be encoded;
[0032] Data encoding is performed based on the frame data.
[0033] In a second aspect, an embodiment of the present application provides a data encoding system, including:
[0034] A data and type acquisition unit, used to acquire the data to be encoded and identify the data type of the data to be encoded;
[0035] A first length estimation unit, configured to determine the coding estimation length of the data to be encoded according to a basic type estimation rule if the data type of the data to be encoded is a basic type;
[0036] a second length estimation unit, configured to obtain the number and data type of data items in the data to be encoded if the data type of the data to be encoded is a complex type, and determine the estimated encoding length of the data to be encoded according to the number and data type of the data items;
[0037] The data encoding unit is used to perform data encoding based on the encoding estimation length of the data to be encoded.
[0038] In a third aspect, an embodiment of the present application provides an intelligent terminal, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the data encoding method as described in the first aspect above is implemented.
[0039] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the data encoding method as described in the first aspect above is implemented.
[0040] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on a smart terminal, the smart terminal executes the data encoding method as described in the first aspect above.
[0041] In an embodiment of the present application, the intelligent terminal obtains the data to be encoded and identifies the data type of the data to be encoded, determines the estimated encoding length of the data to be encoded according to the data type, and if the data type of the data to be encoded is a basic type, determines the estimated encoding length of the data to be encoded according to the basic type estimation rule, and if the data type of the data to be encoded is a complex type, obtains the number and data type of data items in the data to be encoded, and determines the estimated encoding length of the data to be encoded according to the number and data type of the data items, and finally performs data encoding based on the estimated encoding length of the data to be encoded. The present application selects a suitable estimation method for encoding length estimation according to the adaptability of the data type, which is conducive to improving the accuracy of encoding length estimation, and then performs data encoding on the data to be encoded based on the estimated encoding length, which can quickly determine whether the data to be encoded needs to be framed, thereby improving the efficiency of encoding and data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 is a flow chart of the implementation of the data encoding method provided in the embodiment of the present application;
[0044] Figure 2 It is a specific implementation flow chart of determining the coding estimation length according to the estimation factor in the data coding method provided in the embodiment of the present application;
[0045] Figure 3 It is another specific implementation flow chart of determining the coding estimation length according to the estimation factor in the data encoding method provided in the embodiment of the present application;
[0046] Figure 4 This is a specific implementation flow chart of estimating the encoding estimation length of complex type data to be encoded in the data encoding method provided in the embodiment of the present application;
[0047] Figure 4.1 It is a schematic diagram of the data structure of the read data value service response in the data encoding method provided in the embodiment of the present application;
[0048] Figure 4.2 is a schematic diagram of data constructed in the data encoding method provided in an embodiment of the present application;
[0049] Figure 5 This is a specific implementation flow chart of identifying the frame position in the data encoding method provided in the embodiment of the present application;
[0050] Figure 6 is a structural block diagram of a data encoding system provided in an embodiment of the present application;
[0051] Figure 7 It is a schematic diagram of a smart terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0053] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0054] It should also be understood that the term “and / or” used in the specification and appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0055] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0056] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0057] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0058] The data encoding method provided in the embodiment of the present application can be applied to various types of smart terminals or servers that require data encoding transmission, which can specifically include mobile phones, tablet computers, wearable devices, laptop computers, and desktop computers, etc. The embodiment of the present application does not impose any restrictions on the specific types of smart terminals and servers.
[0059] Figure 1 The implementation process of the data encoding method provided in the embodiment of the present application is shown, and the method flow includes steps S101 to S104. The specific implementation principle of each step is as follows:
[0060] Step S101: Acquire data to be encoded, and identify the data type of the data to be encoded.
[0061] Generally, the data to be encoded is data that needs to be transmitted. The present application solution relies on the DL / T860 communication standard, and the data to be encoded is any data that complies with the communication standard.
[0062] In this embodiment, before transmitting the data, the data to be encoded is obtained and the data type of the data to be encoded is identified. The data type of the data to be encoded can be divided into basic type and complex type, where the basic type refers to the simple data type predefined and built-in in the programming language, which can usually be directly mapped to the underlying hardware representation (such as integers, floating point numbers, characters, etc.) and does not need to be explicitly defined through classes or other structures. Complex type is a data type composed of basic type data in a certain way.
[0063] In the embodiments of the present application, complex types include array types (ARRAY) and structure types (STRUCT). An array type can be understood as a group of data of the same type; a structure type is a new type composed of one or more types combined together. In one embodiment, a type marked with ARRAY or STRUCT is a complex type.
[0064] Step S102: If the data type of the data to be encoded is a basic type, determining the encoding estimation length of the data to be encoded according to a basic type estimation rule.
[0065] The basic type estimation rule is a predefined length estimation rule for basic type data. In this embodiment, the basic type includes a fixed-length type and a non-fixed-length type.
[0066] In this embodiment, if the data type of the data to be encoded is a fixed-length type, the estimated encoding length of the data to be encoded is determined according to a coding length comparison table.
[0067] If the data type of the data to be encoded is a fixed-length type, the byte length after encoding is a fixed length, and the estimated encoding length of the data to be encoded can be directly determined according to the encoding length comparison table. The encoding length comparison table includes the mapping relationship between the data type and the encoding length. That is, the estimated encoding length of the basic type of data to be encoded can be directly estimated by looking up the table.
[0068] If the data type of the data to be encoded is a non-fixed-length type, the byte length after encoding is not fixed, and the encoding estimated length of the data to be encoded is determined according to the estimation factor corresponding to the non-fixed-length type. In this embodiment, the non-fixed-length type is a "special" basic type. The non-fixed-length type includes a first non-fixed-length type and a second non-fixed-length type, and the estimation factor includes a default value and a value range constraint.
[0069] As a possible implementation manner of the present application, the non-fixed-length type includes a first non-fixed-length type, and the estimation factor includes a default value; the first non-fixed-length type is a basic type having a default value.
[0070] like Figure 2As shown, if the data type of the data to be encoded is a non-fixed-length type, the step of determining the encoding estimation length of the data to be encoded according to the estimation factor corresponding to the non-fixed-length type includes:
[0071] a1: When the data type of the to-be-encoded data is a first non-fixed-length type, a default value corresponding to the first non-fixed-length type is obtained. The first non-fixed-length type includes a BOOL type.
[0072] a2: Compare the data value of the data to be encoded with the default value.
[0073] a3: If the value of the data to be encoded is equal to the default value, the estimated encoding length of the data to be encoded is zero.
[0074] a4: If the data value of the data to be encoded is not equal to the default value, the estimated encoding length of the data to be encoded is determined according to the first non-fixed-length type and the default value. Specifically, the estimated encoding length of the data to be encoded is determined according to the byte length corresponding to the default value.
[0075] In this embodiment, some specific basic types can agree on a default value. If these types need to be included in the encoded data, and the data value corresponding to the type is the agreed default value, then this default value does not participate in the compilation, that is, it does not increase the compiled byte length. When the data value corresponding to the type is not the agreed default value, then this default value needs to participate in the compilation, which will increase the compiled byte length. Including the default value as an estimation factor in the estimation of the compiled length can improve the estimation accuracy.
[0076] As a possible implementation manner of the present application, the non-fixed-length type includes a second non-fixed-length type, and the estimation factor includes a value range constraint.
[0077] like Figure 3 As shown, if the data type of the data to be encoded is a non-fixed-length type, the step of determining the encoding estimation length of the data to be encoded according to the estimation factor corresponding to the non-fixed-length type includes:
[0078] b1: When the data type of the data to be encoded is the second non-fixed-length type, determine whether the data to be encoded has a value range constraint. The second non-fixed-length type of data includes integer data, bit string type, and string type. Integer data includes signed and unsigned int8, int16, int32, int64, etc. String types include OCTSRT, VSTR, and UTF8STR.
[0079] b2: If there is a range constraint, the estimated encoding length of the data to be encoded is determined according to the encoding length comparison table.
[0080] b3: If the value range constraint does not exist, determine the estimated encoding length of the data to be encoded according to the second non-fixed-length type.
[0081] In this embodiment, for integer data, the value range can be constrained. In actual use, combined with the classification of bit characteristics, for numbers with clear upper and lower value ranges (maximum and minimum values) boundaries, the number of bytes occupied during encoding is fixed length, otherwise it is indefinite length. The encoding of indefinite length types requires adding a length bit to identify the data length. For example, INT32, its encoding length in ASN.1 PER is 1 byte of length bits plus the minimum occupied bytes required to store the data value. Considering the value range constraints in the encoding length estimation can improve the accuracy of the estimation.
[0082] There is no range constraint for the bit string type and the word string type. In some implementations, if there is no range constraint, the estimated encoding length of the data to be encoded is determined based on the data length placeholder and the data value placeholder.
[0083] Exemplarily, the bit string BITSRT contains three pieces of information: strLen (number of bytes), bitNum (actual number of bits used), str (actual data). This type has no leading quantity in the ASN.1 encoding, so there is no need to add leading redundant control bits; the data length range here is limited to INT8, which is a single byte, and the data value length is (bitNum+8) / 8, then the estimated encoding length of the BITSTR type = sizeof(ST_INT8)+(bitNum+8) / 8, where sizeof() is used to count the spatial byte size of the type; that is, the data length placeholder plus the data value placeholder. The encoding length estimation method of the three strings OCTSRT, VSTR, and UTF8STR is the same, which is similar to the encoding length estimation of the bit string, that is, the data length placeholder plus the data value placeholder.
[0084] In a possible implementation, in the step of determining the estimated encoding length of the data to be encoded based on the first non-fixed-length type and the default value, the influence of the value range constraint of the estimation factor is further taken into account, that is, the estimated encoding length of the data to be encoded is determined based on the first non-fixed-length type, the default value and the value range constraint.
[0085] Step S103: If the data type of the data to be encoded is a complex type, the number and data type of data items in the data to be encoded are obtained, and the estimated encoding length of the data to be encoded is determined according to the number and data type of the data items.
[0086] The complex type of data to be encoded includes multiple data items, and the data items may correspond to different data types. It is impossible to directly determine the estimated encoding length of the complex type of data to be encoded by looking up a table. For example, the data to be encoded includes data item 1 and data item 2, where data item 1 is a basic type and data item 2 is a complex type of data consisting of sub-item data 2.1 and sub-item data 2.2. In this embodiment, the estimated encoding length of the data to be encoded is determined based on the number of data items in the data to be encoded and the data type of each data item.
[0087] As a possible implementation of this application, Figure 4 A specific implementation process of determining the estimated encoding length of the data to be encoded according to the number and data type of the data items in the data encoding method provided in the embodiment of the present application is shown, and is described in detail as follows:
[0088] A1: When the data type of the data item is a complex type, the leading redundancy length and the placeholder length of the number of data items in the data to be encoded are estimated according to the number of the data items.
[0089] Leading redundancy is a bit string used to identify whether optional data items exist in complex types of data to be encoded. The bit length occupied by leading redundancy is the leading redundancy length. The bit length occupied by leading redundancy does not exceed the number of data items. The bit length of the number of data items is the number of bytes required for encoding the number of data items. Leading redundancy is expressed in bits, and the number of bits required to represent the number of data items is the number of bits required to represent the number of data items. For example, 10 data items require 10 bits, which is 2 bytes when converted to bytes, while the bit length of the number of data items only requires one Byte to represent it. The value range that one Byte can represent is [0~255].
[0090] A2: Obtain the number and data type of the sub-item data in the data item, and determine the estimated encoding length of the data item according to the number and data type of the sub-item data. A complex type data item includes a plurality of sub-item data, and the data item types of the sub-item data may be the same or different. For basic type sub-item data.
[0091] A3: Determine the estimated coding length of the data to be encoded based on the cumulative result of the estimated coding length of each data item in the data to be encoded, the leading redundant length, and the length of the number of data items.
[0092] When the sub-item data is of a complex type, the length of the leading redundancy of the sub-item and the length of the number of sub-item data in the data item are estimated according to the number of the sub-item data, the number and data type of the sub-item unit data in the sub-item data are obtained, and the coding estimated length of the sub-item data is determined according to the number and data type of the sub-item unit data, and the coding estimated length of the data item is determined according to the cumulative result of the coding estimated length of each sub-item data in the data item, the length of the leading redundancy of the sub-item and the length of the number of sub-item data. Similarly, when the sub-item unit data in the sub-item data is of a complex type, the coding estimated length of the sub-item data can also be estimated with reference to the above steps A1 to A4.
[0093] Before ASN.1 actually encodes a complex structure, some necessary information of the complex structure will be encoded, including whether the optional data item exists, the number of data items, etc., which will make the number of encoded bytes larger. In this embodiment, when estimating the estimated length of the data to be encoded, the leading redundancy length and the length of the number of data items are included in the estimation factors, which can ensure that the length of some necessary information encoding of the complex structure encoded by ASN.1 can be covered, and the overall estimated length will not be less than the actual encoding length, which can improve the accuracy and effectiveness of the estimation.
[0094] As a possible implementation of the present application, when a data item in the complex type of data to be encoded is of a basic type, the encoding estimation length of the data item is determined according to the basic type estimation rule.
[0095] In this embodiment, when the data type of the data item is a fixed-length type in the basic type, the coding estimated length of the data item is determined according to the coding length comparison table; when the data type of the data item is a non-fixed-length type in the basic type, the coding estimated length of the data item is determined according to the data type of the data item and the estimation factor corresponding to the data type; and then the coding estimated length of the data to be encoded is determined according to the accumulated result of the coding estimated lengths of each data item in the data to be encoded. The specific process of determining the coding estimated length of the data item according to the data type of the data item and the estimation factor corresponding to the data type refers to the specific steps of determining the coding estimated length of the data to be encoded according to the estimation factor corresponding to the non-fixed-length type mentioned above, which will not be repeated here.
[0096] In this embodiment, for the coding length estimation of non-fixed-length data items in the data to be encoded, the estimation factors such as default values and range constraints are taken into consideration, so that the estimation accuracy can be further improved. In actual application, the estimation factors to be included can be selected by configuration in combination with actual needs to achieve finer granularity control.
[0097] For example, the data structure of the read data value service response is as follows: Figure 4.1 As shown, the moreFollows variable is of boolean type, and the default value is TRUE. The data constructed for it is as follows Figure 4.2 , the response data of the read data value service contains two data to be encoded. moreFollows indicates whether there is a subsequent frame, and its type is Boolean. The dataValue type is ARRAY type. The dataValue has a sub-item data stucture. The stucture is a data of STRUCT type. The stucture data contains sub-item unit data of two basic types, namely Boolean type and INT32 integer. The response data of the read data value service is a STRUCT type. The length of the leading redundancy is estimated to be 1 Byte, and the length of the number of data to be encoded is estimated to be 1 Byte. When estimating the length of the data to be encoded, the non-ARRAY type sub-item moreFollows should be estimated first. The Boolean type is estimated to have a length of 1 Byte. The leading redundancy length of the ARRAY array type is estimated to be 1 Byte, the number of data to be encoded of the ARRAY is estimated to have a length of 1 Byte, the leading redundancy length of the STRUCT type is estimated to be 1 Byte, the number of sub-item data of the STRUCT is estimated to have a length of 1 Byte, and the Boolean type is estimated to have a length of 1 Byte. The INT32 type is estimated to have a length of 4 Byte. Therefore, the initial estimated value of the encoding of the response data of the read data value service is: 1+1+1+1+1+1+1+1+4=12Bytes. According to the PER alignment encoding result, the total encoding length is 8Bytes. The moreFollows value is TRUE. At this moment, moreFollows does not participate in the encoding. Its encoding is "00011002 1CC00103". The encoding length has an error of 4Bytes from the initial estimated value. If the moreFollows value is set to FALSE and the other values remain unchanged, and a "00" byte is added, then its encoding is "80011002 1CC00103 00" for a total of 9Bytes. At this time, the error from the initial estimated value of 12Byte without considering the default value is 3Bytes. Furthermore, if the constraint range is taken into account and the original 4Byte estimated length of the INT32 type is corrected to 2Bytes, then the overall estimated value changes from 12Bytes to 10Bytes. At this time, compared with the encoding result when the moreFollows value is set to FALSE, the error is reduced to 1Byte.
[0098] In the embodiment of the present application, by estimating the encoding length of the data to be encoded, a fast and effective framing strategy can be provided when the amount of transmitted data is large.
[0099] Step S104: performing data encoding based on the encoding estimation length of the data to be encoded.
[0100] As an important part of the power automation communication network and system, the substation secondary system communication message specification stipulates the communication service mechanism, defines the data frame format and communication process. After the client and the server establish a TCP connection, they will first initiate the association negotiation service, which stipulates other service parameters such as the maximum length of the application protocol data unit (APDU) and the application service data unit (ASDU). The APDU and ASDU values limit the maximum length of the complete application data frame. If the client and the server have a large amount of data to be transmitted at this time and the number of bytes of the data after ASN.1 encoding exceeds the maximum value of the ASDU agreed by the association negotiation service, then this data needs to be effectively framed at the application layer without destroying the integrity of the data.
[0101] As a possible implementation of this application, Figure 5 A specific implementation process of identifying the frame position in the data encoding method provided in the embodiment of the present application is shown, and is described in detail as follows:
[0102] B1: After determining the estimated coding length of the data item, compare the estimated coding length of the data item with a preset data item length threshold. The preset data item length threshold is ASDUSize agreed upon in negotiation.
[0103] B2: If the estimated encoding length of the data item is less than the preset data item length threshold, continue to determine the estimated encoding length of the next data item;
[0104] B3: If the estimated coding length of the data item is greater than or equal to the preset data item length threshold, then before continuing to determine the estimated coding length of the next data item, the previous data item of the data item is framed, and the frame mark is used to identify the frame position.
[0105] In this embodiment, each time after the coding estimated length of a data item is determined, the coding estimated length needs to be accumulated, and the data item identification index value needs to be increased by 1, and the accumulated value of the coding estimated length is compared with the negotiated ASDUSize size. If the accumulated value is less than ASDUSize, the coding estimated length of the next data item is determined. If the accumulated value is greater than ASDUSize, it is considered that the length of the data after encoding exceeds ASDUSize, and the data to be encoded needs to be framed. After the previous data item of the data item is framed, the data item identification index value needs to be reduced by one. Because the length of the data after encoding at the last index position is closest to ASDUSize, the framing position of the data can be determined based on the framing mark.
[0106] In an embodiment of the present application, if the estimated coding length of the data to be encoded is greater than the preset coding length, the data to be encoded can be directly framed according to the frame marks of the data items in the data to be encoded to obtain the frame data of the data to be encoded, thereby achieving fast frame processing, and then data encoding is performed based on the frame data, which can improve the encoding efficiency and data transmission efficiency.
[0107] In this embodiment, the real-time coding length can be estimated and the frame position can be determined simultaneously when the data structure of the data to be encoded is traversed once. When the amount of data is too large, the frame processing can be quickly implemented, which is beneficial to reduce the number of frame divisions and improve coding efficiency and data transmission efficiency.
[0108] In some implementations, the real-time estimated value and the frame mark in the estimation process are temporarily stored and released after the coding estimation length estimation is completed. No resident space is required and the storage space occupancy rate is low.
[0109] In one possible implementation, if the estimated length of the data to be encoded is greater than the preset encoding length and the data to be encoded cannot be framed, the data to be encoded is discarded; and a discard notification is sent to the sender of the data to be encoded, informing the sender that the data to be encoded cannot be encoded and sent.
[0110] As can be seen from the above, in the embodiment of the present application, selecting a suitable estimation method to estimate the coding length according to the adaptability of the data type is beneficial to improving the accuracy of the coding length estimation. Then, data encoding is performed on the data to be encoded based on the coding estimation length, and whether the data to be encoded needs to be framed can be quickly determined, thereby improving the coding efficiency and data transmission efficiency.
[0111] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0112] Corresponding to the data encoding method described in the above embodiment, Figure 6 A structural block diagram of a data encoding system provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0113] Reference Figure 6 The data encoding system comprises: a data and type acquisition unit 61, a first length estimation unit 62, a second length estimation unit 63, and a data encoding unit 64, wherein:
[0114] The data and type acquisition unit 61 is used to acquire the data to be encoded and identify the data type of the data to be encoded;
[0115] A first length estimation unit 62, configured to determine the coding estimation length of the data to be encoded according to a basic type estimation rule if the data type of the data to be encoded is a basic type;
[0116] A second length estimation unit 63 is used to obtain the number and data type of data items in the data to be encoded if the data type of the data to be encoded is a complex type, and determine the encoding estimation length of the data to be encoded according to the number and data type of the data items;
[0117] The data encoding unit 64 is used to perform data encoding based on the encoding estimation length of the data to be encoded.
[0118] As a possible implementation of the present application, the basic type includes a fixed-length type and a non-fixed-length type, and the first length estimation unit 62 includes:
[0119] A first length estimation module, configured to determine the estimated encoding length of the data to be encoded according to an encoding length comparison table if the data type of the data to be encoded is a fixed-length type;
[0120] The second length estimation module is used to determine the coding estimation length of the data to be encoded according to the estimation factor corresponding to the non-fixed length type if the data type of the data to be encoded is a non-fixed length type.
[0121] As a possible implementation manner of the present application, the non-fixed length type includes a first non-fixed length type, and the estimation factor includes a default value; the second length estimation module is specifically used for:
[0122] When the data type of the to-be-encoded data is a first non-fixed-length type, obtaining a default value corresponding to the first non-fixed-length type;
[0123] Comparing the data value of the to-be-encoded data with the default value;
[0124] If the value of the data to be encoded is equal to the default value, the estimated encoding length of the data to be encoded is zero;
[0125] If the data value of the data to be encoded is not equal to the default value, the encoding estimated length of the data to be encoded is determined according to the first non-fixed-length type and the default value.
[0126] As a possible implementation manner of the present application, the non-fixed length type includes a second non-fixed length type, and the estimation factor includes a range constraint; the second length estimation module is specifically used for:
[0127] When the data type of the data to be encoded is a second non-fixed-length type, determining whether the data to be encoded has a value range constraint;
[0128] If there is a value range constraint, determining the estimated encoding length of the data to be encoded according to the encoding length comparison table;
[0129] If the value range constraint does not exist, the estimated encoding length of the data to be encoded is determined according to the second non-fixed-length type.
[0130] As a possible implementation manner of the present application, the second length estimation unit 63 includes:
[0131] A first estimation module, configured to estimate the length of the leading redundancy and the length of the number of data items in the data to be encoded according to the number of the data items when the data type of the data item is a complex type;
[0132] A second estimation module, used for obtaining the number and data type of sub-item data in the data item, and determining the estimated encoding length of the data item according to the number and data type of the sub-item data;
[0133] The third length estimation module is used to determine the estimated coding length of the data to be encoded based on the cumulative result of the estimated coding length of each data item in the data to be encoded, the leading redundancy length and the occupancy length of the number of data items.
[0134] As a possible implementation of the present application, the above data encoding system further includes:
[0135] A comparison marking unit is used to compare the coding estimated length of the data item with a preset data item length threshold; if the coding estimated length of the data item is less than the preset data item length threshold, then continue to determine the coding estimated length of the next data item; if the coding estimated length of the data item is greater than or equal to the preset data item length threshold, then before continuing to determine the coding estimated length of the next data item, the previous data item of the data item is frame marked, and the frame mark is used to identify the frame position.
[0136] As a possible implementation of the present application, the data encoding unit 64 includes:
[0137] A frame processing module, configured to perform frame processing on the data to be encoded according to the frame marking of the data item in the data to be encoded, if the estimated encoding length of the data to be encoded is greater than the preset encoding length, to obtain frame data of the data to be encoded;
[0138] The encoding module is used to perform data encoding based on the frame data.
[0139] As can be seen from the above, in the embodiment of the present application, selecting a suitable estimation method to estimate the coding length according to the adaptability of the data type is beneficial to improving the accuracy of the coding length estimation. Then, data encoding is performed on the data to be encoded based on the coding estimation length, and whether the data to be encoded needs to be framed can be quickly determined, thereby improving the coding efficiency and data transmission efficiency.
[0140] It should be noted that the information interaction, execution process, etc. between the above-mentioned systems / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0141] The present application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, Figures 1 to 5 The steps of any data encoding method represented.
[0142] The embodiment of the present application also provides an intelligent terminal, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the following is achieved: Figures 1 to 5 The steps of any data encoding method represented.
[0143] The embodiment of the present application also provides a computer program product, when the computer program product is run on a smart terminal, the smart terminal executes the following Figures 1 to 5 The steps of any data encoding method represented.
[0144] Figure 7 is a schematic diagram of a smart terminal provided by an embodiment of the present application. Figure 7 As shown, the intelligent terminal 7 of this embodiment includes: a processor 70, a memory 71, and a computer program 72 stored in the memory 71 and executable on the processor 70. When the processor 70 executes the computer program 72, the steps in the above-mentioned data encoding method embodiments are implemented, for example Figure 1 Alternatively, when the processor 70 executes the computer program 72, the functions of each module / unit in the above-mentioned system embodiments are realized, for example Figure 6 The functions of units 61 to 64 are shown.
[0145] Exemplarily, the computer program 72 may be divided into one or more modules / units, which are stored in the memory 71 and executed by the processor 70 to complete the present application. The one or more modules / units may be a series of computer-readable instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 72 in the smart terminal 7.
[0146] The intelligent terminal 7 may include, but is not limited to, a processor 70 and a memory 71. Those skilled in the art will appreciate that Figure 7 It is only an example of the intelligent terminal 7 and does not constitute a limitation on the intelligent terminal 7. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the intelligent terminal 7 may also include input and output devices, network access devices, buses, etc.
[0147] The processor 70 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0148] The memory 71 may be an internal storage unit of the intelligent terminal 7, such as a hard disk or memory of the intelligent terminal 7. The memory 71 may also be an external storage device of the intelligent terminal 7, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the intelligent terminal 7. Further, the memory 71 may also include both an internal storage unit and an external storage device of the intelligent terminal 7. The memory 71 is used to store the computer program and other programs and data required by the intelligent terminal. The memory 71 may also be used to temporarily store data that has been output or is to be output.
[0149] It should be noted that the information interaction, execution process, etc. between the above-mentioned systems / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0150] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0151] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or system that can carry the computer program code to the system / terminal device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0152] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0153] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A data encoding method, characterized in that: include: Acquire data to be encoded, and identify the data type of the data to be encoded; If the data type of the data to be encoded is a basic type, determining the encoding estimation length of the data to be encoded according to a basic type estimation rule; If the data type of the data to be encoded is a complex type, obtaining the number and data type of data items in the data to be encoded, and determining the estimated encoding length of the data to be encoded according to the number and data type of the data items; Data encoding is performed based on the encoding estimation length of the data to be encoded.
2. The method according to claim 1, characterized in that: The basic type includes a fixed-length type and a non-fixed-length type. If the data type of the data to be encoded is the basic type, determining the encoding estimation length of the data to be encoded according to the basic type estimation rule includes: If the data type of the data to be encoded is a fixed-length type, determining the estimated encoding length of the data to be encoded according to the encoding length comparison table; If the data type of the data to be encoded is a non-fixed-length type, the encoding estimation length of the data to be encoded is determined according to the estimation factor corresponding to the non-fixed-length type.
3. The method according to claim 2, characterized in that The non-fixed length type includes a first non-fixed length type, and the estimation factor includes a default value; if the data type of the to-be-encoded data is a non-fixed length type, determining the encoding estimation length of the to-be-encoded data according to the estimation factor corresponding to the non-fixed length type, including: When the data type of the to-be-encoded data is a first non-fixed-length type, obtaining a default value corresponding to the first non-fixed-length type; Comparing the data value of the to-be-encoded data with the default value; If the value of the data to be encoded is equal to the default value, the estimated encoding length of the data to be encoded is zero; If the data value of the data to be encoded is not equal to the default value, the encoding estimated length of the data to be encoded is determined according to the first non-fixed-length type and the default value.
4. The method according to claim 2, characterized in that: The non-fixed length type includes a second non-fixed length type, and the estimation factor includes a range constraint; if the data type of the to-be-encoded data is a non-fixed length type, determining the encoding estimation length of the to-be-encoded data according to the estimation factor corresponding to the non-fixed length type, comprises: When the data type of the data to be encoded is a second non-fixed-length type, determining whether the data to be encoded has a value range constraint; If there is a value range constraint, determining the estimated encoding length of the data to be encoded according to the encoding length comparison table; If the value range constraint does not exist, the estimated encoding length of the data to be encoded is determined according to the second non-fixed-length type.
5. The method according to claim 1, characterized in that: Determining the estimated encoding length of the data to be encoded according to the number and data type of the data items includes: When the data type of the data item is a complex type, estimating the length of the leading redundancy and the length of the number of data items in the data to be encoded according to the number of the data items; Acquire the number and data type of sub-item data in the data item, and determine the estimated encoding length of the data item according to the number and data type of the sub-item data; The estimated coding length of the data to be encoded is determined based on the cumulative result of the estimated coding length of each data item in the data to be encoded, the leading redundant length, and the length of the number of data items.
6. The method according to claim 5, characterized in that After determining the estimated encoding length of the data item, the method further comprises: comparing the estimated encoded length of the data item with a preset data item length threshold; If the estimated encoding length of the data item is less than the preset data item length threshold, continue to determine the estimated encoding length of the next data item; If the estimated coding length of the data item is greater than or equal to the preset data item length threshold, then before continuing to determine the estimated coding length of the next data item, a previous data item of the data item is framed, and the frame mark is used to identify the frame position.
7. The method according to claim 6, characterized in that The data encoding based on the encoding estimation length of the data to be encoded includes: If the estimated encoding length of the data to be encoded is greater than the preset encoding length, performing frame processing on the data to be encoded according to the frame marking of the data item in the data to be encoded to obtain frame data of the data to be encoded; Data encoding is performed based on the frame data.
8. A data encoding system, characterized in that: include: A data and type acquisition unit, used to acquire the data to be encoded and identify the data type of the data to be encoded; A first length estimation unit, configured to determine the coding estimation length of the data to be encoded according to a basic type estimation rule if the data type of the data to be encoded is a basic type; a second length estimation unit, configured to obtain the number and data type of data items in the data to be encoded if the data type of the data to be encoded is a complex type, and determine the estimated encoding length of the data to be encoded according to the number and data type of the data items; The data encoding unit is used to perform data encoding based on the encoding estimation length of the data to be encoded.
9. An intelligent terminal, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the data encoding method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data encoding method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Laboratory data transmission method, device and system based on Internet of Things, and storage medium
CN120567896A