A data transmission method, device and equipment for smart meters and a medium
By performing semantic recognition and segmented compression on the original messages of smart meters, and using multi-type static dictionaries to distinguish semantic segments and form communication data frames with feature flags, the problems of low data transmission efficiency and poor accuracy of smart meters are solved, and efficient and lossless data transmission is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN STAR INSTR
- Filing Date
- 2026-05-08
- Publication Date
- 2026-06-05
AI Technical Summary
Existing smart meter data transmission methods are not specifically designed for the semantic segment features of the original message, resulting in low compression efficiency, redundant data occupying communication bandwidth, and easy semantic confusion and encoding conflicts, which affect the accuracy of data transmission.
By performing semantic recognition on the original message, a predefined multi-type static dictionary is used to distinguish between identifier segments, numerical segments, unit segments, and status segments. A compression mapping table is then used to perform segmented compression, forming a compressed binary stream, which is then encapsulated into a communication data frame containing feature flags.
It improves the efficiency and accuracy of data transmission, reduces communication bandwidth usage and transmission energy consumption, and ensures data integrity and rapid decompression processing at the receiving end.
Smart Images

Figure CN122160438A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of power data governance, and in particular to a data transmission method, apparatus, device, and medium for smart meters. Background Technology
[0002] With the rapid development of smart grids, smart meters, as the core terminal for data acquisition and transmission, need to transmit raw messages containing identifiers, values, units, status and other information to receiving devices in real time in order to realize the monitoring, measurement and control of electricity consumption data.
[0003] Currently, smart meter data transmission mostly uses general compression methods without being specifically designed for the semantic segment characteristics of the original message. This results in low compression efficiency and a large amount of redundant data occupying limited communication bandwidth. Furthermore, existing transmission methods do not perform semantic recognition and classification processing on the original message, which easily leads to semantic confusion and encoding conflicts, affecting the accuracy and integrity of data transmission.
[0004] Therefore, how to achieve accurate semantic recognition and segmented compression of the original message to improve the efficiency and accuracy of smart meter data transmission has become an urgent problem to be solved. Summary of the Invention
[0005] This application provides a data transmission method, apparatus, computer device, and storage medium for smart meters to address the problem of how to achieve accurate semantic recognition and segmented compression of original messages, thereby improving the efficiency and accuracy of smart meter data transmission.
[0006] A data transmission method for smart meters, the data transmission method being applied to a master station or the meter, wherein data transmission is performed between the master station and the meter, comprising: The characters in the original message to be sent are identified sequentially to obtain at least one semantic segment, wherein the semantic segment is at least one of the following: identifier segment, numerical segment, unit segment, and status segment; For any semantic segment, a corresponding compression mapping table is determined based on the semantic segment. The compression mapping table is used to perform mapping matching on the semantic segment to obtain the corresponding matching result. All semantic segments are traversed to obtain the matching result corresponding to each semantic segment. According to the position of each semantic segment in the original message, the matching results corresponding to each semantic segment are sorted to form a compressed binary stream; The compressed binary stream is encapsulated into a communication data frame containing preset feature flags, and the communication data frame is sent out.
[0007] A data transmission device for smart meters, wherein the data transmission method is applied to a master station or the meter, and data transmission is performed between the master station and the meter, comprising: The identification module is used to sequentially identify the characters in the original message to be sent to obtain at least one semantic segment, wherein the semantic segment is at least one of the following: an identifier segment, a numerical segment, a unit segment, and a status segment. The matching module is used to determine the corresponding compression mapping table for any semantic segment, use the compression mapping table to perform mapping matching on the semantic segment, obtain the corresponding matching result, and traverse all semantic segments to obtain the matching result corresponding to each semantic segment. The generation module is used to sort the matching results corresponding to each semantic segment according to the position of each semantic segment in the original message, and form a compressed binary stream; The encapsulation module is used to encapsulate the compressed binary stream into a communication data frame containing preset feature flags, and to send the communication data frame outward.
[0008] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the aforementioned data transmission method for a smart meter.
[0009] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned data transmission method for smart meters.
[0010] The advantages of this application compared to existing technologies are as follows: This application performs semantic recognition scanning on the original message based on a predefined multi-type static dictionary, accurately distinguishing between identifier segments, numerical segments, unit segments, and status segments, avoiding semantic confusion, providing a precise basis for subsequent segmented compression, and improving the targeting and efficiency of compression. By employing a preset compression strategy to perform segmented collaborative compression on different semantic segments, the redundancy of each semantic segment can be reduced in a targeted manner, significantly reducing the size of the compressed binary stream, saving communication bandwidth, and reducing transmission energy consumption. Encapsulating the compressed binary stream into communication data frames containing feature flags facilitates rapid identification of the decompression strategy by the receiving device, improving the efficiency and accuracy of the restoration process. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of a data transmission method for smart meters according to an embodiment of this application; Figure 2 This is another flowchart of a data transmission method for smart meters according to one embodiment of this application; Figure 3 This is a schematic diagram of a data transmission device for a smart meter according to an embodiment of this application; Figure 4 This is a schematic diagram of a computer device according to one embodiment of this application. Detailed Implementation
[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] In one embodiment, such as Figure 1 As shown, a data transmission method for smart meters is provided. The data transmission method is applied to a master station or a smart meter, and data transmission is performed between the master station and the smart meter.
[0015] The data transmission method for smart meters provided in this embodiment can be applied to either the smart meter terminal or the master station terminal. It enables efficient and lossless data transmission between the smart meter and the master station system in resource-constrained environments (such as NB-IoT, LoRaWAN, and RS-485 bus). The smart meter is deployed on the power user side to collect metering data such as voltage, current, power, and electricity consumption and generate raw messages. The master station system is deployed in the core layer of the power metering automation system to receive, parse, store, and manage the data uploaded by the smart meter, and can also issue control commands to downstream smart meters. Data transmission between the smart meter and the master station system is performed via communication links such as RS-485, power line carrier, NB-IoT, or LoRaWAN. Before transmission, the raw messages undergo semantic recognition, segmentation compression, and frame encapsulation to reduce bandwidth consumption and improve transmission efficiency and parsing accuracy.
[0016] Specifically, the data transmission method for smart meters described in this embodiment includes the following steps: S10, the characters in the original message to be sent are identified sequentially to obtain at least one semantic segment, wherein the semantic segment is at least one of the identifier segment, the numerical segment, the unit segment and the status segment.
[0017] In this embodiment, the original message is plaintext in ASCII format generated by the smart meter according to international distribution wire messaging standards (such as IEC 62056 or IEC 62056-21). It consists of identifiers, values, units, error statuses, etc., and typically includes redundant characters such as OBIS codes, parentheses, decimal points, unit symbols, and separators. Semantic segments refer to character fragments in the original message that have independent business meaning. In this embodiment, semantic segments are divided into four categories: identifier segments, value segments, unit segments, and status segments, corresponding to data object identifiers, metering values, physical units, and equipment abnormality information, respectively.
[0018] Before implementing this method, four sets of static mapping tables need to be fixed on both the sending and receiving parties (electricity meter and master station) as the basis for compression and decompression.
[0019] Specifically, the first group is the OBIS code dictionary, used to map frequently occurring object identifiers to single-byte tokens. The Object Identification System (OBIS) is an encoding system used in the Device Language Message Specification (DLMS) / Companion Specification for Energy Metering (COSEM) protocol to uniquely identify data objects. For example, "1.8.0" represents positive active energy, and "1.7.0" represents instantaneous current. In this embodiment, the token value range of the OBIS code dictionary includes 0x80 to 0xBF; for example, "1.8.0" is mapped to 0x83, and "1.7.0" is mapped to 0x82. In this embodiment, the token is a predefined single-byte code in the dictionary, which is essentially a fixed-length short code obtained by mapping and replacing long strings.
[0020] The second group is a unit dictionary, used to map common units of measurement to single-byte tokens. Common units of measurement include, but are not limited to, "kWh" (kilowatt-hour), "V" (volt), "A" (ampere), and "kW" (kilowatt). In this embodiment, the token values in the unit dictionary range from 0x40 to 0x4F. For example, "kWh" is mapped to 0x40, "V" is mapped to 0x41, and "A" is mapped to 0x42.
[0021] The third group is the error code dictionary, used to map standard error strings to single-byte tokens. Standard error strings include, but are not limited to, "ERR:NOT SUPPORT" (not supported) and "ERR:TIMEOUT" (timeout). In this embodiment, the token values in the error code dictionary range from 0x50 to 0x5E. For example, "ERR:NOT SUPPORT" is mapped to 0x50, and "ERR:TIMEOUT" is mapped to 0x51.
[0022] The fourth group is the control character set, used to define special control bytes. In this embodiment, the control character set includes at least a numeric block start character (such as 0x3B), a general escape character (such as 0xFF), and an escape prefix for marking unknown units or unknown errors. The single-byte encoding ranges corresponding to the OBIS code dictionary, the unit of measurement dictionary, and the error status code dictionary do not overlap to ensure that the decoding end can uniquely determine its type based on the byte value.
[0023] It should be noted that the value ranges of the above-mentioned OBIS code dictionary, unit of measurement dictionary, and error status code dictionary can all be selected and adjusted according to actual needs.
[0024] Of course, to accommodate new OBIS codes, new units of measurement, or new error status codes that may appear in long-term smart meter systems, this application also supports a dynamic dictionary update mechanism. Specifically, dictionary update instructions can be received via, for example, over-the-air (OTA) download or out-of-band communication. The dictionary update instruction includes at least: a dictionary type identifier, indicating whether the target dictionary to be updated is an OBIS code dictionary, a unit of measurement dictionary, an error status code dictionary, or a control character set; an update operation type, indicating whether the operation is incremental addition, replacement, or reset; and update data, providing the specific mapping content for the addition or replacement.
[0025] For example, when a power company introduces a new metering data type and a corresponding new OBIS code "1.8.1", it can issue a dictionary update command via OTA to incrementally add "1.8.1" to the OBIS code dictionary and assign it an unused single-byte token (such as 0x84). For the newly added metering unit "MWh" (megawatt-hour), the unit dictionary can also be expanded incrementally.
[0026] The Replace operation is used to correct existing mapping relationships. For example, when a conflict is found between a token and an existing control character, the value of the token can be adjusted through the Replace operation. The Reset operation is used to restore the dictionary to its factory default state. For example, when the device ownership changes or the system is upgraded, all dynamically added entries are cleared, restoring the dictionary to its initial static state.
[0027] After the dictionary is updated, it needs to be synchronized with the receiving device to ensure consistency between the compressed and decompressed dictionaries. This synchronization can be achieved using a version number mechanism: the sending end carries the current dictionary version number in the compressed message, and the receiving end uses the version number to determine whether an update request is needed, thus ensuring that the dictionaries at both ends are always consistent.
[0028] Optionally, the characters in the original message to be sent are sequentially identified to obtain at least one semantic segment, including: The characters in the original message to be sent are identified sequentially; When a character sequence starting with a number is detected, and the character sequence starting with a number matches the syntax format of the OBIS code in the preset OBIS code dictionary, then the character sequence starting with a number is marked as an identifier field.
[0029] Optionally, the characters in the original message to be sent are sequentially identified to obtain at least one semantic segment, including: The characters in the original message to be sent are identified sequentially; When a preset data block start character is detected, the prefix character of the data block within the data block start character is read based on the preset data block parsing mode, and the error status string in the preset error status code dictionary is read. If the prefix character matches the prefix of the error status string, the data block is determined to be a status segment; If the prefix character is a numeric character and does not match the prefix of the error status string, the data block is determined to be a numeric segment; If the character sequence following the numerical segment matches the syntax format of the unit of measurement in the preset unit of measurement dictionary, the character sequence following the numerical segment is determined to be a unit segment. The single-byte encoding ranges corresponding to the OBIS code dictionary, the unit of measurement dictionary, and the error status code dictionary do not overlap.
[0030] In this embodiment, when recognizing the original message, the message content to be sent is scanned character by character to divide the entire message into semantic segments with independent meanings, which facilitates subsequent segmentation and compression.
[0031] Specifically, during the identification process, if a character sequence beginning with a number is scanned, it is further determined whether the sequence conforms to the OBIS code syntax format. When the character sequence meets the OBIS code format requirements, it is marked as an identifier field to uniquely identify the meter's data object.
[0032] When the preset start character of a data block is detected, the preset data block parsing mode is entered to judge the contents of the data block. First, the prefix character at the beginning of the data block is read and compared with the standard error string prefix in the error status code dictionary.
[0033] If the prefix characters at the beginning of the data block match the prefix of the error string, it indicates that the current data block represents device error information, and it is classified as a status segment. If the prefix characters at the beginning of the data block are all numbers and do not match the prefix of the error string, it indicates that the current data block contains metering values, and it is classified as a numeric segment.
[0034] After identifying the numerical segment, if the character sequence following the numerical segment conforms to the syntax format of the unit dictionary, then this part of the characters is identified as the unit segment, which is used to represent the physical dimension corresponding to the numerical value.
[0035] Meanwhile, to ensure that there is no encoding confusion during compression and decompression, the single-byte encoding ranges corresponding to the OBIS code dictionary, unit of measurement dictionary, and error status code dictionary in this scheme are independent of each other and do not overlap, thus avoiding parsing conflicts structurally.
[0036] S11. For any semantic segment, determine the corresponding compression mapping table based on the semantic segment, use the compression mapping table to perform mapping matching on the semantic segment, obtain the corresponding matching result, traverse all semantic segments, and obtain the matching result corresponding to each semantic segment.
[0037] Optionally, the step of using the compression mapping table to map and match the semantic segments to obtain the corresponding matching results includes: For the identified identifier segment, query the OBIS code dictionary and replace the OBIS code in the identifier segment that matches the OBIS code dictionary with the corresponding single-byte code; For the identified status segment, query the error status code dictionary, and replace the error status string in the status segment that matches the error status code dictionary with the corresponding single-byte code; For the identified numerical segment, based on the total number of digits and the number of decimal places in the numerical segment, metadata bytes in a preset format are generated, and the ASCII format numerical sequence in the numerical segment is converted into compressed BCD code; For the identified unit segment, query the unit of measurement dictionary, and replace the unit of measurement in the unit segment that matches the unit of measurement dictionary with the corresponding single-byte code; Specifically, based on a preset control character set, preset escape operations are performed on identifier segments that do not match the OBIS code dictionary, status segments that do not match the error status code dictionary, and unit segments that do not match the unit of measurement dictionary.
[0038] Specifically, a state machine is used to scan each character of the original message. When a character sequence starting with a number is detected, the state machine first queries the OBIS code dictionary. If the query matches, the character sequence is marked as an identifier field, and the corresponding single-byte token is output; if the query does not match, the character sequence is output as is or an escape operation is performed.
[0039] When a preset data block start character, such as a left parenthesis "()", is detected, the state machine enters data block parsing mode. At this time, the state machine reads the first few characters within the parentheses for type prediction. For example, if the leading character within the parentheses begins with "ERR:", the data block is determined to be a state segment (error state segment), and the error code handling sub-process is initiated. In the error code handling sub-process, the error code dictionary is queried: if a match is found, the corresponding single-byte token is output; if no match is found, the corresponding adaptive encapsulation format of "escape character + length + original text" is used for output.
[0040] If the leading character within the parentheses is a number or a decimal point, the data block is determined to be a numeric segment, and the process enters the numeric processing sub-flow. In this sub-flow, the encoder first extracts the pure numeric sequence and decimal point position within the parentheses, calculating the number of decimal places and the total number of digits (the sum of the integer and decimal parts). Then, metadata bytes are generated. Next, the ASCII-formatted numeric sequence is converted to Binary-Coded Decimal (BCD), compressing every two ASCII numeric characters into one byte. Finally, the separator (such as "*") immediately following the numeric value and the unit string are checked, and the unit dictionary is consulted: if a match is found, the unit token is output, and the separator is implicitly omitted; otherwise, an escape operation is performed. After the numeric segment processing is complete, a right parenthesis is output as the block end marker.
[0041] It should be noted that, in this embodiment, the metadata bytes are used to describe the number of decimal places and the total number of digits in the numerical field to guide the decoding and reconstruction of the BCD stream. To accommodate the precision requirements and numerical ranges in different application scenarios, the metadata bytes of this application support two different bit-width extension modes, specifically including: Single-byte metadata mode: Suitable for typical smart meter reading scenarios. In this mode, the metadata byte occupies 1 byte. The high 4 bits are used to store the number of decimal places in the numerical field, ranging from 0 to 15; the low 4 bits are used to store the total number of digits in the numerical field (the sum of the integer and decimal parts), also ranging from 0 to 15. This mode is suitable for values with a total number of digits not exceeding 15, covering most smart meter reading scenarios. For example, for the value "6040.46", the total number of digits is 6, the decimal part is 2, and the metadata byte is 0x26.
[0042] Double-byte metadata mode: Suitable for extended scenarios involving high precision or large numerical ranges. In this mode, metadata occupies 2 bytes, with the first byte storing the number of decimal places and the second byte storing the total number of digits. This mode supports values with a total number of digits not exceeding 255, meeting the needs of special scenarios such as high-precision power quality data and long-term cumulative values. For example, for ultra-high precision values requiring the recording of 8 integer digits and 6 decimal digits, 0x08 (number of decimal places) can be stored in the first byte, and 0x0E (total number of digits, 14) can be stored in the second byte.
[0043] The selection between single-byte and double-byte metadata modes is indicated by the extension bit of the feature flag in the communication data frame. For example, a fourth bit can be added to the feature flag as a metadata mode indicator: when this bit is 0, it indicates the use of single-byte metadata mode; when this bit is 1, it indicates the use of double-byte metadata mode. When decompressing the numerical segment, the decoding end first reads this extension bit of the feature flag, determines the number of bytes of subsequent metadata bytes based on its value, then parses the decimal places and total number of digits according to the corresponding mode, and then continues to read the BCD stream and perform the restoration operation. Through the above extension mechanism, this application can flexibly adapt to the numerical compression requirements of different precisions and ranges while maintaining lightweight characteristics.
[0044] Of course, if the identifier segment, status segment, or unit segment cannot find a matching entry in the corresponding static dictionary, the original data will not be discarded or tampered with. Instead, the data segment will be encapsulated and transmitted using special escape characters in the control character set according to preset rules. This ensures that the original data can still be safely and completely encapsulated and transmitted even when the semantic segment cannot match the corresponding dictionary, thus avoiding data loss or parsing errors due to an overwritten dictionary.
[0045] Specifically, when the content of the identifier field cannot be matched in the OBIS code dictionary, the content of the status field cannot be matched in the error status code dictionary, and the content of the unit field cannot be matched in the unit of measurement dictionary, a special escape character from the control character set is used as an identifier. The semantic field of the unmatched dictionary is uniformly encapsulated into a format recognizable by the decoding end using a fixed format of "escape prefix + data length + original data". Through escape encapsulation, the dictionary-compressed encoded data and the uncompressed original data can be clearly distinguished, allowing the receiving end to accurately determine the data type during decompression and directly extract the original content for restoration.
[0046] Through the above escaping process, this method can be compatible with custom identifiers, extended units, and new error status information not included in the static dictionary, improving the adaptability, integrity, and fault tolerance of data transmission while ensuring a high compression rate.
[0047] S12, sort the matching results corresponding to each semantic segment according to the position of each semantic segment in the original message to form a compressed binary stream.
[0048] In this embodiment, the compressed binary stream refers to a continuous binary data stream formed by concatenating the compression encoding, escape encoding, numerical metadata, and BCD code of each semantic segment in the order of the original message. The volume of this data stream is significantly smaller than that of the original message, which can improve transmission efficiency.
[0049] S13, the compressed binary stream is encapsulated into a communication data frame containing preset feature flags, and the communication data frame is sent out.
[0050] In this embodiment, the communication data frame is a data encapsulation structure that conforms to the underlying communication link specification, ensuring the integrity and parsability of data transmission. The feature flag is a binary bit field used to mark the compression strategy, indicating which decompression strategy the receiving end should use.
[0051] Specifically, first, a frame header identifier byte is generated. This byte is used to distinguish whether the current data frame is a compressed frame; for example, it can be set to a fixed value of 0x7E. Second, an original length field is generated. This 2-byte field stores the byte length of the original message for integrity verification by the receiving end. Then, a feature flag is generated. This 1-byte flag indicates the corresponding compression strategy. For example, bit 0 being 1 indicates the inclusion of OBIS code dictionary compressed data, bit 1 being 1 indicates the inclusion of unit of measurement dictionary compressed data, bit 2 being 1 indicates the inclusion of error status code dictionary compressed data, bit 3 being 1 indicates the inclusion of BCD compressed numerical segment data, and the remaining bits are reserved for expansion. Finally, the frame header identifier byte, original length field, feature flag, and compressed binary stream are concatenated sequentially to form a communication data frame, which is then transmitted to the receiving end via, for example, an NB-IoT, LoRaWAN, or RS-485 bus.
[0052] It should be noted that, in practical applications, the correspondence between feature flags and compression strategies can be set and adjusted according to actual needs.
[0053] Optionally, the process of using the compressed mapping table to map and match the semantic segments to obtain the corresponding matching results further includes: Get the target bytes to be output; Determine whether the target byte belongs to a preset conflict code set, wherein the conflict code set is the union of all single-byte codes in the OBIS code dictionary, all single-byte codes in the unit of measurement dictionary, all single-byte codes in the error status code dictionary, and all control characters in the control character set; If the target byte does not belong to the conflict code set, the target byte is directly output as the matching result; If the target byte belongs to the conflict encoding set, then the preset general escape characters in the control character set and the target byte are output sequentially as the matching result.
[0054] During compression, if a regular character in the original message happens to conflict with a control byte in the control character set or the value range of any Token in the dictionary, a conflict handling mechanism needs to be executed. Specifically, the target byte to be output is obtained, and it is determined whether the target byte belongs to a preset conflict encoding set. This conflict encoding set is the union of all single-byte encodings in the OBIS code dictionary, all single-byte encodings in the unit of measurement dictionary, all single-byte encodings in the error status code dictionary, and all control characters in the control character set. If the target byte does not belong to this conflict encoding set, it is directly output; if the target byte belongs to this conflict encoding set, the preset general escape character (such as 0xFF) in the control character set is output sequentially, followed by the target byte. During decompression, when the receiving end reads a general escape character, it skips the escape character and directly outputs the byte immediately following it as the original character, without performing any dictionary lookup or compression / decoding operations, thus ensuring the lossless and deterministic nature of the compression process.
[0055] This embodiment performs semantic recognition scanning on the original message based on a predefined multi-type static dictionary, accurately distinguishing between identifier segments, value segments, unit segments, and status segments, avoiding semantic confusion, and providing a precise basis for subsequent segmented compression, thus improving the targeting and efficiency of compression. By employing a preset compression strategy to perform segmented collaborative compression on different semantic segments, the redundancy of each semantic segment can be reduced in a targeted manner, significantly reducing the size of the compressed binary stream, saving communication bandwidth, and reducing transmission energy consumption. The compressed binary stream is encapsulated into communication data frames containing feature flags, facilitating rapid identification of the decompression strategy by the receiving device, improving the efficiency and accuracy of the restoration process.
[0056] In one embodiment, such as Figure 2 As shown, a decompression and restoration method corresponding to the data transmission method for smart meters in the above embodiments is provided.
[0057] The step of encapsulating the compressed binary stream into a communication data frame containing feature flag bits includes: S20, Generate frame header identifier bytes, which are used to distinguish the current data frame as a compressed frame.
[0058] S21, Generate an original length field, which is used to store the byte length of the original message.
[0059] S22, Generate a feature flag bit, which is used to indicate the corresponding compression strategy.
[0060] S23, the frame header identifier byte, the original length field, the feature flag bit and the compressed binary stream are concatenated in sequence to form the communication data frame.
[0061] Specifically, the communication data frame in this embodiment includes a frame header identifier byte, an original length field, and a feature flag. First, a frame header identifier byte is generated. This byte is used to distinguish whether the current data frame is a compressed frame; for example, it can be set to a fixed value of 0x7E. Second, an original length field is generated. This 2-byte field stores the byte length of the original message for integrity verification by the receiving end. Then, a feature flag is generated. This 1-byte flag indicates the corresponding compression strategy. For example, bit 0 being 1 indicates the inclusion of OBIS code dictionary compressed data, bit 1 being 1 indicates the inclusion of unit of measurement dictionary compressed data, bit 2 being 1 indicates the inclusion of error status code dictionary compressed data, bit 3 being 1 indicates the inclusion of BCD compressed numerical segment data, and the remaining bits are reserved for expansion. Finally, the frame header identifier byte, original length field, feature flag, and compressed binary stream are concatenated sequentially to form the communication data frame.
[0062] It should be noted that, in practical applications, the correspondence between feature flags and compression strategies can be set and adjusted according to actual needs.
[0063] Optionally, the data transmission method further includes: Receive message data to be decompressed, and extract a communication data frame to be decompressed from the message data; Parse the frame header identifier byte of the communication data frame. If the frame header identifier byte matches the preset compressed frame identifier, then confirm that the current data frame is a compressed frame. Read the original length field of the communication data frame, determine the expected length of the restored message, and determine the corresponding decompression strategy based on the feature flag bits of the communication data frame; Read all bytes in the compressed binary stream sequentially, perform decompression operation on all bytes based on the compression mapping table and the decompression strategy, and concatenate all strings output after decompression operation in the output order to form the restored complete message; Calculate the byte length of the restored complete message and compare it with the expected length. If they match, the restoration is confirmed to be successful, and the restored complete message is output. If they do not match, a preset length verification failure alarm is triggered.
[0064] Specifically, after receiving the message data to be decompressed, the receiving end first extracts the complete communication data frame from the message, and then segments and parses the data frame to separate the frame header identifier byte, the original length field, the feature flag bit, and the compressed binary stream in sequence.
[0065] First, the frame header identifier byte of the communication data frame is parsed to determine whether it matches the preset compressed frame identifier (e.g., equal to 0x7E). If they match, the current data frame is confirmed to be a compressed frame, and the decompression process corresponding to this application is started. If they do not match, they are processed according to the logic of ordinary plaintext frames to ensure protocol compatibility.
[0066] After confirming that it is a compressed frame, the original length field of the communication data frame is read to determine the expected length of the restored message, and the corresponding decompression strategy is determined according to the characteristic flag bits of the communication data frame.
[0067] Next, all bytes in the compressed binary stream are read sequentially. Based on a preset compression mapping table (i.e., the same OBIS code dictionary, unit of measurement dictionary, error status code dictionary, and control character set as the sender), and in conjunction with a decompression strategy, decompression is performed on all bytes. If the current byte belongs to the single-byte encoding range of the OBIS code dictionary, unit of measurement dictionary, or error status code dictionary, then query the corresponding dictionary, restore the current byte to the corresponding string, and output the string. If the current byte is equal to the start character of the numeric block in the control character set (e.g., 0x3B), then the next byte is read as the metadata byte. The decimal places are parsed from the high 4 bits and the total number of digits are parsed from the low 4 bits. The number of BCD bytes to be read is determined based on the total number of digits. The corresponding number of BCD bytes are read, and each BCD byte is restored to two ASCII digits. A decimal point is inserted at the corresponding position according to the number of decimal places to form the restored numeric string. The unit is then padded according to the unit compression flag in the feature flag bit, and the separator "*" between the number and the unit is added. The restored numeric segment string is then output. If the current byte is equal to a common escape character in the control character set (e.g., 0xFF), then the next byte is read and output directly as the raw ASCII character without performing any dictionary lookup or compression / decoding operations. If the current byte is another character, then output that character directly.
[0068] After the decompression operation, all the strings output are concatenated in the output order to form the restored complete message. Finally, the byte length of the restored complete message is calculated and compared with the previously read expected length: if they match, the restoration is confirmed as successful, and the restored complete message is output; if they do not match, a preset length verification failure alarm is triggered, indicating that data may have been corrupted or lost during transmission. Immediately triggering the preset length verification failure alarm prompts the system to retransmit or handle the anomaly, ensuring the reliability and accuracy of data interaction between the smart meter and the master station system.
[0069] The decompression and restoration method described in this embodiment enables the receiving end to accurately and efficiently restore the compressed communication data frames to the original messages, ensuring the integrity and losslessness of the data throughout the compression-transmission-decompression process. Simultaneously, the feature flag-driven decompression strategy routing mechanism gives the decompression process a clear directionality, avoiding unnecessary computational attempts, improving the receiving end's parsing efficiency, and reducing the gateway's parsing latency and power consumption.
[0070] It should be understood that the sequence number of each step in the above embodiments does not imply 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 this application.
[0071] In one embodiment, a data transmission device for smart meters is provided, which corresponds one-to-one with the data transmission method for smart meters described in the above embodiments. For example... Figure 3 As shown, this data transmission device for smart meters includes an identification module, a matching module, a generation module, and an encapsulation module. Detailed descriptions of each functional module are as follows: A data transmission device for smart meters, wherein the data transmission method is applied to a master station or the meter, and data transmission is performed between the master station and the meter, comprising: The identification module is used to sequentially identify the characters in the original message to be sent to obtain at least one semantic segment, wherein the semantic segment is at least one of the following: an identifier segment, a numerical segment, a unit segment, and a status segment. The matching module is used to determine the corresponding compression mapping table for any semantic segment, use the compression mapping table to perform mapping matching on the semantic segment, obtain the corresponding matching result, and traverse all semantic segments to obtain the matching result corresponding to each semantic segment. The generation module is used to sort the matching results corresponding to each semantic segment according to the position of each semantic segment in the original message, and form a compressed binary stream; The encapsulation module is used to encapsulate the compressed binary stream into a communication data frame containing preset feature flags, and to send the communication data frame outward.
[0072] Optionally, the characters in the original message to be sent are sequentially identified to obtain at least one semantic segment, including: The character recognition module is used to sequentially recognize the characters in the original message to be sent; The identifier segment determination module is used to mark the character sequence starting with a number as an identifier segment when it is detected and the character sequence starting with a number matches the syntax format of the OBIS code in the preset OBIS code dictionary.
[0073] Optionally, the characters in the original message to be sent are sequentially identified to obtain at least one semantic segment, including: The sequential recognition module is used to sequentially recognize the characters in the original message to be sent; The data block parsing module is used to read the prefix characters of the data block within the data block starting character based on the preset data block parsing mode when the preset data block starting character is detected, and to read the error status string in the preset error status code dictionary; The status segment determination module is used to determine that the data block is a status segment if the prefix character is consistent with the prefix of the error status string; The numerical segment determination module is used to determine that the data block is a numerical segment if the prefix character is a numeric character and does not match the prefix of the error status string. The unit segment determination module is used to determine that the character sequence following the numerical segment is a unit segment if the character sequence following the numerical segment matches the syntax format of the unit of measurement in a preset unit of measurement dictionary. The single-byte encoding ranges corresponding to the OBIS code dictionary, the unit of measurement dictionary, and the error status code dictionary do not overlap.
[0074] Optionally, the step of using the compression mapping table to map and match the semantic segments to obtain the corresponding matching results includes: The identifier segment compression module is used to query the OBIS code dictionary for the identified identifier segment and replace the OBIS code in the identifier segment that matches the OBIS code dictionary with the corresponding single-byte code. The status segment compression module is used to query the error status code dictionary for the identified status segment and replace the error status string in the status segment that matches the error status code dictionary with the corresponding single-byte code. The numerical segment compression module is used to generate metadata bytes in a preset format based on the total number of digits and the number of decimal places in the identified numerical segment, and to convert the ASCII format number sequence in the numerical segment into compressed BCD code; The unit segment compression module is used to query the unit dictionary for the identified unit segment and replace the unit of measurement in the unit segment that matches the unit dictionary with the corresponding single-byte encoding. The escape operation module is used to perform preset escape operations based on a preset control character set for identifier segments that do not match the OBIS code dictionary, status segments that do not match the error status code dictionary, and unit segments that do not match the unit of measurement dictionary.
[0075] Optionally, the process of using the compressed mapping table to map and match the semantic segments to obtain the corresponding matching results further includes: The target byte acquisition module is used to acquire the target byte to be output. The judgment module is used to determine whether the target byte belongs to a preset conflict code set, wherein the conflict code set is the union of all single-byte codes in the OBIS code dictionary, all single-byte codes in the unit of measurement dictionary, all single-byte codes in the error status code dictionary, and all control characters in the control character set; The direct output module is used to directly output the target byte as a matching result if the target byte does not belong to the conflict encoding set. The sequential output module is used to sequentially output the preset general escape characters in the control character set and the target byte as the matching result if the target byte belongs to the conflict encoding set.
[0076] Optionally, encapsulating the compressed binary stream into a communication data frame containing feature flags includes: A frame header identifier byte generation module is used to generate frame header identifier bytes, which are used to distinguish the current data frame as a compressed frame; The original length field generation module is used to generate an original length field, which is used to store the byte length of the original message; A feature flag generation module is used to generate feature flags, which are used to indicate the corresponding compression strategy; The splicing module is used to sequentially splice the frame header identifier byte, the original length field, the feature flag bit, and the compressed binary stream to form the communication data frame.
[0077] Optionally, the data transmission method further includes: The receiving module is used to receive message data to be decompressed and extract a communication data frame to be decompressed from the message data. The parsing module is used to parse the frame header identifier byte of the communication data frame. If the frame header identifier byte matches the preset compressed frame identifier, the current data frame is confirmed to be a compressed frame. The determination module is used to read the original length field of the communication data frame, determine the expected length of the restored message, and determine the corresponding decompression strategy based on the characteristic flag bits of the communication data frame. The decompression module is used to read all bytes in the compressed binary stream in sequence, perform decompression operation on all bytes based on the compression mapping table and the decompression strategy, and concatenate all strings output after the decompression operation in the output order to form the restored complete message. The calculation module is used to calculate the byte length of the restored complete message and compare it with the expected length. If they match, the restoration is confirmed to be successful and the restored complete message is output. If they do not match, a preset length verification failure alarm is triggered.
[0078] Specific limitations regarding the data transmission device for smart meters can be found in the limitations on data transmission methods for smart meters described above, and will not be repeated here. Each module in the aforementioned data transmission device for smart meters can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0079] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores data used in the data transmission method for smart meters described in the above embodiments. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a data transmission method for smart meters.
[0080] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the data transmission method for smart meters described in the above embodiments, for example... Figure 1 As shown in S10-S13, or Figure 2 As shown, to avoid repetition, it will not be described again here. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in this embodiment of the data transmission device for smart meters, for example... Figure 3 The functions of the identification module, matching module, generation module, and encapsulation module shown are not described again here to avoid repetition.
[0081] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program implements the data transmission method for smart meters described in the above embodiments, for example... Figure 1 As shown in S10-S13, or Figure 2 As shown, to avoid repetition, it will not be described again here. Alternatively, when the computer program is executed by the processor, it implements the functions of each module / unit in this embodiment of the data transmission device for smart meters, for example... Figure 3 The functions of the identification module, matching module, generation module, and encapsulation module shown are not described again here to avoid repetition.
[0082] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0083] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0084] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A data transmission method for smart meters, characterized in that, The data transmission method is applied to a master station or an electricity meter, and data transmission is performed between the master station and the electricity meter, including: The characters in the original message to be sent are identified sequentially to obtain at least one semantic segment, wherein the semantic segment is at least one of the following: identifier segment, numerical segment, unit segment, and status segment; For any semantic segment, a corresponding compression mapping table is determined based on the semantic segment. The compression mapping table is used to perform mapping matching on the semantic segment to obtain the corresponding matching result. All semantic segments are traversed to obtain the matching result corresponding to each semantic segment. According to the position of each semantic segment in the original message, the matching results corresponding to each semantic segment are sorted to form a compressed binary stream; The compressed binary stream is encapsulated into a communication data frame containing preset feature flags, and the communication data frame is sent out.
2. The data transmission method for smart meters according to claim 1, characterized in that, The characters in the original message to be sent are identified sequentially to obtain at least one semantic segment, including: The characters in the original message to be sent are identified sequentially; When a character sequence starting with a number is detected, and the character sequence starting with a number matches the syntax format of the OBIS code in the preset OBIS code dictionary, then the character sequence starting with a number is marked as an identifier field.
3. The data transmission method for smart meters according to claim 2, characterized in that, The characters in the original message to be sent are identified sequentially to obtain at least one semantic segment, including: The characters in the original message to be sent are identified sequentially; When a preset data block start character is detected, the prefix character of the data block within the data block start character is read based on the preset data block parsing mode, and the error status string in the preset error status code dictionary is read. If the prefix character matches the prefix of the error status string, the data block is determined to be a status segment; If the prefix character is a numeric character and does not match the prefix of the error status string, the data block is determined to be a numeric segment; If the character sequence following the numerical segment matches the syntax format of the unit of measurement in the preset unit of measurement dictionary, the character sequence following the numerical segment is determined to be a unit segment. The single-byte encoding ranges corresponding to the OBIS code dictionary, the unit of measurement dictionary, and the error status code dictionary do not overlap.
4. The data transmission method for smart meters according to claim 3, characterized in that, The step of using the compression mapping table to map and match the semantic segments to obtain the corresponding matching results includes: For the identified identifier segment, query the OBIS code dictionary and replace the OBIS code in the identifier segment that matches the OBIS code dictionary with the corresponding single-byte code; For the identified status segment, query the error status code dictionary, and replace the error status string in the status segment that matches the error status code dictionary with the corresponding single-byte code; For the identified numerical segment, based on the total number of digits and the number of decimal places in the numerical segment, metadata bytes in a preset format are generated, and the ASCII format numerical sequence in the numerical segment is converted into compressed BCD code; For the identified unit segment, query the unit of measurement dictionary, and replace the unit of measurement in the unit segment that matches the unit of measurement dictionary with the corresponding single-byte code; Specifically, based on a preset control character set, preset escape operations are performed on identifier segments that do not match the OBIS code dictionary, status segments that do not match the error status code dictionary, and unit segments that do not match the unit of measurement dictionary.
5. A data transmission method for smart meters according to claim 4, characterized in that, The process of using the compressed mapping table to map and match the semantic segments to obtain the corresponding matching results further includes: Get the target bytes to be output; Determine whether the target byte belongs to a preset conflict code set, wherein the conflict code set is the union of all single-byte codes in the OBIS code dictionary, all single-byte codes in the unit of measurement dictionary, all single-byte codes in the error status code dictionary, and all control characters in the control character set; If the target byte does not belong to the conflict code set, the target byte is directly output as the matching result; If the target byte belongs to the conflict encoding set, then the preset general escape characters in the control character set and the target byte are output sequentially as the matching result.
6. The data transmission method for smart meters according to claim 1, characterized in that, The step of encapsulating the compressed binary stream into a communication data frame containing feature flag bits includes: Generate a frame header identifier byte, which is used to distinguish the current data frame as a compressed frame; Generate an original length field, which is used to store the byte length of the original message; Generate feature flags, which are used to indicate the corresponding compression strategy; The frame header identifier byte, the original length field, the feature flag bit, and the compressed binary stream are concatenated in sequence to form the communication data frame.
7. A data transmission method for smart meters according to any one of claims 1 to 6, characterized in that, The data transmission method further includes: Receive message data to be decompressed, and extract a communication data frame to be decompressed from the message data; Parse the frame header identifier byte of the communication data frame. If the frame header identifier byte matches the preset compressed frame identifier, then confirm that the current data frame is a compressed frame. Read the original length field of the communication data frame, determine the expected length of the restored message, and determine the corresponding decompression strategy based on the feature flag bits of the communication data frame; Read all bytes in the compressed binary stream sequentially, perform decompression operation on all bytes based on the compression mapping table and the decompression strategy, and concatenate all strings output after decompression operation in the output order to form the restored complete message; Calculate the byte length of the restored complete message and compare it with the expected length. If they match, the restoration is confirmed to be successful, and the restored complete message is output. If they do not match, a preset length verification failure alarm is triggered.
8. A data transmission device for smart meters, characterized in that, The data transmission device is applied to a master station or an electricity meter, and data transmission is performed between the master station and the electricity meter, including: The identification module is used to sequentially identify the characters in the original message to be sent to obtain at least one semantic segment, wherein the semantic segment is at least one of the following: an identifier segment, a numerical segment, a unit segment, and a status segment. The matching module is used to determine the corresponding compression mapping table for any semantic segment, use the compression mapping table to perform mapping matching on the semantic segment, obtain the corresponding matching result, and traverse all semantic segments to obtain the matching result corresponding to each semantic segment. The generation module is used to sort the matching results corresponding to each semantic segment according to the position of each semantic segment in the original message, and form a compressed binary stream; The encapsulation module is used to encapsulate the compressed binary stream into a communication data frame containing preset feature flags, and to send the communication data frame outward.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the data transmission method for smart meters as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the data transmission method for smart meters as described in any one of claims 1 to 7.