📄 tel.c
字号:
//=============================================================
// 文件名称: tel.c
// 功能描述: 手机操作处理
// 维护记录: by anxing created <anxing@sunnorth.com.cn>
// 2007.08.31 V1.0 modify by lijian <lijian@sunnorth.com.cn>
// 2007.12.21 V1.1 Modify bf hongyan <hongyan@sunnorth.com.cn>
//=============================================================
#include "tel.h"
extern WIN_HANDLE Msg;
//=============================================================
// 语法格式: void TFT_Tel_Print(char *str)
// 实现功能: 先清空LCD上所有的内容,显示一个字符串
// 参数: str 要显示的字符串
// 返回值: 无
//=============================================================
void TFT_Tel_Print(char *str)
{
TFT_ClearWindow(Msg);
TFT_SetTextPos(Msg, 0, 0);
TFT_Print(Msg, str);
}
//=============================================================
// 语法格式: void TFT_Hear(void)
// 实现功能: 接听电话,当停止通过时退出
// 参数: 无
// 返回值: 无
//=============================================================
void Tel_Hear(void)
{
int Key;
int i = 0;
char Tel_Num[20];
short x, y;
delay(10000);
while(1)
{
if(full == TRUE)
{
if(strcmp(g_RecvBuf, "OK\r\n") == 0)
full = FALSE;
if(strcmp(g_RecvBuf, "NO CARRIER\r\n") == 0)
{ // 对方挂机
full = FALSE;
return;
}
if(strcmp(g_RecvBuf, "+CME ERROR: 27\r\n") == 0)
{ // 取消向对方的呼叫
full = FALSE;
return;
}
}
if(Touch_Get(&x, &y) == -1)
continue;
Key = Touch_Trans(x, y);
switch(Key)
{
case C_ENTER:
if(i == 0)
break;
GPRS_SendString("AT+VTS=\"");
Tel_Num[i - 1] = '\"';
Tel_Num[i] = '\0';
GPRS_SendString(Tel_Num);
GPRS_SendString("\r\n");
TFT_Tel_Print("正在通话...");
i = 0;
break; // 退出循环
case C_CANCEL:
i -= 2;
if(i < 0)
i = 0;
Tel_Num[i] = '\0';
break; // 退出函数
case C_HANG: // 挂电话
Tel_Hang();
return;
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9:
Key += 48;
Tel_Num[i++] = Key;
Tel_Num[i++] = ',';
Tel_Num[i] = '\0';
TFT_Tel_Print(Tel_Num);
if(i > 18)
i -= 2;
break;
case C_STAR:
Tel_Num[i++] = 15; //'*'
Tel_Num[i++] = ',';
TFT_Tel_Print(Tel_Num);
if(i > 18)
i -= 2;
break;
case C_JING:
Tel_Num[i++] = 35; //'#'
Tel_Num[i++] = ',';
TFT_Tel_Print(Tel_Num);
if(i > 18)
i -= 2;
break;
}
delay(10000);
}
}
//=============================================================
// 语法格式: void TFT_call(void)
// 实现功能: 拔打电话
// 参数: 无
// 返回值: 无
//=============================================================
void Tel_Call(void)
{
int Key;
int i = 0;
char Tel_Num[20];
char Loop = TRUE;
short x, y;
while(Loop == TRUE)
{
if(Touch_Get(&x, &y) == -1)
continue;
Key = Touch_Trans(x, y);
switch(Key)
{
case C_CALL:
GPRS_SendString("ATD");
Tel_Num[i++] = ';';
Tel_Num[i++] = '\r';
Tel_Num[i++] = '\n';
Tel_Num[i] = '\0';
GPRS_SendString(Tel_Num);
TFT_Tel_Print("正在拔叫...");
Tel_Hear();
Loop = FALSE;
break; //退出循环
case C_HANG:
TFT_Tel_Print("已取消");
Loop = FALSE;
return; //退出函数
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9:
Key += 48;
Tel_Num[i++] = Key;
Tel_Num[i] = '\0';
TFT_Tel_Print(Tel_Num);
if(i > 17)
{
i--;
}
break;
case C_CANCEL:
if(i <= 1)
{
i = 1;
Loop = FALSE;
}
Tel_Num[--i] = '\0';
TFT_Tel_Print(Tel_Num);
}
delay(10000);
}
}
//=============================================================
// 语法格式: void Tel_Ans(void)
// 实现功能: 接听电话
// 参数: 无
// 返回值: 无
//=============================================================
void Tel_Ans(void)
{
GPRS_SendString("ATA\r\n");
TFT_Tel_Print("正在通话...");
}
//=============================================================
// 语法格式: void Tel_Hold(void)
// 实现功能: 挂断电话
// 参数: 无
// 返回值: 无
//=============================================================
void Tel_Hang(void)
{
GPRS_SendString("ATH\r\n");
TFT_Tel_Print("通话结束");
delay(20000);
}
//=============================================================
// 语法格式: void Info_Send(void)
// 实现功能: 发送短信
// 参数: 无
// 返回值: 无
//=============================================================
void Info_Send(void)
{
int Key;
int i = 0;
char Tel_Num[20];
char Tel_Num_Uin[40];
char Loop = TRUE;
char Info[100] = "";
char Info_Uni[200];
short x, y;
TFT_Tel_Print("请输入电话号码:\n");
while(Loop == TRUE)
{
if(Touch_Get(&x, &y) == -1)
continue;
Key = Touch_Trans(x, y);
switch(Key)
{
case C_ENTER:
GPRS_SendString("AT+CMGS=");
GPRS_SendString(StrToUniTel(Tel_Num, Tel_Num_Uin));
TFT_Tel_Print("请输入短消息:\n");
PY_GetString(Info, 100);
if(Info[0] == '\0')
{
GPRS_SendString("\033\r\n");
TFT_Tel_Print("发送取消");
delay(10000);
return;
}
GPRS_SendString(StrToUni(Info, Info_Uni));
GPRS_SendString("\032\r\n");
TFT_Tel_Print("发送成功!");
delay(50000);
return;
case C_HANG:
return;
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8: case 9:
Key += 48;
Tel_Num[i++] = Key;
Tel_Num[i] = '\0';
TFT_Tel_Print(Tel_Num);
if(i > 17)
i--;
break;
case C_CANCEL:
if(i < 1)
{
i = 1;
TFT_Tel_Print("请入电话号码:\n");
continue;
}
Tel_Num[--i] = '\0';
TFT_Tel_Print(Tel_Num);
}
delay(10000);
}
}
//=============================================================
// 语法格式: int Msg_Show(int Num)
// 实现功能: 读取一个短信
// 参数: Num 读取短信的序号
// 返回值: 成功读取返回OK
// 失败返回ERROR
//=============================================================
int Msg_Show(int Num, int MaxNum)
{
int ret;
char Buf[300];
char Buf_GB[300];
if(Num > MaxNum)
{
TFT_Tel_Print("读取短信错误!");
return ERROR;
}
TFT_Tel_Print("请稍候...");
delay(10000);
ClearQueue();
GPRS_SendString("AT+CMGR=");
GPRS_SendInt(Num);
GPRS_SendChar('\r');
GPRS_SendChar('\n');
delay(100000);
ret = DeleteQueue(Buf);
while(ret == OK)
{
if(strncmp(Buf, "+CMS ERROR:", 11) == 0)
{
return ERROR;
}
if(strncmp(Buf, "+CMGR:", 6) ==0)
{
char *TempList[10] = {"", "", "", "", "", ""};
int i;
_strsplit_(Buf, ",", TempList);
TempList[1]++;
TempList[1][strlen(TempList[1]) - 1] = '\0';
TFT_Tel_Print("收件箱");
TempList[3]++;
for(i = strlen(TempList[4]) - 1; i >= 0; i--)
{
if(TempList[4][i] == '+')
{
TempList[4][i] = '\0';
break;
}
}
TFT_Print(Msg, "(%d/%d)\n发件人:%s\n时间:%s-%s\n内容:\n", Num, MaxNum, UniToStr(TempList[1], Buf_GB), TempList[3], TempList[4]);
DeleteQueue(Buf);
TFT_Print(Msg, UniToStr(Buf, Buf_GB));
return OK;
}
ret = DeleteQueue(Buf);
}
return ERROR;
}
//=============================================================
// 语法格式: int Msg_GetNum(void)
// 实现功能: 获取短信数量
// 参数: 无
// 返回值: 短信数量
//=============================================================
int Msg_GetNum(void)
{
int ret;
char Buf[300];
delay(10000);
ClearQueue();
GPRS_SendString("AT+CPMS?");
GPRS_SendChar('\r');
GPRS_SendChar('\n');
delay(100000);
ret = DeleteQueue(Buf);
while(ret == OK)
{
if(strncmp(Buf, "+CMS ERROR:", 11) == 0)
{
return 0;
}
if(strncmp(Buf, "+CPMS:", 6) ==0)
{
char *TempList[10] = {"", "", "", "", "", "", "", "", "", ""};
_strsplit_(Buf, ",", TempList);
ret = _str2dec_(TempList[1]);
DeleteQueue(Buf);
return ret;
}
ret = DeleteQueue(Buf);
}
return 0;
}
//=============================================================
// 语法格式: void Info_Look(void)
// 实现功能: 查询短信
// 参数: 无
// 返回值: 无
//=============================================================
void Info_Look(void)
{
int ret = 1000;
unsigned int result;
short x, y;
unsigned int Info_List = 1;
int MaxNum = 0;
TFT_Tel_Print("进入收件箱, 请稍后...");
MaxNum = Msg_GetNum();
while(Msg_Show(Info_List, MaxNum) == ERROR);
while(1)
{
ret = Touch_Get(&x, &y);
if(ret == -1)
continue;
result = Touch_Trans(x, y);
switch(result)
{
case C_UP:
if(--Info_List < 1)
Info_List = MaxNum;
while(Msg_Show(Info_List, MaxNum) == ERROR);
break;
case C_DOWN:
if(++Info_List > MaxNum)
Info_List = 1;
while(Msg_Show(Info_List, MaxNum) == ERROR);
break;
case C_CANCEL:
case C_HANG:
GPRS_SendCommand("AT\r\n");
return;
}
delay(10000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -