?? tel.c
字號(hào):
//=============================================================
// 文件名稱: tel.c
// 功能描述: 手機(jī)操作處理
// 維護(hù)記錄: 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)
// 實(shí)現(xiàn)功能: 先清空LCD上所有的內(nèi)容,顯示一個(gè)字符串
// 參數(shù): str 要顯示的字符串
// 返回值: 無
//=============================================================
void TFT_Tel_Print(char *str)
{
TFT_ClearWindow(Msg);
TFT_SetTextPos(Msg, 0, 0);
TFT_Print(Msg, str);
}
//=============================================================
// 語法格式: void TFT_Hear(void)
// 實(shí)現(xiàn)功能: 接聽電話,當(dāng)停止通過時(shí)退出
// 參數(shù): 無
// 返回值: 無
//=============================================================
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)
{ // 對(duì)方掛機(jī)
full = FALSE;
return;
}
if(strcmp(g_RecvBuf, "+CME ERROR: 27\r\n") == 0)
{ // 取消向?qū)Ψ降暮艚? 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; // 退出循環(huán)
case C_CANCEL:
i -= 2;
if(i < 0)
i = 0;
Tel_Num[i] = '\0';
break; // 退出函數(shù)
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)
// 實(shí)現(xiàn)功能: 拔打電話
// 參數(shù): 無
// 返回值: 無
//=============================================================
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; //退出循環(huán)
case C_HANG:
TFT_Tel_Print("已取消");
Loop = FALSE;
return; //退出函數(shù)
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)
// 實(shí)現(xiàn)功能: 接聽電話
// 參數(shù): 無
// 返回值: 無
//=============================================================
void Tel_Ans(void)
{
GPRS_SendString("ATA\r\n");
TFT_Tel_Print("正在通話...");
}
//=============================================================
// 語法格式: void Tel_Hold(void)
// 實(shí)現(xiàn)功能: 掛斷電話
// 參數(shù): 無
// 返回值: 無
//=============================================================
void Tel_Hang(void)
{
GPRS_SendString("ATH\r\n");
TFT_Tel_Print("通話結(jié)束");
delay(20000);
}
//=============================================================
// 語法格式: void Info_Send(void)
// 實(shí)現(xiàn)功能: 發(fā)送短信
// 參數(shù): 無
// 返回值: 無
//=============================================================
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("請(qǐng)輸入電話號(hào)碼:\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("請(qǐng)輸入短消息:\n");
PY_GetString(Info, 100);
if(Info[0] == '\0')
{
GPRS_SendString("\033\r\n");
TFT_Tel_Print("發(fā)送取消");
delay(10000);
return;
}
GPRS_SendString(StrToUni(Info, Info_Uni));
GPRS_SendString("\032\r\n");
TFT_Tel_Print("發(fā)送成功!");
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("請(qǐng)入電話號(hào)碼:\n");
continue;
}
Tel_Num[--i] = '\0';
TFT_Tel_Print(Tel_Num);
}
delay(10000);
}
}
//=============================================================
// 語法格式: int Msg_Show(int Num)
// 實(shí)現(xiàn)功能: 讀取一個(gè)短信
// 參數(shù): Num 讀取短信的序號(hào)
// 返回值: 成功讀取返回OK
// 失敗返回ERROR
//=============================================================
int Msg_Show(int Num, int MaxNum)
{
int ret;
char Buf[300];
char Buf_GB[300];
if(Num > MaxNum)
{
TFT_Tel_Print("讀取短信錯(cuò)誤!");
return ERROR;
}
TFT_Tel_Print("請(qǐng)稍候...");
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發(fā)件人:%s\n時(shí)間:%s-%s\n內(nèi)容:\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)
// 實(shí)現(xiàn)功能: 獲取短信數(shù)量
// 參數(shù): 無
// 返回值: 短信數(shù)量
//=============================================================
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)
// 實(shí)現(xiàn)功能: 查詢短信
// 參數(shù): 無
// 返回值: 無
//=============================================================
void Info_Look(void)
{
int ret = 1000;
unsigned int result;
short x, y;
unsigned int Info_List = 1;
int MaxNum = 0;
TFT_Tel_Print("進(jìn)入收件箱, 請(qǐng)稍后...");
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);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -