CN115334175A - Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium - Google Patents

Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium Download PDF

Info

Publication number
CN115334175A
CN115334175A CN202211112281.0A CN202211112281A CN115334175A CN 115334175 A CN115334175 A CN 115334175A CN 202211112281 A CN202211112281 A CN 202211112281A CN 115334175 A CN115334175 A CN 115334175A
Authority
CN
China
Prior art keywords
data packet
current
length
protocol
total consumption
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202211112281.0A
Other languages
Chinese (zh)
Other versions
CN115334175B (en
Inventor
易成林
丁振
陈凡
洪雨婷
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Zhengtai Iot Technology Co ltd
Original Assignee
Zhejiang Zhengtai Iot Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Zhengtai Iot Technology Co ltd filed Critical Zhejiang Zhengtai Iot Technology Co ltd
Priority to CN202211112281.0A priority Critical patent/CN115334175B/en
Publication of CN115334175A publication Critical patent/CN115334175A/en
Application granted granted Critical
Publication of CN115334175B publication Critical patent/CN115334175B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/14Multichannel or multilink protocols
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/12Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/08Protocols for interworking; Protocol conversion
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiment of the invention discloses a multi-protocol self-adaptive analysis method, an Internet of things metering device, equipment and a medium. The method is applied to the metering device of the Internet of things, the metering device of the Internet of things supports various communication protocols, and the method comprises the following steps: taking out a current data packet from a receiving buffer or a receiving message queue based on a first-in first-out mode; traversing and matching the extracted current data packet with a plurality of communication protocols to obtain the communication protocol type satisfied by the current data packet, and generating a corresponding reply data packet according to the communication protocol type; transmitting the reply data packet to a sending buffer area corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer area; and continuously taking out the next data packet to analyze again until all the data packets are analyzed. The invention can automatically distinguish the communication protocol types and match the replies when receiving the data packet, thereby reducing the interruption time and improving the communication efficiency.

Description

Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium
Technical Field
The invention relates to the technical field of communication, in particular to a multi-protocol self-adaptive analysis method, an internet of things metering device, equipment and a medium.
Background
With the development of the electric energy meter industry, the demand for communication protocols is more and more diversified. The communication protocol used in the field of electric meter application is typically Modbus protocol, which is a general-purpose language applied to electronic controllers, and in the field of power distribution, the DL645 protocol and the DL698 protocol are also commonly used communication protocols.
The existing electric meter comprises a mounting type electric meter digital display electric meter and a guide rail type electric meter. However, the mounting type electric meter digital display electric meter supports a Modbus protocol, and the guide rail type electric meter supports a DL645 protocol or a Modbus protocol. If the communication protocol needs to be switched, the protocol needs to be switched through modes such as communication or display key and the like. This results in a need for a commissioning worker to operate the switching protocol during field installation and commissioning.
At present, in the field of internet of things, besides a wired RS485 connection mode, data interaction in a wireless mode and an ethernet mode is more and more, transparent transmission Modbus protocols, DL645 protocols and DL698 protocols are adopted, and a plurality of application scenarios exist, but at present, electric meters for adaptively switching the Modbus protocols, the DL645 protocols and the DL698 protocols are basically absent. That is, the related art needs field switching or an electric meter product supporting a plurality of communication protocol types to be applicable to the corresponding field.
Disclosure of Invention
The embodiment of the invention provides a multi-protocol self-adaptive analysis method, an Internet of things metering device, equipment and a medium.
In a first aspect, to achieve the above object, an embodiment of the present invention provides a multi-protocol adaptive parsing method applied to an internet of things metering device, where the internet of things metering device supports multiple communication protocols, and the method includes:
taking out a current data packet from a receiving buffer or a receiving message queue based on a first-in first-out mode;
traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
transmitting the reply data packet to a sending buffer corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer;
and continuously taking out the next data packet to perform analysis again until all the data packets are analyzed.
In a second aspect, to solve the same technical problem, an embodiment of the present invention provides an internet of things metering device, which supports multiple communication protocols, and includes:
the data taking module is used for taking out a current data packet from the receiving buffer area or the receiving message queue based on a first-in first-out mode;
the matching processing module is used for performing traversal matching on the extracted current data packet and the multiple communication protocols, obtaining the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
the data transmission module is used for transmitting the reply data packet to a sending buffer area corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer area;
and the data taking module is also used for continuously taking out the next data packet to analyze again until all the data packets are analyzed.
In a third aspect, to solve the same technical problem, an embodiment of the present invention provides an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, where the memory is coupled to the processor, and the processor implements the steps in the multi-protocol adaptive parsing method when executing the computer program.
In a fourth aspect, to solve the same technical problem, an embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored, where the computer program, when running, controls a device in which the computer-readable storage medium is located to perform the steps in the multi-protocol adaptive parsing method.
The embodiment of the invention provides a multi-protocol self-adaptive analysis method, an Internet of things metering device, equipment and a medium.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flow chart of an adaptive parsing method for multiple protocols according to an embodiment of the present invention;
fig. 2 is a schematic internal structural diagram of an internet of things metering device provided by an embodiment of the invention;
fig. 3 is another schematic flowchart of a multi-protocol adaptive parsing method according to an embodiment of the present invention;
fig. 4 is another schematic flowchart of a multi-protocol adaptive parsing method according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. It should be apparent that the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the description of the present application, it is to be understood that the terms "one end", "the other end", and the like, indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience in describing the present application and simplifying the description, but do not indicate or imply that the referred device or element must have a specific orientation, be constructed in a specific orientation, and be operated, and thus, should not be construed as limiting the present application. Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the described features. In the description of the present application, "a plurality" means two or more unless specifically limited otherwise.
In the description of the present application, it is to be noted that, unless otherwise explicitly specified or limited, the terms "connected" and "connected" are to be interpreted broadly, e.g., as being either fixedly connected, detachably connected, or integrally connected; may be mechanically connected, may be electrically connected or may be in communication with each other; they may be directly connected or indirectly connected through intervening media, or may be connected through the use of two elements or the interaction of two elements. The specific meaning of the above terms in the present application can be understood by those of ordinary skill in the art as appropriate.
The following disclosure provides many different embodiments or examples for implementing different features of the application. In order to simplify the disclosure of the present application, specific example components and arrangements are described below. Of course, they are merely examples and are not intended to limit the present application. Further, the present application may repeat reference numerals and/or reference letters in the various examples for simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or arrangements discussed. In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
Referring to fig. 1, an embodiment of the present application provides a multi-protocol adaptive parsing method applied to an internet of things metering device, where the internet of things metering device supports multiple communication protocols, and the method includes the steps of:
s101, taking out a current data packet from a receiving buffer area or a receiving message queue based on a first-in first-out mode;
specifically, the FIFO may also be referred to as a First-in First-out FIFO (abbreviation of First Input First Output), which is an in-order execution method, that is, data packets are put into a queue according to the sequence in which the data packets arrive at a receiving interface of a receiving end, and meanwhile, the FIFO puts the data packets out of the queue according to the sequence of the data packets in the queue, the First-in data packets are dequeued First, and the second-in data packets are dequeued later. The receiving end stores the received data packet in a received message queue (belonging to a FIFO queue) or a receiving buffer. If the receiving end stores the received data packets in the message receiving queue, the data packet No. 0 is added into the queue first, then the data packet No. 1 and the data packet No. 2 are \8230, and \8230, then the data packet No. 0 is taken out from the message receiving queue, and at the moment, the data packet No. 1 replaces the position of the instruction No. 0 to wait for being read, and similarly, the data packet No. 2 and the data packet No. 3 are \8230and \8230, and all the data packets are moved forward one position to wait for being read in sequence. If the receiving end stores the received data packet in the receiving buffer area, the data packets stored in the receiving buffer area correspond to respective receiving time, so that the No. 0 data packet, the No. 1 data packet, the No. 2 data packet and the No. 3 data packet \8230, can be sequentially taken out from the receiving buffer area according to the sequence of the receiving time. Therefore, the current packet refers to a packet taken out according to the sequence of the receiving time, for example, if the taken out packet No. 0 is the current packet, the packet No. 1 is the next packet, if the taken out packet No. 1 is the current packet, the packet No. 2 is the next packet, and so on.
The identity type of the metering device of the Internet of things can be a receiving end or a transmitting end. The utility model provides a thing networking metering device includes multiple communication interface, and communication interface both can receive the data package from the sending end, also can send data package to other receiving terminals. The communication interface comprises any one or more of a serial port interface (comprising an RS485 interface, an RS232 interface, a UART interface and the like), a WIFI interface and an Ethernet interface, the type of the communication interface comprises a serial port type and a non-serial port type, and the non-serial port type comprises a WIFI type and an Ethernet type. If the communication interface used for receiving data in the receiving end is a serial port type including an RS485 interface, an RS232 interface, a UART interface and the like), extracting the data packet received by the communication interface from the transmitting end, and storing the data packet into a receiving buffer area in the receiving end. If the communication interface used for receiving data in the receiving end is of a non-serial port type, extracting the data packet received by the communication interface from the sending end, storing the data packet into a receiving buffer area, and then taking out the data packet from the receiving buffer area according to a first-in first-out mode and putting the data packet into a received message queue.
Under the condition that the type of the communication interface is a serial port type, whether a data packet is completely received or not is judged when the data is received in a serial port mode, namely the serial port mode can adopt a frame gap mode, and multi-frame data is stored into an analysis buffer area together, namely the analysis buffer area can take out one data packet from the receiving buffer area in a frame gap mode according to a first-in first-out principle in multiple times as a current data packet.
In the case that the type of the communication interface is a non-serial port type (e.g., WIFI or ethernet), although a frame of data packets is received in a wireless mode (i.e., WIFI mode) and an ethernet mode, the analysis buffer may also take out one data packet from the reception buffer in a frame gap mode in a first-in first-out manner as the current data packet. However, it may happen that the data packet is received in a wireless manner (i.e., in a WIFI manner) and in an ethernet manner relatively quickly, and the current data packet is not yet analyzed and is completely analyzed, and a new data packet arrives, thereby causing a data packet loss. Therefore, after receiving and storing the data packets in the receiving buffer area in a wireless mode (i.e., a WIFI mode) and an ethernet mode, the parsing buffer area takes out the data packets from the receiving buffer area in a first-in first-out mode and puts the data packets into the receiving message queue in a message queue adding mode. Therefore, a buffer can be added for analyzing data and receiving data through the message queue, and received data packets can be ensured to be analyzed subsequently.
S102, traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
s103, transmitting the reply data packet to a sending buffer corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer;
s104, continuously taking out the next data packet to analyze again until all the data packets are analyzed.
Specifically, after a current data packet is taken out from the receiving buffer or the receiving message queue by the parsing buffer in a first-in first-out manner, the current data packet is input to the adaptive consumption module by the parsing buffer, the current data packet is sequentially input to the corresponding parsing modules by the adaptive consumption module according to the order of the protocol importance degrees, that is, the adaptive consumption module sequentially and circularly calls the corresponding parsing modules according to the order of the protocol importance degrees to parse the current data packet to judge the communication protocol type satisfied by the current data packet, and the corresponding reply data packet is generated by the parsing module corresponding to the current communication protocol type until all correct data packets are parsed. In each round of analysis process, each analysis module generates a corresponding reply data packet according to the respective communication protocol type. Then, the analysis module transfers the reply data packet to the corresponding sending buffer area according to the communication protocol type, and the communication interface correspondingly connected with the sending buffer area sends out the reply data packet.
Referring to fig. 2 and fig. 3, fig. 3 is a schematic diagram of an internal structure of an internet of things metering device, where the internet of things metering device includes parsing modules corresponding to the multiple communication protocols, and fig. 2 is a schematic diagram of a flow of traversing and matching the extracted current data packet with the multiple communication protocols, obtaining a communication protocol type satisfied by the current data packet, and generating a corresponding reply data packet according to the communication protocol type, including steps;
s301, setting an initial residual length (n) equal to the length information of the current data packet, and setting an initial current total consumption length (mt) equal to a first set value (0);
specifically, the multiple communication protocols include a Modbus protocol, a DL645 protocol, and a DL698 protocol, and as shown in fig. 3, the metering device of the internet of things includes three kinds of parsing modules, namely, a ModbusRTU parsing module, a DL645 parsing module, and a DL698 parsing module. The preset protocol importance degree sequence is a Modbus protocol, a DL645 protocol and a DL698 protocol.
As shown in fig. 3, the metering device is composed of a communication interface receiving buffer, a message queue, an analysis buffer, a self-adaptive consumption residue judgment logic module, a ModbusRTU analysis module, a DL645-2007 analysis module, a DL698.45 analysis module, and a communication interface sending buffer, and further includes a metering module for measuring an electric quantity parameter and a statistical electric quantity parameter in the power grid; the communication mode of the metering device comprises a serial port mode, a wireless mode and an Ethernet mode. The received communication data enters the communication interface receiving buffer zone after passing through the interfaces. The serial port judges whether a data packet is completely received or not, and judges through the frame gap. The wireless mode and the Ethernet mode can directly read the receiving buffer when receiving a frame of data. However, probably because the received data packet is faster, the message queue is added for analyzing the data and buffering the received data, so as to prevent the data packet from being lost because the analysis is not completed and a new data packet arrives. The message queue mode presses the received data packets into the message queue to ensure that the received data packets can be analyzed subsequently, and adopts a first-in first-out mode to obtain the received data packets and analyze each data packet. Then the analysis buffer zone will take a data packet from the communication interface buffer zone or the message queue of the serial port, and enter the self-adaptive consumption residual judgment logic module. The adaptive consumption module circularly calls the ModbusRTU analysis module, the DL645 analysis module and the DL698 analysis module to analyze the data frames until all correct data frames are analyzed. In the process of each round of analysis, each analysis module can produce a sending frame, send the sending frame to a communication interface sending buffer area and send data out.
S302, judging whether the first sum of the initial current total consumption length and a second set value (6) is greater than the initial residual length;
specifically, when the modbusRTU analysis module, the DL645 analysis module, and the DL698 analysis module analyze, a data packet is copied to the analysis buffer, and the final analysis is performed by using a complete data packet regardless of serial port reception or wireless or Ethernet, and the length of the data packet is set to be n. The total consumption length mt is set to 0. Before each analysis, a condition is determined, namely whether mt +6 is larger than n.
S303, if the first sum is larger than the initial residual length, the self-adaptive analysis of the current data packet is exited and the next data packet is switched and analyzed;
s304, if the first sum is not larger than the initial residual length, calling a current analysis module according to the sequence of the protocol importance degree to judge whether the current data packet meets a reply condition corresponding to the current communication protocol type;
s305, if the current data packet meets the reply condition corresponding to the current communication protocol type, generating a reply data packet corresponding to the current data packet, and updating the latest total consumption length to the sum of the previous total consumption length and the current total consumption length;
s306, if the current data packet does not accord with the reply condition corresponding to the current communication protocol type, switching and calling the next analysis module according to the protocol importance degree sequence to continue judging until the protocol type corresponding to the current data packet is determined or all the analysis modules finish one round of analysis and do not obtain the protocol type.
Specifically, the method works in main loop, each communication protocol type has a data pointer pointing to a receiving buffer area, the adaptive consumption surplus judgment logic module continuously searches for a conforming protocol frame backwards in a first-in first-out loop mode according to the data pointers, and sequentially and circularly calls the corresponding analysis modules to analyze and judge the communication protocol type met by the current data packet according to the protocol importance degree sequence, namely the sequence of the ModbusRTU analysis module → the DL645 analysis module → the DL698 analysis module, and the analysis modules corresponding to the current communication protocol type generate corresponding reply data packets until all the data packets are analyzed. Assuming that the DL645 parsing module is a DL645-2007 parsing module and the DL698 parsing module is a DL698.45 parsing module in this embodiment, the communication protocol type satisfied by the current packet is parsed and determined according to the sequence of protocol importance, i.e., modbusRTU parsing module → DL645-2007 parsing module → DL698.45 parsing module, until all packets are parsed, wherein each parsing module will produce a transmission frame in each round of parsing process, and send the transmission frame to the communication interface transmission buffer to transmit data, and the steps of adaptive parsing shown in fig. 4 are as follows:
step 401: the current packet mentioned above is the packet taken from the parsing buffer.
Step 402: setting the residual length equal to the data packet length, and setting the total consumption length ConSumeLen equal to 0. In other words, during analysis, a data packet is copied to an analysis buffer area, and the final analysis is performed by using a complete data packet regardless of serial port receiving or a wireless or Ethernet mode, wherein the length of the data packet is set to be n. The total consumption length mt is set to 0.
Step 403: and judging whether the sum of the total consumption length and 6 is greater than the data packet length, namely judging whether mt +6> -n is true, if so, exiting the self-adaptive analysis of the data packet, and if not, jumping to the step 404.
Step 404: the modbusRTU analysis module analyzes whether the current frame data packet (namely the current data packet) meets the modbusRTU protocol condition. Calling a ModbusRTU analysis module to judge whether the frame data packet is in accordance with a ModbusRTU protocol frame, setting parameters of the ModbusRTU analysis module in the analysis process, namely setting the consumption length of an analysis buffer area from the data packet, setting the length of the received data packet to be equal to the residual length, calling the ModbusRTU analysis module to judge whether the sending length of a reply data packet to the frame data packet is equal to 0, and if the sending length of the reply data packet is not equal to 0, indicating that the frame data packet is in accordance with the ModbusRTU protocol condition, then jumping to a step 405. If the sending length of the reply data packet is equal to 0, the frame data packet does not meet the conditions of the ModbusRTU protocol, and the step 406 is skipped.
Step 405: and transmitting a return frame (namely a reply data packet corresponding to the current data packet) of the frame data packet to a sending buffer area to wait for sending a reply, wherein the current ConSumeLen = the length consumed by the former ConSumeLen + ModbusRTU analysis, namely the current total consumption length ConSumeLen = the length consumed by the former ConSumeLen + ModbusRTU analysis module, namely the current total consumption length ConSumeLen is equal to the sum of the previous total consumption length and the current ModbusRTU analysis module (the latest total consumption length is updated to the sum of the previous total consumption length and the current total consumption length), and then jumping to step 401.
Step 406: the DL645-2007 parsing module parses whether the packet of the present frame (i.e., the current packet) satisfies the DL645-2007 protocol condition. The present frame data packet, that is, the above-mentioned current data packet, calls the DL645-2007 parsing module to determine whether the present frame data packet is a frame conforming to the DL645-2007 protocol, the parsing process needs to set a parameter of the DL645-2007 parsing module first, that is, the parsing buffer is set to start from the consumption length of the data packet, and the received data packet length is equal to the remaining length, then calls the DL645-2007 parsing module to determine whether the transmission length of the reply data packet to the present frame data packet is equal to 0, and if the transmission length of the reply data packet is not equal to 0, it is determined that the present frame data packet satisfies the DL645-2007 protocol condition, then the process jumps to the 405 st step. If the transmission length of the reply data packet is equal to 0, the data packet of the frame does not meet the condition of the DL645-2007 protocol, and the process jumps to the step 408.
Step 407: and (3) transferring a return frame of the data packet of the current frame (namely a reply data packet corresponding to the current data packet) to a sending buffer to wait for sending a reply, wherein the ConSumeLen = the length of the analysis consumption of the previous ConSumeLen + DL645-2007, namely the ConSumeLen of the current total consumption is equal to the length of the previous total consumption plus the length of the analysis consumption of the analysis module of the current DL645-2007 (the latest total consumption length is updated to the sum of the length of the previous total consumption and the length of the current total consumption), and jumping to the step 401.
Step 408: the DL698.45 parsing module parses whether the packet of the frame (i.e. the current packet) satisfies the DL698.45 protocol condition. The present frame data packet, i.e. the current data packet mentioned above, calls the DL698.45 parsing module to determine whether the present frame data packet is a frame conforming to the DL698.45 protocol, the parsing process needs to set the parameters of the DL698.45 parsing module first, i.e. the parsing buffer is set from the consumption length of the data packet, and the received data packet length is equal to the remaining length, then calls the DL698.45 parsing module to determine whether the transmission length of the reply data packet to the present frame data packet is equal to 0, if the transmission length of the reply data packet is not equal to 0, it is determined that the present frame data packet satisfies the DL698.45 protocol condition, then the process jumps to step 405. If the transmission length of the reply data packet is equal to 0, which indicates that the data packet of the current frame does not satisfy the DL698.45 protocol condition, the process ends to exit the adaptive parsing process of the data packet of the current frame.
Step 409: and (3) transmitting a return frame of the data packet of the current frame (namely a reply data packet corresponding to the current data packet) to a transmission buffer to wait for transmitting a reply, wherein the current ConSumeLen = the length of analysis consumption of the previous ConSumeLen + DL698.45, namely the current total consumption length ConSumeLen is equal to the sum of the previous total consumption length and the length of analysis consumption of the current DL698.45 analysis module (the latest total consumption length is updated to the sum of the previous total consumption length and the current total consumption length), and jumping to the step 401.
In summary, in the adaptive parsing process, a set of parsing of the communication protocol type of the current data is completed through the sequence of modbusRTU parsing module → DL645-2007 parsing module → DL698.45 parsing module, and if none of the above protocols modbusRTU, DL645-2007 and DL698.45 is satisfied, the data in the buffer area is considered to have a problem, and the current buffer area parsing is directly exited.
In some embodiments, an embodiment of the present application provides a multi-protocol adaptive parsing method, where the current parsing module is a ModbusRTU parsing module, the ModbusRTU command frame types include 03H, 04H, 06H, and 10H, and invoking the current parsing module according to a protocol importance level sequence to determine whether the current packet meets a reply condition corresponding to a current communication protocol type includes:
s501, sequentially verifying according to the sequence of a plurality of first judgment conditions in a first condition set corresponding to a Modbus protocol; the sequence of the first judgment conditions in the first condition set is as follows: the ModbusRTU command frame is correct in address code, function code accords with the ModbusRTU command frame type, the ModbusRTU command frame length is not less than a corresponding quantity threshold value, a CRC check value is correct, and a read-write address and a length corresponding to the ModbusRTU command frame are correct;
s502, if any first judgment condition is not met, determining that the current data packet does not conform to the Modbus protocol, and switching and calling a DL645 analysis module to continue to judge the type of the communication protocol of the current data packet;
s503, if all the first judgment conditions are met, determining that the current data packet meets the response condition corresponding to the Modbus protocol, and generating a Modbus protocol response data packet corresponding to the current data packet;
s504, if the ModbusRTU command frame type belongs to any one of 03H, 04H and 06H, determining the current total consumption length as a first value (8), and adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length;
and S505, if the ModbusRTU command frame type belongs to 10H or 16H, determining the current total consumption length as the sum of a value twice the number of registers and a second value (9), and adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length.
Specifically, the current parsing module is a ModbusRTU parsing module, and the step of calling the current parsing module according to the protocol importance degree sequence to determine whether the current packet conforms to the reply condition corresponding to the current communication protocol type includes the steps of: judging whether the address code corresponding to the current data packet is correct, wherein the address code is the 1 st byte of the current data packet, and if the address code is incorrect, finishing the judgment on whether the current data packet conforms to the Modbus protocol; and if the address code is correct, judging whether the function code corresponding to the current data packet conforms to a ModbusRTU command frame supported by a Modbus protocol. The function code is the 2 nd byte of the current data packet, and the function code substantially indicates the command type supported by the ModbusRTU; if the function code does not conform to any ModbusRTU command frame, finishing the judgment on whether the current data packet conforms to the Modbus protocol; and if the function code conforms to any ModbusRTU command frame, subtracting the current total consumption length from the residual length corresponding to the current data packet to obtain the length of the command frame.
Then, judging whether the length of the command frame is smaller than a quantity threshold value corresponding to the current ModbusRTU command frame; the current ModbusRTU command frame conforms to a ModbusRTU command frame supported by a Modbus protocol; the ModbusRTU command frame supported by the Modbus protocol includes a 03 command frame, a 04 command frame, a 06 command frame, a 10 command frame and a 16 command frame, that is, the ModbusRTU command frame has different quantity thresholds, for example, the quantity threshold corresponding to the 03 command frame, the 04 command frame and the 06 command frame is a first value, and the quantity threshold corresponding to the 10 command frame and the 16 command frame is a sum of a value twice the number of registers and a second value (9). If the command frame length is smaller than the quantity threshold value, finishing the judgment on whether the current data packet conforms to the Modbus protocol; if the length of the command frame is not less than the number threshold, detecting whether a CRC (cyclic redundancy check) value corresponding to the current data packet is correct; if the CRC value is wrong, finishing the judgment on whether the current data packet conforms to the Modbus protocol; and if the CRC value is correct, determining that the current data packet conforms to the Modbus protocol and meets a reply condition corresponding to the Modbus protocol, and generating a Modbus protocol reply data packet corresponding to the current data packet.
Illustratively, if the command type is a 03 command frame or a 04 command frame, judging whether the length is less than 8, if the command type is less than 8, exiting the modbusRTU protocol frame, otherwise, detecting whether the CRC check is correct, if the command type is not correct, exiting the modbusRTU protocol frame judgment, otherwise, checking whether the read address and the read length meet the requirements, if the read address and the read length do not meet the requirements, generating an incorrect address type frame, sending the incorrect address type frame to a buffer area, setting the current total consumption length to be 8, exiting the modbusRTU protocol frame judgment, otherwise, reading corresponding register data to the sending buffer area, setting the current total consumption length to be 8, and exiting the modbusRTU protocol frame analysis. Then, judging whether the read address and the length meet the requirements or not; if the reading address and the reading length do not meet the requirements, generating a Modbus reply packet comprising an error address mark, and determining the total consumption length at this time to be a first value (8). Of course, if the read address and the read length meet the requirements, the total consumption length at this time can also be determined to be the first value (8). And adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length, accumulating and updating to obtain the latest total consumption length.
Illustratively, if the command type is a 06 command frame, judging whether the length is less than 8, if the command type is less than 8 exiting the judgment of the modbusRTU protocol frame, otherwise detecting whether the CRC check is correct, if the command type is not correct exiting the modbusRTU protocol frame judgment, otherwise checking whether the read address meets the requirement, if not, generating an incorrect address type frame and sending the incorrect address type frame to a buffer area, setting the current total consumption length to 8, exiting the judgment of the modbusRTU protocol frame, otherwise, processing the setting operation, generating a return frame to the sending buffer area, setting the current total consumption length bit to 8, and exiting the analysis of the modbusRTU protocol frame. Then, judging whether the write address meets the requirement or not and judging whether the write data is in the range or not; if the written address does not meet the requirement or the written data is out of the range, a Modbus reply packet comprising an error address mark is generated, and the total consumption length at this time can be determined to be a first value (8). Of course, if the write address meets the requirement or the write data is in the range, the total consumption length can be determined to be the first value (8). And adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length, accumulating and updating to obtain the latest total consumption length.
Illustratively, if the command type is 10 command frame or 16 command frame, the length Len of the register is obtained, whether the length is less than Len + 2+9 is judged, if the length is less than the judgment of quitting the modbusRTU protocol frame, otherwise, whether the CRC check is correct is detected, if the length is not correct, the ModbusRTU protocol frame is quitted, otherwise, whether the written address and the length meet the requirements is checked, if the written address and the length do not meet the requirements, an incorrect address type frame is generated and sent to the buffer area, the total consumption length of this time is set to Len + 2+9, the judgment of the ModbusRTU protocol frame is quitted, otherwise, the setting operation is processed, a return frame is generated and sent to the buffer area, the total consumption length bit Len + 2+9 of this time is set, and the ModbusRTU protocol frame analysis is quitted. Then, judging whether the write address and the length meet the requirements or not and judging whether the write data are in the range or not; if the write address and the length are not in accordance with the requirement or the write data is out of range, generating a Modbus reply packet comprising an error address mark, and determining that the total consumption length of the time is equal to the sum of two times of the number of the registers and a second value (9) (namely Len + 2+ 9). If the write address and the write length are in accordance with the requirement and the write data are in the range, determining that the total consumption length is equal to the sum value (namely Len + 2+ 9) of two times of the number of the registers and a second value (9). And adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length, accumulating and updating to obtain the latest total consumption length.
In some embodiments, an embodiment of the present application provides a multi-protocol adaptive parsing method, where the current parsing module is a DL645 parsing module, and the step of calling the current parsing module according to a protocol importance order to determine whether the current data packet meets a reply condition corresponding to a current communication protocol type includes:
s601, sequentially verifying according to the sequence of a plurality of second judgment conditions in a second condition set corresponding to the DL645 protocol; the sequence of the judgment conditions in the second condition set is as follows: finding a start character 68H in the buffer area, wherein the first target byte data meets the address requirement corresponding to the DL645 protocol, the second target byte data is 68H, the first data area has correct length, and the end character is 16H;
s602, if any second determination condition is not satisfied, determining that the current data packet does not conform to the DL645 protocol, and switching to invoke the DL698 parsing module to continue to perform communication protocol type determination on the current data packet;
s603, if all the second determination conditions are satisfied, determining that the current data packet conforms to the reply condition corresponding to the DL645 protocol, and generating a DL645 protocol reply data packet corresponding to the current data packet;
s604, calculating a sum value according to the initial position, the length of the first data area and the third numerical value (12) corresponding to the starting character 68H to obtain the total consumption length;
s605, the total consumption length of this time is added with the previous total consumption length stored by the DL698 analysis module to obtain the latest total consumption length;
the first target byte data comprises 6 adjacent characters searched from the starting position from front to back, the second target byte data comprises 7 th characters searched from the starting position from front to back, and the length of the first data area is the number of bits between the starting character 68H and the second target byte data.
Specifically, whether a start character (68H, i.e. 0x 68) is found in the buffer corresponding to the current data packet is judged; if the start character (68H, i.e., 0x 68) is not found from the buffer, ending the determination of whether the current data packet conforms to the DL645 protocol; if the starting character is found from the buffer area, recording the position corresponding to the starting character as the starting position (StartIndex), namely, finding the starting character 0x68 of DL645-2007 from the buffer area transferred by the adaptive logic judgment module to the end of the remaining length, and recording the starting position as StartIndex.
Then, searching to obtain first target byte data according to the initial position, and judging whether the first target byte data meets the address requirement corresponding to the DL645 protocol; the first target byte data comprises adjacent continuous 6 characters searched from the starting position from front to back; if the first target byte data does not accord with the address requirement corresponding to the DL645 protocol, finishing the judgment on whether the current data packet accords with the DL645 protocol; if the first target byte data conforms to the address requirement corresponding to the DL645 protocol, judging whether the character of the second target byte data is the same as the starting character; the second target byte data comprises a 7 th character which is searched from the starting position to the back; if the character of the second target byte data is different from the starting character, finishing the judgment on whether the current data packet conforms to the DL645 protocol; if the character of the second target byte data is the same as the initial character, calculating to obtain a first data area length (DataLen) according to the digit between the initial character and the second target byte data; when the first data area length is checked and judged to be correct, judging whether the ending character is 16H (namely 0x 16); if the end character is 16H (i.e., 0x 16), ending the judgment on whether the current data packet conforms to the DL645 protocol; if the end character is 16H (i.e. 0x 16), it is determined that the current data packet conforms to the DL645 protocol and meets the reply condition corresponding to the DL645 protocol, and a DL645 protocol reply data packet corresponding to the current generated current data packet is calculated.
In addition, the total length of the current consumption is calculated by substituting the starting position corresponding to the starting character 68H and the length of the first data area into the following formula, and the total length of the current consumption and the previous total consumption length stored by the DL698 analysis module are added and updated to obtain the latest total consumption length.
Li=StartIndex+11+DataLen+1;
Where, li is the total length of the current consumption, startIndex is the start position corresponding to the start character 68H, and DataLen is the length of the first data area.
In some embodiments, the current parsing module is a DL698 parsing module, and the invoking the current parsing module according to the protocol importance degree sequence to determine whether the current data packet meets a reply condition corresponding to the current communication protocol type includes:
s701, sequentially verifying according to the sequence of a plurality of third judgment conditions in a third condition set corresponding to a DL698 protocol; the sequence of the judgment conditions in the third condition set is as follows: finding a start character 68H and a third target byte data in the buffer zone, wherein the third target byte data meet the address requirement corresponding to the DL698 protocol, a frame header CRC calculated value is the same as a first CRC stored value, a whole frame CRC calculated value is the same as a second CRC stored value, an end character is 16H, and the number of bytes consumed at this time does not exceed the number of remaining bytes;
s702, if any third judgment condition is not met, determining that the current data packet does not conform to the DL698 protocol, and finishing the communication protocol type judgment of the current data packet;
s703, if all the third determination conditions are satisfied, determining that the current data packet meets the reply condition corresponding to the DL698 protocol, and generating a DL698 protocol reply data packet corresponding to the current data packet;
s704, calculating a sum value according to the starting position, the length of the second data area and the third numerical value (12) corresponding to the starting character 68H to obtain the total consumption length;
s705, adding the total consumption length of the current time and the previous total consumption length stored by the DL645 analysis module to update to obtain the latest total consumption length;
the third target byte data includes a 6 th character searched from the start position from the front to the back, the frame header CRC calculated value is a value obtained by performing CRC calculation according to the frame header of the current data packet, the length of the second data region is a bit number between the start character 68H and the second target byte data, the whole frame CRC calculated value is a value obtained by performing CRC calculation according to the length of the second data region, the number of bytes of the total consumption length this time in a non-broadcast form is equal to a sum of the start position corresponding to the start character 68H, the length of the second data region and a fourth value (16), and the number of bytes of the total consumption length this time in a broadcast form is equal to a sum of the start position corresponding to the start character 68H, the length of the second data region and a fifth value (11).
Specifically, the current parsing module is a DL698 parsing module, and the step of calling the current parsing module according to the protocol importance degree sequence to determine whether the current data packet meets the reply condition corresponding to the current communication protocol type includes the steps of: judging whether a starting character is found from a buffer area corresponding to the current data packet or not; if the starting character is not found from the buffer area, finishing the judgment on whether the current data packet conforms to the DL698 protocol; if the starting character is found from the buffer area, recording the position corresponding to the starting character as a starting position (StartIndex), namely, finding the starting character 0x68 of DL645-2007 from the buffer area transferred by the adaptive logic judgment module to the end of the remaining length, and recording the starting position as StartIndex.
Searching to obtain third target byte data according to the initial position, and judging whether the third target byte data meets the address requirement corresponding to the DL698 protocol; the third target byte data comprises a 6 th character which is searched from the starting position from front to back; if the third target byte data does not meet the address requirement corresponding to the DL698 protocol, ending the judgment on whether the current data packet meets the DL698 protocol. If the third target byte data meets the address requirement corresponding to the DL698 protocol, performing CRC calculation according to the frame header of the current data packet to obtain a frame header CRC calculated value, and judging whether the frame header CRC calculated value is the same as the first CRC stored value; if the frame header CRC calculated value is different from the first CRC stored value, finishing the judgment on whether the current data packet conforms to the DL698 protocol; if the calculated value of the CRC of the frame header is the same as the stored value of the first CRC, calculating to obtain the length of a second data area (DataLen) according to the bit number between the starting character and the third target byte data; performing CRC calculation according to the length of the second data area to obtain a whole frame CRC calculation value, and judging whether the whole frame CRC calculation value is the same as a second CRC storage value; if the CRC calculated value of the whole frame is different from the second CRC stored value, finishing the judgment on whether the current data packet conforms to the DL698 protocol; if the calculated value of the CRC of the whole frame is the same as the stored value of a second CRC, calculating the length of a second data area (DataLen) according to the number of bits between the starting character and the third target byte data; when the second data area length is checked and judged to be correct, judging whether the ending character is 16H (namely 0x 16); if the ending character is not 16H (namely 0x 16), ending the judgment on whether the current data packet conforms to the DL698 protocol; if the ending character is 16H (namely 0x 16), calculating the number of bytes consumed this time, wherein the number of bytes of the total length consumed this time in the non-broadcast form is equal to the sum of the starting position corresponding to the starting character 68H, the length of the second data area and the fourth numerical value (16), and the number of bytes of the total length consumed this time in the broadcast form is equal to the sum of the starting position corresponding to the starting character 68H, the length of the second data area and the fifth numerical value (11). Judging whether the byte number exceeds the residual byte number; if the number of bytes exceeds the number of remaining bytes, finishing the judgment on whether the current data packet conforms to the DL698 protocol; if the number of bytes does not exceed the number of remaining bytes, determining that the current data packet conforms to the DL698 protocol and meets the reply condition corresponding to the DL698 protocol, and calculating to obtain a DL698 protocol reply data packet corresponding to the current generated current data packet.
The application further provides an embodiment, the internet of things metering device provided by the embodiment supports multiple communication protocols, including:
the data taking-out module is used for taking out a current data packet from the receiving buffer or the receiving message queue based on a first-in first-out mode;
the matching processing module is used for traversing and matching the taken current data packet with the multiple communication protocols, obtaining the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
a data transfer module, configured to transfer the reply data packet to a sending buffer corresponding to the communication protocol type, so as to send the reply data packet through a communication interface corresponding to the sending buffer;
and the data taking module is also used for continuously taking out the next data packet to analyze again until all the data packets are analyzed.
In specific implementation, the above modules may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and specific implementation of the above modules may refer to the foregoing method embodiments, which are not described herein again.
Fig. 5 shows a specific structural block diagram of the electronic device provided in the embodiment of the present application, and fig. 5 may be used to implement the multi-protocol adaptive parsing method provided in the embodiment of the present application. The electronic device 900 may be a mobile terminal such as a smart phone or a notebook computer.
The RF circuit 910 is used for receiving and transmitting electromagnetic waves, and interconverting the electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices. RF circuit 910 may include various existing circuit elements for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption/decryption chip, a Subscriber Identity Module (SIM) card, memory, and so forth. The RF circuit 910 may communicate with various networks such as the internet, an intranet, a wireless network, or with other devices over a wireless network. The wireless network may include a cellular telephone network, a wireless local area network, or a metropolitan area network. The Wireless network may use various Communication standards, protocols and technologies, including but not limited to Global System for Mobile Communication (GSM), enhanced Data GSM Environment (EDGE), wideband Code Division Multiple Access (WCDMA), code Division Multiple Access (CDMA), time Division Multiple Access (TDMA), wireless Fidelity (Wi-Fi) (e.g., IEEE802.11 a, IEEE802.11 b, IEEE802.1 g and/or IEEE802.11 n), internet telephony (VoIP), world Interoperability for Microwave, and other suitable protocols for instant messaging, including any other protocols not currently developed.
The memory 920 may be used to store software programs and modules, such as program instructions/modules corresponding to the multi-protocol adaptive parsing method in the above-mentioned embodiment, and the processor 980 may execute the software programs and modules stored in the memory 920, so as to perform the automatic credit card approval process as follows:
taking out a current data packet from a receiving buffer or a receiving message queue based on a first-in first-out mode;
traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
transmitting the reply data packet to a sending buffer corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer;
and continuously taking out the next data packet to perform analysis again until all the data packets are analyzed.
The memory 920 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 920 can further include memory located remotely from the processor 980, which can be connected to the electronic device 900 over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input unit 930 may be used to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control. In particular, the input unit 930 may include a touch-sensitive surface 931 as well as other input devices 932. The touch-sensitive surface 931, also referred to as a touch screen or a touch pad, may collect touch operations by a user on or near the touch-sensitive surface 931 (e.g., operations by a user on or near the touch-sensitive surface 931 using a finger, a stylus, or any other suitable object or attachment) and drive the corresponding connecting device according to a predetermined program. Alternatively, the touch sensitive surface 931 may include both a touch detection device and a touch controller. The touch detection device detects the touch direction of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 980, and can receive and execute commands sent by the processor 980. In addition, the touch sensitive surface 931 may be implemented in various types, such as resistive, capacitive, infrared, and surface acoustic wave. The input unit 930 may also include other input devices 932 in addition to the touch-sensitive surface 931. In particular, other input devices 932 may include, but are not limited to, one or more of a physical keyboard, function keys (e.g., volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like.
The display unit 940 may be used to display information input by or provided to the user and various graphical user interfaces of the electronic device 900, which may be made up of graphics, text, icons, video, and any combination thereof. The Display unit 940 may include a Display panel 941, and optionally, the Display panel 941 may be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like. Further, the touch-sensitive surface 931 may overlay the display panel 941, and when a touch operation is detected on or near the touch-sensitive surface 931, the touch operation is transmitted to the processor 980 to determine the type of touch event, and the processor 980 then provides a corresponding visual output on the display panel 941 according to the type of touch event. Although the touch-sensitive surface 931 and the display panel 941 are shown as two separate components to implement input and output functions, in some embodiments, the touch-sensitive surface 931 and the display panel 941 may be integrated to implement input and output functions.
The electronic device 900 may also include at least one sensor 950, such as a light sensor, motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor that may adjust the brightness of the display panel 941 according to the brightness of ambient light, and a proximity sensor that may generate an interrupt when the folder is closed or closed. As one of the motion sensors, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), can detect the magnitude and direction of gravity when stationary, and can be used for applications of identifying the gesture of a mobile phone (such as horizontal and vertical screen switching, related games, magnetometer gesture calibration), vibration identification related functions (such as pedometer and tapping), and the like; as for other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor, which may be further configured to the electronic device 900, detailed descriptions thereof are omitted.
The audio circuitry 960, speaker 961, microphone 962 may provide an audio interface between a user and the electronic device 900. The audio circuit 960 may transmit the electrical signal converted from the received audio data to the speaker 961, and convert the electrical signal into a sound signal for output by the speaker 961; on the other hand, the microphone 962 converts the collected sound signal into an electric signal, converts the electric signal into audio data after being received by the audio circuit 960, and outputs the audio data to the processor 980 for processing, and then transmits the audio data to another terminal via the RF circuit 910, or outputs the audio data to the memory 920 for further processing. The audio circuit 960 may also include an earbud jack to provide communication of a peripheral headset with the electronic device 900.
The electronic device 900, via the transport module 970 (e.g., a Wi-Fi module), may assist the user in receiving requests, sending information, etc., which provides the user with wireless broadband internet access. Although the transmission module 970 is illustrated in the drawings, it is understood that it does not necessarily belong to the essential constitution of the electronic device 900 and may be omitted entirely as needed within a range not changing the essence of the invention.
The processor 980 is a control center of the electronic device 900, connects various parts of the entire cellular phone using various interfaces and lines, and performs various functions of the electronic device 900 and processes data by operating or executing software programs and/or modules stored in the memory 920 and calling data stored in the memory 920, thereby integrally monitoring the electronic device. Optionally, processor 980 may include one or more processing cores; in some embodiments, the processor 980 may integrate an application processor, which primarily handles operating systems, user interfaces, applications, etc., and a modem processor, which primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into processor 980.
The electronic device 900 also includes a power supply 990 (e.g., a battery) that provides power to the various components and, in some embodiments, may be logically coupled to the processor 980 via a power management system that provides management of charging, discharging, and power consumption. The power supply 990 may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and the like.
Although not shown, the electronic device 900 further includes a camera (e.g., a front camera, a rear camera), a bluetooth module, etc., which are not described in detail herein. Specifically, in this embodiment, the display unit of the electronic device is a touch screen display, the mobile terminal further includes a memory, and one or more programs, where the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for:
taking out a current data packet from a receiving buffer or a receiving message queue based on a first-in first-out mode;
traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
transmitting the reply data packet to a sending buffer corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer;
and continuously taking out the next data packet to analyze again until all the data packets are analyzed.
In specific implementation, the above modules may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and specific implementation of the above modules may refer to the foregoing method embodiments, which are not described herein again.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor. To this end, embodiments of the present application provide a storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to perform the steps of any embodiment of the multi-protocol adaptive parsing method provided in embodiments of the present application.
Wherein the storage medium may include: read Only Memory (ROM), random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the storage medium may execute the steps in any embodiment of the multi-protocol adaptive parsing method provided in the embodiment of the present application, beneficial effects that can be achieved by any multi-protocol adaptive parsing method provided in the embodiment of the present application may be achieved, for details, see the foregoing embodiment, and are not described herein again.
The foregoing describes in detail a multi-protocol adaptive parsing method, apparatus, electronic device, and storage medium provided in an embodiment of the present application, and specific examples are applied herein to explain principles and implementations of the present application, and the description of the foregoing embodiments is only used to help understand a method and a core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application. Moreover, it will be apparent to those skilled in the art that various modifications and adaptations can be made without departing from the principles of the present application and these modifications and adaptations are intended to be within the scope of the present application.

