?? main.c
字號:
/************************************************
* GPRS demo, use ppp to connect internet
* use ttyS1 to ctrol GPRS
* by Zou jian guo <ah_zou@163.com>
* 2004-11-02
*
*************************************************/
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include "tty.h"
#include "gprs.h"
#include "../keyboard/get_key.h"
/*--------------------------------------------------------*/
#define END "--" //程序結束控制鍵
#define FALSE 0
#define TRUE 1
/*--------------------------------------------------------*/
volatile int STOP=FALSE; //程序結束判斷標志
char shell_s[]="\nkeyshell>$: "; //命令提示符
/*--------------------------------------------------------*/
//keyshell線程處理函數
void * keyshell()
{
char cmd[256]={0,};
//鍵盤初始化
kbd_init();
//GPRS初始化
gprs_init();
//輸出命令菜單
printf("\n<gprs control shell>");
printf("\n [1] give a call");
printf("\n [2] respond a call");
printf("\n [3] hold a call");
printf("\n [4] send a msg");
printf("\n [**] help menu");
printf("\n [--] exit");
while(STOP==FALSE){
//輸出命令提示符
printf(shell_s);
//清除緩沖
fflush(stdout);
//讀取一行輸入
get_line(cmd);
//輸出回車換行
printf("\r\n");
if(strncmp("1",cmd,1)==0){
//撥打電話
printf("\ngvie a call, please input number:");
fflush(stdout);
get_line(cmd);
gprs_call(cmd, strlen(cmd));
printf("\ncalling......");
} else if(strncmp("2",cmd,1)==0){
//接聽電話
gprs_ans();
printf("\nanswering.......");
} else if(strncmp("3",cmd,1)==0){
//掛斷電話
gprs_hold();
printf("\nhold a call");
}else if (strncmp("4",cmd,1)==0){
//發送短信
printf("\nsend a message, please input number:");
fflush(stdout);
get_line(cmd);
gprs_msg(cmd, strlen(cmd));
printf("\nsending......");
}else if (strncmp("**",cmd,2)==0){
//重新輸出菜單
printf("\n<gprs control shell>");
printf("\n [1] give a call");
printf("\n [2] respond a call");
printf("\n [3] hold a call");
printf("\n [4] send a msg");
printf("\n [**] help menu");
}else if (strncmp(END,cmd,2)==0){
//設置程序結束標志
printf("\nexit......");
STOP=TRUE;
}else if(cmd[0] != 0){
//系統命令調用
system(cmd);
}
}
}
/*--------------------------------------------------------*/
/*讀gprs反饋信息線程處理函數*/
void* gprs_read(void * data)
{
int i=0;
char c;
char buf[1024];
printf("\nread modem\n");
//循環讀取gprs串口數據,并輸出
while (STOP==FALSE) {
tty_read(&c,1);
printf("%c",c);
}
printf("exit from reading modem\n");
return NULL;
}
/*--------------------------------------------------------*/
int main(int argc,char** argv)
{
pthread_t th_a, th_b;
//初始化gprs串口
tty_init();
//創建keyshell和gprs_read線程
pthread_create(&th_a, NULL, keyshell, 0);
pthread_create(&th_b, NULL, gprs_read, 0);
pthread_join(th_a, NULL);
pthread_join(th_b, NULL);
//恢復并關閉gprs串口
tty_end();
exit(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -