#include<stdio.h>
#include<string.h>
#include<time.h>
#include<minigui/common.h>
#include<minigui/minigui.h>
#include<minigui/gdi.h>
#include<minigui/window.h>
#include<minigui/control.h>
#include<minigui/dti.c>
#include<string.h>
#include <unistd.h>/*Unix 标准函数定义*/
#include <fcntl.h>/*文件控制定义*/
#include <sys/signal.h>/*信号定义*/
#include <termios.h>
#include <stdlib.h>
#include <pthread.h>
#define BAUDRATE B115200 /*波特率预定义*/
#define COM1 "/dev/ttyS0" /*预定义串口1*/
#define IDC_TEXTBOX 0x3000
#define IDC_BTN_ADD 0X4001
#define IDC_BTN_DEL 0X4002
#define IDC_NUM1 100
#define IDC_NUM2 101
#define IDC_NUM3 102
#define IDC_NUM4 103
#define IDC_NUM5 104
#define IDC_NUM6 105
#define IDC_NUM7 106
#define IDC_NUM8 107
#define IDC_NUM9 108
#define IDC_NUM10 109
#define IDC_NUM11 110
#define IDC_NUM12 111
#define FALSE 0
#define TRUE 1
#define MSG_CALL (MSG_USER + 1)
#define MSG_RING (MSG_USER + 2)
volatile int flg=FALSE;
volatile int flg1=TRUE;
struct termios oldtio,newtio;
volatile int fd;
HWND hMainWnd;
tty_writecmd(char *buf,int nbytes)
{
int i;
for(i=0;i<nbytes;i++)
{
write(fd,&buf[i],1);
usleep(100);
}
write(fd,"\r",1);
usleep(300000);
return tcdrain(fd);
}
//读gprs串口数据
int tty_read(char *buf,int nbytes)
{
return read(fd,buf,nbytes);
}
//gprs初始化
void gprs_init()
{
//测试GPRS模块状态
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"));
//启动来电显示
tty_writecmd("at+clip=1", strlen("at+clip=1"));
}
//拨打电话
void gprs_call(char *number, int num)
{
//发送拨打命令ATD
tty_writecmd("atd", strlen("atd"));
//发送电话号码
tty_writecmd(number, num);
//发送分号和命令结束标志
tty_writecmd(";\r", strlen(";\r"));
usleep(200000);
}
//实现接听电话gprs_ans()函数
void gprs_ans()
{
//发送接听命令ATA
tty_writecmd("ata", strlen("ata"));
}
//实现挂断电话gprs_hold()函数
void gprs_hold()
{
//发送挂机命令ATH
tty_writecmd("ath", strlen("ath"));
}
void * gprs_ring_num(void *);
static CTRLDATA ctrls[] = {
{
"edit",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
80 , 30, 180, 30,
IDC_TEXTBOX,
NULL,
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
100 , 80, 50, 25,
IDC_BTN_ADD,
"ok",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
180 , 80, 50, 25,
IDC_BTN_DEL,
"cansel",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
80 , 125, 25, 25,
IDC_NUM1,
"1",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
125 , 125, 25, 25,
IDC_NUM2,
"2",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
170 , 125, 25, 25,
IDC_NUM3,
"3",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
215 , 125, 25, 25,
IDC_NUM4,
"4",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
80 , 165, 25, 25,
IDC_NUM5,
"5",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
125 , 165, 25, 25,
IDC_NUM6,
"6",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
170 , 165, 25, 25,
IDC_NUM7,
"7",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
215 , 165, 25, 25,
IDC_NUM8,
"8",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
80 , 205, 25, 25,
IDC_NUM9,
"9",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
125 , 205, 25, 25,
IDC_NUM10,
"0",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
170 , 205, 25, 25,
IDC_NUM11,
"*",
0
},
{
"button",
WS_TABSTOP | WS_VISIBLE | WS_CHILD,
215 , 205, 25, 25,
IDC_NUM12,
"#",
0
},
};
static DLGTEMPLATE Modal = {
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
40, 20, 400, 420,
"ListBox Demo",
0,
0,
sizeof(ctrls)/sizeof(CTRLDATA),
NULL,
0
};
static int DialogProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
// HWND hWndListBox;
static char buf[100]="";
static char temp[100];
int i,len;
switch(message){
case MSG_INITDIALOG:
break;
case MSG_COMMAND:
{
switch(wParam)
{
case IDC_NUM1:
strcat(buf,"1");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM2:
strcat(buf,"2");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM3:
strcat(buf,"3");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM4:
strcat(buf,"4");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM5:
strcat(buf,"5");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM6:
strcat(buf,"6");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM7:
strcat(buf,"7");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM8:
strcat(buf,"8");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM9:
strcat(buf,"9");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM10:
strcat(buf,"0");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM11:
strcat(buf,"*");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_NUM12:
strcat(buf,"#");
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
break;
case IDC_BTN_DEL:
if(flg==TRUE)
{
gprs_hold();
flg=FALSE;
}
else
{
GetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf,strlen(buf));
len=strlen(buf);
buf[len - 1] = '\0';
SetWindowText(GetDlgItem(hWnd,IDC_TEXTBOX),buf);
}
break;
case IDC_BTN_ADD:
if(flg==FALSE&&flg1==FALSE)
{
gprs_ans();
flg=TRUE;
flg1=TRUE;
}
else if(flg==FALSE)
{
gprs_call(buf,strlen(buf));
flg=TRUE;
SendMessage(hMainWnd,MSG_CALL,0,0);
}
break;
}
}
break;
case MSG_CALL:
MessageBox(hWnd,"你拨打电话啦!","消息",MB_OK);
break;
case MSG_RING:
MessageBox(hWnd,"你来电话啦!","消息",MB_OK);
break;
case MSG_PAINT:
break;
case MSG_CLOSE:
tcsetattr(fd,TCSANOW,&oldtio); /* 恢复旧的设置 */
close(fd);
EndDialog(hWnd,wParam);
break;
}
return DefaultDialogProc(hWnd,message,wParam,lParam);
}
int MiniGUIMain(int argc,const char * argv[])
{
pthread_t thrd1;
int ret;
char temp[20] = {0};
fd = open(COM1, O_RDWR ); //读写方式打开串口1;
if (fd <0)//失败处理
{
perror(COM1);
exit(-1);
}
tcgetattr(fd,&oldtio); /* 存储串口设置 */
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;/*控制模式标志.设定bps的速度;硬体流量控制;8位,无校验位,1个终止位;本地连线,只能接收字元*/
newtio.c_iflag = IGNPAR; /*输入模式标志,IGNPAR忽略奇偶校验位 */
newtio.c_oflag = 0; /*输出模式标志.0 Raw模式输出 */
newtio.c_lflag = 0;/*0非标准型输入,不回应*/
newtio.c_cc[VMIN]= 1;/*在读取到1个字元前先停止*/
newtio.c_cc[VTIME]=0;/*不使用分割字元组的计时器*/
tcflush(fd, TCIFLUSH);/*清除串口缓冲