## 4 CL-APCC Protocol
### The Revised IEEE 802.11 Protocol of CL-APCC  
In this section, the IEEE 802.11 protocol is revised in order to decrease the transmission conflicts of data packets and ensure the fairness and timeliness of networks. In the network, there are different requirements of multi-data flow on reliability and sending timeliness, so it is necessary to have a priority control strategy in WSNs. In this paper, according to the sending priority and he service time of packets at the node, CL-APCC protocol makes a rule on how to deal with the priority of data packets. First, the revised IEEE 802.11 protocol method is described in general. The CL-APCC protocol dynamically adjusts the current competition window (CW) of a node based on the original priority and the service time of packets at the node. As the times of node's competition channel increase, the size of CW gradually decreases and accordingly results in an increase in the probability which acquires the current slot. Once the node competes to obtain slot in period \(t\), then its competition probability reduces to the minimum (CW = \(\beta\)CW\({}_{\max}\)) till the end of the period \(t\). Next, we describe the revised method of the IEEE 802.11 protocol in detail as follows:  
Node \(i\) is analyzed in a certain grid \(k\). Assume the waiting time is \(W_{i}^{q}\left(t_{1}\ t_{2}\right)\) which means packet \(q\) service time at the node \(i\), the length of packet \(q\) is \(L_{\max}^{q}\), the original priority of packet \(q\) is \(p_{initial}^{q}\left(t\right)\). So the sending priority of this packet is calculated as \(p_{i}^{q}\left(t\right)=p_{initial}^{q}\left(t\right)\times W_{i}^{q}\left(t_ {1}\ t_{2}\right).\) According to the feature of sending priority of packets, node \(i\) takes \(Max\left(p_{i}^{q}\left(t\right)\right)\) as a packet to be sent. At the beginning of period \(t\), node \(i\) sends the value of \(Max\left(p_{i}^{q}\left(t\right)\right)\) to the A-type node in the grid. After the integrated calculation of the A-type node, it can be obtained the sending probability of node \(i\) in the first slot as Equation (21). Concurrently, the A-type node notices the sending sequence of nodes to all nodes in the grid. Furthermore, each node maintains a counter to remember the sequence for the calculation of its sending probability and to deal with A-type node failure (as described in subsection 3.2). \[R_{i}\left(t\right)=\frac{p_{i}^{q}\left(t\right)\times W_{i}^{q}\left(t_{1},t _{2}\right)}{\sum\limits_{i=1}^{n}p_{i}^{q}\left(t\right)\times W_{i}^{q}\left( t_{1},t_{2}\right)} \tag{21}\]  
It will be divided into two situations to discuss the sending probability of node \(i\): 1 if node \(i\) can compete to obtain a sending slot at its own moment, then \(R_{i}(t)=0\), the other nodes in the grid will switch into the sleeping state in the next \(\left\lceil\ L_{\max}^{q}\middle/\mu_{real,i}\left(t\right)\right\rceil\) slot to save energy. When node \(i\) finishes sending a data packet, the other nodes in the grid begin to compete for the channel. 2 If node \(i\) doesn't compete to obtain the channel at the moment, it competes again after the node which has already competed to obtain slots and finished sending data. The sending probability of node \(i\) is updated as below:  
\[R_{i}\left(t\right)=R_{i}\left(t\right)+J\times\left(1-R_{i}\left(t\right) \right)\middle/n_{con}^{i} \tag{22}\]  
\(J\) is competition times and \(n_{con}^{i}\) is neighbor quantity in the communication range of node \(i\) (each node's value of \(n_{con}^{i}\) is different), it can show the scope of \(n_{con}^{i}\) in Figure 8.  
\[\left(N\times\pi\times r^{2}\right)\Big{/}\left(4\times L^{2}\right)\leq n_{ con}^{i}\leq\left(N\times\pi\times r^{2}\right)\Big{/}L^{2} \tag{23}\]  
At the end of the period \(t\), the A-type node in the grid turns to the next period of calculation for the average rate and node sending priority.