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

📄 wmfuc.c

📁 AVRMEG32编写的一个项目代码,里面包含一般应用的模块.
💻 C
字号:
#include "includes.h"
//十六进制转换为ASCII码
unsigned char hex2asc(unsigned char hex)
{
  if (hex>=0x0a) hex+=0x37;
    else hex+=0x30;
  return(hex);
}

//ASCII码换为十六进制
unsigned char asc2hex(unsigned char asc)
{
  if (asc>0x39) asc-=0x37;
    else asc-=0x30;
  return(asc);
}

//十六进制换10进制
unsigned char dec2bcd(unsigned char decNum)
{
unsigned char ucTmp;
ucTmp=decNum/10;
ucTmp*=16;
ucTmp+=decNum%10;
return(ucTmp);
}

//10进制换十六进制
unsigned char bcd2dec(unsigned char bcdNum)
{
unsigned char ucTmp;
ucTmp=bcdNum/16;
ucTmp*=10;
ucTmp+=bcdNum%16;
return(ucTmp);
}

//if 0xAA  无告警
void clearAlrByClass(void)
{
    u08 i;
    for(i=0;i<MAXALRREC;i++)
	xRAlrData[i].DCALRDelete_FLAG=0xAA;
}
//清门禁标志位
void cleardor_FLAG(void)
{
    xRdorData[SAMTYPE_MENGJIN1].doropenDelete_FLAG= 0;//清门禁1灵敏度标志,开
    xRdorData[SAMTYPE_MENGJIN2].doropenDelete_FLAG= 0;//清门禁2灵敏度标志
    xRdorData[SAMTYPE_MENGJIN3].doropenDelete_FLAG= 0;//清门禁3灵敏度标志
    xRdorData[SAMTYPE_MENGJIN1].dorcloseDelete_FLAG= 0;//清门禁1灵敏度标志,关
    xRdorData[SAMTYPE_MENGJIN2].dorcloseDelete_FLAG= 0;//清门禁2灵敏度标志
    xRdorData[SAMTYPE_MENGJIN3].dorcloseDelete_FLAG= 0;//清门禁3灵敏度标志
}
//repeat重复告警datum数据
/*u08 isAlrRepeatDatum(u08 ui)
{
u08 ucSamType;
u08 bTmp = 0;
ucSamType=xRAlrData[ui].DCSAMType;
if (xRAlrData[ui].DCALRDelete_FLAG!=0xAA&&xRAlrData[ui].DCALRSAMPSensitityReg==0xAA&&xRAlrData[ui].DCALRHandled_FLAG!=0xAA)
	{
	if (xRAlrData[ui].DCALRReoprted_FLAG==0xAA&&xRAlrData[ui].DCALRRepeated_FLAG!=0xAA&&xRSamplePara[ucSamType-1].DCAlrRptRepeat_FLAG==0xAA)
		bTmp=1;
	}
return(bTmp);
}*/

/*
//未上报
u08 isAlrUnreportedDatum(u08 ui)
{
u08 bTmp = 0;
if ((xRAlrData[ui].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[ui].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[ui].DCALRRptDelaySReg==0xAA)&&(xRAlrData[ui].DCALRReoprted_FLAG!=0xAA))
	bTmp=1;
return(bTmp);
}
*/

//已处理告警函数
/*u08 isAlrHandledDatum(u08 ui)
{
u08 bTmp = 0;
if (xRAlrData[ui].DCALRDelete_FLAG!=0xAA && xRAlrData[ui].DCALRSAMPSensitityReg==0xAA && xRAlrData[ui].DCALRHandled_FLAG==0xAA)
	{
		if (xRAlrData[ui].DCALRHandledReport_FLAG!=0xAA)
		    bTmp=1;
	}
return(bTmp);
}
*/
/*
//清所有重复告警标志
void clrAllAlrRepeatedFlag(void)
{
u08 i;
for (i=0;i<MAXALRREC;i++)
	{
	if (isAlrRepeatReportedDatum(i))
		xRAlrData[i].DCALRRepeated_FLAG=0;
	}
}

*/

