## 5 Proposed Software-in-Loop System
### Channel Simulation  
Event processing is implemented from a receiver viewpoint, and the associated algorithm can be observed in Algorithm 1. For every receiver, the most powerful reception among all the queued events (transmissions) is marked as the preferential transmission and is described by \(P_{max}\). The parametric model described in Equation (3) [37] is used in order to determine the received power associated to each event. All the other transmissions are considered as interference and will be summed up together under the assumption of uncorrelation in addition to the receiver's thermal noise \(\sigma_{thr}^{2}\), to determine the overall noise power (Equation (4)). \[SINR=\frac{P_{max}}{\sum_{l\in I}P_{l}+\sigma_{thr}^{2}}. \tag{4}\]  
\(I\) is the set comprising all the received powers except the one marked as preferential. Once the Signal-to-Interference-and-Noise ratio (SINR) is calculated, the Bit Error Rate (BER) is estimated for the current modem used by the receiver taking into account the modulation format. The physical modem used in HERAKLES' nodes is a CML Microcircuits modem. Therefore, a non-coherent Frequency Shift Keying (FSK) demodulator must be considered (Equation (5)). Moreover, a bit-wise xor operation with a uniformly generated bit mask is performed to the preferential transmission within the 25 ms block in order to simulate errors. The xor mask is randomly obtained taking into account statistical uniformity in the position of the reception errors. Furthermore, the number of errors to be introduced on each event follows a Binomial distribution. After carrying out this process for all the non-transmitting nodes, 25 ms of bits (using modem throughput) will be deleted from every queued event. Taking into account this consideration and the frame length \(N\), the Packet Error Rate (PER) can be expressed as shows Equation (6). \[P_{e}=\frac{1}{2}e^{-\frac{SINR}{2}} \tag{5}\]  
\[PER=1-(1-P_{e})^{N}. \tag{6}\]  
Figure 5: BER calculation for each event. ```
Set \(EventList\gets list()\) while True do\(\triangleright\) Main loop, so run until program ends \(t_{0}\leftarrow CurrentEpoch()\) for all\(n\in connected\_nodes\)do\(\triangleright\) Check for new transmissions if StartedTransmission(s) then  Set \(t\gets GetTransmission(n)\)  Append \(EventList\gets t\) endif endfor for all\(n\in connected\_nodes\)do ifIsTransmitting(n) then \(skip\)\(n\) endif  Set \(e\leftarrow\) FindMostPowerfulReception(\(n\))  Set \(d\leftarrow\) distance(\(n,e.source\_node\))  Set \(pw\gets e.tx\_power-\text{att\_equation}(d)\)\(\triangleright\) As described in Equation (3)  Set \(nb\leftarrow\) GetNodeNoise(\(n\))  Set \(ber\leftarrow\) GetBERFromSNR(\(\frac{pw}{pk}\)) \(\triangleright\) As described in Equation (5)  Set \(bit\_stream\leftarrow\) Randomize(Get25 msecBitStream(\(e\)), \(ber\)) \(\triangleright\) Randomize bitstream call n.send(\(bit\_stream\)) endfor  Set \(t_{diff}\gets CurrentEpoch()-t_{0}\)  Set \(t_{sleep}\gets 0.025-t_{diff}\) \(\triangleright\) Sleep only if \(t_{sleep}>0\), otherwise prints an error endwhile functionFindMostPowerfulReception(\(node\))  Set \(curr\_event\leftarrow-1\)  Set \(curr\_rx\_power\leftarrow-999999\)\(\triangleright\) Power is in dBm for all\(e\in EventList\)do  Set \(d\leftarrow\) distance(\(node,e\to source\_node\))  Set \(pw\gets tx\_power-\text{att\_equation}(d)\) if\(pw>curr\_rx\_power\)then  Set \(curr\_event\gets e.index\)  Set \(curr\_rx\_power\gets pw\) endif endfor return\(curr\_event\) endfunction
```  
**Algorithm 1** Simulator main loop  
If NONARQ messages with a given number \(R\) of retransmissions are enabled in the network, it may have a significant impact on the network's reliability. Under this assumption, the retransmission process can be modeled as a one-way Markov model (Figure 6). A simple transition matrix \(P\) Equation (7) is straightforward to obtain taking into account Equation (6) and Figure 6.  
\[P= \begin{pmatrix}\text{PER}&1\text{-PER}\\ 0&1.\end{pmatrix}