⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsalm.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
字号:
/*************************************************************************
 *
 *  Copyright (C) Asic Center. 2002
 *  All Rights Reserved
 *
 *  Filename : SMS_ALARM.c
 *  Function : 完成短信的提醒工作
 *  Revision :
 *          2002/9/20  magod      Create this file
 *
 ************************************************************************/
#include <stdio.h>
#include <string.h> 

#include "asixwin.h"
#include "asixapp.h"

#include "bitmap.h"
#include "picture.h"

#include "lmalloc.h"
#include "at.h"	
#include "at_rps.h"
#include "at_pdu.h"

#include "psat.h"

#include "carddb.h"	
#include "SMShdb.h"

#include "sms.h"

void SMS_ALARM_BOX( char *inforstr, char *caption );

extern void SMS_Alarm( void );
extern TASKDESCRIPTION SMSTskDesp;

//**********************SERVICE TASK DESCRIPTION*********************
DWORD	SmsAlmStk[STACK_SIZE];

TASKDESCRIPTION SMSAlarmTskDesp = 
{"短信提醒",	ASIX_SERVICE,	NOT_IN_ANYGROUP,	NULL,	STACK_SIZE,	1,	PHY_LCD_W,	PHY_LCD_H,	SMS_Alarm,	SERVICE_PRI};

TASKDESCRIPTIONLIST	SMSAlarmTskDespLst =
{NULL,	NULL,	&SMSAlarmTskDesp, SMSALMSERVER_ID, SmsAlmStk};
//**********************END SERVICE TASK DESCRIPTION****************


/********************************************************************
*   Function SMS_Alarm()  
*	param in:	void		
*	param out: 	void	
*	description: 完成约会的提醒工作
********************************************************************/
void SMS_Alarm(void)
{
	MSG					msg,switchmsg;
	U8					quit = 0;
	U8					*oa;								//发送者的手机号码
	U8					*ud;								//发送的数据
	TIME_STAMP			time;								//短信中心的时间
	U8					time_str[15] = "20020901101000";	//用于存放时间串
	U8					*caption="******************";		//消息框的标题
	U8					curSMSFormat;						//短信内容的格式

	LOCALSEARCHLIST		*searchlist;
	DBLACB				*card_lacb;
	BYTE				*card_data;
	U16					offset;
	SMS					sms;								//			
	char				smsid[5];
	
//	CreateDataBase();										//创建数据库文件
	card_lacb = LinkDataBase( CARD_DATA_BASE );				//链接名片数据库

	WaitUnsolicitedResponse( AT_RPS_CMTI );

	while(!quit)
	{
 		ASIXGetMessage(&msg, NULL, 0, 0);

		switch(msg.message)
		{
			case WM_AT:
			{
				switch( msg.lparam )
				{
					case AT_RPS_ERROR:
						break;
					case AT_RPS_CMTI:
						{
							AT_RPS_PAR	*par = (AT_RPS_PAR *)msg.data;
							SUBPAR		*subpar = par->head;
						
							// get sms index
							subpar = subpar->next;
							strcpy( smsid, subpar->data );

							READ_SMS( smsid );
							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;
						
							curSMSFormat = 0;		//短信的格式为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 )
								{
									oa = pdu->oa;		//get the phone number
									ud = pdu->ud;		//get the SMS content	
									time = pdu->time;	//get the TIME;
								}

								//将短信消息存入未读短信记录								
								strcpy(sms.number, oa+2);	// skip "86"
								strcpy(sms.content, ud);
								sprintf( time_str, "20%02u%02u%u%02u%02u%02u",time.year, time.month, time.day, time.hour, time.min, time.sec );
								Add2SMSHistory(&sms, SMS_UNREAD, time_str); 
								DELETE_SMS( smsid );

								//向声音设备管理的服务任务发出发音的消息

								//根据电话号码查询人名				
								searchlist = LocalFindRecord(card_lacb, CARD_MOBILE_FIELD, oa, PRECISE_FULL_MATCH ); 
								if( searchlist->num == 0 )
								{
									caption = oa;
								}
								else
								{
									card_data = searchlist->head[0].data+12;
									offset = *( (U16 *)card_data );
									caption = card_data + offset;	
								}
							
								//弹出消息框	
								strcat(caption,"的短消息!");
								SMS_ALARM_BOX( "您要查看吗?", caption );
							
								switchmsg.messageType = ASIX_MESSAGE;
								switchmsg.message = SM_SWITCH;
								switchmsg.lparam = SMSALMSERVER_ID;
								switchmsg.wparam = SWAP_TO_BACKGROUND;
								SysSendMessage( SYSTASK_ID, &switchmsg );

								FreeSDPC( pdu );
							}
							FreeParameter( msg.data );
						}
						break;
					default:
						break;
				}//end 	switch( msg.lparam )
				break;
			}//end case AT
			default:
				break;
		}//end switch(msg.message)
			
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam); 

	}// end while

}

/********************************************************************
*   Function SMS_ALARM_BOX()  
*	param in:	char *inforstr, char *caption		
*	param out: 	void	
*	description: 短信提醒消息框
********************************************************************/
void SMS_ALARM_BOX( char *inforstr, char *caption )
{
	U32	mainwin; 
	U32	infor; 
	U32	read, cancel; 
	U8	quit = 0;
	MSG	msg;
	MSG read_sms;
	
//	U32	hgc; 
//	U32	hbmp; 
	
	mainwin = CreateWindow(WNDCLASS_WIN, caption, WS_CAPTION|WS_CLOSEBOX|WS_POPUP, 0, 70, 159, 100, 0, 0, NULL); 
	infor = CreateWindow(WNDCLASS_STATIC, inforstr, WS_CHILD|SS_TEXT, 30, 95, 125, 40, mainwin, 0, NULL); 
	read = CreateWindow(WNDCLASS_BUTTON, "阅读", WS_CHILD|BS_BOARD_REGULAR, 30, 140, 40, 20, mainwin, 0, NULL); 
	cancel = CreateWindow(WNDCLASS_BUTTON, "取消", WS_CHILD|BS_BOARD_REGULAR, 90, 140, 40, 20, mainwin, 0, NULL); 
	
//	hgc = GetGC(); 
	
//	hbmp = LoadBitmap(question_icon);	
//	DisplayBMP(hgc,5,95,hbmp); 
//	FreeBitmap(hbmp); 
	
	PopUpWindow( mainwin, 0 );

	while(!quit)
	{
		ASIXGetMessage(&msg,NULL,0,0);

		switch (msg.message )
		{
			case WM_COMMAND:
				if(msg.lparam == read)	//若点击阅读,则发"阅读短信"的消息给短信任务
				{				
					DWORD	id;
					id = CreateDynamicTask( &SMSTskDesp, RUN_AS_EXISTED_TASK );
					read_sms.messageType = ASIX_MESSAGE;
					read_sms.message = WM_ALARM;
					read_sms.lparam	= 0;
					read_sms.wparam	= ALARM_SMS;			
					read_sms.data = NULL;
					SysSendMessage( id, &read_sms);
					quit =1;
				}	
				else if (msg.lparam == cancel )
				{
					//发消息给主界面
					quit = 1;
				}
				break;
			case WM_QUIT:
				//发消息给主界面
				quit = 1;
				break;	
			case WM_AT:					//若有新的短信到,将新的短信息发给短信提醒任务
				//发消息给主界面
				if( msg.lparam == AT_RPS_CMTI )
				{
					SysSendMessage(SMSALMSERVER_ID, &msg);
					quit = 1;
				}
				break;
			default:
				break;
		}
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
	}

	DestroyWindow(mainwin);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -