Design and development of a new embedded remote monitoring system

Publisher:真诚相伴Latest update time:2012-03-20 Source: 微计算机信息 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

Embedded monitoring system is one of the hot research topics in the current field of industrial automation monitoring application. The improvement of microelectronics technology and microprocessor manufacturing process and the rapid development of network technology have made it possible to build a Web-based embedded remote monitoring system. Such a remote monitoring system can be directly connected to the Internet through the TCP/IP network protocol to achieve remote monitoring, becoming a remote monitoring system that is truly not limited by time and space.

Since the storage capacity of MCUs newly launched by some semiconductor manufacturers has been greatly improved in recent years, and programs written in C language have the advantages of strong portability and good readability, the monitoring software in this article is written in standard C language and compiled in m6811-elf-gcc. This article will start with the communication basis of the embedded Web monitoring system - the Ethernet interface module, and describe the design and implementation of each functional module.

2 Ethernet interface programming

The Ethernet interface program is closely related to the network control chip in the hardware design. Different network control chips have different Ethernet interface programs, but a complete Ethernet interface program usually includes three parts: hardware module initialization, Ethernet frame sending and Ethernet frame receiving.

1. Hardware module initialization

The Freescale MC9S12NE64 MCU used in this article integrates two hardware sub-modules, EPHY and EMAC. Their initialization must be carried out strictly according to the technical manual to avoid ignoring some details.

2. Sending Ethernet frames

To send an Ethernet frame in NE64, the frame content must be written into the transmit buffer (TX buffer) of the EMAC module, and then sent out through the send command. The following work is completed by the lower-level hardware. The registers related to the sending of Ethernet frames include the transmit buffer frame end pointer register (TXEFP) and the transmit control and status register (TXCTS).

3. Receiving Ethernet frames

There are two methods to determine the reception of Ethernet frames: query method and interrupt method. Since the interrupt method has better execution efficiency, this article uses the interrupt method to receive Ethernet frames. Since NE64 has two receiving buffers A and B, the arriving frames may be stored in buffer A or buffer B, so there are also two interrupt vectors: A buffer reception completion interrupt and B buffer reception completion interrupt, and their vector addresses are $FFB2 and $FFB4 respectively. Whether the data is received in buffer A or buffer B, the processing method is the same, which is to read the received data frame and then perform corresponding processing.

3. Programming of uIP Protocol Implementation

3.1 Implementation of TCP Protocol

The TCP protocol is the core of the embedded Web. It provides a reliable data stream transmission method based on connection and with confirmation, which can enhance the service quality of the network. The mechanism of the TCP protocol is very complex, and its complete implementation requires high storage capacity and computing power of the processor. This is a luxury for embedded systems, so it must be simplified. This paper is going to implement a monitoring system based on an embedded Web server. After careful analysis, this paper obtains a simplified TCP state machine as shown in Figure 1. The disconnection of the connection is actively executed by the server. Through multiple experiments, it is concluded that this method is simpler and more stable in this system than the state machine of the standard TCP protocol that actively disconnects the connection.

Figure 1 Simplified TCP state diagram of the server [page]

In addition, this system can adjust the number of connections supported by TCP according to different application requirements, but usually only supports a single TCP connection at the same time. At the same time, in order to avoid deadlock of the state machine due to the loss of datagrams, this paper uses a simple timing mechanism to reset the TCP state machine after timeout.

The process of establishing a TCP connection is called a "three-way handshake". First, the client makes a connection request to the server. At this time, the client inserts its own ISN in the TCP header and sets the SYN flag to 1, indicating that the sequence number field is legal and needs to be checked. Secondly, after receiving the TCP segment, the server responds with its own ISN and confirms receipt of the client's TCP segment by setting the ACK flag to 1. Finally, the client confirms receipt of the server's ISN and sets the ACK flag to 1. At this point, the complete TCP connection is established and the data transmission process in full-duplex mode begins.

3.2 Implementation of other protocols

On the basis of realizing the Ethernet bottom layer driver, the upper layer protocol for Ethernet communication is realized next. The ARP protocol is a communication protocol for the communicating parties to obtain the MAC address of each other. It is the basis of network communication. This paper realizes the sending and receiving of ARP request messages and the receiving and processing of ARP response messages. In order to facilitate network debugging, the Ping command is implemented in uIP. This part can be omitted when the monitoring device is working normally. SD12-MCS is an embedded Web-based application device, not an embedded gateway or router. Therefore, in order to save embedded system resources, this paper cuts the routing function of the IP protocol, and all routing issues are completed by the default gateway. Although the Web-based SD12-MCS uses the TCP protocol, there are currently some applications based on the UDP protocol. In order to make the system more scalable, this paper also implements the UDP protocol.

4 Design and Implementation of Web Server

The working mode of this monitoring system is embedded Web server mode. Therefore, based on the implementation of uIP protocol, this paper designs and implements the HTTP protocol and CGI processing program of the application layer.

4.1 Design and Implementation of HTTP Protocol

