📄 command.c
字号:
/*
* =====================================================================================
*
* Filename: command.c
*
* Description:
*
* Version: 1.0
* Created: 2009年01月14日 10时41分34秒
* Revision: none
* Compiler: gcc
*
* Author: 杨小合 (CH), yang.xiaohe@163.com QQ:475094605
* Company: Student
*
* =====================================================================================
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"command.h"
#include"term.h"
#include"option.h"
#include"wave.h"
static void gprs_trim_lineend(char *cp);
static int gprs_do_relay1(int,char*);
static int gprs_do_relay2(int,char*);
static int gprs_do_monitor(int,char*);
static int gprs_do_sms(int,char*);
static int gprs_do_go1(int,char*);
static int gprs_do_go2(int,char*);
static int gprs_do_light1(int,char*);
static int gprs_do_light2(int,char*);
static int gprs_do_smoke(int,char*);
static int gprs_do_reshi(int,char*);
static int gprs_do_usage(int,char*);
static int gprs_do_quit(int,char*);
struct gprs_cmd_struct gprs_cmds[]=
{
{"RELAY1",gprs_do_relay1},/*继电器1*/
{"RELAY2",gprs_do_relay2},/*继电器2*/
{"MONITOR",gprs_do_monitor},/*回拨指定号码*/
{"SMS",gprs_do_sms},/*指定要发送手机的号码*/
{"GO1",gprs_do_go1},/*光耦1*/
{"GO2",gprs_do_go2},/*光耦2*/
{"LIGHT1",gprs_do_light1},/*红外光电反射1*/
{"LIGHT2",gprs_do_light2},/*红外光电反射2*/
{"SMOKE",gprs_do_smoke},/*烟雾传感器*/
{"RESHI",gprs_do_reshi},/*热释传感器*/
{"HELP",gprs_do_usage},/*帮助信息*/
{"QUIT",gprs_do_quit},
{NULL, NULL}
};
static void gprs_trim_lineend(char *cp)
{
if(cp && strlen(cp) > 0)
{
char *cp2 = &cp[strlen(cp) - 1];
while(*cp2 == '\r' || *cp2 == '\n')
{
*cp2 = '\0';
if(--cp2 < cp)
break;
}
}
}
int gprs_do_request(int fd,char buf[])
{
char *end= &buf[strlen(buf) - 1];
char *space = strchr(buf,' ');
int i;
char save;
if(*end == '\n' || *end == '\r')
{
gprs_trim_lineend(buf);
if(!space)
space = &buf[strlen(buf)];
save = *space;
*space = '\0';
for(i=0;gprs_cmds[i].cmd_name;i++)
{
if(strcmp(buf,gprs_cmds[i].cmd_name) == 0)
{
*space = save;
return gprs_cmds[i].cmd_handler(fd,buf);
}
}
}
return 0;
}
static int gprs_do_smoke(int fd,char *buf)
{
printf("gprs_do_smoke\n");
return 1;
}
static int gprs_do_relay1(int fd,char *buf)
{
playWav(WAVEFILE);
return 1;
}
static int gprs_do_relay2(int fd,char *buf)
{
return 1;
}
static int gprs_do_monitor(int fd,char *buf)
{
return 1;
}
static int gprs_do_sms(int fd,char *buf)
{
return 1;
}
static int gprs_do_go1(int fd,char *buf)
{
return 1;
}
static int gprs_do_go2(int fd,char *buf)
{
return 1;
}
static int gprs_do_light1(int fd,char *buf)
{
return 1;
}
static int gprs_do_light2(int fd,char *buf)
{
return 1;
}
static int gprs_do_reshi(int fd,char *buf)
{
char *cp=strchr(buf,' ');
cp=cp+1;
switch(*cp)
{
case 'T':
break;
case 'P':
break;
case 'R':
{
cp=cp+3;
printf("calling number %s\n",cp);
callph(fd,cp);
// sendSMS(fd,cp,cp);
break;
}
default:
return 0;
}
return 1;
}
static int gprs_do_usage(int fd,char *buf)
{
if(!strcmp(buf,"HELP"))
{
char *messages={"SMS P=phoneNumber\nSMOKE OPEN/CLOSE\nSMKOE T=number\n\
SMOKE P=phoneNumber\nSMOKE RECphoneNumber"};
strcpy(mess.mess_info,messages);
sendSMS(fd,mess.mess_n,mess.mess_info);
}
return 1;
}
static int gprs_do_quit(int fd,char *buf)
{
if(!strcmp(buf,"QUIT"))
gprs_status=0;
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -