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

📄 sc1801.cpp

📁 这是一个在正实际应用当中运行的电力监控系统软件源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
Flag *FLAG=(Flag *)(lpChP->Reserved+80);
FLAG->PAFFLAG=1;
}
//PAR处理,电度数据
void ProcPAR(BYTE FAR * rxb,WORD rdp)
{//           MessageBeep(0);
//	if (PAFFLAG[lpChP->StaNo]==1)
  Flag *FLAG=(Flag *)(lpChP->Reserved+80);
    {
		WORD kwh=0;
		WORD Len=*(rxb+(rdp+2)%rxbuflen)*256+*(rxb+(rdp+3)%rxbuflen);
		for (int i=5;i<Len-1;i+=2,kwh++)
			{
			  	WORD VALUE=(WORD)(*(rxb+(rdp+i)%rxbuflen)*256)+(WORD)(*(rxb+(rdp+i+1)%rxbuflen));
              	SetValue(KWHDB,lpChP->StaNo,kwh,VALUE);
		   	}
		FLAG->PAFFLAG=2;
    }
}
//校时(发校时命令)
WORD CallSST(BYTE FAR *txb,WORD wrp)
{
  Flag *FLAG=(Flag *)(lpChP->Reserved+80);
    if (wrp==0) return 0;
    DWORD      seconds,*s;
	struct time Time;
    struct date Date;
    getdate (&Date);
	gettime (&Time);
	seconds=calsec(Date,Time);
    s=&seconds;
	*(txb+(wrp+0)%txbuflen)=lpStaP->STATIONNO;
	*(txb+(wrp+1)%txbuflen)=SST;
	*(txb+(wrp+2)%txbuflen)=0;
	*(txb+(wrp+3)%txbuflen)=6;
	*(txb+(wrp+4)%txbuflen)=(BYTE)(seconds>>24);
	*(txb+(wrp+5)%txbuflen)=(BYTE)(seconds>>16&0x00ff);
	*(txb+(wrp+6)%txbuflen)=(BYTE)(seconds>>8&0x0000ff);
	*(txb+(wrp+7)%txbuflen)=(BYTE)(seconds&0x000000ff);
	*(txb+(wrp+8)%txbuflen)=(Time.ti_hund*10)/256;
	*(txb+(wrp+9)%txbuflen)=(Time.ti_hund*10)%256;
	*(txb+(wrp+10)%txbuflen)=CallLPC(txb,wrp,10,txbuflen);
/*jgx 98.8

	*(txb+(wrp+9)%txbuflen)=seconds/(65536*256);
	*(txb+(wrp+8)%txbuflen)=(seconds/65536)%256;
	*(txb+(wrp+7)%txbuflen)=(seconds%65536)/256;
	*(txb+(wrp+6)%txbuflen)=seconds%256;
	*(txb+(wrp+5)%txbuflen)=(Time.ti_hund*10)/256;
	*(txb+(wrp+4)%txbuflen)=(Time.ti_hund*10)%256;
	*(txb+(wrp+10)%txbuflen)=CallLPC(txb,wrp,10,txbuflen);
*///jgx 98.8
	lpStaP->HOUR=Time.ti_hour;
	lpStaP->MIN=Time.ti_min;
	lpStaP->SEC=Time.ti_sec;
	FLAG->SSTFlag=0xff;
	return (wrp+11);
}