//已上报重复报警数据
/*u08 isAlrRepeatReportedDatum(u08 ui)
{
u08 ucSamType;
u08 bTmp = 0;
ucSamType=xRAlrData[ui].DCSAMType;
if (xRAlrData[ui].DCALRDelete_FLAG!=0xAA&&xRAlrData[ui].DCALRSAMPSensitityReg==0xAA&&xRAlrData[ui].DCALRRptDelaySReg==0xAA&&xRAlrData[ui].DCALRHandled_FLAG!=0xAA)
	{
	if (xRAlrData[ui].DCALRReoprted_FLAG==0xAA&&xRAlrData[ui].DCALRRepeated_FLAG==0xAA&&xRSamplePara[ucSamType-1].DCAlrRptRepeat_FLAG==0xAA)
		bTmp=1;
	}
return(bTmp);
}
*/
/*void rptDelayPro(void)
{
unsigned int i;
unsigned char ucSamType;
for (i=0;i<MAXALRREC;i++)
	{
	if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRRptDelaySReg!=0xAA))
		{
		xRAlrData[i].DCALRRptDelaySReg++;
		ucSamType=xRAlrData[i].DCSAMType;
		if (xRAlrData[i].DCALRRptDelaySReg>=xRSamplePara[ucSamType-1].DCAlrRptDelayS)
			xRAlrData[i].DCALRRptDelaySReg=0xAA;
		}
	}
}*/

/*//获得告警总数
u08 getTotalAlrByClass(u08 ucViewClass)
{
u08 i;
u08 iTtl;
iTtl=0;
switch (ucViewClass)
	{
	case VClass_UnhandledAlr:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRHandled_FLAG!=0xAA))
				iTtl++;
			}
		break;
	case VClass_HandledQiangDRQNeedShowAndUnhandledOthers:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA))
				{
				if (xRAlrData[i].DCALRHandled_FLAG!=0xAA)
					iTtl++;
				else
					{
					if (isQiangDRQ(xRAlrData[i].DCSAMType)&&(xRAlrData[i].DCALRKeepShowCounter>0))
						iTtl++;
					}
				}
			}
		break;
	case VClass_HandledAlr:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRHandled_FLAG==0xAA))
				iTtl++;
			}
		break;
	case VClass_UnreportedAlr:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRReoprted_FLAG!=0xAA))
				iTtl++;
			}
		break;
	case VClass_ReportedAlr:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRReoprted_FLAG==0xAA))
				iTtl++;
			}
		break;
	case VClass_AllAlr:
		for (i=0;i<MAXALRREC;i++)
			{
			if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA))
				iTtl++;
			}
		break;
	default:
		break;
	}

return(iTtl);
}
*/
/*扫描告警
void scanAlr()
{
unsigned int i;
unsigned char ucSamType;
for (i=0;i<MAXALRREC;i++)
	{
	if ((xRAlrData[i].DCALRDelete_FLAG!=0xAA)&&(xRAlrData[i].DCALRSAMPSensitityReg==0xAA)&&(xRAlrData[i].DCALRRptDelaySReg==0xAA))
		{
		ucSamType=xRAlrData[i].DCSAMType;
		if (xRAlrData[i].DCALRHandled_FLAG!=0xAA)
			{
			g_btUnhandledAlr=1;
			if (isQiangDRQ(ucSamType))
				g_btUnhandledQiangDRQ=1;
			if (xRAlrData[i].DCALRReoprted_FLAG!=0xAA)
				g_btUnreportedUnhandledAlr=1;
			if (xRAlrData[i].DCALRReoprted_FLAG==0xAA&&xRSamplePara[ucSamType-1].DCAlrRptRepeat_FLAG==0xAA)
				g_btRepeatReportedUnhandledAlr=1;
			}
		else
			{
			if (isQiangDRQ(ucSamType)&&(g_ucQianDRQShowDelaySeconds>0)&&(xRAlrData[i].DCALRKeepShowCounter>0))
				{
				xRAlrData[i].DCALRKeepShowCounter-=g_ucQianDRQShowDelaySeconds;
				g_ucQianDRQShowDelaySeconds=0;
				}
			if (xRAlrData[i].DCALRHandledReport_FLAG!=0xAA)
				g_btHandledUnreportedAlr=1;
			}
		if (xRAlrData[i].DCALRReoprted_FLAG!=0xAA)
			g_btUnreportedAlr=1;
		}
	}
}
*/

