## 2 Architecture
### M2M Gateway Resource Abstraction Layer
#### 2.1.2 M2M Gateway Wireless Communication Protocol  
When the M2M gateway communicates with the underlying device, the GPRS protocol is used, which adopts the request-reply mode for data exchange. The gateway transmits the data request packet, and the GPRS communication terminal returns the data reply packet. This communication protocol has a strict data format. Therefore, the data path must be established with the communication module to \begin{table}
\begin{tabular}{c c} \hline \hline
**STX** & **Start Character** \\ \hline high address byte & & \\ low address byte & & Slave address \\ \hline high level function code & & \\ low level function code & Function code \\ \hline data 1 high address & & \\ data 1 low address & & The first byte \\ \hline...... & &...... \\ \hline Data \(N\) high address & & & \\ Data \(N\) low address & & The \(N\)-th Byte \\ \hline LRC high address & & & \\ LRC low address & & LRC \\ \hline End1 & & CR(0 DH) \\ \hline End2 & & LF(0 AH) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Data packet conversion format for ASCII mode. read and write on the PLC. The PLC not only stores the switch data, such as the open and closed states of valves, but also stores analog data, such as the temperature, the pressure, the power, and the flow velocity. Table 2 shows the analog data (for both the RTU mode and the ASCII mode) in the acquisition of the PLC in the sent Modbus request packet. When the PLC issues a Modbus data request packet for analog data, it parses the data packet and then encapsulates the acquired data as the reply packet (for both the RTU mode and the ASCII mode) to return to the server. The format of the reply packet is shown in Table 3.  
The GPRS communication protocol is a commonly used wireless communication protocol. This communication protocol does not have a unified standard. Therefore, the specific communication protocol used by the GPRS module produced by various companies may be different. However, every GPRS protocol uses a socket connection for data transfer. The Hongdian H7000 protocol is a GPRS communication protocol. In the H7000 protocol, there are strict guidelines for the format of the data \begin{table}
\begin{tabular}{c c c c} \hline \hline \multicolumn{4}{c}{**Send**} \\ \hline \multicolumn{2}{c}{**ASCII Mode**} & \multicolumn{2}{c}{**RTU Mode**} \\ \hline
**Field Name** & **Example (Hex)** & **Field Name** & **Example (Hex)** \\ \hline
**Heading** & **3A** & **Slave Address** & **01** \\
**Slave Address** & **01** & **Function** & **03** \\
**Function** & **03** & **Starting Address Hi** & **06** \\
**Starting Address Hi** & **06** & **Starting Address Lo** & **14** \\
**Starting Address Lo** & **14** & **Number of Points Hi** & **00** \\
**Number of Points Hi** & **00** & **Number of Points Lo** & **08** \\
**Number of Points Lo** & **08** & **CRC(low byte)** & **04** \\
**Error Check(LRC)** & **DA** & **CRC(high byte)** & **80** \\
**End1(CR)** & **0D** & & \\
**End2(LF)** & **0A** & & \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Data request packet for analog data. \begin{table}
\begin{tabular}{c c c c} \hline \hline \multicolumn{4}{c}{**Receive**} \\ \hline
**ASCII Mode** & \multicolumn{2}{c}{**RTU Mode**} \\ \hline
**Field Name** & **Example (Hex)** & **Field Name** & **Example (Hex)** \\ \hline
**Heading** & **3A** & **Slave Address** & **01** \\
**Slave Address** & **01** & **Function** & **03** \\
**Function** & **03** & **Bytes Count** & **10** \\
**Bytes Count** & **10** & **Data Hi (T20)** & **00** \\
**Data Lo (T20)** & **01** & **Data Hi (T21)** & **00** \\
**.......** & **...** & **.......** & **...** \\
**Data Lo (T27)** & **08** & **CRC (low byte)** & **72** \\
**Error Check (LRC)** & **C8** & **CRC (high byte)** & **98** \\
**End1 (CR)** & **0D** & & \\
**End2 (LF)** & **0A** & & \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Data reply packet for analog data. and the report. The report includes the head, the packet type, the packet length, the data, the inspection data, and the tail.