第一步 移植boa服务器到2440,在上一篇文章已经描述过。
第二步 2440通过串口连接CC2530 ,2440一共有3个串口,dev/tts/0(1,2)其中串口0是RS232电平的,串口1,2只有TTL电平,串口0要用作终端控制,所以选择串口2作为串口输出,通过一个转换芯片把TTL连接到CC2530的RS232接口上。修改mini2440的串口程序,使程序每执行一次,则发出一个字母‘a’,mini2440 串口程序如下
# include <stdio.h>
# include <stdlib.h>
# include <termio.h>
# include <unistd.h>
# include <fcntl.h>
# include <getopt.h>
# include <time.h>
# include <errno.h>
# include <string.h>
int main(int argc, char **argv)
{
int CommFd, TtyFd;
struct termios TtyAttr;
struct termios BackupTtyAttr;
int DeviceSpeed = B115200;
int TtySpeed = B115200;
int ByteBits = CS8;
const char *DeviceName = "/dev/ttyS0";
const char *TtyName = "/dev/tty";
int OutputHex = 0;
int OutputToStdout = 0;
int UseColor = 0;
opterr = 0;
printf("Content-type: text/html\n\n");
printf("<TITLE>Mult Result</TITLE>");
printf("<H3>Mult Result</H3>");
DeviceName = "/dev/tts/2";
<span style="white-space:pre"> </span> OutputToStdout = 1;
CommFd = open(DeviceName, O_RDWR, 0);
if (CommFd < 0)
<span style="white-space:pre"> </span>Error("Unable to open device");
if (fcntl(CommFd, F_SETFL, O_NONBLOCK) < 0)
<span style="white-space:pre"> </span>Error("Unable set to NONBLOCK mode");
memset(&TtyAttr, 0, sizeof(struct termios));
TtyAttr.c_iflag = IGNPAR;
TtyAttr.c_cflag = DeviceSpeed | HUPCL | ByteBits | CREAD | CLOCAL;
TtyAttr.c_cc[VMIN] = 1;
if (tcsetattr(CommFd, TCSANOW, &TtyAttr) < 0)
Warning("Unable to set comm port");
TtyFd = open(TtyName, O_RDWR | O_NDELAY, 0);
if (TtyFd < 0)
<span style="white-space:pre"> </span>Error("Unable to open tty");
TtyAttr.c_cflag = TtySpeed | HUPCL | ByteBits | CREAD | CLOCAL;
if (tcgetattr(TtyFd, &BackupTtyAttr) < 0)
<span style="white-space:pre"> </span>Error("Unable to get tty");
// if (tcsetattr(TtyFd, TCSANOW, &TtyAttr) < 0) è¿™æ¡å‘½ä»¤ä¼šæ˜¯WEBæ— æ³•æ‰§è¡Œä¸²å£ç¨‹åºru guo you zhe ju hua web buzhi xing chuankou chengxu
//<span style="white-space:pre"> </span>Error("Unable to set ")
for (;;) {
<span style="white-space:pre"> </span>unsigned char Char = 0;
unsigned char Cha='a';
int i=3;
<span style="white-space:pre"> </span>fd_set ReadSetFD;
<span style="white-space:pre"> </span>void OutputStdChar(FILE *File) {
<span style="white-space:pre"> </span> char Buffer[10];
<span style="white-space:pre"> </span> int Len = sprintf(Buffer, OutputHex ? "%.2X " : "%c", Char);
<span style="white-space:pre"> </span> fwrite(Buffer, 1, Len, File);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>FD_ZERO(&ReadSetFD);
<span style="white-space:pre"> </span>FD_SET(CommFd, &ReadSetFD);
<span style="white-space:pre"> </span>FD_SET( TtyFd, &ReadSetFD);
#<span style="white-space:pre"> </span>define max(x,y) ( ((x) >= (y)) ? (x) : (y) )
//<span style="white-space:pre"> </span>if (select(max(CommFd, TtyFd) + 1, &ReadSetFD, NULL, NULL, NULL) < 0) {
//<span style="white-space:pre"> </span> Error(strerror(errno)); // 这条命令会使程序需要一个输入才输出
//<span style="white-space:pre"> </span>}
#<span style="white-space:pre"> </span>undef max
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>static int EscKeyCount = 0;
write(CommFd, &Cha, 1);
<span style="white-space:pre"> </span>if (OutputToStdout) {
<span style="white-space:pre"> </span> if (UseColor)
<span style="white-space:pre"> </span>fwrite("\x1b[01;31m", 1, 8, stderr);
OutputStdChar(stderr);
<span style="white-space:pre"> </span> if (UseColor)
<span style="white-space:pre"> </span>fwrite("\x1b[00m", 1, 8, stderr);
<span style="white-space:pre"> </span> fflush(stderr);
<span style="white-space:pre"> </span> }
goto ExitLabel;
<span style="white-space:pre"> </span>if (Char == '\x1b') {
EscKeyCount ++;
if (EscKeyCount >= 1)
goto ExitLabel;
} else
EscKeyCount = 0;
<span style="white-space:pre"> </span> }
ExitLabel:
if (tcsetattr(TtyFd, TCSANOW, &BackupTtyAttr) < 0)
<span style="white-space:pre"> </span>Error("Unable to set tty");
return 0;
}
交叉编译之后生成armcomtest程序,用mv命令改名字为test.cgi,ftp到板子里
第三步 通过IAR将CC2530的zigbee程序编译好下载CC2530里,协调器程序为一旦串口接受到‘a’字母即向终端发送点灯命令,然后在开发板上执行./test.cgi命令 测试能不能点灯成功,测试发现可以成功。
第四步 通过boa调用test.cgi程序,由于C程序里有<pre name="code" class="cpp">printf("Content-type: text/html\n\n");
printf("<TITLE>Mult Result</TITLE>");
printf("<H3>Mult Result</H3>");
这三条语句,这是CGI程序的接口,表明这个程序可以被boa服务器调用,然后设置mini2440里index.html,调用test.cgi,可以通过网页控制zigbee
第五步 电脑开热点,2440连热点,被分配一个本地IP,手机连上热点访问这个本地IP就可以通过手机控制zigbee。