Claims (10)

1. The self-adaptive analysis method of the multiple protocols is applied to the metering device of the Internet of things, the metering device of the Internet of things supports multiple communication protocols, and the method comprises the following steps:
taking out a current data packet from a receiving buffer or a receiving message queue based on a first-in first-out mode;
traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
transmitting the reply data packet to a sending buffer corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer;
and continuously taking out the next data packet to analyze again until all the data packets are analyzed.
2. The method for multi-protocol adaptive parsing of claim 1, wherein the step of fetching a current data packet from a receiving buffer or a receiving message queue based on a first-in-first-out manner comprises the steps of:
and if the communication interface for receiving the data is of a serial port type, extracting the data packet received by the communication interface from the sending end, and storing the data packet into the receiving buffer area.
3. The method for multi-protocol adaptive parsing of claim 1, wherein the step of fetching a current data packet from a receiving buffer or a receiving message queue based on a first-in-first-out manner comprises the steps of:
if the communication interface used for receiving data is of a non-serial port type, extracting a data packet received by the communication interface from the sending end, storing the data packet into the receiving buffer area, and then taking out the data packet from the receiving buffer area according to a first-in first-out mode and putting the data packet into a received message queue.
4. The multi-protocol adaptive parsing method according to claim 1, wherein the IOT metering device comprises parsing modules corresponding to the plurality of communication protocols; the step of traversing and matching the extracted current data packet with the multiple communication protocols to obtain the communication protocol type satisfied by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
setting the initial residual length equal to the length information of the current data packet, and setting the initial current total consumption length equal to a first set value; the first set value is 0;
judging whether the first sum of the initial current total consumption length and a second set value is greater than the initial residual length or not; the second set value is 6;
if the first sum value is larger than the initial residual length, the self-adaptive analysis of the current data packet is quitted and the next data packet is switched and analyzed;
if the first sum is not larger than the initial residual length, calling a current analysis module according to the sequence of the protocol importance degree to judge whether the current data packet meets a reply condition corresponding to the current communication protocol type;
if the current data packet meets the reply condition corresponding to the current communication protocol type, generating a reply data packet corresponding to the current data packet, and updating the latest total consumption length to the sum of the previous total consumption length and the current total consumption length;
and if the current data packet does not accord with the reply condition corresponding to the current communication protocol type, switching and calling a next analysis module according to the protocol importance degree sequence to continue judging until the protocol type corresponding to the current data packet is determined or all the analysis modules finish one-round analysis and do not obtain the protocol type.
5. The multi-protocol adaptive parsing method of claim 4, wherein the current parsing module is a modbusRTU parsing module, the modbusRTU command frame types include 03H, 04H, 06H and 10H, and the step of calling the current parsing module according to the protocol importance degree sequence to determine whether the current packet conforms to the reply condition corresponding to the current communication protocol type includes the steps of:
sequentially verifying the sequence of a plurality of first judgment conditions in a first condition set corresponding to the Modbus protocol; the sequence of the first judgment conditions in the first condition set is as follows: the ModbusRTU command frame is correct in address code, function code accords with the ModbusRTU command frame type, the ModbusRTU command frame length is not less than a corresponding quantity threshold value, a CRC check value is correct, and a read-write address and length corresponding to the ModbusRTU command frame are correct;
if any first judgment condition is not met, determining that the current data packet does not conform to the Modbus protocol, and switching and calling a DL645 analysis module to continue to judge the type of the communication protocol of the current data packet;
if all the first judgment conditions are met, determining that the current data packet meets the response condition corresponding to the Modbus protocol, and generating a Modbus protocol response data packet corresponding to the current data packet;
the step of updating the latest total consumption length to the sum of the previous total consumption length and the current total consumption length comprises the following steps:
if the ModbusRTU command frame type belongs to any one of 03H, 04H and 06H, determining the current total consumption length as a first numerical value, and adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length; the first value is 8;
if the ModbusRTU command frame type belongs to 10H or 16H, determining the current total consumption length as the sum of a value twice the number of registers and a second value, and adding and updating the current total consumption length and the previous total consumption length to obtain the latest total consumption length; the second value is 9.
6. The multi-protocol adaptive parsing method according to claim 5, wherein the current parsing module is a DL645 parsing module, and the step of calling the current parsing module according to the sequence of the importance of the protocols to determine whether the current data packet conforms to the reply condition corresponding to the current communication protocol type comprises the steps of:
sequentially verifying according to the sequence of a plurality of second judgment conditions in a second condition set corresponding to the DL645 protocol; the sequence of the judgment conditions in the second condition set is as follows: finding a start character 68H in the buffer area, wherein the first target byte data meets the address requirement corresponding to the DL645 protocol, the second target byte data is 68H, the length of the first data area is correct, and the end character is 16H;
if any second judgment condition is not met, determining that the current data packet does not conform to the DL645 protocol, and switching and calling a DL698 analysis module to continue to judge the type of the communication protocol of the current data packet;
if all the second judgment conditions are met, determining that the current data packet meets the reply condition corresponding to the DL645 protocol, and generating a DL645 protocol reply data packet corresponding to the current data packet;
the updating of the latest total consumption length to the sum of the previous total consumption length and the current total consumption length comprises the following steps:
according to the initial position, the length of the first data area and the third numerical value corresponding to the start character 68H, calculating a sum value to obtain the total consumption length; the third value is 12;
adding the total consumption length of the current time and the previous total consumption length stored by the DL698 analysis module to update to obtain the latest total consumption length;
the first target byte data comprises adjacent 6 characters searched from the starting position from front to back, the second target byte data comprises 7 characters searched from the starting position from front to back, the length of the first data area is the number of bits between the starting character 68H and the second target byte data, the number of bytes of the total consumption length is equal to the sum of the starting position corresponding to the starting character 68H, the length of the second data area and a fourth numerical value in a non-broadcasting mode, and the number of bytes of the total consumption length is equal to the sum of the starting position corresponding to the starting character 68H, the length of the second data area and the fifth numerical value in a broadcasting mode; the fourth value is 16 and the fifth value is 11.
7. The multi-protocol adaptive parsing method according to claim 6, wherein the current parsing module is a DL698 parsing module, and the step of calling the current parsing module according to the sequence of protocol importance degrees to determine whether the current data packet conforms to the reply condition corresponding to the current communication protocol type comprises the steps of:
sequentially verifying according to the sequence of a plurality of third judgment conditions in a third condition set corresponding to the DL698 protocol; the sequence of the judgment conditions in the third condition set is as follows: finding a start character 68H and a third target byte data in the buffer zone, wherein the third target byte data meet the address requirement corresponding to the DL698 protocol, a frame header CRC calculated value is the same as a first CRC stored value, a whole frame CRC calculated value is the same as a second CRC stored value, an end character is 16H, and the number of bytes consumed at this time does not exceed the number of remaining bytes;
if any third judgment condition is not met, determining that the current data packet does not conform to the DL698 protocol, and finishing the judgment of the communication protocol type of the current data packet;
if all the third judgment conditions are met, determining that the current data packet meets the reply condition corresponding to the DL698 protocol, and generating a DL698 protocol reply data packet corresponding to the current data packet;
the step of updating the latest total consumption length to the sum of the previous total consumption length and the current total consumption length comprises the following steps:
according to the initial position, the length of the second data area and the third numerical value corresponding to the starting character 68H, calculating a sum value to obtain the total consumption length;
adding the total consumption length of this time and the previous total consumption length stored by the DL645 analysis module to update to obtain the latest total consumption length;
the third target byte data includes a 6 th character searched from the start position from the front to the back, the frame header CRC calculation value is a value obtained by performing CRC calculation according to the frame header of the current data packet, the length of the second data region is a bit number between the start character 68H and the second target byte data, and the whole frame CRC calculation value is a value obtained by performing CRC calculation according to the length of the second data region.
8. An internet of things metering device, the internet of things metering device supporting multiple communication protocols, comprising:
the data taking module is used for taking out a current data packet from the receiving buffer area or the receiving message queue based on a first-in first-out mode;
the matching processing module is used for traversing and matching the taken current data packet with the multiple communication protocols, obtaining the communication protocol type met by the current data packet, and generating a corresponding reply data packet according to the communication protocol type;
the data transmission module is used for transmitting the reply data packet to a sending buffer area corresponding to the communication protocol type so as to send the reply data packet through a communication interface corresponding to the sending buffer area;
and the data taking module is also used for continuously taking out the next data packet to analyze again until all the data packets are analyzed.
9. An electronic device comprising a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, the memory being coupled to the processor and the processor implementing the steps of the multi-protocol adaptive parsing method of any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored, wherein the computer program, when running, controls an apparatus in which the computer-readable storage medium is located to perform the steps in the multi-protocol adaptive parsing method according to any one of claims 1 through 7.
CN202211112281.0A 2022-09-13 2022-09-13 Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium Active CN115334175B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211112281.0A CN115334175B (en) 2022-09-13 2022-09-13 Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211112281.0A CN115334175B (en) 2022-09-13 2022-09-13 Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium

