Design and implementation of embedded SNMP agent based on microcontroller

Publisher:未来感知Latest update time:2006-09-25 Source: 电子工程师Keywords:network Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0 Preface

SNMP (Simple Network Management Protocol) is widely used and powerful. As long as the management software resides in the MIB (Management Information Base) and has appropriate permissions, the manager can access the SNMP agent. SNMP is generally used in computer networks and telecommunications networks. This article proposes using SNMP for control. Since its transmission medium is the Internet, the transmission distance is not limited, which has incomparable advantages over other industrial control buses. The biggest advantage of SNMP is that the protocol is simple and suitable for embedded applications. The SNMP system has strong scalability. As long as the new MIB is loaded on the management software, it can control and access new terminals. This article introduces a solution to implement an embedded agent based on a cheap microcontroller. The microprocessor core implements related hardware and software.

1 SNMP architecture

The architecture of SNMP (see Figure 1) is based on a simple query/answer model. The user who sends the query is the manager, and the SNMP server (agent) answers the query.

SNMP is an application layer protocol in the TCP/IP system. In order to implement the SNMP system, it is necessary to implement all the protocols used from the application layer to the physical layer. The manager is on the PC, the agent is at the monitoring site, and the agent resides in the MIB of the managed system. We use the microcontroller as the core To implement an embedded agent, the embedded agent needs to analyze the data collected on site. If an abnormality occurs, it sends a Trap message to the manager to inform the network management that an abnormality has occurred. The message also contains For information related to abnormal situations, the network management can perform corresponding processing based on this information. In some cases, the agent saves the data for query by the manager.

2 Hardware implementation of embedded agent

The principle of the SNMP-based control system we designed is shown in Figure 2.

The signal collection at the control site is input into the microcontroller by the A/D conversion module. The microcontroller processes the signal and performs the tasks of the SNMP agent. The hardware part mainly includes A/D, serial port, Ethernet, small logic, microcontroller, monitoring signal collection, power supply and monitoring modules. This article focuses on the embedded SNMP agent. closely related parts of the device.

2.1 Serial port module

The microcontroller uses TTL levels, but the RS-23 protocol uses different levels, so level conversion is required, and level conversion is achieved through MAX232.

2.2 A/D module

The A/D module is mainly responsible for collecting external monitoring signals. The AD0809 can be used to collect data from 8 channels. The dynamic range of signal changes is not large. Using this feature and setting the reference voltage reasonably can improve the resolution and use low-cost devices. To achieve good performance, both reference voltages of ADC0809 can be adjusted through potentiometers. In order to ensure the accuracy of the system, the reference voltage must be stable. For this reason, MAX875 of MAXIM is used as the reference voltage source. Another thing to note is that the reference voltage input to the A/D converter is divided by a potentiometer. In order to stabilize the reference voltage, a high-precision and high-stability potentiometer must be selected.

2.3 Ethernet module

The Ethernet module implements communication with Ethernet and is implemented using RealTek's RTL8019 chip.

RTL8919A (see Figure 3) has 3 working modes: jumper mode, the I/O and interrupt of the network card are determined by the jumper; plug-and-play mode, the software automatically configures plug and play; jumper-free mode, the network card I/O and interrupts are determined by the contents of the external 93C46.

Pin 65 (JP) of RTL8019AS determines the working mode of the network card. Pin 65 (JP) is the input pin. When pin 65 is low level, 8019 works in plug-and-play mode or jumper-free mode. Specifically Determined by the content of 93C46, if you can not use 93C46 in embedded applications, you can reduce costs and reduce connections. We connect pin 65 to high level (VCC) and use a jumper. Then, the I/O and interrupts of the network card are not determined by the contents of 93C46, so there is no need to use 93C46.

Pin 64 (AUI) determines whether to use the AUI or BNC interface. The BNC interface mode supports 8-wire twisted pair or coaxial cable. When it is high level, the AUI interface is used; when it is left floating, it is low level, and the BNC interface is used. We generally use BNC and leave this pin floating.
The network interface type is determined by pin 74 (PL0) and pin 77 (PL1). Leave PL0 and PL1 floating, select the automatic detection mode, the chip automatically detects whether the interface type is coaxial cable or twisted pair, and then start working.

IOCS16 of RTL89 is the 16-bit I/O selection pin. When the network card is powered on and reset, this pin is the input of the network card. If this pin is high level, the network card will select 16-bit mode. If this pin is low level, the network card will select 8-bit mode. 51 MCU It is 8-bit data, so resistor R10 is used to pull it down, so the pin is low level during reset, and the network card selects 8-bit mode.

AD0-AD7 is the 8-bit data bus of the network card, which is connected to the P0 port of the microcontroller. RESDRV (pin 33 (RESET)) is connected to T0 (P3.4) of the microcontroller. The microcontroller uses P3.4 to reset the network card. IRQ9 is connected to INT0 (P3.2) of the microcontroller. IRQ9 is the interrupt 9 of the network card. It is connected to the interrupt 0 of the microcontroller. IOR and IOW are connected to P3.6 and P3.7 (/WR, /R) of the microcontroller.

2.4 Small logic module

The small logic module mainly implements some logic functions. The A/D clock is divided by 8 from the ALE signal of the microcontroller. The chip select function of each external device is implemented by the small logic module. Although the function is not complicated, if it is implemented with a small logic device, it It requires more devices, has low device utilization, and occupies a large space on the circuit board, which is inconsistent with embedded applications that require small size. Programmable logic devices can solve these problems.

2.5 Microcontroller module

The microcontroller module consists of a microcontroller and peripheral circuits such as reset and watchdog circuits, external expansion RAM, and clock circuits. The watchdog circuit can reduce interference from harsh conditions on site. When the system is interfered by external interference, the program of the microcontroller will run away. See There is no dog feeding signal for the watchdog. The watchdog circuit resets the microcontroller and RTL8019 and restarts operation.

3 Software design and implementation

Since SNMP encoding and decoding requires a lot of CPU time, and A/D data acquisition and conversion, Ethernet communication, serial communication and other functions must be implemented on the microcontroller, this makes it very difficult to coordinate various functions. Therefore, we choose Micro-C /OS51 is the operating system of the microcontroller. Micro-C/OS51 is the transplanted code of the embedded real-time operating system Micro-C/OS on the 51 microcontroller. The real-time system can greatly improve the efficiency of the CPU and is a multi-tasking system that can To coordinate multiple tasks, we divide the functions to be implemented by the microcontroller into human-computer interaction tasks, A/D processing tasks and SNMP processing tasks.
 
3.1 Human-computer interaction tasks

The human-computer interaction task is to interact with the user through the serial port of the microcontroller. The user connects the PC to the serial port of the microcontroller through a serial cable. Through the super terminal of the PC, the relevant parameters of the agent (gateway address) can be modified using the command line. , host address, etc.) for configuration, and you can also view related running information. The main command lines are:

Host configures the local IP address

Gateway configure gateway address

Mask configure subnet mask

Snmphost configures the SNMP manager IP address

Macadr configures the local physical address

ping can use this command to detect network links

clear Clear the contents of the phone display

The main idea of ​​realizing the human-computer interaction task is that the microcontroller receives the characters input by the user's keyboard and stores them in the command buffer, and echoes them to the screen. When the user presses the Enter key, the software state machine state changes are triggered, and the state is transferred from the input state to the command interpretation. state, and then calls relevant subroutines to perform relevant operations according to user commands, and returns to the input state after completion.

The human-computer interaction program consists of a vocabulary list, a word retrieval subroutine, and a state machine framework program (input echo and command interpretation execution) command-related subroutines. The vocabulary list is a collection of command statements, and the word retrieval subroutine is extracted from the command line statement. The words are stored in the vocabulary list, and matching checks and lexical analysis are performed at the same time. The input echo program checks the user's keyboard input in a loop, and the command interpreter calls the word retrieval subroutine to analyze the user's command line input. According to the first word in the vocabulary list, it is stored in the scattered transfer table. The corresponding execution subroutine is called to process the command at the position in the command interpreter. The command interpreter passes the vocabulary pointer to the corresponding command-related subroutine. The specific execution is decided by the user. After the command-related subroutine returns, it returns to the command input state and completes it once. Enter the entire process of execution, which is executed over and over again.

