Data transmission method and system, electronic equipment and storage medium
By generating a read command with a compression request in the data recording device, the data is extracted and compressed, which solves the problem of low transmission efficiency when the data volume is large, and achieves faster and more efficient data transmission.
Patent Information
- Application Number
- CN202411355752.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-17
AI Technical Summary
Due to the characteristics of the protocol itself, the existing data recording device has a long data transmission time and slow efficiency when the data volume is large.
By determining the total length of the monitoring data and the single length of a single read when triggering the reading of monitoring data in the target slave device, and generating a read command with a compression request based on the single length, the data is extracted from the target slave device. Data is compressed to reduce the amount of data transmission.
This method can shorten the time of data transmission and improve transmission efficiency, especially when the amount of data is large.
Smart Images

Figure CN119324903A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a data transmission method, system, electronic equipment and storage medium. Background Art
[0002] With the continuous development of communication technology, especially in the data transmission between devices, the current recording devices that use low-power radio frequency (BLE, NFC) for data transmission, such as recording devices that record environmental parameters such as temperature or temperature and humidity, generally use Bluetooth or near-field communication for transmission. However, this transmission method has the characteristics of the transmission protocol itself: the number of bits transmitted per second is limited, and it mainly transmits the original data. When the amount of original data is large, its transmission efficiency will be slow. Summary of the invention
[0003] The present invention provides a data transmission method, system, electronic device and storage medium, the main purpose of which is to solve the problem that the existing data recording device has a long data transmission time and low efficiency when the data volume is large due to the characteristics of the protocol itself.
[0004] In a first aspect, the present invention provides a data transmission method, which is applied to a data monitoring system, and the method comprises:
[0005] When triggering to read the monitoring data in the target slave device, determining the total length of the monitoring data and the single length of a single read, and generating a read command with a compression request based on the single length;
[0006] Extracting target data whose data length is equal to the single length from the target slave device based on the read command; compressing the target data based on the compression request to obtain response data;
[0007] Read the response data, and determine whether the monitoring data has been read completely based on the total length;
[0008] If not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data reading is completed.
[0009] Optionally, before reading the response data and judging whether the monitoring data has been read based on the total length, the method further includes:
[0010] Identify whether the read-on identifier in the response data segment corresponding to each transmission data frame is an end character; if not, generate a read-on command to read the response data segment corresponding to the next transmission data frame;
[0011] If it is an end mark, decompress the response data and determine whether the decompressed data is complete, wherein the response data includes at least one response data fragment;
[0012] If complete, executing the step of judging whether the monitoring data has been read based on the total length;
[0013] If it is incomplete, a read command with a compression request is regenerated to read the data again.
[0014] Optionally, before generating a read command with a compression request based on the single length, the method further includes:
[0015] Detecting the signal quality of the target slave device, and determining whether the signal quality meets a preset quality requirement;
[0016] If the preset quality requirement is not met, determining that the single length is equal to the length of a single transmission data frame of the target slave device;
[0017] If the preset quality requirement is met, it is determined that the single length is equal to the single maximum compressed data length of the target slave device.
[0018] Optionally, generating a read command with a compression request based on the single length includes:
[0019] Determine whether the currently triggered reading of monitoring data is the first time;
[0020] If yes, construct a read command based on the length of the single transmission data frame and the compression request; or construct a read command based on the single maximum compressed data length and the compression request;
[0021] If not, a read command is constructed based on the adjusted single length and with compression request.
[0022] Optionally, compressing the target data based on the compression request to obtain response data includes:
[0023] Based on the compression request, a preset compression algorithm is called to losslessly compress the target data to obtain response data.
[0024] Optionally, calling a preset compression algorithm based on the compression request to losslessly compress the target data to obtain response data includes:
[0025] Based on the single length, the target data is divided into N target data segments, and the N target data segments are sorted in the order of segmentation to obtain a segment sequence;
[0026] Adding read-continue identification information after N target data segments in the segment sequence;
[0027] Based on the compression request, a preset compression algorithm is called to perform lossless compression on each of the target data segments to obtain response data, wherein the response data includes N response data segments after the target data segments are compressed.
[0028] Optionally, the adjusting the single length based on a preset adjustment strategy includes:
[0029] Comparing the length of the response data with a preset transmission threshold, and calculating the compression ratio of the response data, wherein the preset transmission threshold is equal to the single maximum compressed data length or the product of the single maximum compressed data length and a compression redundancy coefficient;
[0030] If the length of the response data is greater than the single maximum compressed data length, adjusting the single length based on the compression ratio, the compression redundancy factor, the single maximum compressed data length and the length of the response data;
[0031] If the length of the response data is less than the product of the single maximum compressed data length and the compression redundancy coefficient, the single length is adjusted based on the compression rate, the compression redundancy coefficient and the single maximum compressed data length.
[0032] In a second aspect, the present invention further provides a data monitoring system, comprising:
[0033] The host device is used to determine the total length of the monitoring data and the single length of a single read when triggering the reading of the monitoring data in the target slave device, and generate a read command with a compression request based on the single length;
[0034] at least one slave device communicatively connected to the host device, configured to extract target data having a data length equal to the single length from the target slave device based on the read command; compress the target data based on the compression request to obtain response data, and transmit the response data to the host device;
[0035] The host device is also used to read the response data and determine whether the monitoring data has been read based on the total length; if not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data has been read.
[0036] Optionally, the host device is further used for:
[0037] Identify whether the read-on identifier in the response data segment corresponding to each transmission data frame is an end character; if not, generate a read-on command to read the response data segment corresponding to the next transmission data frame;
[0038] If it is an end mark, decompress the response data and determine whether the decompressed data is complete, wherein the response data includes at least one response data fragment;
[0039] If complete, executing the step of judging whether the monitoring data has been read based on the total length;
[0040] If it is incomplete, a read command with a compression request is regenerated to read the data again.
[0041] Optionally, the host device is further used for:
[0042] Detecting the signal quality of the target slave device, and determining whether the signal quality meets a preset quality requirement;
[0043] If the preset quality requirement is not met, determining that the single length is equal to the length of a single transmission data frame of the target slave device;
[0044] If the preset quality requirement is met, it is determined that the single length is equal to the single maximum compressed data length of the target slave device.
[0045] Optionally, the host device is specifically used for:
[0046] Determine whether the currently triggered reading of monitoring data is the first time;
[0047] If yes, construct a read command based on the length of the single transmission data frame and the compression request; or construct a read command based on the single maximum compressed data length and the compression request;
[0048] If not, a read command is constructed based on the adjusted single length and with compression request.
[0049] Optionally, the slave device is specifically used for:
[0050] Based on the compression request, a preset compression algorithm is called to losslessly compress the target data to obtain response data.
[0051] Optionally, the slave device is used for:
[0052] Based on the single length, the target data is divided into N target data segments, and the N target data segments are sorted in the order of segmentation to obtain a segment sequence;
[0053] Adding read-continue identification information after the first N target data segments in the segment sequence;
[0054] Based on the compression request, a preset compression algorithm is called to perform lossless compression on each of the target data segments to obtain response data, wherein the response data includes N response data segments after the target data segments are compressed.
[0055] Optionally, the host device is specifically used for:
[0056] Comparing the length of the response data with a preset transmission threshold, and calculating the compression ratio of the response data, wherein the preset transmission threshold is equal to the single maximum compressed data length or the product of the single maximum compressed data length and a compression redundancy coefficient;
[0057] If the length of the response data is greater than the single maximum compressed data length, adjusting the single length based on the compression ratio, the compression redundancy factor, the single maximum compressed data length and the length of the response data;
[0058] If the length of the response data is less than the product of the single maximum compressed data length and the compression redundancy coefficient, the single length is adjusted based on the compression rate, the compression redundancy coefficient and the single maximum compressed data length.
[0059] In a third aspect, the present application also provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the data transmission method provided above.
[0060] In a fourth aspect, the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the data transmission method provided above.
[0061] The embodiments of the present disclosure bring the following beneficial effects:
[0062] The above-mentioned data transmission method, system, electronic device and storage medium, when triggering to read the monitoring data in the target slave device, determines the total length of the monitoring data and the single length of a single read, and generates a read command with a compression request based on the single length; extracts the target data with a data length equal to the single length from the target slave device based on the read command; compresses the target data based on the compression request to obtain response data; reads the response data, and determines whether the monitoring data has been read based on the total length; if not, adjusts the single length based on a preset adjustment strategy, and generates a read command based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data has been read. This transmission method compresses the original data before transmitting it, which can reduce the amount of data transmission, thereby shortening the time of data transmission and improving transmission efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A first flow chart of a data transmission method according to an embodiment of the present invention;
[0064] Figure 2 A second flow chart of the data transmission method according to an embodiment of the present invention;
[0065] Figure 3 A third flow chart of the data transmission method according to an embodiment of the present invention;
[0066] Figure 4 A schematic diagram of the structure of a data monitoring system in an embodiment of the present invention;
[0067] Figure 5 FIG. 1 is a schematic diagram of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0068] The present invention provides a data transmission method, system, electronic device and storage medium. The method is to analyze the regularity of data recorded and transmitted in the device and find that these data are linearly changing, especially temperature data. Based on this, the present application proposes a solution to improve the data transmission efficiency at a limited transmission speed, specifically, by compressing the original data to be transmitted before transmitting, the data transmission amount can be reduced, thereby shortening the data transmission time.
[0069] Furthermore, in order to solve the problem of limited data frame size in low-power radio frequency communication, the error retransmission problem of compressed data is solved by adding flag information and detecting data integrity. In addition, in order to solve the problem of different levels of compression for different data complexity, the original compressed data volume is left blank to adapt to different levels of compression in different situations, and to avoid the problem of over-compression.
[0070] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0071] For ease of understanding, the specific process of the embodiment of the present invention is described below. The data transmission method provided by the embodiment of the present invention is applied to a data monitoring system, which includes a host device and multiple slave devices. The host device sends a read command to the slave device, and the slave device obtains the corresponding target data based on the target data length and compression request in the read command, compresses it, and returns it to the host device. The data is decompressed and identified on the host device side. Specifically, Figure 1 As shown, the method comprises the following steps:
[0072] 101. When triggering to read monitoring data from a target slave device, determine the total length of the monitoring data and a single length of a single read, and generate a read command with a compression request based on the single length.
[0073] Specifically, the data transmission parameters of the target slave device are acquired, and a data read command is generated based on the data transmission parameters, wherein the data transmission parameters include the length of a single transmission data frame and a single maximum compressed data length.
[0074] In this step, the target slave device is connected via a local area network or a near field connection, and the transmission method for transmitting data between the host device and the target slave device, that is, the transmission protocol, is determined by handshake. The parameters in the transmission protocol are analyzed to obtain the maximum transmission length of a single data frame transmitted between the two devices.
[0075] Furthermore, the maximum compression length of the single compressed data is analyzed by reading the working mode of the slave device.
[0076] In this embodiment, there are two situations when generating a read command, namely, the first time and the non-first time. In the first request, it can choose to construct the read command based on the length of the single transmission data frame of the target slave device or the single maximum compressed data length of the target slave device according to the signal quality of the target slave device. In the non-first request, it is constructed based on the single length adjusted after the first request, and the adjusted single length can be any value, specifically adjusted based on the compression rate of the response data after the first request.
[0077] That is, generating a read command with a compression request based on the single length includes:
[0078] Determine whether the currently triggered reading of monitoring data is the first time;
[0079] If yes, construct a read command based on the length of the single transmission data frame and the compression request; or construct a read command based on the single maximum compressed data length and the compression request;
[0080] If not, a read command is constructed based on the adjusted single length and with compression request.
[0081] In another embodiment, when constructing a read command according to the signal quality of the target slave device, the principle of determining the corresponding single length is:
[0082] Detecting the signal quality of the target slave device, and determining whether the signal quality meets a preset quality requirement;
[0083] If the preset quality requirement is not met, determining that the single length is equal to the length of a single transmission data frame of the target slave device;
[0084] If the preset quality requirement is met, it is determined that the single length is equal to the single maximum compressed data length of the target slave device.
[0085] 102. Extract target data having a data length equal to a single length from the target slave device based on the read command; compress the target data based on the compression request to obtain response data.
[0086] In this step, the single length and compression request carried in the read command are parsed, where the single length can be understood as the length of the data that needs to be obtained corresponding to the read command, which can be less than the maximum transmission length when the slave device sends data in a transmission gap, or it can be greater than the maximum transmission length, that is, the maximum length of each data frame, which is actually set by the user, for example, by configuring the single length currently required to be read through the operation interface on the slave device.
[0087] The compression request may be implemented by embedding instructions in the command or by setting a flag.
[0088] In this embodiment, after parsing the single length and compression request, the target data is intercepted from the memory or cache area in the slave device based on the single length, and the single length data is intercepted in chronological order to form the target data, and then it is determined whether the single length is greater than the length of the single transmission data frame. If so, the target data needs to be divided into multiple segments, and the length of each segment is not greater than the length of the single transmission data frame.
[0089] In another embodiment, before reading the response data and determining whether the monitoring data has been read based on the total length, the method further includes:
[0090] Identify whether the read-on identifier in the response data segment corresponding to each transmission data frame is an end character; if not, generate a read-on command to read the response data segment corresponding to the next transmission data frame;
[0091] If it is an end mark, decompress the response data and determine whether the decompressed data is complete, wherein the response data includes at least one response data fragment;
[0092] If complete, executing the step of judging whether the monitoring data has been read based on the total length;
[0093] If it is incomplete, a read command with a compression request is regenerated to read the data again.
[0094] Specifically, whether the compressed data is complete is determined by the continuation flag in the response data. The completeness here can be understood as whether the compressed data of a single length is completely transmitted, or whether the compressed data of a single length is received.
[0095] In another embodiment, compressing the target data based on the compression request to obtain response data includes:
[0096] Based on the compression request, a preset compression algorithm is called to losslessly compress the target data to obtain response data.
[0097] Specifically, calling a preset compression algorithm based on the compression request to losslessly compress the target data to obtain response data includes:
[0098] Based on the single length, the target data is divided into N target data segments, and the N target data segments are sorted in the order of segmentation to obtain a segment sequence;
[0099] Adding read-continue identification information after N target data segments in the segment sequence;
[0100] Based on the compression request, a preset compression algorithm is called to perform lossless compression on each of the target data segments to obtain response data, wherein the response data includes N response data segments after the target data segments are compressed.
[0101] 103. Read the response data and determine whether the monitoring data has been read based on the total length.
[0102] 104. If not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data reading is completed.
[0103] In this embodiment, the sum of the lengths of all response data received by the host device within the validity period of a command is calculated, and then it is determined whether the reading is completed. In practical applications, when calculating the sum of the lengths, it can be based on the validity period of the command, or the sum of the lengths of the current response data and the historical response data of the command can be calculated, that is, the judgment is made by cumulative addition in sequence.
[0104] In practical applications, since the single length may be several times greater than the length of a single transmission data frame, in this case, the reading can be achieved by continuous reading, that is, the target data of the single length is divided into several compressions and sent, and the length of each compression should be less than or equal to the length of a single transmission data frame. At the same time, the continuation reading identification information is added to control the continuation reading based on the continuation reading identification information after the host device receives the data until the complete single length data is read.
[0105] In another embodiment, the response data used to identify whether it is complete is composed of multiple response data fragments. After each response data fragment is received, it is identified whether the continuation mark in the response data fragment is the end mark; if not, a data continuation command is generated and sent to the slave device.
[0106] The read-continuation identification information in each response data segment is used to indicate whether data needs to be read continuously to obtain target data of a required length.
[0107] Furthermore, the identification of whether the read-once identification information is a terminator may also be performed after each response data segment is received and decompressed, and the length of each response data segment after decompression is calculated;
[0108] If the sum of the lengths of all decompressed response data segments is less than the target data length, it is determined that the response data has not been read completely.
[0109] Specifically, the adjusting the single length based on a preset adjustment strategy includes:
[0110] Comparing the length of the response data with a preset transmission threshold, and calculating the compression ratio of the response data, wherein the preset transmission threshold is equal to the single maximum compressed data length or the product of the single maximum compressed data length and a compression redundancy coefficient;
[0111] If the length of the response data is greater than the single maximum compressed data length, adjusting the single length based on the compression ratio, the compression redundancy factor, the single maximum compressed data length and the length of the response data;
[0112] If the length of the response data is less than the product of the single maximum compressed data length and the compression redundancy coefficient, the single length is adjusted based on the compression rate, the compression redundancy coefficient and the single maximum compressed data length.
[0113] In another embodiment, after receiving and decompressing the response data, the host device performs an integrity check on the decompressed data. If it is complete, it continues to determine whether the length of all response data received at the current moment is less than the maximum length of the original data, wherein the integrity check can be verified by a verification algorithm such as a hash algorithm.
[0114] In summary, after the host device sends a read command to the slave device, the slave device obtains the target data of the corresponding length based on the read command, and compresses the target data to obtain the response data. The host device decompresses the response data after receiving it, and finally adjusts the target data length to complete the data transmission of the next read command. This method optimizes data encapsulation at the application layer and reduces the number of actual transmission data frames, thereby greatly improving the efficiency of actual data transmission.
[0115] The following describes the above method from two perspectives: the signal quality of the target slave device is poor and the signal quality is good. Assume that the maximum single transmission data frame size of the target slave device is m. max , read the original data length of the target slave device (recording device) is n bytes, and the maximum compressed data length allowed by the recording device is n max , compression redundancy coefficient y (0<y<1). In addition, assuming that the device communication signal cannot ensure stability, it is necessary to avoid the appearance of the read-once command as much as possible to ensure that the data reading and decompression process can be completed in one communication. This situation is applicable to NFC recording devices read by NFC of various brands of mobile phones, or BLE recording devices with poor signals (<-80dbm) in the container. The implementation process is as follows Figure 2As shown in the figure, assuming that the total length of the monitoring data read is 1024 bytes, the maximum single transmission data frame of NFC / BLE communication is m max = 256 bytes, the maximum compressed data length of the NFC environmental parameter recording device is n at most. max = 1024 bytes of data, compression redundancy factor y = 0.95, continue reading byte B mark =OxFF indicates that the data is complete, B mark Other values indicate that the data is incomplete. Figure 2 As shown, the specific process is as follows:
[0116] S1: Start;
[0117] S2: Generate a read command with a compression request, and read the target single length n t1 bytes(first frame n t1 =m max );
[0118] That is, the signal quality of the target slave device is detected, and it is determined whether the signal quality meets the preset quality requirements; if it does not meet the preset quality requirements, the single length is determined to be equal to the length of the single transmission data frame, and a read command is constructed based on the length of the single transmission data frame and the compression request.
[0119] If n is generated t1 =255 bytes single length read command with compression request (the response data contains 1 byte to mark whether to continue reading, so the single length is reserved as 1 byte).
[0120] S3: Send a read command;
[0121] S4: Receive the compressed response data m1 bytes from the target slave device;
[0122] Specifically, the response data m1 bytes also contains the read-on flag information, that is, the response data m1 received from the target slave device is 128 bytes, and the read-on flag B mark =OxFF means complete. The completeness here should be understood as when the data transmitted by the target slave device in a single time is greater than the length of the maximum single transmission data frame, it needs to be sent in multiple times, and the last time carries the continue reading identification information as the end mark, so as to determine whether the read needs to be continued.
[0123] S5: Whether the decompressed data of the device response is complete (the first byte of the response contains a data integrity identifier);
[0124] If it is complete, execute S6, if it is incomplete, execute S2 (reread); for example, after decompressing 255 bytes of data, determine whether the data responded by the device is complete. Obviously, the data is complete at this time.
[0125] S6: Monitor whether the total length of the data has been read. If so, execute S26; if not, proceed to step S7.
[0126] S7: When the response data m1>m max Or m1<m max ×y, execute S8, otherwise execute S2;
[0127] S8: Calculate the compression ratio of the response data When m1>m max When the next read data is adjusted, the single length n t2 =(m1-m1%m max )×x1×y; when m1<m max ×y, adjust the single length n of the next read data t2 =m max ×x1×y, then execute S2;
[0128] S9: At this time, 769 bytes remain, and the total length of the monitoring data has not been read completely;
[0129] S10: Determine the response data 128<255×0.95;
[0130] S11: Calculate the response data compression ratio Adjust the single length of the next read data to n t2 =255×1.99×0.95=482;
[0131] S12: Generate a read command with a single length of 482 bytes and a compression request;
[0132] S13: Send a read command;
[0133] S14: Receive the device's response data 255 bytes, continue reading flag B mark =Ox01 means incomplete;
[0134] S15: Generate a continue reading command;
[0135] S16: Send a read command;
[0136] S17: Receive the response data of the device (15 bytes), continue reading flag B mark =OxFF means complete;
[0137] S18: Decompress and get 482 bytes of data. Is the data responded by the device complete? Obviously, the data is complete at this time.
[0138] S19: Calculate the response data compression ratio Adjust the single length of the next read data to n t3 =(270-270%255)×1.79×0.95=433;
[0139] S20: At this time, 287 bytes remain, and the total length of the monitoring data has not been read completely;
[0140] S21: Generate a read command with a single length of 287 bytes and a compression request;
[0141] S22: Send a read command;
[0142] S23: Receive 140 bytes of data from the device, and continue reading flag B mark =0xFF means complete.
[0143] S24: Decompress and get 287 bytes of data. Is the data responded by the device complete? Obviously, the data is complete at this time.
[0144] S25: At this time, 0 bytes remain, and the total length of the monitoring data has been read;
[0145] S26: End.
[0146] For communication with good signals, we can streamline the communication process and control the target length to achieve: compress once and obtain multiple times, making the communication process simpler. It is suitable for dedicated equipment to read NFC recording devices, or USB communication recording devices. Of course, this communication method can also be implemented on BLE recording devices, but it is not as simple and convenient as subscription communication. Assuming that the total length of the monitoring data read is 2048 bytes, the maximum single transmission data frame of NFC is m. max = 256 bytes, the maximum single compressed data length of the NFC environmental parameter recording device n max = 1024 bytes of data, such as Figure 3 As shown, the implementation process steps are:
[0147] S1: Start;
[0148] S2: Generate a read command with a compression request, and read a single length of n t1 bytes(the first time n t1 =n max );
[0149] That is, a read command with a compression request of a single length of 1024 bytes is generated.
[0150] S3: Send a read command;
[0151] S4: receiving the response data m1bytes of the device;
[0152] S5: Is the decompressed data of the device response complete (the first byte of the response contains a data integrity identifier)? If complete, execute S7, otherwise implement S6;
[0153] When the receiving device's response data m1 = 255 bytes, continue reading flag B mark =0x01 means incomplete; generate a continue-read command and send it. The response data is 255 bytes, and the continue-read flag is B. mark =Ox02 means incomplete.
[0154] S6: Generate a continue-read command and execute S3;
[0155] Generate a read-on command and send it. Get 12 bytes of data, read-on flag B mark =OxFF means complete, and the final response data is 255+255+12=522 bytes; decompress to get 1024 bytes of data, and determine whether the decompressed data responded by the device is complete? Obviously, the data is complete at this time; 1024 bytes are left at this time, and the total length of the monitoring data has not been read; generate a read command with a single length of 1024 bytes and a compression request; send a read command; receive the device's response data of 255 bytes, and continue reading flag B mark =0x01 indicates incomplete; generate a continue-read command and send it. Get 253 bytes of data, continue-read flag B mark =OxFF means complete, and finally get 255+253=508 bytes; decompress to get 1024 bytes of data, and judge whether the decompressed data responded by the device is complete? Obviously, the data is complete at this time. If not, re-execute S2.
[0156] S7: Has the total length of the monitoring data been read? If it is completed, execute S8, otherwise execute S2;
[0157] At this time, there are 0 bytes left and the data reading is completed.
[0158] S8: End.
[0159] See also Figure 4 , an embodiment of the data monitoring system provided by an embodiment of the present invention, the system comprises:
[0160] The host device 410 is used to determine the total length of the monitoring data and the single length of a single read when triggering the reading of the monitoring data in the target slave device, and generate a read command with a compression request based on the single length;
[0161] at least one slave device 420 communicatively connected to the host device 410, configured to extract target data having a data length equal to the single length from the target slave device based on the read command; compress the target data based on the compression request to obtain response data, and transmit the response data to the host device 410;
[0162] The host device 410 is also used to read the response data and determine whether the monitoring data has been read based on the total length; if not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data has been read.
[0163] Optionally, the host device 410 is further configured to:
[0164] Identify whether the read-on identifier in the response data segment corresponding to each transmission data frame is an end character; if not, generate a read-on command to read the response data segment corresponding to the next transmission data frame;
[0165] If it is an end mark, decompress the response data and determine whether the decompressed data is complete, wherein the response data includes at least one response data fragment;
[0166] If complete, executing the step of judging whether the monitoring data has been read based on the total length;
[0167] If it is incomplete, a read command with a compression request is regenerated to read the data again.
[0168] Optionally, the host device 410 is further configured to:
[0169] Detecting the signal quality of the target slave device, and determining whether the signal quality meets a preset quality requirement;
[0170] If the preset quality requirement is not met, determining that the single length is equal to the length of a single transmission data frame of the target slave device;
[0171] If the preset quality requirement is met, it is determined that the single length is equal to the single maximum compressed data length of the target slave device.
[0172] Optionally, the host device 410 is specifically used for:
[0173] Determine whether the currently triggered reading of monitoring data is the first time;
[0174] If yes, construct a read command based on the length of the single transmission data frame and the compression request; or construct a read command based on the single maximum compressed data length and the compression request;
[0175] If not, a read command is constructed based on the adjusted single length and with compression request.
[0176] Optionally, the slave device 420 is specifically used for:
[0177] Based on the compression request, a preset compression algorithm is called to losslessly compress the target data to obtain response data.
[0178] Optionally, the slave device 420 is used for:
[0179] Based on the single length, the target data is divided into N target data segments, and the N target data segments are sorted in the order of segmentation to obtain a segment sequence;
[0180] Adding read-continue identification information after N target data segments in the segment sequence;
[0181] Based on the compression request, a preset compression algorithm is called to perform lossless compression on each of the target data segments to obtain response data, wherein the response data includes N response data segments after the target data segments are compressed.
[0182] Optionally, the host device 410 is specifically used for:
[0183] Comparing the length of the response data with a preset transmission threshold, and calculating the compression ratio of the response data, wherein the preset transmission threshold is equal to the single maximum compressed data length or the product of the single maximum compressed data length and a compression redundancy coefficient;
[0184] If the length of the response data is greater than the single maximum compressed data length, adjusting the single length based on the compression ratio, the compression redundancy factor, the single maximum compressed data length and the length of the response data;
[0185] If the length of the response data is less than the product of the single maximum compressed data length and the compression redundancy coefficient, the single length is adjusted based on the compression rate, the compression redundancy coefficient and the single maximum compressed data length.
[0186] In summary, when triggering the reading of monitoring data in the target slave device, determine the total length of the monitoring data and the single length of a single read, and generate a read command with a compression request based on the single length; extract the target data with a data length equal to the single length from the target slave device based on the read command; compress the target data based on the compression request to obtain the response data; read the response data, and judge whether the monitoring data has been read based on the total length; if not, adjust the single length based on the preset adjustment strategy, and generate a read command based on the adjusted single length to continue reading new target data from the target slave device until it is judged that the monitoring data has been read. This transmission method compresses the original data before transmitting it, which can reduce the amount of data transmission, thereby shortening the data transmission time and improving the transmission efficiency.
[0187] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the data transmission method provided in the above embodiment. The electronic device can be a server or a terminal device.
[0188] See also Figure 5 As shown, the electronic device includes a processor 500 and a memory 501. The memory 501 stores machine executable instructions that can be executed by the processor 500. The processor 500 executes the machine executable instructions to implement the data transmission method provided in the above embodiment.
[0189] Further, Figure 5 The electronic device shown further includes a bus 502 and a communication interface 503 , and the processor 500 , the communication interface 503 and the memory 501 are connected via the bus 502 .
[0190] The memory 501 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 503 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 502 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0191] The processor 500 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 500. The above processor 500 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 501, and the processor 500 reads the information in the memory 501 and completes the data transmission method provided in the above embodiment in combination with its hardware.
[0192] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the data transmission method provided in the above embodiment.
[0193] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0194] 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 technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0195] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those 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 thereof may be replaced by equivalents. However, these 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 invention.
Claims
1. A data transmission method, applied to a data monitoring system, characterized in that: The method comprises: When triggering to read the monitoring data in the target slave device, determining the total length of the monitoring data and the single length of a single read, and generating a read command with a compression request based on the single length; Extracting target data whose data length is equal to the single length from the target slave device based on the read command; compressing the target data based on the compression request to obtain response data; Read the response data, and determine whether the monitoring data has been read completely based on the total length; If not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data reading is completed.
2. The data transmission method according to claim 1, characterized in that: Before reading the response data and judging whether the monitoring data has been read based on the total length, the method further includes: Identify whether the read-on identifier in the response data segment corresponding to each transmission data frame is an end character; if not, generate a read-on command to read the response data segment corresponding to the next transmission data frame; If it is an end mark, decompress the response data and determine whether the decompressed data is complete, wherein the response data includes at least one response data fragment; If complete, executing the step of judging whether the monitoring data has been read based on the total length; If it is incomplete, a read command with a compression request is regenerated to read the data again.
3. The data transmission method according to claim 2, characterized in that: Before generating a read command with a compression request based on the single length, the method further includes: Detecting the signal quality of the target slave device, and determining whether the signal quality meets a preset quality requirement; If the preset quality requirement is not met, determining that the target single data length is equal to the maximum length of a single transmission data frame of the target slave device; If the preset quality requirement is met, it is determined that the target single data length is equal to the single maximum compressed data length of the target slave device.
4. The data transmission method according to claim 3, characterized in that: The generating a read command with a compression request based on the single length includes: Determine whether the currently triggered reading of monitoring data is the first time; If yes, construct a read command based on the length of the single transmission data frame and the compression request; or construct a read command based on the single maximum compressed data length and the compression request; If not, a read command is constructed based on the adjusted single length and with compression request.
5. The data transmission method according to claim 3, characterized in that: The step of compressing the target data based on the compression request to obtain response data includes: Based on the compression request, a preset compression algorithm is called to losslessly compress the target data to obtain response data.
6. The data transmission method according to claim 5, characterized in that: The calling of a preset compression algorithm based on the compression request to losslessly compress the target data to obtain response data includes: Based on the length of the single transmission data frame, the target data is divided into N target data segments, and the N target data segments are sorted in the order of segmentation to obtain a segment sequence; Adding read-continue identification information after N target data segments in the segment sequence; Based on the compression request, a preset compression algorithm is called to perform lossless compression on each of the target data segments to obtain response data, wherein the response data includes N response data segments after the target data segments are compressed.
7. The data transmission method according to any one of claims 1 to 6, characterized in that: The adjusting the single length based on a preset adjustment strategy includes: Comparing the length of the response data with a preset transmission threshold, and calculating the compression ratio of the response data, wherein the preset transmission threshold is equal to the single maximum compressed data length or the product of the single maximum compressed data length and a compression redundancy coefficient; If the length of the response data is greater than the single maximum compressed data length, adjusting the single length based on the compression ratio, the compression redundancy factor, the single maximum compressed data length and the length of the response data; If the length of the response data is less than the product of the single maximum compressed data length and the compression redundancy coefficient, the single length is adjusted based on the compression rate, the compression redundancy coefficient and the single maximum compressed data length.
8. A data monitoring system, characterized in that: include: The host device is used to determine the total length of the monitoring data and the single length of a single read when triggering the reading of the monitoring data in the target slave device, and generate a read command with a compression request based on the single length; at least one slave device communicatively connected to the host device, configured to extract target data having a data length equal to the single length from the target slave device based on the read command; Compressing the target data based on the compression request to obtain response data, and transmitting the response data to the host device; The host device is also used to read the response data and determine whether the monitoring data has been read based on the total length; if not, the single length is adjusted based on a preset adjustment strategy, and a read command is generated based on the adjusted single length to continue reading new target data from the target slave device until it is determined that the monitoring data has been read.
9. An electronic device, characterized in that: The invention comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the data transmission method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the data transmission method according to any one of claims 1 to 7.