📄 server2.cpp
字号:
// Server2.cpp : Implementation of CComServerApp and DLL registration.
#include "stdafx.h"
#include "ComServer.h"
#include "Server2.h"
#include "Server1.h"
static WCHAR gwszTemp[128];
/////////////////////////////////////////////////////////////////////////////
//
STDMETHODIMP Server2::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IDataFlow,
&IID_IDataChange,
};
for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP Server2::getaddrbps(int *port, int *bps)
{
// TODO: Add your implementation code here
*port=Files.sys.addr;
*bps=Files.sys.velo;
return S_OK;
}
STDMETHODIMP Server2::iforder(int *rb)
{
// TODO: Add your implementation code here
int i,j;
*rb=0;
//for(i=0;i<10;i++) 2005-2-24 by QuanGuo
for(i=0;i<24;i++)
{
if(sendbuf[0][i].flag)
{
*rb=1;
switch(sendbuf[0][i].ord)
{
case 0x10:
fix_stno=sendbuf[0][i].stno;
break;
case 0x11:
fix_stno=0xff;
break;
case 2:
ordbuf[0]=sendbuf[0][i].stno;
ordbuf[1]=sendbuf[0][i].ord;
//ordbuf[2]=sendbuf[0][i].bufsize;
for(j=0;j<sendbuf[0][i].bufsize;j++)
ordbuf[j+2]=sendbuf[0][i].buf[j];
break;
default:
ordbuf[0]=sendbuf[0][i].stno;
ordbuf[1]=sendbuf[0][i].ord;
ordbuf[2]=sendbuf[0][i].bufsize;
for(j=0;j<sendbuf[0][i].bufsize;j++)
ordbuf[j+3]=sendbuf[0][i].buf[j];
break;
}
sendbuf[0][i].flag=0;
return S_OK;
}
}
return S_OK;
}
STDMETHODIMP Server2::ifixst(int *rb)
{
// TODO: Add your implementation code here
if(stinfo.stinfo[ordbuf[0]]==2)
*rb=1;
else
*rb=0;
return S_OK;
}
STDMETHODIMP Server2::if01ord(int *rb)
{
// TODO: Add your implementation code here
if(ordbuf[1]==01)
*rb=1;
else
*rb=0;
return S_OK;
}
STDMETHODIMP Server2::setNormalord(int stno, int *nextno)
{
// TODO: Add your implementation code here
int i,j;
if(fix_stno==0xff)
{
for(i=stno;i<255;i++)
{
if((File4.flag[i]&0xc0)==0)
{
ordbuf[0]=i&0xff;
ordbuf[1]=0;
//ordbuf[2]=ordbuf[0];
for(j=i+1;j<255;j++)
{
if((File4.flag[j]&0xc0)==0)
{
*nextno=j;
return S_OK;
}
}
if(j>=255) *nextno=1;
return S_OK;
}
}
}else{
if(fix_stno!=0)
{
ordbuf[0]=fix_stno&0xff;
ordbuf[1]=0;
//ordbuf[2]=ordbuf[0];
*nextno=fix_stno&0xff;
}else fix_stno=0xff;
}
return S_OK;
}
STDMETHODIMP Server2::getordbuf(unsigned char odbuf[300],int *ordsize)
{
// TODO: Add your implementation code here
int i,j;
unsigned char chksum;
int ordlen;
for(i=0;i<255;i++)
odbuf[i]=ordbuf[i];
stinfo.currentstno=ordbuf[0];
switch(ordbuf[1])
{
case 0:
case 1:
case 7:
case 9:
ordlen=3;
break;
case 2:
ordlen=5;
break;
case 3:
case 4:
case 5:
case 6:
ordlen=ordbuf[2]+4;
break;
}
*ordsize=ordlen;
for(i=0;i<5;i++)
stinfo.info[i]=0xff;
chksum=0xff;
for(j=0;j<ordlen;j++)
{
if(j<ordlen-1)
{
stinfo.info[j+i]=ordbuf[j];
chksum^=ordbuf[j];
}else{
stinfo.info[j+i]=chksum;
}
}
stinfo.infoCt=ordlen+5;
return S_OK;
}
STDMETHODIMP Server2::setrecvbuf(int st,int ct,unsigned char *recv)
{
// TODO: Add your implementation code here
int i,j;
if(ct!=0)
{
for(i=0;i<ct;i++)
recvbuf[i]=recv[i];
}
//Server3::gethost(rett);
switch(st)
{
case 1:
stinfo.xorerrcount++;
//stinfo.stinfo[recvbuf[5]]=1; //贺加
if (comsertype==1)
stinfo.stinfo[ordbuf[0]]=1; //于加
//stinfo.stinfo[ordbuf[0]]=1; //于加
// stinfo.currentstno=recvbuf[5];
break;
case 2:
stinfo.overtimecount++;
break;
case 0:
// if(ct!=0) //于改
// {
// for(i=0;i<ct;i++)
// recvbuf[i]=recv[i];
// }
stinfo.normalcount++;
stinfo.stinfo[recvbuf[5]]=0; //贺加
//stinfo.stinfo[recvbuf[5]]=0;
stinfo.currentstno=recvbuf[5];
break;
}
for(j=0;j<ct;j++)
stinfo.info[j]=recv[j];
stinfo.infoCt=ct;
return S_OK;
}
STDMETHODIMP Server2::processdata(int* rb)
{
// TODO: Add your implementation code here
// unsigned char check;
int i,h;
int j;
int exd[10];
int ct=0;
switch(recvbuf[6])
{
case 00:
case 07:
//if(Translate[0].flag) counter0++;
Translate[0].stno=recvbuf[5];
Translate[0].bufsize=recvbuf[8]*256+recvbuf[7];
for(i=0;i<Translate[0].bufsize;i++)
Translate[0].buf[i]=recvbuf[9+i];
#ifdef FiledAlarm
rjAlarmState[Translate[0].stno]=Translate[0].buf[i-1]; //贺加2005-3-7 获取当前分站是否报警
#endif
if(i>0) Translate[0].flag=1;
resendflag=0;
break;
case 02:
case 03:
case 06:
resendflag=0;
break;
case 05:
if(comsertype)
{
h=(File4.info[recvbuf[5]].state_type&0xf0)>>4;
if(Files.st[h].extend==1)
{
for(i=0;i<254;i++)
{
if(st_exd.Statation[i]==recvbuf[5])
{
exd[ct]=i;
ct++;
}
}
ordbuf[0]=recvbuf[5];
ordbuf[1]=6;
ordbuf[2]=ct+1;
ordbuf[3]=ct;
for(j=0;j<ct;j++)
ordbuf[j+4]=exd[j];
resendflag=1;
}else resendflag=0;
}
break;
case 04:
if(comsertype)
{
h=(File4.info[recvbuf[5]].state_type&0xf0)>>4;
if(Files.st[h].other==1)
{
ordbuf[0]=recvbuf[5];
ordbuf[1]=5;
ordbuf[2]=station_xinxi[recvbuf[5]].xinxi_len;
for(j=0;j<ordbuf[2];j++)
ordbuf[j+3]=station_xinxi[recvbuf[5]].info[j];
resendflag=1;
}else resendflag=0;
}
break;
//case 9:
// SYSTEMTIME pdt;
// if((File4.flag[recvbuf[5]]&4)!=0)
// {
// GetLocalTime(&pdt);
// rstm[recvbuf[5]]=dateCal(pdt.wYear,pdt.wMonth,pdt.wDay,pdt.wHour,pdt.wMinute,pdt.wSecond);
// setm_flg=1;
// resendflag=0;
// }
// break;
case 0x20:
case 0x30:
case 0x50:
case 0x60:
if(comsertype)
{
// if(!resendflag) 2002.7.23 modify
resendflag=!resendflag;
}
break;
case 0x40:
int rc;
if(comsertype)
{
// if(!resendflag) 2002.7.23 modify
resendflag=!resendflag;
if(File4.flag[recvbuf[5]]!=4)
{
ifinit(recvbuf[5],&rc);
if(rc==1) resendflag=1;
}
}
break;
}
if(resendflag)
*rb=1;
else
*rb=0;
return S_OK;
}
DATE Server2::dateCal(int year,int month,int day,int hour,int minute,int second)
{
int i;
DATE tmpdate=0;
for(i=1900;i<year;i++)
{
if (if_leapyear(i)==1)
tmpdate+=366;
else
tmpdate+=365;
}
tmpdate+=1;
tmpdate+=day;
for(i=1;i<month;i++)
{
if((i==1) || (i==3) || (i==5) || (i==7) || (i==8) || (i==10))
tmpdate+=31;
else if(i==2)
{
if(if_leapyear(year)==1)
tmpdate+=29;
else
tmpdate+=28;
}
else
tmpdate+=30;
}
tmpdate+=(double)hour/24;
tmpdate+=(double)minute/(24*60);
tmpdate+=(double)second/(24*60*60);
return tmpdate;
}
int Server2::if_leapyear(int year)
{
int leap_year;
if(year % 4==0)
{
if(year%100==0)
{
if(year%400==0)
leap_year=1;
else
leap_year=0;
}
else leap_year=1;
}
else
leap_year=0;
return leap_year;
}
STDMETHODIMP Server2::ifchecktime(int *rb)
{
// TODO: Add your implementation code here
SYSTEMTIME pdt;
// int i,cls,h;
long ct;
bool bl;
DWORD err;
*rb=0;
if(demosys)
{
if(democount>=15000)//2 hour
{
bl=ReleaseSemaphore(termhd,10,&ct);
if(!bl)
err=GetLastError();
}
democount++;
}
GetLocalTime(&pdt);
if(pdt.wMinute==lastime[1])
{
if(pdt.wHour!=lastime[0])
{
if(!tmoutflg)
{
tmok=1;
tmoutflg=1;
}
}
}else tmoutflg=0;
return S_OK;
}
STDMETHODIMP Server2::setstErr()
{
// TODO: Add your implementation code here
stinfo.stinfo[stinfo.currentstno]=2;
return S_OK;
}
STDMETHODIMP Server2::ifinit(int no, int *stno)
{
// TODO: Add your implementation code here
int h,j;
*stno=0;
if((File4.flag[no]&0xc0)==0)
{
if((File4.flag[no]&0x4)==0)
{ //处理KJ95系统分站init
h=(File4.info[no].state_type&0xf0)>>4;
if(Files.st[h].initflag==0)
{
ordbuf[0]=no;
ordbuf[1]=4;
ordbuf[2]=st_ini[no].ini_len;
for(j=0;j<ordbuf[2];j++)
ordbuf[j+3]=st_ini[no].info[j];
*stno=1;
}
}else{//处理人监分站init
ordbuf[0]=no;
//if(rstm[no]==0)
// ordbuf[1]=9;
//else
ordbuf[1]=7;
*stno=2;
}
}
return S_OK;
}
STDMETHODIMP Server2::ifinitExt(int no, int *stno)
{
// TODO: Add your implementation code here
int h,j;
*stno=0;
if((File4.flag[no]&0xc0)==0)
{
h=(File4.info[no].state_type&0xf0)>>4;
if(Files.st[h].other==1)
{
ordbuf[0]=no;
ordbuf[1]=5;
ordbuf[2]=station_xinxi[no].xinxi_len;
for(j=0;j<ordbuf[2];j++)
ordbuf[j+3]=station_xinxi[no].info[j];
*stno=1;
}
}
return S_OK;
}
STDMETHODIMP Server2::ifinitExp(int no, int *stno)
{
// TODO: Add your implementation code here
int i,h,j;
int ct=0;
int exd[10];
*stno=0;
if((File4.flag[no]&0xc0)==0)
{
h=(File4.info[no].state_type&0xf0)>>4;
if(Files.st[h].extend==1)
{
for(i=0;i<254;i++)
{
if(st_exd.Statation[i]==no)
{
exd[ct]=i;
ct++;
}
}
if(ct!=0)
{
ordbuf[0]=no;
ordbuf[1]=6;
ordbuf[2]=ct+1;
ordbuf[3]=ct;
for(j=0;j<ct;j++)
ordbuf[j+4]=exd[j];
*stno=1;
}
}
}
return S_OK;
}
STDMETHODIMP Server2::proc_ord(int i)
{
// TODO: Add your implementation code here
int k,j;
// SYSTEMTIME pdt;
// int tmpxor;
switch(i)
{
case 00:
if(console0out.flag)
{
console0out.flag=0;
j=0;
while((j<24)&&(sendbuf[0][j].flag))
j++;
sendbuf[0][j].stno=console0out.stno;
switch(console0out.ordercode)
{
case 0:
sendbuf[0][j].ord=0x10;
sendbuf[0][j].flag=1;
setEventRecord(6,console0out.stno,0);
break;
case 2:
sendbuf[0][j].ord=0x11;
sendbuf[0][j].flag=1;
setEventRecord(7,console0out.stno,0);
break;
case 1:
sendbuf[0][j].ord=4;
sendbuf[0][j].bufsize=st_ini[sendbuf[0][j].stno].ini_len;
for(k=0;k<sendbuf[0][j].bufsize;k++)
sendbuf[0][j].buf[k]=st_ini[sendbuf[0][j].stno].info[k];
sendbuf[0][j].flag=1;
setEventRecord(5,console0out.stno,0);
break;
}
return S_OK;
}
if(console1out.flag)
{
console1out.flag=0;
j=0;
while((j<24)&&(sendbuf[0][j].flag))
j++;
sendbuf[0][j].stno=console1out.stno;
sendbuf[0][j].ord=2;
sendbuf[0][j].bufsize=2;
sendbuf[0][j].buf[0]=console1out.kc[0];
sendbuf[0][j].buf[1]=console1out.kc[1];
sendbuf[0][j].flag=1;
setEventRecord(2,console1out.stno,console1out.kc[1]*256+console1out.kc[0]);
return S_OK;
}
for(k=0;k<20;k++)
{
if(ctrout[k].flag)
{
ctrout[k].flag=0;
j=0;
while((j<10)&&(sendbuf[0][j].flag))
j++;
sendbuf[0][j].stno=ctrout[k].stno;
sendbuf[0][j].ord=2;
sendbuf[0][j].bufsize=2;
sendbuf[0][j].buf[0]=ctrout[k].kc[0];
sendbuf[0][j].buf[1]=ctrout[k].kc[1];
sendbuf[0][j].flag=1;
setEventRecord(1,ctrout[k].stno,ctrout[k].kc[1]*256+ctrout[k].kc[0]);
return S_OK;
}
}
break;
default:
break;
}
if(fz_ini_req)
{
for(k=0;k<255;k++)
{
if((File4.flag[k]&0xc0)==0)
{
if(File4.flag[k]&1)
{
if(console0out.flag==0)
{
console0out.stno=k;
console0out.ordercode=1;
console0out.flag=1;
File4.flag[k]=0;
}
return S_OK;
}
}
}
fz_ini_req=0;
}
return S_OK;
}
STDMETHODIMP Server2::convdata(int i)
{
// TODO: Add your implementation code here
VARIANT vl;
int j,ct,k,m,n,mlct,h;
unsigned char buf[20],bt;
int ErrOldNum=erroroldrecord.ErrorCun;
vl.vt=VT_I2;
m=0;
switch(i)
{
case 00:
if(Translate[0].flag)
{
if(stations[0].flag) counter1++;
stations[0].stno=Translate[0].stno;
if(File4.flag[stations[0].stno]&0xc0) return S_OK;
h=(File4.info[stations[0].stno].state_type&0xf0)>>4;
ct=Files.st[h].inport;
for(k=0;k<20;k++)
buf[k]=st_ini[stations[0].stno].info[k];
switch(ct)
{
case 4:
case 8:
n=1;
break;
case 16:
case 32:
n=ct/8;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -