Chinaunix首页 | 论坛 | 博客
  • 博客访问: 513857
  • 博文数量: 187
  • 博客积分: 3011
  • 博客等级: 中校
  • 技术积分: 2092
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-28 17:08
文章分类

全部博文(187)

文章存档

2011年(1)

2010年(8)

2009年(178)

我的朋友

分类:

2009-07-02 14:03:17

  

        主要内容是在Linux中驱动摄像头(WebCam),用Spcaserv 服务器架设网络监

       控系统,客户端通过浏览器进行时时监控。

一、    大作业任务要求

linux2.6内核基础上搭建下面的环境

1)摄像头(中星微芯片)

2)搭建web服务器

3)编译一个摄像头采集程序和客户端服务程序(ServfoxSpcaview的使用.

 

 

二、系统结构与功能

       程序结构为B/S模式,其中运行在开发主机上的是浏览器,运行在嵌入式设备上的是服务器端。所以整个监控系统的重点在于服务器端的开发。
        
整个系统服务器端的设计分为两部分:
            A
HttpServer部分
            B
OS监控端部分

 

三、 实现方法

   任务要求提到几点,下面祥细的介绍一下,boa嵌入式web用服务器\摄像头采集程序和客户端服务程序(ServfoxSpcaview的使用.

 

首先讲一下boa的搭建

    一、Boa程序的移植

1、下载Boa源码
   
下载地址:
   
目前最新发行版本: 0.94.13   (几年没更新版本了)
   
下载 boa-0.94.13.tar.gz

注意:若从boa上下载的是boa-0.94.13.tar.tar,解压方式一样

[root@jimmy]# tar xzf boa-0.94.13.tar.gz

 

2、生成Makefile文件
   
进入boa-0.94.13直接运行src/configure文件

[tekkamanninja@Tekkaman-Ninja src]$./configure

3、修改Makefile文件

CC = /usr/local/arm/3.4.1/bin/arm-linux-gcc
CPP = /usr/local/arm/3.4.1/bin/arm-linux-gcc -E

4、交叉编译

[tekkamanninja@Tekkaman-Ninja src]$ make

 

5、去除调试信息,减小体积。(可选)

[tekkamanninja@Tekkaman-Ninja src]$ /usr/local/arm/3.4.1/bin/arm-linux--strip boa

 

6.我在上面的进过中,编译时有提示错误。然后修改如下

util.c:100:1: error: pasting "t" and "->" does not give a valid preprocessing token

make: *** [util.o] Error 1

解决方法:

修改 src/compat.h

找到

#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff

修改成

#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff

 

 

 

 

7.修改boa.conf  和目标板的一样,以下是boa.conf修改后的,注意是修改了所建立目录的路径。

# Boa v0.94 configuration file

# File format has not changed from 0.93

# File format has changed little from 0.92

# version changes are noted in the comments

#

# The Boa configuration file is parsed with a lex/yacc or flex/bison

# generated parser.  If it reports an error, the line number will be

# provided; it should be easy to spot.  The syntax of each of these

# rules is very simple, and they can occur in any order.  Where possible

# these directives mimic those of NCSA httpd 1.3; I saw no reason to

# introduce gratuitous differences.

 

# $Id: boa.conf,v 1.25 2002/03/22 04:33:09 jnelson Exp $

 

# The "ServerRoot" is not in this configuration file.  It can be compiled

# into the server (see defines.h) or specified on the command line with

# the -c option, for example:

#

# boa -c /usr/local/boa

 

 

# Port: The port Boa runs on.  The default port for http servers is 80.

# If it is less than 1024, the server must be started as root.

 

Port 80

 

# Listen: the Internet address to bind(2) to.  If you leave it out,

# it takes the behavior before 0.93.17.2, which is to bind to all

# addresses (INADDR_ANY).  You only get one "Listen" directive,

# if you want service on multiple IP addresses, you have three choices:

#    1. Run boa without a "Listen" directive

#       a. All addresses are treated the same; makes sense if the addresses

#          are localhost, ppp, and eth0.

#       b. Use the VirtualHost directive below to point requests to different

#          files.  Should be good for a very large number of addresses (web

#          hosting clients).

#    2. Run one copy of boa per IP address, each has its own configuration

#       with a "Listen" directive.  No big deal up to a few tens of addresses.

#       Nice separation between clients.

# The name you provide gets run through inet_aton(3), so you have to use dotted

# quad notation.  This configuration is too important to trust some DNS.

 

#Listen 192.68.0.5

 

#  User: The name or UID the server should run as.

# Group: The group name or GID the server should run as.

 

User root

Group 0

 

# ServerAdmin: The email address where server problems should be sent.

# Note: this is not currently used, except as an environment variable

# for CGIs.

 

#ServerAdmin root@localhost

 

# ErrorLog: The location of the error log file. If this does not start

# with /, it is considered relative to the server root.

# Set to /dev/null if you don't want errors logged.

# If unset, defaults to /dev/stderr

 

ErrorLog /mnt/yaffs/var/log/boa/error_log

# Please NOTE: Sending the logs to a pipe ('|'), as shown below,

#  is somewhat experimental and might fail under heavy load.

# "Usual libc implementations of printf will stall the whole

#  process if the receiving end of a pipe stops reading."

#ErrorLog "|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log"

 

# AccessLog: The location of the access log file. If this does not

# start with /, it is considered relative to the server root.

# Comment out or set to /dev/null (less effective) to disable

# Access logging.

 

AccessLog /mnt/yaffs/var/log/boa/access_log

# Please NOTE: Sending the logs to a pipe ('|'), as shown below,

#  is somewhat experimental and might fail under heavy load.

# "Usual libc implementations of printf will stall the whole

#  process if the receiving end of a pipe stops reading."

#AccessLog  "|/usr/sbin/cronolog --symlink=/var/log/boa/access_log /var/log/boa/access-%Y%m%d.log"

 

# UseLocaltime: Logical switch.  Uncomment to use localtime

# instead of UTC time

#UseLocaltime

 

# VerboseCGILogs: this is just a logical switch.

#  It simply notes the start and stop times of cgis in the error log

# Comment out to disable.

 

#VerboseCGILogs

 

# ServerName: the name of this server that should be sent back to

# clients if different than that returned by gethostname + gethostbyname

 

ServerName

 

# VirtualHost: a logical switch.

# Comment out to disable.

# Given DocumentRoot /var/www, requests on interface 'A' or IP 'IP-A'

# become /var/www/IP-A.

# Example: becomes /var/www/127.0.0.1

#

# Not used until version 0.93.17.2.  This "feature" also breaks commonlog

# output rules, it prepends the interface number to each access_log line.

# You are expected to fix that problem with a postprocessing script.

 

#VirtualHost

 

# DocumentRoot: The root directory of the HTML documents.

# Comment out to disable server non user files.

 

DocumentRoot /mnt/yaffs/var/www

 

# UserDir: The name of the directory which is appended onto a user's home

# directory if a ~user request is recieved.

 

UserDir public_html

 

# DirectoryIndex: Name of the file to use as a pre-written HTML

# directory index.  Please MAKE AND USE THESE FILES.  On the

# fly creation of directory indexes can be _slow_.

# Comment out to always use DirectoryMaker

 

DirectoryIndex index.html

 

# DirectoryMaker: Name of program used to create a directory listing.

# Comment out to disable directory listings.  If both this and

# DirectoryIndex are commented out, accessing a directory will give

# an error (though accessing files in the directory are still ok).

 

DirectoryMaker /usr/lib/boa/boa_indexer

 

# DirectoryCache: If DirectoryIndex doesn't exist, and DirectoryMaker

# has been commented out, the the on-the-fly indexing of Boa can be used

# to generate indexes of directories. Be warned that the output is

# extremely minimal and can cause delays when slow disks are used.

# Note: The DirectoryCache must be writable by the same user/group that

# Boa runs as.

 

# DirectoryCache /var/spool/boa/dircache

 

# KeepAliveMax: Number of KeepAlive requests to allow per connection

# Comment out, or set to 0 to disable keepalive processing

 

KeepAliveMax 1000

 

# KeepAliveTimeout: seconds to wait before keepalive connection times out

 

KeepAliveTimeout 10

 

# MimeTypes: This is the file that is used to generate mime type pairs

# and Content-Type fields for boa.

# Set to /dev/null if you do not want to load a mime types file.

# Do *not* comment out (better use AddType!)

 

MimeTypes /mnt/yaffs/temp/mime.types

 

# DefaultType: MIME type used if the file extension is unknown, or there

# is no file extension.

 

DefaultType text/plain

 

# CGIPath: The value of the $PATH environment variable given to CGI progs.

 

CGIPath /bin:/usr/bin:/usr/local/bin

 

# SinglePostLimit: The maximum allowable number of bytes in

# a single POST.  Default is normally 1MB.

 

# AddType: adds types without editing mime.types

# Example: AddType type extension [extension ...]

 

# Uncomment the next line if you want .cgi files to execute from anywhere

#AddType application/x-httpd-cgi cgi

 

# Redirect, Alias, and ScriptAlias all have the same semantics -- they

# match the beginning of a request and take appropriate action.  Use

# Redirect for other servers, Alias for the same server, and ScriptAlias

# to enable directories for script execution.

 

# Redirect allows you to tell clients about documents which used to exist in

# your server's namespace, but do not anymore. This allows you to tell the

# clients where to look for the relocated document.

# Example: Redirect /bar

 

# Aliases: Aliases one path to another.

# Example: Alias /path1/bar /path2/foo

 

Alias /doc /usr/doc

 

# ScriptAlias: Maps a virtual path to a directory for serving scripts

# Example: ScriptAlias /htbin/ /www/htbin/

 

ScriptAlias /cgi-bin/ /mnt/yafss/var/www/cgi-bin/

8Group的修改

修改 Group nogroup
Group 0开发板上有的组)
修改 User nobody
User root组中的一个成员)

根据你的开发板的情况设定。一定要存在的组和用户。

 

9ScriptAlias的修改

修改 ScriptAlias /cgi-bin/  /usr/lib/cgi-bin/
ScriptAlias /cgi-bin/  /mnt/var/www/cgi-bin    (这里也是根据自己的开发板来建立吧)

这是在设置CGI的目录,你也可以设置成别的目录。比如用户文件夹下的某个目录

10ServerName的设置

修改 #ServerName
ServerName

注意:该项默认为未打开,执行Boa会异常退出,提示“gethostbyname::No such file or directory”,所以必须打开。其它默认设置即可。你也可以设置为你自己想要的名字。比如我设置为:ServerName tekkaman2440

此外,还需要:

11(以下配置和boa.conf的配置有关)

创建日志文件所在目录/var/log/boa

创建HTML文档的主目录/var/www

创建CGI脚本所在录 /var/www/cgi-bin

注(上面的目录看你喜欢建立在有权限建立目录的地方下)

[tekkamanninja@Tekkaman-Ninja log]$ mkdir -m 777 boa
[tekkamanninja@Tekkaman-Ninja log]$ cd ..
[tekkamanninja@Tekkaman-Ninja var]$ mkdir -m 777 www
[tekkamanninja@Tekkaman-Ninja var]$ mkdir -m 777 www/cgi-bin
[tekkamanninja@Tekkaman-Ninja var]$ cd ..
然后把boa boa.conf mime.types  移到到目标机的一个目录下。Mime.types 的位置要和boa.conf相对应.

