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

📄 apptalm.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
								conversion_time.month+=1;
						}else
							conversion_time.day+=7;
					}
					break;

				case	BY_DAY:
					if( ( conversion_time.month == 2 ) && ( IsRenNian() == TRUE ) )
					{
						if( conversion_time.day == day_num[conversion_time.month] + 1 )
						{
							conversion_time.day = 1;
							conversion_time.month += 1;
						}else
							conversion_time.day += 1;
					}else{
						if( conversion_time.day == day_num[conversion_time.month] )
						{
							conversion_time.day = 1;
							if( conversion_time.month == 12 )
							{
								conversion_time.month = 1;
								conversion_time.year += 1;
							}else
								conversion_time.month += 1;
						}else
							conversion_time.day += 1;
					}
					break;

				case	BY_HOUR:
					if( ( conversion_time.month == 2 ) && ( IsRenNian() == TRUE ) )	//闰年2月
					{
						if( ( conversion_time.hour == 23 ) && ( conversion_time.minute != 0 ) )	//23~24点之间
						{
							if( conversion_time.day == day_num[conversion_time.month] + 1 )	//闰年2月29日
							{
								conversion_time.month += 1;		//换月,3月
								conversion_time.day = 1;		//换月,1号
							}else{	//2月1~28日
								conversion_time.day += 1;		//2月中的某天加1
							}
							conversion_time.hour = 0;			//0点
						}else{		//0~23点之间
							conversion_time.hour += 1;			//某天中的时加1
							flag = 1;	//表示为同一天
						}
					}else{	//1、3~12月及平年2月
						if( ( conversion_time.hour == 23 ) && ( conversion_time.minute != 0 ) )	//23~24点之间
						{
							if( conversion_time.day == day_num[conversion_time.month] )	//每月最后一天
							{
								if( conversion_time.month == 12 )	//年底12月
								{
									conversion_time.year += 1;		//换年
									conversion_time.month = 1;		//换月,1月
								}else{		//1~11月
									conversion_time.month += 1;		//换月,月加1
								}
								conversion_time.day = 1;			//换月,1号
							}else{	//每月除最后一天
								conversion_time.day += 1;			//换天,天加1
							}
							conversion_time.hour = 0;				//0点
						}else{	//0~23点之间
							conversion_time.hour += 1;				//时加1
							flag = 1;	//表示为同一天
						}
					}
					break;
				default:break;
			}
			TimetoChar( &conversion_time, (TIME_STRU *)scheme_stru->time);
			ModifySchemeRecord( lacb, pt_timer->scheme_index, scheme_stru, 0 );	//提醒次数不为0, 把提醒的记录变为未到期的提醒保存
			AddTimer( pt_timer->scheme_index, 0 );
		}
		APPOINT_ALARM_BOX( scheme_stru->name, scheme_stru->content );		//弹出警告框ttttttt
	}

	DetachDataBase( lacb );
}