HTTP, the application layer protocol of the Web, is the core of the Web. The client/server model implemented by the HTTP protocol is a request/response structure. Considering the number of connections supported by the embedded TCP protocol and security issues during system implementation, this article adopts the HTTP1.0 protocol, and the Web server disconnects the connection each time it sends a response. The status code has many meanings, and this article uses two types: when the request for a web page is successful, the status code 200 is returned with a reason phrase of OK; when the requested web page does not exist, the status code 404 is returned with a reason phrase of NOT FOUND. The header field name is also an optional part, but this article uses one of the options, Content-Length:, to indicate the number of bytes of the object sent, to facilitate program debugging. The entity part is the specific content of the response, such as an HTML web page or a picture, etc.

The implementation of HTTP protocol static page in this article needs to complete the following contents: first obtain the file name in the URL, then call the https_calculatehash() function according to the file name to obtain the file handle, that is, the hash field value in the file processing entry data structure, find the starting address of the file according to the value, and then load the file into the TCP socket send buffer. When the sent file is too long and larger than the size of the send buffer, the buffer overflow problem will occur. The solution of this article is: first determine the length of the file. When the file is too long, divide the file into multiple segments that are not larger than the size of the send buffer, and then send them out in a loop. The program flow of static page processing in HTTP protocol is shown in Figure 2.

Figure 2 HTTP static page processing flow chart [page]

4.2 Design and Implementation of CGI

In this monitoring system, in addition to supporting static pages, it must also support the processing of dynamic content and dynamic forms, mainly including dynamically generating real-time data collection pages and processing control command forms. In order to achieve this function, this paper designs a CGI interface processing program.

Considering the actual application, this paper does not need to transplant the operating system in NE64, so the standard CGI cannot be copied to create a CGI interface for the Web server. First, the Web server in this paper cannot run multiple applications at the same time. The operation of each application will monopolize the CPU until it is completed. Secondly, this paper does not implement a complex cache mechanism, so repeatedly executing applications is a slow process. Therefore, this paper cuts down the standard CGI and designs an embedded CGI. This method realizes the data collection and monitoring of the embedded Web server. Its work process is shown in Figure 3.

Figure 3 CGI processing flow

5 A/D acquisition subroutine

In order to achieve data acquisition with different precision and more channels, the system uses both the NE64 integrated A/D acquisition module and the dedicated A/D acquisition chip TLC2543 expanded through SPI. Therefore, the A/D acquisition subroutine contains the contents of these two parts. In the specific implementation, this paper uses the variable TLCAD to control which acquisition subroutine to call. When TLCAD=100, the TLC2543 acquisition subroutine is called; when TLCAD=99, the integrated A/D acquisition subroutine is called. When the system is collecting data, the analog input signal is connected in sequence from the smallest channel number. The actual number of analog quantities is determined by the variables NE64ADNmb and TLCADNmb, which respectively represent the number of analog quantities with an acquisition precision of 10 bits and the number of analog quantities with an acquisition precision of 12 bits.

In the process of A/D data acquisition, it is inevitable to be interfered by random noise, which will cause inaccurate data acquisition and lead to wrong conclusions. In order to prevent pulse interference in the system, the author of this article adopts the median filtering method. On the basis of median filtering, in order to ensure the stability of the acquired data, the author of this article adopts the arithmetic mean filtering method.

6 Module Testing

The main functions of the monitoring system software are to realize multi-channel data acquisition, network protocol communication and object control mechanism. The module test part mainly tests the software of each module. Due to space limitations, the following mainly introduces the test part of the data acquisition part. SD12-MCS supports a total of 30 channels of analog data acquisition, of which 8 channels of 10-bit precision AD belong to the NE64 A/D module, and the remaining 22 channels belong to two TLC2543 acquisition chips. In order to verify whether each acquisition program is correct, this paper designs such a test case: first run one of the acquisition programs with one precision separately, send the data collected by all channels, send it to the high-end PC through the serial port, and display it by the test case of the PC. If the displayed data is correct, the program is correct. On this basis, send parameters to determine which subroutine to call, and control the acquisition of multiple analog quantities at the same time. Since the analog quantity acquisition in this paper starts from the 0th channel, and so on, there is no need to set which channel the analog quantity is collected, thereby simplifying the program processing.

The author's innovation points:

This paper mainly introduces the design and implementation of a Web-based embedded monitoring system control strategy. The test of each functional module shows that the monitoring system has good performance and meets the relevant design requirements.

References:

[1] Chen Weigang. Network development of industrial control systems [J]. Industrial Instrumentation and Automation Equipment, 2004 (01): 10

[2] Song Yanzhao. Introduction and selection principles of embedded operating system [J]. Industrial Control Computer, 2005(07):41

[3] Wang Jianxin. Current status and trends of remote monitoring technology [J]. Foreign Electronic Measurement Technology, 2005(04):9

[4] Zhu Huasheng, Feng Xiangsheng. Design and implementation of smart home controller based on ARM[J]. Microcomputer Information, 2007, 1-2: 185-187

Reference address:Design and development of a new embedded remote monitoring system

Previous article:A brief discussion on orthogonality in embedded software system design
Next article:Embedded Data Acquisition System Based on Linux

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号