RTDatOpr.cpp
资源名称:PasRTDat.rar [点击查看]
上传用户:shtiemo
上传日期:2017-12-29
资源大小:163k
文件大小:47k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Visual C++
- #include "stdafx.h"
- #include <afxtempl.h>
- #include "math.h"
- #include "RTDatOpr.h"
- #include "ES5SBSys.h"
- #include "RTUYC.h"
- #include "RTUYX.h"
- #include "RTU.h"
- #include "PwrNet.h"
- #include "Station.h"
- #include "CT.h"
- #include "PT.h"
- #include "AMea.h"
- #include "CB.h"
- #include "DisCon.h"
- #include "Tran.h"
- #include "PasRTDat.h"
- int nSecond = 0;
- CTime DatStartTime = CTime::GetCurrentTime(); // 数据断面开始时间
- CTime StartTime = CTime::GetCurrentTime(); // 仿真开始时间
- int nSeconds = 60;
- BOOL bAutoRead = FALSE;
- BOOL bAutoSave = FALSE;
- int gRtuID = 9999;
- #define SHEET_NUM 10
- #define SHEET1_ID 4
- #define SB_REGFAIL 0
- #define SB_REGOK 1
- #define RTSERVER_OK 2
- char szModulName[] = "PASRTDAT_01S"; // 注册模块名称(根据需要改变)
- TCHAR szDBServName[] = "DBSERVER"; // DB Server Name
- HANDLE hReadDataEvent = NULL; // Event Handle
- BOOL bYXYCAryBusy = FALSE;
- static BOOL bSheetUsed[SHEET_NUM] = {0,0,0,0,0,0,0,0,0,0}; //
- BOOL bDBServerOK = FALSE;
- BOOL bSBConnect = TRUE;
- TASKBLK TaskBLK;
- PTASKBLK pCommTask = &TaskBLK; //SB Task block
- CLIENTREQ ClientREQ;
- PCLIENTREQ pClientREQ = &ClientREQ;
- DEVICEVALUE RetData[MAX_ID_NUM]; //
- CArray<PRTU, PRTU> RtuAry; // RTU数组
- CArray<PRTUYX, PRTUYX> YXInfoAry1; // RTU-YX数组
- CArray<PRTUYC, PRTUYC> YCInfoAry1; // RTU-YC数组
- CArray<PRTUYX, PRTUYX> YXInfoAry2; // 数据文件读入-YX数组
- CArray<PRTUYC, PRTUYC> YCInfoAry2; // 数据文件读入-YC数组
- CArray<PRTUYX, PRTUYX> YXInfoAry3; // 由电网部件产生-YX数组
- CArray<PRTUYC, PRTUYC> YCInfoAry3; // 由电网部件产生-YC数组
- BOOL bRTUMea = TRUE; // 默认由RTU信息表获取实时数据
- PWRNETPARA PwrNetPara;
- CArray<LPSTATIONPARA, LPSTATIONPARA> StaParaAry; // 厂站系数
- CArray<LPCTPARA, LPCTPARA> CTParaAry; // CT系数
- CArray<LPPTPARA, LPPTPARA> PTParaAry; // PT系数
- CArray<LPVAMEAPARA, LPVAMEAPARA> VAMeaParaAry; // 虚拟量系数
- CArray<LPCBPARA, LPCBPARA> CBParaAry; // 开关参数
- CArray<LPDISPARA, LPDISPARA> DisParaAry; // 刀闸参数
- CArray<LPTRANPARA, LPTRANPARA> TranParaAry; // 变压器参数
- CArray<PRTU,PRTU> RtuInfoAry; // RTU信息
- void CutSpaceChar(char* pChar, int nLen)
- {
- BOOL bSpace = FALSE;
- for (int i=nLen-1; i>=0; i--)
- {
- if (pChar[i] == 0) continue;
- else if (pChar[i] == 32) pChar[i] = 0;
- else break;
- }
- }
- int GetFreeSheet()
- {
- for (int i=0; i<SHEET_NUM; i++)
- {
- if (!bSheetUsed[i]) return i+SHEET1_ID;
- }
- return INVALID_SHEET;
- }
- VOID RecvServplt (WORD wOpType, LPVOID pPara,
- LPVOID* pRecvBuf, LPDWORD pDataLength)
- {
- switch( wOpType )
- {
- case SB_CALL_LinkBroken:
- bDBServerOK = FALSE;
- break;
- case SB_CALL_LinkRestored:
- bDBServerOK = TRUE;
- break;
- case SB_CALL_NpRecvServerInfo:
- break;
- default:
- break;
- }
- }
- //Connect to DB Server
- BOOL ConnectServ()
- {
- CONNECTSERVER connserv;
- connserv.lpRecvServerInfo = (LP_SBCPLT_ROUTINE)RecvServplt;
- TASKBLK taskblk;
- strcpy(taskblk.cRemoteName, szDBServName); // 请求连服务器
- taskblk.dwCommMode = SBC_CONNECT; // 操作方式
- taskblk.pSendBuf = (LPVOID)&connserv;
- if (SB_Comm(&taskblk)!= SBR_SUCCESS) return FALSE;
- bDBServerOK = TRUE;
- return TRUE;
- }
- //Disconnect from server
- BOOL DisConnectServ()
- {
- TASKBLK taskblk;
- taskblk.dwCommMode = SBC_DISCONNECT; // 操作方式
- strcpy(taskblk.cRemoteName, szDBServName); // 远程服务名
- if (SB_Comm(&taskblk)!= SBR_SUCCESS) return FALSE;
- bDBServerOK = FALSE;
- return TRUE;
- }
- //Cancel sheet
- BOOL CancelDataSheet(LPVOID pDataMenu)
- {
- TASKBLK taskblk;
- taskblk.dwCommMode = SBC_CANCELQUERY; // 操作方式
- strcpy(taskblk.cRemoteName, szDBServName); // 远程服务名
- taskblk.pSendBuf = pDataMenu; // 用户定单结构指针
- if (SB_Comm(&taskblk) != SBR_SUCCESS) return FALSE;
- return TRUE;
- }
- //Module Regist, Module Name: SBVBSERV_01G
- BOOL ModuleRegist()
- {
- int nRet = SB_REGFAIL;
- DWORD result = SB_ModuleRegist(szModulName);
- if (result != SBR_SUCCESS) return FALSE;
- hReadDataEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
- ASSERT(hReadDataEvent);
- return TRUE;
- }
- //Module UnRegist
- BOOL ModuleUnRegist()
- {
- if (bSBConnect)
- {
- if (hReadDataEvent) CloseHandle(hReadDataEvent);
- return SB_ModuleUnregist();
- }
- return FALSE;
- }
- BOOL GetRealData(RTMenuData &RtMenuData)
- {
- int nNewSheet = 4; //GetFreeSheet();
- if (nNewSheet == INVALID_SHEET) return NO_SHEET;
- if (!bDBServerOK) return DBSERVER_ERROR;
- int nIDNum = int(RtMenuData.wIDNum);
- if (nIDNum > MAX_ID_NUM) nIDNum = MAX_ID_NUM;
- bSheetUsed[nNewSheet-SHEET1_ID] = TRUE;
- pClientREQ->wSheetCode = nNewSheet; //(WORD)SheetCode;
- pClientREQ->wCountOfEntry = nIDNum; //2*(1 + pYKXH->GuanLianItemNum);
- pClientREQ->dwUseAddPara = 2; //2*(1 + MAXYKGUANLIANITEMNUM )* 8 + 16;
- pClientREQ->lpReqCallBack = GetRealDataCallBack;
- for (int i=0; i<nIDNum; i++)
- {
- pClientREQ->IDEntryList[i].bIDEntry[0] = BYTE(RtMenuData.PartsRtData[i].wPartTypeID); //CT Type ID
- pClientREQ->IDEntryList[i].bIDEntry[1] = BYTE(RtMenuData.PartsRtData[i].wPartParaID); //P ID
- pClientREQ->IDEntryList[i].bIDEntry[2] = LOBYTE(RtMenuData.PartsRtData[i].wPartID);
- pClientREQ->IDEntryList[i].bIDEntry[3] = HIBYTE(RtMenuData.PartsRtData[i].wPartID);
- pClientREQ->IDEntryList[i].wRefresh = SBD_RENEW_LAZY;
- pClientREQ->IDEntryList[i].pEntryBuf = NULL;
- }
- pCommTask->dwCommMode = SBC_QUERY;
- strcpy(pCommTask->cRemoteName, szDBServName);
- pCommTask->pSendBuf = pClientREQ;
- ResetEvent(hReadDataEvent); //Set Event Single
- WORD wFlag = SB_Comm(pCommTask);
- WORD wOpCode = 0;
- if(wFlag == SBR_SUCCESS)
- {
- DWORD RetValue = WaitForSingleObject(hReadDataEvent, 5000L);
- switch( RetValue )
- {
- case WAIT_OBJECT_0:
- {
- wOpCode = GET_DATA_OK;
- BYTE byData = 0;
- for (i=0; i<nIDNum; i++)
- {
- RtMenuData.PartsRtData[i].fYCData = RetData[i].m_Ycv;
- RtMenuData.PartsRtData[i].dwTap = RetData[i].m_wBYQFJT;
- RtMenuData.PartsRtData[i].dwKWH = DWORD(RetData[i].m_RetwKwhv);
- memcpy(&byData, &RetData[i].m_RetYxv, 1);
- RtMenuData.PartsRtData[i].byYXVal = byData;
- }
- }
- break;
- case WAIT_TIMEOUT:
- //AfxMessageBox(_T("发送数据超时!"));
- wOpCode = WAIT_SHEET_TIMEOUT;
- break;
- case WAIT_ABANDONED:
- //AfxMessageBox(_T("发送数据失败! WAIT_ABANDONED"));
- wOpCode = WAIT_SHEET_ABANDONED;
- break;
- case WAIT_FAILED:
- //AfxMessageBox(_T("发送数据失败! WAIT_FAILED"));
- wOpCode = WAIT_SHEET_FAILED;
- break;
- }
- CancelDataSheet(pClientREQ); //
- }
- else
- {
- SetEvent(hReadDataEvent);
- wOpCode = SBCOM_ERROR;
- //AfxMessageBox(_T("发送提交错误"));
- }
- //Free allocated resources
- bSheetUsed[nNewSheet-SHEET1_ID] = FALSE;
- return wOpCode;
- }
- //SB CallBack Function
- void GetRealDataCallBack(WORD wOpType, LPVOID pPara, LPVOID* pRecBuf, PDWORD pDataLength)
- {
- PCLIENTREQ pGClienTReq = NULL;
- WORD i, wIDNum;
- switch(wOpType)
- {
- case SB_CALL_StaticReqData:
- pGClienTReq = PCLIENTREQ(pPara);
- wIDNum = pGClienTReq->wCountOfEntry;
- for (i=0; i<wIDNum; i++)
- {
- if (pGClienTReq->IDEntryList[i].pEntryBuf)
- memcpy(&RetData[i], pGClienTReq->IDEntryList[i].pEntryBuf, sizeof(DEVICEVALUE));
- else
- memset(&RetData[i], 0, sizeof(DEVICEVALUE));
- }
- SetEvent(hReadDataEvent);
- break;
- default:
- pGClienTReq = NULL;
- break;
- }
- }
- BOOL SetModuleStatus()
- {
- // TODO: Add your command handler code here
- if (!bSBConnect) return FALSE;
- char cStatus;
- if (SB_GetModuleStatus(&cStatus))
- {
- if (cStatus != SBGRADE_MAIN)
- SB_ModuleChangeStatus(SBXTEVT_MQ_Manual,SBGRADE_MAIN);
- else
- SB_ModuleChangeStatus(SBXTEVT_MQ_Manual,SBGRADE_NORMAL);
- return TRUE;
- }
- else return FALSE;
- }
- BOOL GetModuleStatus()
- {
- if (!bSBConnect) return FALSE;
- char cModuleStatus;
- WORD wCode = 0;
- if (SB_GetModuleStatus(&cModuleStatus))
- {
- if (cModuleStatus == SBGRADE_MAIN)
- return TRUE;
- else
- return FALSE;
- }
- else return FALSE;
- }
- #define IES500_SERVERPPIPENAME "CCMTOADM"
- CRITICAL_SECTION crSendSCADA;
- DWORD dwPipePP=0;
- // 永久管道客户端回调:本系统中,不接收服务器回送的数据
- VOID PPipeClientCallbackFor500(WORD, LPVOID, LPVOID*, LPDWORD)
- {
- return;
- };
- // 连接500永久管道服务器
- BOOL Connect500PPipeServer()
- {
- if (dwPipePP!=0) return TRUE;
- TASKBLK tkC;
- tkC.dwCommMode = SBC_OPENPIPE;
- // tkC.dwCommMode = SBC_OPENPIPEPLUSMIS;
- lstrcpy (tkC.cRemoteName, IES500_SERVERPPIPENAME);
- tkC.pCpltRoutine = PPipeClientCallbackFor500;
- if (SB_Comm(&tkC)==SBR_SUCCESS)
- {
- dwPipePP = (DWORD)tkC.phGroup;
- InitializeCriticalSection (&crSendSCADA);
- return TRUE;
- }
- return FALSE;
- };
- // 断开与500永久管道的连接
- // 此管道用于将数据反送至 500 SCADA
- BOOL Disconnect500PPipeServer()
- {
- if (dwPipePP==0) return TRUE;
- TASKBLK tkDC;
- tkDC.dwCommMode = SBC_CLOSEPIPE;
- tkDC.phGroup = (LPVOID)dwPipePP;
- if (SB_Comm(&tkDC)==SBR_SUCCESS)
- {
- dwPipePP = 0;
- DeleteCriticalSection (&crSendSCADA);
- return TRUE;
- }
- return FALSE;
- };
- BOOL CCMComToAdm (LPVOID lpBuf, DWORD dwLen)
- {
- BOOL bRet = TRUE;
- if (dwPipePP == 0) return FALSE;
- EnterCriticalSection (&crSendSCADA);
- try
- {
- TASKBLK tkBlk;
- memset (&tkBlk, sizeof(TASKBLK),0);
- tkBlk.dwCommMode = SBC_SENDPIPE;
- tkBlk.pSendBuf = lpBuf;
- tkBlk.dwSendDataLen = dwLen;
- tkBlk.phGroup = (LPVOID)dwPipePP;
- if (SB_Comm(&tkBlk)!=SBR_SUCCESS) bRet = FALSE;
- }
- catch (...){}
- LeaveCriticalSection (&crSendSCADA);
- return bRet;
- };
- BOOL SendAllDataToADM()
- {
- if (bYXYCAryBusy) return FALSE;
- if (!Connect500PPipeServer()) return FALSE; // 无法连通数据接收服务器
- bYXYCAryBusy = TRUE;
- int i, iStart, iCount;
- COM_SB_BUF bkSBBuf;
- PCOMSBFRAME pFrame;
- PCCMYCDATA pYCData;
- PCCMYXDATA pYXData;
- USHORT nDataLen;
- memset( &bkSBBuf, 0, sizeof( COM_SB_BUF ) );
- BOOL bEnd = FALSE;
- iStart = 0;
- iCount = YCInfoAry2.GetSize();
- while (!bEnd && iCount>0)
- {
- // 组织数据,注意数据地址处数据类型的转换
- bkSBBuf.nDataTotalLength = offsetof(COM_SB_BUF, byBuffer); // 数据总长度
- bkSBBuf.pInfPoint[0] = bkSBBuf.nDataTotalLength;
- bkSBBuf.nInfBlockNum = 1; // 信息块个数只有一个即为遥测数据
- nDataLen = bkSBBuf.nDataTotalLength;
- pFrame = (COMSBFRAME*) (&(bkSBBuf.bySB_Reserve[nDataLen]));
- #ifdef NEW_SYSTEM
- pFrame->byType = 12; // 状态估计浮点型数据
- #else
- pFrame->byType = 0; // 状态估计浮点型数据
- #endif
- pFrame->nDataLength = 0;
- nDataLen += 3;
- bkSBBuf.nDataTotalLength = nDataLen;
- try
- {
- // nDataLen - 当前数据总长度
- pYCData = (PCCMYCDATA)(&(bkSBBuf.bySB_Reserve[nDataLen]));
- for (i=iStart; i<iCount; i++)
- {
- if ( nDataLen+sizeof(CCMYCDATA) >= sizeof(COM_SB_BUF) )
- {
- iStart = i; break; //实施发送
- }
- nDataLen += sizeof(CCMYCDATA);
- // 部件类型
- pYCData->sDataId.byBjType = YCInfoAry2[i]->DBID.byBjType;
- pYCData->sDataId.byCShType = YCInfoAry2[i]->DBID.byCShType;
- pYCData->sDataId.nBjID = YCInfoAry2[i]->DBID.nBjID;
- // pYCData->DataVal = 100;
- pYCData->DataVal = (SHORT)YCInfoAry2[i]->fVal;
- pFrame->nDataLength += sizeof(CCMYCDATA);
- bkSBBuf.nDataTotalLength = nDataLen;
- pYCData++; // 继续下一个
- }
- if (i>=iCount) {bEnd = TRUE;} // 全部组包完毕
- }
- catch (...) {}
- // 发送
- if (bkSBBuf.nDataTotalLength> offsetof(COM_SB_BUF, byBuffer))
- {
- Sleep(1);
- CCMComToAdm (&bkSBBuf, bkSBBuf.nDataTotalLength);
- }
- }
- memset( &bkSBBuf, 0, sizeof( COM_SB_BUF ) );
- bEnd = FALSE;
- iStart = 0;
- iCount = YXInfoAry2.GetSize();
- while (!bEnd && iCount>0)
- {
- // 组织数据,注意数据地址处数据类型的转换
- bkSBBuf.nDataTotalLength = offsetof(COM_SB_BUF, byBuffer); // 数据总长度
- bkSBBuf.pInfPoint[0] = bkSBBuf.nDataTotalLength;
- bkSBBuf.nInfBlockNum = 1; // 信息块个数只有一个即为遥测数据
- nDataLen = bkSBBuf.nDataTotalLength;
- pFrame = (COMSBFRAME*) (&(bkSBBuf.bySB_Reserve[nDataLen]));
- pFrame->byType = 1; // 状态估计浮点型数据
- pFrame->nDataLength = 0;
- nDataLen += 3;
- bkSBBuf.nDataTotalLength = nDataLen;
- try
- {
- // nDataLen - 当前数据总长度
- pYXData = (PCCMYXDATA)(&(bkSBBuf.bySB_Reserve[nDataLen]));
- for (i=iStart; i<iCount; i++)
- {
- if ( nDataLen+sizeof(CCMYXDATA) >= sizeof(COM_SB_BUF) )
- {
- //实施发送
- iStart = i;
- break;
- }
- nDataLen += sizeof(CCMYXDATA);
- // 部件类型
- pYXData->sDataId.byBjType = YXInfoAry2[i]->DBID.byBjType;
- pYXData->sDataId.byCShType = YXInfoAry2[i]->DBID.byCShType;
- pYXData->sDataId.nBjID = YXInfoAry2[i]->DBID.nBjID;
- // pYXData->DataVal = 1;
- pYXData->DataVal = YXInfoAry2[i]->bVal;
- pFrame->nDataLength += sizeof(CCMYXDATA);
- bkSBBuf.nDataTotalLength = nDataLen;
- pYXData++; // 继续下一个
- }
- if (i>=iCount) {bEnd = TRUE;} // 全部组包完毕
- }
- catch (...) {}
- // 发送
- if (bkSBBuf.nDataTotalLength> offsetof(COM_SB_BUF, byBuffer))
- {
- Sleep(1);
- CCMComToAdm (&bkSBBuf, bkSBBuf.nDataTotalLength);
- }
- }
- Disconnect500PPipeServer();
- bYXYCAryBusy = FALSE;
- return TRUE;
- };
- //////////////////////////////////////////////////////////////////////////////
- void GetRtuName(PDBID pDBID,CString& Name,int nYCYX)
- {
- BOOL bFind = FALSE;
- int RtuID=0;
- Name = "RTU";
- if (nYCYX==1)
- {
- int nYCNum = YCInfoAry1.GetSize();
- for (int i=0;i<nYCNum;i++)
- {
- if ((YCInfoAry1[i]->DBID.byBjType==pDBID->byBjType)
- &&(YCInfoAry1[i]->DBID.byCShType==pDBID->byCShType)&&(YCInfoAry1[i]->DBID.nBjID==pDBID->nBjID))
- {
- RtuID = YCInfoAry1[i]->nRTUID;
- bFind = TRUE;
- break;
- }
- }
- }
- else
- {
- int nYXNum = YXInfoAry1.GetSize();
- for (int i=0;i<nYXNum;i++)
- {
- if ((YXInfoAry1[i]->DBID.byBjType==pDBID->byBjType)
- &&(YXInfoAry1[i]->DBID.byCShType==pDBID->byCShType)&&(YXInfoAry1[i]->DBID.nBjID==pDBID->nBjID))
- {
- RtuID = YXInfoAry1[i]->nRTUID;
- bFind = TRUE;
- break;
- }
- }
- }
- if (bFind)
- {
- int nRTUNum = RtuAry.GetSize();
- for (int i=0;i<nRTUNum;i++)
- {
- if (RtuAry[i]->nRtuID==RtuID)
- {
- Name = RtuAry[i]->szName;
- break;
- }
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////
- BOOL ReadRTUYCYXInfo()
- {
- FreeRTUYXYCInfo();
- CRtu Rtu;
- Rtu.m_strSort = ("wRTUNum");
- Rtu.m_strFilter = ("");
- if (Rtu.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!Rtu.IsEOF())
- {
- PRTU pRTU = new RTU; memset(pRTU, 0 , sizeof(RTU));
- sprintf(pRTU->szName , Rtu.m_szMingZi);
- pRTU->nRtuID = Rtu.m_wRTUNum;
- pRTU->nYCNum = Rtu.m_wRTUYCNum;
- pRTU->nYXNum = Rtu.m_wRTUYXNum;
- RtuAry.Add(pRTU);
- Rtu.MoveNext();
- }
- Rtu.Close();
- }
- else
- return FALSE;
- CRTUYC RtuYC;
- RtuYC.m_strSort = ("wRTUNum, YC_NO");
- RtuYC.m_strFilter = ("byBjType<>0 and byCShType<>0 and nBjID<>0");
- float fCoef, fOffSet;
- CString strParaName;
- if (RtuYC.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!RtuYC.IsEOF())
- {
- PRTUYC pRTUYC = new RTUYC; memset(pRTUYC, 0 , sizeof(RTUYC));
- pRTUYC->DBID.byBjType = RtuYC.m_byBjType;
- pRTUYC->DBID.byCShType = RtuYC.m_byCShType;
- pRTUYC->DBID.nBjID = RtuYC.m_nBjID;
- pRTUYC->nRTUID = RtuYC.m_wRTUNum;
- if (GetMeaCoef(&(pRTUYC->DBID), &fCoef, &fOffSet, strParaName))
- {
- sprintf(pRTUYC->szName, strParaName);
- }
- YCInfoAry1.Add(pRTUYC);
- RtuYC.MoveNext();
- }
- RtuYC.Close();
- }
- else
- return FALSE;
- CRTUYX RtuYX;
- RtuYX.m_strSort = ("wRTUNum,YX_NO");
- RtuYX.m_strFilter = ("byBjType<>0 and byCShType<>0 and nBjID<>0");
- if (RtuYX.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!RtuYX.IsEOF())
- {
- PRTUYX pRTUYX = new RTUYX; memset(pRTUYX, 0, sizeof(RTUYX));
- pRTUYX->DBID.byBjType = RtuYX.m_byBjType;
- pRTUYX->DBID.byCShType = RtuYX.m_byCShType;
- pRTUYX->DBID.nBjID = RtuYX.m_nBjID;
- pRTUYX->nRTUID = RtuYX.m_wRTUNum;
- if (GetMeaCoef(&(pRTUYX->DBID), &fCoef, &fOffSet, strParaName))
- {
- sprintf(pRTUYX->szName, strParaName);
- }
- YXInfoAry1.Add(pRTUYX);
- RtuYX.MoveNext();
- }
- RtuYX.Close();
- }
- else
- return FALSE;
- return TRUE;
- };
- // 从电网部件中创建所有的量测信息
- void CreateMeaAryFromPwrNet()
- {
- PRTUYC pRTUYC = NULL;
- PRTUYX pRTUYX = NULL;
- // 电网(频率)
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = DianWangTab_ID;
- pRTUYC->DBID.byCShType = DW_PinLu;
- pRTUYC->DBID.nBjID = 1 ;
- YCInfoAry3.Add(pRTUYC);
- // 厂站(频率)
- int nStaNum = StaParaAry.GetSize();
- for (int i=0; i<nStaNum; i++)
- {
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = ChangZhanTab_ID;
- pRTUYC->DBID.byCShType = CZ_PinLu;
- pRTUYC->DBID.nBjID = StaParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- }
- // CT(有功、无功、电流)
- int nCTNum = CTParaAry.GetSize();
- for (i=0; i<nCTNum; i++)
- {
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_P;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_Q;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #ifdef NEW_SYSTEM
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_Ia;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_Ib;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_Ic;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #else
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = CTTab_ID;
- pRTUYC->DBID.byCShType = CT_I;
- pRTUYC->DBID.nBjID = CTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #endif
- }
- // PT(有功、无功、电流)
- int nPTNum = PTParaAry.GetSize();
- for (i=0; i<nPTNum; i++)
- {
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VA;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VB;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VC;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #ifdef NEW_SYSTEM
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VabX;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VbcX;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VcaX;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #else
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = PTTab_ID;
- pRTUYC->DBID.byCShType = PT_VX;
- pRTUYC->DBID.nBjID = PTParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- #endif
- }
- // 虚拟模拟量(模拟量值)
- int nVMeaNum = VAMeaParaAry.GetSize();
- for (i=0; i<nVMeaNum; i++)
- {
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = XuNiDMNLiangTab_ID;
- pRTUYC->DBID.byCShType = XN_XNValue;
- pRTUYC->DBID.nBjID = VAMeaParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- }
- // 变压器(分接头)
- int nTranNum = TranParaAry.GetSize();
- for (i=0; i<nTranNum; i++)
- {
- if (TranParaAry[i]->bLTC)
- {
- pRTUYC = new RTUYC;
- pRTUYC->DBID.byBjType = BianYaQiTab_ID;
- pRTUYC->DBID.byCShType = BYQ_DDFJT;
- pRTUYC->DBID.nBjID = TranParaAry[i]->ID ;
- YCInfoAry3.Add(pRTUYC);
- }
- }
- // 开关(开关状态)
- int nCBNum = CBParaAry.GetSize();
- for (i=0; i<nCBNum; i++)
- {
- pRTUYX = new RTUYX;
- pRTUYX->DBID.byBjType = KaiGuanTab_ID;
- pRTUYX->DBID.byCShType = KG_KGState;
- pRTUYX->DBID.nBjID = CBParaAry[i]->ID;
- YXInfoAry3.Add(pRTUYX);
- }
- // 刀闸(刀闸状态)
- int nDisNum = DisParaAry.GetSize();
- for (i=0; i<nDisNum; i++)
- {
- pRTUYX = new RTUYX;
- pRTUYX->DBID.byBjType = DaoZhaTab_ID;
- pRTUYX->DBID.byCShType = DZ_DZState;
- pRTUYX->DBID.nBjID = DisParaAry[i]->ID;
- YXInfoAry3.Add(pRTUYX);
- }
- }
- // 从YC、YX表中找出指定RTU的起始索引
- int GetRTUYXYCStartIdx(int nRTUID, int nYCYX)
- {
- int nYCNum = YCInfoAry1.GetSize();
- int nYXNum = YXInfoAry1.GetSize();
- int nStartIdx = -1;
- if (nYCYX == 1)
- {
- for (int i=0; i<nYCNum; i++)
- {
- if (YCInfoAry1[i]->nRTUID == nRTUID)
- {
- nStartIdx = i;
- break;
- }
- }
- }
- else
- {
- for (int i=0; i<nYXNum; i++)
- {
- if (YXInfoAry1[i]->nRTUID == nRTUID)
- {
- nStartIdx = i;
- break;
- }
- }
- }
- return nStartIdx;
- }
- // 从YC、YX表中找出指定RTU的YC或YX数目
- int GetRTUYCYXNum(int nRTUID, int nYC, int nStartIdx)
- {
- int nYCNum = YCInfoAry1.GetSize();
- int nYXNum = YXInfoAry1.GetSize();
- int nYCYXNum = 0;
- if (nYC == 1)
- {
- for (int i=nStartIdx; i<nYCNum; i++)
- {
- if (YCInfoAry1[i]->nRTUID == nRTUID) nYCYXNum++;
- else break;
- }
- }
- else
- {
- for (int i=nStartIdx; i<nYXNum; i++)
- {
- if (YXInfoAry1[i]->nRTUID == nRTUID) nYCYXNum++;
- else break;
- }
- }
- return nYCYXNum;
- }
- // 获取YC、YX信息表中的所有实时数据
- // 1、RTU接收YC、YX量测表;
- // 2、所有电网设备的实时信息组成的量测表
- BOOL GetAllRTData()
- {
- if (!ConnectServ()) return FALSE;
- RTMenuData RtMenuData;
- int nYCNum = 0;
- if (bRTUMea) nYCNum = YCInfoAry1.GetSize();
- else nYCNum = YCInfoAry3.GetSize();
- int nCount = 0;
- for (int i=0; i<nYCNum; i++)
- {
- if (bRTUMea)
- {
- RtMenuData.PartsRtData[nCount].wPartTypeID = YCInfoAry1[i]->DBID.byBjType;
- RtMenuData.PartsRtData[nCount].wPartParaID = YCInfoAry1[i]->DBID.byCShType;
- RtMenuData.PartsRtData[nCount].wPartID = YCInfoAry1[i]->DBID.nBjID;
- }
- else
- {
- RtMenuData.PartsRtData[nCount].wPartTypeID = YCInfoAry3[i]->DBID.byBjType;
- RtMenuData.PartsRtData[nCount].wPartParaID = YCInfoAry3[i]->DBID.byCShType;
- RtMenuData.PartsRtData[nCount].wPartID = YCInfoAry3[i]->DBID.nBjID;
- }
- nCount++;
- if (nCount == MAX_ID_NUM || i == nYCNum-1)
- {
- RtMenuData.wIDNum = nCount;
- GetRealData(RtMenuData);
- for (int j=0; j<nCount; j++)
- {
- if (bRTUMea)
- {
- if (YCInfoAry1[i+1-nCount +j]->DBID.byBjType == BianYaQiTab_ID)
- YCInfoAry1[i+1-nCount +j]->fVal = float(RtMenuData.PartsRtData[j].dwTap);
- else
- YCInfoAry1[i+1-nCount +j]->fVal = RtMenuData.PartsRtData[j].fYCData;
- }
- else
- {
- if (YCInfoAry3[i+1-nCount +j]->DBID.byBjType == BianYaQiTab_ID)
- YCInfoAry3[i+1-nCount +j]->fVal = float(RtMenuData.PartsRtData[j].dwTap);
- else
- YCInfoAry3[i+1-nCount +j]->fVal = RtMenuData.PartsRtData[j].fYCData;
- }
- }
- nCount = 0;
- }
- }
- // 开关状态的处理(KG_RTUKG1, KG_RTUKG2)
- int nYXNum = 0;
- if (bRTUMea) nYXNum = YXInfoAry1.GetSize();
- else nYXNum = YXInfoAry3.GetSize();
- nCount = 0;
- for (i=0; i<nYXNum; i++)
- {
- if (bRTUMea)
- {
- RtMenuData.PartsRtData[nCount].wPartTypeID = YXInfoAry1[i]->DBID.byBjType;
- RtMenuData.PartsRtData[nCount].wPartID = YXInfoAry1[i]->DBID.nBjID;
- if (YXInfoAry1[i]->DBID.byBjType == KaiGuanTab_ID &&
- (YXInfoAry1[i]->DBID.byCShType == KG_RTUKG1 ||
- YXInfoAry1[i]->DBID.byCShType == KG_RTUKG2))
- RtMenuData.PartsRtData[nCount].wPartParaID = KG_KGState;
- }
- else
- {
- RtMenuData.PartsRtData[nCount].wPartTypeID = YXInfoAry3[i]->DBID.byBjType;
- RtMenuData.PartsRtData[nCount].wPartID = YXInfoAry3[i]->DBID.nBjID;
- if (YXInfoAry3[i]->DBID.byBjType == KaiGuanTab_ID &&
- (YXInfoAry3[i]->DBID.byCShType == KG_RTUKG1 ||
- YXInfoAry3[i]->DBID.byCShType == KG_RTUKG2))
- RtMenuData.PartsRtData[nCount].wPartParaID = KG_KGState;
- }
- nCount++;
- if (nCount == MAX_ID_NUM || i == nYXNum-1)
- {
- RtMenuData.wIDNum = nCount;
- GetRealData(RtMenuData);
- for (int j=0; j<nCount; j++)
- {
- if (bRTUMea) YXInfoAry1[i+1-nCount +j]->bVal = RtMenuData.PartsRtData[j].byYXVal;
- else YXInfoAry3[i+1-nCount +j]->bVal = RtMenuData.PartsRtData[j].byYXVal;
- }
- nCount = 0;
- }
- }
- DisConnectServ();
- return TRUE;
- }
- BOOL bSaveAll = TRUE;
- int nPreMinute = -1;
- BOOL saveAllRTDataToFile()
- {
- CString strFile;
- CTime Time = CTime::GetCurrentTime();
- strFile.Format("C:\IES500\PARAM\实时数据\实时数据%02d%02d%02d%02d.dat", Time.GetDay(), Time.GetHour(),
- Time.GetMinute(), Time.GetSecond());
- CFile fWR;
- BOOL bOper = fWR.Open(strFile, CFile::modeWrite|CFile::modeCreate);
- if (!bOper) return FALSE;
- // 每10分钟保存1次全网数据
- int nMinute = Time.GetMinute();
- if (nMinute%10 == 0 && nMinute != nPreMinute)
- {
- bSaveAll = TRUE;
- nPreMinute = nMinute;
- }
- int iItemCount=0;
- int nYCNum = 0;
- if (bRTUMea) nYCNum = YCInfoAry1.GetSize();
- else nYCNum = YCInfoAry3.GetSize();
- int nYXNum = 0;
- if (bRTUMea) nYXNum = YXInfoAry1.GetSize();
- else nYXNum = YXInfoAry3.GetSize();
- int nChangedYCNum = 0;
- int nChangedYXNum = 0;
- for (int i=0; i<nYCNum; i++)
- {
- if (bRTUMea)
- {
- if (YCInfoAry1[i]->DBID.byBjType == DianWangTab_ID && YCInfoAry1[i]->DBID.byCShType == DW_PinLu)
- {
- YCInfoAry1[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else if (YCInfoAry1[i]->DBID.byBjType == ChangZhanTab_ID && YCInfoAry1[i]->DBID.byCShType == CZ_PinLu)
- {
- YCInfoAry1[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else if (fabs(YCInfoAry1[i]->fVal-YCInfoAry1[i]->fPreVal)>0.1)
- {
- YCInfoAry1[i]->fPreVal = YCInfoAry1[i]->fVal;
- YCInfoAry1[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else
- YCInfoAry1[i]->bChanged = 0;
- }
- else
- {
- if (YCInfoAry3[i]->DBID.byBjType == DianWangTab_ID && YCInfoAry3[i]->DBID.byCShType == DW_PinLu)
- {
- YCInfoAry3[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else if (YCInfoAry3[i]->DBID.byBjType == ChangZhanTab_ID && YCInfoAry3[i]->DBID.byCShType == CZ_PinLu)
- {
- YCInfoAry3[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else if (fabs(YCInfoAry3[i]->fVal-YCInfoAry3[i]->fPreVal)>0.1)
- {
- YCInfoAry3[i]->fPreVal = YCInfoAry3[i]->fVal;
- YCInfoAry3[i]->bChanged = 1;
- nChangedYCNum ++;
- }
- else
- YCInfoAry3[i]->bChanged = 0;
- }
- }
- for (i=0; i<nYXNum; i++)
- {
- if (bRTUMea)
- {
- if (YXInfoAry1[i]->bVal != YXInfoAry1[i]->bPreVal)
- {
- YXInfoAry1[i]->bPreVal = YXInfoAry1[i]->bVal;
- YXInfoAry1[i]->bChanged = 1;
- nChangedYXNum ++;
- }
- else
- YXInfoAry1[i]->bChanged = 0;
- }
- else
- {
- if (YXInfoAry3[i]->bVal != YXInfoAry3[i]->bPreVal)
- {
- YXInfoAry3[i]->bPreVal = YXInfoAry3[i]->bVal;
- YXInfoAry3[i]->bChanged = 1;
- nChangedYXNum ++;
- }
- else
- YXInfoAry3[i]->bChanged = 0;
- }
- }
- try
- {
- if (bSaveAll)
- {
- nChangedYCNum = nYCNum;
- nChangedYXNum = nYXNum;
- }
- fWR.Write (&nChangedYCNum, sizeof(int));
- for (int i=0; i<nYCNum; i++)
- {
- if (bRTUMea)
- {
- if (YCInfoAry1[i]->bChanged || bSaveAll)
- {
- fWR.Write (&(YCInfoAry1[i]->DBID), sizeof(DBID));
- fWR.Write (&YCInfoAry1[i]->fVal, sizeof (float));
- }
- }
- else
- {
- if (YCInfoAry3[i]->bChanged || bSaveAll)
- {
- fWR.Write (&(YCInfoAry3[i]->DBID), sizeof(DBID));
- fWR.Write (&YCInfoAry3[i]->fVal, sizeof (float));
- }
- }
- }
- fWR.Write (&nChangedYXNum, sizeof(int));
- for (i=0; i<nYXNum; i++)
- {
- if (bRTUMea)
- {
- if (YXInfoAry1[i]->bChanged || bSaveAll)
- {
- fWR.Write (&(YXInfoAry1[i]->DBID), sizeof(DBID));
- fWR.Write (&YXInfoAry1[i]->bVal, sizeof (BYTE));
- }
- }
- else
- {
- if (YXInfoAry3[i]->bChanged || bSaveAll)
- {
- fWR.Write (&(YXInfoAry3[i]->DBID), sizeof(DBID));
- fWR.Write (&YXInfoAry3[i]->bVal, sizeof (BYTE));
- }
- }
- }
- fWR.Close();
- }
- catch(...){return FALSE;}
- bSaveAll = FALSE;
- return TRUE;
- }
- void FreeRTUYXYCInfo()
- {
- int nRTUNum = RtuAry.GetSize();
- for (int i=0; i<nRTUNum; i++) delete RtuAry[i];
- RtuAry.RemoveAll();
- int nYCNum = YCInfoAry1.GetSize();
- for (i=0; i<nYCNum; i++) delete YCInfoAry1[i];
- YCInfoAry1.RemoveAll();
- int nYXNum = YXInfoAry1.GetSize();
- for (i=0; i<nYXNum; i++) delete YXInfoAry1[i];
- YXInfoAry1.RemoveAll();
- }
- void FreeFileYXYCInfo()
- {
- int nYCNum = YCInfoAry2.GetSize();
- for (int i=0; i<nYCNum; i++) delete YCInfoAry2[i];
- YCInfoAry2.RemoveAll();
- int nYXNum = YXInfoAry2.GetSize();
- for (i=0; i<nYXNum; i++) delete YXInfoAry2[i];
- YXInfoAry2.RemoveAll();
- }
- void FreeMeaCoefInfo()
- {
- int nStaNum = StaParaAry.GetSize();
- for (int i=0; i<nStaNum; i++) delete StaParaAry[i];
- StaParaAry.RemoveAll();
- int nCTNum = CTParaAry.GetSize();
- for (i=0; i<nCTNum; i++) delete CTParaAry[i];
- CTParaAry.RemoveAll();
- int nPTNum = PTParaAry.GetSize();
- for (i=0; i<nPTNum; i++) delete PTParaAry[i];
- PTParaAry.RemoveAll();
- int nVAMeaNum = VAMeaParaAry.GetSize();
- for (i=0; i<nVAMeaNum; i++) delete VAMeaParaAry[i];
- VAMeaParaAry.RemoveAll();
- int nCBNum = CBParaAry.GetSize();
- for (i=0; i<nCBNum; i++) delete CBParaAry[i];
- CBParaAry.RemoveAll();
- int nDisNum = DisParaAry.GetSize();
- for (i=0; i<nDisNum; i++) delete DisParaAry[i];
- DisParaAry.RemoveAll();
- int nTranNum = TranParaAry.GetSize();
- for (i=0; i<nTranNum; i++) delete TranParaAry[i];
- TranParaAry.RemoveAll();
- int nYCNum = YCInfoAry3.GetSize();
- for (i=0; i<nYCNum; i++) delete YCInfoAry3[i];
- YCInfoAry3.RemoveAll();
- int nYXNum = YXInfoAry3.GetSize();
- for (i=0; i<nYXNum; i++) delete YXInfoAry3[i];
- YXInfoAry3.RemoveAll();
- };
- BOOL ReadMeaCoefInfo()
- {
- FreeMeaCoefInfo();
- // 电网参数
- CPwrNet PwrNet;
- if (PwrNet.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- PWRNETPARA PwrNetPara;
- lstrcpyn(PwrNetPara.szName, PwrNet.m_MingZi, PwrNet.m_MingZi.GetLength()+1);
- CutSpaceChar(PwrNetPara.szName, 32);
- PwrNetPara.fPCoef = PwrNet.m_PCoef;
- PwrNetPara.fQCoef = PwrNet.m_QCoef;
- PwrNetPara.fFCoef = 100.f;
- PwrNet.Close();
- }
- else
- return FALSE;
- // 合肥电话 0551-3701024
- // 厂站参数
- CStation Station;
- Station.m_strSort = ("ID");
- Station.m_strFilter = ("ID>0");
- if (Station.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!Station.IsEOF())
- {
- LPSTATIONPARA pStaPara = new STATIONPARA;
- lstrcpyn(pStaPara->szName, Station.m_MingZi, Station.m_MingZi.GetLength()+1);
- CutSpaceChar(pStaPara->szName, 32);
- pStaPara->ID = Station.m_ID;
- pStaPara->fPCoef = Station.m_PCoef;
- pStaPara->fQCoef = Station.m_QCoef;
- pStaPara->fFCoef = 100.f;
- StaParaAry.Add(pStaPara);
- Station.MoveNext();
- }
- Station.Close();
- }
- else
- return FALSE;
- // CT参数
- CCT CT;
- CT.m_strSort = ("ID");
- CT.m_strFilter = ("ID>0");
- if (CT.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!CT.IsEOF())
- {
- LPCTPARA pCTPara = new CTPARA;
- lstrcpyn(pCTPara->szName, CT.m_MingZi, CT.m_MingZi.GetLength()+1);
- CutSpaceChar(pCTPara->szName, 32);
- pCTPara->ID = CT.m_ID;
- pCTPara->fPCoef = CT.m_PCoef;
- pCTPara->fQCoef = CT.m_QCoef;
- pCTPara->fPOffSet = CT.m_POffset;
- pCTPara->fQOffSet = CT.m_QOffset;
- #ifdef NEW_SYSTEM
- pCTPara->fIACoef = CT.m_IACoef;
- pCTPara->fIAOffSet = CT.m_IAOffset;
- pCTPara->fIBCoef = CT.m_IBCoef;
- pCTPara->fIBOffSet = CT.m_IBOffset;
- pCTPara->fICCoef = CT.m_ICCoef;
- pCTPara->fICOffSet = CT.m_ICOffset;
- #else
- pCTPara->fICoef = CT.m_ICoef;
- pCTPara->fIOffSet = CT.m_IOffset;
- #endif
- CTParaAry.Add(pCTPara);
- CT.MoveNext();
- }
- CT.Close();
- }
- else
- return FALSE;
- // PT参数
- CPT PT;
- PT.m_strSort = ("ID");
- PT.m_strFilter = ("ID>0");
- if (PT.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!PT.IsEOF())
- {
- LPPTPARA pPTPara = new PTPARA;
- lstrcpyn(pPTPara->szName, PT.m_MingZi, PT.m_MingZi.GetLength()+1);
- CutSpaceChar(pPTPara->szName, 32);
- pPTPara->ID = PT.m_ID;
- pPTPara->fVACoef = PT.m_VACoef;
- pPTPara->fVBCoef = PT.m_VBCoef;
- pPTPara->fVCCoef = PT.m_VCCoef;
- pPTPara->fVAOffSet = PT.m_VAOffset;
- pPTPara->fVBOffSet = PT.m_VBOffset;
- pPTPara->fVBOffSet = PT.m_VCOffset;
- #ifdef NEW_SYSTEM
- pPTPara->fVABCoef = PT.m_VXABCoef;
- pPTPara->fVABOffSet = PT.m_VXABOffset;
- pPTPara->fVBCCoef = PT.m_VXBCCoef;
- pPTPara->fVBCOffSet = PT.m_VXBCOffset;
- pPTPara->fVACCoef = PT.m_VXBCCoef;
- pPTPara->fVACOffSet = PT.m_VXBCOffset;
- #else
- pPTPara->fVXCoef = PT.m_VXCoef;
- pPTPara->fVXOffSet = PT.m_VXOffset;
- #endif
- PTParaAry.Add(pPTPara);
- PT.MoveNext();
- }
- PT.Close();
- }
- else
- return FALSE;
- // 虚拟量参数
- CAMea VAMea;
- VAMea.m_strSort = ("ID");
- VAMea.m_strFilter = ("ID>0");
- if (VAMea.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!VAMea.IsEOF())
- {
- LPVAMEAPARA pVAMeaPara = new VAMEAPARA;
- lstrcpyn(pVAMeaPara->szName, VAMea.m_MingZi, VAMea.m_MingZi.GetLength()+1);
- CutSpaceChar(pVAMeaPara->szName, 32);
- pVAMeaPara->ID = VAMea.m_ID;
- pVAMeaPara->fCoef = VAMea.m_Coef;
- pVAMeaPara->fOffSet = VAMea.m_OffSetVal;
- VAMeaParaAry.Add(pVAMeaPara);
- VAMea.MoveNext();
- }
- VAMea.Close();
- }
- else
- return FALSE;
- // 开关参数
- CCB CBRec;
- CBRec.m_strSort = ("ID");
- CBRec.m_strFilter = ("ID>0");
- if (CBRec.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!CBRec.IsEOF())
- {
- LPCBPARA pCBPara = new CBPARA;
- lstrcpyn(pCBPara->szName, CBRec.m_MingZi, CBRec.m_MingZi.GetLength()+1);
- CutSpaceChar(pCBPara->szName, 32);
- pCBPara->ID = CBRec.m_ID;
- pCBPara->bNot = CBRec.m_YXConnect;
- pCBPara->bTwoBit = CBRec.m_YXCMode;
- CBParaAry.Add(pCBPara);
- CBRec.MoveNext();
- }
- CBRec.Close();
- }
- else
- return FALSE;
- // 刀闸参数
- CDisCon DisRec;
- DisRec.m_strSort = ("ID");
- DisRec.m_strFilter = ("ID>0");
- if (DisRec.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!DisRec.IsEOF())
- {
- LPDISPARA pDisPara = new DISPARA;
- lstrcpyn(pDisPara->szName, DisRec.m_MingZi, DisRec.m_MingZi.GetLength()+1);
- CutSpaceChar(pDisPara->szName, 32);
- pDisPara->ID = DisRec.m_ID;
- pDisPara->bNot = DisRec.m_Nots;
- DisParaAry.Add(pDisPara);
- DisRec.MoveNext();
- }
- DisRec.Close();
- }
- else
- return FALSE;
- // 变压器参数
- CTran TranRec;
- TranRec.m_strSort = ("ID");
- TranRec.m_strFilter = ("ID>0");
- if (TranRec.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
- {
- while(!TranRec.IsEOF())
- {
- LPTRANPARA pTranPara = new TRANPARA;
- lstrcpyn(pTranPara->szName, TranRec.m_MingZi, TranRec.m_MingZi.GetLength()+1);
- CutSpaceChar(pTranPara->szName, 32);
- pTranPara->ID = TranRec.m_ID;
- pTranPara->bLTC = TranRec.m_DYMode;
- pTranPara->fTapCoef = TranRec.m_DWCoef;
- TranParaAry.Add(pTranPara);
- TranRec.MoveNext();
- }
- TranRec.Close();
- }
- else
- return FALSE;
- CreateMeaAryFromPwrNet();
- return TRUE;
- };
- BOOL GetMeaCoef(PDBID pDBID, float* pCoef, float* pOffSet, CString& strInfo)
- {
- *pCoef = 1.f; *pOffSet = 0.f;
- if (pDBID->byBjType == DianWangTab_ID)
- {
- if (pDBID->byCShType == DW_P)
- {
- *pCoef = PwrNetPara.fPCoef;
- strInfo = "电网有功";
- }
- else if (pDBID->byCShType == DW_Q)
- {
- *pCoef = PwrNetPara.fQCoef;
- strInfo = "电网无功";
- }
- else if (pDBID->byCShType == DW_PinLu)
- {
- *pCoef = PwrNetPara.fFCoef;
- strInfo = "电网频率";
- }
- }
- else if (pDBID->byBjType == ChangZhanTab_ID)
- {
- int nStaNum = StaParaAry.GetSize();
- if (nStaNum<1) return FALSE;
- int nStart = 0, nEnd = nStaNum-1;
- LPSTATIONPARA pStaPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (StaParaAry[nMid]->ID == pDBID->nBjID)
- {
- pStaPara = StaParaAry[nMid]; break;
- }
- else if (StaParaAry[nStart]->ID == pDBID->nBjID)
- {
- pStaPara = StaParaAry[nStart]; break;
- }
- else if (StaParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pStaPara = StaParaAry[nEnd]; break;
- }
- else if (StaParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pStaPara)
- {
- if (pDBID->byCShType == CZ_P)
- {
- *pCoef = pStaPara->fPCoef;
- strInfo.Format("%s--%s", pStaPara->szName, "有功");
- }
- else if (pDBID->byCShType == CZ_Q)
- {
- *pCoef = pStaPara->fQCoef;
- strInfo.Format("%s--%s", pStaPara->szName, "无功");
- }
- else if (pDBID->byCShType == CZ_PinLu)
- {
- *pCoef = pStaPara->fFCoef;
- strInfo.Format("%s--%s", pStaPara->szName, "频率");
- }
- }
- else
- return FALSE;
- }
- else if (pDBID->byBjType == CTTab_ID)
- {
- int nCTNum = CTParaAry.GetSize();
- if (nCTNum<1) return FALSE;
- int nStart = 0, nEnd = nCTNum-1;
- LPCTPARA pCTPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (CTParaAry[nMid]->ID == pDBID->nBjID)
- {
- pCTPara = CTParaAry[nMid]; break;
- }
- else if (CTParaAry[nStart]->ID == pDBID->nBjID)
- {
- pCTPara = CTParaAry[nStart]; break;
- }
- else if (CTParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pCTPara = CTParaAry[nEnd]; break;
- }
- else if (CTParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pCTPara)
- {
- if (pDBID->byCShType == CT_P)
- {
- *pCoef = pCTPara->fPCoef;
- *pOffSet = pCTPara->fPOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "有功");
- }
- else if (pDBID->byCShType == CT_Q)
- {
- *pCoef = pCTPara->fQCoef;
- *pOffSet = pCTPara->fQOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "无功");
- }
- #ifdef NEW_SYSTEM
- else if (pDBID->byCShType == CT_Ia)
- {
- *pCoef = pCTPara->fIACoef;
- *pOffSet = pCTPara->fIAOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "A相电流");
- }
- else if (pDBID->byCShType == CT_Ib)
- {
- *pCoef = pCTPara->fIBCoef;
- *pOffSet = pCTPara->fIBOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "B相电流");
- }
- else if (pDBID->byCShType == CT_Ic)
- {
- *pCoef = pCTPara->fICCoef;
- *pOffSet = pCTPara->fICOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "C相电流");
- }
- #else
- else if (pDBID->byCShType == CT_I)
- {
- *pCoef = pCTPara->fICoef;
- *pOffSet = pCTPara->fIOffSet;
- strInfo.Format("%s--%s", pCTPara->szName, "电流");
- }
- #endif
- }
- else
- return FALSE;
- }
- else if (pDBID->byBjType == PTTab_ID)
- {
- int nPTNum = PTParaAry.GetSize();
- if (nPTNum<1) return FALSE;
- int nStart = 0, nEnd = nPTNum-1;
- LPPTPARA pPTPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (PTParaAry[nMid]->ID == pDBID->nBjID)
- {
- pPTPara = PTParaAry[nMid]; break;
- }
- else if (PTParaAry[nStart]->ID == pDBID->nBjID)
- {
- pPTPara = PTParaAry[nStart]; break;
- }
- else if (PTParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pPTPara = PTParaAry[nEnd]; break;
- }
- else if (PTParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pPTPara)
- {
- if (pDBID->byCShType == PT_VA)
- {
- *pCoef = pPTPara->fVACoef;
- *pOffSet = pPTPara->fVAOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "A相电压");
- }
- else if (pDBID->byCShType == PT_VB)
- {
- *pCoef = pPTPara->fVBCoef;
- *pOffSet = pPTPara->fVBOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "B相电压");
- }
- else if (pDBID->byCShType == PT_VC)
- {
- *pCoef = pPTPara->fVCCoef;
- *pOffSet = pPTPara->fVCOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "C相电压");
- }
- #ifdef NEW_SYSTEM
- else if (pDBID->byCShType == PT_VabX)
- {
- *pCoef = pPTPara->fVABCoef;
- *pOffSet = pPTPara->fVABOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "AB线电压");
- }
- else if (pDBID->byCShType == PT_VbcX)
- {
- *pCoef = pPTPara->fVBCCoef;
- *pOffSet = pPTPara->fVBCOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "BC线电压");
- }
- else if (pDBID->byCShType == PT_VcaX)
- {
- *pCoef = pPTPara->fVACCoef;
- *pOffSet = pPTPara->fVACOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "AC线电压");
- }
- #else
- else if (pDBID->byCShType == PT_VX)
- {
- *pCoef = pPTPara->fVXCoef;
- *pOffSet = pPTPara->fVXOffSet;
- strInfo.Format("%s--%s", pPTPara->szName, "线电压");
- }
- #endif
- }
- else
- return FALSE;
- }
- else if (pDBID->byBjType == XuNiDMNLiangTab_ID)
- {
- int nVAMeaNum = VAMeaParaAry.GetSize();
- if (nVAMeaNum<1) return FALSE;
- int nStart = 0, nEnd = nVAMeaNum-1;
- LPVAMEAPARA pVAMeaPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (VAMeaParaAry[nMid]->ID == pDBID->nBjID)
- {
- pVAMeaPara = VAMeaParaAry[nMid]; break;
- }
- else if (VAMeaParaAry[nStart]->ID == pDBID->nBjID)
- {
- pVAMeaPara = VAMeaParaAry[nStart]; break;
- }
- else if (VAMeaParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pVAMeaPara = VAMeaParaAry[nEnd]; break;
- }
- else if (VAMeaParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pVAMeaPara)
- {
- if (pDBID->byCShType == XN_XNValue)
- {
- *pCoef = pVAMeaPara->fCoef;
- *pOffSet = pVAMeaPara->fOffSet;
- strInfo.Format("%s--%s", pVAMeaPara->szName, "数值");
- }
- }
- else
- return FALSE;
- }
- else if (pDBID->byBjType == KaiGuanTab_ID)
- {
- *pCoef = 0.f;
- int nCBNum = CBParaAry.GetSize();
- if (nCBNum<1) return FALSE;
- int nStart = 0, nEnd = nCBNum-1;
- LPCBPARA pCBPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (CBParaAry[nMid]->ID == pDBID->nBjID)
- {
- pCBPara = CBParaAry[nMid]; break;
- }
- else if (CBParaAry[nStart]->ID == pDBID->nBjID)
- {
- pCBPara = CBParaAry[nStart]; break;
- }
- else if (CBParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pCBPara = CBParaAry[nEnd]; break;
- }
- else if (CBParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pCBPara)
- {
- if (pDBID->byCShType == KG_RTUKG1)
- {
- strInfo.Format("%s--%s", pCBPara->szName, "开关状态1");
- *pCoef = float(pCBPara->bNot);
- }
- else if (pDBID->byCShType == KG_RTUKG2)
- {
- strInfo.Format("%s--%s", pCBPara->szName, "开关状态2");
- *pCoef = float(pCBPara->bNot);
- }
- }
- else
- return FALSE;
- }
- else if (pDBID->byBjType == DaoZhaTab_ID)
- {
- *pCoef = 0.f;
- int nDisNum = DisParaAry.GetSize();
- if (nDisNum<1) return FALSE;
- int nStart = 0, nEnd = nDisNum-1;
- LPDISPARA pDisPara = NULL;
- do
- {
- int nMid = (nStart+nEnd)/2;
- if (DisParaAry[nMid]->ID == pDBID->nBjID)
- {
- pDisPara = DisParaAry[nMid]; break;
- }
- else if (DisParaAry[nStart]->ID == pDBID->nBjID)
- {
- pDisPara = DisParaAry[nStart]; break;
- }
- else if (DisParaAry[nEnd]->ID == pDBID->nBjID)
- {
- pDisPara = DisParaAry[nEnd]; break;
- }
- else if (DisParaAry[nMid]->ID > pDBID->nBjID)
- nEnd = nMid;
- else
- nStart = nMid;
- if (nStart == nEnd || nStart+1 == nEnd) break;
- }while (TRUE);
- if (pDisPara)
- {
- if (pDBID->byCShType == DZ_DZState)
- {
- *pCoef = float(pDisPara->bNot);
- strInfo.Format("%s--%s", pDisPara->szName, "刀闸状态");
- }
- }
- else
- return FALSE;
- }
- return TRUE;
- }
- BOOL LoadRTDataFromFile(LPCSTR lpFName)
- {
- if (bYXYCAryBusy) return FALSE;
- CFile fRD;
- if (lpFName == NULL) return FALSE;
- BOOL bOper = fRD.Open(lpFName, CFile::modeRead);
- if (!bOper) return FALSE;
- bYXYCAryBusy = TRUE;
- FreeFileYXYCInfo();
- char szFile[] = "c:\ies500\tmp\YC-YX数据信息.INF";
- FILE* pFile = fopen(szFile, "w");
- // 数值项个数
- float fCoef, fOffSet;
- CString strInfo;
- int nYCNum, nYXNum;
- try
- {
- fRD.Read(&nYCNum, sizeof(int));
- if (pFile) fprintf(pFile, "YC数目:%dnn", nYCNum);
- if (nYCNum>0)
- {
- for (int i=0; i<nYCNum; i++)
- {
- PRTUYC pRTUYC = new RTUYC;
- fRD.Read(&(pRTUYC->DBID), sizeof(DBID));
- fRD.Read(&(pRTUYC->fVal), sizeof(float));
- //dtting
- if (GetMeaCoef(&(pRTUYC->DBID), &fCoef, &fOffSet, strInfo))
- {
- pRTUYC->fVal = pRTUYC->fVal/fCoef;
- }
- else
- {
- fprintf(pFile,"部件类型:%d ID:%d 参数:%dn",pRTUYC->DBID.byBjType,pRTUYC->DBID.nBjID,pRTUYC->DBID.byCShType);
- pRTUYC->fVal = pRTUYC->fVal/fCoef;
- }
- YCInfoAry2.Add(pRTUYC);
- }
- }
- fRD.Read(&nYXNum, sizeof(int));
- if (pFile) fprintf(pFile, "YX数目:%dnn", nYXNum);
- if (nYXNum>0)
- {
- for (int i=0; i<nYXNum; i++)
- {
- PRTUYX pRTUYX = new RTUYX;
- fRD.Read(&(pRTUYX->DBID), sizeof(DBID));
- YXInfoAry2.Add(pRTUYX);
- fRD.Read(&pRTUYX->bVal, sizeof(BYTE));
- PRTUYX pRTUYX2 = NULL;
- // 开关状态的处理(KG_RTUKG1, KG_RTUKG2)
- if (pRTUYX->DBID.byBjType == KaiGuanTab_ID &&
- pRTUYX->DBID.byCShType == KG_RTUKG1)
- pRTUYX->bVal = pRTUYX->bVal & 1;
- else if (pRTUYX->DBID.byBjType == KaiGuanTab_ID &&
- pRTUYX->DBID.byCShType == KG_RTUKG2)
- pRTUYX->bVal = (pRTUYX->bVal&2)/2;
- else if (pRTUYX->DBID.byBjType == KaiGuanTab_ID &&
- pRTUYX->DBID.byCShType == KG_KGState)
- {
- pRTUYX->DBID.byCShType = KG_RTUKG1;
- pRTUYX->bVal = pRTUYX->bVal & 1;
- pRTUYX2 = new RTUYX;
- memcpy(pRTUYX2, pRTUYX, sizeof(RTUYX));
- pRTUYX2->bVal = (pRTUYX->bVal&2)/2;
- pRTUYX2->DBID.byCShType = KG_RTUKG2;
- YXInfoAry2.Add(pRTUYX2);
- }
- GetMeaCoef(&(pRTUYX->DBID), &fCoef, &fOffSet, strInfo);
- if (fCoef == 1.f) pRTUYX->bVal = !pRTUYX->bVal;
- if (pRTUYX2 && fCoef == 1.f) pRTUYX2->bVal = !pRTUYX2->bVal;
- }
- }
- if (pFile) fclose(pFile);
- fRD.Close();
- }
- catch(...) {return FALSE;}
- bYXYCAryBusy = FALSE;
- return TRUE;
- }
- CSEventSequence CSEvtSeq(ALL_TYPE); // 声明一参数事项队类(指针)
- CSEVENT csEvent;
- // 保存电网数据事项触发 2001.8.1 TIANFZ
- // 检查变压器分接头调整、开关变位、刀闸变位事项
- BOOL BeSCADAEventProcess()
- {
- BOOL bEvtPrc = FALSE;
- int EvtLeftNum = CSEvtSeq.GetEventNum(); // 此时的未处理事项的数目
- while(EvtLeftNum>0)
- {
- //返回值为真, 则有事项存在且未处理,读完全部事项
- if(CSEvtSeq.ReadaEvent(&csEvent, EvtLeftNum))
- {
- // 为避免重复,只判断非 SOE 事项
- if(csEvent.SOEFlag) continue;
- if(csEvent.EventType == BYQEvent)
- {
- if(csEvent.CSType == BYQFJT) bEvtPrc = TRUE;
- }
- else if(csEvent.EventType == KGEvent)
- {
- if(csEvent.CSType == KG) bEvtPrc = TRUE;
- }
- else if(csEvent.EventType == DZEvent)
- {
- if(csEvent.CSType == DZ) bEvtPrc = TRUE;
- }
- }
- };
- return bEvtPrc;
- }
- void Ary2ToAry1()
- {
- int nYC2 = YCInfoAry2.GetSize();
- int nYX2 = YXInfoAry2.GetSize();
- int nYC1 = YCInfoAry1.GetSize();
- int nYX1 = YXInfoAry1.GetSize();
- for (int i=0; i<nYC1; i++) YCInfoAry1[i]->bChanged = 0;
- for (i=0; i<nYX1; i++) YXInfoAry1[i]->bChanged = 0;
- PRTUYC pRTUYC = NULL;
- for (i=0; i<nYC2; i++)
- {
- BOOL bFound = FALSE;
- pRTUYC = YCInfoAry2[i];
- for (int j=0; j<nYC1; j++)
- {
- if (memcmp(&(pRTUYC->DBID), &(YCInfoAry1[j]->DBID), sizeof(DBID)) == 0)
- {
- bFound = TRUE; break;
- }
- }
- if (bFound)
- {
- if (fabs(YCInfoAry1[j]->fVal - pRTUYC->fVal)>0.01)
- {
- YCInfoAry1[j]->fVal = pRTUYC->fVal;
- YCInfoAry1[j]->bChanged = 1;
- }
- }
- }
- PRTUYX pRTUYX = NULL;
- for (i=0; i<nYX2; i++)
- {
- BOOL bFound = FALSE;
- pRTUYX = YXInfoAry2[i];
- for (int j=0; j<nYX1; j++)
- {
- if (memcmp(&(pRTUYX->DBID), &(YXInfoAry1[j]->DBID), sizeof(DBID)) == 0)
- {
- bFound = TRUE; break;
- }
- }
- if (bFound)
- {
- if (YXInfoAry1[j]->bVal != pRTUYX->bVal)
- {
- YXInfoAry1[j]->bVal = pRTUYX->bVal;
- YXInfoAry1[j]->bChanged = 1;
- }
- }
- }
- }