//新告警入口
u08 newAlrOffset(void)
{
u08 i;
u08 uiAlrOffset;
uiAlrOffset=MAXALRREC;
for (i=0;i<MAXALRREC;i++)
	{
	if (xRAlrData[i].DCALRDelete_FLAG==0xAA)
		{
		uiAlrOffset=i;
		break;
		}
	}
return(uiAlrOffset);
}

//found 告警入口
u08 seekAlrOffset(u08 ucSamType)
{
u08 i;
u08 uiAlrOffset;//入口地址
uiAlrOffset=MAXALRREC;
for (i=0;i<MAXALRREC;i++)
	{
	if ((xRAlrData[i].DCSAMType==ucSamType)&&(xRAlrData[i].DCALRDelete_FLAG!=0xAA))
		{
		uiAlrOffset=i;
		break;
		}
	}
return(uiAlrOffset);
}


//正常,无告警处理或告警恢复
void handleOkBit(u08 ucSamType)
{
    u08 uiOffset;
    uiOffset=seekAlrOffset(ucSamType);
    if (uiOffset < MAXALRREC)  //entrance found
	{
	    if (xRAlrData[uiOffset].DCALRHandled_FLAG!=0xAA)
		{
	    	xRAlrData[uiOffset].DCALRHandled_FLAG++;
	    	if (xRAlrData[uiOffset].DCALRHandled_FLAG>=3)
			{
			    xRAlrData[uiOffset].DCALRHandled_FLAG=0xAA;
			    xRAlrData[uiOffset].DCALRSAMPSensitityReg = 0;
			    xRAlrData[uiOffset].DCALRDelete_FLAG=0xAA;
	//		xRAlrData[uiOffset].DCALRHandledTime[0]=YEAR_BUFFER;
	//		xRAlrData[uiOffset].DCALRHandledTime[1]=MONTH_BUFFER;
	//		xRAlrData[uiOffset].DCALRHandledTime[2]=DAY_BUFFER;
	//		xRAlrData[uiOffset].DCALRHandledTime[3]=HOUR_BUFFER;
	//		xRAlrData[uiOffset].DCALRHandledTime[4]=MINUTE_BUFFER;
	//		xRAlrData[uiOffset].DCALRHandledTime[5]=SECOND_BUFFER;
			}
		}
	}
}

//告警类型、告警列、告警值,有告警处理
void handleAlrBit(u08 ucSamType)
{
 	 u08 uiOffset;
	 uiOffset=seekAlrOffset(ucSamType);
	 if (uiOffset<MAXALRREC)  //entrance is found
	{
		if (xRAlrData[uiOffset].DCALRSAMPSensitityReg!=0xAA)
		{
		     xRAlrData[uiOffset].DCALRSAMPSensitityReg++;
		     if(xRAlrData[uiOffset].DCALRSAMPSensitityReg>=3)
		     {
			     xRAlrData[uiOffset].DCALRSAMPSensitityReg=0xAA;//告警一直存在
		         xRAlrData[uiOffset].DCALRHandled_FLAG=0;
             }
		}
	    else
		{
		if(xRAlrData[uiOffset].DCALRHandled_FLAG==0xAA) //if handled,overwrite
			{
			 //   xRAlrData[uiOffset].DCALRValue=uiSamValue;
			 //   writeAlrTime(uiOffset);
			    xRAlrData[uiOffset].DCALRReoprted_FLAG=0;
			    xRAlrData[uiOffset].DCALRHandled_FLAG=0;
			    xRAlrData[uiOffset].DCALRHandledReport_FLAG=0;
			    xRAlrData[uiOffset].DCALRSAMPSensitityReg=1;//灵敏度少一次
			}
		}
	}
    else  //entrance is not found
	{
	    uiOffset=newAlrOffset();
	    if (uiOffset < MAXALRREC)
		{
	         xRAlrData[uiOffset].DCSAMType=ucSamType;
		 //    xRAlrData[uiOffset].DCALRValue=uiSamValue;
		  // writeAlrTime(uiOffset);
		     xRAlrData[uiOffset].DCALRReoprted_FLAG=0;//未上报,0XAA,则已上报
		     xRAlrData[uiOffset].DCALRHandled_FLAG=0;//未处理,0XAA则已处理
		     xRAlrData[uiOffset].DCALRHandledReport_FLAG=0;//已处理告警未上报,0XAA则已上报
		     xRAlrData[uiOffset].DCALRSAMPSensitityReg=0;
		     xRAlrData[uiOffset].DCALRDelete_FLAG=0;
		}
	}
}

