In order to improve the stability of the environmental monitoring system and save system resources, a design scheme of the environmental monitoring system consisting of the lower computer, the transmission network and the upper computer is proposed. The hardware and software design of the lower computer in the system is introduced in detail. The lower computer hardware is based on ARM9 processor S3C2410. The software uses multi-threaded application to process multiple tasks at the same time, and uses thread and mutual repulsion to achieve synchronization between threads. The practical application shows that the system runs stably and improves the system efficiency.

0 Preface

With the development of the national economy and industrial technology, environmental protection has received more and more attention. A variety of environmental monitoring systems have emerged on the market today, but performance is not stable. Most of the on-site monitoring terminals use industrial computer or single-chip microcomputer. The former has good anti-interference performance, but the cost is high. The latter has low processing capacity and unfriendly human-machine interface, which is not conducive to the monitoring and management of field personnel. In response to the above problems, the author designed a multi-thread based environment monitoring system. The system uses multi-threading technology to effectively realize the data collection and storage in the monitoring process, real-time data display, communication between the lower computer (monitoring terminal) and the upper computer (monitoring center), real-time alarm and other functions. This article focuses on the design of the lower position machine of this system.

1 system overall structure

The multi-thread based environment monitoring system consists of three parts: the on-site monitoring terminal (lower position machine), the transmission network, and the monitoring center (host computer). The structure is shown in Figure 1.


Figure 1 is based on multi-threaded environment monitoring system structure

The lower computer is an embedded system based on A RM9, which is used to periodically collect, process and store the monitored feature data. The data processed by the lower computer is sent to the upper computer via the GPRS module according to the relevant protocol. The host computer is operated by a PC, which is responsible for receiving data sent by multiple lower computers and analyzing, processing and displaying the data. The environmental protection department can monitor the pollution discharge status of its jurisdiction through the upper computer. The host computer is based on VB. NET development.

2 lower computer hardware design

The hardware core of the lower computer consists of S3C2410, NandFLASH and SDRAM, as shown in Figure 2. S3C2410 is a 32-bit RISC embedded microprocessor based on ARM920T core produced by Samsung with independent 16 KB instruction cache and 16 KB data cache, LCD controller, RAM controller, N and FLASH controller, parallel I / O port, 8-channel 10-bit ADC, its operating frequency can reach 203 MHz. 8-bit 64 MB Nand FLASH selected chip is K9F1208, 64 MB SDRAM consists of two HY57V561620. The lower computer expands a network port through the Ethernet controller CS8900A, and the data can be transmitted either wirelessly or by wire; 8 DI ports (digital input) and 4 AI ports (analog) are extended through the I/O interface. Quantity input), 4 DO ports (digital output), the lower computer communicates with the monitored device through these interfaces.


Figure 2 lower computer hardware components

3 lower position machine requirements and structural design

The lower computer periodically collects and processes the field data, and stores it in the database, sends the real-time data to the upper computer, and responds to the control command sent by the upper computer. Therefore, the lower computer needs to process multiple tasks at the same time, and these tasks are executed concurrently. If you use a single thread to accomplish these tasks, you need to use multiple timers to trigger, and too many timers will cause system instability. Window s is a preemptive multitasking operating system. Starting an application is equivalent to starting a process. A process usually has a thread. In system resource management, each thread is allocated a certain time slice. The multi-threaded design approach allows a program to have multiple threads so that the program can handle more tasks simultaneously. Therefore, if multiple processes are used to cooperate, the above disadvantages can be avoided and the system is relatively stable. However, the frequent scheduling of processes by the system consumes too much resources, and the readability of the program is not good.

The author uses a parallel, multi-threaded solution to handle multiple tasks well and saves system resources. In this scheme, the lower computer has 5 threads: GU I thread, reset thread, data acquisition and storage thread, network communication thread, decision thread. The GU I thread is the main thread, responsible for interface processing, system data initialization and creating sub-threads; reset thread, data collection and storage thread, network communication thread is the background worker thread, through priority scheduling, thread synchronization and other mechanisms Ensure reliable on-site data acquisition, storage, transmission, display and other tasks. The reset thread loops through the watchdog operation after startup, not as a task processing thread. The relationship between task threads is shown in Figure 3.


Figure 3 Relationship between task threads

4 multi-threading technology in the system

4. 1 thread creation

In the Linux environment, a new thread is created by using the pthread_cr eate() function. By default, the main thread waits for the created sub-thread to finish executing, and returns the result of the sub-thread and then continues to execute. The sub-threads of the real-time monitor program are executed cyclically. They do not need to be merged into the main thread after the end of the run. Set their properties to PT HREAD _ CREATE _DETACHED. Prioritize the importance of the sub-threads to ensure that important threads are executed first. . The priority of the child thread from high to low is reset thread, data acquisition and storage thread, decision thread, network communication thread.

The thread creation and setting pseudo code are as follows:

Void * thr ead_wat chdog(void * arg); // reset thread function

Void * thr ead_collect ion(void * arg); // data collection and storage thread function

Void * thr ead_communi cat ion(void * arg); // network communication thread function

Void * thr ead_decis e(void * arg); // decision thread function

Int dat a[ 12] ; / / data buffer for storing data functions shared between threads

Main()

{

/ / Initialization work

......

Pthread_t wat chd og; / / thread number

Pthread_t collect ion;

Pthread_t commun ication;

Pthread_t deci se;

Pthread_at t r_init(); // initialize thread properties

Pthread_at t r_setdetach st at e(); / / Do not re-merge threads

Pthread_at t r_set s ched param(); // set the priority of the thread

Sem_init(); / / Initialize the relevant semaphore

Pth read_creat e(); // create a new thread

/ / Start the GUI program

......

}

Customized Cleaning Machine

Wuxi Lerin New Energy Technology Co.,Ltd. , https://www.lerin-tech.com