## 3 Design of SOCA
### TDMA Channel Selection  
The ship station selects the TDMA channel to ensure that the VDE-TER data transmission has minimal impact on the AIS transmission. Algorithm 1 presents the procedure for selecting a TDMA channel for VDE-TER data transmission. The algorithm takes \(n_{req}\), \(\textbf{N}_{IS}\), and \(\textbf{N}_{NIS}\) as inputs. \(n_{req}\) represents the number of required slots to transmit a VDE-TER data packet and is calculated by  
\[n_{req}=\left\lceil\frac{l_{data}}{l_{maxPkt}}\right\rceil, \tag{5}\]  
where \(l_{data}\) represents the size of a data packet to be transmitted via VDE-TER. \(l_{maxPkt}\) represents the maximum size of a packet that can be transmitted within a single slot of the TDMA frame. The output of the algorithm is the channel number of the TDMA channel selected by the ship station, denoted as \(ch\).  
The algorithm first defines \(ch\) and initializes it to zero. It also defines \(\textbf{CH}_{preferred}\)-\(\textbf{CH}_{available}\), and \(\textbf{CH}_{maxNIS}\), and initializes them as empty lists. \(\textbf{CH}_{preferred}\) and \(\textbf{CH}_{available}\) refer to the lists of preferred and available TDMA channels, respectively, to be selected by the ship station. The preferred TDMA channel indicates the TDMA channel that has at least as many non-interference slots as the number of required slots for the ship station. The available TDMA channel indicates the TDMA channel in which the total number of non-interference and interference slots are equal to or greater than the number of required slots for the ship station.  
Afterward, the algorithm iterates over the total number of TDMA channels, checking the following conditions for each TDMA channel. If the number of non-interference slots for a given TDMA channel is greater than or equal to the required number of slots, the TDMA channel number is appended to \(\textbf{CH}_{preferred}\). If this condition is not met, but the total number of non-interference and interference slots is greater than or equal to the requirednumber of slots, the TDMA channel number is appended to \(\mathbf{CH}_{available}\). Subsequently, the algorithm first checks if \(\mathbf{CH}_{preferred}\) is not empty. It extracts the TDMA channels with the maximum number of non-interference slots from \(\mathbf{CH}_{preferred}\) and appends them to \(\mathbf{CH}_{maxN1S}\). If \(\mathbf{CH}_{preferred}\) is empty and \(\mathbf{CH}_{available}\) is not empty, it conducts the same process for \(\mathbf{CH}_{available}\). The algorithm then selects the TDMA channel from \(\mathbf{CH}_{maxN1S}\) that is farthest from the AIS 1 channel and set its channel number to \(ch\). If both \(\mathbf{CH}_{preferred}\) and \(\mathbf{CH}_{available}\) are empty, this indicates that none of the TDMA channels in the current TDMA frame can provide sufficient resources for the ship station to transmit VDE-TER data. Accordingly, the ship station waits until it gains access to the next RAC slot, after which it reinitiates TDMA channel selection. Finally, the algorithm returns the selected TDMA channel.  
```
Input:\(n_{req}\) Output:\(ch\) Initialize:
1:\(ch\gets 0\)
2:\(\mathbf{CH}_{preferred}\leftarrow[\ ]\)
3:\(\mathbf{CH}_{available}\leftarrow[\ ]\)
4:\(\mathbf{CH}_{maxN1S}\leftarrow[\ ]\)
5:for\(i=1\) to \(N_{ch}\)do
6:if\(\mathbf{N}_{NIS}(i)\geq n_{req}\)
7:\(\mathbf{CH}_{preferred}\gets i\)
8:elseif\(\mathbf{N}_{NIS}(i)+\mathbf{N}_{IS}(i)\geq n_{req}\)
9:\(\mathbf{CH}_{available}\gets i\)
10:endif
11:endfor
12:if\(\mathbf{CH}_{preferred}\) is not empty
13:\(\mathbf{CH}_{maxN1S}\gets maxNIS\Big{(}\mathbf{CH}_{preferred}\Big{)}\)
14:elseif\(\mathbf{CH}_{available}\) is not empty
15:\(\mathbf{CH}_{maxN1S}\gets maxNIS\big{(}\mathbf{CH}_{available}\big{)}\)
16:else
17: Wait for the next RAC slot.
18:endif
19:\(ch\gets maxFreqDiff(\mathbf{CH}_{maxN1S})\)
20:return\(ch\)
```  
**Algorithm 1** TDMA channel selection