Disclosure of Invention
Aiming at the defects existing in the prior art, the invention provides a clock synchronization method of a wireless time-sensitive network in a spacecraft, which comprises the following steps:
s1, constructing a spacecraft internal wireless network, wherein the spacecraft internal wireless network comprises an Access Point (AP) and a Station (STA), the AP is used as a master clock, and the STA is used as a slave clock;
S2, the master clock and the slave clock acquire time information through Beacon frame communication, and the slave clock performs drift compensation according to the time information to realize coarse synchronization, wherein the time information comprises a Beacon frame sending time stamp and a Beacon frame arrival time stamp;
S3, the master clock and the slave clock carry out bidirectional time measurement communication, the slave clock obtains a time stamp required by calculating the average link propagation delay according to a communication result and calculates the first link propagation delay according to the time stamp;
s4, performing TDMA network time slot allocation according to the first link propagation delay, communicating the master clock and the slave clock by adopting a time measurement message of IEEE802.1AS protocol, and calculating a second link propagation delay;
And S5, the master clock and the slave clock carry out synchronous information transfer and complete clock synchronization according to the propagation delay of the second link.
Preferably, the process of the Beacon frame communication between the master clock and the slave clock includes:
s21, designing a wireless network card driving module and initializing the wireless network card driving module;
S22, based on the wireless network card driving module, under the WiFi network, periodically broadcasting a Beacon frame carrying a sending time stamp by a main clock;
S23, receiving and analyzing the Beacon frame from the clock, obtaining a Beacon frame sending time stamp and recording a Beacon frame arrival time stamp.
Further, the wireless network card driving module comprises a channel access control module, a link scheduling module, a synchronization module, a timer and a message queue;
the channel access control module is used for managing stations accessed to the AP;
The link scheduling module is used for scheduling the accessed stations in sequence;
the synchronization module is used for realizing a clock drift compensation algorithm to calibrate the local clock;
The timer is used for triggering the link scheduling module to perform link scheduling;
The message queue is used for interacting with the link scheduling module to realize message processing and sending.
Preferably, the process of drift compensation of the slave clock according to time information includes:
calculating an ith synchronous period clock drift amount rho i according to the time information, and predicting an (i+1) th synchronous period clock drift amount S i+1 according to the ith synchronous period clock drift amount;
If the Beacon frame sending time stamp is greater than the Beacon frame arrival time stamp, every other time Increasing the TSF timer of the slave clock by 1us, wherein T is the Beacon frame transmission period;
If the Beacon frame sending time stamp is equal to the Beacon frame arrival time stamp, the TSF timer of the slave clock is not adjusted;
if the Beacon frame transmission time stamp is smaller than the Beacon frame arrival time stamp, every other time The TSF timer of the slave clock is reduced by 1us.
Preferably, the process of two-way time measurement communication between the master clock and the slave clock includes:
S31, broadcasting a P delay_req link propagation delay measurement request frame from a clock to a wireless channel in each clock synchronous domain, and recording an initiating time t 1, wherein the P delay_req link propagation delay measurement request frame is packaged with the synchronous domain number of the current node;
S32, the master clock receives and analyzes the P delay_req frame at the time t 2, judges whether the synchronous domain number in the P delay_req frame is the same as the domain number of the current node, if so, discards the synchronous domain number, and if so, records the time t 2 and stores the source MAC address of the P delay_req frame;
S33, the master clock encapsulates time t 2 in a P delay_resp link propagation delay measurement response frame at time t 3, unicasts a P delay_resp frame to a wireless channel by taking the source MAC address of the P delay_req frame as a destination MAC address, and records time t 3;
S34, receiving and analyzing the P delay_resp frame at the time t 4 by the slave clock to obtain the time t 2 and recording the time t 2、t4;
And S35, the master clock sends a P delay_resp_follow_up message containing the time t 3 to the slave clock, and the slave clock records the time t 3.
Preferably, the formula for calculating the propagation delay of the first link is:
where P delay' represents the first link propagation delay, t 4 represents the time when the slave clock receives and parses the P delay_resp frame, t 1 represents the time when the slave clock initiates the P delay_req frame, r represents the clock frequency offset ratio of the master clock node, t 3 represents the time when the master clock unicasts the P delay_resp frame, and t 2 represents the time when the master clock receives and parses the P delay_req frame.
Preferably, the formula for calculating the propagation delay of the second link is:
Wherein P delay represents the second link propagation delay, D s represents the processing delay of the slave clock, W s represents the additional latency in sending the request from the slave clock, T phy,s represents the physical medium occupation time during the period from the sending of the request to the receiving of the request, D m represents the processing delay of the master clock, W m represents the additional latency in sending the response of the master clock, and T phy,m represents the physical medium occupation time during the period from the sending of the response to the receiving of the response.
Preferably, the process of synchronizing information transfer between the master clock and the slave clock and completing clock synchronization includes:
The master clock encapsulates the synchronization information in a Sync synchronization information transfer frame and broadcasts the Sync frame to the wireless channel, wherein the synchronization information comprises an original time stamp, a synchronization domain number, a clock frequency offset ratio and clock correction information of a current node;
judging whether the synchronous domain number in the frame is the same as the synchronous domain number of the current node, if so, discarding the synchronous domain number, and if so, recording the clock information in the Sync frame;
The slave clock corrects the slave clock according to the second link propagation delay and the clock information in the Sync frame, so as to realize accurate synchronization with the master clock.
Further, the formula for correcting the slave clock is:
Tsync=Torigin+Pdelay
where T sync denotes the corrected slave clock time, T origin denotes the original timestamp in the Sync frame, and P delay denotes the second link propagation delay.
The method has the advantages that the method obtains the link propagation delay between the slave clock and the master clock through a bidirectional clock measurement method, ensures that the nodes can timely send clock measurement messages and flexibly adjust time slot division according to different time slot demands of each node through a TDMA time slot distribution mode, ensures the instantaneity of related synchronous messages, furthest avoids the interference of other messages, and can ensure the stable transmission of the synchronous measurement messages in a network, thereby reducing the measurement error of the link delay and improving the clock synchronization precision of master-slave equipment.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The invention provides a clock synchronization method of a wireless time-sensitive network in a spacecraft, which is shown in fig. 1 and comprises the following steps:
S1, constructing a spacecraft internal wireless network, wherein the spacecraft internal wireless network comprises an Access Point (AP) and a Station (STA), the AP is used as a master clock, and the STA is used as a slave clock.
As shown in fig. 2, the wireless network inside the spacecraft includes an access point AP and a station STA, specifically, nodes in the wireless network inside the spacecraft may be divided into a sensor node, a terminal node, a wireless access point, a central controller, and the like, and the sensor and the mobile terminal in a certain area gather data to the central controller through the wireless network. The sensor nodes monitor the shell pressure, temperature and flight attitude of the spacecraft, the monitoring data has the characteristics of periodicity, relatively fixed traffic, relatively sensitive data end-to-end delay and the like, the transmission of time sensitive services is established on the basis of time synchronization between nodes and inside the nodes, and all devices can achieve consistency and execute required operations at the right time point only when the inside of each node has a common time reference.
And S2, the master clock and the slave clock acquire time information through Beacon frame communication, the slave clock performs drift compensation according to the time information to realize coarse synchronization, and the time information comprises a Beacon frame sending time stamp and a Beacon frame arrival time stamp.
S21, designing a wireless network card driving module and initializing the wireless network card driving module.
As shown in fig. 3, the wireless network card driving module includes a channel access control module, a link scheduling module, a synchronization module, a timer and a message queue, wherein the channel access control module is used for managing stations accessed to the AP, the link scheduling module is used for scheduling the accessed stations, the synchronization module is used for implementing a clock drift compensation algorithm to calibrate a local clock, the timer is used for triggering the link scheduling module to perform link scheduling, and the message queue is used for interacting with the link scheduling module to implement message processing and sending.
And S22, based on the wireless network card driving module, under the WiFi network, the master clock periodically broadcasts the Beacon frame carrying the sending time stamp.
In a wireless time-sensitive network, a master clock periodically generates a Beacon frame, an AP places the Beacon frame in a transmission buffer area for transmission, generates an interrupt when reaching one Beacon period, adds a transmission time stamp into a time stamp position reserved by the Beacon frame, and transmits the Beacon frame together with the Beacon frame.
S23, receiving and analyzing the Beacon frame from the clock to obtain a Beacon frame sending time stamp and recording the Beacon frame arrival time stamp
And generating an interrupt when receiving the Beacon frame sent by the AP, recording a receiving time stamp of the slave clock equipment, and analyzing the Beacon frame after receiving to obtain the Beacon frame sending time stamp.
The process of drift compensation of the slave clock according to the time information comprises:
The i-th synchronization period clock drift amount ρ i is calculated according to the time information, and the i+1th synchronization period clock drift amount S i+1 is predicted according to the i-th synchronization period clock drift amount.
Calculating the clock drift amount rho i of the ith synchronization period:
Wherein, The Beacon frame arrival time stamp representing the ith synchronization period,Beacon frame arrival time stamps representing the i-1 st synchronization period,The Beacon frame representing the i-th synchronization period transmits a time stamp,Beacon frame transmission time stamp indicating i-1 st synchronization period, i indicating the number of synchronization times.
According to the calculated clock drift amount rho i of the ith synchronous period, predicting the clock drift S i+1 of the next period by a primary exponential smoothing method:
Si+1=α×ρi+(1-α)×Si
Wherein α is a smoothing coefficient, 0.1-0.5 is taken, ρ i is a clock drift value actually calculated in the ith period, S i is a predicted clock drift value in the ith period, and S 1=ρ1.
The STA local clock drift between two clock adjustments is compensated with the predicted clock drift, the adjustment strategy is as follows:
If the Beacon frame sending time stamp is greater than the Beacon frame arrival time stamp Every other The TSF timer of the slave clock is incremented by 1us, where T is the Beacon frame transmission period.
If the Beacon frame transmission time stamp is equal to the Beacon frame arrival time stampNo adjustment is made to the TSF timer of the slave clock.
If the Beacon frame sending time stamp is smaller than the Beacon frame arrival time stampEvery other The TSF timer of the slave clock is reduced by 1us.
And S3, the master clock and the slave clock carry out bidirectional time measurement communication, and the slave clock obtains a time stamp required for calculating the average link propagation delay according to a communication result and calculates the first link propagation delay according to the time stamp.
The process of two-way time measurement communication between the master clock and the slave clock comprises the following steps:
Fig. 4 illustrates a wireless link propagation delay measurement phase, in which a slave clock device initiates a link propagation delay measurement request, and a master clock device processes the request and issues a response. The flow of the propagation delay measurement of the wireless network link is shown in fig. 5.
S31, broadcasting a P delay_req link propagation delay measurement request frame from a slave clock (slave clock equipment) to a wireless channel in each clock synchronous domain, and recording an initiating time t 1 at an initiating end, wherein the P delay_req link propagation delay measurement request frame is encapsulated with the synchronous domain number of the current node.
S32, the master clock (master clock equipment) receives and analyzes the P delay_req frame at the time t 2, judges whether the synchronous domain number in the P delay_req frame is the same as the domain number of the current node, discards the synchronous domain number if the synchronous domain number is different from the domain number of the current node, records the time t 2 at the receiving end and stores the source MAC address of the P delay_req frame if the synchronous domain number is the same as the domain number of the current node.
And S33, the master clock encapsulates the time t 2 in a P delay_resp link propagation delay measurement response frame at the time t 3, unicasts the P delay_resp frame to the wireless channel by taking the source MAC address of the P delay_req frame as a destination MAC address, and records the time t 3 at the master clock end.
S34, the slave clock receives and analyzes the P delay_resp frame at the time t 4, obtains the time t 2 and records the time t 2、t4 at the slave clock end.
And S35, the master clock sends a P delay_resp_follow_up message containing the time t 3 to the slave clock, and the slave clock records the time t 3.
The slave clock obtains a time stamp required for calculating the average link propagation delay according to the communication result and calculates the first link propagation delay according to the time stamp, wherein the calculation formula is as follows:
where P delay' represents the first link propagation delay, t 4 represents the time when the slave clock receives and parses the P delay_resp frame, t 1 represents the time when the slave clock initiates the P delay_req frame, r represents the clock frequency offset ratio of the master clock node, t 3 represents the time when the master clock unicasts the P delay_resp frame, and t 2 represents the time when the master clock receives and parses the P delay_req frame.
When the first link propagation delay is calculated, the coarse synchronization is finished, and then the fine synchronization process is carried out, wherein the specific process is as follows:
and S4, performing TDMA network time slot allocation according to the first link propagation delay, communicating the master clock and the slave clock by adopting time measurement messages of the IEEE802.1AS protocol, and calculating the second link propagation delay.
From the foregoing, it can be seen that, in the initialization phase before the system is started to arrive at the first time slot of the TDMA mode, the wireless access point AP measures the first link propagation delay of each link, that is, the average propagation delay of the link, through bidirectional delay measurement, and then, in the TDMA network, the AP allocates a corresponding time slot to each node (station). The superframe structure adopted by the invention is shown in fig. 6, wherein each slave clock-master clock pair is allocated a time slot pair, namely one time slot is used for sending request messages by the slave clock, and one time slot is used for sending response messages by the master clock. After time slots are allocated, a slave clock sends a request message, the sending time is recorded, a master clock receives the request and then sends a response message, and after the slave clock receives and analyzes the response message, the current average link propagation delay is calculated. And finally, the master clock transmits a synchronous message to the slave clock, and the slave clock carries out clock correction on the local clock according to the propagation delay and clock drift error, wherein the specific process is as follows:
the master clock and the slave clock communicate by using time measurement messages of IEEE802.1AS protocol:
As shown in fig. 7, in some preferred embodiments, each TDMA wheel is assumed to consist of N time slots. Without loss of generality, slot 0 of all rounds is dedicated to transmitting measurement requests from the slave clock end to the master clock end, and slot n of all rounds is dedicated to transmitting responses from the master clock end to the slave clock end.
As shown in fig. 8, fig. 8 shows a sequence of events in a feedback loop for measuring RTT by the slave clock STA and the master clock AP, specifically including:
Step 1, an interrupt is generated at the MAC layer from the clock STA before the transmission time slot is about to come, a measurement request frame is generated at time T 0, and a request M s is generated at time T 1. Thus, D s=T1-T0 is the time required to generate M s, D s is referred to as the processing delay of the slave clock device;
Step 2 STA waits to T 2, the beginning of slot 0 of the next TDMA round, to transmit M s to AP, resulting in additional STA waiting time W s=T2-T1.Ms requiring a certain transmission time, resulting in STA transmission delay. In fig. 8, the transmission time or delay is T 4-T2, where T 2 is the time when the STA transmits the first bit of M s and T 4 is the time when the STA transmits the last bit of M s;
Step 3. In the wireless channel, a propagation delay from STA to AP needs to be considered. The AP receives the first bit of M s at time T 3 and the last bit of M s at time T 5. There is T 5-T3=T4-T2 and the channel propagation delay is T 3-T2=T5-T4. The transmission delay and the propagation delay can be obtained, and the occupied time of the physical medium is T phy,s=T5-T2;
Step 4-after receiving M s, the AP processes it and generates a measurement response frame M m over some time, resulting in a processing delay for the AP. Suppose the interrupt starts generating M m at time T 6. Then the processing delay of the AP is D m=T6-T5;
Step 5 AP waits until time T 7 (beginning of slot n of TDMA round) to send M m to STA, resulting in additional AP latency W m=T7-T6;
Step 6, the first bit M m of the response arrives at STA at time T 8, and the last bit M m arrives at STA at time T 10. Thus, T 9-T7=T10-T8 is the transmission delay of the AP and T 8-T7=T10-T9 is the propagation delay of the server. The physical medium occupation time is T phy,m=T10-T7.
Thus, the RTT of the entire STA to AP consists of many delay elements, calculated as follows:
RTT=T10-T0=Ds+Ws+Tphy,s+Dm+Wm+Tphy,m
the formula for calculating the propagation delay of the second link is as follows:
Wherein P delay represents the second link propagation delay, D s represents the processing delay of the slave clock, W s represents the additional latency in sending the request from the slave clock, T phy,s represents the physical medium occupation time during the period from the sending of the request to the receiving of the request, D m represents the processing delay of the master clock, W m represents the additional latency in sending the response of the master clock, and T phy,m represents the physical medium occupation time during the period from the sending of the response to the receiving of the response.
And S5, the master clock and the slave clock carry out synchronous information transfer and complete clock synchronization according to the propagation delay of the second link.
In this embodiment, the clock synchronization protocol based on IEEE 802.1AS works in the data link layer, and the high-precision hardware timestamp is obtained by the MAC layer management entity MLME of IEEE 802.11.
In the synchronization information transfer stage, the master clock device broadcasts synchronization information to the wireless channel, and the clock information transfer process is shown in fig. 9, and specifically includes:
The master clock encapsulates the synchronization information in the Sync synchronization information transfer frame and broadcasts the Sync frame to the wireless channel, the synchronization information comprises an original time stamp, a synchronization domain number, a clock frequency offset ratio and clock correction information of the current node, preferably correctionField of the master clock node is 0, the clock frequency offset ratio is 1, and the Sync frame is broadcast to the wireless channel.
And judging whether the synchronous domain number in the frame is the same as the synchronous domain number of the current node, if so, discarding the synchronous domain number, and if so, recording the clock information in the Sync frame.
After obtaining the clock information in the Sync frame, the slave clock corrects the slave clock according to the second link propagation delay and the clock information in the Sync frame to realize accurate synchronization with the master clock, wherein the formula of the corrected slave clock is as follows:
Tsync=Torigin+Pdelay
Where T sync represents the corrected slave clock time and T origin represents the original timestamp in the Sync frame.
The invention realizes the coarse synchronization to ensure the normal operation of the TDMA network through a TSF mechanism, and avoids the conflict between the synchronous protocol message and other messages by combining the IEEE802.1AS synchronous protocol with the TDMA time slot, and can reduce the waiting time delay on the premise of ensuring the successful transmission of the synchronous protocol message in the wireless network, thereby reducing the synchronous error accumulated due to the processing time delay and the channel interference.
While the foregoing is directed to embodiments, aspects and advantages of the present invention, other and further details of the invention may be had by the foregoing description, it will be understood that the foregoing embodiments are merely exemplary of the invention, and that any changes, substitutions, alterations, etc. which may be made herein without departing from the spirit and principles of the invention.