diff --git a/buban101.cpp b/buban101.cpp new file mode 100644 index 0000000..7aa2145 --- /dev/null +++ b/buban101.cpp @@ -0,0 +1,3696 @@ +//*************************************************************** +//* buban101.cpp * +//* aaawen 2005.09.08 * +//*************************************************************** +//_DEBUG_MSG_,_OS_WINDOWS_DEBUG_ +#ifdef OS_LINUX +#include "baohulib/commport.h" +#include "baohulib/serialport.h" +#else +#include "commport.h" +#include "udpcomm.h" +#include "display.h" +#endif +#include +#include +#include "buban101.h" +#include "scadaprotect.h" + +extern SIO_PARAM_DEF SioParam[]; +extern FUNCTION_CALL *FunCallPtr; +extern void *pvconf_handle; +extern void *pvportconf_handle; +extern void *pvdataconf_handle; +extern char pvDataFileName[256]; +extern char IniFilePath[256]; + +const char *gpStrBuban101Cmd[BUBAN101_TIMER_CMD_NUM] = +{ + "×ÜÕÙ»½µç¶ÈÊý¾Ý", + "ÕÙ»½³õʼ»¯Êý¾Ý" +}; + +/*! + ×éÖ¯½á¹¹:Á´Â·(¼ä¸ô)+×°Öà +*/ +char *gpStrBuban101ConfigInfo[] = +{ + " ; ***** ²¿°ä101¹æÔ¼²ÎÊý¶¨Òå *****", + " ", + " ; ËùÓÐÃüÁîÕÙ»½ÖÜÆÚ¾ùÒÔÃëΪµ¥Î»¡£", + " Õ¾µØÖ· = 1 ; ȱʡ= 0 ¡£", + " ƽºâʽͨѶ = 0 ; ȱʡ= 0 ¡£", + " ×ÜÕÙ»½µç¶ÈÊý¾Ý = 120", + " ÕÙ»½³õʼ»¯Êý¾Ý = 300", + " ³¬Ê±Ê±¼ä = 20.0", + " Ò£¿Ø·½Ê½=0", + " ; =0£ºË«µãÒ£¿Ø(ȱʡ)£¬=1£ºµ¥µãÒ£¿Ø¡£", + " ", + "Ò£²âÐÅÏ¢ÌåÆðʼµØÖ·=0x701", + "Ò£ÐÅÐÅÏ¢ÌåÆðʼµØÖ·=0x001", + "Ò£ÂöÐÅÏ¢ÌåÆðʼµØÖ·=0xC01", + "Ò£¿ØÐÅÏ¢ÌåÆðʼµØÖ·=0xB01", + " ;ÒÔÉÏÐÅÏ¢Ì嵨ַ¿ÉÒÔÅäÖÃ,ȱʡֵΪ97°æ²¿°ä101Ëù¹æ¶¨Öµ", + " ", + " °æ±¾ºÅ = 1", + " ;=0 ÊÇbuban101(ȱʡֵ); =1 ÊÇIEC_870_5_101¹æÔ¼", + " ;×¢Òâ:ת·¢½öÖ§³ÖBuban101¹æÔ¼", + " ", + "*******²¿°ä101¹æÔ¼½áÊø*******", + "", // ½áÊø±êÖ¾(Öм䲻Äܺ¬ÓиÿÕ×Ö·û´®) +}; + +//******************************************************************** +//* ¶ÁÈ¡ÅäÖú¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//******************************************************************** +void Buban101ReadConfig(int commid) +{ + int i; + char szSection[128], szbuf[128]; + char szPortConfig[256]; + pBUBAN101PORTPARAM pPortParam; + +#ifdef OS_LINUX + strcpy(szPortConfig, "portconfig.ini"); +#else + //GetCurrentDirectory(sizeof(szDir), szDir); + sprintf(szPortConfig, "%s/portconfig.ini", IniFilePath); +#endif + + SioParam[commid].ExtInfo = HEAP_MALLOC(sizeof(BUBAN101PORTPARAM)); + + if(!SioParam[commid].ExtInfo) + { + sprintf(szbuf, "WARN(%04d): commid_%02d ExtInfo=malloc(%d) failed.\n", + getpid(), commid, sizeof(BUBAN101PORTPARAM)); + DebugPrint(szbuf); + return; + } + + memset(SioParam[commid].ExtInfo, 0, sizeof(BUBAN101PORTPARAM)); + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + + /* Ö»ÓÐÔÚSioParam[commid].m_psBaoHu·Ç¿Õʱ£¬²Å»áÔËÐе½ÕâÀï */ + pPortParam->m_psBaoHu = SioParam[commid].m_psBaoHu; + + sprintf(szSection, "Port%d", commid+1); + + if(GetPrivateProString(szSection, "Õ¾µØÖ·", "0", szbuf, 120, szPortConfig) > 0) + { + pPortParam->LinkAddr = atoi(szbuf); + } + if(GetPrivateProString(szSection, "ƽºâʽͨѶ", "0", szbuf, 120, szPortConfig) > 0) + { + pPortParam->BalanceOrNot = atoi(szbuf); + } + if(GetPrivateProString(szSection, "Ò£¿Ø·½Ê½", "0", szbuf, 120, szPortConfig) > 0) + { + pPortParam->YkMode = atoi(szbuf); + } + if(GetPrivateProString(szSection, "³¬Ê±Ê±¼ä", "20.0", szbuf, 120, szPortConfig) > 0) + { + pPortParam->lTimeOutConst = (long)(atof(szbuf)*1000/TIMER_CNT); + } + pPortParam->RtuVersion = GetPrivateProInt(szSection, "°æ±¾ºÅ", 0, szPortConfig); + pPortParam->iAiBaseAddr = GetPrivateProInt(szSection, "Ò£²âÐÅÏ¢ÌåÆðʼµØÖ·", INFO_AI_BASEADDR, szPortConfig); + pPortParam->iDiBaseAddr = GetPrivateProInt(szSection, "Ò£ÐÅÐÅÏ¢ÌåÆðʼµØÖ·", INFO_DI_BASEADDR, szPortConfig); + pPortParam->iPiBaseAddr = GetPrivateProInt(szSection, "Ò£ÂöÐÅÏ¢ÌåÆðʼµØÖ·", INFO_PI_BASEADDR, szPortConfig); + pPortParam->iYkBaseAddr = GetPrivateProInt(szSection, "Ò£¿ØÐÅÏ¢ÌåÆðʼµØÖ·", INFO_YKYT_BASEADDR, szPortConfig); + + // ÂÖѯָÁîÅäÖà + for(i=0; iCmdTime[i].CmdTimerConst = (long)(atof(szbuf)*1000/TIMER_CNT); + if(pPortParam->CmdTime[i].CmdTimerConst > 5) + { + pPortParam->CmdTime[i].CmdTimerCnt = pPortParam->CmdTime[i].CmdTimerConst - 5; + } + } + + InitBuban101CommandBuffer(commid); +} + +//******************************************************************** +//* ¶ÁÈ¡¶Ë¿ÚÊý¾Ýº¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//* u_char buf : Êý¾ÝÔ´»º³åÇøÖ¸Õë * +//* int len : Êý¾ÝÔ´³¤¶È * +//******************************************************************** +void Buban101RecvData(int commid, u_char *buf, int len)// ¹æÔ¼¶ÁÊý¾Ý´¦Àí +{ + int i; + pBUBAN101PORTPARAM pPortParam; +#ifdef _DEBUG_MSG_ + char szbuf[256]; +#endif + + if(!IsExtInfoPtr(commid)) + return; + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + + // wen 2005.09.12 ÓÐÊý¾Ý½ÓÊÕ,¾ÍÇå¿Õ¸´Î»¼ÆÊý + if(len > 0) + { + pPortParam->LinkOkCnt = 0; + } + + for(i=0; im_psBaoHu->m_iRevStatus) + { + case 0:// 0x10 / 0x68 + pPortParam->m_iRecvLen = 0; + if(buf[i] == 0x10) + { + pPortParam->m_psBaoHu->m_iRevStatus = 4; + pPortParam->m_psBaoHu->m_iNeedRevLength = 4; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + } + else if(buf[i] == 0x68) + { + pPortParam->m_psBaoHu->m_iRevStatus++; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + } + else if(buf[i] == 0xE5) + { + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + Buban101ProcessData(commid, pPortParam, TRUE); + //pPortParam->LinkOkCnt = 0; + pPortParam->m_psBaoHu->RevCmdFlag = 1; +#ifndef OS_LINUX + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + break; + } + else + { + pPortParam->m_psBaoHu->m_iRevStatus = 5; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + } + break; + case 1: + case 2: + pPortParam->m_psBaoHu->m_iRevStatus++; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + break; + case 3:// ³¤¶È¼ÆËã + if(buf[i] == 0x68) + { + if(pPortParam->m_au8RecvBuf[1] != pPortParam->m_au8RecvBuf[2]) + { + pPortParam->m_psBaoHu->m_iRevStatus=1; + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + Buban101ProcessData(commid, pPortParam, FALSE); + pPortParam->m_iRecvLen = 0; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + } + else + { + pPortParam->m_psBaoHu->m_iRevStatus++; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + pPortParam->m_psBaoHu->m_iNeedRevLength = (BYTE)(pPortParam->m_au8RecvBuf[1])+2; + } + } + else + { + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + pPortParam->m_psBaoHu->m_iRevStatus=5; + } + break; + case 4:// ÕýÈ·½ÓÊÕÊý¾Ý + pPortParam->m_psBaoHu->m_iNeedRevLength--; + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + if(pPortParam->m_psBaoHu->m_iNeedRevLength > 0) + break; + + if(buf[i] != 0x16) + { + pPortParam->m_psBaoHu->m_iRevStatus=5; + break; + } + + if(Buban101Check(pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen) == TRUE) + { + Buban101ProcessData(commid, pPortParam, TRUE); + pPortParam->m_psBaoHu->m_iRevStatus = 0; + pPortParam->m_psBaoHu->RevCmdFlag = 1; + } + else + { + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + SioParam[commid].LostSyncCnt++; + pPortParam->m_psBaoHu->m_iRevStatus = 5; + } +#ifndef OS_LINUX + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + //pPortParam->LinkOkCnt = 0; + break; + case 5:// ´íÎó½ÓÊÕÊý¾Ý + default: + //if(buf[i] == 0x16) + if(buf[i] == 0x10) + { +#ifndef OS_LINUX + // wen 2004.11.22 Ôö¼ÓÏÔʾ + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + Buban101ProcessData(commid, pPortParam, FALSE); + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + pPortParam->m_psBaoHu->m_iRevStatus = 4; + pPortParam->m_psBaoHu->m_iNeedRevLength = 4; + pPortParam->m_iRecvLen = 1; + pPortParam->m_au8RecvBuf[0] = buf[i]; + } + else if(buf[i] == 0x68) + { +#ifndef OS_LINUX + // wen 2004.11.22 Ôö¼ÓÏÔʾ + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + Buban101ProcessData(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 if((buf[i] == 0x16) || (buf[i] == 0xE5)) + { + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; +#ifndef OS_LINUX + // wen 2004.11.22 Ôö¼ÓÏÔʾ + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + Buban101ProcessData(commid, pPortParam, FALSE); + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + pPortParam->m_psBaoHu->m_iRevStatus = 0; + pPortParam->m_iRecvLen = 0; + } + else + { + pPortParam->m_au8RecvBuf[pPortParam->m_iRecvLen++] = buf[i]; + if(pPortParam->m_iRecvLen > 200) + { +#ifndef OS_LINUX + // wen 2004.11.22 Ôö¼ÓÏÔʾ + if((GetCurPort() == commid) && IsRealDataDisp()) + { + WatchDataPutDispBuf(commid, SDS_SIO_RECV_DATA, + (BYTE *)pPortParam->m_au8RecvBuf, pPortParam->m_iRecvLen); + } +#endif + Buban101ProcessData(commid, pPortParam, FALSE); + SioParam[commid].ErrMsgNum += pPortParam->m_iRecvLen; + pPortParam->m_iRecvLen = 0; + } + } + //pPortParam->LinkOkCnt = 0; + 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, + SioParam[commid].ErrMsgNum, SioParam[commid].LostSyncCnt); + DebugPrint(szbuf); +#endif +} + +//******************************************************************** +//* ¶¨Ê±Æ÷´¦Àíº¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//******************************************************************** +void Buban101Timer(int commid) +{ + BUBAN101PORTPARAM *pPortParam; + + if(IsExtInfoPtr(commid) == FALSE) + { + return; + } + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + + // Èç¹ûΪת·¢¶Ë¿Ú£¬Ôò²»½øÐÐÂÖѯָÁîµÄÉú³É¡£ + if(PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) + { + if(pPortParam->LinkOk) + { + pPortParam->LinkOkCnt++; + if(pPortParam->LinkOkCnt >= pPortParam->lTimeOutConst) + { + InitBuban101CommandBuffer(commid); + return; + } + } + Buban101FindNextCmd(commid); + } + + Buban101SendCmdFormPollCmdBuf(commid); +} + +//******************************************************************** +//* Ò£¿ØÒ£µ÷Êý¾Ý´¦Àíº¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//* u_char buf : Êý¾ÝÔ´»º³åÇøÖ¸Õë * +//* int len : Êý¾ÝÔ´³¤¶È * +//******************************************************************** +void Buban101YkYtProcess(int commid, u_char *buf, int len) // Ò£¿ØÒ£µ÷´¦Àí +{ + int portno, ykytpnt; + int iDirect; + + // buf[0] --- ¶Ë¿ÚºÅ(=commid) + // buf[1] + // buf[2] + // buf[3] + // buf[4] --- ¿ØµãºÅ + // buf[5] + // buf[6] + // buf[7] + // buf[8] --- ²Ù×÷ÀàÐÍ(Ò£¿Ø:1=Ñ¡Ôñ,2=Ö´ÐÐ,3=È¡Ïû,7=Ö±¿Ø; + // Ò£µ÷:4=Ñ¡Ôñ,5=Ö´ÐÐ,6=È¡Ïû,8=¼±Í£) + // buf[9] --- ¿ØÖÆ×´Ì¬(1=·Öµ½ºÏ£¬2=ºÏµ½·Ö) + // (×î¸ßλΪ1ʱ£¬Îª·µÐ£ÃüÁî, 1=¿ØºÏ, 2=¿Ø·Ö, 3=ʧ°Ü) + // ÔÚת·¢Ò£¿ØÊý¾ÝµãÖУ¬Ö»±£ÁôÁËҪת·¢µÄ¿ØµãºÅ£¬Êµ¼ÊµÄ¶Ë¿ÚºÅÓ¦¸ÃÊǸÃת·¢µãµÄ¶Ë¿Ú + // ¸Ãת·¢µã²¢Ã»ÓÐÖ¸¶¨ÐéÄâµÄת·¢¿Øµã£¬Ôò¿ØµãºÍת·¢µãµÄµãºÅÒ»Ö¡£ + + 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; + + // ·µÐ£ÐÅÏ¢(·´À¡ÐźÅ) + if(iDirect) + { + Buban101ProvMakeYkYtCommand(commid, buf, len); + } + else + { + MakeBuBan101YkYtCommand(commid, buf, len); + } +} + +//******************************************************************** +//* ϵͳÏ·¢¶Ôʱº¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//******************************************************************** +void Buban101SendSystemTime(int commid) // ϵͳ¶Ôʱ +{ + BUBAN101PORTPARAM *pPortParam; + + if(IsExtInfoPtr(commid) == FALSE) + { + return; + } + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(2 != pPortParam->m_psBaoHu->CheckTime) + { + return; + } + + if(pPortParam->Initdata) + { + if(PROTOCOL_SLAVE != pPortParam->m_psBaoHu->PortType) + { + MakeBuban101Command(commid, RTU_TIME); + } + } +} + +//******************************************************************** +//* ϵͳÍ˳öʱ¹æÔ¼´¦Àíº¯Êý * +//*²ÎÊý£ºint commid : ¶Ë¿ÚºÅ * +//******************************************************************** +void Buban101Exit(int commid) +{ + // ÊÍ·ÅËùÓзÖÅäµÄÄÚ´æ +} + +// ¸Ãº¯ÊýÓÃÀ´Çý¶¯ÓÉת·¢¶Ë¿ÚÏ·¢µ½Êµ¼Ê×°Öõı£»¤ÃüÁî +void Buban101BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData) +{ +} + +int Buban101GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB) +{ + return 0; +} +/////////////////////////ͨÓú¯Êý½Ó¿Ú½áÊø/////////////////////////////// + +/////////////////////////buban101¹«¹²º¯Êý½Ó¿Ú/////////////////////////// +// УÑéÊý¾ÝÖ¡ÊÇ·ñÕýÈ· +BOOL Buban101Check(u_char* msg, int len) +{ + BOOL bRetval = FALSE; + int iCheckLen; + if( len == 1 ) + { + if( msg[0] == 0xE5 ) + bRetval = TRUE; + } + else + { + switch( msg[0] ) + { + case 0x10: // ¶ÌÖ¡ + if ( msg[4] != 0x16 ) + break; + if ( CalBuban101Lpc( &msg[1], 2 ) != msg[3] ) + break; + bRetval = TRUE; + break; + case 0x68: // ³¤Ö¡ + if ( msg[0] != msg[3] ) + break; + if ( msg[len-1] != 0x16 ) + break; + if ( msg[1] != msg[2] ) + break; + iCheckLen = msg[1]; + if ( CalBuban101Lpc( &msg[4], iCheckLen ) != msg[len-2] ) + break; + bRetval = TRUE; + break; + default: + break; + } + } + return bRetval; +} + +//¼ÆËã Buban101 ÀۼӺͼìÑéÂë +u_char CalBuban101Lpc(u_char* msg, int len) +{ + int i; + u_char retval = 0; + + for (i = 0 ; i < len; i++) + retval += msg[i]; + return retval; +} + +//Ö¸Á³åÇø³õʼ»¯ +void InitBuban101CommandBuffer(int commid) +{ + pBUBAN101PORTPARAM pPortParam; + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + pPortParam->LinkOk = false; + pPortParam->RstLinkOk = false; + pPortParam->Initdata = false; + pPortParam->CtlByte = 0; + pPortParam->CurCmdIdx = 0; + pPortParam->LinkOkCnt = 0; + + ClearAllCmdFromPollCmdBuf(commid); +} +/////////////////////////buban101¹«¹²º¯Êý½Ó¿Ú½áÊø/////////////////////// + +void Buban101ProvMakeYkYtCommand(int commid, u_char *buf, int len) +{ + // buf[0] --- ¶Ë¿ÚºÅ(=commid) + // buf[1] + // buf[2] + // buf[3] + // buf[4] --- ¿ØµãºÅ + // buf[5] + // buf[6] + // buf[7] + // buf[8] --- ²Ù×÷ÀàÐÍ(Ò£¿Ø:1=Ñ¡Ôñ,2=Ö´ÐÐ,3=È¡Ïû,7=Ö±¿Ø; + // Ò£µ÷:4=Ñ¡Ôñ,5=Ö´ÐÐ,6=È¡Ïû,8=¼±Í£) + // buf[9] --- ¿ØÖÆ×´Ì¬(1=·Öµ½ºÏ£¬2=ºÏµ½·Ö) + // (×î¸ßλΪ1ʱ£¬Îª·µÐ£ÃüÁî, 1=¿ØºÏ, 2=¿Ø·Ö, 3=ʧ°Ü) + // ÔÚת·¢Ò£¿ØÊý¾ÝµãÖУ¬Ö»±£ÁôÁËҪת·¢µÄ¿ØµãºÅ£¬Êµ¼ÊµÄ¶Ë¿ÚºÅÓ¦¸ÃÊǸÃת·¢µãµÄ¶Ë¿Ú + // ¸Ãת·¢µã²¢Ã»ÓÐÖ¸¶¨ÐéÄâµÄת·¢¿Øµã£¬Ôò¿ØµãºÍת·¢µãµÄµãºÅÒ»Ö¡£ + + int ykpoint; + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + static int iYkStatus = 0; + BUBAN101PORTPARAM *pPortParam; + + if(IsExtInfoPtr(commid) == FALSE) + { + return; + } + + if((buf[9] & 0x80) == 0) + { + return; + } + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + + memset( (char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN ); + + ykpoint = buf[4]+buf[5]*256+buf[6]*65536+buf[7]*16777216; + ykpoint += pPortParam->iYkBaseAddr - 1; + + switch(buf[8]) + { + case 1: + case 4: // Ñ¡Ôñ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // Ë«µã¿ØÖÆ + case CONTROL_DIRECT: // Ö±½Ó¿ØÖÆ + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; + } + commandbuf[7] = 1; + if((buf[9] & 0x03) == 0x03) + { + commandbuf[8] = 0x47; + } + else + { + commandbuf[8] = 7; + } + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + if(commandbuf[8] == 0x07) + { + if((buf[9] & 0x01) == 1) + { + if( commandbuf[6] != 45) + { + commandbuf[12] = 0xfc + 2; + iYkStatus = 2; + } + else + { + commandbuf[12] = 0xfc + 1; + iYkStatus = 1; + } + } + else + { + if( commandbuf[6] != 45 ) + { + commandbuf[12] = 0xfc + 1; + iYkStatus = 1; + } + else + { + commandbuf[12] = 0xfc; + iYkStatus = 0; + } + } + } + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + + case 2: + case 5: // Ö´ÐÐ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode ) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // Ë«µã¿ØÖÆ + case CONTROL_DIRECT: // Ö±½Ó¿ØÖÆ + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; + } + commandbuf[7] = 1; + if(buf[9] & 0x01) + { + commandbuf[8] = 7; + } + else + { + commandbuf[8] = 0x47; + } + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + //*(WORD*)&commandbuf[10] = ykpoint; + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + commandbuf[12] = (char)(0x7c + iYkStatus); + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + + case 3: + case 6: + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + commandbuf[6] = 45; + break; + case CONTROL_DOUBLE: // Ë«µã¿ØÖÆ + case CONTROL_DIRECT: // Ö±½Ó¿ØÖÆ + commandbuf[6] = 46;//(rtumsg->MsgData[3] == 1) ? 46 : 47; + break; + } + commandbuf[7] = 1; + if(buf[9] & 0x01) + { + commandbuf[8] = 9; + } + else + { + commandbuf[8] = 0x49; + } + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + //*(WORD*)&commandbuf[10] = ykpoint; + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + commandbuf[12] = (char)(0xfc + iYkStatus); + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + } + + if(ShmGetDispYkYtFlag()) + { + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", + getpid(), commid, ykpoint, (buf[9] & 0x7F)); + } +} + +//===========================ÒÔÏÂΪָÁîÉú³Éº¯Êý======================= +/*! + \brief ѰÕÒ²¢Éú³ÉÏÂÒ»ÌõÃüÁî + \param u_32 portno : RTU¶Ë¿ÚºÅ + \param i_32 iBuIdx : ¼ä¸ô×°ÖÃË÷Òý +*/ +void MakeBuban101Command(u_32 commid, u_char cmdidx) +{ + int i; + DAY_TIME sCurTime; + char commandbuf[MAX_POLLCMD_BUF_LEN]; + BUBAN101PORTPARAM *pPortParam; + + memset( commandbuf, 0, sizeof( commandbuf ) ); + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + switch ( cmdidx ) + { + case ASK_LINK: // ÇëÇóÁ´Â· + commandbuf[0] = 0x10; + commandbuf[1] = 0x49; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 5); + break; + + case RST_LINK: // ¸´Î»Á´Â· + commandbuf[0] = 0x10; + commandbuf[1] = 0x40; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 5); + break; + + case RTU_TIME: // ʱ¼äͬ²½ + GetLocalTimeEx(&sCurTime); + commandbuf[0] = 0x68; + commandbuf[1] = 15; + commandbuf[2] = 15; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 103; + commandbuf[7] = 1; + commandbuf[8] = 6; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + sCurTime.mSec = sCurTime.Sec * 1000 + sCurTime.mSec; + commandbuf[12] = sCurTime.mSec % 256; + commandbuf[13] = sCurTime.mSec / 256; + commandbuf[14] = (u_char)sCurTime.Min; + commandbuf[15] = (u_char)sCurTime.Hour; + commandbuf[16] = (u_char)sCurTime.Day; + commandbuf[17] = (u_char)sCurTime.Month; + commandbuf[18] = (u_char)(sCurTime.Year%100); + commandbuf[20] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, 21); + 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] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x5b; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 100; + commandbuf[7] = 0; + commandbuf[8] = 5; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = 21 + i; + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 15); + } + 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] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x5b; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 100; + commandbuf[7] = 0; + commandbuf[8] = 5; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = 29 + i; + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 15); + } + 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] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x5b; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 101; + commandbuf[7] = 0; + commandbuf[8] = 6; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + if(VER_IEC870_5_101 == pPortParam->RtuVersion) + commandbuf[12] = 1 + i; + else + commandbuf[12] = 2 + i; + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 15); + } + break; + + case ASK_PI: //ÕÙ»½µç¶ÈÁ¿ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 101; + commandbuf[7] = 1; + commandbuf[8] = 6; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + if(VER_IEC870_5_101 == pPortParam->RtuVersion) + commandbuf[12] = 0x45; + else + commandbuf[12] = 0x41; + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 15); + pPortParam->Initdata = FALSE; + break; + + case ASK_ALL_DATA:// ÕÙ»½³õʼ»¯Êý¾Ý + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 100; + commandbuf[7] = 1; + commandbuf[8] = 6; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = 20; + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 15); + pPortParam->Initdata = FALSE; + break; + + case ASK_SECOND_DATA:// ÕÙ»½2¼¶Êý¾Ý + commandbuf[0] = 0x10; + commandbuf[1] = 0x5b; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, NORMAL_POLL_CMD, 0, commandbuf, 5); + break; + + case ASK_FIRST_DATA: // ÕÙ»½1¼¶Êý¾Ý + commandbuf[0] = 0x10; + commandbuf[1] = 0x5a; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, 5); + break; + case ACK: //È·Èϻشð + commandbuf[0] = 0x10; + commandbuf[1] = 0x00; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, commandbuf, 5); + break; + case ANS_LINK: + commandbuf[0] = 0x10; + commandbuf[1] = 0x0b; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, commandbuf, 5); + break; + } +} + +//Éú³ÉÒ£¿ØÒ£µ÷Ö¸Áî +void MakeBuBan101YkYtCommand( u_32 commid, u_char *buf, int len ) +{ + // buf[0] --- ¶Ë¿ÚºÅ(=commid) + // buf[1] + // buf[2] + // buf[3] + // buf[4] --- ¿ØµãºÅ + // buf[5] + // buf[6] + // buf[7] + // buf[8] --- ²Ù×÷ÀàÐÍ(Ò£¿Ø:1=Ñ¡Ôñ,2=Ö´ÐÐ,3=È¡Ïû,7=Ö±¿Ø; + // Ò£µ÷:4=Ñ¡Ôñ,5=Ö´ÐÐ,6=È¡Ïû,8=¼±Í£) + // buf[9] --- ¿ØÖÆ×´Ì¬(1=·Öµ½ºÏ£¬2=ºÏµ½·Ö) + // (×î¸ßλΪ1ʱ£¬Îª·µÐ£ÃüÁî, 1=³É¹¦, 0=ʧ°Ü) + // ÔÚת·¢Ò£¿ØÊý¾ÝµãÖУ¬Ö»±£ÁôÁËҪת·¢µÄ¿ØµãºÅ£¬Êµ¼ÊµÄ¶Ë¿ÚºÅÓ¦¸ÃÊǸÃת·¢µãµÄ¶Ë¿Ú + // ¸Ãת·¢µã²¢Ã»ÓÐÖ¸¶¨ÐéÄâµÄת·¢¿Øµã£¬Ôò¿ØµãºÍת·¢µãµÄµãºÅÒ»Ö¡£ + + int ykpoint; + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + static int iYkStatus = 0; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (pBUBAN101PORTPARAM)SioParam[commid].ExtInfo; + + memset( (char*)commandbuf, 0x00, MAX_POLLCMD_BUF_LEN ); + + ykpoint = buf[4]+buf[5]*256+buf[6]*65536+buf[7]*16777216; + ykpoint += pPortParam->iYkBaseAddr - 1; + + switch(buf[8]) + { + case 1: + case 4: // Ñ¡Ôñ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + 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; + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + if(buf[9] == 1) + { + if( commandbuf[6] != 45 ) + { + commandbuf[12] = 0xfc + 2; + iYkStatus = 2; + } + else + { + commandbuf[12] = 0xfc + 1; + iYkStatus = 1; + } + } + else + { + if( commandbuf[6] != 45 ) + { + commandbuf[12] = 0xfc + 1; + iYkStatus = 1; + } + else + { + commandbuf[12] = 0xfc; + iYkStatus = 0; + } + } + + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + + case 2: + case 5: // Ö´ÐÐ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode ) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + 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; + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + //*(WORD*)&commandbuf[10] = ykpoint; + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + commandbuf[12] = (char)(0x7c + iYkStatus); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + + case 3: + case 6: + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + switch(pPortParam->YkMode) + { + case CONTROL_SINGAL: // µ¥µã¿ØÖÆ + if(VER_IEC870_5_101 != pPortParam->RtuVersion) + commandbuf[6] = 46; + else + 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; + commandbuf[9] = pPortParam->LinkAddr; + + // wen 2002.11.18 ×Ö½Ú˳ÐòÐÞ¸Ä + //*(WORD*)&commandbuf[10] = ykpoint; + commandbuf[10] = (char)(ykpoint & 0x00ff); + commandbuf[11] = (char)((ykpoint & 0xff00)>>8); + + commandbuf[12] = (char)(0xfc + iYkStatus); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, INSERT_POLL_CMD, 0, (char *)commandbuf, 15); + break; + } + + if(ShmGetDispYkYtFlag()) + { + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", + getpid(), commid, ykpoint, (buf[9] & 0x7F)); + } +} + +//===================ÒÔÏÂΪPOLLING¹æÔ¼³£¹æº¯Êý½Ó¿Ú====================== +/*! + \brief ѰÕÒ²¢Éú³ÉÏÂÒ»ÌõÃüÁî + \param u_32 portno : RTU¶Ë¿ÚºÅ + \param i_32 iBuIdx : ¼ä¸ô×°ÖÃË÷Òý +*/ +void Buban101FindNextCmd(int commid) +{ + int i, iCurCmdIdx; + BUBAN101PORTPARAM *pPortParam; + int framename[BUBAN101_TIMER_CMD_NUM] = + { +// ASK_DI_DATA, +// ASK_AI_DATA, +// ASK_PI_DATA, + ASK_PI, + ASK_ALL_DATA + }; + + if((commid < 0) || (commid >= GetMaxPort())) + { + return; + } + + if(!ShmGetPortFlag(commid, FLAG_OPEN)) + { + return; + } + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(!pPortParam->LinkOk) + { + if(CheckPollCmdBufEmpty(commid) <= 0) + { + return; + } + + if(!pPortParam->RstLinkOk) + { + InitBuban101CommandBuffer(commid); + MakeBuban101Command(commid, ASK_LINK); + } + else + { + pPortParam->LinkOkCnt++; + if(pPortParam->LinkOkCnt >= pPortParam->lTimeOutConst) + { + pPortParam->LinkOkCnt = 0; + pPortParam->RstLinkOk = false; + } + } + return; + } + + for(i = 0; i < BUBAN101_TIMER_CMD_NUM; i++) + { + if(pPortParam->CmdTime[i].CmdTimerConst ) + pPortParam->CmdTime[i].CmdTimerCnt++; + } + + if(CheckPollCmdBufEmpty(commid) <= 0) + { + return; + } + + if (!pPortParam->Initdata ) + { + // IEC-870-5-101ÖжàÖ¡Êý¾ÝÂÖѯ + //ÕÅÒ´µÄ¶«·½µç×ÓIEC101ÒªÇó×ÜÕÙ»½ÆÚ¼ä²»ÇëÇó¶þ¼¶Êý¾Ý + //if(VER_IEC870_5_101 == pPortParam->RtuVersion) + // MakeBuban101Command( port, ASK_SECOND_DATA ); + return; + } + + iCurCmdIdx = pPortParam->CurCmdIdx; + for ( i = 0; i < BUBAN101_TIMER_CMD_NUM; i++ ) + { + iCurCmdIdx = (iCurCmdIdx+1) % BUBAN101_TIMER_CMD_NUM; + if ( (pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt + >= pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst) + && ( pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst > 0 )) + { + pPortParam->CurCmdIdx = iCurCmdIdx; + MakeBuban101Command(commid, framename[iCurCmdIdx]); + pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt = 0; + return; + } + } + + MakeBuban101Command(commid, ASK_SECOND_DATA); +} + +BOOL Buban101FindNextCmdEx(int commid) +{ + BOOL bRetVal; + int i, iCurCmdIdx; + BUBAN101PORTPARAM *pPortParam; + int framename[BUBAN101_TIMER_CMD_NUM] = + { +// ASK_DI_DATA, +// ASK_AI_DATA, +// ASK_PI_DATA, + ASK_PI, + ASK_ALL_DATA + }; + + bRetVal = FALSE; + if((commid < 0) || (commid >= GetMaxPort())) + { + return bRetVal; + } + + if(!ShmGetPortFlag(commid, FLAG_OPEN)) + { + return bRetVal; + } + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(!pPortParam->LinkOk) + { + if(CheckPollCmdBufEmpty(commid) <= 0) + { + return bRetVal; + } + + if(!pPortParam->RstLinkOk) + { + InitBuban101CommandBuffer(commid); + MakeBuban101Command(commid, ASK_LINK); + bRetVal = TRUE; + } + else + { + pPortParam->LinkOkCnt++; + if(pPortParam->LinkOkCnt >= pPortParam->lTimeOutConst) + { + pPortParam->LinkOkCnt = 0; + pPortParam->RstLinkOk = false; + } + } + return bRetVal; + } + + for(i = 0; i < BUBAN101_TIMER_CMD_NUM; i++) + { + if(pPortParam->CmdTime[i].CmdTimerConst ) + pPortParam->CmdTime[i].CmdTimerCnt++; + } + + if(CheckPollCmdBufEmpty(commid) <= 0) + { + return bRetVal; + } + + if (!pPortParam->Initdata ) + { + // IEC-870-5-101ÖжàÖ¡Êý¾ÝÂÖѯ + //ÕÅÒ´µÄ¶«·½µç×ÓIEC101ÒªÇó×ÜÕÙ»½ÆÚ¼ä²»ÇëÇó¶þ¼¶Êý¾Ý + //if(VER_IEC870_5_101 == pPortParam->RtuVersion) + // MakeBuban101Command( port, ASK_SECOND_DATA ); + return bRetVal; + } + + iCurCmdIdx = pPortParam->CurCmdIdx; + for ( i = 0; i < BUBAN101_TIMER_CMD_NUM; i++ ) + { + iCurCmdIdx = (iCurCmdIdx+1) % BUBAN101_TIMER_CMD_NUM; + if ( (pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt + >= pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst) + && ( pPortParam->CmdTime[iCurCmdIdx].CmdTimerConst > 0 )) + { + pPortParam->CurCmdIdx = iCurCmdIdx; + MakeBuban101Command(commid, framename[iCurCmdIdx]); + pPortParam->CmdTime[iCurCmdIdx].CmdTimerCnt = 0; + bRetVal = TRUE; + } + } + + if(FALSE == bRetVal) + { + MakeBuban101Command(commid, ASK_SECOND_DATA); + bRetVal = TRUE; + } + + return bRetVal; +} + +void Buban101SendCmdFormPollCmdBuf(int commid) +{ + BYTE fcb = 0x20; + BYTE buf[MAX_MSG_BUF_SIZE]; + i_32 len; + BUBAN101PORTPARAM *pPortParam; + + if((commid < 0) || (commid >= GetMaxPort())) + { + return; + } + + if(!ShmGetPortFlag(commid, FLAG_OPEN)) + { + return; + } + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(pPortParam->m_psBaoHu->ForceWaitFlag + && pPortParam->m_psBaoHu->ForceWaitCnt) + { + pPortParam->m_psBaoHu->ForceWaitCnt--; + if(pPortParam->m_psBaoHu->ForceWaitCnt == 0) + { + // Çå³ýµ±Ç°ÃüÁî + ClearCmdFormPollCmdBuf(commid); + //ClearCmdAllFlag(commid); + } + } + + if(pPortParam->m_psBaoHu->SendCmdFlag + && (pPortParam->m_psBaoHu->RevCmdFlag == 0)) + { + pPortParam->m_psBaoHu->RetryTimeCnt++; + if(pPortParam->m_psBaoHu->RetryTimeCnt < pPortParam->m_psBaoHu->RetryTime) + { + return; + } + + pPortParam->m_psBaoHu->RetryTimeCnt = 0; + + pPortParam->m_psBaoHu->RetryCnt++; + if(pPortParam->m_psBaoHu->RetryCnt > pPortParam->m_psBaoHu->Retry) + { + // Çå³ýµ±Ç°ÃüÁî + ClearCmdFormPollCmdBuf(commid); + //ClearCmdAllFlag(commid); + } + else + { + pPortParam->m_psBaoHu->SendCmdFlag = 0; + pPortParam->m_psBaoHu->RevCmdFlag = 0; + pPortParam->m_psBaoHu->ReSendCmdFlag = 1; + } + } + + if(pPortParam->m_psBaoHu->SendCmdFlag + && pPortParam->m_psBaoHu->RevCmdFlag) + { + // Çå³ýµ±Ç°ÃüÁî + ClearCmdFormPollCmdBuf(commid); + //ClearCmdAllFlag(commid); + } + + if(pPortParam->m_psBaoHu->WaitTime) + { + pPortParam->m_psBaoHu->WaitTimeCnt++; + if(pPortParam->m_psBaoHu->WaitTimeCnt + < pPortParam->m_psBaoHu->WaitTime) + { + return; + } + } + pPortParam->m_psBaoHu->WaitTimeCnt = 0; + + if(pPortParam->m_psBaoHu->ReSendCmdFlag) + { + len = ReGetCmdFormPollCmdBuf(commid, buf, sizeof(buf)); + } + else + { + len = GetCmdFormPollCmdBuf(commid, buf, sizeof(buf)); + } + + if(len < 3) + { + return; + } + +#ifndef OS_LINUX + if(isUdpSocketExist() == TRUE) +#endif + { + switch(buf[2]) + { + case 0x10: + if(PROTOCOL_SLAVE == pPortParam->m_psBaoHu->PortType) + break; + + if((buf[3] & 0x40) == 0) + { + buf[5] = CalBuban101Lpc(&buf[3], 2); + break; + } + + if(pPortParam->m_psBaoHu->ReSendCmdFlag) + { + pPortParam->CtlByte = ~pPortParam->CtlByte; + } + buf[3] |= ( fcb & pPortParam->CtlByte ); + pPortParam->CtlByte = ~pPortParam->CtlByte; + buf[5] = CalBuban101Lpc(&buf[3], 2); + break; + + case 0x68: + if(PROTOCOL_SLAVE == pPortParam->m_psBaoHu->PortType) + break; + + if(pPortParam->m_psBaoHu->ReSendCmdFlag) + { + pPortParam->CtlByte = ~pPortParam->CtlByte; + } + buf[6] |= ( fcb & pPortParam->CtlByte ); + pPortParam->CtlByte = ~pPortParam->CtlByte; + buf[buf[3]+6] = CalBuban101Lpc(&buf[6], buf[3]); + break; + + default: + break; + } + + SendDataToPort(commid, (char *)&buf[2], len-2); + + pPortParam->m_psBaoHu->SendCmdFlag = 1; + pPortParam->m_psBaoHu->ReSendCmdFlag = 0; + pPortParam->m_psBaoHu->RevCmdFlag = 0; + pPortParam->m_psBaoHu->RetryTimeCnt = 0; + } + +#ifdef OS_LINUX + if(pPortParam->m_psBaoHu->LastGetCmdBuf == FAST_CMD_TYPE) +#else + 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 /= TIMER_CNT; + if(pPortParam->m_psBaoHu->ForceWaitCnt) + { + pPortParam->m_psBaoHu->ForceWaitFlag = 1; + } + else + { + ClearCmdFormPollCmdBuf(commid); // Çå³ýµ±Ç°ÃüÁî + //ClearCmdAllFlag(commid); // Çå³ýµ±Ç°ÃüÁî + } + } +} +//===========================Ö¸ÁîÉú³Éº¯Êý½áÊø========================= + +//===========================ÒÔÏÂΪÊý¾Ý´¦Àíº¯Êý======================= +void Buban101ProcessData(u_32 commid, BUBAN101PORTPARAM *psPortParam, BOOL bProcess) +{ + RTUMSG msg; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = psPortParam; + + 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; + + // ×ÓÕ¾Êý¾Ý´¦Àí + if(PROTOCOL_SLAVE == pPortParam->m_psBaoHu->PortType) + { + ProvBuban101dataProcess(commid, &msg); + return; + } + + // Ö÷Õ¾Êý¾Ý´¦Àí + switch(msg.MsgData[0]) + { + case 0x68: + Buban101longprocess(&msg); + break; + case 0x10: + Buban101shortprocess(&msg); + break; + case 0xE5: + Buban101NoChanged(&msg); + break; + default: + break; + } + } +} + +void Buban101NoChanged(RTUMSG * rtumsg) +{ + +} + +//*************************************************************** +//* ½ÓÊÕµÄÊý¾ÝΪ¹Ì¶¨Ö¡³¤Ê±µÄ´¦Àí³ÌÐò +//*²ÎÊý RTUMSG* rtumsg:½ÓÊÕµ½µÄÊý¾ÝÐÅÏ¢ +//*************************************************************** +void Buban101shortprocess(RTUMSG *rtumsg) +{ + int framecnt = 0; + int commid; + BOOL bMakeAllDataFlag; + BUBAN101PORTPARAM *pPortParam; +#ifdef _DEBUG_MSG_ + char szbuf[256]; +#endif + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + // wen 2003.08.11 ÅжÏÊÇ·ñ·¢ËÍÈ«Êý¾ÝÊÇÔÚ¸´Î»¸Õ¸ÕÍê³Éʱ + bMakeAllDataFlag = pPortParam->LinkOk & pPortParam->RstLinkOk; + if((rtumsg->MsgData[1] & 0xc0) == 0xc0) + { + switch(rtumsg->MsgData[1] & 0x0f) + { + case 0x0: //¸´Î»Á´Â·È·ÈÏ0000 + if(!pPortParam->RstLinkOk) + { + MakeBuban101Command(commid, ASK_LINK); + break; + } + else + { + pPortParam->LinkOk = TRUE; + } + if(pPortParam->LinkOk && pPortParam->RstLinkOk) + { + if(!bMakeAllDataFlag) + { + MakeBuban101Command(commid, ASK_ALL_DATA); + } + } + pPortParam->CtlByte = 0xff; + MakeBuban101Command(commid, ACK); + pPortParam->RstLinkOk = TRUE; + break; + case 0x09: //´ÓÕ¾ÇëÇóÖ÷Õ¾ + if(bMakeAllDataFlag) + { + InitBuban101CommandBuffer(commid); + } + MakeBuban101Command(commid, ANS_LINK); + break; + default: + break; + } + return; + } + + //×ÓÕ¾Êý¾ÝÇøÒÑÂúÈçºÎ´¦Àí + if(rtumsg->MsgData[1] & 0x10) + { + ; + } + else + { + // wen 2004.03.16 ÐÞ¸ÄÒ»¼¶Êý¾ÝµÄÎÊѯÌõ¼þ£¬Ö»ÒªÓÐÒ»¼¶Êý¾Ý¾ÍÎÊѯ + //if( bMakeAllDataFlag ) + //{ + // //ÇëÇóÒ»¼¶Êý¾Ý + // if ( (rtumsg->MsgData[1] & 0x20) && pPortParam->Initdata ) + // MakeBuban101Command ( port, ASK_FIRST_DATA); + //} + if(rtumsg->MsgData[1] & 0x20) + { + MakeBuban101Command(commid, ASK_FIRST_DATA); + } + } + + switch(rtumsg->MsgData[1] & 0x0f) + { + case 0x0: //¸´Î»Á´Â·È·ÈÏ0000 + if(pPortParam->RstLinkOk) + { + pPortParam->LinkOk = TRUE; + } + else + { + if(pPortParam->BalanceOrNot == 0) + { + pPortParam->LinkOk = TRUE; + pPortParam->RstLinkOk = TRUE; + } + } + + if(pPortParam->LinkOk && pPortParam->RstLinkOk) + { + if(!bMakeAllDataFlag) + { + MakeBuban101Command(commid, ASK_ALL_DATA); + } + } + pPortParam->RstLinkOk = TRUE; + pPortParam->CtlByte = 0xff; + break; + case 0xb: //Á´Â·ÍêºÃ1011 + MakeBuban101Command(commid, RST_LINK); + break; + case 0x09: + pPortParam->Initdata = TRUE; + break; + default: + break; + } +} + +//*************************************************************** +//* ½ÓÊÕµÄÊý¾ÝΪ¿É±äÖ¡³¤Ê±µÄ´¦Àí³ÌÐò +//*²ÎÊý RTUMSG* rtumsg:½ÓÊÕµ½µÄÊý¾ÝÐÅÏ¢ +//*************************************************************** +void Buban101longprocess(RTUMSG *rtumsg) +{ + int commid; + BUBAN101PORTPARAM *pPortParam; +#ifdef _DEBUG_MSG_ + char szbuf[256]; +#endif + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + if ((rtumsg->MsgData[4] & 0xc0) != 0xc0) + { + //×ÓÕ¾Êý¾ÝÇøÒÑÂúÈçºÎ´¦Àí + if( rtumsg->MsgData[4] & 0x10) + { + ; + } + else + { + // wen 2004.03.16 ÐÞ¸ÄÒ»¼¶Êý¾ÝµÄÎÊѯÌõ¼þ£¬Ö»ÒªÓÐÒ»¼¶Êý¾Ý¾ÍÎÊѯ + ////ÇëÇóÒ»¼¶Êý¾Ý + //if( rtumsg->MsgData[4] & 0x20 && pPortParam->Initdata) + // MakeBuban101Command (rtumsg->PortNumber, ASK_FIRST_DATA); + if(rtumsg->MsgData[4] & 0x20) + { + MakeBuban101Command(commid, ASK_FIRST_DATA); + } + } + } + + switch (rtumsg->MsgData[6]) + { + case 1: // µ¥µãÒ£ÐÅ´¦Àí + Buban101DiDataProcess( rtumsg, 0 ); + break; + + case 2: // µ¥µãÒ£ÐÅSOE´¦Àí + Buban101SoeDataProcess( rtumsg, 0 ); + break; + + case 3: // Ë«µãÒ£ÐÅ´¦Àí + Buban101DiDataProcess( rtumsg, 1 ); + break; + + case 4: // Ë«µãÒ£ÐÅSOE´¦Àí + Buban101SoeDataProcess( rtumsg, 1 ); + break; + + case 5: // ±äѹÆ÷·Ö½ÓͷλÖà + break; + case 6: // ±äѹÆ÷·Ö½ÓͷλÖôøÊ±±ê + break; + case 7: // ×ÓÕ¾Ô¶¶¯ÖÕ¶Ë״̬ + break; + + case 9: // ´øÆ·ÖÊÎÞʱ±êÒ£²â + Buban101AiWithPzDataProcess( rtumsg, 0 ); + break; + + case 10: // ´øÆ·ÖÊ´øÊ±±êÒ£²â + Buban101AiWithPzDataProcess( rtumsg, 1 ); + break; + + case 20: // ×ÓÕ¾´«ËÍÒ£Ðűäλ֡ + Buban101AutoSendDiProcess( rtumsg ); + break; + + case 21: // ȫң²âÊý¾Ý´¦Àí »ò±ä»¯Êý¾Ý + Buban101AllAiDataProcess( rtumsg ); + break; + + case 15: // ²»´øÊ±±êµç¶È + Buban101PiDataProcess( rtumsg ); + break; + case 16: // ´øÊ±±êµç¶È + Buban101PiWithTimeDataProcess( rtumsg ); + break; + + case 17: // ¼Ìµç±£»¤×°Öõ¥¸öʼþ˳Ðò¼Ç¼֡ + case 18: // ¼Ìµç±£»¤×°ÖóÉ×é¼Ç¼Æô¶¯Ê¼þ˳Ðò + case 19: // ¼Ìµç±£»¤×°ÖóÉ×éÊä³öµç·µÄʼþ˳Ðò¼Ç¼ + Buban101BaoHuDataProcess( rtumsg ); + break; + + // wen 2004.05.27 »ª¶«101¹æÔ¼Ð޸ĵã(???) + case 30: // ´øCP56Time2aʱ±êµÄµ¥µãÐÅÏ¢ M_SP_TB_1 + Buban101SoeDataProcessWithCP56Time2a( rtumsg, 0 ); + break; + case 31: // ´øCP56Time2aʱ±êµÄË«µãÐÅÏ¢ M_DP_TB_1 + Buban101SoeDataProcessWithCP56Time2a( rtumsg, 1 ); + 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 + Buban101AiWithDataProcessWithM_ME_TD_1( rtumsg ); + break; + case 35: // ´øCP56Time2aʱ±êµÄ²âÁ¿Öµ, ±ê¶È»¯Öµ M_ME_TE_1 + Buban101AiWithDataProcessWithM_ME_TE_1( rtumsg ); + break; + case 36: // ´øCP56Time2aʱ±êµÄ²âÁ¿Öµ, ¶Ì¸¡µãÊý M_ME_TF_1 + Buban101AiWithDataProcessWithM_ME_TF_1( rtumsg ); + break; + case 37: // ´øCP56Time2aʱ±êµÄÀÛ¼ÆÁ¿ M_IT_TB_1 + Buban101PiWithTimeDataProcessWithM_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: // Ò£µ÷·µÐ£ + Buban101YkYtAck( rtumsg ); + break; + case 48: // É趨ȷÈÏ + Buban101SetAck( rtumsg ); + break; + case 100: // ×ÜÕÙ»½È·ÈÏ + Buban101InitdataProecss( rtumsg ); + break; + + case 101: // µç¶È½áÊøÖ¡ + Buban101PidataEnd( rtumsg ); + break; + case 103: // ʱ¼äͬ²½È·ÈÏÖ¡ + Buban101SynTime( rtumsg ); + break; + + default: +#ifdef _DEBUG_MSG_ + DebugPrint("½ÓÊÕµ½²»ÈÏʶµÄÃüÁÇë¼ì²é³ÌÐò.\n"); +#endif + break; + } +} + +/* Buban101 ³õʼ»¯Êý¾Ý´¦Àí */ +void Buban101InitdataProecss(RTUMSG * rtumsg) +{ + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + switch(rtumsg->MsgData[8]) + { + case 7: + case 9://×ÜÕÙ»½È·ÈÏ + break; + + case 10://×ÜÕÙ»½½áÊø + pPortParam->Initdata = TRUE; + break; + } +} + +/* µç¶È½áÊøÖ¡ */ +void Buban101PidataEnd(RTUMSG * rtumsg) +{ + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(rtumsg->MsgData[8] & 0x40) + { + pPortParam->Initdata = TRUE; + return; + } + + switch(rtumsg->MsgData[8]) + { + case 7://×ÜÕÙ»½È·ÈÏ + break; + + case 10://µç¶ÈÕÙ»½½áÊø + pPortParam->Initdata = TRUE; + break; + } +} + +//É趨ȷÈÏ +void Buban101SetAck( RTUMSG *rtumsg) +{ + +} + +//Buban101 Ò£¿ØÒ£µ÷·µÐ£³ÌÐò +void Buban101YkYtAck(RTUMSG * rtumsg) +{ + int commid; + YKYT_PARAM YkYtParam; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + YkYtParam.m_iYkYtPnt = (rtumsg->MsgData[11]<<8) + rtumsg->MsgData[10]; + YkYtParam.m_iYkYtPnt -= pPortParam->iYkBaseAddr; + + YkYtParam.m_iYkYtPnt %= 256; + + if(rtumsg->MsgData[12] & 0x80) //Ñ¡Ôñ·µÐ£ + { + YkYtParam.m_iYkYtStep = STEP_YKYT_SELECT; + + //´ËλΪ¿Ï¶¨»ò·ñ¶¨È·ÈÏλ + if(rtumsg->MsgData[8] & 0x40) + { + YkYtParam.m_iYkYtOperate = 3; + } + else if(rtumsg->MsgData[8] == 0x07) + { + if(rtumsg->MsgData[6] != 45) + { + switch(rtumsg->MsgData[12] & 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: + YkYtParam.m_iYkYtOperate = 3; + break; + } + } + else + { + // ¿ØºÏ + if( rtumsg->MsgData[12] & 0x01 ) + { + if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 1) + { + YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; + } + else + { + YkYtParam.m_iYkYtOperate = 3; + } + } + // ¿Ø·Ö + else + { + if(pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate == 2) + { + YkYtParam.m_iYkYtOperate = pPortParam->m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate; + } + else + { + YkYtParam.m_iYkYtOperate = 3; + } + } + } + } + + YkYtParam.m_iYkYtUpDown = YKYT_SEND_UP; + SendYkYtCommand2(commid, &YkYtParam); + } + else //Ö´Ðв¢Íê³É + { + //´ËλΪ¿Ï¶¨»ò·ñ¶¨È·ÈÏλ + if( ( rtumsg->MsgData[8] & 0x40 ) == 0 ) + { + switch( rtumsg->MsgData[8] ) + { + case 0x07://Ö´ÐÐÈ·ÈÏ + break; + case 0x0a://Ö´ÐÐÍê³É + break; + default: + break; + } + } + } +} + +/* Buban101 ¶Ôʱ³ÌÐò */ +void Buban101SynTime(RTUMSG * rtumsg) +{ + int commid; + DAY_TIME stime; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(1 != pPortParam->m_psBaoHu->CheckTime) + { + return; + } + + if(rtumsg->MsgData[8] != 0x07) + return; + + stime.mSec = (rtumsg->MsgData[13]<<8) + rtumsg->MsgData[12]; + stime.Sec = stime.mSec / 1000; + stime.mSec %= 1000; + 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; + SetLocalTimeEx(&stime); +} + +/* ×ÓÕ¾Ö÷¶¯´«ËÍÒ£Ðűäλ֡ */ +void Buban101AutoSendDiProcess(RTUMSG *rtumsg) +{ + int i, j, dipnt, len; + DI_DEF pntmsg; + WORD wStatus, wStatusBit; + + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + + //´ÓÕ¾Ö÷¶¯ÉÏ·¢ ±ä»¯Ò£ÐÅ + //if( ( rtumsg->MsgData[8] & 0x0f ) == 0x03 ) //¶«·½µç×Ӽ̱£ËùʹÓøñ¨ÎÄ(±íʾºÅ20£¬´«ËÍÔ­Òò20)Ó¦´ð×ÜÕÙ»½£¬Òò´Ë½«´ËÅжÏÈ¡Ïûjessie in 2003.04.15 + //{ + // wen 2002.09.06 Ò£²âÒ£ÐÅÊý¾Ý´¦Àí¹ý³¤ + //len -= 6; + //for ( i = 10; i < 10 + len; i += 7 ) + for ( i = 10; i < 4 + len; i += 7 ) + { + dipnt = rtumsg->MsgData[i+1]; + dipnt = rtumsg->MsgData[i] + (dipnt<<8) - pPortParam->iDiBaseAddr; + + wStatus = rtumsg->MsgData[i+3]; + wStatus = (wStatus<<8) + rtumsg->MsgData[i+2]; + wStatusBit = rtumsg->MsgData[i+5]; + wStatusBit = (wStatusBit<<8) + rtumsg->MsgData[i+4]; + + for( j = 0; j < 16; j++ ) + { + //ÕÅÒ´µÄ±ä»¯¼ì³ö״̬Ϊ0£¬¹ÊÈ¡Ïû´ËÅÐ¶Ï jessie in 2004.19 + //if( wStatusBit & (0x0001 << j) ) + //{ + if( wStatus & (0x0001 << j) ) + pntmsg.Status = 1; + else + pntmsg.Status = 0; + SetPntMsg(commid, dipnt+j, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); + //} + } + } + + // wen 2005.09.28 Ð޸ĶÔÖ÷¶¯ÉÏËÍÊý¾ÝµÄÈ·ÈÏÓ¦´ð + // MakeBuban101Command(commid, ACK); + if(pPortParam->BalanceOrNot) + { + if((rtumsg->MsgData[4] & 0xc0) == 0xc0) + { + MakeBuban101Command(commid, ACK); + } + } + //} +} + +// Buban101 ´øÆ·ÖÊÃèÊöµÄÒ£²âÊý¾Ý´¦Àí +void Buban101AiWithPzDataProcess(RTUMSG * rtumsg, int flag) +{ + int i, aipnt, len; + AI_DEF pntmsg; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + + //´¦Àí±ä»¯Ò£²â + if((rtumsg->MsgData[7] & 0x80)==0) + { + for ( i = 10; i < 4 + len; i += 5 ) + { + aipnt = rtumsg->MsgData[i+1]; + aipnt = (aipnt<<8) + rtumsg->MsgData[i] - pPortParam->iAiBaseAddr; + + pntmsg.RawValue = rtumsg->MsgData[i+3]; + pntmsg.RawValue = (pntmsg.RawValue<<8) + rtumsg->MsgData[i+2]; + // Æ·ÖÊÃèÊö + // rtumsg->MsgData[i+4]; + + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + + // ʱ±ê + if(flag) + { + i += 3; + } + } + } + else// ´¦ÀíÒ£²âÈ«Êý¾Ý + { + aipnt = rtumsg->MsgData[11]; + + aipnt = (aipnt<<8) + rtumsg->MsgData[10] - pPortParam->iAiBaseAddr; + + if( len < 0 ) + return; + + for ( i = 12; i < len + 4; i+= 3 ) + { + pntmsg.RawValue = rtumsg->MsgData[i+1]; + pntmsg.RawValue = (pntmsg.RawValue<<8) + rtumsg->MsgData[i]; + + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + aipnt++; + // Æ·ÖÊÃèÊö + // rtumsg->MsgData[i+2]; + + // ʱ±ê + if ( flag ) + i += 3; + } + } +} + +void Buban101AllAiDataProcess(RTUMSG *rtumsg) +{ + int i, aipnt, len; + AI_DEF pntmsg; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + + aipnt = 0; + //´¦Àí±ä»¯Ò£²â + if((rtumsg->MsgData[7] & 0x80)==0) + { + for ( i = 10; i < len + 4; i+= 4 ) + { + aipnt = rtumsg->MsgData[i+1]; + + aipnt = (aipnt<<8) + rtumsg->MsgData[i] - pPortParam->iAiBaseAddr; + + pntmsg.RawValue = rtumsg->MsgData[i+3]; + pntmsg.RawValue = (pntmsg.RawValue<<8) + rtumsg->MsgData[i+2]; + + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + } + return; + } + + //´¦Àíȫң²â + aipnt = rtumsg->MsgData[11]; + aipnt = (aipnt<<8) + rtumsg->MsgData[10] - pPortParam->iAiBaseAddr; + + if(len < 0) + { + return; + } + + for ( i = 12; i < len + 4; i+= 2 ) + { + pntmsg.RawValue = rtumsg->MsgData[i+1]; + pntmsg.RawValue = (pntmsg.RawValue<<8) + rtumsg->MsgData[i]; + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + aipnt++; + } +} + +void Buban101DiDataProcess(RTUMSG *rtumsg, int flag) +{ + int i, dipnt, len; + DI_DEF pntmsg; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + + //´ÓÕ¾Ö÷¶¯ÉÏ·¢ ±ä»¯Ò£ÐÅ + if( ( rtumsg->MsgData[8] & 0x0f ) == 0x03 ) + { + for ( i = 10; i < 4 + len; i += 3 ) + { + dipnt = rtumsg->MsgData[i+1]; + dipnt = (dipnt<<8) + rtumsg->MsgData[i] - pPortParam->iDiBaseAddr; + + if ( flag == 0 ) + pntmsg.Status = rtumsg->MsgData[i+2] & 0x1; + else + { + switch ( rtumsg->MsgData[i+2] & 0x3 ) + { + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; + } + } + if ( pntmsg.Status != 0xff ) + { + SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); + } + } + + // wen 2005.09.28 Ð޸ĶÔÖ÷¶¯ÉÏËÍÊý¾ÝµÄÈ·ÈÏÓ¦´ð + if(pPortParam->BalanceOrNot) + { + if((rtumsg->MsgData[4] & 0xc0) == 0xc0) + { + MakeBuban101Command(commid, ACK); + } + } + return; + } + + if(rtumsg->MsgData[7] & 0x80) + { + dipnt = rtumsg->MsgData[11]; + dipnt = (dipnt<<8) + rtumsg->MsgData[10] - pPortParam->iDiBaseAddr; + + for ( i = 12; i < 4 + len; i++,dipnt++ ) + { + if ( flag == 0 ) + pntmsg.Status = rtumsg->MsgData[i] & 0x1; + else + { + switch ( rtumsg->MsgData[i] & 0x3 ) + { + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; + } + } + if(pntmsg.Status != 0xff) + { + SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); + } + } + } + else + { + for ( i = 10; i < 4 + len; i += 3 ) + { + dipnt = rtumsg->MsgData[i+1]; + dipnt = (dipnt<<8) + rtumsg->MsgData[i] - pPortParam->iDiBaseAddr; + + if ( flag == 0 ) + pntmsg.Status = rtumsg->MsgData[i+2] & 0x1; + else + { + switch ( rtumsg->MsgData[i+2] & 0x3 ) + { + case 1: + pntmsg.Status = 1; + break; + case 2: + pntmsg.Status = 0; + break; + default: + pntmsg.Status = 0xff; + break; + } + } + if(pntmsg.Status != 0xff) + { + SetPntMsg(commid, dipnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_STATUS); + } + } + } +} + +void Buban101SoeDataProcess(RTUMSG *rtumsg, int flag) +{ + _int64 i64Millseconds; + time_t iTime; + int i, pnt, len; + char st; + int sec; + DI_DEF pntmsg; + DAY_TIME sm; + struct tm *testtm; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + for ( i = 10; i < len + 4; i += 6 ) + { + pnt = rtumsg->MsgData[i+1]; + pnt = (pnt<<8) + rtumsg->MsgData[i] - pPortParam->iDiBaseAddr; + + if ( flag == 0 ) + st = rtumsg->MsgData[i+2] & 0x01; + else + { + switch ( rtumsg->MsgData[i+2] & 0x3 ) + { + case 1: + st = 1; + break; + case 2: + st = 0; + break; + default: + st = 0x0f; + break; + } + } + if ( st == 0x0f ) + continue; + + sec = rtumsg->MsgData[i+3] + ( rtumsg->MsgData[i+4] << 8 ); + pntmsg.SoeTime.mSec = sec % 1000; + pntmsg.SoeTime.Sec = sec / 1000; + pntmsg.SoeTime.Min = (rtumsg->MsgData[i+5] & 0x3f); // ·Ö + GetLocalTimeEx(&sm); + if(abs(pntmsg.SoeTime.Min-sm.Min) > 50) + { + i64Millseconds = SystemTimeToMillseconds(&sm, 0); + if(i64Millseconds > 0) + { + // ¼õȥһСʱ + iTime = (long)(i64Millseconds/1000) - 3600; + testtm = localtime(&iTime); + sm.Year = testtm->tm_year + 1900; + sm.Month = testtm->tm_mon + 1; + sm.Day = testtm->tm_mday; + sm.Hour = testtm->tm_hour; + sm.Min = testtm->tm_min; + sm.Sec = testtm->tm_sec; + } + } + + pntmsg.SoeTime.Hour = sm.Hour; + pntmsg.SoeTime.Day = sm.Day; + pntmsg.SoeTime.Month = sm.Month; + pntmsg.SoeTime.Year = sm.Year; + pntmsg.Status = st; + + SetPntMsg(commid, pnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_SOE_TIME); + } +} + +void Buban101PiDataProcess( RTUMSG * rtumsg ) +{ + int i, point, len; + PI_DEF pntmsg; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + for(i = 10; i < 4 + len; i += 7) + { + point = rtumsg->MsgData[i+1]; + point = (point<<8) + rtumsg->MsgData[i] - pPortParam->iPiBaseAddr; + + pntmsg.RawValue = (rtumsg->MsgData[i+5]<<24) + (rtumsg->MsgData[i+4]<<16) + + (rtumsg->MsgData[i+3]<<8) + rtumsg->MsgData[i+2]; + + SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); + } +} + +void Buban101PiWithTimeDataProcess( RTUMSG *rtumsg ) +{ + int i, point, len; + PI_DEF pntmsg; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + for ( i = 10; i < 4 + len; i += 10 ) + { + point = rtumsg->MsgData[i+1]; + + point = (point<<8) + rtumsg->MsgData[i] - pPortParam->iPiBaseAddr; + + pntmsg.RawValue = (rtumsg->MsgData[i+5]<<24) + (rtumsg->MsgData[i+4]<<16) + + (rtumsg->MsgData[i+3]<<8) + rtumsg->MsgData[i+2]; + + SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); + } +} + +void Buban101BaoHuDataProcess( RTUMSG *rtumsg ) +{ + // ¸Ã¹¦Äܲ»×ö´¦Àí +} + +void Buban101DefaultBaoHuDataProcess( RTUMSG *rtumsg ) +{ + // ¸Ã¹¦Äܲ»×ö´¦Àí +} + +// ÐÂÔöº¯Êý£¬º¬ÓÐ 7 BYTE µÄʱ±ê +//*************************************************************** +//* Buban101 SOE Êý¾Ý´¦Àí(7 bytes ʱ¼ä) * +//*************************************************************** +void Buban101SoeDataProcessWithCP56Time2a( RTUMSG *rtumsg, int flag ) +{ + _int64 i64Millseconds; + time_t iTime; + int i, pnt, len; + char st; + int sec; + DI_DEF pntmsg; + DAY_TIME sm; + struct tm *testtm; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + for ( i = 10; i < len + 4; i += 9 ) + { + pnt = rtumsg->MsgData[i+1]; + pnt = (pnt<<8) + rtumsg->MsgData[i] - pPortParam->iDiBaseAddr; + + if(flag == 0) + { + st = rtumsg->MsgData[i+2] & 0x01; + } + else + { + switch ( rtumsg->MsgData[i+2] & 0x3 ) + { + case 1: + st = 1; + break; + case 2: + st = 0; + break; + default: + st = 0x0f; + break; + } + } + if(st == 0x0f) + { + continue; + } + + sec = rtumsg->MsgData[i+3] + (rtumsg->MsgData[i+4] << 8); + pntmsg.SoeTime.mSec = sec % 1000; + pntmsg.SoeTime.Sec = sec / 1000; + pntmsg.SoeTime.Min = (char)(rtumsg->MsgData[i+5] & 0x3f); + pntmsg.SoeTime.Hour = (char)(rtumsg->MsgData[i+6] & 0x1f); + pntmsg.SoeTime.Day = (char)(rtumsg->MsgData[i+7] & 0x1f); + + GetLocalTimeEx(&sm); + if((pntmsg.SoeTime.Day-sm.Day) < 0) + { + i64Millseconds = SystemTimeToMillseconds(&sm, 0); + if(i64Millseconds > 0) + { + // ¼õȥһСʱ + iTime = (long)(i64Millseconds/1000) - 3600; + testtm = localtime(&iTime); + sm.Year = testtm->tm_year + 1900; + sm.Month = testtm->tm_mon + 1; + sm.Day = testtm->tm_mday; + sm.Hour = testtm->tm_hour; + sm.Min = testtm->tm_min; + sm.Sec = testtm->tm_sec; + } + } + + pntmsg.SoeTime.Month = sm.Month; + pntmsg.SoeTime.Year = sm.Year; + pntmsg.Status = st; + SetPntMsg(commid, pnt, (void *)&pntmsg, DI_PNT_TYPE, PNT_SOE_TIME); + } +} + +void Buban101AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg) +{ + int i, aipnt, len; + AI_DEF pntmsg; + char szbuf[256]; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + //´¦Àí±ä»¯Ò£²â + for(i = 10; i < 4 + len; i += 12) + { + if( ( i + 12 ) > (4 + len)) + { + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban101AiWithDataProcessWithM_ME_TD_1", + getpid(), commid, len); + DebugPrint(szbuf); + break; + } + aipnt = rtumsg->MsgData[i+1]; + + aipnt = (aipnt<<8) + rtumsg->MsgData[i] - pPortParam->iAiBaseAddr; + + pntmsg.RawValue = rtumsg->MsgData[i+3]; + pntmsg.RawValue = (pntmsg.RawValue<<8) + rtumsg->MsgData[i+2]; + + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + + // 7×Ö½Úʱ±ê + } +} + +void Buban101AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg) +{ + Buban101AiWithDataProcessWithM_ME_TD_1(rtumsg); +} + +void Buban101AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg) +{ + int i, aipnt, len; + AI_DEF pntmsg; + char szbuf[256]; + float fValue; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + + //´¦Àí±ä»¯Ò£²â + for ( i = 10; i < 4 + len; i += 14 ) + { + if( ( i + 14 ) > (4 + len)) + { + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban101AiWithDataProcessWithM_ME_TF_1", + getpid(), commid, len); + DebugPrint(szbuf); + break; + } + aipnt = rtumsg->MsgData[i+1]; + + aipnt = (aipnt<<8) + rtumsg->MsgData[i] - pPortParam->iAiBaseAddr; + + fValue = *((float *)&rtumsg->MsgData[i+2]); + SequenceRtuToHost((char *)&fValue, sizeof(float)); + + // Æ·ÖÊÃèÊö + // rtumsg->MsgData[i+6]; + + // ±£Áô2λСÊý + pntmsg.RawValue = (int)(fValue * 100); + SetPntMsg(commid, aipnt, (void *)&pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + + // 7×Ö½Úʱ±ê + } +} + +//Buban101 µç¶ÈÊý¾Ý´¦Àíwith time +void Buban101PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg) +{ + int i, point, len; + AI_DEF pntmsg; + char szbuf[256]; + int commid; + BUBAN101PORTPARAM *pPortParam; + + commid = rtumsg->PortIdx; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + len = (int)rtumsg->MsgData[1]; + for(i = 10; i < 4 + len; i += 14) + { + if( ( i + 14 ) > (4 + len)) + { + sprintf(szbuf, ">>>>>WARN(%04d): Commid_%02d (iLen=%d) is not enough in Buban101PiWithTimeDataProcessWithM_IT_TB_1", + getpid(), commid, len); + DebugPrint(szbuf); + break; + } + + point = rtumsg->MsgData[i+1]; + point = (point<<8) + rtumsg->MsgData[i] - pPortParam->iPiBaseAddr; + + pntmsg.RawValue = (rtumsg->MsgData[i+5]<<24) + (rtumsg->MsgData[i+4]<<16) + + (rtumsg->MsgData[i+3]<<8) + rtumsg->MsgData[i+2]; + + SetPntMsg(commid, point, (void *)&pntmsg, PI_PNT_TYPE, PNT_RAWVALUE); + + // 1 BYTE (IV CA CY ˳ÐòºÅ) + // 7 BYTE ʱ±ê + } +} + +//=========================ÒÔÏÂΪBuban101ת·¢Êý¾Ý¹¦ÄÜ=======================// +void ProvBuban101dataProcess(int commid, RTUMSG *rtumsg) +{ + // Êý¾ÝУÑé´íÎó( ¸½¼Ó×ֽڵĵڶþ¸ö×Ö½Ú) + if(rtumsg->MsgData[rtumsg->MsgLen+1] > 0) + { + return; + } + + switch(rtumsg->MsgData[0]) + { + case 0x68: + ProvBuban101longprocess(commid, rtumsg); + break; + + case 0x10://shortframe process + ProvBuban101shortprocess(commid, rtumsg); + break; + + default: + break; + } +} + +void ProvBuban101shortprocess(int commid, RTUMSG * rtumsg) +{ + int framecnt = 0; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + //Ö÷Õ¾±»¶¯·¢ËÍ + if((rtumsg->MsgData[1] & 0xc0) == 0x00) + { + switch(rtumsg->MsgData[1] & 0x0f) + { + case 0x0b://»Ø´ðÁ´Â·×´Ì¬(Á´Â·ÍêºÃ) + ProvMakeBuban101Command(commid, RST_LINK); + break; + case 0x00://Á´Â·È·ÈÏ + if(pPortParam->RstLinkOk) + { + pPortParam->LinkOk = TRUE; + } + // wen 2005.09.13 Á´Â·µÄÈ·ÈÏÖ¡²»ÐèÒªÓÐÓ¦´ð + //ProvMakeBuban101Command(commid, ACK); + break; + default: + break; + } + return; + } + + switch(rtumsg->MsgData[1] & 0x0f) + { + case 0x09://Á´Â·×´Ì¬ÇëÇó + ProvMakeBuban101Command(commid, ANS_LINK); + break; + case 0x00://¸´Î»Á´Â· + if(pPortParam->BalanceOrNot==0) + { + pPortParam->LinkOk = TRUE; + pPortParam->RstLinkOk = TRUE; + ProvMakeBuban101Command(commid, ACK); + } + else + { + pPortParam->LinkOk = FALSE; + pPortParam->RstLinkOk = TRUE; + ProvMakeBuban101Command(commid, ACK); + //ProvMakeBuban101Command(commid, RST_LINK); + ProvMakeBuban101Command(commid, ASK_LINK); + } + break; + case 0x0a://ÕÙ»½Ò»¼¶Êý¾Ý + if(pPortParam->LinkOk) + { + ProvMakeBuban101Command(commid, ASK_FIRST_DATA); + } + break; + case 0x0b://ÕÙ»½¶þ¼¶Êý¾Ý + if(pPortParam->LinkOk) + { + ProvMakeBuban101Command(commid, ASK_SECOND_DATA); + } + break; + default: + break; + } +} + +void ProvBuban101longprocess(int commid, RTUMSG * rtumsg) +{ + if((rtumsg->MsgData[4] & 0xc0) != 0x40) + { + ProvMakeBuban101Command(commid, ASK_DATA_NO); + } + + switch(rtumsg->MsgData[6]) + { + case 1: // µ¥µãÒ£ÐÅ´¦Àí + break; + + case 2: // µ¥µãÒ£ÐÅSOE´¦Àí + break; + + case 3: // Ë«µãÒ£ÐÅ´¦Àí + break; + + case 4: // µ¥µãÒ£ÐÅSOE´¦Àí + break; + + case 5: // ±äѹÆ÷·Ö½ÓͷλÖà + break; + case 6: // ±äѹÆ÷·Ö½ÓͷλÖôøÊ±±ê + break; + case 7: // ×ÓÕ¾Ô¶¶¯ÖÕ¶Ë״̬ + break; + + case 9: // ´øÆ·ÖÊÎÞʱ±êÒ£²â + break; + + case 10: // ´øÆ·ÖÊ´øÊ±±êÒ£²â + break; + + case 21: // ȫң²âÊý¾Ý´¦Àí »ò±ä»¯Êý¾Ý + break; + + case 15: // ²»´øÊ±±êµç¶È + break; + case 16: // ´øÊ±±êµç¶È + break; + + case 17: + case 18: + case 19: // ±£»¤Êý¾Ý + break; + + case 46: // Ò£¿Ø·µÐ£ + case 47: // Ò£µ÷·µÐ£ + ProvBuban101YkYtData(commid, rtumsg); + break; + + case 100: // ÕÙ»½Êý¾Ý + ProvBuban101SendAllData(commid, rtumsg); + break; + + case 101: // ÕÙ»½µç¶È + ProvBuban101SendPIData(commid, rtumsg); + break; + + case 103: // ʱ¼äͬ²½È·ÈÏÖ¡ + ProvBuban101ProcessTime(commid, rtumsg); + break; + } +} + +//ÏìÓ¦·Ö×éÕÙ»½ºÍ×ÜÕÙ»½ +//×ÜÕÙ»½È·ÈÏ(´«ËÍÔ­Òò[8]=0x07,0x09È·ÈÏ; =0x0a ×ÜÕÙ»½½áÊø) +void ProvBuban101SendAllData(int commid, RTUMSG * rtumsg) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + int iGroup; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + //·Ö×éÕÙ»½ + if(rtumsg->MsgData[12] != 20) + { + iGroup = rtumsg->MsgData[12] - 20; + //ÎÞЧ×éºÅ + if( ( iGroup <= 0 ) || ( iGroup > 12 ) ) + { + ProvMakeBuban101Command(commid, ASK_DATA_NO); + return; + } + if(iGroup > 8) + { + iGroup -= 8; + ProvBuban101SendAI(commid, rtumsg, iGroup); + } + else + ProvBuban101SendDI(commid, rtumsg, iGroup); + return; + } + + //×ÜÕÙ»½ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x00; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 100; + commandbuf[7] = 0; + switch(rtumsg->MsgData[8]) + { + case 0x06://¼¤»î + commandbuf[8] = 7; + break; + case 0x08://Í£Ö¹¼¤»î + default: + commandbuf[8] = 9; + break; + } + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = 0x14; + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 15); + + if(rtumsg->MsgData[8] != 0x06) + return; + + ProvBuban101SendAI(commid, rtumsg, 0); + ProvBuban101SendDI(commid, rtumsg, 0); + + //×ÜÕÙ»½½áÊø + ProvMakeBuban101Command(commid, ASK_ALLDATA_END); + pPortParam->m_psBaoHu->DiChange = FALSE; +} + +void ProvBuban101SendPIData(int commid, RTUMSG * rtumsg) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + int iGroup = rtumsg->MsgData[12] & 0x3F; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + /*switch((rtumsg->MsgData[12]&0xc0)>>6) + { + case 0x00://ÎÞЧָÁî¸ñʽ + break; + case 0x01://¶³½á²»¸´Î» + break; + case 0x02://¶³½á¸´Î» + break; + case 0x03://µçÄܼÆÊýÆ÷¸´Î» + break; + }*/ + + //·Ö×éÕÙ»½ + if( iGroup != 1 ) + { + //ÎÞЧ»òÕßÀ©Õ¹×éºÅ + if(( iGroup <= 0 ) || ( iGroup > 5 )) + { + ProvMakeBuban101Command(commid, ASK_DATA_NO); + return; + } + + ProvBuban101SendPI(commid, rtumsg, iGroup-1); + return; + } + + //×ÜÕÙ»½È·ÈÏ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x00; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 101; + commandbuf[7] = 0; + commandbuf[8] = 7; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = rtumsg->MsgData[12]; + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 15); + + ProvBuban101SendPI(commid, rtumsg, 0); + + //×ÜÕÙ»½½áÊø + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x80; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 101; + commandbuf[7] = 0; + commandbuf[8] = 10; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = rtumsg->MsgData[12]; + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 15); +} + +void ProvBuban101ProcessTime(int commid, RTUMSG *rtumsg) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + BUBAN101PORTPARAM *pPortParam; + DAY_TIME sCurTime; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + //´«ËÍÔ­Òò + switch(rtumsg->MsgData[8]) + { + case 0x06://¼¤»î(¶Ôʱ) + commandbuf[0] = 0x68; + commandbuf[1] = 15; + commandbuf[2] = 15; + commandbuf[3] = 0x68; + commandbuf[4] = 0x53; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 103; + commandbuf[7] = 1; + commandbuf[8] = 7; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + memcpy(commandbuf+12, rtumsg->MsgData+12, 7); + commandbuf[19] = CalBuban101Lpc(&commandbuf[4], commandbuf[1]); + commandbuf[20] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 21); + + // wen 2006.03.29 Ôö¼Ó¶Ôʱ + if(1 == pPortParam->m_psBaoHu->CheckTime) + { + 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; + + SetLocalTimeEx(&sCurTime); + } + break; + case 0x07://¼¤»îÈ·ÈÏ + break; + } +} + +void ProvBuban101SendPI(int commid, RTUMSG *rtumsg, int iGroupNo) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + WORD wStartAddr; + int iLenth, iSendCount=1; + int i, j, iAllDataCount, iSendNum; + int iNo; + PI_DEF pntmsg; + PROV_PI_PNT *piprovptr; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(iGroupNo == 0)//×ÜÕÙ»½ + { + wStartAddr = MAX_GROUP_PINUM*iGroupNo + pPortParam->iPiBaseAddr; + + iAllDataCount = pPortParam->m_psBaoHu->PiNum; + iSendCount = (iAllDataCount+MAX_PINUM-1)/MAX_PINUM; + } + else//·Ö×éÕÙ»½ + { + wStartAddr = MAX_GROUP_PINUM*(iGroupNo-1); + iAllDataCount = pPortParam->m_psBaoHu->PiNum - wStartAddr; + + wStartAddr += pPortParam->iPiBaseAddr; + + if( iAllDataCount > MAX_GROUP_PINUM) + { + iSendCount = 2; + if((iAllDataCount - MAX_GROUP_PINUM)>0) + iAllDataCount = MAX_GROUP_PINUM; + } + } + + piprovptr = (PROV_PI_PNT *)pPortParam->m_psBaoHu->PiPtr; + for(i = 0; i < iSendCount; i++) + { + commandbuf[0] = 0x68; + commandbuf[3] = 0x68; + commandbuf[4] = 0x08; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 15; + commandbuf[8] = 37+iGroupNo; + commandbuf[9] = pPortParam->LinkAddr; + //Ò£²âÖµ + if(iAllDataCount>MAX_PINUM) + { + iAllDataCount -= MAX_PINUM; + iSendNum = MAX_PINUM; + } + else + { + iSendNum = iAllDataCount; + } + + for(j = 0, iLenth = 10; j < iSendNum; j++, wStartAddr++) + { + commandbuf[iLenth++] = (char)(wStartAddr &0x00ff); + commandbuf[iLenth++] = (char)((wStartAddr &0xff00)>>8); + + iNo = wStartAddr - pPortParam->iPiBaseAddr; + + pntmsg.RawValue = 0; + 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[7] = (BYTE)j; + commandbuf[1] = (char)(iLenth-4); + commandbuf[2] = commandbuf[1]; + commandbuf[iLenth++] = CalBuban101Lpc(&commandbuf[4], commandbuf[1]); + commandbuf[iLenth++] = 0x16; + if(iGroupNo != 0) + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + else + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + } +} + +void ProvBuban101SendAI(int commid, RTUMSG *rtumsg, int iGroupNo) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + WORD wStartAddr; + int iLenth, iSendCount=1; + int i, j, iAllDataCount, iSendNum; + int iNo; + AI_DEF pntmsg; + PROV_AI_PNT *aiprovptr; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if( iGroupNo == 0 )//×ÜÕÙ»½ + { + wStartAddr = MAX_GROUP_AINUM*iGroupNo + pPortParam->iAiBaseAddr; + + iAllDataCount = pPortParam->m_psBaoHu->AiNum; + iSendCount = (iAllDataCount+MAX_AINUM-1)/MAX_AINUM; + } + else//·Ö×éÕÙ»½ + { + wStartAddr = MAX_GROUP_AINUM*(iGroupNo-1); + iAllDataCount = pPortParam->m_psBaoHu->AiNum - wStartAddr; + wStartAddr += pPortParam->iAiBaseAddr; + + if(iAllDataCount > MAX_AINUM) + { + iSendCount = 2; + if((iAllDataCount - MAX_GROUP_AINUM) > 0) + { + iAllDataCount = MAX_GROUP_AINUM; + } + } + } + + aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; + for( i = 0; i < iSendCount; i++ ) + { + commandbuf[0] = 0x68; + commandbuf[3] = 0x68; + commandbuf[4] = 0x08; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 21; + commandbuf[8] = rtumsg->MsgData[12]; + commandbuf[9] = pPortParam->LinkAddr; + + commandbuf[10] = (char)(wStartAddr); + commandbuf[11] = (char)((wStartAddr&0xff00)>>8); + //Ò£²âÖµ + if(iAllDataCount > MAX_AINUM) + { + iAllDataCount -= MAX_AINUM; + iSendNum = MAX_AINUM; + } + else + { + iSendNum = iAllDataCount; + } + + iNo = wStartAddr - pPortParam->iAiBaseAddr; + for(j = 0, iLenth = 12; j < iSendNum; j++) + { + GetPntMsg(aiprovptr[iNo+j].PortNo, aiprovptr[iNo+j].PntNo, + &pntmsg, AI_PNT_TYPE, PNT_RAWVALUE); + aiprovptr[iNo+j].ChangeFlag = FALSE; + commandbuf[iLenth++] = (char)(pntmsg.RawValue); + commandbuf[iLenth++] = (char)((pntmsg.RawValue&0xff00)>>8); + } + + commandbuf[7] = (BYTE)j; + commandbuf[7] |= 0x80; + commandbuf[1] = commandbuf[2] = (char)(iLenth-4); + commandbuf[iLenth++] = CalBuban101Lpc( &commandbuf[4], commandbuf[1]); + commandbuf[iLenth++] = 0x16; + if(iGroupNo != 0) + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + else + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + wStartAddr += MAX_AINUM; + } +} + +void ProvBuban101SendDI(int commid, RTUMSG *rtumsg, int iGroupNo) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + + WORD wStartAddr; + int iLenth, iSendCount=1; + int i, j, iAllDataCount, iSendNum; + int iNo; + DI_DEF pntmsg; + PROV_DI_PNT *diprovptr; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + if(iGroupNo == 0)//×ÜÕÙ»½ + { + wStartAddr = MAX_GROUP_DINUM*iGroupNo + pPortParam->iDiBaseAddr; + + iAllDataCount = pPortParam->m_psBaoHu->DiNum; + iSendCount = (iAllDataCount+MAX_DINUM-1)/MAX_DINUM; + } + else//·Ö×éÕÙ»½ + { + wStartAddr = MAX_GROUP_DINUM*(iGroupNo-1); + iAllDataCount = pPortParam->m_psBaoHu->DiNum - wStartAddr; + + wStartAddr += pPortParam->iDiBaseAddr; + + if( iAllDataCount > MAX_GROUP_DINUM) + { + iAllDataCount = MAX_GROUP_DINUM; + } + } + + diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; + for(i=0; iLinkAddr; + commandbuf[6] = 1;//=3,Ϊ˫µã + commandbuf[8] = rtumsg->MsgData[12]; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = (char)(wStartAddr); + commandbuf[11] = (char)((wStartAddr&0xff00)>>8); + + if(iAllDataCount > MAX_DINUM) + { + iAllDataCount -= MAX_DINUM; + iSendNum = MAX_DINUM; + } + else + { + iSendNum = iAllDataCount; + } + + iNo = wStartAddr - pPortParam->iDiBaseAddr; + + for( j = 0, iLenth = 12; j < iSendNum; j++ ) + { + GetPntMsg(diprovptr[iNo+j].PortNo, diprovptr[iNo+j].PntNo, + &pntmsg, DI_PNT_TYPE, PNT_STATUS); + diprovptr[iNo+j].ChangeFlag = FALSE; + commandbuf[iLenth++] = pntmsg.Status; + } + + commandbuf[7] = (char)j; + commandbuf[7] |= 0x80; + commandbuf[1] = (char)(iLenth-4); + commandbuf[2] = commandbuf[1]; + commandbuf[iLenth++] = CalBuban101Lpc( &commandbuf[4], commandbuf[1]); + commandbuf[iLenth++] = 0x16; + if(iGroupNo != 0) + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + else + { + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + wStartAddr += MAX_DINUM; + } +} + +void ProvBuban101YkYtData(int commid, RTUMSG *rtumsg) +{ + PROV_DI_PNT *diprovptr; + DI_DEF *diptr; + int ykytcommid, provpnt; + int ykytpnt, ykytop, step; + YKYT_PARAM YkYtParam; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + if(rtumsg->MsgData[8] == 8) + { + step = STEP_YKYT_CANCEL; + } + else + { + if(rtumsg->MsgData[12] & 0x80) //Ñ¡Ôñ·µÐ£ + { + step = STEP_YKYT_SELECT; + } + else + { + step = STEP_YKYT_EXEC; + } + } + + ykytpnt = 0; + ykytop = 3; + + if(ShmGetDispYkYtFlag()) + { + printf("TIP_(%04d): commid =%d recv ykyt select.\n", getpid(), commid); + } + + ykytpnt = (rtumsg->MsgData[11]<<8) + rtumsg->MsgData[10]; + ykytpnt -= pPortParam->iYkBaseAddr; + ykytpnt += 1; + + //ykytop = ((rtumsg->MsgData[12] & 0x03) == 1) ? 2 : 1; + if(rtumsg->MsgData[6] == 45) + { + // ykytop == 1 ¿ØºÏ, == 2 ¿Ø·Ö + ykytop = ((rtumsg->MsgData[12] & 0x03) == 1) ? 1 : 2; + } + else if(rtumsg->MsgData[6] == 46) + { + ykytop = ((rtumsg->MsgData[12] & 0x03) == 2) ? 1 : 2; + } + else // == 47 + { + //step = STEP_YKYT_CANCEL; + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + return; + } + + provpnt = FindProvPntFromYkYtPnt(commid, ykytpnt, pPortParam->m_psBaoHu); + if(provpnt < 0) // ¿ØµãºÅ´í + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + } + else + { + diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; + ykytcommid = diprovptr[provpnt].PortNo; + if(!SioParam[ykytcommid].m_psBaoHu) + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + return; + } + + if(!SioParam[ykytcommid].m_psBaoHu->DiPtr) + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + return; + } + + diptr = (DI_DEF *)SioParam[ykytcommid].m_psBaoHu->DiPtr; + + // Èç¹û¶ÔÓ¦µãûÓпصã»òÕ߿ص㲻ÏàµÈ + if(!diptr[diprovptr[provpnt].PntNo].CtrlEnable) + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + return; + } + + if(STEP_YKYT_SELECT == step) + { + if(STEP_YKYT_SELECT == SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtStep) + { + if(!ProvPortYkYtIsTimeOut(ykytcommid, &SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg)) + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, 3, step); + return; + } + } + } + + SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iProvPntIdx = provpnt; + SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iProvPortIdx = commid; + SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iProvYkYtPointIdx = ykytpnt; + SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtPointIdx = diptr[diprovptr[provpnt].PntNo].ControlNo; + SioParam[ykytcommid].m_psBaoHu->ProvYkYtMsg.m_iYkYtOperate = ykytop; + + // buf[0] --- ¶Ë¿ÚºÅ(=commid) + // buf[1] + // buf[2] + // buf[3] + // buf[4] --- ¿ØµãºÅ + // buf[5] + // buf[6] + // buf[7] + // buf[8] --- ²Ù×÷ÀàÐÍ(Ò£¿Ø:1=Ñ¡Ôñ,2=Ö´ÐÐ,3=È¡Ïû,7=Ö±¿Ø; + // Ò£µ÷:4=Ñ¡Ôñ,5=Ö´ÐÐ,6=È¡Ïû,8=¼±Í£) + // buf[9] --- ¿ØÖÆ×´Ì¬(1=·Öµ½ºÏ£¬2=ºÏµ½·Ö) + // (×î¸ßλΪ1ʱ£¬Îª·µÐ£ÃüÁî, 1=³É¹¦, 0=ʧ°Ü) + //buf[0] = ykytcommid & 0xFF; + //buf[1] = (ykytcommid & 0xFF00) >> 8; + //buf[2] = (ykytcommid & 0xFF0000) >> 16; + //buf[3] = (ykytcommid & 0xFF000000) >> 24; + //buf[4] = diptr[diprovptr[provpnt].PntNo].ControlNo & 0xFF; + //buf[5] = (diptr[diprovptr[provpnt].PntNo].ControlNo & 0xFF00) >> 8; + //buf[6] = (diptr[diprovptr[provpnt].PntNo].ControlNo & 0xFF0000) >> 16; + //buf[7] = (diptr[diprovptr[provpnt].PntNo].ControlNo & 0xFF000000) >> 24; + //buf[8] = STEP_YKYT_SELECT; + //buf[9] = ykytop; + //SendYkYtCommand(ykytcommid, (char *)buf, 10); // ·¢ËÍÒ£¿ØÒ£µ÷ÃüÁî + + YkYtParam.m_iYkYtOperate = ykytop; + YkYtParam.m_iYkYtPnt = diptr[diprovptr[provpnt].PntNo].ControlNo; + YkYtParam.m_iYkYtStep = step; + YkYtParam.m_iYkYtUpDown = YKYT_SEND_DOWN; + SendYkYtCommand2(ykytcommid, &YkYtParam); + + if(STEP_YKYT_EXEC == step) + { + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, ykytop, step); + MakeProvBuban101YkYtAckMsg(commid, ykytpnt, ykytop, STEP_YKYT_NOEXEC); + } + } +} + +void MakeProvBuban101YkYtAckMsg(int commid, int pnt, int op, int step) +{ + int iCount; + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + memset(commandbuf, 0, sizeof(commandbuf)); + iCount = 4; + commandbuf[0] = 0x68; + commandbuf[1] = 0x09; + commandbuf[2] = 0x09; + commandbuf[3] = 0x68; + commandbuf[4] = 0x80; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 46;/*47*/ + commandbuf[7] = 1; + // DCS/RCS + switch(op) + { + case 1: // Ñ¡ÔñºÏ + commandbuf[12] = 2; + break; + case 2: // Ñ¡Ôñ·Ö + commandbuf[12] = 1; + break; + case 3: // Ñ¡Ôñʧ°Ü + default: + commandbuf[8] = 0x40; + commandbuf[12] = 0; + break; + } + // ´«ËÍÔ­Òò + if(STEP_YKYT_SELECT == step) + { + commandbuf[8] |= 7; + // DCS/RCS + commandbuf[12] |= 0x80; + } + else if(STEP_YKYT_EXEC == step) + { + commandbuf[8] |= 7; + } + else if(STEP_YKYT_CANCEL == step) + { + commandbuf[8] |= 9; + // DCS/RCS + commandbuf[12] |= 0x80; + } + else// ½áÊøÖ¡ + { + commandbuf[8] = 10; + } + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = LOBYTE((WORD)(pnt+pPortParam->iYkBaseAddr)); + commandbuf[11] = HIBYTE((WORD)(pnt+pPortParam->iYkBaseAddr)); + + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], commandbuf[1]); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 15); + + if(ShmGetDispYkYtFlag()) + { + printf("TIP_(%04d): commid =%d ykytpnt=%d, op=%d checked.\n", getpid(), commid, pnt, op); + } +} + +void ProvBuban101SendClass1(int commid) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + WORD wStartAddr; + int iLenth, iSendCount=1; + int j, iDataNum; + DI_DEF pntmsg; + PROV_DI_PNT *diprovptr; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + // wen 2005.01.15 ÐÞ¸ÄÊý¾ÝÐÅÏ¢ÌåÆðʼµØÖ· + wStartAddr = pPortParam->iDiBaseAddr; + + commandbuf[0] = 0x68; + commandbuf[3] = 0x68; + //commandbuf[4] = 0x08; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 1;//=3,Ϊ˫µã + //commandbuf[8] = 3; + commandbuf[8] = 5;// Ó¦¸ÃΪ±»ÇëÇóÊý¾Ý£¬¶ø²»ÊÇÍ»·¢Êý¾Ý + commandbuf[9] = pPortParam->LinkAddr; + + diprovptr = (PROV_DI_PNT *)pPortParam->m_psBaoHu->DiPtr; + for(j = 0, iDataNum = 0, iLenth = 10; j < pPortParam->m_psBaoHu->DiNum; j++) + { + if(diprovptr[j].ChangeFlag) + { + iDataNum++; + commandbuf[iLenth++] = (char)(wStartAddr+j); + commandbuf[iLenth++] = (char)((wStartAddr+j)>>8); + + GetPntMsg(diprovptr[j].PortNo, diprovptr[j].PntNo, + &pntmsg, DI_PNT_TYPE, PNT_STATUS); + diprovptr[j].ChangeFlag = FALSE; + commandbuf[iLenth++] = pntmsg.Status; + if(iLenth > 256) + { + break; + } + } + } + + if(j >= pPortParam->m_psBaoHu->DiNum) + { + pPortParam->m_psBaoHu->DiChange = FALSE; + } + + if(pPortParam->m_psBaoHu->DiChange) + { + commandbuf[4] = 0x28; + } + else + { + commandbuf[4] = 0x08; + } + + commandbuf[7] = (char)iDataNum; + commandbuf[1] = (char)(iLenth-4); + commandbuf[2] = commandbuf[1]; + commandbuf[iLenth++] = CalBuban101Lpc( &commandbuf[4], commandbuf[1]); + commandbuf[iLenth++] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); +} + +void ProvBuban101SendClass2(int commid) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + + BOOL bHaveData = FALSE; + WORD wStartAddr, wmSec; + int iLenth; + int j, iDataNum; + AI_DEF pntmsg; + SOE_DEF soemsg; + PROV_AI_PNT *aiprovptr; + BUBAN101PORTPARAM *pPortParam; + + iDataNum = 0; + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + commandbuf[0] = 0x68; + commandbuf[3] = 0x68; + if(pPortParam->m_psBaoHu->DiChange) + { + commandbuf[4] = 0x28; + } + else + { + commandbuf[4] = 0x08; + } + commandbuf[5] = pPortParam->LinkAddr; + //commandbuf[8] = 3; + commandbuf[8] = 5; + commandbuf[9] = pPortParam->LinkAddr; + + //SOE Êý¾Ý + if(ProvHaveSoeData(commid) > 0) + { + // µ¥µã + commandbuf[6] = 2; + bHaveData = TRUE; + iLenth = 10; + // wen 2005.01.15 ÐÞ¸ÄÊý¾ÝÐÅÏ¢ÌåÆðʼµØÖ· + wStartAddr = pPortParam->iDiBaseAddr; + + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // wen 2006.07.12 ÐÞ¸ÄsoeΪµ¥¸öʱ£¬Êý¾Ý¶ªÊ§µÄÎÊÌâ. + /* + while(ProvAndDelGetSoeData(commid, &soemsg) > 0) + { + iDataNum++; + commandbuf[iLenth++] = (char)(wStartAddr+soemsg.iPntNo); + commandbuf[iLenth++] = (char)((wStartAddr+soemsg.iPntNo)>>8); + commandbuf[iLenth++] = soemsg.bStatus; + wmSec = soemsg.SoeTime.mSec + soemsg.SoeTime.Sec*1000; + commandbuf[iLenth++] = LOBYTE(wmSec); + commandbuf[iLenth++] = HIBYTE(wmSec); + commandbuf[iLenth++] = soemsg.SoeTime.Min; + if(iLenth >= 255) + { + break; + } + } + */ + //=========================================================== + while(ProvHaveSoeData(commid) > 0) + { + ProvAndDelGetSoeData(commid, &soemsg); + iDataNum++; + commandbuf[iLenth++] = (char)(wStartAddr+soemsg.iPntNo); + commandbuf[iLenth++] = (char)((wStartAddr+soemsg.iPntNo)>>8); + commandbuf[iLenth++] = soemsg.bStatus; + wmSec = soemsg.SoeTime.mSec + soemsg.SoeTime.Sec*1000; + commandbuf[iLenth++] = LOBYTE(wmSec); + commandbuf[iLenth++] = HIBYTE(wmSec); + commandbuf[iLenth++] = soemsg.SoeTime.Min; + if(iLenth >= 255) + { + break; + } + }; + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + } + else + { + // wen 2005.01.15 ÐÞ¸ÄÊý¾ÝÐÅÏ¢ÌåÆðʼµØÖ· + wStartAddr = pPortParam->iAiBaseAddr; + commandbuf[6] = 21; + //Ò£²âÖµ + aiprovptr = (PROV_AI_PNT *)pPortParam->m_psBaoHu->AiPtr; + for(j = 0, iDataNum = 0, iLenth = 10; j < pPortParam->m_psBaoHu->AiNum; j++) + { + if(aiprovptr[j].ChangeFlag) + { + iDataNum++; + bHaveData = TRUE; + + commandbuf[iLenth++] = (char)(wStartAddr+j); + commandbuf[iLenth++] = (char)((wStartAddr+j)>>8); + + 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); + + if(iLenth >= 255) + { + break; + } + } + } + } + + if(bHaveData) + { + commandbuf[7] = (char)iDataNum; + commandbuf[1] = (char)(iLenth-4); + commandbuf[2] = commandbuf[1]; + commandbuf[iLenth++] = CalBuban101Lpc( &commandbuf[4], commandbuf[1]); + commandbuf[iLenth++] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, iLenth); + } + else + { + if(pPortParam->m_psBaoHu->DiChange) + { + commandbuf[0] = 0x10; + commandbuf[1] = 0x29; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + } + else + { + commandbuf[0] = 0xE5; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 1); + } + } +} + +void ProvMakeBuban101Command(int commid, u_char cmdidx) +{ + u_char commandbuf[MAX_POLLCMD_BUF_LEN]; + BUBAN101PORTPARAM *pPortParam; + + pPortParam = (BUBAN101PORTPARAM *)SioParam[commid].ExtInfo; + + switch(cmdidx) + { + case ASK_LINK: // ÇëÇóÁ´Â· + commandbuf[0] = 0x10; + commandbuf[1] = 0xc9; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + break; + + case RST_LINK: // ¸´Î»Á´Â· + commandbuf[0] = 0x10; + commandbuf[1] = 0xc0; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + break; + + case ASK_SECOND_DATA: // ÕÙ»½2¼¶Êý¾Ý + ProvBuban101SendClass2(commid); + break; + + case ASK_FIRST_DATA: // ÕÙ»½1¼¶Êý¾Ý + ProvBuban101SendClass1(commid); + break; + + case ACK: // È·Èϻشð + commandbuf[0] = 0x10; + commandbuf[1] = 0x00; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + break; + + case ANS_LINK: // »Ø´ðÁ´Â·×´Ì¬ + commandbuf[0] = 0x10; + commandbuf[1] = 0x0b; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + break; + + case ASK_DATA_NO: // ÎÞËùÇëÇóµÄÊý¾Ý + commandbuf[0] = 0x10; + commandbuf[1] = 0x09; + commandbuf[2] = pPortParam->LinkAddr; + commandbuf[3] = CalBuban101Lpc(&commandbuf[1], 2); + commandbuf[4] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 5); + break; + + case ASK_ALLDATA_END: // ×ÜÕÙ»½½áÊøÖ¡ + commandbuf[0] = 0x68; + commandbuf[1] = 9; + commandbuf[2] = 9; + commandbuf[3] = 0x68; + commandbuf[4] = 0x08; + commandbuf[5] = pPortParam->LinkAddr; + commandbuf[6] = 100; + commandbuf[7] = 1; + commandbuf[8] = 10; + commandbuf[9] = pPortParam->LinkAddr; + commandbuf[10] = 0; + commandbuf[11] = 0; + commandbuf[12] = 0x14; + commandbuf[13] = CalBuban101Lpc(&commandbuf[4], 9); + commandbuf[14] = 0x16; + PutPollCmdToBuf(commid, FAST_POLL_CMD, 0, (char *)commandbuf, 15); + break; + + case RTU_TIME: // ʱ¼äͬ²½ + break; + + case ASK_DI_DATA: // ÕÙ»½2¼¶Êý¾ÝYX + break; + + case ASK_AI_DATA: // ÕÙ»½2¼¶Êý¾ÝYC + break; + + case ASK_PI_DATA: // ÕÙ»½2¼¶Êý¾ÝYM + break; + + case ASK_PI: //ÕÙ»½µç¶ÈÁ¿ + break; + + case ASK_ALL_DATA: // ÕÙ»½³õʼ»¯Êý¾Ý + break; + } +} +//===========================ת·¢Êý¾Ý´¦Àí½áÊø===============================// + +//===========================Êý¾Ý´¦Àíº¯Êý½áÊø===============================// \ No newline at end of file diff --git a/buban101.h b/buban101.h new file mode 100644 index 0000000..268b6a4 --- /dev/null +++ b/buban101.h @@ -0,0 +1,311 @@ +/************************************************************************************ + * + * Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd. + * All rights reserved. + * + * ÎļþÃû³Æ£ºbuban101.h + * Îļþ±êʶ£º²¿°ä101¹æÔ¼ + * Õª Òª£º101¹æÔ¼µÄ´¦ÀíµÄ½á¹¹¡¢ºê»¹Óк¯Êý¶¨Òå + * + * µ±Ç°°æ±¾£º1.0 + * ×÷ Õߣºaaawen + * Íê³ÉÈÕÆÚ£º2005/09/08 + * + * È¡´ú°æ±¾£º1.0 + * Ô­×÷Õß £º + * Íê³ÉÈÕÆÚ£º + * + * ˵ Ã÷£ºÊý¾Ý¶¨Ò广Ôò + * u8 --- BYTE(usigned char) + * ch --- char + * w --- WORD(u_short, usigned short) + * sh --- short + * b --- BOOL(bool) + * i --- int + * l --- long + * u32 --- u_32 + * ui --- unsigned int(u_int) + * ul --- unsigned long(u_long) + * f --- float + * db --- double + * c --- class + * s --- struct + * sta --- static + * g --- È«¾Ö±äÁ¿ + * Array --- Êý×é + * a --- Êý×é + * m_ --- Êý¾Ý³ÉÔ± + * p --- Ö¸Õë + * str --- ×Ö·û´® + * È«²¿´óд --- ³£Á¿ + * Ê××Ö½Ú±ØÐë´óд--- ÀàÃû³Æ£¬½á¹¹£¬º¯Êý + **************************************************************************************/ +// buban101.h: interface for the buban101 class. +// +////////////////////////////////////////////////////////////////////// +#if !defined(_BUBAN101_H_200509081012__INCLUDED_) +#define _BUBAN101_H_200509081012__INCLUDED_ +#ifdef OS_LINUX +#include "baohulib/common.h" +#else +#include "common.h" +#endif + +////////////////////////////////////////////////////////////////////////// +// ºê¶¨Òå // +// WEN 2005.09.08 // +////////////////////////////////////////////////////////////////////////// +//ÐÅÏ¢Ì嵨ַ +#define INFO_DI_BASEADDR 0x001 // µ¥,Ë«µãÒ£ÐÅÁ¿ +#define INFO_PROTECT_BASEADDR 0x401 // ±£»¤µ¥¸öʼþÐÅÏ¢ +#define INFO_PROTECT_STARTBASEADDR 0x501 // ±£»¤Æô¶¯Ê¼þ +#define INFO_PROTECT_GROUPBASEADDR 0x601 // ±£»¤³É×éÊä³öµç·ÐÅÏ¢ +#define INFO_AI_BASEADDR 0x701 // Ò£²âÁ¿ +#define INFO_PARA_BASEADDR 0x901 // ²ÎÊýµØÖ·,ºÍÒ£²âÁ¿Ò»Ò»¶ÔÓ¦ +#define INFO_YKYT_BASEADDR 0xB01 // Ò£¿Ø¡¢Ò£µ÷ +#define INFO_SET_BASEADDR 0xB81 // É趨µØÖ··¶Î§ +#define INFO_PI_BASEADDR 0xC01 // µç¶ÈÁ¿ +#define INFO_STEP_BASEADDR 0xC81 // ²½³¤Á¿(Èç:±äѹÆ÷·Ö½ÓÍ·) +#define INFO_BIN_BASEADDR 0xCA1 // ¶þ½øÖÆ×´Ì¬ÐÅÏ¢ +#define INFO_BCD_BASEADDR 0xCC1 // BCDÂë(ˮλ,ƵÂÊ) +#define INFO_STATUS_BASEADDR 0xCE9 // ×ÓÕ¾Ô¶¶«ÖÕ¶Ë״̬ +#define INFO_FILE_BASEADDR 0xCEA // Îļþ´«Êä + +//Ò»×éÖеĸöÀàÐÍÊý¾Ý×î´ó¸öÊý +#define MAX_GROUP_AINUM 128 +//#define MAX_GROUP_FLOATAINUM 128 +#define MAX_GROUP_DINUM 128 +#define MAX_GROUP_PINUM 32 + +//ת·¢¸÷ÖÖÀàÐ͵ÄÊý¾ÝµÄ×î´óÊýÁ¿ +#define MAX_AINUM 120 +#define MAX_FLOATAINUM 48 +#define MAX_DINUM 127 +#define MAX_PINUM 35 + +#define MAX_POLL_CMD_BUF_NUM 32 // ×î´óÃüÁ³åÇøÊýÄ¿ + +// ÃüÁîÀàÐͶ¨Òå +#define ASK_LINK 0 // ÇëÇóÁ´Â· +#define RST_LINK 1 // ¸´Î»Á´Â· +#define RTU_TIME 2 // ¶Ôʱʱ¼ä +#define ASK_DI_DATA 3 // ÕÙ»½2 ¼¶Êý¾ÝYX +#define ASK_AI_DATA 4 // ÕÙ»½2 ¼¶Êý¾ÝYC +#define ASK_PI_DATA 5 // ÕÙ»½2 ¼¶Êý¾ÝYM +#define ASK_ALL_DATA 6 // ³õʼ»¯×ÜÕÙ»½ + +#define ASK_FIRST_DATA 7 // ÕÙ»½1 ¼¶Êý¾Ý +#define ASK_SECOND_DATA 8 // ÕÙ»½2 ¼¶Êý¾Ý +#define ACK 9 // È·Èϻشð +#define ANS_LINK 10 // Á´Â·»Ø´ð +#define ASK_PI 11 // ÕÙ»½Êý¾ÝYM + +#define ASK_DATA_NO 12 // ÎÞËùÇëÇóµÄÊý¾Ý +#define ASK_ALLDATA_END 13 // ÕÙ»½Êý¾Ý½áÊø(ÓÃÓÚ×ÜÕÙ»½ºÍµç¶ÈÕÙ»½) +//#define ASK_ALLDATA_ACK 14 // ÕÙ»½Êý¾ÝÈ·ÈÏ(ÓÃÓÚ×ÜÕÙ»½ºÍµç¶ÈÕÙ»½) + +// ¶¨Ê±ÕÙ»½ÃüÁî¼°ÃüÁîÃû³Æ +#define BUBAN101_TIMER_CMD_NUM 2 // ×î´óÃüÁîÊýÄ¿ +#define MAX_POLLCMD_BUF_LEN 320 // ×î´óÃüÁ³åÇøÊýÄ¿ + +// ¿ØÖÆÄ£Ê½ +#define CONTROL_DOUBLE 0 // Ë«µã¿ØÖÆ +#define CONTROL_SINGAL 1 // µ¥µã¿ØÖÆ +#define CONTROL_DIRECT 2 // Ö±½Ó¿ØÖÆ + +// ¹æÔ¼°æ±¾ºÅ +#define VER_BUBAN_101 0 // ²¿°ä101 +#define VER_IEC870_5_101 1 // IEC101 +/////////////////////////////½á¹¹¶¨Òå///////////////////////////////// +typedef struct +{ + long CmdTimerCnt; + long CmdTimerConst; +} BUBAN101CMDDEF; + +typedef struct tagBUBAN101PORTPARAM +{ + BOOL RstLinkOk; // ³õʼ»¯Ê±£ºFALSE + BOOL LinkOk; // Ö÷Õ¾³õʼ»¯±êÖ¾ 1:ok; 0:no ³õʼ»¯Ê±£ºFALSE + BOOL Initdata; // ³õʼ»¯×ÜÕÙ»½±êÖ¾ TRUE£ºÊÕµ½×ÜÕÙ»½½áÊøÖ¡ + // FALSE£ºÎ´ÊÕµ½×ÜÕÙ»½½áÊøÖ¡ + // ÕÙ»½µç¶È±êÖ¾ TRUE£ºÊÕµ½ÕÙ»½½áÊøÖ¡ + // FALSE£ºÎ´ÊÕµ½ÕÙ»½½áÊøÖ¡ + BYTE LinkAddr; // µØÖ·Óò + BYTE CtlByte; // ¿ØÖÆÐÅÏ¢ + + long LinkOkCnt; + long lTimeOutConst; // ³¬Ê±Ê±¼ä¼ä¸ô + + short RtuVersion; // °æ±¾ºÅ + + short BalanceOrNot; //ÊÇ·ñƽºâʽ =1:ok; =0:no + + short CurCmdIdx; + short YkMode; // Ò£¿Ø·½Ê½(=0£ºË«µãÒ£¿Ø£¬=1£ºµ¥µãÒ£¿Ø£¬=2£ºÖ±¿Ø·½Ê½) + + // wen 2005.01.15 ÐÞ¸ÄÊý¾ÝÐÅÏ¢ÌåÆðʼµØÖ· + int iAiBaseAddr; //Ò£²âÆðʼµØÖ· + int iDiBaseAddr; //Ò£ÐÅÆðʼµØÖ· + int iPiBaseAddr; //Ò£ÂöÆðʼµØÖ· + int iYkBaseAddr; //Ò£¿ØÆðʼµØÖ· + + BYTE m_au8RecvBuf[300]; + int m_iRecvLen; + + BUBAN101CMDDEF CmdTime[BUBAN101_TIMER_CMD_NUM]; + + SIO_PARAM_BAOHU_DEF *m_psBaoHu; // ¸Ã¹æÔ¼µÄ¶Ë¿ÚÊý¾ÝÖ¸Õë +} BUBAN101PORTPARAM, *pBUBAN101PORTPARAM; + +/////////////////////////ÒÔÏÂΪͨÓú¯Êý½Ó¿Ú/////////////////////////// +/*! + \brief ¶ÁÈ¡ÅäÖú¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + */ +void Buban101ReadConfig(int commid); // ³õʼ»¯´¦Àí +/*! + \brief ¶ÁÈ¡¶Ë¿ÚÊý¾Ýº¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + \param buf -- Êý¾ÝÔ´»º³åÇøÖ¸Õë + \param len -- Êý¾ÝÔ´³¤¶È + */ +void Buban101RecvData(int commid, u_char *buf, int len);// ¹æÔ¼¶ÁÊý¾Ý´¦Àí +/*! + \brief ¹æÔ¼Êý¾Ý´¦Àí¶¨Ê±Æ÷º¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + */ +void Buban101Timer(int commid); // ¶¨Ê±Æ÷´¦Àí +/*! + \brief Ò£¿ØÒ£µ÷Êý¾Ý´¦Àíº¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + \param buf -- Êý¾ÝÔ´»º³åÇøÖ¸Õë + \param len -- Êý¾ÝÔ´³¤¶È + */ +void Buban101YkYtProcess(int commid, u_char *buf, int len); // Ò£¿ØÒ£µ÷´¦Àí +/*! + \brief ϵͳÏ·¢¶Ôʱº¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + */ +void Buban101SendSystemTime(int commid); // ϵͳ¶Ôʱ +/*! + \brief ϵͳÍ˳öʱ¹æÔ¼´¦Àíº¯Êý + \param commid -- ¶Ë¿ÚºÅ + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + */ +void Buban101Exit(int commid); // ¹æÔ¼Í˳ö +/*! + \brief ±£»¤ÃüÁî´¦Àíº¯Êý + \param commid -- ¶Ë¿ÚºÅ + \param rtumsg -- Ï·¢µÄ±£»¤ÃüÁîÖ¸Õë + \note + ȡֵ·¶Î§£º0 -- MaxSerialPortNum + MaxNetPortNum -1\n + */ +void Buban101BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData); +/*! + \brief È¡±£»¤Êý¾Ý¿âÖ¸Õ뺯Êý + \param commid -- ¶Ë¿ÚºÅ + \param iProvAddr -- ͳһ±àÅŵı£»¤×ª·¢µØÖ· + \param ppBaoHuDB -- ´æ·Å±£»¤Êý¾ÝÖ¸ÕëµÄÖ¸Õë + \retval -- ·µ»Ø¸Ã×°Öñ£»¤Êý¾Ý×éÊý + */ +int Buban101GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB); +/////////////////////////ͨÓú¯Êý½Ó¿Ú½áÊø/////////////////////////////// + +/////////////////////////buban101¹«¹²º¯Êý½Ó¿Ú/////////////////////////// +// УÑéÊý¾ÝÖ¡ÊÇ·ñÕýÈ· +BOOL Buban101Check(u_char* msg, int len); +//¼ÆËã Buban101 ÀۼӺͼìÑéÂë +u_char CalBuban101Lpc(u_char* msg, int len); +//Ö¸Á³åÇø³õʼ»¯ +void InitBuban101CommandBuffer(int commid); +/////////////////////////buban101¹«¹²º¯Êý½Ó¿Ú½áÊø/////////////////////// + +/////////////////////////ÒÔÏÂΪͨÓú¯ÊýÖ§³Ö½Ó¿Ú///////////////////////// +void Buban101ProvMakeYkYtCommand(int commid, u_char *buf, int len); +/////////////////////////ͨÓú¯ÊýÖ§³Ö½Ó¿Ú½áÊø/////////////////////////// + +///////////////////////////ÒÔÏÂΪָÁîÉú³Éº¯Êý/////////////////////////// +//Éú³É Buban101 ÃüÁîë +void MakeBuban101Command(u_32 commid, u_char cmdidx); +//Éú³ÉÒ£¿ØÒ£µ÷Ö¸Áî +void MakeBuBan101YkYtCommand(u_32 commid, u_char *buf, int len); +///////////////////////////Ö¸ÁîÉú³Éº¯Êý½áÊø///////////////////////////// + +/////////////////////ÒÔÏÂΪPOLLING¹æÔ¼³£¹æº¯Êý½Ó¿Ú////////////////////// +void Buban101FindNextCmd(int commid); +BOOL Buban101FindNextCmdEx(int commid); +void Buban101SendCmdFormPollCmdBuf(int commid); +//////////////////////POLLING¹æÔ¼³£¹æº¯Êý½Ó¿Ú½áÊø/////////////////////// + +///////////////////////ÒÔÏÂΪ¹æÔ¼´¦Àíº¯Êý½Ó¿Ú/////////////////////////// +//======================ÒÔÏÂΪÖ÷Õ¾Êý¾Ý´¦Àí============================ +void Buban101ProcessData(u_32 commid, BUBAN101PORTPARAM *psPortParam, BOOL bProcess); +void Buban101shortprocess(RTUMSG *rtumsg); +void Buban101longprocess(RTUMSG *rtumsg); +void Buban101NoChanged(RTUMSG * rtumsg); + +//Buban101 ³õʼ»¯Êý¾Ý´¦Àí +void Buban101InitdataProecss(RTUMSG * rtumsg); +//µç¶È½áÊøÖ¡ +void Buban101PidataEnd(RTUMSG * rtumsg); +//É趨ȷÈÏ +void Buban101SetAck(RTUMSG *rtumsg); +//Buban101 Ò£¿ØÒ£µ÷·µÐ£³ÌÐò +void Buban101YkYtAck(RTUMSG * rtumsg); +//Buban101 ¶Ôʱ³ÌÐò +void Buban101SynTime(RTUMSG * rtumsg); + +// ×ÓÕ¾Ö÷¶¯´«ËÍÒ£Ðűäλ֡ +void Buban101AutoSendDiProcess(RTUMSG *rtumsg); + +void Buban101AiWithPzDataProcess(RTUMSG *, int); +void Buban101AllAiDataProcess(RTUMSG *rtumsg); +void Buban101DiDataProcess(RTUMSG *rtumsg, int); +void Buban101SoeDataProcess(RTUMSG *rtumsg, int); +void Buban101PiDataProcess(RTUMSG * rtumsg); +void Buban101PiWithTimeDataProcess(RTUMSG *rtumsg); + +//±£»¤Êý¾Ý´¦Àí +void Buban101BaoHuDataProcess(RTUMSG *rtumsg); +void Buban101DefaultBaoHuDataProcess(RTUMSG *rtumsg); + +// ÐÂÔöº¯Êý£¬º¬ÓÐ 7 BYTE µÄʱ±ê +void Buban101SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag); +void Buban101AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg); +void Buban101AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg); +void Buban101AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg); +void Buban101PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg); + +//======================ÒÔÏÂΪ×ÓÕ¾Êý¾Ý´¦Àí============================ +void ProvBuban101dataProcess(int commid, RTUMSG *rtumsg); +void ProvBuban101shortprocess(int commid, RTUMSG * rtumsg); +void ProvBuban101longprocess(int commid, RTUMSG * rtumsg); +void ProvBuban101SendAllData(int commid, RTUMSG * rtumsg); +void ProvBuban101SendPIData(int commid, RTUMSG * rtumsg); +void ProvBuban101ProcessTime(int commid, RTUMSG *rtumsg); +//iGroupNo=0ΪÏìÓ¦×ÜÕÙ»½ +void ProvBuban101SendPI(int commid, RTUMSG *rtumsg, int iGroupNo); +void ProvBuban101SendAI(int commid, RTUMSG *rtumsg, int iGroupNo); +void ProvBuban101SendDI(int commid, RTUMSG *rtumsg, int iGroupNo); + +void ProvBuban101YkYtData(int commid, RTUMSG *rtumsg); +void MakeProvBuban101YkYtAckMsg(int commid, int pnt, int op, int step); + +void ProvBuban101SendClass1(int commid); +void ProvBuban101SendClass2(int commid); +void ProvMakeBuban101Command(int commid, u_char cmdidx); +/////////////////////////¹æÔ¼´¦Àíº¯Êý½Ó¿Ú½áÊø/////////////////////////// + +#endif // !defined(_BUBAN101_H_200509081012__INCLUDED_)