电力系统103的通信程序
void Proc_ReqEvents(unsigned char addr){
char pStr[100];
short year, month, day, hour, minute, second, ms;
float seconds;
unsigned char no, action;
time_t tmp;
struct tm *ptm;
int i, Rcvlen;
printf("%s : Proc_ReqEvents\n", localProcName);
tmp = time(NULL);
ptm = (struct tm *)localtime(&tmp);
year = ptm->tm_year;
month = ptm->tm_mon;
day = ptm->tm_mday;
Rcvlen = RecvDef.Buf[1];
no = RecvDef.Buf[11];
action = RecvDef.Buf[12] & 0x03;
for (i=0; Protect3Event[i].type > 0; i++)
if (Protect3Event[i].addr == addr &&Protect3Event[i].type==RecvDef.Buf[10] && Protect3Event[i].index==no) break;
if(Protect3Event[i].type <= 0) return;
printf("%s : type=%d index=%d action=%d\n", localProcName, Protect3Event[i].type, Protect3Event[i].index, action);
//if (action == 1)
// sprintf(pStr,"%s%s(通讯)", relay103[addr-1], Protect3Event[i].text1);
//else
// if(action == 2)
// sprintf(pStr, "%s%s(通讯)", relay103[addr-1], Protect3Event[i].text);
// else return;
if((action!=1)||(action!=2))
return ;
printf("--------------Rcvlen=%d-------------------\n",Rcvlen);
if(RecvDef.Buf[5] == pIECDEF[addr].Occno && RecvDef.Buf[8] == M_COT_SPN &&
( RecvDef.Buf[10] == 0xc2 || RecvDef.Buf[10] == 0xc6 || RecvDef.Buf[10] == 0xd2 ||
RecvDef.Buf[10] == 0xf2 || RecvDef.Buf[10] == 0xb2 || RecvDef.Buf[10] == 0xf8 ||
RecvDef.Buf[10] == 0xe2 || RecvDef.Buf[10] == 0xe6 || RecvDef.Buf[10] == 0x02 ||
RecvDef.Buf[10] == 0x01 || RecvDef.Buf[10] == 0xb8 || RecvDef.Buf[10] == 0xd3 ||
RecvDef.Buf[10] == 0xd4|| RecvDef.Buf[10] == 0xd5 || RecvDef.Buf[10] == 0xd6
)) {
if (RecvDef.Buf[6] == ASDU_1 && Rcvlen == 14) {
hour = RecvDef.Buf[16] & 0x1f;
minute = RecvDef.Buf[15] & 0x3f;
second = (RecvDef.Buf[14]*256 + RecvDef.Buf[13]) / 1000;
ms = ((RecvDef.Buf[14]*256 + RecvDef.Buf[13]) % 1000) * 10;
seconds=second + ms/10000;
}
if (RecvDef.Buf[6] == ASDU_2 && Rcvlen == 18) {
hour = RecvDef.Buf[20] & 0x1f;
minute = RecvDef.Buf[19] & 0x3f;
second = (RecvDef.Buf[18]*256 + RecvDef.Buf[17]) / 1000;
ms = (((RecvDef.Buf[18]-RecvDef.Buf[14])*256 + (RecvDef.Buf[17]-RecvDef.Buf[13])) % 1000) * 10;
seconds=second + ms/10000;
}
if (action == 1)
sprintf(pStr,"%s%s,动作时间:%d时%d分%f秒", relay103[addr-1], Protect3Event[i].text1,hour,minute,seconds);
else
if(action == 2)
sprintf(pStr, "%s%s,动作时间:%d时%d分%f秒", relay103[addr-1], Protect3Event[i].text,hour,minute,seconds);
//else return ;
printf("%s %d-%d-%d-%d-%d-%d-%d %d %d\n", pStr,year,month,day,hour,minute,second,ms/10,locationInfo.plant,locationInfo.lcu);
Self_Write_Log(pStr, ALM_RELAY_LOG, 1, 1, year, month, day, hour, minute, second, ms/10, locationInfo.plant, locationInfo.lcu);
}
}
程序如上:有两个地方存在疑虑,首先程序执行时打印出来的action等于1的时候却在
if((action!=1)||(action!=2))
return ;
return了.然后我放在后面返回//else return ;程序就能执行下去了;
其次我的seconds是定义的实型的,但是运算出来的结果却是小数点后全是六个0,比如,27.000000