//数据发送处理
WORD CallData(BYTE FAR *txb,WORD wrp,BYTE Command)
{
//	PollOver[lpChP->StaNo]=0;
  Flag *FLAG=(Flag *)(lpChP->Reserved+80);
	FLAG->PollOver=0;
	*(txb+(wrp+0)%txbuflen)=lpStaP->STATIONNO;
	*(txb+(wrp+1)%txbuflen)=Command;
	if (FLAG->Retry==1){*(txb+(wrp+1)%txbuflen)|=0x80;
						 FLAG->Retry=0;
	                    }
    if (Command!=SDB)
       {
	    *(txb+(wrp+2)%txbuflen)=0;
	    *(txb+(wrp+3)%txbuflen)=0;
	    *(txb+(wrp+4)%txbuflen)=CallLPC(txb,wrp,4,txbuflen);
        return (wrp+5);
       }
    else
        {
	    *(txb+(wrp+2)%txbuflen)=0;
	    *(txb+(wrp+3)%txbuflen)=2;
	    *(txb+(wrp+4)%txbuflen)=HIBYTE(lpStaP->DeadValue);
	    *(txb+(wrp+5)%txbuflen)=LOBYTE(lpStaP->DeadValue);
		*(txb+(wrp+6)%txbuflen)=CallLPC(txb,wrp,6,txbuflen);
        return (wrp+7);
        }
}
//遥控执行
WORD ExecYk(BYTE FAR *txb,WORD wrp)
{
  BYTE constartboard=lpStaP->ConStartBoard; //jgx
  Flag *FLAG=(Flag *)(lpChP->Reserved+80);
 *(txb+wrp)=lpStaP->STATIONNO;
 *(txb+(wrp+1)%txbuflen)=COE;//jgx COA
 if (FLAG->Retry==1) *(txb+(wrp+1)%txbuflen)|=0x80;
 *(txb+(wrp+2)%txbuflen)=0;
 *(txb+(wrp+3)%txbuflen)=1;//jgx 2
 BYTE SwitchNo=lpStaP->DownCmd[lpStaP->DownCmdRP].Cmd[3];
      lpStaP->SwitchNo=SwitchNo;
// jgx SwitchNo=(SwitchNo/24+lpStaP->YXB[0])*16+SwitchNo%24;
 constartboard+=SwitchNo/16;//jgx 98.8
 SwitchNo=SwitchNo%16+constartboard*16;//jgx 98.8.20
 *(txb+(wrp+4)%txbuflen)=SwitchNo;
 BYTE LPC=CallLPC(txb,wrp,5,txbuflen);
 *(txb+(wrp+5)%txbuflen)=LPC;
 wrp+=6;
 return wrp;
}

//  遥控预置 遥控执行 遥控撤消
/*
   Cmd[0] = DCMDYK0 / DCMDYK1 / DCMDYK2;
   Cmd[1] = RTU序号低字节;
   Cmd[2] = RTU序号高字节;
   Cmd[3] = 遥控序号低字节;
   Cmd[4] = 遥控序号高字节;
   Cmd[5] = 遥控状态 (合0xcc/分0x33);
*/