//门,开
void handleopendorBit(u08 ucSamType,u08 data)
{
    u08 i;
	for(i=0;i<3;i++)
	{
	    if (ucSamType == i)
	        if (xRdorData[i].doropenDelete_FLAG!=0xAA)
		    {
                xRdorData[i].dorcloseDelete_FLAG=0;
                xRdorData[i].doropenDelete_FLAG++;
	    	    if (xRdorData[i].doropenDelete_FLAG>1)//灵敏度
			       {
				       xRdorData[i].dorValue = 1;//门开
                       xRdorData[i].doropenDelete_FLAG=0xAA;
                      
					   return;
                   }
			 }
     }
}
//门,关
void handledorBit(u08 ucSamType,u08 data)
{
    u08 i;
	for(i=0;i<3;i++)
	{
 	    if (ucSamType == i)
            if (xRdorData[i].dorcloseDelete_FLAG!=0xAA)
	        {
                 xRdorData[i].doropenDelete_FLAG=0;
				 xRdorData[i].dorcloseDelete_FLAG++;//灵敏度
                 if (xRdorData[i].dorcloseDelete_FLAG >1)
                     {
					     xRdorData[i].dorValue = 0;//门关
                         xRdorData[i].dorcloseDelete_FLAG=0xAA;
					     
						 return;
					 }
            }
	}
}
#if 0
void unusedorBit(u08 data)//门禁未启用
{
	if(data == SAMTYPE_MENGJIN1)
    {
		xRdorData[SAMTYPE_MENGJIN1].dorValue = SAMTYPE_MENGJIN_UNUSE;//门禁一未启用
	    xRdorData[SAMTYPE_MENGJIN1].dorDelete_FLAG= 5;//清灵敏度标志
    }
	if(data == SAMTYPE_MENGJIN2)
	{
	    xRdorData[SAMTYPE_MENGJIN2].dorValue = SAMTYPE_MENGJIN_UNUSE;//门禁二未启用
	    xRdorData[SAMTYPE_MENGJIN2].dorDelete_FLAG= 5;
	}
	else
	{
	    xRdorData[SAMTYPE_MENGJIN3].dorValue = SAMTYPE_MENGJIN_UNUSE;//门禁三未启用
        xRdorData[SAMTYPE_MENGJIN3].dorDelete_FLAG = 5;
    }
}
#endif
//告警时间
/*void writeAlrTime(unsigned int uiOffset)
{
xRAlrData[uiOffset].DCALRTime[0]=YEAR_BUFFER;
xRAlrData[uiOffset].DCALRTime[1]=MONTH_BUFFER;
xRAlrData[uiOffset].DCALRTime[2]=DAY_BUFFER;
xRAlrData[uiOffset].DCALRTime[3]=HOUR_BUFFER;
xRAlrData[uiOffset].DCALRTime[4]=MINUTE_BUFFER;
xRAlrData[uiOffset].DCALRTime[5]=SECOND_BUFFER;
}*/




⌨️ 快捷键说明

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