繁体中文
设为首页
加入收藏
当前位置:技术文章首页 >> 嵌入式系统 >> 使用ATMega88实现HTTP/TCP(AVR Web服务器)

使用ATMega88实现HTTP/TCP(AVR Web服务器) (1)

2007-12-02 23:38:12  作者:  来源:互联网  浏览次数:187  文字大小:【】【】【
简介:本文是之前《基于AR的以太网设备》的续篇。硬件还 ...
本文是之前《基于AR的以太网设备》的续篇。硬件还和之前一样(ENC28j60+ATMega88)。片内软件现在已经升级到能够支持做一个Web服务器了。 That is: instead of using a command line application and send UDP packets to the Ethernet deice we can just point our web browser to it. .... and een better: we add only the web serer and all the UDP based functionality is still there. Now you can use both! 升级的部分是:使用web浏览器取代之前的命令行发送UDR数据报的方式来访问我们的以太网设备……之前的UDP基本功能仍然保留。现在,这两种功能你都可以使用了! The code is written in C and there is een a lot of space left on the atmega88 microcontroller. 即便代码是使用C编写的,(编译以后)ATMeg88存储器中仍然有相当的剩余。 All hardware components are aailable from shop.tuxgraphics.org. The software and circuit diagrams are aailable for free (GPL 2 license). 代码和电路都是免费可用的。 Introduction A UDP command interface is sufficient for most applications but an integrated web-serer is much more uniersal and easier to use. How to build a web serer into an atmega88 chip? 对于大部分应用场合,UDP命令行的方式已经足够了,但是,对于一个简单通用的综合性Web服务器来说,却远远不够。怎样在一个ATMega88中建立一个Web服务器呢? Before starting this Ethernet project I did of course some prototyping and then I noticed already that UDP was not a problem with lots of space left on the atmega88. Therefore I was quite confident that TCP + HTTP will work. TCP/IP was inented more than 25 years ago. Todays microcontrollers proide almost the computing power a standard computer had at that time. No jaa or xml was used at that time. Things were done in smart and efficient ways. 在我开始做这个以太网项目的之前,我做了一些原型机,在这个过程中,我注意到,即便实现了UDP协议以后,ATMega88中仍然有大量的空间剩余。因此,我对于实现TCP+HTTP非常有信心。TCP/IP协议已经诞生了将近25年。当今的微控制器提供了一个几乎和从前标准计算机相同的计算能力。而从前,没有jaa和xml。今天,同样的事情通过一种更加小巧有效的方法完成。 So here is a real web-serer on an atmega88 AR microcontroller. 所以今天,我们将在这里通过ATMega88实现一个真正的Web网络服务器。 TCP is a state machine TCP 是一个状态机 TCP is a protocol where one establishes a connection. For this a number of packets are first exchanged and both sides of the connection go through seeral states [see tcp state machine from rfc793]. Once the connection is established a number of data packets can be sent. More than one packet, large amounts of data can be sent. Counters and the state machine ensure that the actual user data arries in correct order and without data loss. TCP是一个建立网络连接的协议。通过该协议,在连接建立之前,连接双方通过交换一些IP数据报实现在一些状态间进行切换[请参照RFC793标准中TCP状态机的相关内容]。一旦连接建立成功,包含数据的IP数据报将被传送——实现海量数据的传输。通过计数器和状态机我们可以确认数据被按照正确的顺序传送,并且没有发生丢失。 Large web pages will need to send many data packets. Small pages less. How many do we need to send??? 大的网页需要发送大量的数据包,当然,小的网页需要传送的数据包就要少些(数据包就是包含实际数据的IP数据报),那么,我们究竟需要发送多少呢? Let’s take a look at the application introduced in the first article [June 2006, article060601]. In this first article we just switch on and off something. It can be done with a simple web page which might look like this: 让我们回顾一下本文的前篇中提到过的那个程序。在前文中,我们只是(用UDP协议实现)将一些开关打开(Switch on)或者关闭(Switch off),同样的功能可以通过下面的简单网页来实现: Output is: ON Switch off Figure 1: The web page needed for the Ethernet Remote Deice circuit. Figure 1:使用网页来配置远处的以太网设备 Other applications might be measurement of temperature or air pressure. Those are all small web pages with is ery little data. In other words we will send less than 100 bytes including all the html tags. How many IP packets with data will be sent for such a page? Just one! 在其他的应用中,可能是(用UDP协议)来采集温度或者气压。这些都是小的网页,只需要很少少的信息量。换句话说,我们只需要发送不到100个字节的信息就可以包含所有的HTML网页信息了。那么,这种情况下究竟需要多少IP数据包来发送这样的页面呢? The whole point of using TCP is that one can send more than one packet of data but we don’t need that functionality. We need TCP only because HTTP is based on it and we want HTTP in order to use our web browser. 使用TCP协议的要点是:虽然发送者可以发送多个数据包,但我们并不需要这样能够的功能。我们是用TCP协议,只是因为我们网页浏览器使用的HTTP协议是建立在TCP基础之上的。 Under the assumption that you will neer need to send more than one packet with data the whole TCP protocol and state handling can be simplified a lot. We can e.g send the FIN immediately together with the data. This makes the state handling for the closing of the connection ery simple. 假设我们永远也不需要发送多于一个的数据包,那么整个TCP协议以及其状态处理可以大大的简化。例如,我们可以在发送完数据以后立即发送FIN(申请断开连接的请求信号)。这样,关闭连接的状态处理就变得非常简单了(因为
[1] [2]

责任编辑:cjb


 

最新文章

更多

· 基于PXA255的交通管理系...
· 基于TMS320DM642设计的网...
· 基于嵌入式 Linux 的移动...
· 一种基于单片机和GPRS的...
· 基于TMS320DM642设计的视...
· 基于S3C2410设计的脉象仪...
· 基于CAN总线的网络化智能...
· 基于单片机AT89C52和VB设...
· 飞思卡尔MPX5050血压监视...
· BGA715L7 GPS低噪放大方案

推荐文章

更多

· 基于PXA255的交通管理系...
· 基于TMS320DM642设计的网...
· 基于嵌入式 Linux 的移动...
· 一种基于单片机和GPRS的...
· 基于TMS320DM642设计的视...
· 基于S3C2410设计的脉象仪...
· 基于CAN总线的网络化智能...
· 基于单片机AT89C52和VB设...
· 飞思卡尔MPX5050血压监视...
· BGA715L7 GPS低噪放大方案
. 使用ATMega88实现HTTP/TCP(AVR Web服务器)

热点文章

更多

· 基于TMS320DM642设计的网...
· 基于PXA255的交通管理系...
. 使用ATMega88实现HTTP/TCP(AVR Web服务器)