//遥控预置/撤消 命令发送
WORD CallYk(BYTE FAR *txb,WORD wrp)
{
 BYTE constartboard=lpStaP->ConStartBoard; //jgx
 Flag *FLAG=(Flag *)(lpChP->Reserved+80);
 *(txb+wrp)=lpStaP->STATIONNO;
 *(txb+(wrp+1)%txbuflen)=COA;
 if (FLAG->Retry==1) *(txb+(wrp+1)%txbuflen)|=0x80;
 *(txb+(wrp+2)%txbuflen)=0;
 *(txb+(wrp+3)%txbuflen)=2;
 *(txb+(wrp+4)%txbuflen)=40; //40*250ms=10秒
 BYTE SwitchNo=lpStaP->DownCmd[lpStaP->DownCmdRP].Cmd[3];//遥控序号
	  lpStaP->SwitchNo=SwitchNo;//jgx add
//jgx SwitchNo=(SwitchNo/24+lpStaP->YXB[0])*16+SwitchNo%24;
 constartboard+=SwitchNo/16;//jgx 98.8
 SwitchNo=SwitchNo%16+constartboard*16;//jgx 98.8.20
 *(txb+(wrp+5)%txbuflen)=SwitchNo;//jgx 98.8
//jgx lpStaP->SwitchNo=SwitchNo;
 BYTE LPC=CallLPC(txb,wrp,6,txbuflen);
 *(txb+(wrp+6)%txbuflen)=LPC;
 wrp+=7;
 return wrp;
}
//遥控返校处理
void ProcCOA(BYTE FAR *rxb,WORD rdp)
{
 BYTE FJFLAG=0x55; //撤消
 if((*(rxb+(rdp+6)%rxbuflen))==0xff-((lpStaP->ConStartBoard+lpStaP->SwitchNo/16)*16+lpStaP->SwitchNo%16))
 {
//    MessageBox(0,"","",MB_OK);  //执行 jgx
	FJFLAG=0xaa;
   }
 COMMAND cmdrcd;
 BYTE rp = (lpStaP->DownCmdRP-1) & 3;
//jgx WORD rtuno = lpStaP->DownCmd[rp].Cmd[0]+lpStaP->DownCmd[rp].Cmd[1]*256;
  WORD rtuno = lpStaP->DownCmd[rp].Cmd[1]+lpStaP->DownCmd[rp].Cmd[2]*256;//jgx 98.8

 if(lpStaP->DownCmd[rp].Cmd[0]==DCMDYK0)//jgx && (lpChP->StaNo == rtuno))
  {
	 cmdrcd.CmdContent[0] = 0x44;  //遥控返校
	 cmdrcd.CmdContent[1] = lpStaP->DownCmd[rp].Cmd[1];
     cmdrcd.CmdContent[2] = lpStaP->DownCmd[rp].Cmd[2];
	 cmdrcd.CmdContent[3] = lpStaP->SwitchNo;//*(rxb+(rdp+3)%rxbuflen);//3 jgx
	 cmdrcd.CmdContent[4] =0;//jgx  *(rxb+(rdp+4)%rxbuflen);
	 cmdrcd.CmdContent[5] = 0x9e;// *(rxb+(rdp+1)%rxbuflen);
	 cmdrcd.CmdContent[6] = FJFLAG;//0xAA;  //遥控返校错:0x55  遥控返校正确:0xAA
	 cmdrcd.SubCmdType = TCZYKCMD;
     cmdrcd.DataLen = 0;
	 cmdrcd.DataPt = 0;
     WriteACommand(COMMANDDB, SENDCMDBUF, &cmdrcd, NULL);
	 lpStaP->DownCmd[rp].Cmd[0]=0;

	}
}
void CreateSoeForSCI(WORD Sta,WORD yx,BYTE yxv)
{
BYTE OldYx;
struct date Date;
struct time Time;
DWORD yxattr = GetAttr(YXDB, Sta, yx);
if (yxattr&YXXOR) yxv ^=1;
OldYx=GetValue(YXDB,Sta,yx);
if ((yxattr&YXCREATESOE) && (yxattr&RECRTUSOE) && (OldYx&1)!=(yxv&1))
	   {
                EVENT evercd;
			    BYTE yxtype = GetType(YXDB, Sta, yx);
                if (yxtype&YXSWITCH) evercd.EventType = KGEVENT;
                else if (yxtype&YXLINKER) evercd.EventType = DZEVENT;
                else if (yxtype&YXPROTECT) evercd.EventType = BHEVENT;
			    evercd.EventType =1;
                evercd.Station = Sta;
                evercd.Order = yx;

                getdate (&Date);
                gettime (&Time);

			    evercd.Hour=Time.ti_hour;
			    evercd.Min=Time.ti_min;
			    evercd.Sec=Time.ti_sec;
			    evercd.Ms=Time.ti_hund;
			    if (yxv&1) evercd.Status = 0xCC;
                else evercd.Status = 0x33;
                evercd.EventAttr &= ~SGFLAG;
                if (GetTimerValue(RTUDB, evercd.Station))
                   {
                    if (evercd.Status==0x33)
                       {
                        if ((yxtype==YXSWITCH) || (yxtype==YXLINKER))
                           evercd.EventAttr |= SGFLAG;
					   }
                    else if (yxtype==YXPROTECT) evercd.EventAttr |= SGFLAG;
                    }
			    evercd.data[0]=evercd.Status;
			    if (
				   ((lpStaP)->Soe[0].ORDER!=yx)||
				   ((lpStaP)->Soe[0].TIME!=evercd.Hour)||
				   ((lpStaP)->Soe[0].MINUTE!=evercd.Min)||
				   ((lpStaP)->Soe[0].SECOND!=evercd.Sec)||
				   ((lpStaP)->Soe[0].MSH!=evercd.Ms/100)||
				   ((lpStaP)->Soe[0].MSL!=evercd.Ms%100)||
				   ((lpStaP)->Soe[0].STATUS!=evercd.Status)
				  )
				    {
				        (lpStaP)->Soe[0].ORDER=yx;
				        (lpStaP)->Soe[0].TIME=evercd.Hour;
				        (lpStaP)->Soe[0].MINUTE=evercd.Min;
				        (lpStaP)->Soe[0].SECOND=evercd.Sec;
				        (lpStaP)->Soe[0].MSH=evercd.Ms/100;
				        (lpStaP)->Soe[0].MSL=evercd.Ms%100;
				        (lpStaP)->Soe[0].STATUS=evercd.Status;
		
					    WriteAEvent(EVENTDB, &evercd);
                    }
            }
}

