## 4 Overview of the Proposed Error Recovery Mechanism
### The Proposed Error Recovery Mechanism
#### 4.3.2 Adaptive Error Recovery Mechanism
As shown in the algorithm, it iteratively finds the optimal number of extra encoded packets \(P_{\mathit{nep}}\) required at the destination for PER between 18%-100%, both for critical and non-critical medical applications. For every value of PER higher than 18%, it first calculates the corresponding PLR. If the PLR is higher than the maximum allowed range (\(PLR_{\mathit{cr-max}}\) or \(PLR_{\mathit{ncr-max}}\)) of the application, then the destination is provided with one \"extra\" encoded packet for each high priority sensor datum. This continues until PLR or \(y\) satisfy the application requirement. From the numerical method, it is found that for the considered network scenario, extra encoded packets \(P_{\mathit{nep}}\) for priority sensors vary from one to six, according to the PER. Equation 4 presents the minimum or optimum number of extra encoded packets required at the destination to achieve a PLR lower than 1% for high priority data. As every relay node (in the considered WBSN) receives the data only from six sensors, it cannot make more than five extra encoded packets. For example, R1 (Relay 1) receives the data from S1 (Sensor 1), S2, S3, S4, S5 and S6. This relay node is also responsible for making extra encoded packets for S1, S2 and S3. If S2 is a high priority sensor, R1 needs to make extra encoded packets for the data of S2. For this, the possible maximum number of combinations for R1 in providing the data of S2 is: \(S1\oplus S2\), \(S3\oplus S2\), \(S4\oplus S2\), \(S5\oplus S2\), \(S6\oplus S2\) and \(S2\oplus S2\). This is because XoR with itself (\(S2\oplus S2\)) provides zero. Hence, with the chosen network configuration 3, the proposed mechanism cannot provide the destination with more than five \"extra\" encoded packets and cannot provide the destination with an acceptable level of PLR for high priority data at PER higher than 52%. However, with a different network configuration, it will change. \[P_{\mathit{nep}}= \begin{cases}0&PER<18\%\\ 1&18\%>PER\leq 30\%\\ 2&30\%>PER\leq 40\%\\ 3&40\%>PER\leq 45\%\\ 4&45\%>PER\leq 49\%\\ 5&49\%>PER\leq 52\%\\ 6&52\%>PER\\ \end{cases}  \tag{3}\]  
Let us explain a scenario to show how the proposed adaptive error recovery mechanism works. Consider that S8 and S2 are identified by users as critical sensors at the PS or MS, and this message is propagated to the relay nodes. After that, the relay nodes (the concerned relay nodes) find the number of required extra encoded packets based on the current PER from which the channel is suffering (using Algorithm 1). Finally, once they receive the data from the priority nodes S2 or S8, they add those extra encoded packets for these nodes' packets. Thus, at the destination, say PS or MS, more information is available to recover the data from S2 and S8. The recovery mechanism at the MS or PS is presented in Algorithm 2. Figure 7a-c presents the packet coding schema for PER between 0%-18%, 18%-30% and 40%-45% respectively, when S2 and S8 are labeled as critical sensors. ```
1:\(x\) : current PER value
2:\(y\) : current PER's corresponding PLR
3:\(Ap_{criticality}\) : Criticality of the monitoring application type
4:\(P_{nep}\) : Optimal number of extra encoded packets
5:\(PLR_{cr-max}=.01\), maximum allowed PLR for critical applications
6:\(PLR_{ncr-max}\) : maximum allowed PLR for non-critical applications
7:if\(Ap_{criticality}=true\)then
8:while\(y\geq PLR_{cr-max}\)do
9:\(P_{nep}=P_{nep}+1\)
10: read current PER
11: calculate corresponding PLR or \(y\)
12:endwhile
13:else
14:while\(y\geq PLR_{ncr-max}\)do
15:\(P_{nep}=P_{nep}+1\)
16: read current PER
17: calculate corresponding PLR or \(y\)
18:endwhile
19:endif
```  
**Algorithm 1** : Network's channel condition and sensor priority-based adaptive encoding.