📄 at_app.c
字号:
#include <stdio.h>
#include <string.h>
#include "asixwin.h"
#include "asixapp.h"
#include "lmalloc.h"
#include "at.h"
#include "asix_ed.h"
#include "at_rps.h"
#include "at_pdu.h"
#include "psat.h"
#define ST_COMMAND_ERROR 0x00
#define ST_INACTIVE_HANG_UP 0x03
#define ST_INACTIVE_PICK_UP 0x04
#define ST_DIALING 0x05
#define ST_TALKING 0x06
#define ST_RINGING 0x07
static U8 ReceiveCallDlg( char *number );
static U8 ReceiveSMSDlg( void );
static U8 VoiceCall( void );
static U8 SMSCenter( void );
static U8 ReadSMS( char *number );
static U8 curSMSFormat;
static U8 LastSMS = 25;
void testAt( )
{
MSG msg;
U32 hGC;
U8 failure, quit;
hGC = GetGC();
// initialize GSM module
do
{
ClearScreen( hGC, GPC_WHITE );
DrawText( hGC, "正在初始化GSM\n请等待片刻...", 40, 60, 120, 140, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
failure = 0;
// Set echo mode
//TEST_AT( ); // test
//if( WAIT_AT_COMMAND_RPS( &msg, AT_COM_AT ) != SYS_OK )
// failure |= 0x01;//goto ERROR_HANDLE;
SET_ECHO_MODE( "0" ); // echo off
if( WAIT_AT_COMMAND_RPS( &msg, AT_COM_ATE ) != SYS_OK )
failure |= 0x01;//goto ERROR_HANDLE;
// Set SMS format
SET_SMS_FORMAT( "0" ); // PDU format
if( WAIT_AT_COMMAND_RPS( &msg, AT_COM_CMGF ) != SYS_OK )
failure |= 0x02;//goto ERROR_HANDLE;
// Set CNMI
SET_CNMI_MODE( "2,1,0,0,1" ); // alert display arriving sms
if( WAIT_AT_COMMAND_RPS( &msg, AT_COM_CNMI ) != SYS_OK )
failure |= 0x04;//goto ERROR_HANDLE;
// Set CLIP
SET_CLIP_MODE( "1" ); // display incoming call number
if( WAIT_AT_COMMAND_RPS( &msg, AT_COM_CLIP ) != SYS_OK )
failure |= 0x08;//goto ERROR_HANDLE;
if( failure != 0 )
{
S8 str[25] = "初始化GSM失败...";
ClearScreen( hGC, GPC_WHITE );
sprintf( &str[16], "%x", failure );
DrawText( hGC, str, 20, 60, 140, 140, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
switch( MessageBox( 0, "初始化GSM失败!\n重新初始化?", "警告!", MB_YESNO ) )
{
case IDYES:
quit = 0;
break;
case IDNO:
quit = 1;
break;
}
}
else
quit = 1;
}while( quit == 0 );
VoiceCall( );
/* // because GSM module can not provide BUSY signal, we use soft timer to detect hangup.
CreateTimer( &ringTimer, 10000, NULL, NULL, ALARM_MODE|AUTO_CLEAR_MODE );
while( !quit )
{
ASIXGetMessage( &msg, NULL, 0, 0 );
switch( msg.message )
{
case WM_COMMAND:
if( msg.lparam == btTest )
{
TEST_AT( );
}
else if( msg.lparam == btCall )
{
//char *add = "13809000282";
//char *add = "13851614197";
char *add = "13813839703";
//char *add = "0253794248";
DIAL( add );
}
else if( msg.lparam == btHangUp )
{
HANG_UP( );
}
else if( msg.lparam == btPickUp )
{
PICK_UP( );
}
else if( msg.lparam == btSMSFormat )
{
char *comstr;
if( curSMSFormat == 0 ) // previous is PDU format, then change to Text format
{
comstr = "1";
curSMSFormat = 1;
SetWindowText( stSMSFormat, "Text Format", NULL );
}
else // previous is Text format, then change to PDU format
{
comstr = "0";
curSMSFormat = 0;
SetWindowText( stSMSFormat, "PDU Format", NULL );
}
SET_SMS_FORMAT( comstr );
}
else if( msg.lparam == btSMSRead )
{
READ_SMS( "1" );
}
else if( msg.lparam == btSMSSend )
{
//char *ad = "13813839703", *data = "okok!成功";//"哈立希岛上,姐姐爱尔克,每夜每夜都燃着一盏灯。灯光就亮在她的窗前,她要用这灯光来给她航海的兄弟指路,她怕他那远航的兄弟找不到回家的门。有时候";
//char *ad = "13851614197", *data = "你好";
//char *ad = "13952060913", *data = "ok!成功";
char *ad = "13851792696", *data = "ok!成功";
SEND_SMS( ad, data );
}
break;
case WM_AT:
switch( msg.lparam )
{
case AT_RPS_OK:
// uartmsg.message = SM_SWITCH;
// uartmsg.lparam = SWAP_TASK_LATER;
// uartmsg.wparam = PSA_TASK_ID;
// uartmsg.data = NULL;
// SysSendMessage( SYSTASK_ID, &uartmsg );
SetWindowText( stState, "OK", NULL );
break;
case AT_RPS_RING:
uartmsg.message = SM_SWITCH;
uartmsg.lparam = SWAP_TASK_LATER;
uartmsg.wparam = PSA_TASK_ID;
uartmsg.data = NULL;
SysSendMessage( SYSTASK_ID, &uartmsg );
SetWindowText( stState, "Ring", NULL );
StartTimer( ringTimer );
break;
case AT_RPS_CONNECT:
SetWindowText( stState, "Connect", NULL );
break;
case AT_RPS_BUSY:
SetWindowText( stState, "Busy", NULL );
break;
case AT_RPS_NO_CARRIER:
SetWindowText( stState, "No carrier", NULL );
break;
case AT_RPS_ERROR:
SetWindowText( stState, "Error", NULL );
break;
case AT_RPS_CMTI:
uartmsg.message = SM_SWITCH;
uartmsg.lparam = SWAP_TASK_LATER;
uartmsg.wparam = PSA_TASK_ID;
uartmsg.data = NULL;
SysSendMessage( SYSTASK_ID, &uartmsg );
{
AT_RPS_PAR *par = (AT_RPS_PAR *)msg.data;
SUBPAR *subpar = par->head;
char info[15] = "New sms ";
// get sms index
subpar = subpar->next;
strcat( info, subpar->data );
SetWindowText( stState, info, NULL );
READ_SMS( subpar->data );
FreeParameter( msg.data );
}
break;
case AT_RPS_CLIP:
uartmsg.message = SM_SWITCH;
uartmsg.lparam = SWAP_TASK_LATER;
uartmsg.wparam = PSA_TASK_ID;
uartmsg.data = NULL;
SysSendMessage( SYSTASK_ID, &uartmsg );
{
AT_RPS_PAR *par = (AT_RPS_PAR *)msg.data;
SUBPAR *subpar = par->head;
char info[25];
dataLen = (U8)strlen( subpar->data );
memcpy( info, &subpar->data[2], dataLen -3 );
info[dataLen-3] = '\0';
SetWindowText( stState, info, NULL );
FreeParameter( msg.data );
ReceiveCallDlg( info );
}
break;
case AT_RPS_CMGF:
{
char newMode;
newMode = ((AT_RPS_PAR *)msg.data)->head->data[1];
switch( newMode )
{
case '0':
SetWindowText( stSMSFormat, "PDU Format", NULL );
curSMSFormat = 0;
break;
case '1':
SetWindowText( stSMSFormat, "Text Format", NULL );
curSMSFormat = 1;
break;
default:
SetWindowText( stSMSFormat, "Unknown Format", NULL );
break;
}
FreeParameter( msg.data );
}
break;
case AT_RPS_CMGR:
{
AT_RPS_PAR *par = (AT_RPS_PAR *)msg.data;
SUBPAR *subpar = par->head;
int i = 0, line = 0;
SMS_DELIVER_PDU_CONTENT *pdu;
if( curSMSFormat == 0 ) // PDU format
{
int k = 0;
// get user data
while( subpar->next != NULL && k < 3 )
{
subpar = subpar->next;
k++;
}
pdu = TranslateSDPC( subpar->data );
if( pdu != NULL )
SetWindowText( edSMS, pdu->ud, NULL );
FreeSDPC( pdu );
}
FreeParameter( msg.data );
}
break;
case AT_RPS_READY:
SEND_SMS_DATA();
break;
default:
break;
}
break;
case WM_TIMER:
SetWindowText( stState, "No carrier", NULL );
CreateTimer( &ringTimer, 10000, NULL, NULL, ALARM_MODE|AUTO_CLEAR_MODE );
break;
case WM_QUIT:
uartmsg.message = SM_SWITCH;
uartmsg.lparam = SWAP_TASK_LATER;
uartmsg.wparam = 0;
uartmsg.data = NULL;
SysSendMessage( SYSTASK_ID, &uartmsg );
// quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
*/
//ERROR_HANDLE:
EndofTask();
}
U8 ReceiveCallDlg( char *number )
{
MSG msg;
U32 mainwin;
U32 stState;
U32 btHangUp, btPickUp;
// U32 hGC;
U8 quit = 0;
U8 result;
U32 ringTimer;
// WINDOW ARRANGEMENT
const U16 formW = PHY_LCD_W, formH = PHY_LCD_H/3, formX = 0, formY = ( PHY_LCD_H - formH )/2;
const U16 stW = formW - 8, stH = 20, stX = formX + 4, stY = formY + 22;
const U16 btW = 32, btH = 20, btGap = ( formW - btW * 2 )/3;
const U16 btPickUpX = formX + formW - btW - btGap, btPickUpY = formY + formH - 24;
const U16 btHangUpX = formX + btGap, btHangUpY = formY + formH - 24;
mainwin = CreateWindow( WNDCLASS_WIN,
"来电显示",
WS_OVERLAPPEDWINDOW,
formX,formY,
formW,formH,
0,
0,
NULL);
btHangUp = CreateWindow( WNDCLASS_BUTTON,
"挂断",
WS_CHILD | BS_REGULAR,
btHangUpX,btHangUpY,
btW,btH,
mainwin,
0,
NULL);
btPickUp = CreateWindow( WNDCLASS_BUTTON,
"接听",
WS_CHILD | BS_REGULAR,
btPickUpX,btPickUpY,
btW,btH,
mainwin,
0,
NULL);
stState = CreateWindow( WNDCLASS_STATIC,
number,
WS_CHILD|SS_TEXT,
stX,stY,
stW,stH,
mainwin,
0,
NULL);
CreateTimer( &ringTimer, 10000, NULL, NULL, ALARM_MODE|AUTO_CLEAR_MODE );
StartTimer( ringTimer );
while( !quit )
{
ASIXGetMessage( &msg, NULL, 0, 0 );
switch( msg.message )
{
case WM_COMMAND:
if( msg.lparam == btHangUp )
{
HANG_UP( );
result = IDCANCEL;
}
else if( msg.lparam == btPickUp )
{
PICK_UP( );
result = IDOK;
}
quit = 1;
break;
case WM_AT:
switch( msg.lparam )
{
case AT_RPS_RING:
StartTimer( ringTimer );
break;
case AT_RPS_NO_CARRIER:
SetWindowText( stState, "No carrier", NULL );
quit = 1;
result = ST_INACTIVE_HANG_UP;
break;
case AT_RPS_ERROR:
SetWindowText( stState, "Error", NULL );
result = ST_COMMAND_ERROR;
quit = 1;
break;
case AT_RPS_CMTI:
FreeParameter( msg.data );
break;
default:
FreeParameter( msg.data );
break;
}
break;
case WM_TIMER:
SetWindowText( stState, "No carrier", NULL );
quit = 1;
result = ST_INACTIVE_HANG_UP;
break;
case WM_QUIT:
HANG_UP( );
quit = 1;
result = IDCANCEL;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
FreeTimer( ringTimer );
DestroyWindow( mainwin );
return result;
}
U8 ReceiveSMSDlg( void )
{
MSG msg;
U32 mainwin;
U32 stState;
U32 btRead, btNeglect;
// U32 hGC;
U8 quit = 0;
U8 result;
// WINDOW ARRANGEMENT
const U16 formW = PHY_LCD_W, formH = PHY_LCD_H/3, formX = 0, formY = ( PHY_LCD_H - formH )/2;
const U16 stW = formW - 8, stH = 20, stX = formX + 4, stY = formY + 22;
const U16 btW = 32, btH = 20, btGap = ( formW - btW * 2 )/3;
const U16 btReadX = formX + formW - btW - btGap, btReadY = formY + formH - 24;
const U16 btNeglectX = formX + btGap, btNeglectY = formY + formH - 24;
mainwin = CreateWindow( WNDCLASS_WIN,
"短消息",
WS_OVERLAPPEDWINDOW,
formX,formY,
formW,formH,
0,
0,
NULL);
btRead = CreateWindow( WNDCLASS_BUTTON,
"忽略",
WS_CHILD | BS_REGULAR,
btReadX,btReadY,
btW,btH,
mainwin,
0,
NULL);
btNeglect = CreateWindow( WNDCLASS_BUTTON,
"阅读",
WS_CHILD | BS_REGULAR,
btNeglectX,btNeglectY,
btW,btH,
mainwin,
0,
NULL);
stState = CreateWindow( WNDCLASS_STATIC,
"新到短消息,是否阅读?",
WS_CHILD|SS_TEXT,
stX,stY,
stW,stH,
mainwin,
0,
NULL);
while( !quit )
{
ASIXGetMessage( &msg, NULL, 0, 0 );
switch( msg.message )
{
case WM_COMMAND:
if( msg.lparam == btRead )
{
result = IDOK;
}
else if( msg.lparam == btNeglect )
{
PICK_UP( );
result = IDCANCEL;
}
quit = 1;
break;
case WM_AT:
switch( msg.lparam )
{
case AT_RPS_RING:
quit = 1;
result = ST_RINGING;
break;
case AT_RPS_ERROR:
SetWindowText( stState, "Error", NULL );
quit = 1;
result = ST_COMMAND_ERROR;
break;
case AT_RPS_CMTI:
FreeParameter( msg.data );
break;
default:
FreeParameter( msg.data );
break;
}
break;
case WM_QUIT:
quit = 1;
result = IDCANCEL;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow( mainwin );
return result;
}
U8 VoiceCall( )
{
MSG msg, uartmsg;
U32 mainwin;
U32 stState;
U32 btCall, btHangUp, btDel, btSMS;
U32 dialPanel;
U32 editor;
U32 ringTimer;
// U32 hGC;
U8 quit = 0;
U8 dataLen;
U8 state;
// WINDOW ARRANGEMENT
const U16 formW = PHY_LCD_W, formH = PHY_LCD_H, formX = 0, formY = 0;
const U16 stW = formW - 8, stH = 20, stX = formX + 4, stY = formY + 22;
const U16 edW = formW - 8, edH = 20, edX = formX + 4, edY = formY + 42;
const U16 btW = 32, btH = 20, btGap = ( formW - btW * 4 )/5;
const U16 btCallX = formX + formW - btW - btGap, btCallY = formY + formH - 24;
const U16 btHangUpX = formX + btGap, btHangUpY = btCallY;
const U16 btDelX = btHangUpX + btW + btGap, btDelY = btCallY;
const U16 btSMSX = btDelX + btW + btGap, btSMSY = btCallY;
mainwin = CreateWindow( WNDCLASS_WIN,
"电话",
WS_OVERLAPPEDWINDOW,
formX,formY,
formW,formH,
0,
0,
NULL);
btCall = CreateWindow( WNDCLASS_BUTTON,
"拨号",
WS_CHILD | BS_REGULAR,
btCallX,btCallY,
btW,btH,
mainwin,
0,
NULL);
btDel = CreateWindow( WNDCLASS_BUTTON,
"删除",
WS_CHILD | BS_REGULAR,
btDelX,btDelY,
btW,btH,
mainwin,
0,
NULL);
btSMS = CreateWindow( WNDCLASS_BUTTON,
"短信",
WS_CHILD | BS_REGULAR,
btSMSX,btSMSY,
btW,btH,
mainwin,
0,
NULL);
btHangUp = CreateWindow( WNDCLASS_BUTTON,
"挂断",
WS_CHILD | BS_REGULAR,
btHangUpX,btHangUpY,
btW,btH,
mainwin,
0,
NULL);
stState = CreateWindow( WNDCLASS_STATIC,
NULL,
WS_CHILD|SS_TEXT,
stX,stY,
stW,stH,
mainwin,
0,
NULL);
editor = CreateWindow( WNDCLASS_EDITOR,
NULL,
WS_CHILD | ES_SINGLELINE | ES_RIGHT,
edX,edY,
edW,edH,
mainwin,
0,
NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -