#include <minigui/common.h> #include <minigui/minigui.h> #include <minigui/gdi.h> #include <minigui/window.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include "tty.h" #include "gprs.h" //gprs初始化
//设置音频通道、输出音频信号增益、话筒增益
void gprs_init() { tty_writecmd("at", strlen("at")); tty_writecmd("ate0", strlen("ate0")); //设置音频通道:1,副音频通道
tty_writecmd("at+chfa=1", strlen("at+chfa=1")); //设置输出音频信号增益:100,最大音量
tty_writecmd("at+clvl=100", strlen("at+clvl=100")); //设置通道1的话筒增益:10,最大增益
tty_writecmd("at+cmic=1,10", strlen("at+cmic=1,10")); //发送修改字符集命令:1,text格式
tty_writecmd("at+cmgf=1", strlen("at+cmgf=1")); //来电显示
tty_writecmd("at+clip=1", strlen("at+clip=1")); //选择TE字符集:GSM默认
tty_writecmd("at+cscs=\"GSM\"", strlen("at+cscs=\"GSM\"")); //接收新短消息
tty_writecmd("at+cnmi=2,1,0,0,0", strlen("at+cnmi=2,1,0,0,0")); }
//拨打电话
void gprs_call(char *number, int num) { tty_writecmd("at", strlen("at")); //发送拨打命令ATD
tty_write("atd", strlen("atd")); //发送电话号码
tty_write(number, num); //发送分号和命令结束标志
tty_write(";\r", strlen(";\r")); usleep(200000); } //实现接听电话gprs_ans()函数
void gprs_ans() { tty_writecmd("at", strlen("at")); //发送接听命令ATA
tty_writecmd("ata", strlen("ata")); } //完善代码:实现挂断电话gprs_hold()函数
void gprs_hold() { tty_writecmd("at", strlen("at")); //发送挂机命令ATH
tty_writecmd("ath", strlen("ath")); //tcflush(fd,TCIFLUCH);
} //实现发送短信的函数
void msg_send(char *number, char *text) { char ctl[]={26,0}; //ctl[0]=26,ctrl+z
tty_writecmd("at", strlen("at")); //发送修改字符集命令:1,text格式
tty_writecmd("at+cmgf=1", strlen("at+cmgf=1")); //发送短信命令:命令+号码+信息+结束符
tty_write("at+cmgs=", strlen("at+cmgs=")); //发送电话号码
tty_writecmd(number, strlen(number)); //发送文本信息
tty_write(text, strlen(text)); //发送结束符
tty_write(ctl, 1); usleep(300000); } //发送读取短信命令并获得短信的索引
void msg_read(int index) { char Cmd_Buffer[11]="at+cmgr="; char buffer[3]={'\0'}; gcvt((double)index, 2, buffer); //index转化为字符串
strcat(Cmd_Buffer,buffer); printf("the string is %s\n", Cmd_Buffer); //tty_writecmd("at", strlen("at"));
tty_writecmd(Cmd_Buffer, strlen(Cmd_Buffer)); } //删除短信息
void msg_delete(int index) { char Cmd_Buffer[11]="at+cmgd="; char buffer[3]={'\0'}; //tty_writecmd("at", strlen("at"));
gcvt((double)index, 2, buffer); strcat(Cmd_Buffer,buffer); tty_writecmd(Cmd_Buffer, strlen(Cmd_Buffer)); }
|