## 2 Architecture
### M2M Gateway Resource Abstraction Layer  
#### 2.1.1 M2M Gateway Data Acquisition Protocol  
The sensors store the data in real time in different storage areas of the PLC device through physical wiring, and the PLC device is connected to the communication module with physical wires. The communication module has the network communication function and implements the data communication with the Internet. The Modbus protocol [21] is a serial communications protocol specification used in industrial control, and the Modbus protocol used in the hardware module produced by different companies can vary. Enterprises such as Samsung, Siemens, and Delta all produce different PLC devices. Modbus protocol has two different modes of operation, _i.e._, the remote terminal unit (RTU) mode and the American Standard Code for Information Interchange (ASCII) mode. These two working modes are described in the following:  
_RTU mode_, when the controller is set to communicate in the RTU mode on the Modbus network, every 8-bit byte in the information contains two 4-bit hexadecimal characters. The primary advantage of this mode is that under the same baud rate, more data can be transferred in the RTU mode than in the ASCII mode.  
_ASCII mode_, when the controller is set to communicate in ASCII mode on the Modbus network, every 8-bit byte in the information is transmitted as an ASCII code (two hexadecimal characters). The primary advantage of this approach is that the time interval for character transmission can be as long as 1 s without generating an error. If we use the PLC in the ASCII mode, when the data packet is being sent, except for the start of the text character (STX) and the end, the first four bits and the last four bits of every byte are converted to ASCII code. For example, if a byte represents 5A, it is converted to two characters, \"5\" and \"A\". The conversion format is shown in Table 1.  
The longitudinal redundancy check (LRC) in the data packet is a verification model that represents the inspection calculation for the data in the data packet. The verification procedure is the following. The adaptive dynamic routing (ADR) is summed to the LRC. In the summation, the byte is the smallest unit; when there is carryover in the process of summing, the carryover is ignored; and, eventually, the complement of the sum with respect to 2 is the value of the LRC. The details of the calculation of the LRC verification code is as follows:  
\begin{tabular}{c c c c c c c c}
**STX** & **Address** & **Function** & **Data1** & **Data2** & **Data3** & **Data4** & **LRC** & **End** \\
3A & 01 & 03 & 04 & 01 & 00 & 01 & 0D0A \\ \end{tabular}  
The procedure of computation is as follows: Address + Function + Data1 + Data2 + Data3 + Data4 = 01 + 03 + 04 + 01 + 00 + 01 = 0A; convert the value of 0A to the complement (the complement is the reverse of every bit in the data to be converted, _i.e._, 0 changes to 1, and 1 changes to 0, and then, the reversed data are added to 1 to derive the complement); and the 2-complement of 0A is F6. For both the transmitting data packet and the receiving reply packet, the data verification is required to ensure that the received data are usable and effective.