⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个基于ARM平台的应用程序 能够具有接打电话
💻 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 + -