## 2 System Design
### Base Station Module
#### 2.3.2 The Base Station Module Software  
(1) Embedded operation system--ZKOS  
The embedded operation system is applicable to different single chips and features small code, less dependence on stacks, registers, timers and interrupters and being applicable to different single chips. The software structure of the embedded operation system ZKOS is shown in Figure 3.  
Figure 3: The software structure of ZKOS. Figure 2: Hardware components of the base station module. (2) The ZKOS-based remote wireless monitoring system  
All tasks performed by the embedded operation system ZKOS in the remote wireless water-level monitoring system can be classified into five types:  
Task 1: All signals from the analog channel would be converted in a timely fashion into digital signals by A/D. The digital signals then would be converted into the true value. The timing must be above 10 \(\upmu\)s and may be revised. Task 2: The sample data of the water-level sensors can be acquired in time after the communication through all the data channels. The Timing must be above 0.1 ms and may be revised. Task 3: The acquired data acquired should be packed up and transmitted to the remote Internet server in time by the GPRS module. The Timing must be above 1 min and may be revised. Task 4: The working modes of the system or the corresponding operations can be set by the instructions derived from the text messages received by the GSM. Task 5: To upgrade the program remotely. (3) The remote upgrade task  
The software of the system needs to be improved in order to solve some specific problems noted during the running. The current method is to download the procedures or to change the FLASH accessories on the spot. However, it may be hard to access the spots once the system has been set up in the field, therefore, it is a good method to remotely upgrade the program remotely using the GPRS network [8]. The online upgrade can be carried out by dividing the memory space of the FLASH in the MCU of the base station module and defining the data format transmitted by the upgrade file using IAP (Internet Access Provider). The GPRS remote upgrade system consists of the server and the remote terminal. The server checks if there are new programs to upgrade. The remote terminal includes MCU and GPRS modules, which communicate through USART interfaces. The server and the remote terminal communicate through GPRS. When the software needs to be upgraded at the server, the upgrade bit will be marked and then the upgrade label and upgrade package will be sent back to the terminal via GPRS. In the remote terminal there are two types of FLASH storage media: internal FLASH and external NAND-FLASH. The internal storage media is divided by IAP programs area and application programs area. The IAP programs are only executed to upgrade the software when the system starts and upgrade programs are needed. The application programs are executed to implement all the functions of the system when the system operates normally. The external NAND-FLASH storage media can also be divided into two portions: program package areas and data storage area. The system will receive the program package from the GPRS module and save it into the program package areas. When receiving of the correct program package is confirmed, the system will be reset. The program will be written into the internal program package areas by IAP program. The system will operate normally after the second resetting. The flow chart of the remote upgrade process at the terminal is shown in Figure 4.  
The system checks the upgrade label each time after being reset. If the upgrade bit is marked, then the system is operated by the IAP program. The program package of the external NAND-FLASH will be written into the internal FLASH program areas, then reset the system. If not marked, then the system is operated by the application program.