12运行Boa

开发板操作:

[root@~]#boa

如果发现boa没有运行,则可以在开发板的/var/log/boa/error_log文件中找原因。

比如端口已被其他程序占用:

[root@~]#cat /var/log/boa/error_log
[20/Feb/2008:21:21:57 +0000] boa.c:194 - unable to bind: Address already in use

或是用户设置错误等等,都可以查到。

13功能测试

静态网页测试

将静态网页存入根文件系统的/var/www目录下(可以将主机 /usr/share/doc/HTML/目录下的index.htmlhomepage.cssimgstylesheet-images目录复制到/var/www目录下

运行boa的命令:

#/boa –c      最后的点是当前目录,它要指定boa.conf所在.

 

ServfoxSpcaview的使用

下载的原码包:servfox-R1_1_3.tar.gz    spcaview-20061208.tar.gz

   

客户端浏览服务器采集的视频可以有两种形式。

一种是通过在pc(linux )浏览,要编译  spcaview-20061208.tar.gz 产生一个spcaview来浏览。另一种是通过在xp下浏览器来访问,要安装一个jre-6u7-windows-i586-p-s.exe的插件。

 

现在讲第一种先。

2.移植服务器端程序

服务器端程序我用的是servfox ,下载,解压,进入其目录,观察之,发现没有makefile,但有一个makefile.arm,还有一个makefile.386,于是将makefile.arm改名为makefile,然后输入命令
make          
编译正常,没有出错

 

运行servfox,出错,提示为找到到该命令,老问题,以前遇到过类似问题,原因是该命令为动态链接,而开发板上没有相关的库文件,所以无法运行,需要静态链接。
回到PC,打开makefile,将所有用到arm-linux-gcc的地方,都加上一个参数-static,其实就三个地方。
然后重新编译,在开发板上运行,输入命令:
./servfox –g -d /dev/video0 -s 320x240 -w 7070
程序运行了,提示为
servfox version: 1.1.3 date: 11:12:2005 (C)
[email=mxhaard@magic.fr]mxhaard@magic.fr[/email]
wrong spca5xx device
Waiting .... for connection. CTrl_c to stop !!!!
Got connection from 192.168.141.234

 

3编译客户端程序

客户端程序使用的是spcaview

这个程序是在PC上运行的,解压后,直接编译就行,
make
生成可执行文件spcaview,运行之

注(一开始我在ubuntumake 这个程序,提示很多错误。好像缺少很多变量。最后我在redhat 9里编译,就没有错误的提示。对比了一下,两边环境的gcc版本不同redhat9 ubuntu 低。可能是用低版本的编译器才支持。)

 

./spcaview -g -s 320x240 -w 192.168.141.236:7070

上面成功运行后,就产一个小界面,看得到摄像头所照的东西。

 

 

4.通过浏览器

  XP下安装jre-6u7-windows-i586-p-s.exe这个小插件就OK了。

 

5.付上无线网卡的设置过程

# insmod rt73.ko

# ifconfig rausb0 inet 192.168.0.3 up

# route add default gw 192.168.0.1

# iwconfig rausb0 essid "dansen"

# iwconfig rausb0 mode Ad-hoc

# iwconfig rausb0 channel 1

 

 

 

四、 运行状况

      视频彩集比较流畅,画面算清晰。

 

 

五、结论

这个课程设计是在之前移植linux2.6内核的基础上慢慢扩展开来的。移植好内核后,想在上面搭建一个web、后面想移植usb摄像头驱动,通过web来监控周围的环境。现在也调试成功,通过无线网卡来访问实验箱里的web服务器.

 

 通过前面的工作,感觉自己这次课程设计像在做监控系统。如果做成监控系统,现在的系统的功能还不够强大。现在想到的就是想扩展以下几项工能:

1.         增加一个gprs发送功能

2.         增加一个红外感应

增加摄像头拍照和存储功能
阅读(1343) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Linux磁盘管理--fstab文件的修改

给主人留下些什么吧!~~