Publications (2)

Publication Number Publication Date
CN115334175A true CN115334175A (en) 2022-11-11
CN115334175B CN115334175B (en) 2024-06-25

Family

ID=83929142

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211112281.0A Active CN115334175B (en) 2022-09-13 2022-09-13 Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium

Country Status (1)

Country Link
CN (1) CN115334175B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116112456A (en) * 2023-02-01 2023-05-12 镁佳(北京)科技有限公司 BAP protocol-based data caching method, device, equipment and medium
CN116545772A (en) * 2023-07-04 2023-08-04 杭州海康威视数字技术股份有限公司 Protocol identification method, device and equipment for lightweight Internet of things traffic

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104052758A (en) * 2014-07-14 2014-09-17 威胜集团有限公司 Self-adaptive method of multiple communication protocols of electric energy meter
US9094333B1 (en) * 2011-10-26 2015-07-28 Qlogic, Corporation Systems and methods for sending and receiving information via a network device
CN105491017A (en) * 2015-11-23 2016-04-13 泰华智慧产业集团股份有限公司 RS485 bus multi-device multi-protocol analysis method and RS485 bus multi-device multi-protocol analysis system
CN109005353A (en) * 2018-09-07 2018-12-14 厦门亿联网络技术股份有限公司 A kind of camera self-adaptation control method and device based on various control agreement
US20200028937A1 (en) * 2018-07-20 2020-01-23 Boe Technology Group Co., Ltd. Home gateway and control method thereof
CN111130690A (en) * 2019-11-12 2020-05-08 广西电网有限责任公司 Processing method and device for multiple communication protocols of IR46 smart electric meter
CN111741019A (en) * 2020-07-28 2020-10-02 常州昊云工控科技有限公司 Communication protocol analysis method and system based on field description

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9094333B1 (en) * 2011-10-26 2015-07-28 Qlogic, Corporation Systems and methods for sending and receiving information via a network device
CN104052758A (en) * 2014-07-14 2014-09-17 威胜集团有限公司 Self-adaptive method of multiple communication protocols of electric energy meter
CN105491017A (en) * 2015-11-23 2016-04-13 泰华智慧产业集团股份有限公司 RS485 bus multi-device multi-protocol analysis method and RS485 bus multi-device multi-protocol analysis system
US20200028937A1 (en) * 2018-07-20 2020-01-23 Boe Technology Group Co., Ltd. Home gateway and control method thereof
CN109005353A (en) * 2018-09-07 2018-12-14 厦门亿联网络技术股份有限公司 A kind of camera self-adaptation control method and device based on various control agreement
CN111130690A (en) * 2019-11-12 2020-05-08 广西电网有限责任公司 Processing method and device for multiple communication protocols of IR46 smart electric meter
CN111741019A (en) * 2020-07-28 2020-10-02 常州昊云工控科技有限公司 Communication protocol analysis method and system based on field description

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116112456A (en) * 2023-02-01 2023-05-12 镁佳(北京)科技有限公司 BAP protocol-based data caching method, device, equipment and medium
CN116112456B (en) * 2023-02-01 2024-02-13 镁佳(北京)科技有限公司 BAP protocol-based data caching method, device, equipment and medium
CN116545772A (en) * 2023-07-04 2023-08-04 杭州海康威视数字技术股份有限公司 Protocol identification method, device and equipment for lightweight Internet of things traffic
CN116545772B (en) * 2023-07-04 2023-09-19 杭州海康威视数字技术股份有限公司 Protocol identification method, device and equipment for lightweight Internet of Things traffic

