标题:电力系统103的通信程序
只看楼主
lemonyoung
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-9
结帖率:100%
已结贴  问题点数:20 回复次数:3 
电力系统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

搜索更多相关主题的帖子: 电力 系统 通信 
2010-04-09 15:50
秀痘魔导士
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:250
专家分:1150
注 册:2009-12-23
得分:20 
if((action!=1)&&(action!=2))   
     return ;
等于1的时候后半句为真,当然return了。

float  seconds;

哪里是int型的?
2010-04-09 16:13
lemonyoung
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-4-9
得分:0 
非常感谢,好幼稚的一个错误啊!其次那个seconds还是没有弄清楚啊,seconds=second + ms/10000;其中seconds是实型的,second和ms都是short类型的,运算出来的seconds却是小数点后全是0,不过不一定是这个原因了,因为我们的字符指针pStr也许真的不认
2010-04-13 09:25
秀痘魔导士
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:250
专家分:1150
注 册:2009-12-23
得分:0 
以下是引用lemonyoung在2010-4-13 09:25:57的发言:

非常感谢,好幼稚的一个错误啊!其次那个seconds还是没有弄清楚啊,seconds=second + ms/10000;其中seconds是实型的,second和ms都是short类型的,运算出来的seconds却是小数点后全是0,不过不一定是这个原因了,因为我们的字符指针pStr也许真的不认
seconds=second + ms/10000.0
2010-04-13 09:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-302333-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.166779 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved