Time setting method, device and instrument
By generating time synchronization requests and time difference prediction models, the second-level time error and network time difference problems of wireless remote flow meters are solved, and millisecond-level time calibration of the instrument equipment is achieved, ensuring billing accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-04-07
AI Technical Summary
Existing wireless remote flow meter calibration methods suffer from second-level time errors and network propagation time differences, leading to billing anomalies.
By generating a time synchronization request, the system receives the precise system time from the host computer, determines the actual time difference, and uses a time difference prediction model to predict the time difference for the next moment. If the threshold is met, a time synchronization operation is performed to ensure that the time of the instrument equipment is accurate to the millisecond.
It effectively avoids time synchronization deviations caused by network anomalies, achieves accurate time calibration of instruments and equipment, and improves billing accuracy.
Smart Images

Figure CN115987443B_ABST
Abstract
Description
Technical Field
[0001] This application relates to data processing technology, and more particularly to a time synchronization method, apparatus, and instrument. Background Technology
[0002] Currently, wireless remote flow meters are used in industrial applications. They have a large instantaneous flow rate and require high-frequency data acquisition and billing. The billing price is multiplied by the usage volume.
[0003] In existing technology, when the billing price changes, the host computer generates a price adjustment instruction and an effective time and sends it to the flow meter. When the flow meter receives the price adjustment instruction and the effective time, it adjusts its own price and time and bills according to the adjusted price and time.
[0004] However, in the current technology, the flow meter is generally calibrated using timestamps, which only go down to the second level, resulting in a certain time error. In addition, the time difference in command transmission during the calibration process leads to a large billing error in the flow meter, which in turn leads to billing anomalies. Summary of the Invention
[0005] This application provides a time synchronization method, apparatus, and instrument to solve the technical problem of low accuracy of billing results from instrument equipment.
[0006] Firstly, this application provides a time synchronization method, including:
[0007] A time synchronization request is generated and sent to the host computer, so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the sender of the time synchronization request, wherein the time synchronization reply instruction includes the system time with a preset accuracy of the host computer;
[0008] Determine the actual time difference between the receiving time of the time synchronization reply command and the system time; wherein, the receiving time is a preset precision;
[0009] The time difference is predicted for the next moment according to a preset time difference prediction model, and the predicted time difference for the next moment is determined with a preset accuracy; wherein, the preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points.
[0010] If the difference between the actual time difference and the predicted time difference is determined to meet a preset threshold, then the predicted time difference is determined to be the target time difference, and the actual time in the instrument is calibrated according to the target time difference to complete the time calibration operation.
[0011] Further, the step of predicting the time difference for the next moment based on a preset time difference prediction model, and determining the predicted time difference for the next moment with a preset accuracy, includes:
[0012] Determine the current time and determine a preset number of training set data points prior to the current time;
[0013] Based on the preset amount of training data, the time difference of the next moment is predicted according to the preset time difference prediction model, and the predicted time difference of the next moment with preset accuracy is determined.
[0014] Furthermore, the calibration of the actual time within the instrument based on the target time difference includes:
[0015] The target time is obtained by summing the target time difference with the system time.
[0016] Replace the actual time in the instrument with the target time.
[0017] Furthermore, the method also includes:
[0018] Acquire training set data for each historical time point from multiple consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision;
[0019] The training set data at each historical time point is normalized to obtain normalized training set data.
[0020] The initial prediction model is trained using normalized training set data to obtain the time difference prediction model.
[0021] Further, the step of training the initial prediction model based on normalized training set data to obtain the time difference prediction model includes:
[0022] Based on the preset test set partitioning criteria, a preset number of training set data points with adjacent historical time points are determined in the normalized training set data;
[0023] The initial prediction model is trained based on the preset number of training sets of adjacent historical time points to determine the preliminary time difference of the preset accuracy for the next moment.
[0024] Based on the initial time difference with a preset accuracy for the next time moment, and the historical time difference corresponding to the initial time difference, the initial prediction model is corrected until the next time moment is the last historical time point of multiple consecutive historical time points, at which point the prediction training stops, and a time difference prediction model is generated.
[0025] Furthermore, the preset precision is milliseconds.
[0026] Secondly, this application provides a time synchronization device, comprising:
[0027] A generation unit is used to generate a time synchronization request and send the time synchronization request to a host computer, so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the party that sent the time synchronization request, wherein the time synchronization reply instruction includes the system time with a preset accuracy of the host computer;
[0028] The first determining unit is used to determine the actual time difference between the receiving time of the time synchronization reply instruction and the system time; wherein the receiving time is a preset precision.
[0029] The second determining unit is used to predict the time difference of the next moment according to a preset time difference prediction model, and determine the predicted time difference of the next moment with a preset accuracy; wherein, the preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points.
[0030] The third determining unit is used to determine the predicted time difference as the target time difference if the difference between the actual time difference and the predicted time difference meets a preset threshold.
[0031] The calibration unit is used to calibrate the actual time within the instrument based on the target time difference to complete the time synchronization operation.
[0032] Further, the second determining unit includes:
[0033] The first determining module is used to determine the current time and determine a preset number of training set data located before the current time;
[0034] The second determining module is used to predict the time difference of the next moment based on the preset amount of training set data and a preset time difference prediction model, and to determine the predicted time difference of the next moment with a preset accuracy.
[0035] Further, the calibration unit includes:
[0036] The summation module is used to sum the target time difference with the system time to obtain the target time;
[0037] The replacement module is used to replace the actual time in the instrument with the target time.
[0038] Furthermore, the device also includes:
[0039] An acquisition unit is used to acquire training set data for each historical time point in a plurality of consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision;
[0040] The normalization unit is used to normalize the training set data at each historical time point to obtain normalized training set data.
[0041] The training unit is used to train the initial prediction model based on the normalized training set data to obtain the time difference prediction model.
[0042] Furthermore, the training unit includes:
[0043] The third determining module is used to determine a preset number of training set data points of adjacent historical time points in the normalized training set data based on preset test set division standard information.
[0044] The fourth determining module is used to perform prediction training on the initial prediction model based on the preset number of training sets of adjacent historical time points, and to determine the preliminary time difference of the preset accuracy for the next moment.
[0045] The generation module is used to revise the initial prediction model based on the preliminary time difference with a preset accuracy for the next time moment and the historical time difference corresponding to the preliminary time difference, until the prediction training stops when the next time moment is the last historical time point of multiple consecutive historical time points, and a time difference prediction model is generated.
[0046] Furthermore, the preset precision is milliseconds.
[0047] Thirdly, this application provides an instrument device, including a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the computer program to implement the method described in the first aspect.
[0048] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method described in the first aspect.
[0049] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method described in the first aspect.
[0050] This application provides a time synchronization method, apparatus, and instrument. A time synchronization request is generated and sent to a host computer. Upon receiving the request, the host computer sends a time synchronization reply instruction to the requester. The reply instruction includes the host computer's system time with a preset precision. The actual time difference between the received time and the system time is determined, with the received time having a preset precision. A time difference prediction model is used to predict the next time step based on a preset time difference prediction model, which is trained using training data from multiple consecutive historical time points. If the difference between the actual and predicted time differences meets a preset threshold, the predicted time difference is determined as the target time difference. The actual time within the instrument is then calibrated based on this target time difference to complete the time synchronization operation. In this scheme, a time synchronization request is generated and sent to the host computer. Upon receiving the request, the host computer immediately obtains its system time accurate to milliseconds and sends this millisecond-accurate system time as a time synchronization reply instruction to the instrument. The instrument receives the time synchronization reply command and determines the system time in the command. Since the received time and the system time have the same preset precision, the difference between the system time and the received time is used to obtain the actual time difference with the preset precision. Then, based on the preset time difference prediction model, the instrument predicts the time difference for the next moment, determining the predicted time difference with the preset precision. The instrument first determines the difference between the actual time difference and the predicted time difference and compares this difference with a preset threshold. If the difference between the actual time difference and the predicted time difference meets the preset threshold, the predicted time difference is determined as the target time difference. The instrument then calibrates the actual time within it based on the target time difference. At this point, the calibrated time within the instrument is the target time accurate to milliseconds, thus completing the time synchronization operation. Therefore, this application uses a time difference prediction model to predict the target time difference for the next moment and performs time synchronization operations on the instrument equipment based on the target time difference. This can effectively avoid time synchronization deviations caused by network anomalies or inconsistent upload and download transmission times, achieve automatic calibration of the clock preset accuracy, ensure the time accuracy of the instrument equipment, improve the billing accuracy of the instrument equipment, and solve the technical problem of low billing accuracy of the instrument equipment. Attached Figure Description
[0051] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0052] Figure 1 A flowchart illustrating a time synchronization method provided in an embodiment of this application;
[0053] Figure 2 A flowchart illustrating another time synchronization method provided in an embodiment of this application;
[0054] Figure 3 A flowchart illustrating another time synchronization method provided in an embodiment of this application;
[0055] Figure 4 A flowchart illustrating yet another time synchronization method provided in an embodiment of this application;
[0056] Figure 5 This is a schematic diagram of the structure of a time synchronization device provided in an embodiment of this application;
[0057] Figure 6 This is a schematic diagram of another time synchronization device provided in an embodiment of this application;
[0058] Figure 7 This is a schematic diagram of the structure of an instrument device provided in an embodiment of this application.
[0059] The accompanying drawings have illustrated specific embodiments of this disclosure, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concepts of this disclosure to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0060] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure.
[0061] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with relevant laws, regulations and standards, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0062] Currently, wireless remote flow meters are used in industrial applications, where the instantaneous flow rate is relatively large, requiring high-frequency data acquisition and billing. Billing is performed by multiplying the price by the usage volume. When the billing price changes, the host computer generates a price adjustment command and an effective time, which is sent to the flow meter via the server. Upon receiving the price adjustment command and effective time, the flow meter adjusts its own price and time and bills accordingly.
[0063] In one example, because current flow meter calibration generally uses timestamps, which only go down to the second, there is a certain time error, resulting in a large billing error for the flow meter, which in turn leads to billing anomalies.
[0064] In one example, the host computer and the flow meter transmit price adjustment instructions and effective times via a server. If the server is busy, network congestion may occur, or a power outage may prevent transmission. In both cases, the flow meter may not receive the price adjustment instructions from the host computer in a timely manner, resulting in a time error between the flow meter and the host computer, and consequently, billing anomalies.
[0065] This application provides a time synchronization method, apparatus, and instrument, which aims to solve the above-mentioned technical problems of the prior art.
[0066] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0067] Figure 1 This is a flowchart illustrating a time synchronization method provided in an embodiment of this application, as shown below. Figure 1 As shown, the method includes:
[0068] Step 101: Generate a time synchronization request and send it to the host computer so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the sender. The time synchronization reply instruction includes the system time with the preset accuracy of the host computer.
[0069] For example, the execution subject in this embodiment can be an instrument device. During the time synchronization operation, the instrument device needs to interact with the host computer. The host computer refers to a system deployed in the cloud. The host computer can control, recharge, adjust prices, and bill the instrument device according to the issued instructions. The instrument device refers to a device that is capable of communicating with a remote host computer for counting and billing. For example, the instrument device is a smart gas flow meter.
[0070] First, the instrument automatically triggers time synchronization, generating a time synchronization request and establishing a communication connection with the host computer. A session channel is opened between the instrument and the host computer, and the instrument sends the time synchronization request to the host computer through this channel, recording the sending time to the millisecond. Upon receiving the time synchronization request, the host computer immediately obtains its system time to the millisecond and, according to the time synchronization instruction rules, sends the system time to the millisecond as a time synchronization reply instruction back to the requesting party, which is the instrument.
[0071] Step 102: Determine the actual time difference between the received time of the time synchronization reply command and the system time; where the received time is a preset precision.
[0072] For example, the preset precision can be a time unit such as milliseconds. The instrument records the reception time of the time synchronization reply command, and the reception time is also accurate to milliseconds. Then, the time synchronization reply command is parsed to obtain the system time of the host computer accurate to milliseconds. Finally, the difference between the system time and the reception time is calculated to obtain the actual time difference.
[0073] Step 103: Predict the time difference for the next moment based on the preset time difference prediction model, and determine the predicted time difference for the next moment with a preset accuracy; wherein, the preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points.
[0074] For example, the preset time difference prediction model is trained using training set data from multiple consecutive historical time points. The training set data includes the historical time differences for each corresponding time point. The time difference prediction model can predict the predicted time difference for the next time point based on multiple training datasets prior to the current time point. First, the current time point can be determined, along with a preset number of training datasets preceding it. Based on this preset number of training datasets, the time difference for the next time point is predicted using the preset time difference prediction model, thus determining a predicted time difference with a preset precision for the next time point.
[0075] For example, three training data sets prior to the current time are identified. For each of these three sets, the historical system time, the historical reception time, and the historical time difference between the historical system time and the historical reception time are determined. Combining these historical time differences from the three consecutive time points, a predicted time difference with a preset accuracy for the next time step is calculated and predicted.
[0076] Step 104: If the difference between the actual time difference and the predicted time difference meets the preset threshold, the predicted time difference is determined as the target time difference, and the actual time in the instrument is calibrated according to the target time difference to complete the time calibration operation.
[0077] For example, the instrument first determines the difference between the actual time difference and the predicted time difference, and compares the difference with a preset threshold, where the preset threshold is a pre-set critical value. If the difference between the actual time difference and the predicted time difference meets the preset threshold, the predicted time difference is determined as the target time difference. The target time difference is summed with the system time to obtain the target time, and the actual time in the instrument is replaced with the target time. At this point, the time in the instrument is the target time accurate to milliseconds, thus completing the time synchronization operation.
[0078] For example, if the preset threshold is 2%, and the difference is determined to be less than 2%, then the predicted time difference accurate to milliseconds is added to the system time of the host computer to obtain the target time.
[0079] In this embodiment, a time synchronization request is generated and sent to the host computer. Upon receiving the request, the host computer sends a time synchronization response instruction to the requester. This response instruction includes the host computer's system time with a preset precision. The actual time difference between the received time of the time synchronization response instruction and the system time is determined; the received time has a preset precision. A time difference prediction model is used to predict the time difference for the next moment, determining a predicted time difference with a preset precision for the next moment. This model is trained using training data from multiple consecutive historical time points. If the difference between the actual time difference and the predicted time difference meets a preset threshold, the predicted time difference is determined as the target time difference. The actual time within the instrument is then calibrated based on the target time difference to complete the time synchronization operation. In this scheme, a time synchronization request is generated and sent to the host computer. Upon receiving the request, the host computer immediately obtains its system time accurate to milliseconds and sends this millisecond-accurate system time as a time synchronization response instruction back to the instrument. The instrument receives the time synchronization reply command and determines the system time in the command. Since the received time and the system time have the same preset precision, the difference between the system time and the received time is used to obtain the actual time difference with the preset precision. Then, based on the preset time difference prediction model, the instrument predicts the time difference for the next moment, determining the predicted time difference with the preset precision. The instrument first determines the difference between the actual time difference and the predicted time difference and compares this difference with a preset threshold. If the difference between the actual time difference and the predicted time difference meets the preset threshold, the predicted time difference is determined as the target time difference. The instrument then calibrates the actual time within it based on the target time difference. At this point, the calibrated time within the instrument is the target time accurate to milliseconds, thus completing the time synchronization operation. Therefore, this application uses a time difference prediction model to predict the target time difference for the next moment and performs time synchronization operations on the instrument equipment based on the target time difference. This can effectively avoid time synchronization deviations caused by network anomalies or inconsistent upload and download transmission times, achieve automatic calibration of the clock preset accuracy, ensure the time accuracy of the instrument equipment, improve the billing accuracy of the instrument equipment, and solve the technical problem of low billing accuracy of the instrument equipment.
[0080] Figure 2 A flowchart illustrating another time synchronization method provided in this application embodiment is shown below. Figure 2 As shown, the method includes:
[0081] Step 201: Obtain training set data for each historical time point in multiple consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision.
[0082] In one example, the preset precision is milliseconds.
[0083] For example, at each of the multiple consecutive historical time points, the instrument device performs a time calibration operation and obtains a training dataset. Therefore, the instrument device can obtain the training set data for each of the multiple consecutive historical time points. The training set data includes the historical system time, the historical reception time, and the historical time difference between the historical system time and the historical reception time at the historical time point where the training set data is located. The historical time difference is the difference between the historical system time and the historical reception time, and the preset precision of the historical time difference is milliseconds.
[0084] Specifically, when the instrument records the historical time difference for each time synchronization operation, it uses the historical reception time minus the historical system time, requiring the historical time difference to be less than 5 seconds (S); otherwise, the historical time difference data for that time synchronization operation is discarded.
[0085] Step 202: Normalize the training data at each historical time point to obtain normalized training data.
[0086] For example, the instrument can perform maximum value normalization on the historical time difference for each historical time point, that is, divide the historical time difference by its maximum value each time. The normalization formula (1) is as follows:
[0087]
[0088] Among them, Fit i (i∈[1,2,…,n]) represents the training set data of the i-th sample in the historical time difference of the instrument equipment, Fit max Fi represents the maximum value of the sampled data, and Fi represents the normalized training set data.
[0089] Step 203: Train the initial prediction model using the normalized training set data to obtain the time difference prediction model.
[0090] In one example, step 203 includes: determining a preset number of adjacent historical time points in the normalized training set data based on preset test set partitioning criteria information; training the initial prediction model based on the preset number of adjacent historical time points to determine the preliminary time difference of the preset accuracy at the next moment; and correcting the initial prediction model based on the preliminary time difference of the preset accuracy at the next moment and the historical time difference corresponding to the preliminary time difference, until the prediction training stops when the next moment is the last historical time point of multiple consecutive historical time points, thereby generating a time difference prediction model.
[0091] For example, the instrument first establishes a prediction mechanism using a Long Short-Term Memory (LSTM) artificial neural network as the basic regression algorithm, and then constructs an initial prediction model based on the prediction mechanism. Next, the initial prediction model is trained using normalized training set data to obtain a time difference prediction model (i.e., an LSTM prediction model).
[0092] The preset test set partitioning criteria are pre-defined rules for partitioning the training dataset. For example, the test set partitioning criteria indicate that a preset number of training data sets are determined based on a preset dataset selection interval. Taking a dataset selection interval of 1 and a preset number of 3 as an example, the test set partitioning criteria use the historical time point furthest from the current time as the initial time point and the historical time point furthest from the current time point as the end time point. Starting from the initial time point, training data sets are determined for 3 adjacent historical time points. These 3 adjacent historical time points form the first set of training data. Similarly, starting from historical time points after the initial time point, training data sets for 3 adjacent historical time points are determined, thus obtaining the second set of training data, and so on. During the prediction training process, based on the pre-defined test set partitioning criteria, a first set of training data is determined from the normalized training data. The initial prediction model is then trained using this first set of training data to determine the output value with a pre-defined accuracy for the next time step. This output value is multiplied by the maximum value used for normalization to obtain the initial time difference for the next time step. Based on this initial time difference with pre-defined accuracy for the next time step, and the corresponding historical time differences, the initial prediction model is corrected. After correction, a second set of training data is determined from the normalized training data, and the initial prediction model is trained and corrected using this second set of training data. This process is iterated until the next time step is the last historical time point among multiple consecutive historical time points, at which point prediction training stops, and the time difference prediction model is generated.
[0093] For example, Figure 3 A flowchart illustrating another time synchronization method provided in this application embodiment is shown below. Figure 3 As shown, the constructed time difference prediction model consists of an input layer, a hidden layer, and an output layer; the output of the previous time node serves as the input of the next time node, and the final output is processed by linear regression to obtain the predicted value, which is the preliminary residual of the prediction.
[0094] The time difference prediction model incorporates a threshold mechanism: a forget gate f, an input gate i, an input gate o, and an internal memory unit c.
[0095] Forget gate f: determines how much of the cell state from the previous time step needs to be retained in the current time step. A value between 0 and 1 is calculated using the sigmoid function to control the degree of forgetting between the current layer input x_t and the output h_(t-1) of the previous hidden layer node. The calculation formula (2) is shown below:
[0096] f t =σ(W xr x t +W hf h t-1 +b r (2)
[0097] Where σ is the sigmoid function, W xf W hf W cf All are function coefficients, x t h is the input value for this layer. t-1 b is the output value of the previous hidden node. f For constant terms;
[0098] Input gate i: Determines how much of the network's input data at the current time step needs to be saved to the cell state. The value is calculated using the sigmoid function and the candidate vector value is generated using the tanh function. It will be added to the state, and the calculation formulas (3) and (4) are as follows:
[0099] i t =σ(W xi x t +W hi h t-1 +b i (3)
[0100]
[0101] Where σ is the sigmoid function, W xi W hi W xc W hc All are function coefficients, b i b c x is a constant term. t h is the input value for this layer. t-1 Output the value for the previous hidden node;
[0102] The time required to update the old cell state is calculated using the following formula (5):
[0103]
[0104] Input gate o: controls how much of the current cell state needs to be output to the current output value. The output data is calculated using the sigmoid function, and then processed by the tanh function to obtain a value between -1 and 1. The calculation formulas (6) and (7) are as follows:
[0105] o t =σ(W xo x t +W ho h t-1 +b o (6)
[0106] h t =o t *tanh(c t (7)
[0107] Therefore, based on the formulas mentioned above, the initial prediction model is trained and corrected, and this process is repeated until the next moment is the last historical time point of multiple consecutive historical time points, at which point the prediction training stops and a time difference prediction model is generated.
[0108] In one example, the prediction training process of the initial prediction model is as follows:
[0109] Step 1: Obtain the historical time difference obtained from the time calibration operation of the instrument equipment at multiple consecutive historical time points, as shown in Table 1 below;
[0110] Table 1
[0111] Historical Time Points 0:00 1:00 2:00 3:00 4:00 5:00 Historical time difference 3305 3802 3912 3817 3783 3734 Historical Time Points 6:00 7:00 8:00 9:00 10:00 11:00 Historical time difference 3712 3412 3215 3162 3126 3098
[0112] Step 2: Normalize the historical time difference data of the instruments and equipment to obtain the training set data;
[0113] From the historical flow meter calibration time difference data in Table 1, we can obtain: Fitmax = 3912
[0114] The data was normalized, and the results are shown in Table 2 below:
[0115] Table 2
[0116] 0:00 1:00 2:00 3:00 4:00 5:00 0.845 0.972 1 0.976 0.967 0.954 6:00 7:00 8:00 9:00 10:00 11:00 0.949 0.872 0.822 0.808 0.799 0.792
[0117] Step 3: Construct the LSTM prediction model, i.e., construct the preliminary prediction model, as shown in Table 3 below;
[0118] Table 3
[0119]
[0120] Step 4: Design the LSTM prediction model and LSTM optimizer for learning and training. The neural network of this LSTM prediction model consists of an input layer, hidden layers, and an output layer. The hidden layer has 6 neurons, and the learning rate lr = 0.01. The goal of the LSTM prediction model is to minimize the mean squared error between the predicted time difference and the actual time difference.
[0121] Step 5: Based on the custom parameters in the LSTM prediction model, input the training set data prepared in Step 3 into the LSTM prediction model designed in Step 4, and perform forward calculations according to the formulas (2) to (7) mentioned above. Reduce the loss function value through the LSTM optimizer and update the LSTM prediction model and the LSTM optimizer weight parameters ω. f ω i ω c and ω o The learned network weight parameters are obtained, and the training and correction of the LSTM prediction model are completed.
[0122] Step 6: The last three historical time points in each test set are used as input to the LSTM prediction model. The LSTM prediction model trained in Step 5 is applied to obtain the output value. The output value is multiplied by the maximum value used for normalization to obtain the preliminary time difference for the next time step. The prediction results are shown in Table 4 below:
[0123] Table 4
[0124]
[0125] The data in Table 4 shows that, except for 3:00, 4:00 and 7:00 when the error is larger due to communication peaks, the relative error between the predicted and actual values in other years is within 2%, which proves that the difference between the predicted and actual values is small and the fit is high. Therefore, the LSTM prediction model is corrected based on the predicted values with relative errors within 2% and the corresponding actual values, and the predicted values with relative errors outside 2% are removed.
[0126] Therefore, this application adopts edge computing combined with neural network model correction method, and uses LSTM algorithm to correct communication errors and automatically synchronize time, ensuring that the time synchronization error is within ±1 millisecond, and realizing time synchronization to the millisecond level.
[0127] Step 204: Generate a time synchronization request and send it to the host computer so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the sender. The time synchronization reply instruction includes the system time with preset accuracy of the host computer.
[0128] For example, this step can be referred to Figure 1 Step 101 in the text will not be repeated here.
[0129] Step 205: Determine the actual time difference between the received time of the time synchronization reply command and the system time, where the received time is a preset precision.
[0130] For example, the preset precision of the receiving time and the system time is the same, both accurate to milliseconds. The instrument can subtract the system time from the receiving time to obtain the actual time difference with the preset precision.
[0131] Step 206: Determine the current time and determine the preset number of training set data located before the current time.
[0132] For example, the instrument can determine the current time and a preset number of training datasets prior to the current time. For instance, if the current time is determined to be 9:00 AM in 2022, and multiple consecutive time points prior to 9:00 AM in 2022 have undergone time synchronization operations and obtained training datasets, then the training datasets of the three most recent consecutive time points prior to 9:00 AM in 2022 are selected, namely the training datasets at 8:30 AM in 2022, 8:00 AM in 2022, and 7:30 AM in 2022.
[0133] Step 207: Based on a preset amount of training data, predict the time difference for the next moment according to a preset time difference prediction model, and determine the predicted time difference for the next moment with a preset accuracy.
[0134] For example, based on the training dataset at 8:30 AM in 2022, the training dataset at 8:00 AM in 2022, and the training dataset at 7:30 AM in 2022, the instrument device can predict the time difference for the next moment according to the preset time difference prediction model and determine the predicted time difference for the next moment with a preset accuracy.
[0135] Step 208: If the difference between the actual time difference and the predicted time difference meets the preset threshold, then the predicted time difference is determined as the target time difference.
[0136] For example, the instrument first determines the difference between the actual time difference and the predicted time difference, and compares the difference with a preset threshold, where the preset threshold is a pre-set critical value. If the difference between the actual time difference and the predicted time difference is determined to meet the preset threshold, the predicted time difference is determined to be the target time difference.
[0137] Step 209: Sum the target time difference with the system time to obtain the target time.
[0138] For example, the instrument can add the target time difference to the system time to obtain the target time.
[0139] Step 210: Replace the actual time in the instrument with the target time to complete the time synchronization operation.
[0140] For example, the instrument can replace the actual time in the instrument with the target time. At this time, the time in the instrument is the target time accurate to the millisecond, thus completing the time synchronization operation.
[0141] In this embodiment, training set data for each historical time point from multiple consecutive historical time points is acquired. The training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference has a preset precision. The training set data for each historical time point is normalized to obtain normalized training set data. An initial prediction model is trained based on the normalized training set data to obtain a time difference prediction model. A time synchronization request is generated and sent to the host computer, so that the host computer, upon receiving the time synchronization request, sends a time synchronization response instruction to the requester. The time synchronization response instruction includes the host computer's system time with a preset precision. The actual time difference between the received time of the time synchronization response instruction and the system time is determined, where the received time has a preset precision. The current time is determined, and a preset number of training set data points preceding the current time are determined. Based on the preset number of training set data points, a time difference prediction is performed for the next time point according to the preset time difference prediction model, determining the predicted time difference with a preset precision for the next time point. If the difference between the actual time difference and the predicted time difference meets a preset threshold, the predicted time difference is determined as the target time difference. The target time is obtained by summing the target time difference with the system time. The actual time in the instrument is then replaced with the target time to complete the time synchronization operation. Therefore, this application uses a time difference prediction model to predict the target time difference for the next moment and performs time synchronization on the instrument based on the target time difference. This effectively avoids time synchronization deviations caused by network anomalies or inconsistent upload and download transmission times, achieves automatic calibration of the clock's preset accuracy, ensures the accuracy of the instrument's time, improves the accuracy of the instrument's billing, and solves the technical problem of low accuracy in the billing results of the instrument.
[0142] For example, Figure 4 A flowchart illustrating another time synchronization method provided in this application embodiment is shown below. Figure 4As shown, the instrument automatically triggers time synchronization, generates a time synchronization request, sends it to the host computer, and records the sending time of the request. Upon receiving the request, the host computer immediately obtains its system time and sends it back to the instrument as a time synchronization reply instruction. The instrument receives the reply instruction, records the receiving time, and obtains the host computer's system time from the reply instruction. Then, the instrument predicts the predicted time difference for the next moment based on a time difference prediction model. If the difference between the actual time difference and the predicted time difference meets a preset threshold, the predicted time difference is determined as the target time difference. The instrument then calibrates the actual time within its memory based on the target time difference, thus completing the time synchronization operation.
[0143] Figure 5 This is a schematic diagram of the structure of a time synchronization device provided in an embodiment of this application, as shown below. Figure 5 As shown, the device includes:
[0144] The generation unit 31 is used to generate a time synchronization request and send the time synchronization request to the host computer, so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the sender of the time synchronization request. The time synchronization reply instruction includes the system time with preset accuracy of the host computer.
[0145] The first determining unit 32 is used to determine the actual time difference between the receiving time of the received time synchronization reply instruction and the system time; wherein the receiving time is a preset precision.
[0146] The second determining unit 33 is used to predict the time difference of the next moment according to the preset time difference prediction model, and determine the predicted time difference of the next moment with a preset accuracy; wherein, the preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points.
[0147] The third determining unit 34 is used to determine the predicted time difference as the target time difference if the difference between the actual time difference and the predicted time difference meets a preset threshold.
[0148] The calibration unit 35 is used to calibrate the actual time in the instrument equipment according to the target time difference in order to complete the time calibration operation.
[0149] The apparatus in this embodiment can execute the technical solutions in the above method. Its specific implementation process and technical principles are the same, and will not be repeated here.
[0150] Figure 6 This is a schematic diagram of another time synchronization device provided in an embodiment of this application. Figure 5 Based on the illustrated embodiments, as Figure 6 As shown, the second determining unit 33 includes:
[0151] The first determining module 331 is used to determine the current time and determine a preset number of training set data located before the current time.
[0152] The second determining module 332 is used to predict the time difference of the next moment based on a preset amount of training set data and a preset time difference prediction model, and to determine the predicted time difference of the next moment with a preset accuracy.
[0153] In one example, calibration unit 35 includes:
[0154] The summation module 351 is used to sum the target time difference with the system time to obtain the target time.
[0155] Replacement module 352 is used to replace the actual time in the instrument with the target time.
[0156] In one example, the device also includes:
[0157] The acquisition unit 41 is used to acquire training set data for each historical time point in multiple consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision.
[0158] Normalization unit 42 is used to normalize the training set data at each historical time point to obtain normalized training set data.
[0159] Training unit 43 is used to train the initial prediction model based on the normalized training set data to obtain the time difference prediction model.
[0160] In one example, training unit 43 includes:
[0161] The third determining module 431 is used to determine a preset number of training set data points of adjacent historical time points in the normalized training set data based on the preset test set division standard information.
[0162] The fourth determining module 432 is used to perform prediction training on the initial prediction model based on a preset number of training sets of adjacent historical time points, and to determine the preliminary time difference of the preset accuracy for the next moment.
[0163] The generation module 433 is used to correct the initial prediction model based on the preliminary time difference with a preset accuracy for the next time moment and the historical time difference corresponding to the preliminary time difference, until the prediction training stops when the next time moment is the last historical time point of multiple consecutive historical time points, and the time difference prediction model is generated.
[0164] In one example, the preset precision is milliseconds.
[0165] The apparatus in this embodiment can execute the technical solutions in the above method. Its specific implementation process and technical principles are the same, and will not be repeated here.
[0166] Figure 7 This application provides a schematic diagram of the structure of an instrument device, as shown in the embodiment. Figure 7 As shown, the instrument equipment includes: memory 51 and processor 52.
[0167] The memory 51 stores a computer program that can run on the processor 52.
[0168] Processor 52 is configured to perform the methods provided in the embodiments described above.
[0169] The instrument also includes a receiver 53 and a transmitter 54. The receiver 53 is used to receive instructions and data sent by external devices, and the transmitter 54 is used to send instructions and data to external devices.
[0170] This application also provides a non-transitory computer-readable storage medium, which, when the instructions in the storage medium are executed by the processor of an instrument, enables the instrument to perform the method provided in the above embodiments.
[0171] This application also provides a computer program product, which includes a computer program stored in a readable storage medium. At least one processor of the instrument can read the computer program from the readable storage medium, and the at least one processor executes the computer program to cause the instrument to perform the solution provided in any of the above embodiments.
[0172] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0173] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A time synchronization method, characterized in that, include: A time synchronization request is generated and sent to the host computer, so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the sender of the time synchronization request, wherein the time synchronization reply instruction includes the system time with a preset accuracy of the host computer; Determine the actual time difference between the receiving time of the time synchronization reply command and the system time; wherein, the receiving time is a preset precision; The time difference is predicted for the next moment based on a preset time difference prediction model, and the predicted time difference for the next moment is determined with a preset accuracy. The preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points. The training set data includes the historical time difference of the corresponding historical time point. The preset time difference prediction model is used to predict the predicted time difference for the next moment with a preset accuracy based on the historical time difference training dataset of multiple consecutive time points. If the difference between the actual time difference and the predicted time difference is determined to meet a preset threshold, then the predicted time difference is determined to be the target time difference, and the actual time in the instrument is calibrated according to the target time difference to complete the time calibration operation.
2. The method according to claim 1, characterized in that, The step of predicting the time difference for the next moment based on a preset time difference prediction model, and determining the predicted time difference for the next moment with a preset accuracy, includes: Determine the current time and determine a preset number of training set data points prior to the current time; Based on the preset amount of training data, the time difference of the next moment is predicted according to the preset time difference prediction model, and the predicted time difference of the next moment with preset accuracy is determined.
3. The method according to claim 1, characterized in that, The calibration of the actual time within the instrument based on the target time difference includes: The target time is obtained by summing the target time difference with the system time. Replace the actual time in the instrument with the target time.
4. The method according to any one of claims 1-3, characterized in that, The method further includes: Acquire training set data for each historical time point from multiple consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision; The training set data at each historical time point is normalized to obtain normalized training set data. The initial prediction model is trained using normalized training set data to obtain the time difference prediction model.
5. The method according to claim 4, characterized in that, The step of training the initial prediction model based on normalized training set data to obtain the time difference prediction model includes: Based on the preset test set partitioning criteria, a preset number of training set data points with adjacent historical time points are determined in the normalized training set data; The initial prediction model is trained based on the preset number of training sets of adjacent historical time points to determine the preliminary time difference of the preset accuracy for the next moment. Based on the initial time difference with a preset accuracy for the next time moment, and the historical time difference corresponding to the initial time difference, the initial prediction model is corrected until the next time moment is the last historical time point of multiple consecutive historical time points, at which point the prediction training stops, and a time difference prediction model is generated.
6. A time synchronization device, characterized in that, include: A generation unit is used to generate a time synchronization request and send the time synchronization request to a host computer, so that when the host computer receives the time synchronization request, it sends a time synchronization reply instruction to the party that sent the time synchronization request, wherein the time synchronization reply instruction includes the system time with a preset accuracy of the host computer; The first determining unit is used to determine the actual time difference between the receiving time of the time synchronization reply instruction and the system time; wherein the receiving time is a preset precision. The second determining unit is used to predict the time difference of the next moment according to a preset time difference prediction model, and determine the predicted time difference of the next moment with a preset accuracy; wherein, the preset time difference prediction model is trained based on the training set data of each historical time point in multiple consecutive historical time points, the training set data includes the historical time difference of the corresponding historical time point, and the preset time difference prediction model is used to predict the predicted time difference of the next moment with a preset accuracy based on the historical time difference training dataset of multiple consecutive time points. The third determining unit is used to determine the predicted time difference as the target time difference if the difference between the actual time difference and the predicted time difference meets a preset threshold. The calibration unit is used to calibrate the actual time within the instrument based on the target time difference to complete the time synchronization operation.
7. The apparatus according to claim 6, characterized in that, The second determining unit includes: The first determining module is used to determine the current time and determine a preset number of training set data located before the current time; The second determining module is used to predict the time difference of the next moment based on the preset amount of training set data and a preset time difference prediction model, and to determine the predicted time difference of the next moment with a preset accuracy.
8. The apparatus according to claim 6, characterized in that, The calibration unit includes: The summation module is used to sum the target time difference with the system time to obtain the target time; The replacement module is used to replace the actual time in the instrument with the target time.
9. The apparatus according to any one of claims 6-8, characterized in that, The device further includes: An acquisition unit is used to acquire training set data for each historical time point in a plurality of consecutive historical time points; wherein, the training set data includes the historical time difference of the historical time point where the training set data is located, and the historical time difference is a preset precision; The normalization unit is used to normalize the training set data at each historical time point to obtain normalized training set data. The training unit is used to train the initial prediction model based on the normalized training set data to obtain the time difference prediction model.
10. An instrument device, characterized in that, The method includes a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the computer program to implement the method of any one of claims 1-5.
Citation Information
Patent Citations
Clock-aided satellite navigation receiver system for monitoring the integrity of satellite signals
US5931889A