/***********************************************************************************************/
//增加一个定时器
void AddTimer( U32 scheme_index, U8 reserved )
{
	DBLACB				*lacb;						//约会提醒数据库的局部访问控制块
	SCHEME_STRU			*scheme_stru;
	ASIX_DATE			date;
	ASIX_TIME			time;
	TIME_STRU			cur_time, conversion_time; 
	char				cur_time_str[15] = {0};
	U32					count_time;
	U32					timer;
	TIMER_LIST_STRU		*pt_timer;

	lacb =  LinkDataBase( SCHEME_DATA_BASE );		//链接约会提醒数据库

	scheme_stru = ReadSchemeRecord( lacb, scheme_index, 0 );

	//得到当天的时间串
	ReadDateTime( &date, &time );
	cur_time.year = (U32)date.year;
	cur_time.month = date.month;
	cur_time.day = date.day;
	cur_time.hour = time.hour;
	cur_time.minute = time.minute;
	cur_time.second = time.second;
	TimetoInt( (TIME_STRU *)scheme_stru->time, &conversion_time );

	if( ( conversion_time.year == cur_time.year ) && ( conversion_time.month == cur_time.month ) && ( conversion_time.day == cur_time.day ) )	//当天
	{
		TimetoChar( &cur_time, &conversion_time );	//把当前时刻转换为字符串
		memcpy( cur_time_str, &conversion_time, 14 );
//		cur_time_str[14] = '\0';
		if( strcmp( scheme_stru->time, cur_time_str ) > 0 )		//当前时刻早于需要定时的时刻
		{
			if( ( *(scheme_stru->alarm_type) != DO_NOT_ALARM ) && ( *(scheme_stru->type) != SCHEME_MATURITY ) )	//记录未到期且需要提醒,则创建定时器
			{
				if( ( pt_timer=(TIMER_LIST_STRU*)Lcalloc( sizeof(TIMER_LIST_STRU)) ) == NULL )
					return;

				pt_timer->scheme_index = scheme_index;		//存入约会的索引号

				//算出定时器的定时值
				count_time = CountTime( (TIME_STRU *)scheme_stru->time );

//				CreateTimer( &timer, count_time, (void (*)())AlarmTimerProc, pt_timer, ALARM_MODE|AUTO_CLEAR_MODE );
				CreateTimer( &timer, count_time, NULL, NULL, ALARM_MODE|AUTO_CLEAR_MODE );
				pt_timer->timer_id = timer;					//创建定时器,并存入定时器的id号

				if( TIMER_LIST != NULL )
					pt_timer->next = TIMER_LIST;
				else
					pt_timer->next=NULL;
				TIMER_LIST = pt_timer;

				StartTimer( timer );						//启动定时器
			}
		}

	}

	DetachDataBase( lacb );

}

/***********************************************************************************************/
//删除一个定时器
void DelTimer( U32 scheme_index, U8 reserved )
{
	TIMER_LIST_STRU		*pt_timer, *pre_timer;
	DBLACB				*lacb;
	SCHEME_STRU			*scheme_stru;
	ASIX_DATE			date;
	ASIX_TIME			time;
	TIME_STRU			cur_time, conversion_time; 
	char				cur_time_str[15] = {0};
//	U32					count_time;

	lacb =  LinkDataBase( SCHEME_DATA_BASE );		//链接约会提醒数据库

	scheme_stru = ReadSchemeRecord( lacb, scheme_index, 0 );

	//得到当天的时间串
	ReadDateTime( &date, &time );
	cur_time.year = (U32)date.year;
	cur_time.month = date.month;
	cur_time.day = date.day;
	cur_time.hour = time.hour;
	cur_time.minute = time.minute;
	cur_time.second = time.second;
	TimetoInt( (TIME_STRU *)scheme_stru->time, &conversion_time );

	if( ( conversion_time.year == cur_time.year ) && ( conversion_time.month == cur_time.month ) && ( conversion_time.day == cur_time.day ) )	//当天
	{
		TimetoChar( &cur_time, &conversion_time );	//把当前时刻转换为字符串
		memcpy( cur_time_str, &conversion_time, 14 );
		if( strcmp( scheme_stru->time, cur_time_str ) > 0 )		//当前时刻早于需要定时的时刻
		{
			if( ( *(scheme_stru->alarm_type) != DO_NOT_ALARM ) && ( *(scheme_stru->type) != SCHEME_MATURITY ) )	//记录未到期且需要提醒,则创建定时器
			{
				pre_timer = pt_timer = TIMER_LIST;
				while( pt_timer != NULL )
				{
					if( pt_timer->scheme_index == scheme_index )
						break;
					else
					{
						pre_timer = pt_timer;
						pt_timer = pt_timer->next;
					}
				}

				if( pt_timer != NULL )
				{
					if( pt_timer->next != NULL )
					{
						pre_timer->next = pt_timer->next;
						FreeTimer( pt_timer->timer_id );
						Lfree( pt_timer );
						pt_timer = pre_timer->next;
					}
					else
					{
						pre_timer->next = NULL;
						FreeTimer( pt_timer->timer_id );
						Lfree( pt_timer );
						pt_timer = NULL;
					}
				}
			}
		}
	}
				
	DetachDataBase( lacb );
}

