## 2 Architecture
### M2M Gateway Resource Abstraction Layer
#### 2.1.2 M2M Gateway Wireless Communication Protocol
The packet length includes the length of the entire protocol packet. The protocol packet uses hexadecimal transmission; the high byte is in the front, and the low byte is in the back. The data packet format of the H7000 protocol is as follows: \begin{tabular}{c c c c c}
**Head (0 \(\times\) 7B)** & **Type (8 Bits)** & **Length (16 Bits)** & **Data Tail (0 \(\times\) 7B)** \\ Head & Type & Length & Tail \\ \end{tabular}   
In the H7000 protocol, there are many types of data packets, such as the registration packet of the terminal request, the cancellation packet of the terminal request, and the request for the IP address of a particular desktop unit (DTU). The detailed types of data packets are shown in Table 4.  
The M2M gateway system uses the communication module to establish the inter-sensor data transfer. The GPRS communication module will initially send the terminal registration packet to the M2M gateway system. When M2M gateway receives the terminal registration packet, it responds to the terminal registration packet, and the reply with the successful registration is sent to the terminal. When the GPRS communication terminal receives the reply packet, the connection between the communication terminal and the server is established. That is, the registration of the terminal on the server is successful, the data path between the terminal and the server is established, and it can then be used for the exchange of data. The data format for the reply packet returned from the server is as follows: \begin{tabular}{c c c c}
**Head** & **Type** & **Length** & **DTU ID** & **Tail** \\
1 byte & 1 byte & 2 bytes & 11 byte & 1 byte \\
0 \(\times\) 7B & 0 \(\times\) 81 & 0 \(\times\) 10 & 0 \(\times\) 7B \\ \end{tabular}   
After the data path between the terminal and the M2M gateway is established, the data can be transferred using this data path. The sensor data are stored in the PLC, and the PLC and the GPRS communication module are connected. Therefore, when the PLC interacts with the server end, it encapsulates the server data in the loading region in the GPRS communication protocol. When the server parses the load, it acquires the sensor data. The format of the users' data packet is as follows: \begin{tabular}{c c c c c}
**Head** & **Type** & **Length** & **DTU ID** & **Client Data** & **Tail** \\
1 byte & 1 byte & 2 bytes & 11 byte & \(\leqslant\)1024 bytes & 1 byte \\
0 \(\times\) 7B & 0 \(\times\) 89 & 0 \(\times\) 10 & & 0 \(\times\) 7B \\ \end{tabular}   
When the terminal receives the data request package sent from the M2M gateway, it replies to the data request package. The PLC encapsulates the format of the Modbus data protocol used by the sensor \begin{table}
\begin{tabular}{c c c} \hline \hline
**Data Packet ID** & **Type of Data Packet** \\ \hline
0 \(\times\) 01 & terminal request for registration \\
0 \(\times\) 02 & terminal request for cancellation \\
0 \(\times\) 03 & query of IP address for certain DTU \\
0 \(\times\) 04 & packet of invalid command or protocol (usually used for question answering or setup instructions) \\
0 \(\times\) 05 & receiving a data packet from a user (from DSC) \\
0 \(\times\) 09 & data packet from a user (from DTU to DSC) \\
0 \(\times\) 0B & DTU parameters inquiry answer packet \\
0 \(\times\) 0D & set up a DTU parameters inquiry answer packet \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Basic protocol packets of the H7000. required by the server and transmits it to the GPRS module through hard-wiring. The GPRS terminal module encapsulates the Modbus protocol data packet in its user data domain and transmits it to the M2M gateway system through the established data path. Here, the OSGi technology [22] is adopted to create a uniform protocol management framework with the Dependence Inversion Principle (DIP) to access the different physical devices. Here, the Dependence Inversion Principle means that the high level modules should not depend on low level modules.