## 4 Overview of the Proposed Error Recovery Mechanism
### The Proposed Error Recovery Mechanism
#### 4.3.3 Recovery Process  
Like the MP's mechanism, the proposed mechanism considers TDMA (time division multiple access) for channel access. When the sensor nodes send packets to the MS/PS using TDMA, the packets sent in the same TDMA frame are considered the same generation packets. Typically, in the relay nodes, the same generation's packets are encoded at the same time. Similarly, at the destination, the decoding process is done only with the packets of the same generation. For encoding, we have used the format shown in Figure 8, where the encoding vector \(\{m,n\}\) represents the sensor ID of the packets that are coded in the packet. For any packet with an encoding vector, where \(m\
eq n\), the payload is: \(P_{mn}=P_{m}\oplus P_{n}\); where \(P_{m}\) and \(P_{n}\) represent the packets received from the sensors \(S_{m}\) and \(S_{n}\), and \(m,n=1,2,...,12\) (or maximum number of sensors). If \(m=n\), the payload is \(P_{mm}=P_{m}\), and this is the uncoded packet \(P_{m}\) from sensor \(S_{m}\).  
During each TDMA cycle, the MS/PS receives \(P_{i,j}\) coded packets of the same generation and stores them in the memory. After that, they are buffered, and pointers (\(A_{i,j}\)) to the first byte of each packet (\(P_{i,j}\)) are written in the decoding matrix \(D(n,n)\) (shown in Equation 4).  
At the end of every communication cycle, the recovery process (as shown in Figure 9 ) at MS/PS is done in two steps:  
Step 1. As \(P_{m}\oplus P_{n}=P_{n}\oplus P_{m}\), \(D_{nn}\) (Equation 2) is updated in such way that: if \(D(m,n)\
eq 0\), then \(D(n,m)=D(m,n)\), and both pointers point to the same packet \(P_{m,n}=P_{n,m}\).  
Step 2. As \(P_{m}=P_{k}\oplus(P_{k}\oplus P_{m})\), packets are recovered using the following rule: if (\(D(k,k)\
eq 0\) & \(D(k,m)\
eq 0\)), then \(P_{m,m}=P_{k,k}\oplus P_{k,m}\); recovered packet \(P_{m,m}\) is stored in buffer, and matrix \(D(n,n)\) is modified to contain the pointer to that packet \(D(m,m)=A_{m,m}\).  
Figure 8: Packet format considered in the proposed mechanism.  
Figure 7: Packet coding schema for PER (in percentage) between (**a**) \(0\)–\(18\), (**b**) \(18\)–\(30\) and (**c**) \(40\)–\(45\) for S2 and S8 as critical sensors.  
Step 2 is repeated until all of the packets are reconstructed. Once this is done, the matrix \(D\) is then emptied to make it ready for the next communication cycle. These steps are summarized as Algorithm 2.  
\[D(n,n)=\begin{pmatrix}A_{1,1}&A_{1,2}&0&0&A_{1,5}&\cdots&A_{1,n}\\ 0&0&A_{2,3}&0&A_{2,5}&\cdots&0\\ A_{3,1}&0&0&A_{3,4}&0&\cdots&0\\ A_{4,1}&0&0&A_{4,4}&0&\cdots&0\\ \vdots&&&\vdots&\vdots&&\\ A_{n,1}&0&0&A_{n,4}&0&\cdots&A_{n,n}\end{pmatrix} \tag{4}\]  
where:  
\(D(i,j)=0(Null)\): if \(P_{i,j}\) was not received or does not exist;  
\(D(i,j)\
eq 0,i=j\): if \(P_{i}\) was received and stored in memory;  
\(D(i,j)\
eq 0,i\
eq j\): if \(P_{i,j}(=P_{i}\oplus P_{j})\) was reviewed and buffered.  
```
1:Step 1:
2:for\(i=1\) to \(12\)do
3:for\(j=1\) to \(12\)do
4:if\(D(i,j)\
eq 0\)then
5:\(D(j,i)=D(i,j)\) {Both pointers point to the same packet}
6:endif
7:endfor
8:endfor
9:Step 2:
10:\(V_{repeat}=1\)
11:while\(V_{repeat}>0\)do
12:for\(i=1\) to \(12\)do
13:if\(D(i,i)\
eq 0\)then
14:for\(j=1\) to \(12\)do
15:if\(D(i,j)\
eq 0\) & \(D(j,j)\
eq 0\)then
16:\(P_{j,j}=P_{i,i}\oplus P_{i,j}\) {Recovered \(P_{j}=P_{i}\oplus(P_{i}\oplus P_{j})\)}
17:\(D(j,j)=Aj,j\) {Packet \(P_{j}\) is buffered and pointer in \(D(n,n)\)}
18:\(V_{repeat}=1\)
19:endif
20:endfor
21:endif
22:endfor
23:endwhile
```  
**Algorithm 2** : Recovery process at Personal Server /monitoring station (MS).