# RDSP: Rapidly Deployable Wireless Ad Hoc System for Post-Disaster Management
## 3 System Architecture of the RDSP Scheme
As shown in step 2, the server device continuously waits for the detection of \(R_{msg}\). If \(R_{msg}\) is detected, alarm message is generated, acknowledgment is sent back to the client device and \(R_{msg}\) is printed on screen. The microcontroller in the server device utilizes the Haversine formula [30] to determine the distance between the client device and server. This process is defined by the following Equation (1):  
\[dist=2r\text{sin}^{-1}\sqrt{\text{sin}^{2}\left(\frac{\Delta\phi}{2}\right)+ \text{cos}\left(\phi_{1}\right)\text{*}\text{cos}\left(\phi_{2}\right)\text{*} \text{sin}^{2}\left(\frac{\Delta\delta}{2}\right)} \tag{1}\]  
where \(\phi\) is the latitude, \(\delta\) is longitude (in radians). ```
1:procedure
2: Step 1: defining and initializing variables
3: Step 2: detecting events
4:while 1 do
5:if\(R_{msg}=true\)then
6: Generate \(Alarm_{msg}\)
7: send \(Ack_{msg}\) back
8: Print request message on screen. 9:endif
10:endwhile
11:endprocedure
```  
**Algorithm 1** Server device  
Figure 2: Flow chart of server device. Figure 3 shows the flow chart of the relay device. After initialization, the relay device scans for available networks and applies the Dynamic ID Assignment (DIA) algorithm (explained later in Algorithm 2) to generate its own ID. Then, the Minimum Maximum Neighbor (MMN) algorithm is utilized that returns minimum and maximum IDs (explained later). Afterwards, the relay device waits for the arrival of messages. If the request message arrives, it selects the minimum ID to transmit the message to the server. The relay with the minimum ID is selected because it is much closer to the server (as will be explained later in the DIA algorithm) and delivers the message in minimum possible time. However, if an Ack message arrives, the relay device selects the maximum ID to transmit the message back to the client. ```
1:procedure
2: Step 1: defining and initializing variables
3:\(Array_{id}\) = Array containing available networks IDs
4:\(F_{index}\) = First index of \(Array_{id}\)
5:\(S_{index}\) = Second index of \(Array_{id}\)
6: Step 2: Assigning ID to relay
7: Store \(AVB_{net}\) in \(Array_{id}\)
8: Sort \(Array_{id}\) in ascending order
9:\(ID_{assigned}\) = \(Array_{id}\) [ \(F_{index}\)]
10:if\(ID_{assigned}\) = \(-1\)then
11:\(ID_{assigned}\)= \(Array_{id}\) [ \(S_{index}\)]
12:endif
13:\(ID_{assigned}\) = \(ID_{assigned}\) +1
14:endprocedure
```  
**Algorithm 2** Dynamic ID Assignment (DIA)  
Algorithm 2 presents the dynamic ID assignment (DIA) algorithm. This DIA algorithm is used by relay devices to dynamically select their IDs based on all the available IDs of networks. Initially, it is assumed that the server has an ID = 0 and all the deployed relay devices have an ID = \(-1\). As shown in step 2, each relay device stores available network IDs in \(Array_{id}\). Then, \(Array_{id}\) is sorted in ascending order. Finally, the relay device generates its own ID by selecting the first index of \(Array_{id}\) as it the contains minimum ID. However, if the first index of \(Array_{id}\) contains \(-1\), then the second index of \(Array_{id}\) is selected and incremented by 1. Figure 3: Flow chart of relay device. The detailed procedure of the DIA algorithm is explained in Figure 4. All relays are deployed randomly at a distance of 90m and initially their IDs are \(-1\) and the server ID are 0, as shown in Figure 4a. According to Figure 4b, relay X will receive network IDs 0 and \(-1\) from server S and relay Y, respectively. By applying the DIA algorithm, relay X will choose the positive minimum ID, i.e., 0 and increments it by 1. Therefore, the ID of relay X becomes 1. Similarly, in the same fashion, relay Y will receive IDs 1 and \(-1\) from relay X and Z, respectively. As shown in Figure 4c, after applying the DIA algorithm, relay Y will chose the positive minimum ID, i.e., 1 and increments it by 1. Therefore, the ID of relay Y will become 2 and this process will continue until all the relays will be assigned dynamic IDs, as shown in Figure 4e.