void ProcSDB(BYTE FAR *rxb,WORD rdp) 
{
Flag *FLAG=(Flag *)(lpChP->Reserved+80);
    FLAG->SDBB=1;
}


DWORD calsec(struct date Date,struct time Time)
{
DWORD  total=0,temp=0;
DWORD    year,month,day,hour,min,sec,i;
DWORD    Days;
year=Date.da_year;//
month=Date.da_mon;//
day=Date.da_day;//
hour=Time.ti_hour;//
min=Time.ti_min;//
sec=Time.ti_sec;//

if (year<2010)
{
for (i=1999;i<year;i++)
    {
        Days=DayPeYear(i);
        temp+=(DWORD)Days*(DWORD)86400;          
    }
for (i=1;i<month;i++)
    {
        Days=DayPeMonth(year,i);
        temp+=(DWORD)Days*(DWORD)86400;
    }
        temp+=(DWORD)(day-1)*(DWORD)86400;
        temp+=(DWORD)hour*(DWORD)3600;
        temp+=(DWORD)min*(DWORD)60;
temp+=sec;
total=0xffffffff-(DWORD)94608000+temp+(DWORD)1;//jgx 98.8
//total=94608000-temp;
//total=946684800-temp;
return total;
}
else
{
if (year!=2010)
for (i=2010;i<year;i++)
    {
        Days=DayPeYear(i);
        temp+=Days*86400;          
    }
if (month!=1)
for (i=1;i<month;i++)
    {
        Days=DayPeMonth(year,i);
        temp+=Days*86400;
    }
        temp+=(DWORD)(day-1)*(DWORD)86400;
        temp+=(DWORD)hour*(DWORD)3600;
        temp+=(DWORD)min*(DWORD)60;
temp+=sec;
total=temp;
return total;

}
}

DWORD    DayPeYear(DWORD year)
{
    if (year%4!=0 || (year%4==0 && year%100==0)) return 365;
    /*if (year%4==0)*/
    return 366;
}
DWORD    DayPeMonth(DWORD  year,DWORD month)
{
    if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
       return    31;
    if (month==4 || month==6 || month==9 || month==11)
       return    30;
    if (month==2 && (year%4!=0 || (year%4==0 && year%100==0))) return 28;
	if (year%4==0 && month==2) return 29;
    return 0;
}

Group Current(DWORD seconds)
{
DWORD month=1,day,hour,min,sec,flag;
Group total;
DWORD   Ddays,Secs,i,j,year;
struct  date D;
getdate (&D);
if (D.da_year<2020)
{
seconds=94608000-seconds;//94608000为97年至2020年的秒数 jgx
Ddays=seconds/86400;
Secs=seconds%86400;
hour=Secs/3600;
min=(Secs%3600)/60;
sec=Secs%60;
year=1999+Ddays/365;
Ddays=Ddays%365;
for (j=1;j<13;j++)
    {
        if ((Ddays<DayPeMonth(year,j)))
           {
            day=Ddays+1;
            break;
           }
        else
            {
                Ddays-=DayPeMonth(year,j);
            }
        month=j+1;
    }
if (day==0) day=1;
total.year=year;
total.month=month;
total.day=day;
total.hour=hour;
total.min=min;
total.sec=sec;
return total;
}
else
{
Ddays=seconds/86400;
Secs=seconds%86400;
hour=Secs/3600;
min=(Secs%3600)/60;
sec=Secs%60;
for (year=2020;year<3000;year++)
{
    if (Ddays>DayPeYear(year))
       {
              Ddays-=DayPeYear(year);
       }
    else    break; 
}
//Ddays=Ddays%365;
for (j=1;j<13;j++)
    {
        if ((Ddays<DayPeMonth(year,j)))
           {
            day=Ddays+1;
            break;
           }
        else
            {
                Ddays-=DayPeMonth(year,j);
            }
        month=j+1;
    }
if (day==0) day=1;
total.year=year;
total.month=month;
total.day=day;
total.hour=hour;
total.min=min;
total.sec=sec;
return total;
}
}

⌨️ 快捷键说明

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