3.2 A/D processing tasks

A/D conversion takes a certain amount of time. There are three ways to read the results of A/D conversion:

a) Interrupt mode is used to read data in a timely manner, while frequent interrupt processing increases the burden on the CPU.

b) The query method causes a waste of CPU time and greatly reduces CPU efficiency;

c) The waiting method seems to have no advantages, but in the UC/OS51 operating system, a very important idea in task scheduling is delay. After a high-priority task is executed for a period of time, it is delayed for a period of time so that low-priority tasks can be delayed for a period of time. Priority task execution, so that the waiting time is placed in the delay time of the A/D processing task, can serve the purpose of killing multiple birds with one stone. We adopt this method.

3.3 SNMP processing tasks

When the UDP packet is received and the UDP header is processed, the SNMP packet is processed by the function udp_recv(). The basic idea is: decode the SNMP message. If the decoding is correct, determine whether the Community has the authority to perform the requested operation. If it does not have the authority, discard the message and send a Trap message to the manager. If the permissions are correct, the requested object is looked up from the MIB table on the agent. After finding it, perform the corresponding operation and generate a response message. Then SNMP encoding is performed. If the encoding is correct, the SNMP message is handed over to the upper layer protocol for processing. The SNMP processing flow is shown in Figure 4.

In the SNMP processing process, SNMP encoding and decoding are very critical. Taking decoding as an example to illustrate, the decoded SNMP message uses the SNMP version number, the community number used in the message, and the version number, indicating that the message uses SNMP. version. If the manager and the agent use different versions of the protocol, they will not be able to communicate normally. The community is equivalent to a key. Only the manager with the key can access the agent. Otherwise, the agent will not respond and the PDU will be decoded. The object to be accessed by the manager, the flow chart of SNMP decoding is shown in Figure 5.

The snmpDec() function in the flow chart decodes the SNMP function message and extracts useful information. The function of the MibRequest() function is to find the decoded OID (object identifier) ​​in the MIB residing in the embedded SNMP agent. ), after finding the OID, the information of this object is obtained at the same time, and the encoding starts at the same time. The function of the MibCmpObjId() function is to use comparison to find table entries. The SnmpEnc() function encodes the obtained response message into an SNMP message according to the SNMP encoding rules. The make_udp() function encapsulates SNMP messages in UDP messages. After being encapsulated by IP protocol and Ethernet protocol, it can be transmitted through Ethernet.

4 Conclusion

We use this system for network management and monitoring systems for optical wireless communications. After use, it was found that this system can monitor the operation of the optical wireless communication system in real time. Since the Internet is used to transmit data, the transmission distance is not limited. SNMP is the most widely used network management protocol and the implementation of embedded SNMP agents can make optical The management of the wireless communication system can be easily added to the existing network management system. Since a cheap microcontroller is used to implement the embedded SNMP agent, the main protocol processing is implemented by software, and the cost is very low.

Keywords:network Reference address:Design and implementation of embedded SNMP agent based on microcontroller

Previous article:Microcontroller driver stepper motor program
Next article:RTOS-AVRX application of AVR microcontroller

Recommended ReadingLatest update time:2024-11-16 19:59

MICA.network presents Industry 4.0 solutions at SPS IPC Drives
Harting will focus on solutions for standalone function boards of modular industrial computing architecture, which makes it very easy to implement industrial fieldbus interfaces and wireless communications. In addition to Profinet, EtherCAT, Ethernet EtherNet/IP and Modbus RTU/TCP, the modular industrial computing ar
[Industrial Control]
MICA.network presents Industry 4.0 solutions at SPS IPC Drives
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号