Also Published As

Publication number Publication date
CN115334175B (en) 2024-06-25

Similar Documents

Publication Publication Date Title
CN115334175B (en) Multi-protocol self-adaptive analysis method, internet of things metering device, equipment and medium
EP2830044B1 (en) Instruction processing method, apparatus, and system
CN106708554B (en) Program operating method and device
CN110391867B (en) DCI detection method, DCI sending method, terminal and base station
WO2015058646A1 (en) Method for processing queue messages, and method and device for controlling messages to enter queue
WO2015081664A1 (en) Method, apparatus, device and system for controlling wireless network to be switched on/off
WO2018126457A1 (en) Data transmission method and device
CN112235082A (en) Communication information transmission method, device, equipment and storage medium
CN111273955B (en) Thermal restoration plug-in optimization method and device, storage medium and electronic equipment
CN112612745A (en) Data transmission method and device, electronic equipment and readable storage medium
CN111491292B (en) Internet access mode adjusting method and device, storage medium and mobile terminal
CN115118636A (en) Method and device for determining network jitter state, electronic equipment and storage medium
CN111210299B (en) Single number generation and management method and device
CN111277386B (en) Downlink allocation index determining method, terminal and network equipment
CN108769934B (en) Information processing method and device and mobile terminal
CN112468870A (en) Video playing method, device, equipment and storage medium
CN109151154B (en) Power consumption control method and mobile terminal
CN111651299A (en) Wireless chip reset control method and device, storage medium and mobile terminal
CN113328998B (en) Image data transmission method and electronic equipment
CN117033083B (en) Data backup method, system and storage medium
CN114095585B (en) Data transmission method, device, storage medium and electronic equipment
CN113595697B (en) DAI counting method, DAI counting control method, terminal and network equipment
CN117255231B (en) Virtual video synthesis method, device and related products
CN117938310A (en) Information transmission method and device and computer equipment
CN109561481B (en) Data sending method, terminal and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 325603 Wenzhou Bridge Industrial Park, Beibeixiang Town, Yueqing City, Wenzhou City, Zhejiang Province

Applicant after: Zhejiang Zhengtai IOT Technology Co.,Ltd.

Address before: 325603 Wenzhou Bridge Industrial Park, Beibaixiang Town, Qing City, Wenzhou City, Zhejiang Province

Applicant before: Zhejiang Zhengtai IOT Technology Co.,Ltd.

GR01 Patent grant
GR01 Patent grant