diff --git a/portconfig.ini b/portconfig.ini index 7df0424..1738cbf 100644 --- a/portconfig.ini +++ b/portconfig.ini @@ -188,9 +188,9 @@ CheckTime=NO [Port18] Protocol=buban104 NetCommMode=TCP,Server -NetPort=50105 +NetPort=50104 NetCommAddr=10.142.247.14 -AiNum=128 +AiNum=65500 DiNum=256 PiNum=64 Retry=1 @@ -204,7 +204,7 @@ CheckTime=UP 总召唤电度数据=120.00 召唤初始化数据=300.00 帧序应答=20.00 -超时时间=3.00 +超时时间=300.00 转发返校超时时间=0.00 转发是否要求应答=0 超时发送测试帧=0 diff --git a/src/buban104.cpp b/src/buban104.cpp index fddfd0a..9ea1de2 100644 --- a/src/buban104.cpp +++ b/src/buban104.cpp @@ -43,7 +43,7 @@ const char *gpStrBuban104Cmd[BUBAN104_TIMER_CMD_NUM] = 组织结构:链路(间隔)+装置 */ const char *gpStrBuban104ConfigInfo[] = -{ +{ " ; ***** 部颁104规约参数定义 *****", " ", " ; 所有命令召唤周期均以秒为单位,可以为xx.xxx秒。", @@ -69,7 +69,7 @@ const char *gpStrBuban104ConfigInfo[] = " ;以上信息体地址可以配置,缺省值为97版部颁104所规定值", " ", " 帧序应答尺寸=2", - " ", + " ", " 版本号 = 1", " ;=0 是buban104(缺省值); =1 是IEC_870_5_104规约", " 发布时间=2000", @@ -92,53 +92,53 @@ void Buban104ReadConfig(int commid) pBUBAN104PORTPARAM pPortParam; #ifdef OS_LINUX - strcpy(szPortConfig, "portconfig.ini"); + strcpy(szPortConfig, "portconfig.ini"); #else - //GetCurrentDirectory(sizeof(szDir), szDir); + //GetCurrentDirectory(sizeof(szDir), szDir); sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath); #endif SioParam[commid].ExtInfo = HEAP_MALLOC(sizeof(BUBAN104PORTPARAM)); - if(!SioParam[commid].ExtInfo) + if (!SioParam[commid].ExtInfo) { - sprintf(szbuf, "WARN(%04d): commid_%02d ExtInfo=malloc(%d) failed.\n", + sprintf(szbuf, "WARN(%04d): commid_%02d ExtInfo=malloc(%d) failed.\n", _getpid(), commid, sizeof(BUBAN104PORTPARAM)); DebugPrint(szbuf); return; } - memset(SioParam[commid].ExtInfo, 0, sizeof(BUBAN104PORTPARAM)); + memset(SioParam[commid].ExtInfo, 0, sizeof(BUBAN104PORTPARAM)); pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; /* 只有在SioParam[commid].m_psBaoHu非空时,才会运行到这里 */ pPortParam->m_psBaoHu = SioParam[commid].m_psBaoHu; - sprintf(szSection, "Port%d", commid+1); + sprintf(szSection, "Port%d", commid + 1); - if(GetPrivateProString(szSection, "站地址", "0", szbuf, 120, szPortConfig) > 0) + if (GetPrivateProString(szSection, "站地址", "0", szbuf, 120, szPortConfig) > 0) { pPortParam->wLinkAddr = atoi(szbuf); } // 轮询指令配置 - for(i=0; iCmdTime[i].CmdTimerConst = (long)(atof(szbuf)*1000/TIMER_CNT); - if(pPortParam->CmdTime[i].CmdTimerConst > 5) + pPortParam->CmdTime[i].CmdTimerConst = (long)(atof(szbuf) * 1000 / TIMER_CNT); + if (pPortParam->CmdTime[i].CmdTimerConst > 5) { pPortParam->CmdTime[i].CmdTimerCnt = pPortParam->CmdTime[i].CmdTimerConst - 5; } } - if(GetPrivateProString(szSection, "超时时间", "20.0", szbuf, 120, szPortConfig) > 0) + if (GetPrivateProString(szSection, "超时时间", "20.0", szbuf, 120, szPortConfig) > 0) { - pPortParam->lTimeOutConst = (long)(atof(szbuf)*1000/TIMER_CNT); + pPortParam->lTimeOutConst = (long)(atof(szbuf) * 1000 / TIMER_CNT); } pPortParam->ProvAckOrNot = GetPrivateProInt(szSection, "转发是否要求应答", 0, szPortConfig); - if(pPortParam->ProvAckOrNot > 0) + if (pPortParam->ProvAckOrNot > 0) { pPortParam->ProvAckOrNot = 1; } @@ -150,11 +150,11 @@ void Buban104ReadConfig(int commid) // wen 2005.10.28 修改超时时是否发送测试报文 pPortParam->lTimeOutSendTest = GetPrivateProInt(szSection, "超时发送测试帧", 0, szPortConfig); - if(GetPrivateProString(szSection, "遥控方式", "0", szbuf, 120, szPortConfig) > 0) + if (GetPrivateProString(szSection, "遥控方式", "0", szbuf, 120, szPortConfig) > 0) { pPortParam->YkMode = atoi(szbuf); } - + pPortParam->iAiBaseAddr = GetPrivateProInt(szSection, "遥测信息体起始地址", INFO_AI_BASEADDR, szPortConfig); pPortParam->iDiBaseAddr = GetPrivateProInt(szSection, "遥信信息体起始地址", INFO_DI_BASEADDR, szPortConfig); pPortParam->iPiBaseAddr = GetPrivateProInt(szSection, "遥脉信息体起始地址", INFO_PI_BASEADDR, szPortConfig); @@ -165,8 +165,8 @@ void Buban104ReadConfig(int commid) pPortParam->RtuVersion = GetPrivateProInt(szSection, "版本号", 0, szPortConfig); pPortParam->m_iPublishYear = GetPrivateProInt(szSection, "发布时间", 2000, szPortConfig); - pPortParam->m_bProvAiType = GetPrivateProInt(szSection, "转发遥测类型标识", 13, szPortConfig); - + pPortParam->m_bProvAiType = GetPrivateProInt(szSection, "转发遥测类型标识", 13, szPortConfig); + InitBuban104CommandBuffer(commid); } // @@ -185,105 +185,105 @@ void Buban104RecvData(int commid, u_char *buf, int len)// 规约读数据处理 char szbuf[256]; #endif - if(!IsExtInfoPtr(commid)) + if (!IsExtInfoPtr(commid)) return; - + pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; printf("recvbuf: "); for (i = 0; i < len; i++) printf("%02X ", buf[i]); printf("\n"); - for(i=0; im_psBaoHu->m_iRevStatus) + switch (pPortParam->m_psBaoHu->m_iRevStatus) { - case 0:// 0x10 / 0x68 - pPortParam->m_iRecvLen = 0; - if(buf[i] == 0x68) - { - pPortParam->m_psBaoHu->m_iRevStatus++; - pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; - } - else - { - pPortParam->m_psBaoHu->m_iRevStatus = 100; - pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; - } - break; - case 1:// length + case 0:// 0x10 / 0x68 + pPortParam->m_iRecvLen = 0; + if (buf[i] == 0x68) + { + pPortParam->m_psBaoHu->m_iRevStatus++; pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; - pPortParam->m_psBaoHu->m_iNeedRevLength = buf[i]; - if(pPortParam->m_psBaoHu->m_iNeedRevLength <= 0) - { - pPortParam->m_psBaoHu->m_iRevStatus = 100; - } - else - { - pPortParam->m_psBaoHu->m_iRevStatus++; - } - break; - case 2:// 正确接收数据 - pPortParam->m_psBaoHu->m_iNeedRevLength--; + } + else + { + pPortParam->m_psBaoHu->m_iRevStatus = 100; pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; - if(pPortParam->m_psBaoHu->m_iNeedRevLength > 0) - break; + } + break; + case 1:// length + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + pPortParam->m_psBaoHu->m_iNeedRevLength = buf[i]; + if (pPortParam->m_psBaoHu->m_iNeedRevLength <= 0) + { + pPortParam->m_psBaoHu->m_iRevStatus = 100; + } + else + { + pPortParam->m_psBaoHu->m_iRevStatus++; + } + break; + case 2:// 正确接收数据 + pPortParam->m_psBaoHu->m_iNeedRevLength--; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + if (pPortParam->m_psBaoHu->m_iNeedRevLength > 0) + break; - Buban104ProcessData(commid, pPortParam, TRUE); - pPortParam->m_psBaoHu->m_iRevStatus = 0; - pPortParam->m_psBaoHu->RevCmdFlag = 1; + Buban104ProcessData(commid, pPortParam, TRUE); + pPortParam->m_psBaoHu->m_iRevStatus = 0; + pPortParam->m_psBaoHu->RevCmdFlag = 1; +#ifdef _WIN32 + if ((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + //pPortParam->LinkOkCnt = 0; + break; + case 100:// 错误接收数据 + default: + if (buf[i] == 0x68) + { #ifdef _WIN32 - if((GetCurPort() == commid) && IsRealDataDisp()) + // wen 2004.11.22 增加显示 + if ((GetCurPort() == commid) && IsRealDataDisp()) { - WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); } #endif - //pPortParam->LinkOkCnt = 0; - break; - case 100:// 错误接收数据 - default: - if(buf[i] == 0x68) + Buban104ProcessData(commid, pPortParam, FALSE); + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + pPortParam->m_psBaoHu->m_iRevStatus = 1; + pPortParam->m_iRecvLen = 1; + pPortParam->m_au8RecvBuf[0] = buf[i]; + } + else + { + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + if (pPortParam->m_iRecvLen > 200) { #ifdef _WIN32 // wen 2004.11.22 增加显示 - if((GetCurPort() == commid) && IsRealDataDisp()) + if ((GetCurPort() == commid) && IsRealDataDisp()) { - WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); } #endif Buban104ProcessData(commid, pPortParam, FALSE); SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; - pPortParam->m_psBaoHu->m_iRevStatus = 1; - pPortParam->m_iRecvLen = 1; - pPortParam->m_au8RecvBuf[0] = buf[i]; + pPortParam->m_iRecvLen = 0; } - else - { - pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; - if(pPortParam->m_iRecvLen > 200) - { -#ifdef _WIN32 - // wen 2004.11.22 增加显示 - if((GetCurPort() == commid) && IsRealDataDisp()) - { - WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, - (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); - } -#endif - Buban104ProcessData(commid, pPortParam, FALSE); - SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; - pPortParam->m_iRecvLen = 0; - } - } - break; + } + break; } } #ifdef _DEBUG_MSG_ - sprintf(szbuf, "wen: commid = %d, send=%d, recv=%d, error=%d, lost=%d\n", commid, - SioParam[commid].SendCharNum, SioParam[commid].RecvCharNum, + sprintf(szbuf, "wen: commid = %d, send=%d, recv=%d, error=%d, lost=%d\n", commid, + SioParam[commid].SendCharNum, SioParam[commid].RecvCharNum, SioParam[commid].ErrMsgNum, SioParam[commid].LostSyncCnt); DebugPrint(szbuf); #endif @@ -297,20 +297,20 @@ void Buban104Timer(int commid) { BUBAN104PORTPARAM *pPortParam; - if(IsExtInfoPtr(commid) == FALSE) + if (IsExtInfoPtr(commid) == FALSE) { return; } pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; - if(pPortParam->LinkOk) + if (pPortParam->LinkOk) { // 超时计数 pPortParam->lTimeOutCnt++; } // 如果为转发端口,则不进行轮询指令的生成。 - if(PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) + if (PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) { Buban104FindNextCmd(commid); } @@ -318,7 +318,7 @@ void Buban104Timer(int commid) { Buban104FindNextProvCmd(commid); } - + Buban104SendCmdFormPollCmdBuf(commid); } @@ -348,17 +348,17 @@ void Buban104YkYtProcess(int commid, u_char *buf, int len) // 遥控遥调处 // 在转发遥控数据点中,只保留了要转发的控点号,实际的端口号应该是该转发点的端口 // 该转发点并没有指定虚拟的转发控点,则控点和转发点的点号一致。 - if(IsExtInfoPtr(commid) == FALSE) + if (IsExtInfoPtr(commid) == FALSE) { return; } iDirect = buf[9] & 0x80; - portno = buf[0]+buf[1]*256+buf[2]*65536+buf[3]*16777216; - ykytpnt = buf[4]+buf[5]*256+buf[6]*65536+buf[7]*16777216; + portno = buf[0] + buf[1] * 256 + buf[2] * 65536 + buf[3] * 16777216; + ykytpnt = buf[4] + buf[5] * 256 + buf[6] * 65536 + buf[7] * 16777216; // 返校信息(反馈信号) - if(iDirect) + if (iDirect) { Buban104ProvMakeYkYtCommand(commid, buf, len); } @@ -376,21 +376,21 @@ void Buban104SendSystemTime(int commid) // 系统对时 { BUBAN104PORTPARAM *pPortParam; - if(IsExtInfoPtr(commid) == FALSE) + if (IsExtInfoPtr(commid) == FALSE) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - - if(2 != pPortParam->m_psBaoHu->CheckTime) + + if (2 != pPortParam->m_psBaoHu->CheckTime) { return; } - if(pPortParam->Initdata) + if (pPortParam->Initdata) { - if(PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) + if (PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) { MakeBuban104Command(commid, RTU_TIME); } @@ -425,7 +425,7 @@ void InitBuban104CommandBuffer(int commid) pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; pPortParam->LinkOk = false; - + // wen 2005.09.15 将该标识修改为true后, // 在主站下发总召命令和总召电度后,会将其标识置为false; // 而子站端不会受此标识的影响,标识为false,不下发数据。 @@ -439,7 +439,7 @@ void InitBuban104CommandBuffer(int commid) pPortParam->wRecvSequence = 0; pPortParam->wSendSequence = 0; pPortParam->wAckSequence = 0; - pPortParam->lTimeOutCnt = 0; + pPortParam->lTimeOutCnt = 0; ClearAllCmdFromPollCmdBuf(commid); } @@ -470,43 +470,43 @@ void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len) // 该转发点并没有指定虚拟的转发控点,则控点和转发点的点号一致。 int ykpoint, iLen; - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; BOOL bHaveOrder = FALSE; BUBAN104PORTPARAM *pPortParam; - if(IsExtInfoPtr(commid) == FALSE) + if (IsExtInfoPtr(commid) == FALSE) { return; } - if((buf[9] & 0x80) == 0) + if ((buf[9] & 0x80) == 0) { return; } pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; - - memset( (char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN ); - - ykpoint = buf[4]+buf[5]*256+buf[6]*65536+buf[7]*16777216; + + memset((char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN); + + ykpoint = buf[4] + buf[5] * 256 + buf[6] * 65536 + buf[7] * 16777216; ykpoint += pPortParam->iYkBaseAddr - 1; commandbuf[0] = 0x68; commandbuf[1] = 14; - switch(pPortParam->YkMode) - { - case CONTROL_SINGAL: // 单点控制 - commandbuf[6] = 45; - break; - case CONTROL_DOUBLE: // 双点控制 - case CONTROL_DIRECT: // 直接控制 - commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; - break; + switch (pPortParam->YkMode) + { + case CONTROL_SINGAL: // 单点控制 + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // 双点控制 + case CONTROL_DIRECT: // 直接控制 + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; } commandbuf[7] = 1; //commandbuf[8] 传送原因 iLen = 9; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = LOBYTE(LOWORD(ykpoint)); @@ -521,43 +521,43 @@ void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len) commandbuf[iLen++] = HIBYTE(LOWORD(ykpoint)); commandbuf[iLen++] = LOBYTE(HIWORD(ykpoint)); } - - switch(buf[8]) - { - case 1: - case 4: // 选择 - bHaveOrder = TRUE; - commandbuf[8] = 7; - commandbuf[iLen] = 0xfc; - break; - - case 2: - case 5: // 执行 - bHaveOrder = TRUE; - commandbuf[8] = 7; - commandbuf[iLen] = 0x7c; - break; - - case 3: - case 6: - bHaveOrder = TRUE; - commandbuf[8] = 9; - commandbuf[iLen] = 0xfc; - break; + + switch (buf[8]) + { + case 1: + case 4: // 选择 + bHaveOrder = TRUE; + commandbuf[8] = 7; + commandbuf[iLen] = 0xfc; + break; + + case 2: + case 5: // 执行 + bHaveOrder = TRUE; + commandbuf[8] = 7; + commandbuf[iLen] = 0x7c; + break; + + case 3: + case 6: + bHaveOrder = TRUE; + commandbuf[8] = 9; + commandbuf[iLen] = 0xfc; + break; } - if( bHaveOrder ) + if (bHaveOrder) { - if((buf[9] & 0x03) == 0x03) + if ((buf[9] & 0x03) == 0x03) { commandbuf[8] |= 0x40; } else { // 控分还是控合 - if((buf[9] & 0x03) == 0x01)// 控合 + if ((buf[9] & 0x03) == 0x01)// 控合 { - if(CONTROL_SINGAL == pPortParam->YkMode) + if (CONTROL_SINGAL == pPortParam->YkMode) { commandbuf[iLen++] |= 1; } @@ -568,7 +568,7 @@ void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len) } else// 控分 { - if(CONTROL_SINGAL != pPortParam->YkMode) + if (CONTROL_SINGAL != pPortParam->YkMode) { commandbuf[iLen++] |= 1; } @@ -578,9 +578,9 @@ void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len) PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); } - if(ShmGetDispYkYtFlag()) + if (ShmGetDispYkYtFlag()) { - printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", _getpid(), commid, ykpoint, (buf[9] & 0x7F)); } } @@ -598,30 +598,68 @@ void MakeBuban104Command(u_32 commid, u_char cmdidx) char commandbuf[MAX_POLLCMD_BUF_LEN]; BUBAN104PORTPARAM *pPortParam; - memset( commandbuf, 0, sizeof( commandbuf ) ); + memset(commandbuf, 0, sizeof(commandbuf)); pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; iLen = 0; - switch ( cmdidx ) - { + switch (cmdidx) + { // format-i - case RTU_TIME: // 时间同步 - GetLocalTimeEx(&sCurTime); + case RTU_TIME: // 时间同步 + GetLocalTimeEx(&sCurTime); + commandbuf[0] = 0x68; + iLen = 6; + commandbuf[iLen++] = 103; + commandbuf[iLen++] = 1; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + else + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + sCurTime.mSec = sCurTime.Sec * 1000 + sCurTime.mSec; + commandbuf[iLen++] = sCurTime.mSec % 256; + commandbuf[iLen++] = sCurTime.mSec / 256; + commandbuf[iLen++] = (u_char)sCurTime.Min; + commandbuf[iLen++] = (u_char)sCurTime.Hour; + commandbuf[iLen++] = (u_char)sCurTime.Day; + commandbuf[iLen++] = (u_char)sCurTime.Month; + commandbuf[iLen++] = (u_char)(sCurTime.Year % 100); + commandbuf[1] = (BYTE)(iLen - 2); + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); + break; + + case ASK_DI_DATA: // 召唤2级数据YX + for (i = 0; i < (pPortParam->m_psBaoHu->DiNum + MAX_GROUP_DINUM - 1) / MAX_GROUP_DINUM; i++) + { commandbuf[0] = 0x68; + //commandbuf[1] = 14; iLen = 6; - commandbuf[iLen++] = 103; - commandbuf[iLen++] = 1; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + commandbuf[iLen++] = 100; + commandbuf[iLen++] = 0; + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - commandbuf[iLen++] = 6; + commandbuf[iLen++] = 5; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; + } else { - commandbuf[iLen++] = 6; + commandbuf[iLen++] = 5; commandbuf[iLen++] = 0; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); @@ -629,129 +667,30 @@ void MakeBuban104Command(u_32 commid, u_char cmdidx) commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; } - sCurTime.mSec = sCurTime.Sec * 1000 + sCurTime.mSec; - commandbuf[iLen++] = sCurTime.mSec % 256; - commandbuf[iLen++] = sCurTime.mSec / 256; - commandbuf[iLen++] = (u_char)sCurTime.Min; - commandbuf[iLen++] = (u_char)sCurTime.Hour; - commandbuf[iLen++] = (u_char)sCurTime.Day; - commandbuf[iLen++] = (u_char)sCurTime.Month; - commandbuf[iLen++] = (u_char)(sCurTime.Year%100); + commandbuf[iLen++] = 21 + i; commandbuf[1] = (BYTE)(iLen - 2); - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); - break; - - case ASK_DI_DATA: // 召唤2级数据YX - for ( i = 0; i < (pPortParam->m_psBaoHu->DiNum+MAX_GROUP_DINUM-1)/MAX_GROUP_DINUM; i++) - { - commandbuf[0] = 0x68; - //commandbuf[1] = 14; - iLen = 6; - commandbuf[iLen++] = 100; - commandbuf[iLen++] = 0; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = 5; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - - } - else - { - commandbuf[iLen++] = 5; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - commandbuf[iLen++] = 21 + i; - commandbuf[1] = (BYTE)(iLen - 2); - PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); - } - break; - - case ASK_AI_DATA: // 召唤2级数据YC - for ( i = 0; i < (pPortParam->m_psBaoHu->AiNum+MAX_GROUP_AINUM-1)/MAX_GROUP_AINUM; i++) - { - commandbuf[0] = 0x68; - //commandbuf[1] = 14; - iLen = 6; - commandbuf[iLen++] = 100; - commandbuf[iLen++] = 0; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = 5; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - else - { - commandbuf[iLen++] = 5; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - commandbuf[iLen++] = 29 + i; - commandbuf[1] = (BYTE)(iLen - 2); - PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); - } - break; - - case ASK_PI_DATA: // 召唤2级数据YM - for ( i = 0; i < (pPortParam->m_psBaoHu->PiNum+MAX_GROUP_PINUM-1)/MAX_GROUP_PINUM; i++) - { - commandbuf[0] = 0x68; - //commandbuf[1] = 14; - iLen = 6; - commandbuf[iLen++] = 101; - commandbuf[iLen++] = 0; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = 6; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - else - { - commandbuf[iLen++] = 6; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - commandbuf[iLen++] = 2 + i; - commandbuf[1] = (BYTE)(iLen - 2); - PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); - } - break; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); + } + break; - case ASK_PI: //召唤电度量 + case ASK_AI_DATA: // 召唤2级数据YC + for (i = 0; i < (pPortParam->m_psBaoHu->AiNum + MAX_GROUP_AINUM - 1) / MAX_GROUP_AINUM; i++) + { commandbuf[0] = 0x68; //commandbuf[1] = 14; iLen = 6; - commandbuf[iLen++] = 101; - commandbuf[iLen++] = 1; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + commandbuf[iLen++] = 100; + commandbuf[iLen++] = 0; + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - commandbuf[iLen++] = 6; + commandbuf[iLen++] = 5; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; - } else { - commandbuf[iLen++] = 6; + commandbuf[iLen++] = 5; commandbuf[iLen++] = 0; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); @@ -759,28 +698,21 @@ void MakeBuban104Command(u_32 commid, u_char cmdidx) commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; } - // wen 2006.04.03 发布时间97版和2000版组分配不同 - if(pPortParam->m_iPublishYear == 1997) - { - commandbuf[iLen++] = 0x41; - } - else - { - commandbuf[iLen++] = 0x45; - } - + commandbuf[iLen++] = 29 + i; commandbuf[1] = (BYTE)(iLen - 2); PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); - pPortParam->Initdata = false; - break; + } + break; - case ASK_ALL_DATA:// 召唤初始化数据 + case ASK_PI_DATA: // 召唤2级数据YM + for (i = 0; i < (pPortParam->m_psBaoHu->PiNum + MAX_GROUP_PINUM - 1) / MAX_GROUP_PINUM; i++) + { commandbuf[0] = 0x68; //commandbuf[1] = 14; iLen = 6; - commandbuf[iLen++] = 100; - commandbuf[iLen++] = 1; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + commandbuf[iLen++] = 101; + commandbuf[iLen++] = 0; + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLen++] = 6; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); @@ -797,96 +729,164 @@ void MakeBuban104Command(u_32 commid, u_char cmdidx) commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; } - commandbuf[iLen++] = 20; + commandbuf[iLen++] = 2 + i; commandbuf[1] = (BYTE)(iLen - 2); - PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); - pPortParam->Initdata = false; - break; - - // format-s - case FORMAT_S: // S-格式 - // wen 2005.09.21 如果缓冲区内有数据,则不生成S帧 - if(CheckPollCmdBufEmpty(commid) <= 0) - { - break; - } - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x01; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); - break; - - // format-u - case FORMAT_U_START_ACT: // U-格式启动 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x07; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); - break; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); + } + break; - case FORMAT_U_START_CON: // U-格式启动应答 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x0b; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); - break; + case ASK_PI: //召唤电度量 + commandbuf[0] = 0x68; + //commandbuf[1] = 14; + iLen = 6; + commandbuf[iLen++] = 101; + commandbuf[iLen++] = 1; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; - case FORMAT_U_STOP_ACT: // U-格式停止 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x13; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); - break; + } + else + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + // wen 2006.04.03 发布时间97版和2000版组分配不同 + if (pPortParam->m_iPublishYear == 1997) + { + commandbuf[iLen++] = 0x41; + } + else + { + commandbuf[iLen++] = 0x45; + } - case FORMAT_U_STOP_CON: // U-格式停止应答 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x23; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); - break; + commandbuf[1] = (BYTE)(iLen - 2); + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); + pPortParam->Initdata = false; + break; - case FORMAT_U_TEST_ACT: // U-格式测试 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = 0x43; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); - break; + case ASK_ALL_DATA:// 召唤初始化数据 + commandbuf[0] = 0x68; + //commandbuf[1] = 14; + iLen = 6; + commandbuf[iLen++] = 100; + commandbuf[iLen++] = 1; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + else + { + commandbuf[iLen++] = 6; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + commandbuf[iLen++] = 20; + commandbuf[1] = (BYTE)(iLen - 2); + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, iLen); + pPortParam->Initdata = false; + break; - case FORMAT_U_TEST_CON: // U-格式测试应答 - commandbuf[iLen++] = 0x68; - commandbuf[iLen++] = 4; - commandbuf[iLen++] = (char)0x83; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - commandbuf[iLen++] = 0x00; - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); + // format-s + case FORMAT_S: // S-格式 + // wen 2005.09.21 如果缓冲区内有数据,则不生成S帧 + if (CheckPollCmdBufEmpty(commid) <= 0) + { break; + } + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x01; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); + break; - default: - break; - } + // format-u + case FORMAT_U_START_ACT: // U-格式启动 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x07; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); + break; + + case FORMAT_U_START_CON: // U-格式启动应答 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x0b; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); + break; + + case FORMAT_U_STOP_ACT: // U-格式停止 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x13; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); + break; + + case FORMAT_U_STOP_CON: // U-格式停止应答 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x23; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); + break; + + case FORMAT_U_TEST_ACT: // U-格式测试 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = 0x43; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, iLen); + break; + + case FORMAT_U_TEST_CON: // U-格式测试应答 + commandbuf[iLen++] = 0x68; + commandbuf[iLen++] = 4; + commandbuf[iLen++] = (char)0x83; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + commandbuf[iLen++] = 0x00; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, iLen); + break; + + default: + break; + } } //生成遥控遥调指令 -void MakeBuBan104YkYtCommand( u_32 commid, u_char *buf, int len ) +void MakeBuBan104YkYtCommand(u_32 commid, u_char *buf, int len) { // buf[0] --- 端口号(=commid) // buf[1] @@ -904,164 +904,164 @@ void MakeBuBan104YkYtCommand( u_32 commid, u_char *buf, int len ) // 该转发点并没有指定虚拟的转发控点,则控点和转发点的点号一致。 int ykpoint, iLen; - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; static int iYkStatus = 0; BUBAN104PORTPARAM *pPortParam; pPortParam = (pBUBAN104PORTPARAM)SioParam[commid].ExtInfo; - - memset( (char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN ); - - ykpoint = buf[4]+buf[5]*256+buf[6]*65536+buf[7]*16777216; + + memset((char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN); + + ykpoint = buf[4] + buf[5] * 256 + buf[6] * 65536 + buf[7] * 16777216; ykpoint += pPortParam->iYkBaseAddr - 1; iLen = 9; - switch(buf[8]) - { - case 1: - case 4: // 选择 - commandbuf[0] = 0x68; - commandbuf[1] = 14; - switch(pPortParam->YkMode) - { - case CONTROL_SINGAL: // 单点控制 - commandbuf[6] = 45; - break; - case CONTROL_DOUBLE: // 双点控制 - case CONTROL_DIRECT: // 直接控制 - commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; - break; - } - commandbuf[7] = 1; - commandbuf[8] = 6; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); - } - else - { - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - - // wen 2002.11.18 字节顺序修改 - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); - commandbuf[iLen++] = 0; - } - - if(buf[9] == 1) + switch (buf[8]) + { + case 1: + case 4: // 选择 + commandbuf[0] = 0x68; + commandbuf[1] = 14; + switch (pPortParam->YkMode) + { + case CONTROL_SINGAL: // 单点控制 + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // 双点控制 + case CONTROL_DIRECT: // 直接控制 + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; + } + commandbuf[7] = 1; + commandbuf[8] = 6; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + } + else + { + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); + + // wen 2002.11.18 字节顺序修改 + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + commandbuf[iLen++] = 0; + } + + if (buf[9] == 1) + { + if (CONTROL_SINGAL == pPortParam->YkMode) { - if(CONTROL_SINGAL == pPortParam->YkMode) - { - iYkStatus = 1; - } - else - { - iYkStatus = 2; - } + iYkStatus = 1; } else { - if(CONTROL_SINGAL == pPortParam->YkMode) - { - iYkStatus = 0; - } - else - { - iYkStatus = 1; - } - } - commandbuf[iLen++] = (BYTE)(0xfc + iYkStatus); - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); - break; - - case 2: - case 5: // 执行 - commandbuf[0] = 0x68; - commandbuf[1] = 14; - switch(pPortParam->YkMode) - { - case CONTROL_SINGAL: // 单点控制 - commandbuf[6] = 45; - break; - case CONTROL_DOUBLE: // 双点控制 - case CONTROL_DIRECT: // 直接控制 - commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; - break; + iYkStatus = 2; } - commandbuf[7] = 1; - commandbuf[8] = 6; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + } + else + { + if (CONTROL_SINGAL == pPortParam->YkMode) { - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - // wen 2002.11.18 字节顺序修改 - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); + iYkStatus = 0; } else { - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - - // wen 2002.11.18 字节顺序修改 - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); - commandbuf[iLen++] = 0; + iYkStatus = 1; } + } + commandbuf[iLen++] = (BYTE)(0xfc + iYkStatus); + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); + break; - commandbuf[iLen++] = 0x7c + iYkStatus; - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); + case 2: + case 5: // 执行 + commandbuf[0] = 0x68; + commandbuf[1] = 14; + switch (pPortParam->YkMode) + { + case CONTROL_SINGAL: // 单点控制 + commandbuf[6] = 45; break; - - case 3: - case 6: - commandbuf[0] = 0x68; - commandbuf[1] = 14; - switch(pPortParam->YkMode) - { - case CONTROL_SINGAL: // 单点控制 - commandbuf[6] = 45; - break; - case CONTROL_DOUBLE: // 双点控制 - case CONTROL_DIRECT: // 直接控制 - commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; - break; - } - commandbuf[7] = 1; - commandbuf[8] = 8; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - - // wen 2002.11.18 字节顺序修改 - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); - } - else - { - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - - // wen 2002.11.18 字节顺序修改 - commandbuf[iLen++] = (char)(ykpoint & 0x00ff); - commandbuf[iLen++] = (char)((ykpoint & 0xff00)>>8); - commandbuf[iLen++] = 0; - } + case CONTROL_DOUBLE: // 双点控制 + case CONTROL_DIRECT: // 直接控制 + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; + } + commandbuf[7] = 1; + commandbuf[8] = 6; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + // wen 2002.11.18 字节顺序修改 + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + } + else + { + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0xfc + iYkStatus; - PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); + // wen 2002.11.18 字节顺序修改 + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + commandbuf[iLen++] = 0; + } + + commandbuf[iLen++] = 0x7c + iYkStatus; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); + break; + + case 3: + case 6: + commandbuf[0] = 0x68; + commandbuf[1] = 14; + switch (pPortParam->YkMode) + { + case CONTROL_SINGAL: // 单点控制 + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // 双点控制 + case CONTROL_DIRECT: // 直接控制 + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; break; + } + commandbuf[7] = 1; + commandbuf[8] = 8; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + + // wen 2002.11.18 字节顺序修改 + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + } + else + { + commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); + + // wen 2002.11.18 字节顺序修改 + commandbuf[iLen++] = (char)(ykpoint & 0x00ff); + commandbuf[iLen++] = (char)((ykpoint & 0xff00) >> 8); + commandbuf[iLen++] = 0; + } + + commandbuf[iLen++] = 0xfc + iYkStatus; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); + break; } - if(ShmGetDispYkYtFlag()) + if (ShmGetDispYkYtFlag()) { #ifdef _WIN32 - printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", _getpid(), commid, ykpoint, (buf[9] & 0x7F)); #else printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", @@ -1080,28 +1080,28 @@ void Buban104FindNextCmd(int commid) { int i, iCurCmdIdx; BUBAN104PORTPARAM *pPortParam; - int framename[BUBAN104_TIMER_CMD_NUM] = - { - ASK_PI, - ASK_ALL_DATA, - FORMAT_S - }; + int framename[BUBAN104_TIMER_CMD_NUM] = + { + ASK_PI, + ASK_ALL_DATA, + FORMAT_S + }; - if((commid < 0) || (commid >= GetMaxPort())) + if ((commid < 0) || (commid >= GetMaxPort())) { return; } - if(!ShmGetPortFlag(commid, FLAG_OPEN)) + if (!ShmGetPortFlag(commid, FLAG_OPEN)) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(!pPortParam->LinkOk) + if (!pPortParam->LinkOk) { - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { return; } @@ -1110,55 +1110,55 @@ void Buban104FindNextCmd(int commid) return; } - for(i=0; iCmdTime[i].CmdTimerConst ) + if (pPortParam->CmdTime[i].CmdTimerConst) pPortParam->CmdTime[i].CmdTimerCnt++; } - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { return; } - + iCurCmdIdx = pPortParam->CurCmdIdx; - for ( i = 0; i < BUBAN104_TIMER_CMD_NUM; i++ ) + for (i = 0; i < BUBAN104_TIMER_CMD_NUM; i++) { - if(!pPortParam->bAckRight) + if (!pPortParam->bAckRight) { break; } // wen 2005.09.16 在初始化不成功时,不生成轮询指令 - if(!pPortParam->Initdata) + if (!pPortParam->Initdata) { break; } - iCurCmdIdx = (iCurCmdIdx+1) % BUBAN104_TIMER_CMD_NUM; - if ( (pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt - >= pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst) - && ( pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst > 0 )) - { - pPortParam->CurCmdIdx = iCurCmdIdx; - MakeBuban104Command(commid, framename[iCurCmdIdx]); - pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt = 0; - return; - } + iCurCmdIdx = (iCurCmdIdx + 1) % BUBAN104_TIMER_CMD_NUM; + if ((pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt + >= pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst) + && (pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst > 0)) + { + pPortParam->CurCmdIdx = iCurCmdIdx; + MakeBuban104Command(commid, framename[iCurCmdIdx]); + pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt = 0; + return; + } } // wen (超时情况下) - if(CheckPollCmdBufEmpty(commid) > 0) + if (CheckPollCmdBufEmpty(commid) > 0) { - if(pPortParam->lTimeOutCnt >= pPortParam->lTimeOutConst) + if (pPortParam->lTimeOutCnt >= pPortParam->lTimeOutConst) { - if(!pPortParam->bCloseSocket) + if (!pPortParam->bCloseSocket) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2005.10.28 修改超时时是否发送测试报文 //MakeBuban104Command(commid, FORMAT_S); //====================================================== - if(pPortParam->lTimeOutSendTest) + if (pPortParam->lTimeOutSendTest) { MakeBuban104Command(commid, FORMAT_U_TEST_ACT); } @@ -1183,43 +1183,43 @@ void Buban104FindNextCmd(int commid) void Buban104FindNextProvCmd(int commid) { BUBAN104PORTPARAM *pPortParam; - - if((commid < 0) || (commid >= GetMaxPort())) + + if ((commid < 0) || (commid >= GetMaxPort())) { return; } - if(!ShmGetPortFlag(commid, FLAG_OPEN)) + if (!ShmGetPortFlag(commid, FLAG_OPEN)) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(!pPortParam->LinkOk) + if (!pPortParam->LinkOk) { return; } - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { return; } - + // wen (超时情况下) - if(pPortParam->lTimeOutCnt >= pPortParam->lTimeOutConst) + if (pPortParam->lTimeOutCnt >= pPortParam->lTimeOutConst) { - if(!pPortParam->bCloseSocket) + if (!pPortParam->bCloseSocket) { - if(pPortParam->bAckRight) + if (pPortParam->bAckRight) { - if(pPortParam->Initdata) + if (pPortParam->Initdata) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2006.03.23 修改超时时是否发送测试报文 //MakeBuban104Command(commid, FORMAT_U_TEST_ACT); //====================================================== - if(pPortParam->lTimeOutSendTest) + if (pPortParam->lTimeOutSendTest) { ;//MakeBuban104Command(commid, FORMAT_U_TEST_ACT); } @@ -1240,21 +1240,21 @@ void Buban104FindNextProvCmd(int commid) InitBuban104CommandBuffer(commid); // 关闭网络端口 Buban104CloseSocket(commid); - } + } } - - if(CheckPollCmdBufEmpty(commid) <= 0) + + if (CheckPollCmdBufEmpty(commid) <= 0) { return; } - if(pPortParam->bAckRight) + if (pPortParam->bAckRight) { - if(pPortParam->Initdata) + if (pPortParam->Initdata) { // 一类数据( 遥信变位 ) //ProvBuban104SendClass1(commid); - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { pPortParam->m_lNoDataCnt = 0; return; @@ -1262,7 +1262,7 @@ void Buban104FindNextProvCmd(int commid) // 转发soe数据 //ProvBuban104SendSoe(commid); - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { pPortParam->m_lNoDataCnt = 0; return; @@ -1283,7 +1283,7 @@ void Buban104FindNextProvCmd(int commid) }*/ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - if(CheckPollCmdBufEmpty(commid) <= 0) + if (CheckPollCmdBufEmpty(commid) <= 0) { pPortParam->m_lNoDataCnt = 0; return; @@ -1298,10 +1298,10 @@ void Buban104FindNextProvCmd(int commid) // MakeBuban104Command(commid, FORMAT_U_TEST_ACT); //} //====================================================== - if(pPortParam->lTimeOutSendTest) + if (pPortParam->lTimeOutSendTest) { pPortParam->m_lNoDataCnt++; - if(pPortParam->m_lNoDataCnt >= pPortParam->lTimeOutConst) + if (pPortParam->m_lNoDataCnt >= pPortParam->lTimeOutConst) { pPortParam->m_lNoDataCnt = 0; //MakeBuban104Command(commid, FORMAT_U_TEST_ACT); @@ -1319,23 +1319,23 @@ void Buban104SendCmdFormPollCmdBuf(int commid) i_32 len; BUBAN104PORTPARAM *pPortParam; - if((commid < 0) || (commid >= GetMaxPort())) + if ((commid < 0) || (commid >= GetMaxPort())) { return; } - if(!ShmGetPortFlag(commid, FLAG_OPEN)) + if (!ShmGetPortFlag(commid, FLAG_OPEN)) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(pPortParam->m_psBaoHu->ForceWaitFlag + if (pPortParam->m_psBaoHu->ForceWaitFlag && pPortParam->m_psBaoHu->ForceWaitCnt) { pPortParam->m_psBaoHu->ForceWaitCnt--; - if(pPortParam->m_psBaoHu->ForceWaitCnt == 0) + if (pPortParam->m_psBaoHu->ForceWaitCnt == 0) { // 清除当前命令 ClearCmdFormPollCmdBuf(commid); @@ -1343,11 +1343,11 @@ void Buban104SendCmdFormPollCmdBuf(int commid) } } - if(pPortParam->m_psBaoHu->SendCmdFlag + if (pPortParam->m_psBaoHu->SendCmdFlag && (pPortParam->m_psBaoHu->RevCmdFlag == 0)) - { + { pPortParam->m_psBaoHu->RetryTimeCnt++; - if(pPortParam->m_psBaoHu->RetryTimeCnt < pPortParam->m_psBaoHu->RetryTime) + if (pPortParam->m_psBaoHu->RetryTimeCnt < pPortParam->m_psBaoHu->RetryTime) { return; } @@ -1355,7 +1355,7 @@ void Buban104SendCmdFormPollCmdBuf(int commid) pPortParam->m_psBaoHu->RetryTimeCnt = 0; pPortParam->m_psBaoHu->RetryCnt++; - if(pPortParam->m_psBaoHu->RetryCnt > pPortParam->m_psBaoHu->Retry) + if (pPortParam->m_psBaoHu->RetryCnt > pPortParam->m_psBaoHu->Retry) { // 清除当前命令 ClearCmdFormPollCmdBuf(commid); @@ -1369,13 +1369,13 @@ void Buban104SendCmdFormPollCmdBuf(int commid) } } - if(pPortParam->m_psBaoHu->SendCmdFlag + if (pPortParam->m_psBaoHu->SendCmdFlag && pPortParam->m_psBaoHu->RevCmdFlag) { // 清除当前命令 ClearCmdFormPollCmdBuf(commid); //ClearCmdAllFlag(commid); - if(pPortParam->bSendFormatI) + if (pPortParam->bSendFormatI) { //pPortParam->wSendSequence++; //pPortParam->wSendSequence %= MAX_SEQUENCE; @@ -1383,10 +1383,10 @@ void Buban104SendCmdFormPollCmdBuf(int commid) } } - if(pPortParam->m_psBaoHu->WaitTime) + if (pPortParam->m_psBaoHu->WaitTime) { pPortParam->m_psBaoHu->WaitTimeCnt++; - if(pPortParam->m_psBaoHu->WaitTimeCnt + if (pPortParam->m_psBaoHu->WaitTimeCnt < pPortParam->m_psBaoHu->WaitTime) { return; @@ -1394,7 +1394,7 @@ void Buban104SendCmdFormPollCmdBuf(int commid) } pPortParam->m_psBaoHu->WaitTimeCnt = 0; - if(pPortParam->m_psBaoHu->ReSendCmdFlag) + if (pPortParam->m_psBaoHu->ReSendCmdFlag) { len = ReGetCmdFormPollCmdBuf(commid, buf, sizeof(buf)); } @@ -1405,19 +1405,19 @@ void Buban104SendCmdFormPollCmdBuf(int commid) //pPortParam->m_psBaoHu->RetryCnt = 0; } - if(len < 3) + if (len < 3) { return; } #ifdef _WIN32 - if(isUdpSocketExist() == TRUE) + if (isUdpSocketExist() == TRUE) #endif { - if(buf[4] & 0x01 ) + if (buf[4] & 0x01) { // format_s - if((buf[4] & 0x02) == 0 ) + if ((buf[4] & 0x02) == 0) { buf[6] = LOBYTE(pPortParam->wRecvSequence << 1); buf[7] = HIBYTE(pPortParam->wRecvSequence << 1); @@ -1432,14 +1432,14 @@ void Buban104SendCmdFormPollCmdBuf(int commid) buf[6] = LOBYTE(pPortParam->wRecvSequence << 1); buf[7] = HIBYTE(pPortParam->wRecvSequence << 1); pPortParam->bSendFormatI = TRUE; - //4.bug_1.2.3_20060807_3/bug_2.0.1_20060807_4 104规约不能转发第二个端口的遥测数据 + //4.bug_1.2.3_20060807_3/bug_2.0.1_20060807_4 104规约不能转发第二个端口的遥测数据 //发送数据后应当立即将发送序号+1,而不应当在清除命令时+1 pPortParam->wSendSequence++; pPortParam->wSendSequence %= MAX_SEQUENCE; } - SendDataToPort(commid, (char *)&buf[2], len-2); - + SendDataToPort(commid, (char *)&buf[2], len - 2); + pPortParam->m_psBaoHu->SendCmdFlag = 1; pPortParam->m_psBaoHu->ReSendCmdFlag = 0; pPortParam->m_psBaoHu->RevCmdFlag = 0; @@ -1447,15 +1447,15 @@ void Buban104SendCmdFormPollCmdBuf(int commid) } #ifndef _WIN32 - if(pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) + if (pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) #else - if((pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) - || !isUdpSocketExist()) + if ((pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) + || !isUdpSocketExist()) #endif { - pPortParam->m_psBaoHu->ForceWaitCnt = BYTE1(buf[0])+BYTE0(buf[1])+TIMER_CNT-1; + pPortParam->m_psBaoHu->ForceWaitCnt = BYTE1(buf[0]) + BYTE0(buf[1]) + TIMER_CNT - 1; pPortParam->m_psBaoHu->ForceWaitCnt /= TIMER_CNT; - if(pPortParam->m_psBaoHu->ForceWaitCnt) + if (pPortParam->m_psBaoHu->ForceWaitCnt) { pPortParam->m_psBaoHu->ForceWaitFlag = 1; } @@ -1463,7 +1463,7 @@ void Buban104SendCmdFormPollCmdBuf(int commid) { ClearCmdFormPollCmdBuf(commid); // 清除当前命令 //ClearCmdAllFlag(commid); // 清除当前命令 - if(pPortParam->bSendFormatI) + if (pPortParam->bSendFormatI) { //pPortParam->wSendSequence++; //pPortParam->wSendSequence %= MAX_SEQUENCE; @@ -1479,30 +1479,30 @@ void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProc { RTUMSG msg; BUBAN104PORTPARAM *pPortParam; - + pPortParam = psPortParam; - if(TRUE == bProcess) + if (TRUE == bProcess) { msg.PortIdx = (BYTE)commid; msg.MsgLen = psPortParam->m_iRecvLen; memcpy(msg.MsgData, psPortParam->m_au8RecvBuf, msg.MsgLen); msg.MsgData[msg.MsgLen] = CHECK_WHOLE; - msg.MsgData[msg.MsgLen+1] = 0; + msg.MsgData[msg.MsgLen + 1] = 0; // 超时计数清零 pPortParam->lTimeOutCnt = 0; pPortParam->bCloseSocket = FALSE; // 子站数据处理 - if(PROTOCOL_SLAVE == pPortParam->m_psBaoHu->PortType) + if (PROTOCOL_SLAVE == pPortParam->m_psBaoHu->PortType) { ProvBuban104dataProcess(commid, &msg); return; } // format-i - if((msg.MsgData[2] & 0x01) == 0) + if ((msg.MsgData[2] & 0x01) == 0) { Buban104FormatI(&msg); } @@ -1510,7 +1510,7 @@ void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProc else { // format-u - if((msg.MsgData[2] & 0x02) != 0 ) + if ((msg.MsgData[2] & 0x02) != 0) { Buban104FormatU(&msg); } @@ -1525,15 +1525,15 @@ void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProc //*参数 RTUMSG* rtumsg:接收到的数据信息 //*************************************************************** void Buban104FormatI(RTUMSG *rtumsg) -{ +{ int commid, iSequenceInc; BUBAN104PORTPARAM *pPortParam; #ifdef _DEBUG_MSG_ char szbuf[256]; #endif - + // length - if(rtumsg->MsgData[1] < 4) + if (rtumsg->MsgData[1] < 4) { return; } @@ -1541,8 +1541,8 @@ void Buban104FormatI(RTUMSG *rtumsg) commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - pPortParam->wAckSequence = (rtumsg->MsgData[4]+(rtumsg->MsgData[5] << 8)) >> 1; - + pPortParam->wAckSequence = (rtumsg->MsgData[4] + (rtumsg->MsgData[5] << 8)) >> 1; + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// // wen 2005.09.19 帧序匹配算法修改 /* @@ -1555,154 +1555,154 @@ void Buban104FormatI(RTUMSG *rtumsg) { pPortParam->bAckRight = TRUE; } - */ - - iSequenceInc = pPortParam->wSendSequence - pPortParam->wAckSequence; - if(iSequenceInc < 0) - { - iSequenceInc += MAX_SEQUENCE; - } - //不大于帧序应答尺寸(缺省值=MAX_FRAMEMATCHING_SIZE) - if((pPortParam->wSendSequence != pPortParam->wAckSequence ) - && (iSequenceInc > pPortParam->m_iFrameSize)) - { - pPortParam->bAckRight = FALSE; - } - //??? WEN 2002.09.17 WHY - else - { - pPortParam->bAckRight = TRUE; - } - //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// - - pPortParam->wRecvSequence = (rtumsg->MsgData[2]+(rtumsg->MsgData[3] << 8)) >> 1; - pPortParam->wRecvSequence += 1; - pPortParam->wRecvSequence %= MAX_SEQUENCE; - - switch (rtumsg->MsgData[6]) - { - case 1: // 单点遥信处理 - Buban104DiDataProcess( rtumsg, 0 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command(commid, FORMAT_S ); - break; - - case 2: // 单点遥信SOE处理 - Buban104SoeDataProcess( rtumsg, 0 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command(commid, FORMAT_S); - break; - - case 3: // 双点遥信处理 - Buban104DiDataProcess( rtumsg, 1 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command(commid, FORMAT_S); - break; - - case 4: // 双点遥信SOE处理 - Buban104SoeDataProcess( rtumsg, 1 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command(commid, FORMAT_S); - break; - - case 5: // 变压器分接头位置 - break; - case 6: // 变压器分接头位置带时标 - break; - case 7: // 子站远动终端状态 - break; - - case 9: // 带品质无时标遥测 - Buban104AiWithPzDataProcess( rtumsg, 0 ); - break; - - case 10: // 带品质带时标遥测 - Buban104AiWithPzDataProcess( rtumsg, 1 ); - break; - - case 13: - Buban104AllFloatAiDataProcess( rtumsg ); - break; - - case 20: // 子站传送遥信变位帧 - Buban104AutoSendDiProcess( rtumsg ); - break; - - case 21: // 全遥测数据处理 或变化数据 - Buban104AllAiDataProcess( rtumsg ); - break; - - case 15: // 不带时标电度 - Buban104PiDataProcess( rtumsg ); - break; - case 16: // 带时标电度 - Buban104PiWithTimeDataProcess( rtumsg ); - break; - - case 17: // 继电保护装置单个事件顺序记录帧 - case 18: // 继电保护装置成组记录启动事件顺序 - case 19: // 继电保护装置成组输出电路的事件顺序记录 - Buban104BaoHuDataProcess( rtumsg ); - break; + */ - // wen 2004.05.27 华东104规约修改点(???) - case 30: // 带CP56Time2a时标的单点信息 M_SP_TB_1 - Buban104SoeDataProcessWithCP56Time2a( rtumsg, 0 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command( commid, FORMAT_S ); - break; - case 31: // 带CP56Time2a时标的双点信息 M_DP_TB_1 - Buban104SoeDataProcessWithCP56Time2a( rtumsg, 1 ); - // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) - MakeBuban104Command( commid, FORMAT_S ); - break; - case 32: // 带CP56Time2a时标的步位置信息 M_ST_TB_1 - break; - case 33: // 带CP56Time2a时标的32比特串 M_BO_TB_1 - break; - case 34: // 带CP56Time2a时标的测量值, 规一化值 M_ME_TD_1 - Buban104AiWithDataProcessWithM_ME_TD_1( rtumsg ); - break; - case 35: // 带CP56Time2a时标的测量值, 标度化值 M_ME_TE_1 - Buban104AiWithDataProcessWithM_ME_TE_1( rtumsg ); - break; - case 36: // 带CP56Time2a时标的测量值, 短浮点数 M_ME_TF_1 - Buban104AiWithDataProcessWithM_ME_TF_1( rtumsg ); - break; - case 37: // 带CP56Time2a时标的累计量 M_IT_TB_1 - Buban104PiWithTimeDataProcessWithM_IT_TB_1( rtumsg ); - break; - case 38: // 带CP56Time2a时标的继电保护装置事件 M_EP_TD_1 - break; - case 39: // 带CP56Time2a时标的继电保护装置成组启动事件 M_EP_TE_1 - break; - case 40: // 带CP56Time2a时标的继电保拌装置成组输出电路信息M_EP_TF_1 - break; + iSequenceInc = pPortParam->wSendSequence - pPortParam->wAckSequence; + if (iSequenceInc < 0) + { + iSequenceInc += MAX_SEQUENCE; + } + //不大于帧序应答尺寸(缺省值=MAX_FRAMEMATCHING_SIZE) + if ((pPortParam->wSendSequence != pPortParam->wAckSequence) + && (iSequenceInc > pPortParam->m_iFrameSize)) + { + pPortParam->bAckRight = FALSE; + } + //??? WEN 2002.09.17 WHY + else + { + pPortParam->bAckRight = TRUE; + } + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// - case 45: - case 46: // 遥控返校 - case 47: // 遥调返校 - Buban104YkYtAck( rtumsg ); - break; - case 48: // 设定确认 - Buban104SetAck( rtumsg ); - break; - case 100: // 总召唤确认 - Buban104InitdataProecss( rtumsg ); - break; + pPortParam->wRecvSequence = (rtumsg->MsgData[2] + (rtumsg->MsgData[3] << 8)) >> 1; + pPortParam->wRecvSequence += 1; + pPortParam->wRecvSequence %= MAX_SEQUENCE; - case 101: // 电度结束帧 - Buban104PidataEnd( rtumsg ); - break; - case 103: // 时间同步确认帧 - Buban104SynTime( rtumsg ); - break; + switch (rtumsg->MsgData[6]) + { + case 1: // 单点遥信处理 + Buban104DiDataProcess(rtumsg, 0); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + + case 2: // 单点遥信SOE处理 + Buban104SoeDataProcess(rtumsg, 0); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + + case 3: // 双点遥信处理 + Buban104DiDataProcess(rtumsg, 1); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + + case 4: // 双点遥信SOE处理 + Buban104SoeDataProcess(rtumsg, 1); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + + case 5: // 变压器分接头位置 + break; + case 6: // 变压器分接头位置带时标 + break; + case 7: // 子站远动终端状态 + break; + + case 9: // 带品质无时标遥测 + Buban104AiWithPzDataProcess(rtumsg, 0); + break; + + case 10: // 带品质带时标遥测 + Buban104AiWithPzDataProcess(rtumsg, 1); + break; + + case 13: + Buban104AllFloatAiDataProcess(rtumsg); + break; + + case 20: // 子站传送遥信变位帧 + Buban104AutoSendDiProcess(rtumsg); + break; + + case 21: // 全遥测数据处理 或变化数据 + Buban104AllAiDataProcess(rtumsg); + break; + + case 15: // 不带时标电度 + Buban104PiDataProcess(rtumsg); + break; + case 16: // 带时标电度 + Buban104PiWithTimeDataProcess(rtumsg); + break; + + case 17: // 继电保护装置单个事件顺序记录帧 + case 18: // 继电保护装置成组记录启动事件顺序 + case 19: // 继电保护装置成组输出电路的事件顺序记录 + Buban104BaoHuDataProcess(rtumsg); + break; - default: + // wen 2004.05.27 华东104规约修改点(???) + case 30: // 带CP56Time2a时标的单点信息 M_SP_TB_1 + Buban104SoeDataProcessWithCP56Time2a(rtumsg, 0); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + case 31: // 带CP56Time2a时标的双点信息 M_DP_TB_1 + Buban104SoeDataProcessWithCP56Time2a(rtumsg, 1); + // wen 2004.09.02 修改为对于遥信变位和soe数据帧确认,以使对方能确认数据收到(拓邦公司用) + MakeBuban104Command(commid, FORMAT_S); + break; + case 32: // 带CP56Time2a时标的步位置信息 M_ST_TB_1 + break; + case 33: // 带CP56Time2a时标的32比特串 M_BO_TB_1 + break; + case 34: // 带CP56Time2a时标的测量值, 规一化值 M_ME_TD_1 + Buban104AiWithDataProcessWithM_ME_TD_1(rtumsg); + break; + case 35: // 带CP56Time2a时标的测量值, 标度化值 M_ME_TE_1 + Buban104AiWithDataProcessWithM_ME_TE_1(rtumsg); + break; + case 36: // 带CP56Time2a时标的测量值, 短浮点数 M_ME_TF_1 + Buban104AiWithDataProcessWithM_ME_TF_1(rtumsg); + break; + case 37: // 带CP56Time2a时标的累计量 M_IT_TB_1 + Buban104PiWithTimeDataProcessWithM_IT_TB_1(rtumsg); + break; + case 38: // 带CP56Time2a时标的继电保护装置事件 M_EP_TD_1 + break; + case 39: // 带CP56Time2a时标的继电保护装置成组启动事件 M_EP_TE_1 + break; + case 40: // 带CP56Time2a时标的继电保拌装置成组输出电路信息M_EP_TF_1 + break; + + case 45: + case 46: // 遥控返校 + case 47: // 遥调返校 + Buban104YkYtAck(rtumsg); + break; + case 48: // 设定确认 + Buban104SetAck(rtumsg); + break; + case 100: // 总召唤确认 + Buban104InitdataProecss(rtumsg); + break; + + case 101: // 电度结束帧 + Buban104PidataEnd(rtumsg); + break; + case 103: // 时间同步确认帧 + Buban104SynTime(rtumsg); + break; + + default: #ifdef _DEBUG_MSG_ - DebugPrint("接收到不认识的命令,请检查程序.\n"); + DebugPrint("接收到不认识的命令,请检查程序.\n"); #endif - break; + break; } } @@ -1710,9 +1710,9 @@ void Buban104FormatU(RTUMSG *rtumsg) { int commid; BUBAN104PORTPARAM *pPortParam; - + // length - if(rtumsg->MsgData[1] < 4) + if (rtumsg->MsgData[1] < 4) { return; } @@ -1720,35 +1720,35 @@ void Buban104FormatU(RTUMSG *rtumsg) commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - switch(rtumsg->MsgData[2] & 0xfc) + switch (rtumsg->MsgData[2] & 0xfc) { - case 0x08: // 启动动作响应 - InitBuban104CommandBuffer(commid); - pPortParam->bAckRight = TRUE; - pPortParam->LinkOk = TRUE; - break; - case 0x20: // 停止动作响应 + case 0x08: // 启动动作响应 + InitBuban104CommandBuffer(commid); + pPortParam->bAckRight = TRUE; + pPortParam->LinkOk = TRUE; + break; + case 0x20: // 停止动作响应 + pPortParam->bAckRight = TRUE; + break; + case 0x40: // 测试动作 + //pPortParam->bAckRight = TRUE; + MakeBuban104Command(commid, FORMAT_U_TEST_CON); + if (!pPortParam->bAckRight) + { pPortParam->bAckRight = TRUE; - break; - case 0x40: // 测试动作 - //pPortParam->bAckRight = TRUE; - MakeBuban104Command(commid, FORMAT_U_TEST_CON); - if( !pPortParam->bAckRight ) - { - pPortParam->bAckRight = TRUE; - pPortParam->wSendSequence = pPortParam->wAckSequence; - } - break; + pPortParam->wSendSequence = pPortParam->wAckSequence; + } + break; // wen 2005.11.02 增加测试响应处理 - case 0x80: // 测试响应 - if(!pPortParam->bAckRight) - { - pPortParam->bAckRight = TRUE; - } - break; - default: // 错误的响应 - pPortParam->bAckRight = FALSE; - break; + case 0x80: // 测试响应 + if (!pPortParam->bAckRight) + { + pPortParam->bAckRight = TRUE; + } + break; + default: // 错误的响应 + pPortParam->bAckRight = FALSE; + break; } } @@ -1758,11 +1758,11 @@ void Buban104InitdataProecss(RTUMSG * rtumsg) int commid; WORD wTransCause; BUBAN104PORTPARAM *pPortParam; - + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; } @@ -1770,15 +1770,15 @@ void Buban104InitdataProecss(RTUMSG * rtumsg) { wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); } - switch(wTransCause) + switch (wTransCause) { - case 7: - case 9://总召唤确认 - break; + case 7: + case 9://总召唤确认 + break; - case 10://总召唤结束 - pPortParam->Initdata = TRUE; - break; + case 10://总召唤结束 + pPortParam->Initdata = TRUE; + break; } } @@ -1788,11 +1788,11 @@ void Buban104PidataEnd(RTUMSG * rtumsg) int commid; WORD wTransCause; BUBAN104PORTPARAM *pPortParam; - + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; } @@ -1801,25 +1801,25 @@ void Buban104PidataEnd(RTUMSG * rtumsg) wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); } - if(wTransCause & 0x0040) - { + if (wTransCause & 0x0040) + { pPortParam->Initdata = TRUE; return; } - switch(wTransCause) + switch (wTransCause) { - case 7://总召唤确认 - break; + case 7://总召唤确认 + break; - case 10://电度召唤结束 - pPortParam->Initdata = TRUE; - break; + case 10://电度召唤结束 + pPortParam->Initdata = TRUE; + break; } } //设定确认 -void Buban104SetAck( RTUMSG *rtumsg) +void Buban104SetAck(RTUMSG *rtumsg) { } @@ -1832,18 +1832,18 @@ void Buban104YkYtAck(RTUMSG * rtumsg) WORD wTransCause; YKYT_PARAM YkYtParam; BUBAN104PORTPARAM *pPortParam; - + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - YkYtParam.m_iYkYtPnt = (rtumsg->MsgData[11]<<8) + rtumsg->MsgData[10]; + YkYtParam.m_iYkYtPnt = (rtumsg->MsgData[11] << 8) + rtumsg->MsgData[10]; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2006.03.24 //YkYtParam.m_iYkYtPnt -= pPortParam->iYkBaseAddr; //======================================================================= - YkYtParam.m_iYkYtPnt -= (pPortParam->iYkBaseAddr-1); + YkYtParam.m_iYkYtPnt -= (pPortParam->iYkBaseAddr - 1); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ YkYtParam.m_iYkYtPnt %= 256; @@ -1852,66 +1852,66 @@ void Buban104YkYtAck(RTUMSG * rtumsg) } else { - YkYtParam.m_iYkYtPnt = (rtumsg->MsgData[14] << 16) - + (rtumsg->MsgData[13]<<8) + rtumsg->MsgData[12]; + YkYtParam.m_iYkYtPnt = (rtumsg->MsgData[14] << 16) + + (rtumsg->MsgData[13] << 8) + rtumsg->MsgData[12]; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2006.03.24 //YkYtParam.m_iYkYtPnt -= pPortParam->iYkBaseAddr; //======================================================================= - YkYtParam.m_iYkYtPnt -= (pPortParam->iYkBaseAddr-1); + YkYtParam.m_iYkYtPnt -= (pPortParam->iYkBaseAddr - 1); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ YkYtParam.m_iYkYtPnt %= 256; - wTransCause = (rtumsg->MsgData[9]<<8) + rtumsg->MsgData[8]; + wTransCause = (rtumsg->MsgData[9] << 8) + rtumsg->MsgData[8]; bYkOperate = rtumsg->MsgData[15]; } - - if(bYkOperate & 0x80) //选择返校 + + if (bYkOperate & 0x80) //选择返校 { YkYtParam.m_iYkYtStep = STEP_YKYT_SELECT; //此位为肯定或否定确认位 || 撤销确认 - if((wTransCause & 0x0040) || (wTransCause == 0x0009)) + if ((wTransCause & 0x0040) || (wTransCause == 0x0009)) { YkYtParam.m_iYkYtOperate = 3; } - else if(wTransCause == 0x0007) + else if (wTransCause == 0x0007) { - if(rtumsg->MsgData[6] != 45) + if (rtumsg->MsgData[6] != 45) { - switch(bYkOperate & 0x03) + switch (bYkOperate & 0x03) { - case 1://控分 - if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 2) - { - YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; - } - else - { - YkYtParam.m_iYkYtOperate = 3; - } - break; - case 2://控合 - if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 1) - { - YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; - } - else - { - YkYtParam.m_iYkYtOperate = 3; - } - break; - default: + case 1://控分 + if (pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 2) + { + YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; + } + else + { + YkYtParam.m_iYkYtOperate = 3; + } + break; + case 2://控合 + if (pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 1) + { + YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; + } + else + { YkYtParam.m_iYkYtOperate = 3; - break; + } + break; + default: + YkYtParam.m_iYkYtOperate = 3; + break; } } else { // 控合 - if( bYkOperate & 0x01 ) - { - if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 1) + if (bYkOperate & 0x01) + { + if (pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 1) { YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; } @@ -1923,7 +1923,7 @@ void Buban104YkYtAck(RTUMSG * rtumsg) // 控分 else { - if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 2) + if (pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 2) { YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; } @@ -1939,18 +1939,18 @@ void Buban104YkYtAck(RTUMSG * rtumsg) SendYkYtCommand2(commid, &YkYtParam); } else //执行并完成 - { + { //此位为肯定或否定确认位 - if((wTransCause & 0x0040) == 0) - { - switch(wTransCause) + if ((wTransCause & 0x0040) == 0) + { + switch (wTransCause) { - case 0x0007://执行确认 - break; - case 0x000a://执行完成 - break; - default: - break; + case 0x0007://执行确认 + break; + case 0x000a://执行完成 + break; + default: + break; } } } @@ -1964,48 +1964,48 @@ void Buban104SynTime(RTUMSG * rtumsg) DAY_TIME stime; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(1 != pPortParam->m_psBaoHu->CheckTime) + if (1 != pPortParam->m_psBaoHu->CheckTime) { return; } - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; } else { - wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9]<<8); + wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); } - - if(wTransCause != 0x0007) + + if (wTransCause != 0x0007) { return; } - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - stime.mSec = (rtumsg->MsgData[13]<<8) + rtumsg->MsgData[12]; - stime.Sec = stime.mSec / 1000; + stime.mSec = (rtumsg->MsgData[13] << 8) + rtumsg->MsgData[12]; + stime.Sec = stime.mSec / 1000; stime.mSec %= 1000; - stime.Min = rtumsg->MsgData[14] & 0x3F; + stime.Min = rtumsg->MsgData[14] & 0x3F; stime.Hour = rtumsg->MsgData[15] & 0x1F; - stime.Day = rtumsg->MsgData[16] & 0x1F; - stime.Month= rtumsg->MsgData[17] & 0x0F; - stime.Year = (rtumsg->MsgData[18] & 0x7F)+2000; + stime.Day = rtumsg->MsgData[16] & 0x1F; + stime.Month = rtumsg->MsgData[17] & 0x0F; + stime.Year = (rtumsg->MsgData[18] & 0x7F) + 2000; } else { - stime.mSec = (rtumsg->MsgData[16]<<8) + rtumsg->MsgData[15]; - stime.Sec = stime.mSec / 1000; + stime.mSec = (rtumsg->MsgData[16] << 8) + rtumsg->MsgData[15]; + stime.Sec = stime.mSec / 1000; stime.mSec %= 1000; - stime.Min = rtumsg->MsgData[17] & 0x3F; + stime.Min = rtumsg->MsgData[17] & 0x3F; stime.Hour = rtumsg->MsgData[18] & 0x1F; - stime.Day = rtumsg->MsgData[19] & 0x1F; - stime.Month= rtumsg->MsgData[20] & 0x0F; - stime.Year = (rtumsg->MsgData[21] & 0x7F)+2000; + stime.Day = rtumsg->MsgData[19] & 0x1F; + stime.Month = rtumsg->MsgData[20] & 0x0F; + stime.Year = (rtumsg->MsgData[21] & 0x7F) + 2000; } SetLocalTimeEx(&stime); } @@ -2016,52 +2016,52 @@ void Buban104AutoSendDiProcess(RTUMSG *rtumsg) int i, j, dipnt, len, istart; DI_DEF pntmsg; WORD wStatus, wStatusBit, wTransCause; - + int commid; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; istart = 10; } else { - wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9]<<8); + wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); istart = 12; } - if(wTransCause == 0x0003) + if (wTransCause == 0x0003) { - for(i = istart; i < (2 + len); ) + for (i = istart; i < (2 + len); ) { dipnt = rtumsg->MsgData[i++]; - dipnt += (rtumsg->MsgData[i++]<<8); - if(VER_IEC870_5_104 == pPortParam->RtuVersion) + dipnt += (rtumsg->MsgData[i++] << 8); + if (VER_IEC870_5_104 == pPortParam->RtuVersion) { - dipnt += (rtumsg->MsgData[i++]<<16); + dipnt += (rtumsg->MsgData[i++] << 16); } dipnt -= pPortParam->iDiBaseAddr; - + wStatus = rtumsg->MsgData[i++]; - wStatus = (wStatus<<8) + rtumsg->MsgData[i++]; + wStatus = (wStatus << 8) + rtumsg->MsgData[i++]; wStatusBit = rtumsg->MsgData[i++]; - wStatusBit = (wStatusBit<<8) + rtumsg->MsgData[i++]; + wStatusBit = (wStatusBit << 8) + rtumsg->MsgData[i++]; - for( j = 0; j < 16; j++ ) + for (j = 0; j < 16; j++) { - if( wStatusBit & (0x0001 << j) ) + if (wStatusBit & (0x0001 << j)) { - if( wStatus & (0x0001 << j) ) + if (wStatus & (0x0001 << j)) pntmsg.Status = 1; else pntmsg.Status = 0; - SetPntMsg(commid, dipnt+j, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); + SetPntMsg(commid, dipnt + j, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); } } } @@ -2076,12 +2076,12 @@ void Buban104AiWithPzDataProcess(RTUMSG * rtumsg, int flag) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2089,31 +2089,31 @@ void Buban104AiWithPzDataProcess(RTUMSG * rtumsg, int flag) { istart = 12; } - + //处理变化遥测 - for(i = istart; i < (2 + len);) + for (i = istart; i < (2 + len);) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } aipnt -= pPortParam->iAiBaseAddr; - pntmsg.RawValue = (short)(rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)); + pntmsg.RawValue = (short)(rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8)); // 品质描述 // rtumsg->MsgData[i+2]; i += 3; - + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); - + // 时标 - if(flag) + if (flag) { i += 3; } @@ -2127,21 +2127,21 @@ void Buban104AllAiDataProcess(RTUMSG *rtumsg) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(len <= 0) + if (len <= 0) { return; } aipnt = 0; //处理变化遥测 - if((rtumsg->MsgData[7] & 0x80)==0) + if ((rtumsg->MsgData[7] & 0x80) == 0) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2150,45 +2150,45 @@ void Buban104AllAiDataProcess(RTUMSG *rtumsg) istart = 12; } - for(i = istart; i < len + 2;) + for (i = istart; i < len + 2;) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } aipnt -= pPortParam->iAiBaseAddr; - - pntmsg.RawValue = (short)((rtumsg->MsgData[i+1]<<8) + rtumsg->MsgData[i]); + + pntmsg.RawValue = (short)((rtumsg->MsgData[i + 1] << 8) + rtumsg->MsgData[i]); i += 2; SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); } return; } - + //处理全遥测 - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 12; - aipnt = rtumsg->MsgData[10]+(rtumsg->MsgData[11]<<8); + aipnt = rtumsg->MsgData[10] + (rtumsg->MsgData[11] << 8); } else { istart = 15; - aipnt = rtumsg->MsgData[12]+(rtumsg->MsgData[13]<<8)+(rtumsg->MsgData[14]<<16); + aipnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8) + (rtumsg->MsgData[14] << 16); } aipnt -= pPortParam->iAiBaseAddr; - - for(i=istart; i < (len+2); i+=2) + + for (i = istart; i < (len + 2); i += 2) { - pntmsg.RawValue = (short)(rtumsg->MsgData[i] + (rtumsg->MsgData[i+1]<<8)); + pntmsg.RawValue = (short)(rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8)); SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); aipnt++; } @@ -2202,21 +2202,21 @@ void Buban104AllFloatAiDataProcess(RTUMSG *rtumsg) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(len <= 0) + if (len <= 0) { return; } aipnt = 0; //处理变化遥测 - if((rtumsg->MsgData[7] & 0x80)==0) + if ((rtumsg->MsgData[7] & 0x80) == 0) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2225,45 +2225,45 @@ void Buban104AllFloatAiDataProcess(RTUMSG *rtumsg) istart = 12; } - for(i = istart; i < len + 4;) + for (i = istart; i < len + 4;) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } aipnt -= pPortParam->iAiBaseAddr; - + fValue = SequenceRtuToHostfloat((*((float *)&rtumsg->MsgData[i]))); pntmsg.RawValue = (unsigned long)fValue; // 含有一个字节的品质描述 - i += sizeof(float)+1; + i += sizeof(float) + 1; SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); } return; } - + //处理全遥测 - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 12; - aipnt = rtumsg->MsgData[10]+(rtumsg->MsgData[11]<<8); + aipnt = rtumsg->MsgData[10] + (rtumsg->MsgData[11] << 8); } else { istart = 15; - aipnt = rtumsg->MsgData[12]+(rtumsg->MsgData[13]<<8)+(rtumsg->MsgData[14]<<16); + aipnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8) + (rtumsg->MsgData[14] << 16); } aipnt -= pPortParam->iAiBaseAddr; - - for(i=istart; i < (len+2); i+=5) + + for (i = istart; i < (len + 2); i += 5) { fValue = SequenceRtuToHostfloat((*((float *)&rtumsg->MsgData[i]))); pntmsg.RawValue = (unsigned long)fValue; @@ -2280,24 +2280,24 @@ void Buban104DiDataProcess(RTUMSG *rtumsg, int flag) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; } else { - wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9]<<8); + wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); } //从站主动上发 变化遥信 - if(wTransCause == 0x0003) + if (wTransCause == 0x0003) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2305,38 +2305,38 @@ void Buban104DiDataProcess(RTUMSG *rtumsg, int flag) { istart = 12; } - for ( i = istart; i < 2 + len; ) + for (i = istart; i < 2 + len; ) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - dipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + dipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - dipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + dipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } dipnt -= pPortParam->iDiBaseAddr; - if ( flag == 0 ) + if (flag == 0) pntmsg.Status = rtumsg->MsgData[i++] & 0x1; else { - switch ( rtumsg->MsgData[i++] & 0x3 ) + switch (rtumsg->MsgData[i++] & 0x3) { - case 1: - pntmsg.Status = 1; - break; - case 2: - pntmsg.Status = 0; - break; - default: - pntmsg.Status = 0xff; - break; + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; } } - if ( pntmsg.Status != 0xff ) + if (pntmsg.Status != 0xff) { SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); } @@ -2345,40 +2345,40 @@ void Buban104DiDataProcess(RTUMSG *rtumsg, int flag) return; } - if(rtumsg->MsgData[7] & 0x80) + if (rtumsg->MsgData[7] & 0x80) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 12; - dipnt = rtumsg->MsgData[10]+(rtumsg->MsgData[11]<<8); + dipnt = rtumsg->MsgData[10] + (rtumsg->MsgData[11] << 8); } else { istart = 15; - dipnt = rtumsg->MsgData[12]+(rtumsg->MsgData[13]<<8)+(rtumsg->MsgData[14]<<16); + dipnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8) + (rtumsg->MsgData[14] << 16); } dipnt -= pPortParam->iDiBaseAddr; - - for ( i = istart; i < 2 + len; i++,dipnt++ ) + + for (i = istart; i < 2 + len; i++, dipnt++) { - if ( flag == 0 ) + if (flag == 0) pntmsg.Status = rtumsg->MsgData[i] & 0x1; else { - switch ( rtumsg->MsgData[i] & 0x3 ) + switch (rtumsg->MsgData[i] & 0x3) { - case 1: - pntmsg.Status = 1; - break; - case 2: - pntmsg.Status = 0; - break; - default: - pntmsg.Status = 0xff; - break; + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; } } - if(pntmsg.Status != 0xff) + if (pntmsg.Status != 0xff) { SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); } @@ -2386,7 +2386,7 @@ void Buban104DiDataProcess(RTUMSG *rtumsg, int flag) } else { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2394,38 +2394,38 @@ void Buban104DiDataProcess(RTUMSG *rtumsg, int flag) { istart = 12; } - for ( i = istart; i < 2 + len; ) + for (i = istart; i < 2 + len; ) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - dipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + dipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - dipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + dipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } dipnt -= pPortParam->iDiBaseAddr; - - if ( flag == 0 ) + + if (flag == 0) pntmsg.Status = rtumsg->MsgData[i++] & 0x1; else { - switch ( rtumsg->MsgData[i++] & 0x3 ) + switch (rtumsg->MsgData[i++] & 0x3) { - case 1: - pntmsg.Status = 1; - break; - case 2: - pntmsg.Status = 0; - break; - default: - pntmsg.Status = 0xff; - break; + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; } } - if(pntmsg.Status != 0xff) + if (pntmsg.Status != 0xff) { SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); } @@ -2438,7 +2438,7 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int flag) _int64 i64Millseconds; time_t iTime; int i, pnt, len; - char st; + char st; int sec; DI_DEF pntmsg; DAY_TIME sm; @@ -2446,12 +2446,12 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int flag) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2459,53 +2459,53 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int flag) { istart = 12; } - for ( i = istart; i < len + 2;) + for (i = istart; i < len + 2;) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - pnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + pnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - pnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + pnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } pnt -= pPortParam->iDiBaseAddr; - - if ( flag == 0 ) + + if (flag == 0) st = rtumsg->MsgData[i++] & 0x01; else { - switch ( rtumsg->MsgData[i++] & 0x3 ) + switch (rtumsg->MsgData[i++] & 0x3) { - case 1: - st = 1; - break; - case 2: - st = 0; - break; - default: - st = 0x0f; - break; + case 1: + st = 1; + break; + case 2: + st = 0; + break; + default: + st = 0x0f; + break; } } - if ( st == 0x0f ) + if (st == 0x0f) continue; - sec = rtumsg->MsgData[i] + ( rtumsg->MsgData[i+1] << 8 ); + sec = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); pntmsg.SoeTime.mSec = sec % 1000; pntmsg.SoeTime.Sec = sec / 1000; - pntmsg.SoeTime.Min = (rtumsg->MsgData[i+2] & 0x3f); // 分 + pntmsg.SoeTime.Min = (rtumsg->MsgData[i + 2] & 0x3f); // 分 i += 3; GetLocalTimeEx(&sm); - if(abs(pntmsg.SoeTime.Min-sm.Min) > 50) + if (abs(pntmsg.SoeTime.Min - sm.Min) > 50) { i64Millseconds = SystemTimeToMillseconds(&sm, 0); - if(i64Millseconds > 0) + if (i64Millseconds > 0) { // 减去一小时 - iTime = (long)(i64Millseconds/1000) - 3600; + iTime = (long)(i64Millseconds / 1000) - 3600; testtm = localtime(&iTime); sm.Year = testtm->tm_year + 1900; sm.Month = testtm->tm_mon + 1; @@ -2515,7 +2515,7 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int flag) sm.Sec = testtm->tm_sec; } } - + pntmsg.SoeTime.Hour = sm.Hour; pntmsg.SoeTime.Day = sm.Day; pntmsg.SoeTime.Month = sm.Month; @@ -2526,18 +2526,18 @@ void Buban104SoeDataProcess(RTUMSG *rtumsg, int flag) } } -void Buban104PiDataProcess( RTUMSG * rtumsg ) +void Buban104PiDataProcess(RTUMSG * rtumsg) { int i, point, len; PI_DEF pntmsg; int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2545,42 +2545,42 @@ void Buban104PiDataProcess( RTUMSG * rtumsg ) { istart = 12; } - for ( i = istart; i < 2 + len; ) - { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + for (i = istart; i < 2 + len; ) + { + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } point -= pPortParam->iPiBaseAddr; - pntmsg.RawValue = (rtumsg->MsgData[i+3]<<24) + (rtumsg->MsgData[i+2]<<16) - + (rtumsg->MsgData[i+1]<<8) + rtumsg->MsgData[i]; + pntmsg.RawValue = (rtumsg->MsgData[i + 3] << 24) + (rtumsg->MsgData[i + 2] << 16) + + (rtumsg->MsgData[i + 1] << 8) + rtumsg->MsgData[i]; //rtumsg->MsgData[i+4]; // 顺序记号 i += 5; - + SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); - } + } } -void Buban104PiWithTimeDataProcess( RTUMSG *rtumsg ) +void Buban104PiWithTimeDataProcess(RTUMSG *rtumsg) { int i, point, len; PI_DEF pntmsg; int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2588,37 +2588,37 @@ void Buban104PiWithTimeDataProcess( RTUMSG *rtumsg ) { istart = 12; } - for ( i = istart; i < 2 + len; ) - { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + for (i = istart; i < 2 + len; ) + { + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } point -= pPortParam->iPiBaseAddr; - pntmsg.RawValue = (rtumsg->MsgData[i+3]<<24) + (rtumsg->MsgData[i+2]<<16) - + (rtumsg->MsgData[i+1]<<8) + rtumsg->MsgData[i]; + pntmsg.RawValue = (rtumsg->MsgData[i + 3] << 24) + (rtumsg->MsgData[i + 2] << 16) + + (rtumsg->MsgData[i + 1] << 8) + rtumsg->MsgData[i]; //rtumsg->MsgData[i+4]; // 顺序记号 // 3bytes 时间 i += 8; SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); - } + } } -void Buban104BaoHuDataProcess( RTUMSG *rtumsg ) +void Buban104BaoHuDataProcess(RTUMSG *rtumsg) { // 该功能不做处理 } -void Buban104DefaultBaoHuDataProcess( RTUMSG *rtumsg ) +void Buban104DefaultBaoHuDataProcess(RTUMSG *rtumsg) { // 该功能不做处理 } @@ -2627,12 +2627,12 @@ void Buban104DefaultBaoHuDataProcess( RTUMSG *rtumsg ) //*************************************************************** //* Buban104 SOE 数据处理(7 bytes 时间) * //*************************************************************** -void Buban104SoeDataProcessWithCP56Time2a( RTUMSG *rtumsg, int flag ) +void Buban104SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag) { _int64 i64Millseconds; time_t iTime; int i, pnt, len; - char st; + char st; int sec; DI_DEF pntmsg; DAY_TIME sm; @@ -2640,12 +2640,12 @@ void Buban104SoeDataProcessWithCP56Time2a( RTUMSG *rtumsg, int flag ) int commid, istart; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; } @@ -2653,62 +2653,62 @@ void Buban104SoeDataProcessWithCP56Time2a( RTUMSG *rtumsg, int flag ) { istart = 12; } - for ( i = istart; i < len + 2; ) + for (i = istart; i < len + 2; ) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - pnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + pnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - pnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + pnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } pnt -= pPortParam->iDiBaseAddr; - - if(flag == 0) + + if (flag == 0) { st = rtumsg->MsgData[i++] & 0x01; } else { - switch ( rtumsg->MsgData[i++] & 0x3 ) + switch (rtumsg->MsgData[i++] & 0x3) { - case 1: - st = 1; - break; - case 2: - st = 0; - break; - default: - st = 0x0f; - break; + case 1: + st = 1; + break; + case 2: + st = 0; + break; + default: + st = 0x0f; + break; } } - if(st == 0x0f) + if (st == 0x0f) { continue; } - sec = rtumsg->MsgData[i] + (rtumsg->MsgData[i+1] << 8); + sec = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); pntmsg.SoeTime.mSec = sec % 1000; pntmsg.SoeTime.Sec = sec / 1000; - pntmsg.SoeTime.Min = (char)(rtumsg->MsgData[i+2] & 0x3f); - pntmsg.SoeTime.Hour = (char)(rtumsg->MsgData[i+3] & 0x1f); - pntmsg.SoeTime.Day = (char)(rtumsg->MsgData[i+4] & 0x1f); + pntmsg.SoeTime.Min = (char)(rtumsg->MsgData[i + 2] & 0x3f); + pntmsg.SoeTime.Hour = (char)(rtumsg->MsgData[i + 3] & 0x1f); + pntmsg.SoeTime.Day = (char)(rtumsg->MsgData[i + 4] & 0x1f); //rtumsg->MsgData[i+5]; // month //rtumsg->MsgData[i+6]; // year i += 7; GetLocalTimeEx(&sm); - if((pntmsg.SoeTime.Day-sm.Day) < 0) + if ((pntmsg.SoeTime.Day - sm.Day) < 0) { i64Millseconds = SystemTimeToMillseconds(&sm, 0); - if(i64Millseconds > 0) + if (i64Millseconds > 0) { // 减去一小时 - iTime = (long)(i64Millseconds/1000) - 3600; + iTime = (long)(i64Millseconds / 1000) - 3600; testtm = localtime(&iTime); sm.Year = testtm->tm_year + 1900; sm.Month = testtm->tm_mon + 1; @@ -2734,12 +2734,12 @@ void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg) int commid, istart, istep; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; istep = 11; @@ -2750,12 +2750,12 @@ void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg) istep = 12; } //处理变化遥测 - for ( i = istart; i < 2 + len; ) + for (i = istart; i < 2 + len; ) { - if( ( i + istep ) > (2 + len)) + if ((i + istep) > (2 + len)) { #ifdef _WIN32 - sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TD_1", + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TD_1", _getpid(), commid, len); #else sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TD_1", @@ -2764,23 +2764,23 @@ void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg) DebugPrint(szbuf); break; } - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } - + aipnt -= pPortParam->iAiBaseAddr; - pntmsg.RawValue = (short)((rtumsg->MsgData[i+1]<<8) + rtumsg->MsgData[i]); - + pntmsg.RawValue = (short)((rtumsg->MsgData[i + 1] << 8) + rtumsg->MsgData[i]); + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); - + // 7字节时标 i += 9; } @@ -2800,12 +2800,12 @@ void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) int commid, istart, istep; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - + len = (int)rtumsg->MsgData[1]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; istep = 14; @@ -2816,12 +2816,12 @@ void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) istep = 15; } //处理变化遥测 - for ( i = istart; i < 2 + len; ) + for (i = istart; i < 2 + len; ) { - if( ( i + istep ) > (2 + len)) + if ((i + istep) > (2 + len)) { #ifdef _WIN32 - sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TF_1", + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TF_1", _getpid(), commid, len); #else sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104AiWithDataProcessWithM_ME_TF_1", @@ -2831,14 +2831,14 @@ void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) break; } - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - aipnt = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + aipnt = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } @@ -2846,14 +2846,14 @@ void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) fValue = *((float *)&rtumsg->MsgData[i]); SequenceRtuToHost((char *)&fValue, sizeof(float)); - + // 品质描述 // rtumsg->MsgData[i+1]; - + // 保留2位小数 pntmsg.RawValue = (int)(fValue * 100); SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); - + // 7字节时标 i += 12; } @@ -2868,10 +2868,10 @@ void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg) int commid, istart, istep; BUBAN104PORTPARAM *pPortParam; - commid = rtumsg->PortIdx; + commid = rtumsg->PortIdx; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { istart = 10; istep = 14; @@ -2881,13 +2881,13 @@ void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg) istart = 12; istep = 15; } - len = (int)rtumsg->MsgData[1]; - for ( i = istart; i < 2 + len; ) - { - if( ( i + istep ) > (2 + len)) + len = (int)rtumsg->MsgData[1]; + for (i = istart; i < 2 + len; ) + { + if ((i + istep) > (2 + len)) { #ifdef _WIN32 - sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104PiWithTimeDataProcessWithM_IT_TB_1", + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104PiWithTimeDataProcessWithM_IT_TB_1", _getpid(), commid, len); #else sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban104PiWithTimeDataProcessWithM_IT_TB_1", @@ -2897,27 +2897,27 @@ void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg) break; } - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8); i += 2; } else { - point = rtumsg->MsgData[i]+(rtumsg->MsgData[i+1]<<8)+(rtumsg->MsgData[i+2]<<16); + point = rtumsg->MsgData[i] + (rtumsg->MsgData[i + 1] << 8) + (rtumsg->MsgData[i + 2] << 16); i += 3; } point -= pPortParam->iPiBaseAddr; - pntmsg.RawValue = (rtumsg->MsgData[i+3]<<24) + (rtumsg->MsgData[i+2]<<16) - + (rtumsg->MsgData[i+1]<<8) + rtumsg->MsgData[i]; + pntmsg.RawValue = (rtumsg->MsgData[i + 3] << 24) + (rtumsg->MsgData[i + 2] << 16) + + (rtumsg->MsgData[i + 1] << 8) + rtumsg->MsgData[i]; SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); // 1 BYTE (IV CA CY 顺序号) // 7 BYTE 时标 i += 12; - } + } } //=========================以下为Buban104转发数据功能=======================// @@ -2928,15 +2928,15 @@ void ProvBuban104dataProcess(int commid, RTUMSG *rtumsg) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; // 数据校验错误( 附加字节的第二个字节) - if(rtumsg->MsgData[rtumsg->MsgLen+1] > 0) + if (rtumsg->MsgData[rtumsg->MsgLen + 1] > 0) { return; } // format-i - if((rtumsg->MsgData[2] & 0x01) == 0) + if ((rtumsg->MsgData[2] & 0x01) == 0) { - if(pPortParam->LinkOk) + if (pPortParam->LinkOk) { ProvBuban104FormatI(commid, rtumsg); } @@ -2945,14 +2945,14 @@ void ProvBuban104dataProcess(int commid, RTUMSG *rtumsg) else { // format-u - if((rtumsg->MsgData[2] & 0x02) != 0) + if ((rtumsg->MsgData[2] & 0x02) != 0) { - ProvBuban104FormatU( commid, rtumsg ); + ProvBuban104FormatU(commid, rtumsg); } // format-s else { - ProvBuban104FormatS( commid, rtumsg ); + ProvBuban104FormatS(commid, rtumsg); } } } @@ -2964,7 +2964,7 @@ void ProvBuban104FormatI(int commid, RTUMSG *rtumsg) BUBAN104PORTPARAM *pPortParam; // length - if( rtumsg->MsgData[1] < 4 ) + if (rtumsg->MsgData[1] < 4) { return; } @@ -2974,7 +2974,7 @@ void ProvBuban104FormatI(int commid, RTUMSG *rtumsg) // 超时计数清零 pPortParam->lTimeOutCnt = 0; - pPortParam->wAckSequence = (rtumsg->MsgData[4] + (rtumsg->MsgData[5]<<8)) >> 1; + pPortParam->wAckSequence = (rtumsg->MsgData[4] + (rtumsg->MsgData[5] << 8)) >> 1; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// // wen 2005.09.19 帧序匹配算法修改 /* @@ -2998,12 +2998,12 @@ void ProvBuban104FormatI(int commid, RTUMSG *rtumsg) } */ iSequenceInc = pPortParam->wSendSequence - pPortParam->wAckSequence; - if(iSequenceInc < 0) + if (iSequenceInc < 0) { iSequenceInc += MAX_SEQUENCE; } //不大于帧序应答尺寸(缺省值=MAX_FRAMEMATCHING_SIZE) - if((pPortParam->wSendSequence != pPortParam->wAckSequence ) + if ((pPortParam->wSendSequence != pPortParam->wAckSequence) && (iSequenceInc > pPortParam->m_iFrameSize)) { pPortParam->bAckRight = FALSE; @@ -3015,67 +3015,67 @@ void ProvBuban104FormatI(int commid, RTUMSG *rtumsg) } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// - pPortParam->wRecvSequence = ((rtumsg->MsgData[2] + (rtumsg->MsgData[3]<<8)) >> 1)+1; + pPortParam->wRecvSequence = ((rtumsg->MsgData[2] + (rtumsg->MsgData[3] << 8)) >> 1) + 1; pPortParam->wRecvSequence %= MAX_SEQUENCE; - switch(rtumsg->MsgData[6]) - { - case 1: // 单点遥信处理 - break; + switch (rtumsg->MsgData[6]) + { + case 1: // 单点遥信处理 + break; - case 2: // 单点遥信SOE处理 - break; + case 2: // 单点遥信SOE处理 + break; - case 3: // 双点遥信处理 - break; + case 3: // 双点遥信处理 + break; - case 4: // 单点遥信SOE处理 - break; + case 4: // 单点遥信SOE处理 + break; - case 5: // 变压器分接头位置 - break; - case 6: // 变压器分接头位置带时标 - break; - case 7: // 总召唤数据 - ProvBuban104SendAllData(commid, rtumsg); - break; + case 5: // 变压器分接头位置 + break; + case 6: // 变压器分接头位置带时标 + break; + case 7: // 总召唤数据 + ProvBuban104SendAllData(commid, rtumsg); + break; - case 9: // 带品质无时标遥测 - break; + case 9: // 带品质无时标遥测 + break; - case 10: // 带品质带时标遥测 - break; - - case 21: // 全遥测数据处理 或变化数据 - break; - - case 15: // 不带时标电度 - break; - case 16: // 带时标电度 - break; + case 10: // 带品质带时标遥测 + break; - case 17: - case 18: - case 19: // 保护数据 - break; + case 21: // 全遥测数据处理 或变化数据 + break; - case 45: // wen 2006.07.11 - case 46: // 遥控返校 - case 47: // 遥调返校 - //ProvBuban104YkYtData(commid, rtumsg); - break; + case 15: // 不带时标电度 + break; + case 16: // 带时标电度 + break; - case 100: // 召唤数据 - //ProvBuban104SendAllData(commid, rtumsg); - break; + case 17: + case 18: + case 19: // 保护数据 + break; - case 101: // 召唤电度 - //ProvBuban104SendPIData(commid, rtumsg); - break; - - case 103: // 时间同步确认帧 - //ProvBuban104ProcessTime(commid, rtumsg); - break; + case 45: // wen 2006.07.11 + case 46: // 遥控返校 + case 47: // 遥调返校 + //ProvBuban104YkYtData(commid, rtumsg); + break; + + case 100: // 召唤数据 + //ProvBuban104SendAllData(commid, rtumsg); + break; + + case 101: // 召唤电度 + //ProvBuban104SendPIData(commid, rtumsg); + break; + + case 103: // 时间同步确认帧 + //ProvBuban104ProcessTime(commid, rtumsg); + break; } } @@ -3084,44 +3084,44 @@ void ProvBuban104FormatU(int commid, RTUMSG *rtumsg) BUBAN104PORTPARAM *pPortParam; // length - if( rtumsg->MsgData[1] != 4 ) + if (rtumsg->MsgData[1] != 4) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - switch(rtumsg->MsgData[2] & 0xfc) - { - case 0x04: // 启动动作 - InitBuban104CommandBuffer(commid); - pPortParam->LinkOk = TRUE; - MakeBuban104Command(commid, FORMAT_U_START_CON); - break; - case 0x10: // 停止动作 - pPortParam->LinkOk = FALSE; - MakeBuban104Command(commid, FORMAT_U_STOP_CON); - break; - case 0x80: // 测试动作响应 - pPortParam->bAckRight = TRUE; - // 超时计数清零 - pPortParam->lTimeOutCnt = 0; - pPortParam->bCloseSocket = FALSE; - break; - case 0x40: // 测试动作 - //if(!pPortParam->LinkOk) - //{ - // break; - //} - pPortParam->LinkOk = TRUE; - MakeBuban104Command(commid, FORMAT_U_TEST_CON); - pPortParam->lTimeOutCnt = 0; - pPortParam->bCloseSocket = FALSE; - pPortParam->bAckRight = TRUE; - break; - default: // 错误的响应 - pPortParam->bAckRight = FALSE; - break; + switch (rtumsg->MsgData[2] & 0xfc) + { + case 0x04: // 启动动作 + InitBuban104CommandBuffer(commid); + pPortParam->LinkOk = TRUE; + MakeBuban104Command(commid, FORMAT_U_START_CON); + break; + case 0x10: // 停止动作 + pPortParam->LinkOk = FALSE; + MakeBuban104Command(commid, FORMAT_U_STOP_CON); + break; + case 0x80: // 测试动作响应 + pPortParam->bAckRight = TRUE; + // 超时计数清零 + pPortParam->lTimeOutCnt = 0; + pPortParam->bCloseSocket = FALSE; + break; + case 0x40: // 测试动作 + //if(!pPortParam->LinkOk) + //{ + // break; + //} + pPortParam->LinkOk = TRUE; + MakeBuban104Command(commid, FORMAT_U_TEST_CON); + pPortParam->lTimeOutCnt = 0; + pPortParam->bCloseSocket = FALSE; + pPortParam->bAckRight = TRUE; + break; + default: // 错误的响应 + pPortParam->bAckRight = FALSE; + break; } } @@ -3132,14 +3132,14 @@ void ProvBuban104FormatS(int commid, RTUMSG *rtumsg) BUBAN104PORTPARAM *pPortParam; // length - if( rtumsg->MsgData[1] != 4 ) + if (rtumsg->MsgData[1] != 4) { return; } pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - pPortParam->wAckSequence = (rtumsg->MsgData[4] + (rtumsg->MsgData[5]<<8)) >> 1; + pPortParam->wAckSequence = (rtumsg->MsgData[4] + (rtumsg->MsgData[5] << 8)) >> 1; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// // wen 2005.09.19 帧序匹配算法修改 @@ -3163,12 +3163,12 @@ void ProvBuban104FormatS(int commid, RTUMSG *rtumsg) */ iSequenceInc = pPortParam->wSendSequence - pPortParam->wAckSequence; - if(iSequenceInc < 0) + if (iSequenceInc < 0) { iSequenceInc += MAX_SEQUENCE; } //不大于帧序应答尺寸(缺省值=MAX_FRAMEMATCHING_SIZE) - if((pPortParam->wSendSequence == pPortParam->wAckSequence) + if ((pPortParam->wSendSequence == pPortParam->wAckSequence) || (iSequenceInc < pPortParam->m_iFrameSize)) { pPortParam->bAckRight = TRUE; @@ -3183,7 +3183,7 @@ void ProvBuban104FormatS(int commid, RTUMSG *rtumsg) void ProvBuban104SendAllData(int commid, RTUMSG * rtumsg) { char commandbuf[MAX_POLLCMD_BUF_LEN]; - int iGroup, iCmdType, iLen=0; + int iGroup, iCmdType, iLen = 0; WORD wTransCause; BUBAN104PORTPARAM *pPortParam; @@ -3193,7 +3193,7 @@ void ProvBuban104SendAllData(int commid, RTUMSG * rtumsg) wTransCause = rtumsg->MsgData[8]; iCmdType = FAST_POLL_CMD; - + //总召唤应答 /*commandbuf[0] = 0x68; iLen = 2; @@ -3212,7 +3212,7 @@ void ProvBuban104SendAllData(int commid, RTUMSG * rtumsg) commandbuf[1] = (BYTE)(iLen - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLen);*/ - + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2006.03.23 支持浮点数遥测的传送 //ProvBuban104SendAI(commid, rtumsg, 0); @@ -3398,7 +3398,7 @@ void ProvBuban104SendPIData(int commid, RTUMSG * rtumsg) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { iGroup = rtumsg->MsgData[12] & 0x3F; } @@ -3408,38 +3408,38 @@ void ProvBuban104SendPIData(int commid, RTUMSG * rtumsg) } // wen 2006.04.03 发布时间97版和2000版组分配不同 - if(pPortParam->m_iPublishYear == 1997) + if (pPortParam->m_iPublishYear == 1997) { //分组召唤 - if( iGroup != 1 ) + if (iGroup != 1) { //无效或者扩展组号 - if(( iGroup <= 0 ) || ( iGroup > 5 )) + if ((iGroup <= 0) || (iGroup > 5)) { return; } - - ProvBuban104SendPI(commid, rtumsg, iGroup-1); + + ProvBuban104SendPI(commid, rtumsg, iGroup - 1); return; } } else { //分组召唤 - if( iGroup != 5 ) + if (iGroup != 5) { //无效或者扩展组号 - if(( iGroup <= 0 ) || ( iGroup > 5 )) + if ((iGroup <= 0) || (iGroup > 5)) { return; } - + ProvBuban104SendPI(commid, rtumsg, iGroup); return; } } - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -3457,7 +3457,7 @@ void ProvBuban104SendPIData(int commid, RTUMSG * rtumsg) commandbuf[iLen++] = 0; commandbuf[iLen++] = 101; commandbuf[iLen++] = 0; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLen++] = 7; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); @@ -3491,7 +3491,7 @@ void ProvBuban104SendPIData(int commid, RTUMSG * rtumsg) commandbuf[iLen++] = 0; commandbuf[iLen++] = 101; commandbuf[iLen++] = 0; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLen++] = 10; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); @@ -3512,7 +3512,7 @@ void ProvBuban104SendPIData(int commid, RTUMSG * rtumsg) } commandbuf[1] = (BYTE)(iLen - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLen); - + pPortParam->Initdata = TRUE; } @@ -3526,103 +3526,103 @@ void ProvBuban104ProcessTime(int commid, RTUMSG *rtumsg) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { wTransCause = rtumsg->MsgData[8]; } else { - wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9]<<8); + wTransCause = rtumsg->MsgData[8] + (rtumsg->MsgData[9] << 8); } //传送原因 - switch(wTransCause) + switch (wTransCause) { - case 0x0006://激活(对时) - commandbuf[0] = 0x68; - //commandbuf[1] = 20; - iLen = 2; + case 0x0006://激活(对时) + commandbuf[0] = 0x68; + //commandbuf[1] = 20; + iLen = 2; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 103; + commandbuf[iLen++] = 1; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = 7; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; + } + else + { + commandbuf[iLen++] = 7; commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; - commandbuf[iLen++] = 103; - commandbuf[iLen++] = 1; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = 7; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - else - { - commandbuf[iLen++] = 7; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - GetLocalTimeEx(&sCurTime); - sCurTime.mSec = sCurTime.Sec * 1000 + sCurTime.mSec; - commandbuf[iLen++] = sCurTime.mSec % 256; - commandbuf[iLen++] = sCurTime.mSec / 256; - commandbuf[iLen++] = (u_char)sCurTime.Min; - commandbuf[iLen++] = (u_char)sCurTime.Hour; - commandbuf[iLen++] = (u_char)sCurTime.Day; - commandbuf[iLen++] = (u_char)sCurTime.Month; - commandbuf[iLen++] = (u_char)(sCurTime.Year%100); - commandbuf[1] = (BYTE)(iLen - 2); - if(pPortParam->ProvAckOrNot) + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + GetLocalTimeEx(&sCurTime); + sCurTime.mSec = sCurTime.Sec * 1000 + sCurTime.mSec; + commandbuf[iLen++] = sCurTime.mSec % 256; + commandbuf[iLen++] = sCurTime.mSec / 256; + commandbuf[iLen++] = (u_char)sCurTime.Min; + commandbuf[iLen++] = (u_char)sCurTime.Hour; + commandbuf[iLen++] = (u_char)sCurTime.Day; + commandbuf[iLen++] = (u_char)sCurTime.Month; + commandbuf[iLen++] = (u_char)(sCurTime.Year % 100); + commandbuf[1] = (BYTE)(iLen - 2); + if (pPortParam->ProvAckOrNot) + { + iCmdType = INSERT_POLL_CMD; + } + else + { + iCmdType = FAST_POLL_CMD; + } + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLen); + + // 对时 + if (1 == pPortParam->m_psBaoHu->CheckTime) + { + if (VER_BUBAN_104 == pPortParam->RtuVersion) { - iCmdType = INSERT_POLL_CMD; + sCurTime.mSec = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8); + sCurTime.Sec = sCurTime.mSec / 1000; + sCurTime.mSec = sCurTime.mSec % 1000; + sCurTime.Min = rtumsg->MsgData[14] & 0x3F; + sCurTime.Hour = rtumsg->MsgData[15] & 0x1F; + sCurTime.Day = rtumsg->MsgData[16] & 0x1F; + sCurTime.Month = rtumsg->MsgData[17] & 0x0F; + sCurTime.Year = (rtumsg->MsgData[18] & 0x7F) + 2000; } else { - iCmdType = FAST_POLL_CMD; - } - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLen); - - // 对时 - if(1 == pPortParam->m_psBaoHu->CheckTime) - { - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - sCurTime.mSec = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8); - sCurTime.Sec = sCurTime.mSec/1000; - sCurTime.mSec = sCurTime.mSec % 1000; - sCurTime.Min = rtumsg->MsgData[14] & 0x3F; - sCurTime.Hour = rtumsg->MsgData[15] & 0x1F; - sCurTime.Day = rtumsg->MsgData[16] & 0x1F; - sCurTime.Month= rtumsg->MsgData[17] & 0x0F; - sCurTime.Year = (rtumsg->MsgData[18] & 0x7F)+2000; - } - else - { - sCurTime.mSec = rtumsg->MsgData[15] + (rtumsg->MsgData[16] << 8); - sCurTime.Sec = sCurTime.mSec/1000; - sCurTime.mSec = sCurTime.mSec % 1000; - sCurTime.Min = rtumsg->MsgData[17] & 0x3F; - sCurTime.Hour = rtumsg->MsgData[18] & 0x1F; - sCurTime.Day = rtumsg->MsgData[19] & 0x1F; - sCurTime.Month= rtumsg->MsgData[20] & 0x0F; - sCurTime.Year = (rtumsg->MsgData[21] & 0x7F)+2000; - } - SetLocalTimeEx(&sCurTime); + sCurTime.mSec = rtumsg->MsgData[15] + (rtumsg->MsgData[16] << 8); + sCurTime.Sec = sCurTime.mSec / 1000; + sCurTime.mSec = sCurTime.mSec % 1000; + sCurTime.Min = rtumsg->MsgData[17] & 0x3F; + sCurTime.Hour = rtumsg->MsgData[18] & 0x1F; + sCurTime.Day = rtumsg->MsgData[19] & 0x1F; + sCurTime.Month = rtumsg->MsgData[20] & 0x0F; + sCurTime.Year = (rtumsg->MsgData[21] & 0x7F) + 2000; } - break; + SetLocalTimeEx(&sCurTime); + } + break; - case 0x07://激活确认 - break; + case 0x07://激活确认 + break; } } void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) { - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int i, j, iAllDataCount, iSendNum; int iNo; int iCmdType; @@ -3632,7 +3632,7 @@ void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -3641,40 +3641,40 @@ void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) iCmdType = FAST_POLL_CMD; } - if(iGroupNo == 0)//总召唤 + if (iGroupNo == 0)//总召唤 { - dwStartAddr = MAX_GROUP_PINUM*iGroupNo + pPortParam->iPiBaseAddr; + dwStartAddr = MAX_GROUP_PINUM * iGroupNo + pPortParam->iPiBaseAddr; iAllDataCount = pPortParam->m_psBaoHu->PiNum; - iSendCount = (iAllDataCount+MAX_104_PINUM-1)/MAX_104_PINUM; + iSendCount = (iAllDataCount + MAX_104_PINUM - 1) / MAX_104_PINUM; iCmdType = FAST_POLL_CMD; } else//分组召唤 { - dwStartAddr = MAX_GROUP_PINUM*(iGroupNo-1); + dwStartAddr = MAX_GROUP_PINUM * (iGroupNo - 1); iAllDataCount = pPortParam->m_psBaoHu->PiNum - dwStartAddr; - + dwStartAddr += pPortParam->iPiBaseAddr; - if( iAllDataCount > MAX_GROUP_PINUM) + if (iAllDataCount > MAX_GROUP_PINUM) { iSendCount = 2; - if((iAllDataCount - MAX_GROUP_PINUM)>0) + if ((iAllDataCount - MAX_GROUP_PINUM) > 0) iAllDataCount = MAX_GROUP_PINUM; } } piprovptr = (PROV_PI_PNT *)pPortParam->m_psBaoHu->PiPtr; - for(i = 0; i < iSendCount; i++) + for (i = 0; i < iSendCount; i++) { commandbuf[0] = 0x68; commandbuf[2] = 0; commandbuf[3] = 0; commandbuf[4] = 0; commandbuf[5] = 0; - commandbuf[6] = 15; - commandbuf[8] = 37+iGroupNo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + commandbuf[6] = 15; + commandbuf[8] = 37 + iGroupNo; + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); iLenth = 10; @@ -3687,7 +3687,7 @@ void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) iLenth = 12; } //遥测值 - if(iAllDataCount>MAX_104_PINUM) + if (iAllDataCount > MAX_104_PINUM) { iAllDataCount -= MAX_104_PINUM; iSendNum = MAX_104_PINUM; @@ -3697,18 +3697,18 @@ void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) iSendNum = iAllDataCount; } - for(j = 0; j < iSendNum; j++, dwStartAddr++) + for (j = 0; j < iSendNum; j++, dwStartAddr++) { - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLenth++] = (char)(dwStartAddr & 0x00ff); - commandbuf[iLenth++] = (char)((dwStartAddr & 0xff00)>>8); + commandbuf[iLenth++] = (char)((dwStartAddr & 0xff00) >> 8); } else { commandbuf[iLenth++] = (char)(dwStartAddr & 0x00ff); - commandbuf[iLenth++] = (char)((dwStartAddr & 0xff00)>>8); - commandbuf[iLenth++] = (char)((dwStartAddr & 0xff0000)>>16); + commandbuf[iLenth++] = (char)((dwStartAddr & 0xff00) >> 8); + commandbuf[iLenth++] = (char)((dwStartAddr & 0xff0000) >> 16); } iNo = dwStartAddr - pPortParam->iPiBaseAddr; @@ -3717,25 +3717,25 @@ void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) GetPntMsg(piprovptr[iNo].PortNo, piprovptr[iNo].PntNo, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); piprovptr[iNo].ChangeFlag = FALSE; - + commandbuf[iLenth++] = (char)(pntmsg.RawValue & 0x000000ff); - commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0x0000ff00)>>8); - commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0x00ff0000)>>16); - commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0xff000000)>>24); - commandbuf[iLenth++] = (char)(j+1); + commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0x0000ff00) >> 8); + commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0x00ff0000) >> 16); + commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0xff000000) >> 24); + commandbuf[iLenth++] = (char)(j + 1); } commandbuf[7] = (BYTE)j; - commandbuf[1] = (char)(iLenth-2); + commandbuf[1] = (char)(iLenth - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } } void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) { - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int i, j, iAllDataCount, iSendNum; int iNo, iCmdType; AI_DEF pntmsg; @@ -3744,7 +3744,7 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -3753,24 +3753,24 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) iCmdType = FAST_POLL_CMD; } - if( iGroupNo == 0 )//总召唤 + if (iGroupNo == 0)//总召唤 { - dwStartAddr = MAX_GROUP_AINUM*iGroupNo + pPortParam->iAiBaseAddr; + dwStartAddr = MAX_GROUP_AINUM * iGroupNo + pPortParam->iAiBaseAddr; iAllDataCount = pPortParam->m_psBaoHu->AiNum; - iSendCount = (iAllDataCount+MAX_AINUM-1)/MAX_AINUM; + iSendCount = (iAllDataCount + MAX_AINUM - 1) / MAX_AINUM; iCmdType = FAST_POLL_CMD; } else//分组召唤 { - dwStartAddr = MAX_GROUP_AINUM*(iGroupNo-1); - iAllDataCount = pPortParam->m_psBaoHu->AiNum - dwStartAddr; + dwStartAddr = MAX_GROUP_AINUM * (iGroupNo - 1); + iAllDataCount = pPortParam->m_psBaoHu->AiNum - dwStartAddr; dwStartAddr += pPortParam->iAiBaseAddr; - - if(iAllDataCount > MAX_AINUM) + + if (iAllDataCount > MAX_AINUM) { iSendCount = 2; - if((iAllDataCount - MAX_GROUP_AINUM) > 0) + if ((iAllDataCount - MAX_GROUP_AINUM) > 0) { iAllDataCount = MAX_GROUP_AINUM; } @@ -3778,17 +3778,17 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) } aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; - for( i = 0; i < iSendCount; i++ ) + for (i = 0; i < iSendCount; i++) { commandbuf[0] = 0x68; commandbuf[2] = 0; commandbuf[3] = 0; commandbuf[4] = 0; commandbuf[5] = 0; - commandbuf[6] = 21; + commandbuf[6] = 21; //commandbuf[8] = rtumsg->MsgData[15]; commandbuf[8] = rtumsg->MsgData[8]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); // 信息体地址为2个字节 @@ -3811,10 +3811,10 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) } //遥测值 - if(iAllDataCount > MAX_AINUM) + if (iAllDataCount > MAX_AINUM) { iAllDataCount -= MAX_AINUM; - iSendNum = MAX_AINUM; + iSendNum = MAX_AINUM; } else { @@ -3822,19 +3822,19 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) } iNo = dwStartAddr - pPortParam->iAiBaseAddr; - for( j = 0; j < iSendNum; j++ ) + for (j = 0; j < iSendNum; j++) { - GetPntMsg(aiprovptr[iNo+j].PortNo, aiprovptr[iNo+j].PntNo, + GetPntMsg(aiprovptr[iNo + j].PortNo, aiprovptr[iNo + j].PntNo, &pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); - aiprovptr[iNo+j].ChangeFlag = FALSE; + aiprovptr[iNo + j].ChangeFlag = FALSE; commandbuf[iLenth++] = (char)(pntmsg.RawValue); - commandbuf[iLenth++] = (char)((pntmsg.RawValue&0xff00)>>8); + commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0xff00) >> 8); } commandbuf[7] = (BYTE)j; commandbuf[7] |= 0x80; - commandbuf[1] = (char)(iLenth-2); - + commandbuf[1] = (char)(iLenth - 2); + PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); dwStartAddr += MAX_AINUM; @@ -3844,9 +3844,9 @@ void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) { char commandbuf[MAX_POLLCMD_BUF_LEN]; - + DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int i, j, iAllDataCount, iSendNum; int iNo, iCmdType; DI_DEF pntmsg; @@ -3855,7 +3855,7 @@ void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -3864,29 +3864,29 @@ void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) iCmdType = FAST_POLL_CMD; } - if(iGroupNo == 0)//总召唤 + if (iGroupNo == 0)//总召唤 { - dwStartAddr = MAX_GROUP_DINUM*iGroupNo + pPortParam->iDiBaseAddr; + dwStartAddr = MAX_GROUP_DINUM * iGroupNo + pPortParam->iDiBaseAddr; iAllDataCount = pPortParam->m_psBaoHu->DiNum; - iSendCount = (iAllDataCount+MAX_DINUM-1)/MAX_DINUM; + iSendCount = (iAllDataCount + MAX_DINUM - 1) / MAX_DINUM; iCmdType = FAST_POLL_CMD; } else//分组召唤 { - dwStartAddr = MAX_GROUP_DINUM*(iGroupNo-1); + dwStartAddr = MAX_GROUP_DINUM * (iGroupNo - 1); iAllDataCount = pPortParam->m_psBaoHu->DiNum - dwStartAddr; - + dwStartAddr += pPortParam->iDiBaseAddr; - if( iAllDataCount > MAX_GROUP_DINUM) + if (iAllDataCount > MAX_GROUP_DINUM) { iAllDataCount = MAX_GROUP_DINUM; } } diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; - for(i=0; iMsgData[12]; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); commandbuf[10] = LOBYTE(LOWORD(dwStartAddr)); @@ -3915,10 +3915,10 @@ void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) iLenth = 15; } - if(iAllDataCount > MAX_DINUM) + if (iAllDataCount > MAX_DINUM) { iAllDataCount -= MAX_DINUM; - iSendNum = MAX_DINUM; + iSendNum = MAX_DINUM; } else { @@ -3926,20 +3926,20 @@ void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) } iNo = dwStartAddr - pPortParam->iDiBaseAddr; - for( j = 0; j < iSendNum; j++ ) + for (j = 0; j < iSendNum; j++) { - GetPntMsg(diprovptr[iNo+j].PortNo, diprovptr[iNo+j].PntNo, + GetPntMsg(diprovptr[iNo + j].PortNo, diprovptr[iNo + j].PntNo, &pntmsg, DI_PNT_TYPE, PNT_STATUS); - diprovptr[iNo+j].ChangeFlag = FALSE; + diprovptr[iNo + j].ChangeFlag = FALSE; commandbuf[iLenth++] = pntmsg.Status; } commandbuf[7] = (char)j; commandbuf[7] |= 0x80; - commandbuf[1] = (char)(iLenth-2); - + commandbuf[1] = (char)(iLenth - 2); + PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); - + dwStartAddr += MAX_DINUM; } } @@ -3951,19 +3951,19 @@ void ProvBuban104SendSoe(int commid) BOOL bHaveData = FALSE; WORD wmSec; DWORD dwAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int iDataNum, iCmdType; SOE_DEF soemsg; BUBAN104PORTPARAM *pPortParam; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(ProvHaveSoeData(commid) <= 0) + if (ProvHaveSoeData(commid) <= 0) { return; } - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -3979,7 +3979,7 @@ void ProvBuban104SendSoe(int commid) commandbuf[5] = 0; commandbuf[6] = 2;//单点soe commandbuf[8] = 3; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); } @@ -3987,7 +3987,7 @@ void ProvBuban104SendSoe(int commid) { commandbuf[9] = 0; commandbuf[10] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); } bHaveData = TRUE; @@ -4000,7 +4000,7 @@ void ProvBuban104SendSoe(int commid) { iDataNum++; dwAddr = (DWORD)(pPortParam->iDiBaseAddr+soemsg.iPntNo); - + commandbuf[iLenth++] = LOBYTE(LOWORD(dwAddr)); commandbuf[iLenth++] = HIBYTE(LOWORD(dwAddr)); if(VER_IEC870_5_104 == pPortParam->RtuVersion) @@ -4018,24 +4018,24 @@ void ProvBuban104SendSoe(int commid) } }*/ //=========================================================== - while(ProvHaveSoeData(commid) > 0) + while (ProvHaveSoeData(commid) > 0) { ProvAndDelGetSoeData(commid, &soemsg); iDataNum++; - dwAddr = (DWORD)(pPortParam->iDiBaseAddr+soemsg.iPntNo); - + dwAddr = (DWORD)(pPortParam->iDiBaseAddr + soemsg.iPntNo); + commandbuf[iLenth++] = LOBYTE(LOWORD(dwAddr)); commandbuf[iLenth++] = HIBYTE(LOWORD(dwAddr)); - if(VER_IEC870_5_104 == pPortParam->RtuVersion) + if (VER_IEC870_5_104 == pPortParam->RtuVersion) { commandbuf[iLenth++] = LOBYTE(HIWORD(dwAddr)); } commandbuf[iLenth++] = soemsg.bStatus; - wmSec = soemsg.SoeTime.mSec + soemsg.SoeTime.Sec*1000; + wmSec = soemsg.SoeTime.mSec + soemsg.SoeTime.Sec * 1000; commandbuf[iLenth++] = LOBYTE(wmSec); commandbuf[iLenth++] = HIBYTE(wmSec); commandbuf[iLenth++] = soemsg.SoeTime.Min & 0x3f; - if(iLenth >= 248) + if (iLenth >= 248) { break; } @@ -4043,14 +4043,14 @@ void ProvBuban104SendSoe(int commid) //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ commandbuf[7] = (BYTE)iDataNum; - commandbuf[1] = (BYTE)(iLenth-2); + commandbuf[1] = (BYTE)(iLenth - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) { PROV_DI_PNT *diprovptr; - DI_DEF *diptr; + DI_DEF *diptr; int ykytcommid, provpnt; int ykytpnt, ykytop, step; BYTE bYkOperate; @@ -4062,36 +4062,36 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) ykytop = 3; pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { bYkOperate = rtumsg->MsgData[12]; - ykytpnt = rtumsg->MsgData[10] + (rtumsg->MsgData[11]<<8); + ykytpnt = rtumsg->MsgData[10] + (rtumsg->MsgData[11] << 8); } else { bYkOperate = rtumsg->MsgData[15]; // wen 2005.11.27 修改最高字节信息体地址不做判断 //ykytpnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13]<<8) + (rtumsg->MsgData[14]<<16); - ykytpnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13]<<8); + ykytpnt = rtumsg->MsgData[12] + (rtumsg->MsgData[13] << 8); } - if(rtumsg->MsgData[8] == 8) + if (rtumsg->MsgData[8] == 8) { step = STEP_YKYT_CANCEL; } else { - if(bYkOperate & 0x80) //选择返校 + if (bYkOperate & 0x80) //选择返校 { step = STEP_YKYT_SELECT; } else { - step = STEP_YKYT_EXEC; + step = STEP_YKYT_EXEC; } } - - if(ShmGetDispYkYtFlag()) + + if (ShmGetDispYkYtFlag()) { #ifdef _WIN32 printf("TIP_(%04d): commid =%d recv ykyt select.\n", _getpid(), commid); @@ -4103,12 +4103,12 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) ykytpnt -= pPortParam->iYkBaseAddr; ykytpnt += 1; - if(rtumsg->MsgData[6] == 45) + if (rtumsg->MsgData[6] == 45) { // ykytop == 1 控合, == 2 控分 ykytop = ((bYkOperate & 0x03) == 1) ? 1 : 2; } - else if(rtumsg->MsgData[6] == 46) + else if (rtumsg->MsgData[6] == 46) { ykytop = ((bYkOperate & 0x03) == 2) ? 1 : 2; } @@ -4118,28 +4118,28 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) MakeProvBuban104YkYtAckMsg(commid, ykytpnt, 3, step); return; } - + provpnt = FindProvPntFromYkYtPnt(commid, ykytpnt, pPortParam->m_psBaoHu); - if(provpnt < 0) // 控点号错 + if (provpnt < 0) // 控点号错 { - sprintf(szbuf, "WARN(%04d): 控点错误.\n", _getpid()); - DebugPrint(szbuf); + sprintf(szbuf, "WARN(%04d): 控点错误.\n", _getpid()); + DebugPrint(szbuf); MakeProvBuban104YkYtAckMsg(commid, ykytpnt, 3, step); } else { diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; ykytcommid = diprovptr[provpnt].PortNo; - if(!SioParam[ykytcommid].m_psBaoHu) + if (!SioParam[ykytcommid].m_psBaoHu) { MakeProvBuban104YkYtAckMsg(commid, ykytpnt, 3, step); return; } - if(!SioParam[ykytcommid].m_psBaoHu->DiPtr) + if (!SioParam[ykytcommid].m_psBaoHu->DiPtr) { - sprintf(szbuf, "WARN(%04d): 没有控点m_psBaoHu->DiPtr=NULL.\n", _getpid()); - DebugPrint(szbuf); + sprintf(szbuf, "WARN(%04d): 没有控点m_psBaoHu->DiPtr=NULL.\n", _getpid()); + DebugPrint(szbuf); MakeProvBuban104YkYtAckMsg(commid, ykytpnt, 3, step); return; } @@ -4147,19 +4147,19 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) diptr = (DI_DEF *)SioParam[ykytcommid].m_psBaoHu->DiPtr; // 如果对应点没有控点或者控点不相等 - if(!diptr[diprovptr[provpnt].PntNo].CtrlEnable) + if (!diptr[diprovptr[provpnt].PntNo].CtrlEnable) { - sprintf(szbuf, "WARN(%04d): 对应点没有控点或者控点不相等.\n", _getpid()); - DebugPrint(szbuf); + sprintf(szbuf, "WARN(%04d): 对应点没有控点或者控点不相等.\n", _getpid()); + DebugPrint(szbuf); MakeProvBuban104YkYtAckMsg(commid, ykytpnt, 3, step); return; } - if(STEP_YKYT_SELECT == step) + if (STEP_YKYT_SELECT == step) { - if(STEP_YKYT_SELECT == SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtStep) + if (STEP_YKYT_SELECT == SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtStep) { - if(!ProvPortYkYtIsTimeOut(ykytcommid, &SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg)) + if (!ProvPortYkYtIsTimeOut(ykytcommid, &SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg)) { sprintf(szbuf, "WARN(%04d): 超时 failed.\n", _getpid()); DebugPrint(szbuf); @@ -4205,7 +4205,7 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) YkYtParam.m_iYkYtUpDown = YKYT_SEND_DOWN; SendYkYtCommand2(ykytcommid, &YkYtParam); - if(STEP_YKYT_EXEC == step) + if (STEP_YKYT_EXEC == step) { MakeProvBuban104YkYtAckMsg(commid, ykytpnt, ykytop, step); MakeProvBuban104YkYtAckMsg(commid, ykytpnt, ykytop, STEP_YKYT_NOEXEC); @@ -4216,31 +4216,31 @@ void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg) void MakeProvBuban104YkYtAckMsg(int commid, int pnt, int op, int step) { int iCount, ykpoint, iLen; - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; BUBAN104PORTPARAM *pPortParam; - + pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; memset(commandbuf, 0, sizeof(commandbuf)); iCount = 4; commandbuf[0] = 0x68; commandbuf[1] = 14; - switch(pPortParam->YkMode) + switch (pPortParam->YkMode) { - case CONTROL_SINGAL: // 单点控制 - commandbuf[6] = 45; - break; - case CONTROL_DOUBLE: // 双点控制 - case CONTROL_DIRECT: // 直接控制 - commandbuf[6] = 46; // 47; - break; + case CONTROL_SINGAL: // 单点控制 + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // 双点控制 + case CONTROL_DIRECT: // 直接控制 + commandbuf[6] = 46; // 47; + break; } commandbuf[7] = 1; //commandbuf[8];// 传送原因 iLen = 9; - ykpoint = (pnt-1) + pPortParam->iYkBaseAddr; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + ykpoint = (pnt - 1) + pPortParam->iYkBaseAddr; + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = LOBYTE(LOWORD(ykpoint)); @@ -4248,66 +4248,66 @@ void MakeProvBuban104YkYtAckMsg(int commid, int pnt, int op, int step) } else { - commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = LOBYTE(LOWORD(ykpoint)); commandbuf[iLen++] = HIBYTE(LOWORD(ykpoint)); commandbuf[iLen++] = LOBYTE(HIWORD(ykpoint)); } - - switch(step) + + switch (step) { - case STEP_YKYT_SELECT: // 选择 - commandbuf[8] = 7; - commandbuf[iLen] = 0xfc; - break; - - case STEP_YKYT_EXEC: // 执行 - commandbuf[8] = 7; - commandbuf[iLen] = 0x7c; - break; - - case STEP_YKYT_CANCEL: // 撤销 - commandbuf[8] = 9; - commandbuf[iLen] = 0xfc; - break; + case STEP_YKYT_SELECT: // 选择 + commandbuf[8] = 7; + commandbuf[iLen] = 0xfc; + break; - default:// 结束帧 - commandbuf[8] = 10; - commandbuf[iLen] = 0; - break; + case STEP_YKYT_EXEC: // 执行 + commandbuf[8] = 7; + commandbuf[iLen] = 0x7c; + break; + + case STEP_YKYT_CANCEL: // 撤销 + commandbuf[8] = 9; + commandbuf[iLen] = 0xfc; + break; + + default:// 结束帧 + commandbuf[8] = 10; + commandbuf[iLen] = 0; + break; } // DCS/RCS - switch(op) + switch (op) { - case 1: // 选择合 - if(CONTROL_SINGAL == pPortParam->YkMode) - { - commandbuf[iLen] |= 1; - } - else - { - commandbuf[iLen] |= 2; - } - break; - case 2: // 选择分 - if(CONTROL_SINGAL != pPortParam->YkMode) - { - commandbuf[iLen] |= 1; - } - break; - case 3: // 选择失败 - default: - commandbuf[8] |= 0x40; - break; + case 1: // 选择合 + if (CONTROL_SINGAL == pPortParam->YkMode) + { + commandbuf[iLen] |= 1; + } + else + { + commandbuf[iLen] |= 2; + } + break; + case 2: // 选择分 + if (CONTROL_SINGAL != pPortParam->YkMode) + { + commandbuf[iLen] |= 1; + } + break; + case 3: // 选择失败 + default: + commandbuf[8] |= 0x40; + break; } - + iLen++; PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, iLen); - if(ShmGetDispYkYtFlag()) + if (ShmGetDispYkYtFlag()) { printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", _getpid(), commid, pnt, op); } @@ -4317,7 +4317,7 @@ void ProvBuban104SendClass1(int commid) { char commandbuf[MAX_POLLCMD_BUF_LEN]; DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int j, iDataNum, iCmdType; DI_DEF pntmsg; PROV_DI_PNT *diprovptr; @@ -4325,12 +4325,12 @@ void ProvBuban104SendClass1(int commid) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(!pPortParam->m_psBaoHu->DiChange) + if (!pPortParam->m_psBaoHu->DiChange) { return; } - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -4349,7 +4349,7 @@ void ProvBuban104SendClass1(int commid) commandbuf[5] = 0; commandbuf[6] = 1;//=3,为双点 commandbuf[8] = 3; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); iLenth = 10; @@ -4358,40 +4358,40 @@ void ProvBuban104SendClass1(int commid) { commandbuf[9] = 0; commandbuf[10] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); iLenth = 12; } diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; - for(j = 0, iDataNum = 0; jm_psBaoHu->DiNum; j++) + for (j = 0, iDataNum = 0; j < pPortParam->m_psBaoHu->DiNum; j++) { - if(diprovptr[j].ChangeFlag) + if (diprovptr[j].ChangeFlag) { iDataNum++; - commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr+j)); - commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr+j)); - if(VER_IEC870_5_104 == pPortParam->RtuVersion) + commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr + j)); + commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr + j)); + if (VER_IEC870_5_104 == pPortParam->RtuVersion) { - commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr+j)); + commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr + j)); } GetPntMsg(diprovptr[j].PortNo, diprovptr[j].PntNo, &pntmsg, DI_PNT_TYPE, PNT_STATUS); diprovptr[j].ChangeFlag = FALSE; commandbuf[iLenth++] = pntmsg.Status; - if(iLenth > 256) + if (iLenth > 256) { break; } } } - if(j >= pPortParam->m_psBaoHu->DiNum) + if (j >= pPortParam->m_psBaoHu->DiNum) { pPortParam->m_psBaoHu->DiChange = FALSE; } commandbuf[7] = (char)iDataNum; - commandbuf[1] = (char)(iLenth-2); + commandbuf[1] = (char)(iLenth - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } @@ -4401,7 +4401,7 @@ void ProvBuban104SendClass2(int commid) BOOL bHaveData = FALSE; DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int j, iDataNum, iCmdType; AI_DEF pntmsg; PROV_AI_PNT *aiprovptr; @@ -4409,12 +4409,12 @@ void ProvBuban104SendClass2(int commid) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(!pPortParam->m_psBaoHu->AiChange) + if (!pPortParam->m_psBaoHu->AiChange) { return; } - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -4430,7 +4430,7 @@ void ProvBuban104SendClass2(int commid) commandbuf[5] = 0; commandbuf[6] = 21; commandbuf[8] = 3; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); iLenth = 10; @@ -4439,51 +4439,51 @@ void ProvBuban104SendClass2(int commid) { commandbuf[9] = 0; commandbuf[10] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); iLenth = 12; } - + // wen 2005.01.15 修改数据信息体起始地址 dwStartAddr = pPortParam->iAiBaseAddr; commandbuf[6] = 21; //遥测值 aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; - for(j = 0, iDataNum = 0; j < pPortParam->m_psBaoHu->AiNum; j++) + for (j = 0, iDataNum = 0; j < pPortParam->m_psBaoHu->AiNum; j++) { - if(aiprovptr[j].ChangeFlag) + if (aiprovptr[j].ChangeFlag) { iDataNum++; bHaveData = TRUE; - commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr+j)); - commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr+j)); - if(VER_IEC870_5_104 == pPortParam->RtuVersion) + commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr + j)); + commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr + j)); + if (VER_IEC870_5_104 == pPortParam->RtuVersion) { - commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr+j)); + commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr + j)); } GetPntMsg(aiprovptr[j].PortNo, aiprovptr[j].PntNo, &pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); aiprovptr[j].ChangeFlag = FALSE; commandbuf[iLenth++] = (char)(pntmsg.RawValue); - commandbuf[iLenth++] = (char)((pntmsg.RawValue&0xff00)>>8); + commandbuf[iLenth++] = (char)((pntmsg.RawValue & 0xff00) >> 8); - if(iLenth >= 251) + if (iLenth >= 251) { break; } } } - if(j >= pPortParam->m_psBaoHu->AiNum) + if (j >= pPortParam->m_psBaoHu->AiNum) { pPortParam->m_psBaoHu->AiChange = false; } - if(bHaveData) + if (bHaveData) { commandbuf[7] = (char)iDataNum; - commandbuf[1] = (char)(iLenth-2); + commandbuf[1] = (char)(iLenth - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } } @@ -4496,85 +4496,85 @@ void ProvMakeBuban104Command(int commid, u_char cmdidx) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - switch(cmdidx) - { - case ASK_SECOND_DATA: // 召唤2级数据 - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // wen 2006.03.23 支持浮点数遥测的传送 - //ProvBuban104SendClass2(commid); - //==================================================================== - if(pPortParam->m_bProvAiType == 13) - { - ProvBuban104SendClass2withFloat(commid); - } - else - { - ProvBuban104SendClass2(commid); - } - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - break; + switch (cmdidx) + { + case ASK_SECOND_DATA: // 召唤2级数据 + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // wen 2006.03.23 支持浮点数遥测的传送 + //ProvBuban104SendClass2(commid); + //==================================================================== + if (pPortParam->m_bProvAiType == 13) + { + ProvBuban104SendClass2withFloat(commid); + } + else + { + ProvBuban104SendClass2(commid); + } + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + break; - case ASK_FIRST_DATA: // 召唤1级数据 - ProvBuban104SendClass1(commid); - break; + case ASK_FIRST_DATA: // 召唤1级数据 + ProvBuban104SendClass1(commid); + break; - case ASK_ALLDATA_END: // 总召唤结束帧 - commandbuf[0] = 0x68; - //commandbuf[iLen++] = 14; - iLen = 2; + case ASK_ALLDATA_END: // 总召唤结束帧 + commandbuf[0] = 0x68; + //commandbuf[iLen++] = 14; + iLen = 2; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 100; + commandbuf[iLen++] = 1; + commandbuf[iLen++] = 10; + if (VER_BUBAN_104 == pPortParam->RtuVersion) + { + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; commandbuf[iLen++] = 0; + } + else + { commandbuf[iLen++] = 0; + commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); + commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); commandbuf[iLen++] = 0; - commandbuf[iLen++] = 100; - commandbuf[iLen++] = 1; - commandbuf[iLen++] = 10; - if(VER_BUBAN_104 == pPortParam->RtuVersion) - { - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - else - { - commandbuf[iLen++] = 0; - commandbuf[iLen++] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = HIBYTE(pPortParam->wLinkAddr); - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - commandbuf[iLen++] = 0; - } - commandbuf[iLen++] = 0x14; - commandbuf[1] = (BYTE)(iLen - 2); - if(pPortParam->ProvAckOrNot) - { - PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, (char *)commandbuf, iLen); - } - else - { - PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLen); - } - pPortParam->Initdata = TRUE; - break; + commandbuf[iLen++] = 0; + commandbuf[iLen++] = 0; + } + commandbuf[iLen++] = 0x14; + commandbuf[1] = (BYTE)(iLen - 2); + if (pPortParam->ProvAckOrNot) + { + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, (char *)commandbuf, iLen); + } + else + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLen); + } + pPortParam->Initdata = TRUE; + break; - case RTU_TIME: // 时间同步 - break; + case RTU_TIME: // 时间同步 + break; - case ASK_DI_DATA: // 召唤2级数据YX - break; + case ASK_DI_DATA: // 召唤2级数据YX + break; - case ASK_AI_DATA: // 召唤2级数据YC - break; + case ASK_AI_DATA: // 召唤2级数据YC + break; - case ASK_PI_DATA: // 召唤2级数据YM - break; + case ASK_PI_DATA: // 召唤2级数据YM + break; - case ASK_PI: //召唤电度量 - break; + case ASK_PI: //召唤电度量 + break; - case ASK_ALL_DATA: // 召唤初始化数据 - break; - } + case ASK_ALL_DATA: // 召唤初始化数据 + break; + } } /* int j // 对应数据库数据点号 @@ -4615,11 +4615,11 @@ int GetAIPntMsg(int j, int *igno, int* iItemNo, DAY_TIME* sCurTime, float* pfVal void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) { - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; //DWORD dwStartAddr; - int iLenth, iSendCount=1, iaddr0=1, iaddr1=1; - int i, j, iAllDataCount, iSendNum,flag; - int iNo, iCmdType, igno,iItemNo; + int iLenth, iSendCount = 1, iaddr0 = 1, iaddr1 = 1, ibyid = 11827; + int i, j, iAllDataCount, iSendNum, flag; + int iNo, iCmdType, igno, iItemNo; float *pfValue; DAY_TIME sCurTime; AI_DEF pntmsg; @@ -4630,7 +4630,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) iCmdType = FAST_POLL_CMD; - if( iGroupNo == 0 )//总召唤 + if (iGroupNo == 0)//总召唤 { //dwStartAddr = MAX_GROUP_AINUM*iGroupNo + pPortParam->iAiBaseAddr; @@ -4639,7 +4639,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) } //aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; - for( i = 0; i < iAllDataCount; /*i++*/ ) + for (i = 0; i < iAllDataCount; /*i++*/) { memset(commandbuf, 0, sizeof(commandbuf)); commandbuf[0] = 0x68; @@ -4657,38 +4657,49 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) commandbuf[13] = 0; // 返回信息标识码RII //遥测值 - if(iAllDataCount-i > MAX_FLOATAINUM) + if (iAllDataCount - i > MAX_FLOATAINUM) { - iSendNum = MAX_FLOATAINUM; - commandbuf[14] = (iSendNum & 0x80); // 通用分类数据集数目NGD + iSendNum = MAX_FLOATAINUM; + commandbuf[14] = (iSendNum | 0x80); // 通用分类数据集数目NGD } else { - iSendNum = iAllDataCount-i; + iSendNum = iAllDataCount - i; commandbuf[14] = iSendNum; // 通用分类数据集数目NGD } iNo = i; iLenth = 15; - for( j = 0; j < iSendNum; j++ ) + for (j = 0; j < iSendNum; j++) { - pfValue = (float *)&commandbuf[iLenth+14]; - flag = GetAIPntMsg(j+iNo, (unsigned int*)&igno, (unsigned int*)&iItemNo, &sCurTime, pfValue, (unsigned int*)&iaddr1); + pfValue = (float *)&commandbuf[iLenth + 13]; + flag = GetAIPntMsg(j + iNo, (unsigned int*)&igno, (unsigned int*)&iItemNo, &sCurTime, pfValue, (unsigned int*)&iaddr1); if (0 == flag) break; if (-1 == flag) continue; + if (0 == j) + { + commandbuf[9] = (u_char)iaddr1; // + commandbuf[10] = (u_char)(iaddr1 >> 8); // 应用服务数据单元公共地址 + } if (iaddr1 == iaddr0) - ; + { + ; //commandbuf[9] = (u_char)iaddr0; // + //commandbuf[10] = (u_char)(iaddr0 >> 8); // 应用服务数据单元公共地址 + } else { iaddr0 = iaddr1; if (15 == iLenth) - ; + { + ; //commandbuf[9] = (u_char)iaddr0; // + //commandbuf[10] = (u_char)(iaddr0 >> 8); // 应用服务数据单元公共地址 + } else break; } - commandbuf[iLenth] = igno; + commandbuf[iLenth++] = igno; commandbuf[iLenth++] = iItemNo; commandbuf[iLenth++] = 1; // 描述类别KOD(实际值) commandbuf[iLenth++] = 7; // 数据类型 @@ -4701,38 +4712,41 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) commandbuf[iLenth++] = (u_char)sCurTime.Day; commandbuf[iLenth++] = (u_char)sCurTime.Month; commandbuf[iLenth++] = (u_char)(sCurTime.Year % 100); - iLenth += 12; + iLenth += 8; //*pfValue = SequenceHostToRtufloat((float)((int)pntmsg.RawValue)); //iLenth += sizeof(float); - //commandbuf[iLenth++] = 0; + commandbuf[iLenth++] = (u_char)ibyid; + commandbuf[iLenth++] = (u_char)(ibyid >> 8); + commandbuf[iLenth++] = (u_char)(ibyid >> 16); + commandbuf[iLenth++] = (u_char)(ibyid >> 24); } if (15 == iLenth) break; - commandbuf[9] = (u_char)iaddr0; // - commandbuf[10] = (u_char)(iaddr0 >> 8); // 应用服务数据单元公共地址 i += j; if (flag == 0) { + printf("get total %d item!\n", i); i = iAllDataCount; } - if(i >= iAllDataCount) + if (i >= iAllDataCount) { commandbuf[14] = j; // 通用分类数据集数目NGD } else - commandbuf[14] = (j & 0x80); // 通用分类数据集数目NGD + commandbuf[14] = (j | 0x80); // 通用分类数据集数目NGD + + commandbuf[1] = (char)(iLenth - 2); - commandbuf[1] = (char)(iLenth-2); - PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } + //printf("get total %d item!\n", i); } /*void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) { - char commandbuf[MAX_POLLCMD_BUF_LEN]; + char commandbuf[MAX_POLLCMD_BUF_LEN]; DWORD dwStartAddr; int iLenth, iSendCount=1; int i, j, iAllDataCount, iSendNum; @@ -4764,9 +4778,9 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) else//分组召唤 { dwStartAddr = MAX_GROUP_AINUM*(iGroupNo-1); - iAllDataCount = pPortParam->m_psBaoHu->AiNum - dwStartAddr; + iAllDataCount = pPortParam->m_psBaoHu->AiNum - dwStartAddr; dwStartAddr += pPortParam->iAiBaseAddr; - + if(iAllDataCount > MAX_FLOATAINUM) { iSendCount = 2; @@ -4785,7 +4799,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) commandbuf[3] = 0; commandbuf[4] = 0; commandbuf[5] = 0; - commandbuf[6] = 13; + commandbuf[6] = 13; //commandbuf[8] = rtumsg->MsgData[15]; commandbuf[8] = rtumsg->MsgData[8]; if(VER_BUBAN_104 == pPortParam->RtuVersion) @@ -4814,7 +4828,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) if(iAllDataCount > MAX_FLOATAINUM) { iAllDataCount -= MAX_FLOATAINUM; - iSendNum = MAX_FLOATAINUM; + iSendNum = MAX_FLOATAINUM; } else { @@ -4828,7 +4842,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) &pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); aiprovptr[iNo+j].ChangeFlag = FALSE; pfValue = (float *)&commandbuf[iLenth]; - + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // wen 2006.07.13 修改负数的传送 //*pfValue = SequenceHostToRtufloat((float)pntmsg.RawValue); @@ -4843,7 +4857,7 @@ void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo) commandbuf[7] = (BYTE)j; commandbuf[7] |= 0x80; commandbuf[1] = (char)(iLenth-2); - + PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); dwStartAddr += MAX_FLOATAINUM; @@ -4857,7 +4871,7 @@ void ProvBuban104SendClass2withFloat(int commid) BOOL bHaveData = FALSE; DWORD dwStartAddr; - int iLenth, iSendCount=1; + int iLenth, iSendCount = 1; int j, iDataNum, iCmdType; float *pfValue; AI_DEF pntmsg; @@ -4866,12 +4880,12 @@ void ProvBuban104SendClass2withFloat(int commid) pPortParam = (BUBAN104PORTPARAM *)SioParam[commid].ExtInfo; - if(!pPortParam->m_psBaoHu->AiChange) + if (!pPortParam->m_psBaoHu->AiChange) { return; } - if(pPortParam->ProvAckOrNot) + if (pPortParam->ProvAckOrNot) { iCmdType = NORMAL_POLL_CMD; } @@ -4887,7 +4901,7 @@ void ProvBuban104SendClass2withFloat(int commid) commandbuf[5] = 0; commandbuf[6] = 21; commandbuf[8] = 3; - if(VER_BUBAN_104 == pPortParam->RtuVersion) + if (VER_BUBAN_104 == pPortParam->RtuVersion) { commandbuf[9] = LOBYTE(pPortParam->wLinkAddr); iLenth = 10; @@ -4896,27 +4910,27 @@ void ProvBuban104SendClass2withFloat(int commid) { commandbuf[9] = 0; commandbuf[10] = LOBYTE(pPortParam->wLinkAddr); - commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); + commandbuf[11] = HIBYTE(pPortParam->wLinkAddr); iLenth = 12; } - + // wen 2005.01.15 修改数据信息体起始地址 dwStartAddr = pPortParam->iAiBaseAddr; commandbuf[6] = 13; //遥测值 aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; - for(j = 0, iDataNum = 0; j < pPortParam->m_psBaoHu->AiNum; j++) + for (j = 0, iDataNum = 0; j < pPortParam->m_psBaoHu->AiNum; j++) { - if(aiprovptr[j].ChangeFlag) + if (aiprovptr[j].ChangeFlag) { iDataNum++; bHaveData = TRUE; - commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr+j)); - commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr+j)); - if(VER_IEC870_5_104 == pPortParam->RtuVersion) + commandbuf[iLenth++] = LOBYTE(LOWORD(dwStartAddr + j)); + commandbuf[iLenth++] = HIBYTE(LOWORD(dwStartAddr + j)); + if (VER_IEC870_5_104 == pPortParam->RtuVersion) { - commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr+j)); + commandbuf[iLenth++] = LOBYTE(HIWORD(dwStartAddr + j)); } GetPntMsg(aiprovptr[j].PortNo, aiprovptr[j].PntNo, @@ -4933,25 +4947,25 @@ void ProvBuban104SendClass2withFloat(int commid) iLenth += sizeof(float); commandbuf[iLenth++] = 0; - //4.bug_1.2.3_20060807_3/bug_2.0.1_20060807_4 104规约不能转发第二个端口的遥测数据 + //4.bug_1.2.3_20060807_3/bug_2.0.1_20060807_4 104规约不能转发第二个端口的遥测数据 //不能操作251(原来使用255可能导致发送报文长度超过255,一个字节不能表述) //另外命令缓冲区应当使用char而不应当使用u_char - if(iLenth >= 251) + if (iLenth >= 251) { break; } } } - if(j >= pPortParam->m_psBaoHu->AiNum) + if (j >= pPortParam->m_psBaoHu->AiNum) { pPortParam->m_psBaoHu->AiChange = false; } - if(bHaveData) + if (bHaveData) { commandbuf[7] = (char)iDataNum; - commandbuf[1] = (char)(iLenth-2); + commandbuf[1] = (char)(iLenth - 2); PutPollCmdToBuf(commid, iCmdType, 0, (char *)commandbuf, iLenth); } }