A software and hardware multi-level synchronous acquisition method based on process conflict judgment
By unifying the clock source of the sampling device is Beidou time, combined with the Ricart-Agrawala algorithm and differential interpolation processing, the clock inconsistency and process conflicts in the synchronous acquisition of hardware and software is solved, and high-precision synchronous acquisition of multi-device is achieved.
Patent Information
- Application Number
- CN202211189687.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-28
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2042-09-28
AI Technical Summary
In the existing synchronous acquisition technology, different hardware clock sources lead to inconsistent sampling moments, different software sampling frequency leads to difficulty in synchronous acquisition, and process conflicts are prone to occur during multi-thread synchronization, resulting in synchronization errors and locking.
By unifying the clocks of different sampling devices into Beidou time, the Ricart-Agrawala algorithm is used to realize the synchronous acquisition of software devices, and differential interpolation is used to process the data of devices of different sampling frequency devices to realize the synchronous acquisition of software and hardware.
It effectively reduces the synchronization errors between hardware and software, ensures synchronous acquisition of multi-sampling devices at the same time, and improves synchronization accuracy and data processing synchronization.
Smart Images

Figure CN115580366B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of synchronous acquisition, and in particular to a software and hardware multi-level synchronous acquisition method based on process conflict judgment, which realizes synchronous acquisition of software and hardware by using a differential method based on realizing synchronous acquisition of software and hardware respectively. Background Art
[0002] The current synchronous acquisition technology is mainly based on multi-channel acquisition technology controlled by single-chip microcomputers and communication control based on wireless sensor networks. There are synchronization errors in both hardware and software. The hardware error is mainly reflected in the different clock sources of different sampling devices and the occurrence of clock drift. The software error is mainly reflected in the inability to achieve synchronous acquisition due to the different sampling frequencies of different sampling devices, and the occurrence of process conflicts in the multi-threaded synchronous acquisition process. In order to solve these problems, a synchronous acquisition technology for multi-sampling devices based on interpolation and a multi-threaded soft synchronization control algorithm are proposed.
[0003] In order to solve the problem of inconsistent sampling time due to different clock sources of hardware devices in the present invention, the sampling time is first uniformly converted into the format of seconds in the week of Beidou time, and the clock drift and cumulative error are reduced by real-time calibration with Beidou time. Secondly, in order to solve the process conflict in software synchronous acquisition, the Ricart-Agrawala algorithm is used to realize soft synchronous acquisition. Finally, due to the problem that the sampling frequency of the sampling devices is different and it is impossible to sample at the same time, it is proposed to interpolate the collected data based on the idea of difference, and solve the sampling information of the target time by interpolating the sampling data of adjacent moments, so that different sampling devices can obtain sampling information at the same time. Summary of the invention
[0004] The present invention proposes a method for realizing synchronous acquisition of hardware and software by using a differential method based on realizing synchronous acquisition of software and hardware. Firstly, the clock sources of different devices are unified and converted into Beidou time. Secondly, the Ricart-Agrawala algorithm is used to realize synchronous acquisition of multiple sampling devices based on software. Finally, the synchronous acquisition of software and hardware is realized by using differential method.
[0005] Step 1: Unify the clocks of different acquisition systems
[0006] There are two main data collection methods for different sampling devices: hardware-triggered and software-timestamp-controlled. Hardware-triggered sampling devices use Beidou clock pulses as a benchmark, while software-timestamp-controlled sampling devices generally use GPS time. In order to unify the clock source with hardware-triggered sampling devices, the GPS clock needs to be uniformly converted into Beidou time.
[0007] Beidou time is based on 00:00:00 on January 1, 2006, and GPS time is based on 00:00:00 on January 6, 1980. For example, the time recorded by the timestamp is the seconds of the week in GPS. The week of the current time is week, and the seconds of the week are wis. The Beidou week is bdsweek, and the seconds of the week are bdswis.
[0008] Sub-step 1.1: Calculate the total number of seconds at the current GPS time
[0009] GPStime = week * 604800 + wis
[0010] Sub-step 1.2: Convert the current calculated total seconds into the total seconds of Beidou time
[0011] time = gpstime-14-1256*604800
[0012] Sub-step 1.3: Convert the current total number of seconds into Beidou time seconds in the week format
[0013] bdsweek=time / 604800
[0014] bdswis=time%604800
[0015] For sampling devices based on single-chip frequency division control, the Beidou time-week second time corresponding to the rising edge of the sampling moment can also be obtained through networking, thereby unifying the data collection time of different sampling devices into the same time system, which is an important basis for controlling different sampling devices to perform synchronous collection.
[0016] Step 2: Use the Ricart-Agrawala algorithm to perform synchronous acquisition of multiple sampling devices
[0017] For software-based synchronous data collection of multiple sampling devices, thread conflicts may cause process locks or idle waiting. In order to effectively solve this problem, this patent adopts the Ricart-Agrawala algorithm, using a logical clock instead of a timing clock to allow multiple sampling devices to execute sequentially in the shortest possible time, approximately achieving the goal of multi-program soft synchronization.
[0018] In order to transform the sequential clock into a logical clock, the timestamp is defined as follows:
[0019] a) Each event corresponds to a Ricart-Agrawala timestamp, with an initial value of 0;
[0020] b) If the event occurs within the node, the timestamp in the local process is incremented by 1;
[0021] c) If the event is a send event, the timestamp in the local process is incremented by 1 and the timestamp is included in the message;
[0022] d) If the event is a received event, the timestamp in the local process = Max (local timestamp, timestamp in the message) + 1;
[0023] Based on the four definitions, the original sequential time system is arranged according to the logical time system to ensure that events are executed in sequence according to the logical order, and then used to solve the problem of distributed locks.
[0024] Sub-step 2.1: When sampling device P i When requesting data collection, first broadcast the request Request to all other sampling devices (t i , P i ), other sampling devices save the request to the local request queue. After receiving the request, other sampling devices (receivers) will make the following decisions:
[0025] a) If you have not requested data collection and are not currently collecting data, just replay;
[0026] b) If you are requesting data collection, but the timestamp of the request sent by the recipient is greater than the timestamp of the request message, you can also directly replay it;
[0027] c) If it is neither of the above two situations, that is, after receiving the request message, the receiver finds that it needs to enter data collection earlier than this request, then it first records a local array RD[P i ]=1, indicating a delayed reply to a request from sampling device Pi.
[0028] Sub-step 2.2: A sampling device can only start data sampling after receiving the Replay of all sampling devices. After completing data collection, the delayed Replay should be sent out according to the records in the RD array.
[0029] The Ricart-Agrawala algorithm removes the Release message. That is, when a sampling device completes sampling, the signal to notify other sampling devices that they can start data sampling no longer needs to be notified through the Release signal. Instead, the delayed Replay signal is complemented to make other sampling devices meet the conditions for sampling (at this time, the previous sampling device has completed sampling), and then sampling can be carried out directly.
[0030] Step 3: Interpolate the sampling information collected by devices with different sampling frequencies
[0031] Usually, different sampling devices have different sampling frequencies and cannot collect data synchronously at the same time. In order to obtain the sampling data of the two at the same time, it is necessary to use the interpolation method to interpolate the sampling information and solve the sampling information at any time, so as to obtain the synchronous collection information of different sampling devices at the same time.
[0032] For hardware devices with sampling frequencies of f1 and software devices with sampling frequencies of f2, in order to unify the sampling frequencies of the two devices, the cubic interpolation method is used to interpolate and fit the data collected by the hardware devices.
[0033] For a hardware device with a sampling frequency of f1, each The information will be collected once. The sampling frequency of the software device is f2, every The data will be collected. The time when the two samples are first collected together is recorded as exist Both will work at the same time, but Only software devices can sample, and hardware devices cannot sample, so the information collected by the hardware devices is interpolated.
[0034] The time t at which any software sampling device does not sample simultaneously with the hardware sampling device k , the sampling information of the hardware device is interpolated and fitted using the cubic interpolation method, so as to obtain the state quantity of the hardware sampling device at that moment.
[0035] Sub-step 3.1: Find the sampling information near the point to be interpolated
[0036] Because the sampling information is attached with the timestamp of the sampling time, the timestamp can be used to determine the sampling information near the target time. k The four groups of sampling information near the time can be used to extract the sampling information of the hardware device in sequence.
[0037] Sub-step 3.2: Differentially solve the sampling information at the target time
[0038] Let the hardware device sample t at the corresponding time k0 ,t k1 ,t k2 ,t k3 The state quantities at each moment are h k0 ,h k1 ,h k2 ,h k3 For t k The state at the moment is h k
[0039] h k =((h k3 -hk2 )-(h k0 -h k1 ))t 3 +(2(h k0 -h k1 )-(h k3 -h k2 ))t 2 +(h k2 -h k0 )t+h k1
[0040]
[0041] By using the cubic interpolation formula, the hardware sampling information corresponding to any software sampling time can be approximately solved, so that the sampling device based on hardware control and the sampling device controlled by software can realize data synchronous acquisition.
[0042] Compared with the prior art, the beneficial effects of the present invention are: ensuring the synchronization of multi-sensor information from two aspects of software and hardware acquisition and data processing, and having high synchronization accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0044] With the development of wireless sensor networks and the diversification and popularization of sampling equipment, synchronous acquisition technology has become increasingly important. Currently, the mainstream synchronous acquisition technologies are mainly divided into time synchronization and space synchronization. This patent mainly explains the time synchronization acquisition technology.
[0045] The purpose of the present invention is to realize the synchronous acquisition of hardware and software of multiple sampling devices by differential method on the basis of realizing synchronous control of sampling devices controlled by hardware and sampling devices controlled by software. The specific steps include:
[0046] Step 1: Unify the clocks of different acquisition systems
[0047] The sampling equipment based on hardware triggering uses Beidou clock pulse as the benchmark, while the software sampling equipment based on timestamp control generally uses GPS time. In order to unify the clock source with the sampling equipment triggered by hardware, the GPS clock needs to be uniformly converted into Beidou time.
[0048] Beidou time is based on 00:00:00 on January 1, 2006, and GPS time is based on 00:00:00 on January 6, 1980. For example, the time recorded by the timestamp is the seconds of the week in GPS. The week of the current time is week, and the seconds of the week are wis. The Beidou week is bdsweek, and the seconds of the week are bdswis.
[0049] Sub-step 1.1: Calculate the total number of seconds at the current GPS time
[0050] GPStime = week * 604800 + wis
[0051] Sub-step 1.2: Convert the current calculated total seconds into the total seconds of Beidou time
[0052] time = gpstime-14-1256*604800
[0053] Sub-step 1.3: Convert the current total number of seconds into Beidou time seconds in the week format
[0054] bdsweek=time / 604800
[0055] bdswis=time%604800
[0056] For sampling devices based on single-chip frequency division control, the Beidou time-week second time corresponding to the rising edge of the sampling moment can also be obtained through networking, thereby unifying the data collection time of different sampling devices into the same time system, which is an important basis for controlling different sampling devices to perform synchronous collection.
[0057] Step 2: Use the Ricart-Agrawala algorithm to perform synchronous acquisition of multiple sampling devices
[0058] For software-based synchronous data collection of multiple sampling devices, thread conflicts may cause process locks or idle waiting. In order to effectively solve this problem, this patent adopts the Ricart-Agrawala algorithm, using a logical clock instead of a timing clock to allow multiple sampling devices to execute sequentially in the shortest possible time, approximately achieving the goal of multi-program soft synchronization.
[0059] In order to transform the sequential clock into a logical clock, the timestamp is defined as follows:
[0060] a) Each event corresponds to a Ricart-Agrawala timestamp, with an initial value of 0;
[0061] b) If the event occurs within the node, the timestamp in the local process is incremented by 1;
[0062] c) If the event is a send event, the timestamp in the local process is incremented by 1 and the timestamp is included in the message;
[0063] d) If the event is a received event, the timestamp in the local process = Max (local timestamp, timestamp in the message) + 1;
[0064] Based on the four definitions, the original sequential time system is arranged according to the logical time system to ensure that events are executed in sequence according to the logical order, and then used to solve the problem of distributed locks.
[0065] Sub-step 2.1: When sampling device P i When requesting data collection, first broadcast the request Request to all other sampling devices (t i , P i ), other sampling devices save the request to the local request queue. After receiving the request, other sampling devices (receivers) will make the following decisions:
[0066] a) If you have not requested data collection and are not currently collecting data, just replay;
[0067] b) If you are requesting data collection, but the timestamp of the request sent by the recipient is greater than the timestamp of the request message, you can also directly replay it;
[0068] c) If it is neither of the above two situations, that is, after receiving the request message, the receiver finds that it needs to enter data collection earlier than this request, then it first records a local array RD[P i ]=1, indicating delayed response sampling device P i A request.
[0069] Sub-step 2.2: A sampling device can only start data sampling after receiving the Replay of all sampling devices. After completing data collection, the delayed Replay should be sent out according to the records in the RD array.
[0070] The Ricart-Agrawala algorithm removes the Release message. That is, when a sampling device completes sampling, the signal to notify other sampling devices that they can start data sampling no longer needs to be notified through the Release signal. Instead, the delayed Replay signal is complemented to make other sampling devices meet the conditions for sampling (at this time, the previous sampling device has completed sampling), and then sampling can be carried out directly.
[0071] Step 3: Interpolate the sampling information collected by devices with different sampling frequencies
[0072] Usually, different sampling devices have different sampling frequencies and cannot collect data synchronously at the same time. In order to obtain the sampling data of the two at the same time, it is necessary to use the interpolation method to interpolate the sampling information and solve the sampling information at any time, so as to obtain the synchronous collection information of different sampling devices at the same time.
[0073] For hardware devices with sampling frequencies of f1 and software devices with sampling frequencies of f2, in order to unify the sampling frequencies of the two devices, the cubic interpolation method is used to interpolate and fit the data collected by the hardware devices.
[0074] For a hardware device with a sampling frequency of f1, each The information will be collected once. The sampling frequency of the software device is f2, every The data will be collected. The time when the two samples are first collected together is recorded as exist Both will work at the same time, but Only software devices can sample, and hardware devices cannot sample, so the information collected by the hardware devices is interpolated.
[0075] The time t at which any software sampling device does not sample simultaneously with the hardware sampling device k , the sampling information of the hardware device is interpolated and fitted using the cubic interpolation method, so as to obtain the state quantity of the hardware sampling device at that moment.
[0076] Sub-step 3.1: Find the sampling information near the point to be interpolated
[0077] Because the sampling information is attached with the timestamp of the sampling time, the timestamp can be used to determine the sampling information near the target time. k The four groups of sampling information near the time can be used to extract the sampling information of the hardware device in sequence.
[0078] Sub-step 3.2: Differentially solve the sampling information at the target time
[0079] Let the hardware device sample t at the corresponding time k0 ,t k1 ,t k2 ,t k3 The state quantities at each moment are h k0 ,h k1 ,h k2 ,h k3 For t k The state at the moment is h k
[0080] h k =((h k3 -h k2 )-(h k0 -h k1 ))t 3 +(2(h k0 -h k1 )-(h k3 -h k2 ))t2 +(h k2 -h k0 )t+h k1
[0081]
[0082] By using the cubic interpolation formula, the hardware sampling information corresponding to any software sampling time can be approximately solved, so that the sampling device based on hardware control and the sampling device controlled by software can realize data synchronous acquisition.
[0083] Method Validation:
[0084] For distributed systems, it is necessary to control which process can access critical area resources (such as CPU) through message passing. To evaluate whether the distributed system can achieve this goal, three algorithm indicators are proposed:
[0085] a) ME1 security: at most one process is using the critical section at the same time, and no multiple processes can be executed in the critical section at the same time
[0086] b) ME2 activity: There will be no conflicts between processes that cause them to be locked in the critical section, and there will be no conflicts that prevent the critical section from being used.
[0087] c) ME3 fairness: For processes, the principle of sequential execution (FIFO) is followed, and first come first served.
[0088] The Ricart-Agrawala algorithm is verified using these three algorithm indicators
[0089] a) ME1: For two processes P i and P j If they can enter the critical section at the same time, they must have sent Replay messages to each other at the same time. However, because the queue is sorted in timestamp order, Replay also has a sequence. Therefore, only when a process broadcasts the Release signal when exiting from the critical section can another process be allowed to enter.
[0090] b) ME2: Assume that process P i After the execution is completed in the critical section, when it leaves the critical section, a delayed Replay signal will be sent. Other processes can enter the critical section only after receiving the Replay signal, so that deadlock will not occur.
[0091] c) ME3: Process P i First broadcast the request to enter the critical section r i , then process P j Broadcast a request to enter the critical section r j, add P j First enter the critical section, indicating r j The timestamp is greater than r i , which is not true, because the Ricart-Agrawala algorithm will pass r i and r j The timestamp of the request is used to determine whether to replay immediately or delay replay, so that the request r sent first can be i First get Replay to enter the critical section.
[0092] After verification, it can be concluded that the Ricart-Agrawala algorithm can be used to achieve multi-threaded soft synchronization acquisition of different data acquisition devices, which meets the requirements.
[0093] The hardware synchronous acquisition technology and the acquisition technology of multiple sampling devices based on software synchronization proposed in the present invention are feasible. On this basis, the synchronous acquisition of software and hardware sampling devices at different sampling frequencies is realized through cubic interpolation. Compared with traditional synchronous acquisition technology, it has wider applicability and universality.
Claims
1. A software and hardware multi-level synchronous acquisition method based on process conflict judgment, characterized in that: Based on the sampling results of software and hardware, the sampling results at the corresponding sampling frequency are obtained by differential means to achieve synchronous acquisition of software and hardware. The specific steps include: Step 1: Unify the clocks of different acquisition systems The sampling device based on hardware triggering uses Beidou clock pulse as the benchmark, while the software sampling device based on timestamp control uses GPS time. In order to unify the clock source with the sampling device triggered by hardware, the GPS clock is uniformly converted into Beidou time; Beidou time is based on 00:00:00 on January 1, 2006, and GPS time is based on 00:00:00 on January 6, 1980. The time recorded by the timestamp is the seconds in the week of GPS. The week of the current time is week, and the seconds in the week are wis. The week converted to Beidou is bdsweek, and the seconds in the week are bdswis. Sub-step 1.1: Calculate the total number of seconds at the current GPS time GPStime = week * 604800 + wis Sub-step 1..2: Convert the total number of seconds currently calculated into the total number of seconds in Beidou time time = gpstime-14-1256*604800 Sub-step 1.3: Convert the current total number of seconds into Beidou time seconds in the week format bdsweek=time / 604800 bdswis=time%604800 For sampling devices based on single-chip frequency division control, the Beidou time-week second time corresponding to the rising edge of the sampling time can also be obtained through networking, thereby unifying the data collection time of different sampling devices into the same time system, which is an important basis for controlling different sampling devices to perform synchronous collection; Step 2: Use the Ricart-Agrawala algorithm to perform synchronous acquisition of multiple sampling devices For software-based synchronous data acquisition of multiple sampling devices, thread conflicts may cause process lock or idle waiting. In order to effectively solve this problem, the Ricart-Agrawala algorithm is used to use logical clocks instead of timing clocks to allow multiple sampling devices to execute sequentially in the shortest possible time, approximately achieving the goal of multi-program soft synchronization. In order to transform the sequential clock into a logical clock, the timestamp is defined as follows: a) Each event corresponds to a Ricart-Agrawala timestamp, with an initial value of 0; b) If the event occurs within the node, the timestamp in the local process is incremented by 1; c) If the event is a send event, the timestamp in the local process is incremented by 1 and the timestamp is included in the message; d) If the event is a received event, the timestamp in the local process = Max (local timestamp, timestamp in the message) + 1; Based on the four definitions, the original sequential time system is arranged according to the logical time system to ensure that events are executed in a logical order, and then used to solve the distributed lock problem; Sub-step 2.1: When sampling device P i When requesting data collection, first broadcast the request Request to all other sampling devices (t i , P i ), other sampling devices save the request to the local request queue. After receiving the request, other sampling devices (receivers) will make the following decisions: a) If you have not requested data collection and are not currently collecting data, just replay; b) If you are requesting data collection, but the timestamp of the request sent by the recipient is greater than the timestamp of the request message, you can also directly replay it; c) If it is neither of the above two situations, that is, after receiving the request message, the receiver finds that it needs to enter data collection earlier than this request, then it first records a local array RD[P i ]=1, indicating delayed response sampling device P i A request of Sub-step 2.2: A sampling device can only start data sampling after receiving the Replays from all sampling devices; after completing data collection, the delayed Replays must be sent out according to the records in the RD array; The Ricart-Agrawala algorithm removes the Release message. That is, when a sampling device completes sampling, the signal to notify other sampling devices to start data sampling no longer needs to be notified through the Release signal. Instead, the delayed Replay signal is used to complete the delay so that other sampling devices meet the conditions for sampling. At this time, the previous sampling device has completed sampling, and then sampling can be carried out directly. Step 3: Interpolate the sampling information collected by devices with different sampling frequencies Different sampling devices have different sampling frequencies and cannot be collected synchronously at the same time. In order to obtain the sampling data of the two at the same time, it is necessary to use the interpolation method to interpolate the sampling information and solve the sampling information at any time, so as to obtain the synchronous collection information of different sampling devices at the same time. For hardware devices with sampling frequencies of f1 and software devices with sampling frequencies of f2, in order to unify the sampling frequencies of the two devices, the cubic interpolation method is used to interpolate and fit the data collected by the hardware devices. For a hardware device with a sampling frequency of f1, each The information will be collected once; the software device with sampling frequency f2, every Data collection will be performed; the time when the two samples are first collected together is recorded as exist Both will work at the same time, but When only the software device samples, the hardware device cannot sample, so the information collected by the hardware device is interpolated; The time t at which any software sampling device does not sample simultaneously with the hardware sampling device k , use the cubic interpolation method to interpolate and fit the sampling information of the hardware device, so as to obtain the state quantity of the hardware sampling device at that moment; Sub-step 3.1: Find the sampling information near the point to be interpolated Because the sampling information is attached with the timestamp of the sampling time, the timestamp is used to determine the sampling information near the target time; in order to find t k Four sets of sampling information near the time are used to extract the sampling information of the hardware devices in turn; Sub-step 3.2: Differentially solve the sampling information at the target time Let the hardware device sample t at the corresponding time k0 ,t k1 ,t k2 ,t k3 The state quantities at each moment are h k0 ,h k1 ,h k2 ,h k3 For t k The state at the moment is h k The cubic interpolation formula is used to approximately solve the hardware sampling information corresponding to any software sampling time; thereby achieving synchronous data acquisition between the sampling device based on hardware control and the sampling device based on software control.
Citation Information
Patent Citations
Integration unit for electric energy quality monitoring and synchronous sampling method of integration unit
CN103116096A
Non-data-aided parallel clock synchronizing method and system
CN103812594A
