## 3 System Design and Implementation
### Software Design
#### 3.3.2 Implementation of the AUDP Mechanism  
To enhance the reliability of UDP-based communication, this study introduces four reliability mechanisms through an in-depth analysis of UDP transmission characteristics: (1) CRC checksum mechanism, (2) retransmission mechanism, (3) Transaction ID matching mechanism, and (4) exponential backoff mechanism. Figure 10: UDP communication workflow. Figure 9: Software architecture diagram. Analysis of UDP Validation Mechanism  
UDP employs its own checksum mechanism covering the IP pseudo-header, UDP header, and data fields using a 16-bit 1's complement summation algorithm, with an undetected error probability denoted as \(P_{UDP}^{undetected}\):  
\[P_{\text{undetected}}^{\text{UDP}}=\frac{1}{2^{16}}\approx 1.53\times 10^{-5} \tag{7}\]  
In the high-noise environment, where the channel bit error rate reaches up to \(10^{-4}\), relying solely on the UDP transport layer's checksum mechanism severely weakens the error detection capability. Numerous corrupted packets caused by channel interference may go undetected and reach the application layer directly, ultimately triggering unpredictable anomalies in the receiver's business logic. However, with the addition of a CRC-16 checksum at the application layer, the total undetected probability becomes \(P_{undetected}^{\text{UDT}}\). \[P_{\text{undetected}}^{\text{total}}=P_{\text{undetected}}^{\text{UDP}} \times P_{\text{undetected}}^{\text{CRC}}=\frac{1}{2^{16}}\times\frac{1}{2^{16} }=\frac{1}{2^{32}}\approx 2.33\times 10^{-10} \tag{8}\]  
The undetected error probability has been significantly reduced. Therefore, this study implements dual-layer validation at both the transport and application layers by appending a two-byte CRC-16 checksum to the end of the Modbus UDP frame as illustrated in Figure 11. After the data is transmitted to the gateway, the received CRC checksum (denoted as'receive_CRC') is extracted from the Modbus UDP frame. A new CRC calculation is performed on the data to derive the 'caculate_CRC'. If'receive_CRC' matches 'caculate_CRC', this confirms that the data integrity has been preserved during transmission. Analysis of Retransmission Mechanism  
A Markov chain model is constructed for the UDP-based transmission process, where \(S_{1}\), \(S_{2}\), and \(S_{3}\) denote the waiting-for-response state, success state, and failure state, respectively. The corresponding state transition probability matrix \(P\) is defined as  
\[P= \begin{bmatrix}0&1-\beta&\beta\\ 1&0&0\\ \gamma&0&1-\gamma\end{bmatrix}  \tag{9}\]  
where \(\beta\) is the probability that the request is waiting for a timeout, and \(\gamma\) is the probability that the failure state triggers a retransmission. After the retransmission is introduced, \(S_{2}\) retransmits the request with probability \(\gamma\) and maintains the failure state with \(1-\gamma\). According to Equation (6), the stationary distribution \((\pi_{1},\pi_{2},\pi_{3})\) satisfies \((\pi_{1},\pi_{2},\pi_{3})P=(\pi_{1},\pi_{2},\pi_{3})\), where \(\pi_{2}\) represents the long-term probability of the system being in the success state, and its value is provided in Equation (10):  
\[\pi_{2}=\frac{\gamma(1-\beta)}{\beta+\gamma} \tag{10}\]  
Figure 12 illustrates the variation of steady-state success rate \(\pi_{2}\) with timeout probability \(\beta\) and retransmission probability \(\gamma\). When \(\beta\to 0\) and \(\gamma\to 1\), \(\pi_{2}\) approaches 1; conversely, when \(\beta\to 1\) or \(\gamma\to 0\), \(\pi_{2}\) decreases significantly. This demonstrates that the retransmission mechanism is essential to ensure reliability. Figure 11: Modbus UDP frame structure. Consequently, this study implements a retransmission mechanism at the application layer of UDP to enhance the reliability of Modbus UDP transmissions. * Analysis of Transaction ID Matching Mechanism  
Assuming that the transmission process conforms to the Markov property, the following three assumptions are made: (1) After each transmission, the system waits for a response with a timeout period set to \(T\) seconds.