Message monitoring method and device, electronic equipment and readable storage medium
By acquiring and parsing request and receipt messages on the bus, the complex problem of implementing the multi-master and one-slave hub scheme in the prior art is solved, and zero-invasive data acquisition and simple solution implementation are realized.
Patent Information
- Application Number
- CN202411959156.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-05-06
AI Technical Summary
In the industrial field, the prior art coordinates the transmission and reception of packets of multiple hosts by installing a multi-master and one-slave hub, resulting in complex implementation of the solution.
The current request message is obtained through the bus, and the host communicates with the slave via the bus; if the current request message is a target message, the subsequent message is obtained; if the subsequent message is a receipt message, the receipt message is parsed according to the register configuration, the acquisition value is obtained, and the acquisition value is sent to the target device.
It realizes monitoring the messages transmitted on the bus to obtain the acquisition value, no additional hub is required, zero-invasive data acquisition is collected, and the original wiring pattern is not changed, making the solution simple to implement.
Smart Images

Figure CN119945953A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of industrial technology, and in particular relates to a message monitoring method, device, electronic device and readable storage medium. Background Art
[0002] In the industrial field, Modbus protocol is usually used to read messages. If in actual scenarios, there is already a host on site that polls the slaves and it is impossible to add a host directly, in this case, a multi-master and one-slave hub is installed to coordinate the message sending and receiving of multiple hosts. However, this solution will change the original wiring, making the solution complicated to implement. Summary of the invention
[0003] The embodiments of the present application provide a message monitoring method, device, electronic device and readable storage medium, which can solve the problem of complex solution implementation caused by installing a multi-master and one-slave hub.
[0004] In a first aspect, an embodiment of the present application provides a method for monitoring a message, including:
[0005] The host computer communicates with the slave computer through the bus by obtaining the current request message;
[0006] If the current request message is the target message, then obtain the subsequent message;
[0007] If the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value;
[0008] The collected value is sent to the target device.
[0009] In one embodiment, obtaining the current request message through the bus includes:
[0010] Obtain the current byte stream via the bus;
[0011] If the first number of bytes in the current byte stream are a preset request prefix, obtaining the remaining bytes of the first message to obtain the current message;
[0012] Determine a first checksum according to the first second number of bytes in the current message;
[0013] If the first checksum is the same as the remaining bytes in the current message, it is determined that the current message is a request message, and the remaining bytes of the current message are the first check code.
[0014] In one embodiment, after determining the first checksum, the method further includes:
[0015] If the first checksum is different from the remaining bytes in the current message, discard the first third number of bytes in the current message, obtain the third number of bytes through the bus to obtain the current message, and return to the execution step: determine the first checksum based on the first second number of bytes in the current message.
[0016] In one embodiment, if the current request message is a target message, obtaining a subsequent message includes:
[0017] Compare the current request message with the to-be-matched list;
[0018] If a matching message corresponding to the current request message is found in the to-be-matched list, the current request message is determined to be the target message, and the subsequent message is obtained.
[0019] In one embodiment, the obtaining of subsequent messages includes:
[0020] Get the subsequent byte stream;
[0021] Determining the number of data bytes according to the byte at the target position in the subsequent byte stream, wherein the target position is determined according to the position of the byte representing the number of data bytes in the receipt message;
[0022] According to the number of data bytes, obtaining the remaining bytes of the second message, and obtaining the subsequent message;
[0023] If the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value, including:
[0024] Determine a second checksum according to the first fourth number of bytes in the subsequent message;
[0025] If the second checksum is the same as the remaining bytes in the subsequent message, it is determined that the subsequent message is the receipt message, and the receipt message is parsed according to the register configuration to obtain the collection value, and the remaining bytes in the subsequent message are the second check code.
[0026] In one embodiment, if the second checksum is different from the remaining bytes in the subsequent message, it is determined that the subsequent message is not the receipt message, and the current request message is discarded.
[0027] In one embodiment, after obtaining the subsequent byte stream, the method further includes:
[0028] If it is determined that the first fifth number of bytes in the subsequent byte stream are a new request message, the current request message is discarded.
[0029] In a second aspect, an embodiment of the present application provides a message monitoring device, including:
[0030] The acquisition module is used to obtain the current request message through the bus, and the host communicates with the slave through the bus;
[0031] Also used for obtaining subsequent messages if the current request message is a target message;
[0032] A parsing module, configured to parse the receipt message according to the register configuration to obtain a collection value if the subsequent message is a receipt message;
[0033] The forwarding module is used to send the collected value to the target device.
[0034] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a method as described in any one of the above-mentioned first aspects when executing the computer program.
[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method as described in any one of the above-mentioned first aspects is implemented.
[0036] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods described in the first aspect.
[0037] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0038] The embodiment of the present application obtains the current request message through the bus, and the host communicates with the slave through the bus; if the current request message is the target message, the subsequent message is obtained; if the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value; the collection value is sent to the target device, and the message transmitted on the bus is monitored to obtain the collection value. There is no need to install an additional hub, and data is collected in a zero-invasive manner without changing the original wiring pattern, making the solution simple to implement.
[0039] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0041] Figure 1 It is a flowchart of a method for monitoring messages provided in an embodiment of the present application;
[0042] Figure 2 is an example diagram of a list to be matched provided in an embodiment of the present application;
[0043] Figure 3 It is a structural diagram of a message monitoring device provided in an embodiment of the present application;
[0044] Figure 4 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0045] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0046] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0047] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0048] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0049] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0050] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0051] In one embodiment, Figure 1 FIG. 1 is a flow chart of a method for monitoring messages provided in an embodiment of the present application. Figure 1 As shown, the method is applied to an electronic device, comprising:
[0052] S11: Get the current request message through the bus.
[0053] The master communicates with the slaves through the bus. The master is the device that sends a message requesting the register content during the polling process. The slave is the device that responds to the master's message. Only one device on the bus is sending information at the same time.
[0054] In the application, the electronic device can be a monitoring device. The monitoring device is incorporated into the bus on the host side to monitor the information on the bus. Specifically, the A and B lines of the monitoring device are connected to the A and B interfaces on the host side, and are configured the same as the serial port of the polled host. The baud rate, data bit, stop bit, and check method are configured according to the actual situation of the scene. Then the monitoring device monitors the message transmitted on the bus.
[0055] The types of messages include request messages and receipt messages. The request message is sent by the host when reading the information of the slave register, and is expressed in the form of a byte array. The receipt message is returned by the slave in response to the request message of the host, and contains the register content, and is expressed in the form of a byte array.
[0056] In a possible implementation, step S11 includes:
[0057] S111: Obtain the current byte stream through the bus.
[0058] In the application, the monitoring device monitors the bus information in real time and obtains the current byte stream.
[0059] S112: If the first number of bytes in the current byte stream are a preset request prefix, the remaining bytes of the first message are obtained to obtain the current message.
[0060] The first number is determined according to the bytes occupied by the request prefix of the request message. The remaining bytes of the first message include the request content and the first check code.
[0061] In the application, according to the format of the request message, the first first number of bytes are the request prefix. The first first number of bytes in the current byte stream are compared with the preset request prefix list. If the corresponding request prefix is found in the preset request prefix list, the first first number of bytes are determined to be the preset request prefix. The current first number of bytes is the preset request prefix, and the bytes required to form the current request message, that is, the remaining bytes of the first message, are continued to be obtained to obtain the current message.
[0062] The preset request prefix list is set according to the slave machine to be monitored. The request prefix includes the slave machine address and the read function code.
[0063] For example, the addresses of the slaves to be monitored include slave 1 and slave 2. The monitoring device generates a preset request prefix list based on the entered slave address and function code. The preset request prefix list is shown in the following table:
[0064] Slave Address Read function code Request prefix 01 01 0101 01 02 0102 01 03 0103 01 04 0104 02 01 0201 02 02 0202 02 03 0203 02 04 0204
[0065] In a possible implementation, after step S111, the method further includes:
[0066] If the first number of bytes in the current byte stream are not the preset request prefix, the first third number of bytes are discarded.
[0067] In the application, the monitoring device is incorporated into the host side, which may be before the message is sent or during the message is sent, to prevent missing the legal and complete message and discard the first third number of bytes.
[0068] For example, the host's request message contains eight bytes, and the first two bytes are the request prefix. The monitoring device monitors two bytes from the director: E603, and determines that E603 does not match the request prefix defined in the preset request prefix list, and discards the previous byte E6. Then the monitoring device continues to monitor and obtains another byte 04, and determines that 0304 matches the request prefix defined in the preset request prefix list.
[0069] S113: Determine a first checksum according to the first second number of bytes in the current message.
[0070] The second number is determined according to the number of bytes occupied by the request prefix and the request content of the request message of the host.
[0071] In the application, according to the format of the request message, the part of the current message belonging to the request prefix and the request content is checked to determine whether the current message is a request message. Specifically, the first second number of bytes in the current message are obtained. According to the first second number of bytes in the current message, a first checksum is determined.
[0072] S114: If the first checksum is the same as the remaining bytes in the current message, the current message is determined to be a request message, and the current request message is obtained.
[0073] The remaining bytes of the current message are the first check code. The remaining bytes in the current message are the bytes except the first second number of bytes.
[0074] In the application, when the first checksum is the same as the remaining bytes in the current message, it means that the check is passed, the current message is determined to be a request message, the current request message is obtained, and the request is legal.
[0075] For example, the request message of the host includes eight bytes, the first two bytes are the request prefix, the first six bytes include the request prefix and the request content, and the last two bytes are the first check code.
[0076] The information transmitted on the bus includes 020400000014F036020428E04A 3F 7B 000042BF 9E6441E2 E906421E 8C 283E FB 0D BC 3F 870000. The first two bytes of the current byte stream: 0204, it is judged that 0204 meets the request prefix defined in the preset request prefix list, which means 02 good slave 04 function code. Then the monitoring device continues to monitor and obtains another six bytes, and then obtains the current message 020400000014F036 containing eight bytes. The CRC checksum calculation is performed on the first six bytes 020400000014 to obtain the first checksum F036. The first checksum F036 is the same as the first check code F036, and it is determined that the current message 020400000014F036 is a request message, and the current request message is obtained, and the message is legal.
[0077] S115: If the first checksum is different from the remaining bytes in the current message, discard the first third number of bytes in the current message, obtain the third number of bytes through the bus to obtain the current message, and return to execute step S113: determine the first checksum based on the first second number of bytes in the current message.
[0078] In the application, the monitoring device is incorporated into the host side, which may be before the message is sent or during the message is sent, to prevent missing the legal and complete message and discard the first third number of bytes.
[0079] When the first checksum is different from the remaining bytes in the current message, it means that the current message is not a request message, and the first third number of bytes need to be discarded. Then the monitoring device continues to monitor, obtains the third number of bytes through the bus, and supplements the bytes required for the current message. Then continue to check the current message.
[0080] For example, the information transmitted on the bus includes 0104000E 00089029. The monitoring device monitors two bytes from the director: 0104, and determines that 0104 meets the request prefix defined in the preset request prefix list, which means 01 OK slave 04 function code. Then the monitoring device continues to monitor and obtains six more bytes, and then obtains the current message 0104000E00089029 containing eight bytes. The CRC checksum calculation is performed on the first six bytes 0104000E 0008 to obtain the first checksum 0F 00. The first checksum 0F 00 is different from the first check code 9029, and it is determined that the current message 0104000E 0008 is not a request message, and the message is illegal, and then the first byte in the current message is discarded.
[0081] Through steps S111 to S115, it is ensured that a legal and complete request message is monitored, thereby preventing the request message of the host from being missed.
[0082] S12: If the current request message is the target message, then obtain the subsequent message.
[0083] In a possible implementation, step S12 includes:
[0084] S121: Compare the current request message with the to-be-matched list.
[0085] S122: If a matching message corresponding to the current request message is found in the to-be-matched list, the current request message is determined to be the target message, and a subsequent message is obtained.
[0086] Among them, the list to be matched is generated by the user selecting at least one host's request message in the request list according to the monitoring requirements. The request list is set according to the real and valid request messages sent by the acquired host. After the legitimate request message is obtained after the inspection, it is put into the request list for the user to select. The user can check the request message of the host on the display page to generate the list to be matched. After determining that the current request message is the target message, the subsequent message is obtained, so as to monitor the messages required by the user instead of the messages not required by the user, which can reduce the burden of the monitoring device.
[0087] Please refer to Figure 2 , Figure 21 is an example diagram of a list to be matched provided by an embodiment of the present application. The list to be matched includes a request message of a host selected by a user, and also includes a slave address, a function code, a register start address, and the number of registers.
[0088] It is understandable that the request list is set by obtaining the real and valid request messages sent by the host, so that the message verification in the request list is legal and conforms to the actual situation of the scenario. It is a request message actually sent by the host and can instruct the slave to respond.
[0089] For example, in some scenarios, although the data actually to be collected includes the contents of 40 registers starting from address 0000, the request message of the host set according to the writing rules is 030400000028F1 F6, but the slave responds to the request to read 120 register addresses at one time, based on hexadecimal, 120 = 7 * 16 + 8, and the corresponding request message of the host is 030400000078F1 CA. The request list is set by obtaining the real and valid request message sent by the host to ensure that the user monitors the real message that meets the actual situation of the scene.
[0090] In a possible implementation, obtaining a subsequent message includes:
[0091] S21: Obtain subsequent byte stream.
[0092] In the application, when it is determined that the current message is a request message, the subsequent bytes of the current message are continuously monitored to obtain a subsequent byte stream.
[0093] S22: Determine the number of data bytes according to the bytes at the target position in the subsequent byte stream.
[0094] The target position is determined according to the position of the byte representing the number of data bytes in the receipt message.
[0095] S23: According to the number of data bytes, obtain the remaining bytes of the second message to obtain a subsequent message.
[0096] In the application, the subsequent message is obtained in the subsequent byte stream according to the format of the receipt message. The remaining bytes of the second message include the content of the slave register and the second check code.
[0097] For example, the first two bytes of the slave's receipt message are prefixes, including the slave address and function code. The third byte in the receipt message is the byte representing the number of data bytes, and the corresponding target position is the third byte. The number of data bytes represents the number of bytes occupied by the contents of the slave register. The last two bytes of the receipt message are the second check code. The third byte is 04, which determines that the number of data bytes is four bytes, and then continues to monitor and obtain six bytes to obtain the remaining bytes of the second message, and then obtain the subsequent message.
[0098] After step S21, the method further includes:
[0099] S24: If it is determined that the first fifth number of bytes in the subsequent byte stream are a new request message, the current request message is discarded.
[0100] The fifth number is determined according to the number of bytes occupied by the request message of the host.
[0101] In the application, after the host sends a request message, due to the lack of response from the sub-machine, the host will send the request message again or send a new request message after a period of time, making the confirmed request message useless, that is, the current request message is useless and needs to be discarded.
[0102] The first fifth number of bytes in the subsequent byte stream are verified. If the verification passes, it means that the first fifth number of bytes in the subsequent byte stream do not belong to the content of the receipt message, but to the content of the new request message, and then a new request message is obtained. Then the current request message is discarded, and the subsequent bytes of the new request message are obtained to obtain a new subsequent byte stream, and whether the subsequent message is a receipt message is determined, and so on.
[0103] If it is determined that the first fifth number of bytes in the subsequent byte stream is a new request message, the current request message is discarded, thereby ensuring that a complete and valid request message can be obtained and preventing the request message of the host from being missed.
[0104] S13: If the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collected value.
[0105] In a possible implementation, step S13 includes:
[0106] S131: Determine a second checksum according to the first fourth number of bytes in the subsequent message.
[0107] The first fourth number of bytes include the prefix in the receipt message, the byte representing the number of data bytes, and the bytes occupied by the contents of the slave register.
[0108] S132: If the second checksum is the same as the remaining bytes in the subsequent message, it is determined that the subsequent message is a receipt message, and the receipt message is parsed according to the register configuration to obtain the collection value.
[0109] The remaining bytes in the subsequent message are the second check code. The remaining bytes in the subsequent message are the bytes other than the first fourth number of bytes.
[0110] In the application, the register configuration is pre-entered, and the register configuration includes the register start address, register function code, register end address, register number, and data type of the register content, so as to correctly parse the received receipt message later.
[0111] According to the format of the receipt message, checksum calculation is performed on the bytes other than the second check code in the subsequent message, that is, the first fourth number of bytes in the subsequent message are obtained, and checksum calculation is performed on the first fourth number of bytes to obtain the second checksum.
[0112] When the second checksum is the same as the remaining bytes in the subsequent message, it indicates that the subsequent message is a receipt message, and a legal and complete receipt message is obtained. The receipt message is parsed according to the register configuration to obtain the collection value.
[0113] S14: Send the collected value to the target device.
[0114] The target device may be a target host or other device.
[0115] In the application, after parsing the receipt message to obtain the collected value, the monitoring device can forward the collected value to the target device according to the pre-set forwarding address and user name, password and other information to ensure the timeliness of on-site data collection.
[0116] This embodiment obtains the current request message through the bus, and the host communicates with the slave through the bus; if the current request message is the target message, the subsequent message is obtained; if the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value; the collection value is sent to the target device, and the message transmitted on the bus is monitored to obtain the collection value. There is no need to install an additional hub, and the data is collected in a zero-invasive manner without changing the original wiring pattern, making the solution simple to implement.
[0117] In one embodiment, after step S131, the method further includes:
[0118] S133: If the second checksum is different from the remaining bytes in the subsequent message, it is determined that the subsequent message is not a receipt message, and the current request message is discarded.
[0119] In the application, when the second checksum is different from the remaining bytes in the subsequent message, it means that the subsequent message is not a receipt message, and the current request message is useless, so the current request message is discarded. Then the monitoring device continues to monitor.
[0120] This embodiment determines that the subsequent message is not a receipt message and the current request message if the second checksum is different from the remaining bytes in the subsequent message, thereby reducing the acquisition of erroneous receipt messages, reducing the monitoring quality, and providing a basis for monitoring a complete and valid request message.
[0121] It can be understood that the message monitoring method provided in the embodiment of the present application is implemented by incorporating an electronic device on the host side, without going through other cloud devices, which makes the solution simple to implement.
[0122] And, it should be noted that the message monitoring method provided in the embodiment of the present application can be applied to the Modbus scenario. ModbusRTU and ModbusASCII belong to the same Modbus protocol family, and ModbusASCII can be used to encode the content of ModbusRTU in ASCII, that is, the actual content expressed by the two is the same. It can be obtained that the message monitoring method provided in the embodiment of the present application can be applied to ModbusRTU and ModbusASCII.
[0123] It should be understood that the order of execution of the steps in the above embodiments does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, the data collection in the above embodiments is compliant, and its use or implementation does not involve any infringement on the public interest.
[0124] Corresponding to the method described in the above embodiment, for the convenience of explanation, only the part related to the embodiment of the present application is shown.
[0125] In one embodiment, Figure 3 Schematic diagram of the structure of a message monitoring device provided by an embodiment of the present application. Figure 3 As shown, the device comprises:
[0126] The acquisition module 10 is used to acquire the current request message through the bus, and the host communicates with the slave through the bus;
[0127] It is also used to obtain subsequent messages if the current request message is the target message;
[0128] The parsing module 11 is used to parse the receipt message according to the register configuration to obtain the collection value if the subsequent message is a receipt message;
[0129] The forwarding module 12 is used to send the collected value to the target device.
[0130] In one embodiment, the acquisition module is specifically used to acquire the current byte stream through the bus; if the first number of bytes in the current byte stream are a preset request prefix, the remaining bytes of the first message are acquired to obtain the current message; based on the first second number of bytes in the current message, a first checksum is determined; if the first checksum is the same as the remaining bytes in the current message, the current message is determined to be a request message, the current request message is obtained, and the remaining bytes of the current message are the first check code.
[0131] In one embodiment, the acquisition module is also used to discard the first third number of bytes in the current message if the first checksum is different from the remaining bytes in the current message, and acquire the third number of bytes through the bus to obtain the current message, and return to the execution step: determine the first checksum based on the first second number of bytes in the current message.
[0132] In one embodiment, the acquisition module is specifically used to compare the current request message with the to-be-matched list; if a matching message corresponding to the current request message is found in the to-be-matched list, the current request message is determined to be the target message, and a subsequent message is acquired.
[0133] In one embodiment, the acquisition module is specifically used to acquire a subsequent byte stream; determine the number of data bytes based on the bytes at the target position in the subsequent byte stream, where the target position is determined based on the position of the bytes representing the number of data bytes in the receipt message; acquire the remaining bytes of the message based on the number of data bytes to obtain a subsequent message.
[0134] In one embodiment, the parsing module is specifically used to determine a second checksum based on the first fourth number of bytes in a subsequent message; if the second checksum is the same as the remaining bytes in the subsequent message, it is determined that the subsequent message is a receipt message, and the receipt message is parsed according to the register configuration to obtain the collected value, and the remaining bytes in the subsequent message represent the second check code.
[0135] In one embodiment, the parsing module is further configured to determine that the subsequent message is not a receipt message and discard the current request message if the second checksum is different from the remaining bytes in the subsequent message.
[0136] In one embodiment, the parsing module is further configured to discard the current request message if it is determined that the first fifth number of bytes in the subsequent byte stream are a new request message.
[0137] Figure 4 A schematic diagram of the structure of an electronic device is provided for one embodiment of the present application. Figure 4 As shown, the electronic device 2 of this embodiment includes: at least one processor 20 ( Figure 4 Only one is shown in the figure), a memory 21, and a computer program 22 stored in the memory 21 and executable on the at least one processor 20, wherein the processor 20 implements the steps of any of the above-mentioned method embodiments when executing the computer program 22.
[0138] The electronic device 2 may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 4It is only an example of the electronic device 2 and does not constitute a limitation on the electronic device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0139] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0140] In some embodiments, the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or memory of the electronic device 2. In other embodiments, the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 2. Further, the memory 21 may also include both an internal storage unit of the electronic device 2 and an external storage device. The memory 21 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program. The memory 21 may also be used to temporarily store data that has been output or is to be output.
[0141] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0142] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0143] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0144] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0145] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / terminal device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some cases, the computer-readable medium cannot be an electric carrier signal and a telecommunication signal.
[0146] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0147] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0148] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0149] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0150] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for monitoring messages, characterized in that: include: The host computer communicates with the slave computer through the bus by obtaining the current request message; If the current request message is the target message, then obtain the subsequent message; If the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value; The collected value is sent to the target device.
2. The method according to claim 1, characterized in that: The obtaining of the current request message through the bus includes: Obtain the current byte stream via the bus; If the first number of bytes in the current byte stream are a preset request prefix, obtaining the remaining bytes of the first message to obtain the current message; Determine a first checksum according to the first second number of bytes in the current message; If the first checksum is the same as the remaining bytes in the current message, it is determined that the current message is a request message, the current request message is obtained, and the remaining bytes of the current message are the first check code.
3. The method according to claim 2, characterized in that After determining the first checksum, the method further includes: If the first checksum is different from the remaining bytes in the current message, discard the first third number of bytes in the current message, obtain the third number of bytes through the bus to obtain the current message, and return to the execution step: determine the first checksum based on the first second number of bytes in the current message.
4. The method according to any one of claims 1 to 3, characterized in that: If the current request message is a target message, obtaining a subsequent message includes: Compare the current request message with the to-be-matched list; If a matching message corresponding to the current request message is found in the to-be-matched list, the current request message is determined to be the target message, and the subsequent message is obtained.
5. The method according to claim 4, characterized in that The obtaining of subsequent messages includes: Get the subsequent byte stream; Determining the number of data bytes according to the byte at the target position in the subsequent byte stream, wherein the target position is determined according to the position of the byte representing the number of data bytes in the receipt message; According to the number of data bytes, obtaining the remaining bytes of the second message, and obtaining the subsequent message; If the subsequent message is a receipt message, the receipt message is parsed according to the register configuration to obtain the collection value, including: Determine a second checksum according to the first fourth number of bytes in the subsequent message; If the second checksum is the same as the remaining bytes in the subsequent message, the subsequent message is determined to be the receipt message, and the receipt message is parsed according to the register configuration to obtain the collection value, and the remaining bytes in the subsequent message are the second check code.
6. The method according to claim 5, characterized in that After determining the second checksum, the method further includes: If the second checksum is different from the remaining bytes in the subsequent message, it is determined that the subsequent message is not the receipt message, and the current request message is discarded.
7. The method according to claim 6, characterized in that After obtaining the subsequent byte stream, the method further includes: If it is determined that the first fifth number of bytes in the subsequent byte stream are a new request message, the current request message is discarded.
8. A message monitoring device, characterized in that: include: The acquisition module is used to obtain the current request message through the bus, and the host communicates with the slave through the bus; Also used for obtaining subsequent messages if the current request message is a target message; A parsing module, configured to parse the receipt message according to the register configuration to obtain a collection value if the subsequent message is a receipt message; The forwarding module is used to send the collected value to the target device.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.