/***********************************************************************************************/
//读取当天的提醒列表
LOCALSEARCHLIST*  GetCurSchemeList( DBLACB	*lacb )
{
	ASIX_DATE			date;
	TIME_STRU			time, conversion_time;
	static char			keystring[KEYSTRING_LEN] = {0}, type[2] = {0};
	LOCALSEARCHLIST		*searchlist;

	//读取当天的提醒列表:
	GetDate( &date );
	time.year = (U32)date.year;
	time.month = date.month;
	time.day = date.day;
	time.hour = time.minute = time.second = 0;
	TimetoChar( &time, &conversion_time );

	//获得关键字
	memcpy( keystring, SCHEME_DAY_RANGE, 2 );
	strcat( keystring, (char *)(&conversion_time) );	
	keystring[15] = '\0';
	type[0] = SCHEME_NO_MATURITY ;	//当天未到期的提醒
	searchlist = SchemeDBFindRecord( lacb, SCHEME_TIME, keystring, PRECISE_FULL_MATCH );//读出当天的提醒记录

	return searchlist;
}

/***********************************************************************************************/
SCHEME_STRU* ReadSchemeRecord(  DBLACB *lacb, U32 index, U8 reserved)
{
	SCHEME_STRU		*scheme_stru;
	BYTE			*record;
	DBRECORDHEAD	*head_info;
	U8				*data;
	U16				*field_head;
	
	if( ( scheme_stru = (SCHEME_STRU *)Lcalloc(sizeof(SCHEME_STRU)) ) == NULL )
		return	NULL;

	record = LocalReadRecord( lacb, index );
	head_info = (DBRECORDHEAD *)record;
	data = (BYTE *)(&head_info->data);
	field_head = (WORD *)data;
	scheme_stru->time =  data + field_head[SCHEME_TIME];
	scheme_stru->name = data + field_head[SCHEME_NAME];
	scheme_stru->alarm_type = data + field_head[SCHEME_ALARM_TYPE];
	scheme_stru->type = data + field_head[SCHEME_TYPE];
	scheme_stru->alarm_mode = data + field_head[SCHEME_ALARM_MODE];
	scheme_stru->content = data + field_head[SCHEME_CONTENT];
	scheme_stru->alarm_repeat_num = data + field_head[SCHEME_REPEAT_NUM];

	return	scheme_stru;
}

/***********************************************************************************************/
STATUS CreateSchemeRcord( DBLACB *lacb, SCHEME_STRU *scheme_stru, U8 reversed )
{
	U8			i;
	U8			*add_data, *data;
	FIELDLIST	fieldlist[SCHEME_FIELD_NUM];
	U16			datalen;
	U32			tmp_id;

	fieldlist[0].fieldvalue = scheme_stru->time;
	fieldlist[1].fieldvalue = scheme_stru->name;
	fieldlist[2].fieldvalue = scheme_stru->alarm_type;
	fieldlist[3].fieldvalue = scheme_stru->type;
	fieldlist[4].fieldvalue = scheme_stru->alarm_mode;
	fieldlist[5].fieldvalue = scheme_stru->content;
	fieldlist[6].fieldvalue = scheme_stru->alarm_repeat_num;
	datalen = (WORD)( SCHEME_FIELD_NUM * sizeof(WORD) );
	for( i = 0; i < SCHEME_FIELD_NUM; i++ )
	{
		if( fieldlist[i].fieldvalue == NULL )
		{
			fieldlist[i].headoffset = 0;
		}else{
			fieldlist[i].headoffset = datalen;
			datalen += (U16)( strlen( fieldlist[i].fieldvalue ) + 1 );
		}
	}
	
	add_data = (BYTE *)SysLmalloc(datalen);
	if( add_data == NULL )
		return SCHEME_ERROR;
	data = add_data;

	for( i = 0; i < SCHEME_FIELD_NUM; i++ )	//填充偏移值
	{
		memcpy( data, &fieldlist[i].headoffset, sizeof(WORD) );
		data += sizeof(WORD);
	}

	for( i = 0; i < SCHEME_FIELD_NUM; i++ )	//填充字段值
	{
		if( fieldlist[i].headoffset != 0 )
		{
			memcpy( data, fieldlist[i].fieldvalue , ( strlen( fieldlist[i].fieldvalue ) + 1 ) );
			data += ( strlen( fieldlist[i].fieldvalue ) + 1 );
		}
	}

	tmp_id = LocalAddRecord( lacb, add_data, datalen );
	if( tmp_id == DB_ERROR )
		return SCHEME_ERROR;

	return	SCHEME_OK;
}

