PrtIEC101.cpp
上传用户:asikq0571
上传日期:2014-07-12
资源大小:528k
文件大小:37k
- // PrtIEC101.cpp: implementation of the CPrtIEC101 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Peugeot.h"
- #include "PrtIEC101.h"
- #include "MainFrm.h"
- #include "PeugeotDoc.h"
- #include "PeugeotView.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CPrtIEC101::CPrtIEC101()
- {
- //初始化变量
- m_Addr = 0x01;
- m_CauseOfTranLen = 0x01;
- m_CommAddrLen = 0x01;
- m_MsgAddrLen = 0x02;
- m_YXChara = YX_SINGLE | TIME24;
- m_YCChara = YC_TYPEA | TIME24;
- m_YKChara = YK_SINGLE | YK_S_ACK | YK_E_ACK;
- m_FCBFlag = 0x00;
- m_ACDFlag = 0x00;
-
- int i;
- for (i=0; i<21; i++)
- m_SRecByte[i] = 0x00;
-
- for (i=0; i<261; i++)
- m_SSendByte[i] = 0x00;
-
- m_SReadState = StartByte;
- m_MsgIndex = 0;
- }
- CPrtIEC101::~CPrtIEC101()
- {
- }
- void CPrtIEC101::StartTimer()
- {
- //启动主站召唤时钟
- //pView->SetTimer(1,m_CallIntv,NULL);
- }
- void CPrtIEC101::CloseTimer()
- {
- //关闭主站召唤时钟
- // pView->KillTimer(m_CallTimerID);
- }
- void CPrtIEC101::MasterSend(UINT nIDEvent)
- {
- //if (m_CallYXFlag)
-
- // CString s1;
- // s1.Format ("%d",nIDEvent);
- // AfxMessageBox(s1);
- }
- void CPrtIEC101::InitPrt()
- {
- // 规约初始化
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //视图指针
- ASSERT_VALID(pDoc);
- m_SSendLv1 = None; //子站发送1级数据的流程
- m_SYXAddrToSend = pDoc->m_YXAddr;
- m_SYCAddrToSend = pDoc->m_YCAddr;
- m_SYMAddrToSend = pDoc->m_YMAddr;
-
- int i = 0;
- //链路复位应答报文
- m_SAck_LinkR[0] = 0x10;
- m_SAck_LinkR[1] = 0x80; //最高位为传输方向,以下各帧同
- m_SAck_LinkR[2] = m_Addr;
- m_SAck_LinkR[3] = m_SAck_LinkR[1] + m_SAck_LinkR[2];
- m_SAck_LinkR[4] = 0x16;
- //请求链路状态应答报文
- m_SAck_LinkS[0] = 0x10;
- m_SAck_LinkS[1] = 0x8b;
- m_SAck_LinkS[2] = m_Addr;
- m_SAck_LinkS[3] = m_SAck_LinkS[1] + m_SAck_LinkS[2];
- m_SAck_LinkS[4] = 0x16;
- //应答2级数据
- m_SAck_Lv2[0] = 0x10;
- m_SAck_Lv2[1] = 0x89;
- m_SAck_Lv2[2] = m_Addr;
- m_SAck_Lv2[3] = m_SAck_Lv2[1] + m_SAck_Lv2[2];
- m_SAck_Lv2[4] = 0x16;
-
- //总召唤应答
- m_SAck_IC[0] = 0x68;
- m_SAck_IC[1] = 0x05 + m_CauseOfTranLen + m_CommAddrLen + m_MsgAddrLen;
- m_SAck_IC[2] = m_SAck_IC[1];
- m_SAck_IC[3] = 0x68;
- m_SAck_IC[4] = 0xa0; //传输方向,及要求访问位1010 0000
- m_SAck_IC[5] = m_Addr;
- m_SAck_IC[6] = 0x64; //类型标识
- m_SAck_IC[7] = 0x01;
- m_SAck_IC[8] = 0x07; //传送原因:激活确认
- m_SAck_IC[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
-
- for (i=0; i<m_CommAddrLen; i++) //ASDU公共地址
- m_SAck_IC[8+m_CauseOfTranLen+i] = m_Addr;
- for (i=0; i<m_MsgAddrLen; i++)
- m_SAck_IC[8+m_CauseOfTranLen+m_CommAddrLen+i] = 0x00; //信息体公共地址
- m_SAck_IC[3+m_SAck_IC[1]] = 0x14; //站召唤
- m_SAck_IC[4+m_SAck_IC[1]] = GetAddByte(m_SAck_IC,m_SAck_IC[1],4); //和校验
- m_SAck_IC[5+m_SAck_IC[1]] = 0x16;
- //总召唤结束
- m_SAck_IC_End[0] = 0x68;
- m_SAck_IC_End[1] = 0x05 + m_CauseOfTranLen + m_CommAddrLen + m_MsgAddrLen;
- m_SAck_IC_End[2] = m_SAck_IC_End[1];
- m_SAck_IC_End[3] = 0x68;
- m_SAck_IC_End[4] = 0x80 + 0x08; //传输方向,要求访问位为0
- m_SAck_IC_End[5] = m_Addr;
- m_SAck_IC_End[6] = 0x64; //类型标识
- m_SAck_IC_End[7] = 0x01;
- m_SAck_IC_End[8] = 0x0a; //传送原因:激活中止
- m_SAck_IC_End[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
-
-
- for (i=0; i<m_CommAddrLen; i++) //ASDU公共地址
- m_SAck_IC_End[8+m_CauseOfTranLen+i] = m_Addr;
- for (i=0; i<m_MsgAddrLen; i++)
- m_SAck_IC_End[8+m_CauseOfTranLen+m_CommAddrLen+i] = 0x00; //信息体公共地址
- m_SAck_IC_End[3+m_SAck_IC_End[1]] = 0x14; //站召唤
- m_SAck_IC_End[4+m_SAck_IC_End[1]] = GetAddByte(m_SAck_IC_End,m_SAck_IC_End[1],4); //和校验
- m_SAck_IC_End[5+m_SAck_IC_End[1]] = 0x16;
- }
- void CPrtIEC101::MasterRec(BYTE recByte)
- {
- }
- //子站接收主站报文
- void CPrtIEC101::SlaveRec(BYTE recByte)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- switch (m_SReadState)
- {
- case StartByte:
- m_SRecByte[0] = recByte;
- if (m_SRecByte[0] == 0x10)
- m_SReadState = CtrlByte;
- else if (m_SRecByte[0] == 0x68)
- m_SReadState = Num_68H_1;
- break;
- //=========== 启动字符为10H ==========//
- case CtrlByte:
- m_SRecByte[1] = recByte;
- m_SReadState = AddrByte;
- break;
- case AddrByte:
- if ( recByte == m_Addr)
- {
- m_SRecByte[2] = recByte;
- m_SReadState = CheckByte;
- }
- else
- m_SReadState = StartByte;
- break;
- case CheckByte:
- m_SRecByte[3] = recByte;
- BYTE b1 ;
- b1 = m_SRecByte[1] + m_SRecByte[2];
- if (m_SRecByte[3] == b1)
- m_SReadState = EndByte;
- else
- m_SReadState = StartByte;
- break;
- case EndByte: //启动字符为10H的报文接收完毕,解包
- m_SRecByte[4] = recByte;
- if (m_SRecByte[4] == 0X16)
- SUnPack_Start10H(); //解包
- m_SReadState = StartByte;
- break;
- //=========== 启动字符为68H ==========//
- case Num_68H_1:
- m_SRecByte[1] = recByte;
- m_SReadState = Num_68H_2;
- break;
- case Num_68H_2:
- m_SRecByte[2] = recByte;
- if (m_SRecByte[2] == m_SRecByte[1])
- m_SReadState = Start_68H_2;
- else
- m_SReadState = StartByte;
- break;
- case Start_68H_2:
- m_SRecByte[3] = recByte;
- if (m_SRecByte[3] == 0x68)
- {
- m_MsgIndex = 0;
- m_SReadState = Msg_68H;
- }
- else
- m_SReadState = StartByte;
- break;
- case Msg_68H:
- m_SRecByte[4+m_MsgIndex] = recByte;
- if (m_MsgIndex < (m_SRecByte[1]-1)) // 如读取的字节数小于信息字节数,则继续读取
- m_MsgIndex++;
- else
- {
- m_SReadState = Check_68H;
- m_MsgIndex = 0;
- }
- break;
- case Check_68H:
- m_SRecByte[4+m_SRecByte[1]] = recByte;
- BYTE tembyte;
- tembyte = GetAddByte(m_SRecByte,m_SRecByte[1],4);
- if (m_SRecByte[4+m_SRecByte[1]] == tembyte)
- m_SReadState = End_68H;
- else
- m_SReadState = StartByte;
- break;
- case End_68H: //启动字符为68H的报文接收完毕,解包
- m_SRecByte[5+m_SRecByte[1]] = recByte;
- if (m_SRecByte[5+m_SRecByte[1]] == 0X16 &&
- m_SRecByte[5] == m_Addr)
- SUnPack_Start68H(); //解包
-
- m_SReadState = StartByte;
- break;
- ///////////////////////////////////////////////
- default:
- m_SReadState = StartByte; //重新从地址码读取
- break;
- }
- }
- void CPrtIEC101::SlaveSend()
- {
- }
- //解包 10H
- void CPrtIEC101::SUnPack_Start10H()
- {
- switch (m_SRecByte[1] & 0x0f)
- {
- case 0x00:
- SUnPack_FC00H();
- break;
-
- case 0x09:
- SUnPack_FC09H();
- break;
- case 0x0b:
- SUnPack_FC0bH();
- break;
- case 0x0a:
- SUnPack_FC0aH();
- break;
- default:
- SUnPack_Start10H_Unknow();
- break;
- }
- }
- //解包 68H
- void CPrtIEC101::SUnPack_Start68H()
- {
- switch (m_SRecByte[6]) //类型标识
- {
- case 0x64: //总召唤
- SUnPack_TypeID64H();
- break;
- case 0x67:
- SUnPack_TypeID67H(); //主站对时
- break;
- case 0x2d:
- SUnPack_TypeID2DH(); //单点遥控
- break;
- case 0x2e:
- SUnPack_TypeID2EH(); //双点遥控
- break;
- case 0x65:
- SUnPack_TypeID65H(); //二进制计数器读数(BCR) -- 电度累计量
- break;
- default:
- SUnPack_Start68H_Unknow();
- break;
- }
- }
- //接收/应答主站总召唤
- void CPrtIEC101::SUnPack_TypeID64H()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- s1 = "<Rec>: 101主站--总召唤";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
- if (pView->Send(m_SAck_IC,6+m_SAck_IC[1],dwBytesSended)) //发送应答报文并显示
- {
- s1 = "<Send>:101子站--总召唤确认";
- s1 = s1 + "rn" + ByteArrayToString(m_SAck_IC,6+m_SAck_IC[1]) + "rn";
- pView->DisplayMsg(s1);
- m_SSendLv1 = YX;
- m_ACDFlag = 0x20;
- }
- }
- void CPrtIEC101::SUnPack_Start68H_Unknow()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- CString s1 = "";
- s1 = "<Rec>: 101主站--未知命令";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
- }
- void CPrtIEC101::SUnPack_Start10H_Unknow()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- CString s1 = "";
- s1 = "<Rec>: 101主站--未知命令";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,5) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
- }
- void CPrtIEC101::SUnPack_FC00H()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
-
- s1 = "<Rec>: 101主站--远方复位链路";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,5) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
-
- if (pView->Send(m_SAck_LinkR,5,dwBytesSended)) //发送应答报文并显示
- {
- s1 = "<Send>:101子站--复位链路确认";
- s1 = s1 + "rn" + ByteArrayToString(m_SAck_LinkR,5) + "rn";
- pView->DisplayMsg(s1);
- }
- }
- void CPrtIEC101::SUnPack_FC09H()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- s1 = "<Rec>:101主站--请求链路状态";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,5) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
- if (pView->Send(m_SAck_LinkS,5,dwBytesSended)) //发送应答报文并显示
- {
- s1 = "<Send>:101子站--链路状态应答";
- s1 = s1 + "rn" + ByteArrayToString(m_SAck_LinkS,5) + "rn";
- pView->DisplayMsg(s1);
- }
- }
- //接收/应答 ‘召2级数据’
- void CPrtIEC101::SUnPack_FC0bH()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- s1 = "<Rec>:101主站--召2级数据";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,5) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
- if (pView->Send(m_SAck_Lv2,5,dwBytesSended)) //发送应答报文并显示
- {
- s1 = "<Send>:101子站--无数据";
- s1 = s1 + "rn" + ByteArrayToString(m_SAck_Lv2,5) + "rn";
- pView->DisplayMsg(s1);
- }
- }
- //接收/应答 ‘召1级数据’
- void CPrtIEC101::SUnPack_FC0aH()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- s1 = "<Rec>:101主站--召1级数据";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,5) + "rn";
- pView->DisplayMsg(s1); //显示召唤报文
-
- switch (m_SSendLv1)
- {
- case YX:
- SlaveSend_Lv1YX();
- break;
- case YC:
- SlaveSend_Lv1YC();
- break;
- case None:
- SlaveSend_Lv1End();
- break;
- default:
- m_SSendLv1 = None;
- break;
- }
- }
- void CPrtIEC101::SlaveSend_Lv1YX()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- SPack_M_SP_DP_NA(); //打遥信包
-
- if((m_YXChara & 0x01) == YX_SINGLE)
- s1 = "<Send>:101子站--单点信息 M_SP_NA";
- else
- s1 = "<Send>:101子站--双点信息 M_DP_NA";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- void CPrtIEC101::SlaveSend_Lv1YC()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- SPack_M_ME_ND(); //打遥测包,目前总召唤遥测按不带品质的归一化类型
-
- s1 = "<Send>:101子站--遥测值,不带品质描述的归一化值 M_ME_ND";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- void CPrtIEC101::SPack_M_SP_DP_NA()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- //int nMaxNumToSend; //1帧最大发送的遥信个数
- int nYXNumToSend; //
- BOOL IsFullSended = false; //遥信点信息是否全部发送
- // nMaxNumToSend = 255-2-1-1-m_CauseOfTranLen-m_CommAddrLen-m_MsgAddrLen;
- nYXNumToSend = pDoc->m_YXNum - (m_SYXAddrToSend - pDoc->m_YXAddr);
-
- if (nYXNumToSend > 0x7f)
- nYXNumToSend = 0x7f;
- else
- IsFullSended = true; //本帧能全部发送遥信
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = nYXNumToSend+2+1+1+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80 + m_ACDFlag + 0x08; //功能码
- m_SSendByte[5] = m_Addr;
- //m_SSendByte[6] = TypeID:Single OR Double
- m_SSendByte[7] = 0x80 + nYXNumToSend; //SQ=1
- m_SSendByte[8] = 0x14; //传送原因:响应站召唤
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr;
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- WORD temVar = 0x0000;
- temVar = (WORD)m_SYXAddrToSend; //信息体地址
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = LOBYTE(temVar);
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = HIBYTE(temVar); //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+2] = 0x00;
-
- for (int i=0; i<nYXNumToSend; i++)
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen+i]
- = pDoc->m_pYXData[m_SYXAddrToSend-pDoc->m_YXAddr+i];
- if ((m_YXChara & 0x01) == 0)
- m_SSendByte[6] = 0x01;
- else
- m_SSendByte[6] = 0x03;
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- /////////////////////////////////////////////////////////
- if (IsFullSended)
- {
- m_SSendLv1 = YC;
- m_SYXAddrToSend = pDoc->m_YXAddr;
- }
- else
- m_SYXAddrToSend = m_SYXAddrToSend + 0x7f;
- }
- void CPrtIEC101::SPack_M_ME_ND()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- int nMaxNumToSend; //1帧最大发送的遥测个数
- int nYCNumToSend; //
- BOOL IsFullSended = false; //遥测点信息是否全部发送
- nMaxNumToSend = (255-2-1-1-m_CauseOfTranLen-m_CommAddrLen-m_MsgAddrLen)/2; //每个遥测两个字节
- nYCNumToSend = pDoc->m_YCNum - (m_SYCAddrToSend - pDoc->m_YCAddr);
-
- if (nYCNumToSend > nMaxNumToSend)
- nYCNumToSend = nMaxNumToSend;
- else
- IsFullSended = true; //本帧能全部发送遥测
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = nYCNumToSend*2+2+1+1+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80 + m_ACDFlag + 0x08; //功能码
- m_SSendByte[5] = m_Addr;
- m_SSendByte[6] = 0x15; //类型标识 21
- m_SSendByte[7] = 0x80 + nYCNumToSend; //SQ=1
- m_SSendByte[8] = 0x14; //传送原因:响应站召唤
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr;
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- WORD temVar = 0x0000;
- temVar = (WORD)m_SYCAddrToSend; //信息体地址
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = LOBYTE(temVar);
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = HIBYTE(temVar); //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+2] = 0x00;
-
- int i,j;
- j = 8+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen;
- for (i=0; i<nYCNumToSend; i++)
- {
- temVar = pDoc->m_pYCData[m_SYCAddrToSend-pDoc->m_YCAddr+i];
- m_SSendByte[j+i*2] = LOBYTE(temVar);
- m_SSendByte[j+i*2+1] = HIBYTE(temVar);
- }
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- /////////////////////////////////////////////////////////
- if (IsFullSended)
- {
- m_SSendLv1 = None;
- m_SYCAddrToSend = pDoc->m_YCAddr;
- }
- else
- m_SYCAddrToSend = m_SYCAddrToSend + nYCNumToSend;
- }
- //void CPrtIEC101::SPack_M_DP_NA()
- //{
- //}
- void CPrtIEC101::SlaveSend_Lv1End()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- s1 = "<Send>:101子站--总召唤结束";
- s1 = s1 + "rn" + ByteArrayToString(m_SAck_IC_End,6+m_SAck_IC_End[1]) + "rn";
- if (pView->Send(m_SAck_IC_End,6+m_SAck_IC_End[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- //接收时钟同步命令
- void CPrtIEC101::SUnPack_TypeID67H()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- BYTE nYear, nMonth, nDay, nHour, nMin; //nSec, nSec_m
- WORD wSec;
- float fSec;
- nYear = m_SRecByte[m_SRecByte[1]+3];
- nMonth = m_SRecByte[m_SRecByte[1]+2];
- nDay = m_SRecByte[m_SRecByte[1]+1] & 0x1f;
- nHour = m_SRecByte[m_SRecByte[1]];
- nMin = m_SRecByte[m_SRecByte[1]-1];
- wSec = (m_SRecByte[m_SRecByte[1]-2]<<8) | m_SRecByte[m_SRecByte[1]-3];
- fSec = (float)wSec/1000;
-
- DWORD dwBytesSended = 0;
- CString s1 = "";
-
- if (nYear < 0x0a)
- s1.Format("时钟同步 200%d-%d-%d %d:%d:%2.3f",nYear,nMonth,nDay,nHour,nMin,fSec);//%2.3f 保留三位小数点
- else
- s1.Format("时钟同步 20%d-%d-%d %d:%d:%2.3f",nYear,nMonth,nDay,nHour,nMin,fSec);
- pMainFrame->DisplayEvent(1,s1); //消息窗口显示
- s1 = "<Rec>: 101主站--" + s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1);
-
- //应答时钟同步
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = 2+1+1+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen+7;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80; //功能码0x80+0x00
- m_SSendByte[5] = m_Addr;
- m_SSendByte[6] = 0x67; //类型标识 103
- m_SSendByte[7] = 0x01; //SQ=0
- m_SSendByte[8] = 0x07; //传送原因:激活确认
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr;
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = 0x00; //信息体公共地址
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = 0x00; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+2] = 0x00;
- for (int i=0; i<7; i++)
- m_SSendByte[m_SSendByte[1]-3+i] = m_SRecByte[m_SRecByte[1]-3+i];
-
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- s1 ="<Send>: 101子站--时钟同步确认";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended))
- pView->DisplayMsg(s1);
- }
- //24位时标的单点/双点信息报文
- void CPrtIEC101::SPack_M_SP_DP_TA(int nIndex, int nNumber)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = 2+1+1+m_CauseOfTranLen+m_CommAddrLen+(m_MsgAddrLen+4)*nNumber;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80 + 0x08; //功能码
- m_SSendByte[5] = m_Addr;
- //m_SSendByte[6] = TypeID:Single OR Double
- m_SSendByte[7] = 0x00 + nNumber; //SQ=0
- m_SSendByte[8] = 0x03; //传送原因:自发(突发)
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr; //公共体地址
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- WORD wtemVar = 0x0000;
- WORD wSec;
- int ntemVar;
- ntemVar = 8+m_CauseOfTranLen+m_CommAddrLen; //信息体之前的字节数
- SYSTEMTIME t1; //时间结构
- GetLocalTime(&t1);
- wSec = t1.wSecond*1000 + t1.wMilliseconds; //毫秒
- for (int i=0; i<nNumber; i++)
- {
- wtemVar = (WORD)(pDoc->m_YXAddr + nIndex + i); //第nIndex+i信息体地址
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i] = LOBYTE(wtemVar);
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+1] = HIBYTE(wtemVar); //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+2] = 0x00;
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+m_MsgAddrLen] = pDoc->m_pYXData[nIndex+i];
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+m_MsgAddrLen+1] = LOBYTE(wSec); //3字节时标CTime
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+m_MsgAddrLen+2] = HIBYTE(wSec);
- m_SSendByte[ntemVar+(m_MsgAddrLen+4)*i+m_MsgAddrLen+3] = (BYTE)t1.wMinute;
- }
- if ((m_YXChara & 0x01) == 0)
- m_SSendByte[6] = 0x02;
- else
- m_SSendByte[6] = 0x04;
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- }
- //56位时标的单点/双点信息报文
- void CPrtIEC101::SPack_M_SP_DP_TB(int nIndex, int nNumber)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = 2+1+1+m_CauseOfTranLen+m_CommAddrLen+(m_MsgAddrLen+8)*nNumber;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80 + 0x08; //功能码
- m_SSendByte[5] = m_Addr;
- //m_SSendByte[6] = TypeID:Single OR Double
- m_SSendByte[7] = 0x00 + nNumber; //SQ=0
- m_SSendByte[8] = 0x03; //传送原因:自发(突发)
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr; //公共体地址
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- WORD wtemVar = 0x0000;
- WORD wSec;
- int ntemVar;
- ntemVar = 8+m_CauseOfTranLen+m_CommAddrLen; //信息体之前的字节数
- SYSTEMTIME t1; //时间结构
- GetLocalTime(&t1);
- wSec = t1.wSecond*1000 + t1.wMilliseconds; //毫秒
- for (int i=0; i<nNumber; i++)
- {
- wtemVar = (WORD)(pDoc->m_YXAddr + nIndex + i); //第nIndex+i信息体地址
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i] = LOBYTE(wtemVar);
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+1] = HIBYTE(wtemVar); //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+2] = 0x00;
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen] = pDoc->m_pYXData[nIndex+i];
-
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+1] = LOBYTE(wSec); //3字节时标CTime
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+2] = HIBYTE(wSec);
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+3] = (BYTE)t1.wMinute; //分
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+4] = (BYTE)t1.wHour; //时
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+5] = (BYTE)t1.wDayOfWeek<<5 | (BYTE)t1.wDay; //日
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+6] = (BYTE)t1.wMonth; //月
- m_SSendByte[ntemVar+(m_MsgAddrLen+8)*i+m_MsgAddrLen+7] = (BYTE)(t1.wYear % 100); //年(余除100)
- }
- if ((m_YXChara & 0x01) == 0)
- m_SSendByte[6] = 0x1e; //typeid:30
- else
- m_SSendByte[6] = 0x1f; //typeid:31
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- }
- void CPrtIEC101::SlaveSend_ChangeYX(UINT nIndex, UINT nNumber)
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- if ((m_YXChara & 0x02) == TIME24)
- {
- s1 = "<Send>:101子站--带24位时标的";
- SPack_M_SP_DP_TA(nIndex,nNumber); //24位时标单(双)点遥信打包
- }
- else
- {
- s1 = "<Send>:101子站--带56位时标的";
- SPack_M_SP_DP_TB(nIndex,nNumber); //56位时标单(双)点遥信打包
- }
-
- if ((m_YXChara & 0x01) == YX_SINGLE)
- s1 = s1+"单点遥信(突发)";
- else
- s1 = s1+"双点遥信(突发)";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- void CPrtIEC101::SUnPack_TypeID2DH()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x80) == 0x80) //遥控选择
- s1 = "<Rec>: 101主站--单点命令:遥控选择";
- else
- s1 = "<Rec>: 101主站--单点命令:遥控执行";
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x01) == 0x01) //合闸
- s1 = s1 + "(合闸)";
- else
- s1 = s1 + "(分闸)";
- CString s2;
- if (m_MsgAddrLen == 2)
- s2 = ByteToString(m_SRecByte[m_SRecByte[1]+2]) + ByteToString(m_SRecByte[m_SRecByte[1]+1]);
- else //信息体地址为3字节
- s2 = ByteToString(m_SRecByte[m_SRecByte[1]+2]) + ByteToString(m_SRecByte[m_SRecByte[1]+1])
- + ByteToString(m_SRecByte[m_SRecByte[1]]);
- s1 = s1 + " Addr:" + s2;
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1);
- SPack_C_SC_DC_Echo(); //遥控应答打包
- if ((m_SSendByte[4] & 0x01) == 0)
- s1 = "<Send>: 101子站--单点命令:确认";
- else
- s1 = "<Send>: 101子站--单点命令:否定应答";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- void CPrtIEC101::SUnPack_TypeID2EH()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x80) == 0x80) //遥控选择
- s1 = "<Rec>: 101主站--双点命令:遥控选择";
- else
- s1 = "<Rec>: 101主站--双点命令:遥控执行";
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x03) == 0x02) //合闸
- s1 = s1 + "(合闸)";
- else if ((m_SRecByte[m_SRecByte[1]+3] & 0x03) == 0x01) //分闸
- s1 = s1 + "(分闸)";
- else
- {
- s1 = s1 + "(不允许)";
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1);
- return;
- }
- CString s2;
- if (m_MsgAddrLen == 2)
- s2 = ByteToString(m_SRecByte[m_SRecByte[1]+2]) + ByteToString(m_SRecByte[m_SRecByte[1]+1]);
- else //信息体地址为3字节
- s2 = ByteToString(m_SRecByte[m_SRecByte[1]+2]) + ByteToString(m_SRecByte[m_SRecByte[1]+1])
- + ByteToString(m_SRecByte[m_SRecByte[1]]);
- s1 = s1 + " Addr:" + s2;
- s1 = s1 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1);
- SPack_C_SC_DC_Echo(); //遥控应答打包
- if ((m_SSendByte[4] & 0x01) == 0)
- s1 = "<Send>: 101子站--双点命令:确认";
- else
- s1 = "<Send>: 101子站--双点命令:否定应答";
- s1 = s1 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- //子站应答遥控命令(单点/双点)m_SRecByte m_SSendByte
- void CPrtIEC101::SPack_C_SC_DC_Echo()
- {
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = 0x05 + m_CauseOfTranLen + m_CommAddrLen + m_MsgAddrLen;
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x80) == 0x80) //‘选择’应答
- m_SSendByte[4] = 0x80 | ((m_YKChara & 0x02)>>1); //传输方向+应答方式
- else //‘执行’应答
- m_SSendByte[4] = 0x80 | ((m_YKChara & 0x04)>>2);
-
- m_SSendByte[5] = m_Addr;
- m_SSendByte[6] = m_SRecByte[6]; //类型标识
- m_SSendByte[7] = 0x01;
- m_SSendByte[8] = 0x07; //传送原因:激活确认
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
-
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr; //ASDU公共地址
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- if (m_MsgAddrLen == 2)
- {
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = m_SRecByte[m_SRecByte[1]+1];
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = m_SRecByte[m_SRecByte[1]+2];
- }
- else //信息体地址为3字节
- {
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = m_SRecByte[m_SRecByte[1]];
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = m_SRecByte[m_SRecByte[1]+1];
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+2] = m_SRecByte[m_SRecByte[1]+2];
- }
- m_SSendByte[3+m_SSendByte[1]] = m_SRecByte[m_SRecByte[1]+3]; //SCO OR DC0
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4); //和校验
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- }
- void CPrtIEC101::SUnPack_TypeID65H()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotView* pView = (CPeugeotView*) pMainFrame->GetActiveView(); //视图指针
- ASSERT_VALID(pView);
- DWORD dwBytesSended = 0;
- CString s1 = "";
- CString s2 = "";
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x07) < 0x04) //计数量召唤命令限定词(QCC)->RQT 仅取低3位
- s1.Format("计数量召唤:第%d组",m_SRecByte[m_SRecByte[1]+3] & 0x07);
- else if((m_SRecByte[m_SRecByte[1]+3] & 0x07) == 0x05)
- s1 = "计数量召唤:总请求";
- else
- s1 = "计数量召唤:未知命令(保留)";
- switch (m_SRecByte[m_SRecByte[1]+3] & 0xc0) //计数量召唤命令限定词(QCC)->FRZ bit7~8
- {
- case 0x00:
- s2 = "(读命令)";
- break;
-
- case 0x40:
- s2 = "(冻结不带复位)";
- break;
- case 0x80:
- s2 = "(冻结带复位)";
- break;
- case 0xc0:
- s2 = "(复位命令)";
- break;
- default:
- s2 = "(读命令)";
- break;
- }
- s1 = "<Rec>: 101主站--" + s1 + s2 + "rn" + ByteArrayToString(m_SRecByte,6+m_SRecByte[1]) + "rn";
- pView->DisplayMsg(s1);
- if (m_SRecByte[m_SRecByte[1]+3] & 0xc0 == 0x00)
- {
- SPack_IT_NA();
- s2 = "脉冲数据";
- }
- else
- {
- SPack_C_CI_ACK();
- s2 = s2 + "确认应答";
- }
- s1 = "<Send>: 101子站--" + s2 + "rn" + ByteArrayToString(m_SSendByte,6+m_SSendByte[1]) + "rn";
- if (pView->Send(m_SSendByte,6+m_SSendByte[1],dwBytesSended)) //发送应答报文并显示
- pView->DisplayMsg(s1);
- }
- //子站发送脉冲电度(不带时标)SQ = 1
- void CPrtIEC101::SPack_IT_NA()
- {
- CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; //框架窗口指针;
- CPeugeotDoc* pDoc = (CPeugeotDoc*) pMainFrame->GetActiveDocument(); //文档指针
- ASSERT_VALID(pDoc);
- int nMaxNumToSend; //1帧最大发送的电度个数
- int nYMNumToSend; //
- BOOL IsFullSended = false; //脉冲点信息是否全部发送
- //nMaxNumToSend = (255-2-1-1-m_CauseOfTranLen-m_CommAddrLen) / (m_MsgAddrLen+5); // SQ = 0
- nMaxNumToSend = (255-2-1-1-m_CauseOfTranLen-m_CommAddrLen-m_MsgAddrLen) / 5; // SQ = 1
- nYMNumToSend = pDoc->m_YMNum - (m_SYMAddrToSend - pDoc->m_YMAddr);
-
- BYTE b1; //请求发送标志,如果是最后一帧,置0
- if (nYMNumToSend > nMaxNumToSend)
- {
- nYMNumToSend = nMaxNumToSend;
- b1 = 0x02;
- }
- else
- {
- IsFullSended = true; //本帧能全部发送脉冲
- b1 = 0x00;
- }
- m_SSendByte[0] = 0x68;
- m_SSendByte[1] = nYMNumToSend*5+2+1+1+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen; // 按SQ =1
- m_SSendByte[2] = m_SSendByte[1];
- m_SSendByte[3] = 0x68;
- m_SSendByte[4] = 0x80 + 0x08 + b1; //功能码
- m_SSendByte[5] = m_Addr;
- m_SSendByte[6] = 0x0f; //类型标识 15
- m_SSendByte[7] = 0x80 + nYMNumToSend; //SQ=1
- if ((m_SRecByte[m_SRecByte[1]+3] & 0x07) < 0x04) //计数量召唤命令限定词(QCC)->RQT 仅取低3位
- m_SSendByte[8] = 37 + (m_SRecByte[m_SRecByte[1]+3] & 0x07); //传送原因:响应第i组召唤
- else
- m_SSendByte[8] = 37; //传送原因:响应计量总召唤
- m_SSendByte[9] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen] = m_Addr; //公共地址
- m_SSendByte[8+m_CauseOfTranLen+1] = m_Addr; //如与实际字节数不符,后面仍能覆盖
- WORD temVar = 0x0000;
- temVar = (WORD)m_SYCAddrToSend; //信息体地址
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen] = LOBYTE(temVar);
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+1] = HIBYTE(temVar); //如与实际字节数不符,后面仍能覆盖
- m_SSendByte[8+m_CauseOfTranLen+m_CommAddrLen+2] = 0x00;
-
- int i,j;
- j = 8+m_CauseOfTranLen+m_CommAddrLen+m_MsgAddrLen;
- for (i=0; i<nYMNumToSend; i++)
- {
- temVar = LOWORD(pDoc->m_pYMData[m_SYMAddrToSend-pDoc->m_YMAddr+i]); //低2字节
- m_SSendByte[j+i*5] = LOBYTE(temVar);
- m_SSendByte[j+i*5+1] = HIBYTE(temVar);
- temVar = HIWORD(pDoc->m_pYMData[m_SYMAddrToSend-pDoc->m_YMAddr+i]); //高2字节
- m_SSendByte[j+i*5+2] = LOBYTE(temVar);
- m_SSendByte[j+i*5+3] = HIBYTE(temVar);
- m_SSendByte[j+i*5+4] = i;
- }
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4);
- m_SSendByte[5+m_SSendByte[1]] = 0x16;
- /////////////////////////////////////////////////////////
- if (IsFullSended)
- m_SYMAddrToSend = pDoc->m_YMAddr;
- else
- m_SYMAddrToSend = m_SYMAddrToSend + nYMNumToSend;
- }
- //应答主站召记数量(确认应答)
- void CPrtIEC101::SPack_C_CI_ACK()
- {
- for (int i=0; i<m_SRecByte[1]+6; i++)
- m_SSendByte[i] = m_SRecByte[i];
-
- m_SSendByte[4] = 0x80 + 0x20; //传输方向+ACD标志
- m_SSendByte[8] = 0x07; //传送原因
-
- m_SSendByte[4+m_SSendByte[1]] = GetAddByte(m_SSendByte,m_SSendByte[1],4); //和校验
- }