/***********************************************************************************************/
STATUS ModifySchemeRecord( DBLACB *lacb, U32 index, SCHEME_STRU *scheme_stru, U8 reserved )
{
	U8			i;
	U8			*modify_data, *data;
	FIELDLIST	fieldlist[SCHEME_FIELD_NUM];
	U16			datalen;

	fieldlist[0].fieldvalue = scheme_stru->time;
	fieldlist[1].fieldvalue = scheme_stru->name;
	fieldlist[2].fieldvalue = scheme_stru->alarm_type;
	fieldlist[3].fieldvalue = scheme_stru->type;
	fieldlist[4].fieldvalue = scheme_stru->alarm_mode;
	fieldlist[5].fieldvalue = scheme_stru->content;
	fieldlist[6].fieldvalue = scheme_stru->alarm_repeat_num;
	datalen = (WORD)( SCHEME_FIELD_NUM * sizeof(WORD) );
	for( i = 0; i < SCHEME_FIELD_NUM; i++ )
	{
		if( fieldlist[i].fieldvalue == NULL )
		{
			fieldlist[i].headoffset = 0;
		}else{
			fieldlist[i].headoffset = datalen;
			datalen += (U16)( strlen( fieldlist[i].fieldvalue ) + 1 );
		}
	}
	
	modify_data = (BYTE *)SysLmalloc(datalen);
	if( modify_data == NULL )
		return SCHEME_ERROR;
	data = modify_data;

	for( i = 0; i < SCHEME_FIELD_NUM; i++ )	//填充偏移值
	{
		memcpy( data, &fieldlist[i].headoffset, sizeof(WORD) );
		data += sizeof(WORD);
	}

	for( i = 0; i < SCHEME_FIELD_NUM; i++ )	//填充字段值
	{
		if( fieldlist[i].headoffset != 0 )
		{
			memcpy( data, fieldlist[i].fieldvalue , ( strlen( fieldlist[i].fieldvalue ) + 1 ) );
			data += ( strlen( fieldlist[i].fieldvalue ) + 1 );
		}
	}
	
	if( LocalModifyRecord( lacb, index, modify_data, datalen ) == DB_ERROR )
		return SCHEME_ERROR;

	return	SCHEME_OK;
}

/***********************************************************************************************/
STATUS	DelSchemeRecord(  DBLACB *lacb, U32 index, U8 reserved )
{
	LocalDelRecord( lacb, index );
	return	SCHEME_OK;
}

/***********************************************************************************************/
U32	CountTime( TIME_STRU *time )
{
	TIME_STRU	conversion_time;
	ASIX_TIME	cur_time;
	
	GetTime( &cur_time );
	TimetoInt( time, &conversion_time );

	return	(U32)( ( conversion_time.hour*3600 + conversion_time.minute*60 + conversion_time.second - cur_time.hour*3600 - cur_time.minute*60 - cur_time.second ) * 1000 );
}

/***********************************************************************************************/
U8	IsRenNian( void )
{
	ASIX_DATE	date;
	
	GetDate( &date );

	if( ( ( date.year - 2000 ) % 4 ) == 0 )
		return	TRUE;
	else
		return	FALSE;
}

⌨️ 快捷键说明

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