// RtuProcess.cpp: implementation of the CRtuProcess class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "rtugprs.h"
#include "RtuProcess.h"
#include "DataType.h"
#include "MainFrm.h"
#include "Tools.h"
#include "PaintView.h"
#include "SQLMng.h"
//#include <afxsock.h>
#include "CVsp.h"
#include "WellClass.h"
#include "CanSock.h"
#include "TcpServer.h"
//#include "cstringt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRtuProcess::CRtuProcess(CWnd *pWnd)
{
    m_CJSJ=0;
    m_pParent=pWnd;
    m_nRtuID=0;
    //*********************************包类型初始化******************************************
    m_pRTUStaticInfo=NULL;
    m_pRtuRunCnt=NULL;
    m_pCardPacket=NULL;
    m_pRealData=NULL;
    m_pDynInfo=NULL;
    m_pElecPack=NULL;
    m_nDeviceCnt=NULL;
    m_nDeviceByte=NULL;
    m_nByteCnt=NULL;
    m_bSendConf=FALSE;
    m_nRealCnt=0;
    m_nStaticCnt=0;
    m_nDynCnt=0;
    m_nRunCnt=0;
    m_nCardCnt=0;
    m_nElecCnt=0;
    memset(m_pWellTime,0,sizeof(m_pWellTime));
    memset(m_sBuf,0,sizeof(m_sBuf));
    ZeroMemory(m_sBufUpData,sizeof(m_sBufUpData));
    m_nUpData=0;
    for (int i=0;i<4;i++)
    {
        m_pWellCalss[i]=NULL;
    }
    //    memset(m_Device,0,sizeof(m_Device));
}

CRtuProcess::~CRtuProcess()
{
    int i;
    for (i=0;i<4;i++)
    {
        if (m_pWellCalss[i]!=NULL)
        {
            delete m_pWellCalss[i];
            m_pWellCalss[i]=NULL;
        }
    }
    
    if (m_pRTUStaticInfo!=NULL)
    {
        for(i=0;i<MAXBYTE;i++)
        {
            if (m_pRTUStaticInfo->ArrayGTBaseInfo[i]!=NULL)
            {
                delete [] m_pRTUStaticInfo->ArrayGTBaseInfo[i];
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]=NULL;
            }    
            
        }
        delete m_pRTUStaticInfo;
        m_pRTUStaticInfo=NULL;
    }
    if (m_pRtuRunCnt!=NULL)
    {
        for(i=0;i<MAXBYTE;i++)
        {
            if(m_pRtuRunCnt->ArrayEquipStatue[i]!=NULL)
            {
                delete m_pRtuRunCnt->ArrayEquipStatue[i];
                m_pRtuRunCnt->ArrayEquipStatue[i]=NULL;
            }
        }
        delete m_pRtuRunCnt;
        m_pRtuRunCnt=NULL;
    }
    if (m_pCardPacket!=NULL)
    {
        
        delete m_pCardPacket;
        m_pCardPacket=NULL;
    }
    if (m_pDynInfo!=NULL)
    {
        for(i=0;i<4;i++)
        {
            if(m_pDynInfo->DynConf.ArraryWellConf[i]!=NULL)
            {
                delete m_pDynInfo->DynConf.ArraryWellConf[i];
                m_pDynInfo->DynConf.ArraryWellConf[i]=NULL;
            }
        }   
        
        for(i=0;i<4;i++)
        {
            if(m_pDynInfo->DeviceMapping.ArrayWell[i]!=NULL)
            {
                for(int j=0;j<8;j++)
                {
                    if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]!=NULL)
                    {
                        delete m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j];
                        m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]=NULL;
                    }
                }
                //    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]
                delete m_pDynInfo->DeviceMapping.ArrayWell[i];
                m_pDynInfo->DeviceMapping.ArrayWell[i]=NULL;
            }
        } 
        delete m_pDynInfo;
        m_pDynInfo=NULL;
    }
    if (m_pRealData!=NULL)
    {
        delete m_pRealData;
        m_pRealData=NULL;
    }
    if (m_pElecPack!=NULL)
    {
        delete  m_pElecPack;
        m_pElecPack=NULL;
    }
    for(i=0;i<4;i++)
    {
        if (m_pWellTime[i]!=NULL)
        {
            delete m_pWellTime[i];
            m_pWellTime[i]=NULL;
        }
    }
}
void CRtuProcess::AcceptData(char *buf,int nLen)
{
/*    if(m_pDynInfo!=NULL)
{
if(m_pDynInfo->uPacketType!=0xB1)
{
m_pDynInfo=NULL;
memset(m_pWellCalss,0,sizeof(m_pWellCalss));
}
}*/
    int nSer=sizeof(sockaddr_in);
    memcpy((char *)&m_Server,buf,nSer);
    CMainFrame *pMain=(CMainFrame *)m_pParent;
    if (m_bSendConf==TRUE)
    {
        pMain->ResposeConf(buf+4+nSer,m_nDynConf+2,m_Server,0x10,m_bufDynConf);
    }
    /*    if (m_sBuf!="")
    {
    if (MAKEWORD(*(buf+nLen-1),*(buf+nLen-2))==MAKEWORD(*(m_sBuf+m_nBuf-1),*(m_sBuf+m_nBuf-2)))
    {
    return ;
    }
    }
    */
    
    
    int i=0;
    m_nRtuID=CTools::CharToInt((unsigned char *)buf+4+nSer,8);
    memset(m_sBuf,0,sizeof(m_sBuf));
    memcpy(m_sBuf,buf+nSer,nLen);
    m_nBuf=nLen;
    BYTE a=m_sBuf[0];

    //****************************升级程序*************************    
    if (a!=0xE0 && m_nUpData!=NULL)
    {
        ((CMainFrame *)m_pParent)->m_pSock->Send((unsigned char *)m_sBufUpData,m_nUpData,m_Server);
    }
    //*************************************************************
    if (a!=RTU_PACKTYPE_STATICINFO && m_pRTUStaticInfo==NULL)
    {
        ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x02);
        return;
    }
    if (m_pRTUStaticInfo!=NULL)
    {
        if (a!=RTU_PACKTYPE_DYNINFO && m_pDynInfo==NULL)
        {
            ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x20);
            return;
        }
    }
    
    switch(a)
    {
    case RTU_PACKTYPE_EXTENSION:
        break;
        
    case RTU_PACKTYPE_STATICINFO:
        m_nStaticCnt++;
        if(AnalysisStaticInfo()==FALSE)
        {
        /*    if (m_pRTUStaticInfo!=NULL)
        {
        for(i=0;i<MAXBYTE;i++)
        {
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[i]!=NULL)
        {
        delete [] m_pRTUStaticInfo->ArrayGTBaseInfo[i];
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]=NULL;
        }    
        
          }
          delete m_pRTUStaticInfo;
          m_pRTUStaticInfo=NULL;
        }*/
            ;
        }
        
        break;
        
    case RTU_PACKTYPE_DYNINFO:
        m_nDynCnt++;
        if(AnalysisDynInfo()==FALSE)
        {
            if (m_pDynInfo!=NULL)
            {
                for(i=0;i<4;i++)
                {
                    if(m_pDynInfo->DynConf.ArraryWellConf[i]!=NULL)
                    {
                        delete m_pDynInfo->DynConf.ArraryWellConf[i];
                        m_pDynInfo->DynConf.ArraryWellConf[i]=NULL;
                    }
                }   
                
                for(i=0;i<4;i++)
                {
                    if(m_pDynInfo->DeviceMapping.ArrayWell[i]!=NULL)
                    {
                        for(int j=0;j<8;j++)
                        {
                            if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]!=NULL)
                            {
                                delete m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j];
                                m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]=NULL;
                            }
                        }
                        //    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]
                        delete m_pDynInfo->DeviceMapping.ArrayWell[i];
                        m_pDynInfo->DeviceMapping.ArrayWell[i]=NULL;
                    }
                } 
                delete m_pDynInfo;
                m_pDynInfo=NULL;
            }
        }
        
        //        a=1000;
        break;
        
    case RTU_PACKTYPE_RESPONSE:
        break;
        
    case RTU_PACKTYPE_LONGDATA:
        AnalysisUpdata();
        break;
        
    case RTU_PACKTYPE_RUNCNT:
        m_nRunCnt++;
        AnalysisRunCnt();
        break;
        
    case RTU_PACKTYPE_TESTDATA:
        m_nRealCnt++;
        AnalysisRealData();
        break;
        
    case RTU_PACKTYPE_CARD:
        m_nCardCnt++;
        AnalysisCardsPacket();
        break;
        
    case RTU_PACKTYPE_ELECPARA:
        m_nElecCnt++;
        AnalysisElecPacket();
        break;
        
    case RTU_PACKTYPE_SCREW:
        break;
        
    case RTU_PACKTYPE_INJECTION:
        break;
        
    default: 
        break;
    }
    
    return;
}

BOOL CRtuProcess::AnalysisStaticInfo()
{
    //**************************解析*****************************************
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    int nTolStatic=0;
    if (m_pRTUStaticInfo==NULL)
    {
        m_pRTUStaticInfo=new CRTUStaticInfo;
        memset(m_pRTUStaticInfo,0,sizeof(CRTUStaticInfo));
    }
    CTools::WriteLog("1",1,"Static26");
    //
    m_pRTUStaticInfo->uPacketType=*pData++;
    nTolStatic++;
    m_pRTUStaticInfo->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    nTolStatic+=2;
    m_pRTUStaticInfo->uVersion=*(pData++);
    nTolStatic++;
    m_pRTUStaticInfo->uRTUPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    nTolStatic+=8;
    m_pRTUStaticInfo->uPackageTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    nTolStatic+=4;
    m_pRTUStaticInfo->uDeviceCnt=*(pData++);
    nTolStatic++;
    if(m_pRTUStaticInfo->uDeviceCnt>18)
    {
        //        memset(m_pRTUStaticInfo,0,size);
        return false;
    }
    //    m_pRTUStaticInfo->uDeviceSN=*(pData++);
    //    m_pRTUStaticInfo->uDeviceLen=*(pData++);
    int i;
    for(i=0;i<m_pRTUStaticInfo->uDeviceCnt;i++)
    {
        int nTolDevLen=0;
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[i]==NULL)
        {
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]=new CGTBaseInfo;
            memset(m_pRTUStaticInfo->ArrayGTBaseInfo[i],0,sizeof(CGTBaseInfo));
        }
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDeviceSN=*(pData++);
        nTolDevLen++;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDeviceLen=*(pData++);
        nTolDevLen++;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uGTPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
        pData+=8;
        nTolDevLen+=8;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uModel=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        nTolDevLen+=2;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uInstrumentationType=*(pData++);
        nTolDevLen++;
        //        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDataType=*(pData++);
        memcpy(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sModelCode,pData,8);
        pData+=8;
        nTolDevLen+=8;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uSN=CTools::CharToInt((unsigned char *)pData,4);
        pData+=4;
        nTolDevLen+=4;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uFirmwareVS=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        nTolDevLen+=2;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uSoftwareVS=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        nTolDevLen+=2;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uRange=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        nTolDevLen+=2;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uAccuracy=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        nTolDevLen+=2;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uLowOperatingTemperature=*(pData++);
        nTolDevLen++;
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uHighOperatingTemperature=*(pData++);
        nTolDevLen++;
        //        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uReserve=*(pData++);
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uProLev=*(pData++);
        nTolDevLen++;
        memcpy(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sExplosionLev,pData,8);
        pData+=8;
        nTolDevLen+=8;
        /*#define INSTRUTYPE_INTEGRATIONLOAD        0x01        //一体化负荷
        #define INSTRUTYPE_PRESS                0x02           //压力
        #define INSTRUTYPE_TEMP                    0x03           //温度
        #define INSTRUTYPE_ELEC                    0x04           //3相电参数
        #define INSTRUTYPE_SPEED                0x05        //转速
        #define INSTRUTYPE_FLOWMETER            0x06        //流量计
        #define INSTRUTYPE_VALVE                0x07        //调节阀
        #define INSTRUTYPE_TLSENSOR                0x08        //扭矩载荷传感器
        
          #define INSTRUTYPE_RTUEQ                0xf0        //RTU设备
#define INSTRUTYPE_HANDWRITE            0xf1           //手操器*/
        switch(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uInstrumentationType)
        {
        case 0x01:
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            break;
        case 0x02:
            break;
        case 0x03:
            break;
        case 0x04:
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange3=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy3=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            break;
        case 0x05:
            break;
        case 0x06:
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            break;
        case 0x07:
            break;
        case 0x08:
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            nTolDevLen+=2;
            break;
        case 0xf0:
            break;
        case 0xf1:
            break;
        default:
            break;
        }
        CTools::WriteLog("5",1,"Static26");
        m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark=*(pData++);
        nTolDevLen++;
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark>100)
        {
            ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x80);
            int nBuf=m_nBuf;
            CTime dt=CTime::GetCurrentTime();
            char sbuf[MAXWORD]="";
            CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
            CTools::WriteLog(sbuf,EC_DATA_STATICNOTE,dt.Format("%Y-%m-%d"));
            ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_STATICNOTE++;
            return FALSE;
        }
        memcpy(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sRemark,pData,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark);
        pData+=m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark;
        nTolDevLen+=m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark;
        if ((nTolDevLen-2)!=m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDeviceLen)
        {
            ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x80);
            int nBuf=m_nBuf;
            CTime dt=CTime::GetCurrentTime();
            char sbuf[MAXWORD]="";
            CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
            CTools::WriteLog(sbuf,EC_DATA_STATICDEV,dt.Format("%Y-%m-%d"));
            ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_STATICDEV++;
            return FALSE;
        }
        nTolStatic+=nTolDevLen;
    }
    CTools::WriteLog("4",1,"Static26");
    if ((nTolStatic+2)!=m_nBuf)
    {
        ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x80);
        int nBuf=m_nBuf;
        CTime dt=CTime::GetCurrentTime();
        char sbuf[MAXWORD]="";
        CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
        CTools::WriteLog(sbuf,EC_DATA_STATICLEN,dt.Format("%Y-%m-%d"));
        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_STATICLEN++;
        return FALSE;
    }
//    CTools::WriteLog("2",1,"Static26");
#if DEBUG_DB
    AfxGetSQLMng()->InsertStaticInfo(m_pRTUStaticInfo); // DB去掉 
#endif
//    CTools::WriteLog("3",1,"Static26");
    if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
        ShowStaticInfo();
    return TRUE;
}
BOOL    CRtuProcess::ShowStaticInfo()
{
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    msg+="**********RTU设备静态信息包定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pRTUStaticInfo->uVersion);   
    msg+=hexTostr;
    //    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pRtuRunCnt->uRTUPhysicAddr));
    hexTostr.Format("RTU物理地址:%s\r\n",CTools::LONG64TOSTR(m_pRTUStaticInfo->uRTUPhysicAddr));   
    msg+=hexTostr;
    //打包时间
    hexTostr.Format("从设备数量:%u\r\n",m_pRTUStaticInfo->uDeviceCnt);   
    msg+=hexTostr;
    
    
    int i;
    for(i=0;i<m_pRTUStaticInfo->uDeviceCnt;i++)
    {
        hexTostr.Format("仪表序号:%u\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDeviceSN);   
        msg+=hexTostr;
        
        hexTostr.Format("仪表长度:%u\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uDeviceLen);   
        msg+=hexTostr;
        //    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pRtuRunCnt->uRTUPhysicAddr));
        hexTostr.Format("设备%u物理地址:%s\r\n",i,CTools::LONG64TOSTR(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uGTPhysicAddr));
        msg+=hexTostr;
        hexTostr.Format("厂商代码:%u      仪表类型:%u   \r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uModel,
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uInstrumentationType);
        msg+=hexTostr;
        hexTostr.Format("型号代码:%.8s      序列号:%u\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sModelCode,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uSN);
        msg+=hexTostr;
        hexTostr.Format("固件版本:%u.%u      软件版本:%u.%u     量程:%u.%u\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uFirmwareVS/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uFirmwareVS%100,
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uSoftwareVS/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uSoftwareVS%100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uRange/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uRange%100);
        msg+=hexTostr;
        hexTostr.Format("精度:%u.%u      最低工作温度:%d     最高工作温度:%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uAccuracy/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uAccuracy%100,
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uLowOperatingTemperature,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uHighOperatingTemperature);
        msg+=hexTostr;
        hexTostr.Format("防护等级:%u     防爆等级:%.8s\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uProLev,
            m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sExplosionLev);
        msg+=hexTostr;
        switch(m_pRTUStaticInfo->ArrayGTBaseInfo[i]->uInstrumentationType)
        {
        case 0x01:
            hexTostr.Format("辅助变量1 量程:%d.%d     辅助变量1 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1%100);
            msg+=hexTostr;
            break;
        case 0x02:
            break;
        case 0x03:
            break;
        case 0x04:
            hexTostr.Format("辅助变量1 量程:%d.%d     辅助变量1 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1%100);
            msg+=hexTostr;
            hexTostr.Format("辅助变量2 量程:%d.%d     辅助变量2 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2%100);
            msg+=hexTostr;
            hexTostr.Format("辅助变量3 量程:%d.%d     辅助变量3 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange3/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange3%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy3/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy3%100);
            msg+=hexTostr;
            break;
        case 0x05:
            break;
        case 0x06:
            hexTostr.Format("辅助变量4 量程:%d.%d     辅助变量1 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1%100);
            msg+=hexTostr;
            break;
        case 0x07:
            break;
        case 0x08:
            hexTostr.Format("辅助变量1 量程:%d.%d     辅助变量1 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange1%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy1%100);
            msg+=hexTostr;
            hexTostr.Format("辅助变量2 量程:%d.%d     辅助变量2 测量精度:%d.%d\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarRange2%100,
                m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2/100,m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nAidVarAccuracy2%100);
            msg+=hexTostr;
            break;
        case 0xf0:
            break;
        case 0xf1:
            break;
        default:
            break;
        }
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[i]->nRemark>0)
        {
            hexTostr.Format("备注:%s\r\n",m_pRTUStaticInfo->ArrayGTBaseInfo[i]->sRemark);
            msg+=hexTostr;
        }
        
    }
    
    
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    
    return TRUE;
}
BOOL    CRtuProcess::AnalysisRunCnt()
{
    //**************************解析*****************************************
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    if (m_pRtuRunCnt==NULL)
    {
        m_pRtuRunCnt=new CRTURunCnt;
        memset(m_pRtuRunCnt,0,sizeof(CRTURunCnt));
    }
    //    memset(m_pRtuRunCnt,0,sizeof(CRTURunCnt));            //
    //    memcpy(m_pRtuRunCnt,pData,35);                        //前17个字节是固定的
    //    pData+=35;
    
    m_pRtuRunCnt->uPacketType=*pData++;
    m_pRtuRunCnt->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pRtuRunCnt->uVersion=*(pData++);
    m_pRtuRunCnt->uRTUPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pRtuRunCnt->uPacketTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pRtuRunCnt->uRtuRunTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pRtuRunCnt->uTotalRtuSend=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pRtuRunCnt->uTotalRtuRecv=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pRtuRunCnt->uSendCnt=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pRtuRunCnt->uRecvCnt=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pRtuRunCnt->uReSend=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pRtuRunCnt->uEquipmentCnt=*(pData++);
    BYTE uDevCnt=m_pRtuRunCnt->uEquipmentCnt;            //
    int i;
    for(i=0;i<uDevCnt;i++)
    {
        if (m_pRtuRunCnt->ArrayEquipStatue[i]==NULL)
        {
            m_pRtuRunCnt->ArrayEquipStatue[i]=new CEquipStatue;
            memset(m_pRtuRunCnt->ArrayEquipStatue[i],0,sizeof(CEquipStatue));
        }
        //    int nSize=sizeof(CEquipStatue);
        //    memcpy(m_pRtuRunCnt->ArrayEquipStatue[i],pData,nSize);
        //    pData+=nSize;
        m_pRtuRunCnt->ArrayEquipStatue[i]->uEquipPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
        pData+=8;
        m_pRtuRunCnt->ArrayEquipStatue[i]->nStatus=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        m_pRtuRunCnt->ArrayEquipStatue[i]->uCommEffic=*(pData++);
        m_pRtuRunCnt->ArrayEquipStatue[i]->uBarV=*(pData++);
        m_pRtuRunCnt->ArrayEquipStatue[i]->nDormTime=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        m_pRtuRunCnt->ArrayEquipStatue[i]->uInstStatus=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
    }
    memcpy(m_pRtuRunCnt->sAlarmInfo,pData,20);
#if DEBUG_DB
    AfxGetSQLMng()->InsertRTURunCnt(m_pRtuRunCnt);
#endif
    if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
        ShowRunCnt();
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    return TRUE;
}

BOOL  CRtuProcess::ShowRunCnt()
{
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    //****************************拼凑字符串************************************************
    msg+="**********RTU设备运行统计信息包定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pRtuRunCnt->uVersion);
    msg+=hexTostr;
    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pRtuRunCnt->uRTUPhysicAddr));
    msg+=hexTostr;
    hexTostr.Format("运行时间:%u     通过DTU发送总长度:%u    通过DTU接收总长度:%u        \r\n",m_pRtuRunCnt->uRtuRunTime,
        m_pRtuRunCnt->uTotalRtuSend,m_pRtuRunCnt->uTotalRtuRecv);
    msg+=hexTostr;
    hexTostr.Format("通过DTU发送次数:%u    从DTU接收到数据次数:%u   通过DTU重发次数:%u    后续列表中的设备数量:%u\r\n",m_pRtuRunCnt->uSendCnt,
        m_pRtuRunCnt->uRecvCnt,m_pRtuRunCnt->uReSend,m_pRtuRunCnt->uEquipmentCnt);
    msg+=hexTostr;
    hexTostr.Format("报警信息:%.20s\r\n",m_pRtuRunCnt->sAlarmInfo);
    msg+=hexTostr;
    int i;
    for(i=0;i<m_pRtuRunCnt->uEquipmentCnt;i++)
    {
        hexTostr.Format("设备%u的物理地址:%s     在线状态:%u    通信效率:%u        \r\n",i,CTools::LONG64TOSTR(m_pRtuRunCnt->ArrayEquipStatue[i]->uEquipPhysicAddr),
            m_pRtuRunCnt->ArrayEquipStatue[i]->nStatus,m_pRtuRunCnt->ArrayEquipStatue[i]->uCommEffic);
        msg+=hexTostr;
        hexTostr.Format("电池电压:%u     休眠时间:%u    仪表状态:%u        \r\n",m_pRtuRunCnt->ArrayEquipStatue[i]->uBarV,
            m_pRtuRunCnt->ArrayEquipStatue[i]->nDormTime,m_pRtuRunCnt->ArrayEquipStatue[i]->uInstStatus);
        msg+=hexTostr;
    }
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    return TRUE;
}
//油井RTU上传功图数据包定义                    
BOOL CRtuProcess::AnalysisCardsPacket()
{
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    int nBuf=m_nBuf;
    CTime dt=CTime::GetCurrentTime();
    char sbuf[MAXWORD]="";
    CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
    CTools::WriteLog(sbuf,EC_GONGTU,"示功图");
    //**************************解析*****************************************    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    if (m_pCardPacket==NULL)
    {
        m_pCardPacket=new CCardPacket;
        memset(m_pCardPacket,0,sizeof(CCardPacket));
    }
    m_pCardPacket->uPacketType=(*pData++);
    m_pCardPacket->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pCardPacket->uVersion=*(pData++);
    m_pCardPacket->uRTUPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pCardPacket->uPacketTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pCardPacket->uElecParamark=(*pData++);
    
    m_pCardPacket->uCardPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pCardPacket->uCardCollectTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pCardPacket->uStroke=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pCardPacket->uOfStroke=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pCardPacket->uDayProductionTime=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pCardPacket->uTotalProductionTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pCardPacket->uCardPoint=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    int i;
    for(i=0;i<m_pCardPacket->uCardPoint;i++)
    {
        m_pCardPacket->ArrayCards[i].uDisplace=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
    }
    for(i=0;i<m_pCardPacket->uCardPoint;i++)
    {
        m_pCardPacket->ArrayCards[i].uLoad=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
    }
    if (m_pCardPacket->uElecParamark==1)
    {
        
        m_pCardPacket->uElecParaID=CTools::CharToInt((unsigned char *)pData,8);
        pData+=8;
        m_pCardPacket->uElecCollectTime=CTools::CharToInt((unsigned char *)pData,4);
        pData+=4;
        m_pCardPacket->uUpMaxCurrent=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        m_pCardPacket->uDownMaxCurrent=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        m_pCardPacket->uDayPower=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
        m_pCardPacket->uTotalPower=CTools::CharToInt((unsigned char *)pData,2);
        pData+=4;
        m_pCardPacket->uElecPoint=CTools::CharToInt((unsigned char *)pData,2);
        
        pData+=2;
        
        for(i=0;i<m_pCardPacket->uElecPoint;i++)
        {
            m_pCardPacket->ArrayElec[i].uElec=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            
        }
        for(i=0;i<m_pCardPacket->uElecPoint;i++)
        {
            
            m_pCardPacket->ArrayElec[i].uPower=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
        }
    }
    BOOL bTag=FALSE;
    if (m_pDynInfo!=NULL)
    {
        for(i=0;i<m_pDynInfo->DeviceMapping.uWellCnt;i++)
        {
            if (m_pDynInfo->DeviceMapping.ArrayWell[i]==NULL)
            {
                ASSERT(FALSE);
            }
            for (int j=0;j<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;j++)
            {
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]==NULL)
                {
                    ASSERT(FALSE);
                }
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceID==m_pCardPacket->uCardPhysicAddr)
                {
                    if (m_pWellCalss[i]!=NULL)
                    {
                        m_pWellCalss[i]->setCard(*m_pCardPacket);
                    }
#if DEBUG_DB
                    if(AfxGetSQLMng()->InsertCard(m_pDynInfo->DeviceMapping.ArrayWell[i],m_pCardPacket)==3L)//// DB去掉
                    {
                        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_WELL_TYPE++;
                    }
#endif                     
                    bTag=TRUE;
                    break;
                }
            }
        }
    }
    if (bTag==FALSE)
    {
        int nBuf=m_nBuf;
        CTime dt=CTime::GetCurrentTime();
        char sbuf[MAXWORD]="";
        CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
        CTools::WriteLog(sbuf,EC_DATA_CHECKCARDIDFAIL,dt.Format("%Y-%m-%d"));
        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_CHECKCARDIDFAIL++;
        return FALSE;
    }
    
    if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
        ShowCardPacket();
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    return TRUE;
}
BOOL   CRtuProcess::ShowCardPacket()
{
    
    //    str="";
    //    MessageBox("str");
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    msg+="**********油井RTU上传功图数据包定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pCardPacket->uVersion);
    msg+=hexTostr;
    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pCardPacket->uRTUPhysicAddr));
    msg+=hexTostr;
    hexTostr.Format("示功图 设备ID:%s    示功图采集时间:%u \r\n",CTools::LONG64TOSTR(m_pCardPacket->uCardPhysicAddr),m_pCardPacket->uCardCollectTime);
    msg+=hexTostr;
    hexTostr.Format("冲程:%u     冲次:%u    日生产时间:%u \r\n",m_pCardPacket->uStroke,m_pCardPacket->uOfStroke,m_pCardPacket->uDayProductionTime);
    msg+=hexTostr;
    hexTostr.Format("累计生产时间:%u     示功图点数:%u \r\n",m_pCardPacket->uTotalProductionTime,m_pCardPacket->uCardPoint);
    msg+=hexTostr;
    int i;
    CPaintView* pDefView = (CPaintView*)(((CMainFrame*)m_pParent)->m_wndSplitter1x2_2).GetPane(0,1);
    pDefView->initCurve(CTools::LONG64TOSTR(m_pCardPacket->uCardPhysicAddr));
    pDefView->m_uCardPoint=m_pCardPacket->uCardPoint;
    for (i=0;i<m_pCardPacket->uCardPoint;i++)
    {
        pDefView->m_uDisp[i]=m_pCardPacket->ArrayCards[i].uDisplace;
        pDefView->m_uLoad[i]=m_pCardPacket->ArrayCards[i].uLoad;
        hexTostr.Format("点%u     位移数据:%u     载荷数据:%u    \r\n",i,m_pCardPacket->ArrayCards[i].uDisplace,
            m_pCardPacket->ArrayCards[i].uLoad);
        msg+=hexTostr;
    }
    
    hexTostr.Format("电参的 设备ID:%s     电参图采集时间:%u \r\n",CTools::LONG64TOSTR(m_pCardPacket->uElecParaID),m_pCardPacket->uElecCollectTime);
    msg+=hexTostr;
    hexTostr.Format("上行最大电流:%u      下行最大电流:%u \r\n",m_pCardPacket->uUpMaxCurrent,m_pCardPacket->uDownMaxCurrent);
    msg+=hexTostr;
    hexTostr.Format("日耗电:%u      累计耗电:%u   电流,功率数据点数:%u\r\n",m_pCardPacket->uDayPower,m_pCardPacket->uTotalPower,m_pCardPacket->uElecPoint);
    msg+=hexTostr;
    
    
    pDefView->m_uElecPoint=m_pCardPacket->uElecPoint;
    for(i=0;i<m_pCardPacket->uElecPoint;i++)
    {
        pDefView->m_uCurrent[i]=m_pCardPacket->ArrayElec[i].uElec;
        pDefView->m_uPower[i]=m_pCardPacket->ArrayElec[i].uPower;
        hexTostr.Format("点%u     电流:%u     功率:%d    \r\n",i,m_pCardPacket->ArrayElec[i].uElec,
            m_pCardPacket->ArrayElec[i].uPower);
        msg+=hexTostr;
    }
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    pDefView->InvalidateRect(0,TRUE);
    return TRUE;
}

//*********************************电参数据包****************************************************
BOOL   CRtuProcess::AnalysisElecPacket()
{
    int nBuf=m_nBuf;
    CTime dt=CTime::GetCurrentTime();
    char sbuf[MAXWORD]="";
    CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
    //    CTools::WriteLog(sbuf,EC_DIANLIUTU,"电流图");
    
    char *pData=(char*)m_sBuf;
    if (m_pElecPack==NULL)
    {
        m_pElecPack=new CElecPacket;
        memset(m_pElecPack,0,sizeof(CElecPacket));
    }
    m_pElecPack->uPacketType=*pData++;
    m_pElecPack->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pElecPack->uVersion=*(pData++);
    m_pElecPack->uRTUPhysicAddr=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pElecPack->uPacketTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    
    m_pElecPack->uElecParaID=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pElecPack->uElecCollectTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pElecPack->uUpMaxCurrent=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pElecPack->uDownMaxCurrent=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pElecPack->uDayPower=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pElecPack->uTotalPower=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pElecPack->uElecPoint=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    int i;
    
    int nPowerSun=0;
    for(i=0;i<m_pElecPack->uElecPoint;i++)
    {
        m_pElecPack->ArrayElec[i].uElec=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
    }    
    for (i=0;i<m_pElecPack->uElecPoint;i++)
    {
        m_pElecPack->ArrayElec[i].uPower=CTools::CharToInt((unsigned char *)pData,2);
        pData+=2;
    }
    BOOL bTag=FALSE;
    if (m_pDynInfo!=NULL)
    {
        for(i=0;i<m_pDynInfo->DeviceMapping.uWellCnt;i++)
        {
            if (m_pDynInfo->DeviceMapping.ArrayWell[i]==NULL)
            {
                ASSERT(FALSE);
            }
            for (int j=0;j<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;j++)
            {
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]==NULL)
                {
                    ASSERT(FALSE);
                }
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceID==m_pElecPack->uElecParaID)
                {
                    if (m_pWellCalss[i]!=NULL)
                    {
                        m_pWellCalss[i]->setElec(*m_pElecPack);
                    }
#if DEBUG_DB
                    //    CTools::WriteLog(sbuf,1,"电流图");
                    if(AfxGetSQLMng()->InsertElec(m_pDynInfo->DeviceMapping.ArrayWell[i],m_pElecPack,m_pCardPacket)==3L)
                    {
                        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_WELL_TYPE++;
                    }
                    //        
#endif
                    bTag=TRUE;
                    break;
                }
            }
        }
    }
    if (bTag==FALSE)
    {
        CTime dt=CTime::GetCurrentTime();
        CTools::WriteLog(CTools::LONG64TOSTR(m_pElecPack->uElecParaID),EC_DATA_CHECKCARDIDFAIL,dt.Format("%Y-%m-%d"));
        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_CHECKCARDIDFAIL++;
    }
    
    if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
        ShowElecPacket();
    return FALSE;
}
//******************************************电参协议解析*************************
BOOL CRtuProcess::ShowElecPacket()
{
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    //****************************拼凑字符串************************************************
    msg+="**********油井RTU上传电参数据包定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pElecPack->uVersion);
    msg+=hexTostr;
    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pElecPack->uRTUPhysicAddr));
    msg+=hexTostr;
    hexTostr.Format("电参设备ID:%s\r\n",CTools::LONG64TOSTR(m_pElecPack->uElecParaID));
    msg+=hexTostr;
    hexTostr.Format("电参图采集时间:%u\r\n",m_pElecPack->uElecCollectTime);
    msg+=hexTostr;
    hexTostr.Format("上行最大电流:%u     下行最大电流:%u\r\n",m_pElecPack->uUpMaxCurrent,m_pElecPack->uDownMaxCurrent);
    msg+=hexTostr;
    hexTostr.Format("日耗电:%u            累计耗电:%u\r\n",m_pElecPack->uDayPower,m_pElecPack->uTotalPower);
    msg+=hexTostr;
    hexTostr.Format("电流,功率数据点数:%u\r\n",m_pElecPack->uElecPoint);
    msg+=hexTostr;
    CPaintView* pDefView = (CPaintView*)(((CMainFrame*)m_pParent)->m_wndSplitter1x2_2).GetPane(0,1);
    pDefView->m_uElecPoint=m_pElecPack->uElecPoint;
    
    for(int i=0;i<m_pElecPack->uElecPoint;i++)
    {
        pDefView->m_uCurrent[i]=m_pElecPack->ArrayElec[i].uElec;
        pDefView->m_uPower[i]=m_pElecPack->ArrayElec[i].uPower;
        hexTostr.Format("电流数据:%u     功率数据:%d\r\n",m_pElecPack->ArrayElec[i].uElec,m_pElecPack->ArrayElec[i].uPower);
        msg+=hexTostr;
    }
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    pDefView->InvalidateRect(0,TRUE);
    return TRUE;
}
//************************************************************************************
BOOL   CRtuProcess::AnalysisDynInfo()
{
    TRY 
    {
        if (m_pRTUStaticInfo==NULL)
        {
            ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0x02);
            return FALSE;
        }
        m_nByteCnt=0;
        m_nDeviceCnt=0;
        m_nDeviceByte=0;
        //    memset(m_Device,0,sizeof(m_Device));
        char *pData=(char*)m_sBuf;
        if (m_pDynInfo==NULL)
        {
            m_pDynInfo=new CDynInfo;
            memset(m_pDynInfo,0,sizeof(CDynInfo));
        }
        m_pDynInfo->uPacketType=*pData++;
        m_pDynInfo->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
        
        if(m_pDynInfo->uPacketLen<100)
            return false;
        pData+=2;
        m_pDynInfo->uVersion=*(pData++);
        m_pDynInfo->uMacAddress=CTools::CharToInt((unsigned char *)pData,8);
        pData+=8;
        m_pDynInfo->uPackageTime=CTools::CharToInt((unsigned char *)pData,4);
        pData+=4;
        m_pDynInfo->uItem=*pData++;
        int i=0;
        if (m_pDynInfo->uItem&0x10)
        {
            
            //    memcpy()
            //rtu动态配置信息结构
            m_pDynInfo->DynConf.uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
            if (m_pDynInfo->DynConf.uPacketLen>m_pDynInfo->uPacketLen-18)
            {
                return false;
            }
            if (m_bSendConf==FALSE)
            {
                memset(m_bufDynConf,0,sizeof(m_bufDynConf));//测试配置
                memcpy(m_bufDynConf,pData,m_pDynInfo->DynConf.uPacketLen+2);//测试配置
            }
            else
            {
                int a=10000;
            }
            if (memcmp(pData,m_bufDynConf,m_pDynInfo->DynConf.uPacketLen)==0)
            {
                m_bSendConf=FALSE;
            }
            
            /*    if (((CMainFrame*)m_pParent)->m_pSetConf!=NULL)
            {
            SetDynConf();// 写入动态配置
        }*/
            //m_pDynInfo->DynConf.uPacketLen
            
            pData+=2;
            memcpy(m_pDynInfo->DynConf.sWellMark,pData,20);
            if (m_pDynInfo->DynConf.sWellMark=="")
            {
                strcpy(m_pDynInfo->DynConf.sWellMark,"0");
            }
            pData+=20;
            m_pDynInfo->DynConf.uWellCnt=*(pData++);
            m_pDynInfo->DynConf.uReportedRealCycle=*(pData++);
            m_pDynInfo->DynConf.uStartTime=*pData++;
            m_pDynInfo->DynConf.uResponseTimeout=*(pData++);
            m_pDynInfo->DynConf.uRepeatAmount=*(pData++);
            
            m_pDynInfo->DynConf.IPAddrA=*(unsigned int*)pData;//CTools::CharToInt((unsigned char *)pData,4);
            pData+=4;
            m_pDynInfo->DynConf.PortA=*(unsigned short*)pData;//CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            m_pDynInfo->DynConf.IPAddrB=*(unsigned int*)pData;//CTools::CharToInt((unsigned char *)pData,4);
            pData+=4;
            m_pDynInfo->DynConf.PortB=*(unsigned short*)pData;//CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            
            m_pDynInfo->DynConf.uDynConfCnt=*(pData++);
            if (m_pDynInfo->DynConf.uDynConfCnt>4 || m_pDynInfo->DynConf.uDynConfCnt==0)
            {
                //    CTools::WriteLog(sbuf,EC_DATA_CHECKLEN,dt.Format("%Y-%m-%d"));
                return FALSE;
            }
            for (i=0;i<m_pDynInfo->DynConf.uDynConfCnt;i++)
            {
                if (m_pDynInfo->DynConf.ArraryWellConf[i]==NULL)
                {
                    m_pDynInfo->DynConf.ArraryWellConf[i]=new CWellConf;
                    memset(m_pDynInfo->DynConf.ArraryWellConf[i],0,sizeof(CWellConf));
                }
                m_pDynInfo->DynConf.ArraryWellConf[i]->uMasterID=CTools::CharToInt((unsigned char *)pData,8);
                pData+=8;
                memcpy(m_pDynInfo->DynConf.ArraryWellConf[i]->sWellName,pData,20);
                if (m_pDynInfo->DynConf.ArraryWellConf[i]->sWellName=="")
                {
                    strcpy(m_pDynInfo->DynConf.ArraryWellConf[i]->sWellName,"0");
                }
                pData+=20;
                m_pDynInfo->DynConf.ArraryWellConf[i]->uCardDiagram=CTools::CharToInt((unsigned char *)pData,2);
                pData+=2;
                m_pDynInfo->DynConf.ArraryWellConf[i]->uCardPoint=*(pData++);
                m_pDynInfo->DynConf.ArraryWellConf[i]->uSetDayFluence=CTools::CharToInt((unsigned char *)pData,2);
                pData+=2;
                m_pDynInfo->DynConf.ArraryWellConf[i]->uSetTemp=CTools::CharToInt((unsigned char *)pData,2);
                pData+=2;
            }
            m_pDynInfo->DynConf.uCRC=CTools::CharToInt((unsigned char *)pData,2);
            pData+=2;
            if (m_pRTUStaticInfo->ArrayGTBaseInfo[0]!=NULL && m_pRTUStaticInfo->ArrayGTBaseInfo[0]->uModel==0x02 && m_pDynInfo->DynConf.IPAddrB!=inet_addr("110.167.124.38"))
            {
                //m_WriteWellConf=m_pDynInfo->DynConf;
                ZeroMemory(&m_WriteWellConf,sizeof(m_WriteWellConf));
                strcpy((char *)m_WriteWellConf.IPAddrB,"110.167.124.38");
                SetDynConf();
            }
        }
        
        if (m_pDynInfo->uItem&0x20)
        {
            memset(m_bufMapping,0,sizeof(m_bufMapping));//测试配置
            
            //设备对应关系表
            m_pDynInfo->DeviceMapping.uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
            if (m_pDynInfo->uPacketLen+1!=m_pDynInfo->DynConf.uPacketLen+2+m_pDynInfo->DeviceMapping.uPacketLen+2+19)
            {
                return FALSE;
            }
            memcpy(m_bufMapping,pData,m_pDynInfo->DeviceMapping.uPacketLen+2);//测试配置
            pData+=2;
            m_pDynInfo->DeviceMapping.uWellCnt=*(pData++);
            m_pDynInfo->DeviceMapping.uStatus=*(pData++);
            if (m_pDynInfo->DeviceMapping.uWellCnt>4)
            {
                return FALSE;
            }
            for(i=0;i<m_pDynInfo->DeviceMapping.uWellCnt;i++)
            {
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]==NULL)
                {
                    m_pDynInfo->DeviceMapping.ArrayWell[i]=new CWellHead;
                    memset(m_pDynInfo->DeviceMapping.ArrayWell[i],0,sizeof(CWellHead));
                }
                m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt=*(pData++);
                m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellStatus=*(pData++);
                m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType=*(pData++);
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType!=01 && m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType!=02 &&\
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType!=03 && m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType!=04 &&\
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType!=10)
                {
                    CTime dt=CTime::GetCurrentTime();
                    char sbuf[MAXWORD]="";
                    int nLen=m_nBuf;
                    CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nLen);
                    CTools::WriteLog(sbuf,EC_DATA_CHECKLEN,dt.Format("%Y-%m-%d"));
                    ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_CHECKLEN++;
                }
                m_pDynInfo->DeviceMapping.ArrayWell[i]->uReserve=*(pData++);
                //***    memcpy(m_pDynInfo->DeviceMapping.ArrayWell[i]->sWellName,pData,10);  暂时用动态配置里的井名替代
                //        if (m_pDynInfo->DynConf.ArraryWellConf[i]!=NULL)
                //    {
                //        memcpy(m_pDynInfo->DeviceMapping.ArrayWell[i]->sWellName,m_pDynInfo->DynConf.ArraryWellConf[i]->sWellName,20);
                //        }
                //    else
                //        {
                memcpy(m_pDynInfo->DeviceMapping.ArrayWell[i]->sWellName,pData,20);
                //    }
                //            CTools::WriteLog("a",1,"a");
                //**************************************************************************************************        
                pData+=20;
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt>6)
                {
                    return FALSE;
                }
                for (int j=0;j<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;j++)
                {
                    CString asd;
                    //        AfxMessageBox(asd);
                    if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]==NULL)
                    {
                        //    AfxMessageBox(asd);
                        m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]=new CDeviceHead;
                        memset(m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j],0,sizeof(CDeviceHead));
                        //            AfxMessageBox(asd);
                    }
                    //            AfxMessageBox(asd);
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceID=CTools::CharToInt((unsigned char *)pData,8);
                    //            AfxMessageBox(asd);
                    pData+=8;
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uInstType=*(pData++);
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uMeasurementType=*(pData++);
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceStatus=*(pData++);
                    m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uItemLen=*(pData++);
                    m_nDeviceCnt++;
                    m_nDeviceByte+=m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uItemLen;
                    
                }
                if (m_pWellCalss[i]==NULL)
                {
                    if(m_nRtuID==0x0013a2004076d552)
                    {
                        int a=0;
                        a++;
                    }
                    m_pWellCalss[i]=new CWellClass(this);
                    m_pWellCalss[i]->setMapping(m_pDynInfo->DeviceMapping.ArrayWell[i]);
                }
                else
                {
                    m_pWellCalss[i]->setMapping(m_pDynInfo->DeviceMapping.ArrayWell[i]);
                }
                //        CTools::WriteLog("b",1,"a");
                //*********************金时油压套压单独分析*************************
                /*        if (m_pRTUStaticInfo==NULL)
                {
                ASSERT(FALSE);
                }
                if (m_pRTUStaticInfo->ArrayGTBaseInfo[0]->uInstrumentationType==0xf0 && m_pRTUStaticInfo->ArrayGTBaseInfo[0]->uModel==0x0002)
                {
                int nOil=-1;
                for (int x=0;x<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;x++)
                {    
                if(m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[x]->uInstType==0x02)
                {
                if (nOil!=-1)
                {
                if (m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[nOil]->uDeviceID>m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[x]->uDeviceID)
                {
                m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[nOil]->uMeasurementType=0x04;
                m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[x]->uMeasurementType=0x03;
                }else
                {
                m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[x]->uMeasurementType=0x04;
                m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[nOil]->uMeasurementType=0x03;
                }
                break;
                }
                nOil=x;
                }
                }
            }*/
                //******************************************************************
            }
        }else
        {
            return false;
        }
        
#if DEBUG_DB    
        AfxGetSQLMng()->InsertDynInfo(m_pDynInfo);
#endif
        //根据金时判断
        /*    if (m_pRTUStaticInfo!=NULL)
        {
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[0]!=NULL)
        {
        if (m_pRTUStaticInfo->ArrayGTBaseInfo[0]->uModel=0x02)
        {
        for(i=0;i<m_pDynInfo->DeviceMapping.uWellCnt;i++)
        {
        for (int j=0;j<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;j++)
        {
        m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceStatus=0x01;
        }
        }
        }
        }    
        }*/
        //        CTools::WriteLog("c",1,"a");
        if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
            ShowDynInfo();
        //        CTools::WriteLog("d",1,"a");
    }
    CATCH (CMemoryException, e)
    {
        int nBuf=m_nBuf;
        CTime dt=CTime::GetCurrentTime();
        char sbuf[MAXWORD]="";
        CTools::HexToTxt((unsigned char *)m_sBuf,sbuf,nBuf);
        CTools::WriteLog(sbuf,EC_DYN_CATCH,dt.Format("%Y-%m-%d"));
        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DYN_CATCH++;
        //            return FALSE;
        //    CTools::WriteLog(e.,EC_DYN_CATCH,dt.Format("%Y-%m-%d"));
        return FALSE;
        //e->m_szMessage
    }
    END_CATCH
        if (m_pDynInfo->uPacketType!=0xB1)
        {
            ASSERT(FALSE);
        }
        return TRUE;
}
//动态协议包解析
BOOL  CRtuProcess::ShowDynInfo()
{
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    //****************************拼凑字符串************************************************
    msg+="**********RTU设备动态配置信息包定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pDynInfo->uVersion);
    msg+=hexTostr;
    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pDynInfo->uMacAddress));
    msg+=hexTostr;
    int i;
    if (m_pDynInfo->uItem&0x10)
    {
        hexTostr.Format("***动态配置结构****:\r\n");
        msg+=hexTostr;
        hexTostr.Format("井号和井组标记:%.20s\r\n",m_pDynInfo->DynConf.sWellMark);
        msg+=hexTostr;
        hexTostr.Format("油井数量或注水井数量:%u    上报实时数据周期:%u\r\n",m_pDynInfo->DynConf.uWellCnt,m_pDynInfo->DynConf.uReportedRealCycle);
        msg+=hexTostr;
        hexTostr.Format("日统计数据的开始时间:%u    没有接收到主机响应的超时时间:%u\r\n",m_pDynInfo->DynConf.uStartTime,m_pDynInfo->DynConf.uResponseTimeout);
        msg+=hexTostr;
        hexTostr.Format("油井数量或注水井数量:%u    上报实时数据周期:%u\r\n",m_pDynInfo->DynConf.uWellCnt,m_pDynInfo->DynConf.uReportedRealCycle);
        msg+=hexTostr;
        hexTostr.Format("重发次数:%u    上报实时数据周期:%u\r\n",m_pDynInfo->DynConf.uRepeatAmount,m_pDynInfo->DynConf.uDynConfCnt);
        msg+=hexTostr;
        in_addr   aa; 
        aa.S_un.S_addr   =   m_pDynInfo->DynConf.IPAddrA;
        hexTostr.Format("主设备IP地址 : %s:%u\r\n",inet_ntoa(aa),ntohs(m_pDynInfo->DynConf.PortA));
        msg+=hexTostr;
        aa.S_un.S_addr     =   m_pDynInfo->DynConf.IPAddrB;
        hexTostr.Format("备用设备IP地址: %s:%u\r\n",inet_ntoa(aa),ntohs(m_pDynInfo->DynConf.PortB));
        msg+=hexTostr;
        
        
        
        
        for (i=0;i<m_pDynInfo->DynConf.uDynConfCnt;i++)
        {
            hexTostr.Format("井%u主设备ID:%s\r\n",i,CTools::LONG64TOSTR(m_pDynInfo->DynConf.ArraryWellConf[i]->uMasterID));
            msg+=hexTostr;
            hexTostr.Format("ASC码标记号:%.20s\r\n",m_pDynInfo->DynConf.ArraryWellConf[i]->sWellName);
            msg+=hexTostr;
            
            
            hexTostr.Format( "上报示功图周期:%u\r\n",m_pDynInfo->DynConf.ArraryWellConf[i]->uCardDiagram);
            msg+=hexTostr;
            hexTostr.Format("功图点数:%u\r\n",m_pDynInfo->DynConf.ArraryWellConf[i]->uCardPoint);
            msg+=hexTostr;
            hexTostr.Format("设定日配注量:%u\r\n",m_pDynInfo->DynConf.ArraryWellConf[i]->uSetDayFluence);
            msg+=hexTostr;
            hexTostr.Format("设定温度:%u\r\n",m_pDynInfo->DynConf.ArraryWellConf[i]->uSetTemp);
            msg+=hexTostr;
        }
    }
    if (m_pDynInfo->uItem&0x20)
    {
        hexTostr.Format("***设备对应表****:\r\n");
        msg+=hexTostr;
        hexTostr.Format("井数:%u    数据状态:%u\r\n",m_pDynInfo->DeviceMapping.uWellCnt,m_pDynInfo->DeviceMapping.uStatus);
        msg+=hexTostr;
        hexTostr.Format("%u");
        for(i=0;i<m_pDynInfo->DeviceMapping.uWellCnt;i++)
        {
            hexTostr.Format("井%u设备数:%u   使用状态:%u\r\n",i,m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt,m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellStatus);
            msg+=hexTostr;
            hexTostr.Format("井%u类型:%u   保留:%u\r\n",i,m_pDynInfo->DeviceMapping.ArrayWell[i]->uWellType,m_pDynInfo->DeviceMapping.ArrayWell[i]->uReserve);
            msg+=hexTostr;
            hexTostr.Format("井号:%.20s\r\n",m_pDynInfo->DeviceMapping.ArrayWell[i]->sWellName);
            msg+=hexTostr;
            for(int j=0;j<m_pDynInfo->DeviceMapping.ArrayWell[i]->uDeviceCnt;j++)
            {
                hexTostr.Format("井%u设备%uID:%s\r\n",i,j,CTools::LONG64TOSTR(m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceID));
                msg+=hexTostr;
                hexTostr.Format("仪表类型%u     测量项目:%u\r\n",m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uInstType,m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uMeasurementType);
                msg+=hexTostr;
                hexTostr.Format("使用状态%u     数据项长度:%u\r\n",m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uDeviceStatus,m_pDynInfo->DeviceMapping.ArrayWell[i]->ArrayDevice[j]->uItemLen);
                msg+=hexTostr;
            }
            
        }
    }
    
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    return TRUE;
}
//*****************************实时数据********************************************
BOOL CRtuProcess::AnalysisRealData()
{
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    /*--------*/
    
    char *pData=(char*)m_sBuf;
    if(memcmp(m_pDynInfo->DynConf.sWellMark,"跃573",5)==0)
    {
        int a=100;
    }
    if(m_pRealData==NULL)
    {
        m_pRealData=new CRealData;
        memset(m_pRealData,0,sizeof(CRealData));
    }
    
    m_pRealData->uPacketType=*pData++;
    m_pRealData->uPacketLen=CTools::CharToInt((unsigned char *)pData,2);
    pData+=2;
    m_pRealData->uVersion=*(pData++);
    m_pRealData->uMacAddress=CTools::CharToInt((unsigned char *)pData,8);
    pData+=8;
    m_pRealData->uPackageTime=CTools::CharToInt((unsigned char *)pData,4);
    pData+=4;
    m_pRealData->nDataItem=*(pData++);
    m_pRealData->uInstruCnt=*(pData++);
    char *ppData=pData;
    
    if (!(m_pRealData->nDataItem & 0x01))
    {
        return 0;
    }
    if (m_pDynInfo!=NULL && m_nDeviceCnt==m_pRealData->uInstruCnt && (m_pRealData->uPacketLen-(m_pRealData->nDataItem&0x04?39:19))==m_nDeviceByte )
    {
        //******************
        /*    BOOL bTagg=FALSE;//判断中276油压 套压
        if(m_nRtuID==0x0013a200406f6b65)
        {
        char La,Lb;
        La=*(m_sBuf+m_nBuf-6);
        Lb=*(m_sBuf+m_nBuf-5);
        *(m_sBuf+m_nBuf-6)=*(m_sBuf+m_nBuf-4);
        *(m_sBuf+m_nBuf-5)=*(m_sBuf+m_nBuf-3);
        *(m_sBuf+m_nBuf-4)=La;
        *(m_sBuf+m_nBuf-3)=Lb;
        
    }*/
        //**************************
        int nWell=0,nDev=0;
        for (int i=0;i<m_pRealData->uInstruCnt;i++)
        {
            if(m_pDynInfo->DeviceMapping.ArrayWell[nWell]==NULL)
            {
                return 0;
            }
            if (m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]==NULL)
            {
                //申请设备对应表
                return 0;
            }
            pData+=m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]->uItemLen;
            nDev++;
            if (m_pDynInfo->DeviceMapping.ArrayWell[nWell]->uDeviceCnt==nDev)
            {
                //    AfxGetSQLMng()->InsertRealData(m_pDynInfo->DeviceMapping.ArrayWell[nWell],ppData);
                if (m_pWellCalss[nWell]!=NULL)
                {
                    if(m_nRtuID==0x0013a2004076d552)
                    {
                        int a=0;
                        a++;
                    }
                    m_pWellCalss[nWell]->setRealData(m_pRealData,ppData);
                    //`    m_pWellCalss[nWell]->
                }
#if DEBUG_DB
                CString strData;
                CTools::CalYMDHMSOfSecs(m_pRealData->uPackageTime,strData);
                AfxGetSQLMng()->UpdateRealData(m_pDynInfo->DeviceMapping.ArrayWell[nWell],ppData,strData);
                
#endif
                for (int x=0;x<4;x++)
                {
                    if (m_pWellTime[x]==NULL)
                    {
                        m_pWellTime[x]=new CWellHeadTime;
                        m_pWellTime[x]->PreTime=COleDateTime(2010,1,1,1,1,1);
                        m_pWellTime[x]->wellhead=*(m_pDynInfo->DeviceMapping.ArrayWell[nWell]);
                        //    AfxGetSQLMng()->InsertRealDataNet(m_pWellTime[x],ppData);
                        break;
                    }
                    else if (strncmp(m_pWellTime[x]->wellhead.sWellName,m_pDynInfo->DeviceMapping.ArrayWell[nWell]->sWellName,10)==0)
                    {
                        //    CTools::WriteLog("abc",12345,"testnet");
                        //    AfxGetSQLMng()->InsertRealDataNet(m_pWellTime[x],ppData);
                        break;
                    }
                }
                
                ppData=pData;
                nDev=0;
                nWell++;
            }
        }
    }
    else
    {
        CTime dt=CTime::GetCurrentTime();
        char sBuff[MAXWORD]="";
        int nlen = m_nBuf;
        CTools::HexToTxt((unsigned char *)m_sBuf,sBuff,nlen);
        CTools::WriteLog(sBuff,EC_DATA_REALDATALENFAIL,dt.Format("%Y-%m-%d"));
        ((CMainFrame *)m_pParent)->m_ErrorCode.nEC_DATA_REALDATALENFAIL++;
        ((CMainFrame *)m_pParent)->Response(m_sBuf+4,0,m_Server,0xA0);
        pData+=(m_pRealData->uPacketLen-39);
        return FALSE;
    }
    if (m_pRealData->nDataItem&0x04)
    {
        memcpy(m_pRealData->sAlarmInfo,pData,20);
    }
    if (((CMainFrame *)m_pParent)->m_bShowUI==TRUE)
        ShowRealData();
    //**************************检查是否需要升级********************************
    if(m_pRTUStaticInfo!=NULL)
    {
        for (int z=0;z<m_pRTUStaticInfo->uDeviceCnt;z++)
        {
            if (m_pRTUStaticInfo->ArrayGTBaseInfo[z]!=NULL)
            {
                int nCompany,nVersion;
                AfxGetVsp()->GetParaInt("setting.ini","UPDATARTU","version",&nVersion);
                AfxGetVsp()->GetParaInt("setting.ini","UPDATARTU","company",&nCompany);
                //                AfxGetVsp()->GetParaInt("setting.ini","UPDATARTU","rtuid",&nCompany);
                if(m_pRTUStaticInfo->uPacketType!=0xB0)
                    return 0;
                if (m_pRTUStaticInfo->ArrayGTBaseInfo[z]->uInstrumentationType==INSTRUTYPE_RTUEQ && m_pRTUStaticInfo->ArrayGTBaseInfo[z]->uModel==nCompany && m_pRealData->uVersion!=nVersion)
                {
                    char sBufSend[300]="";
                    CLongPack *pLongPack=(CLongPack *)sBufSend;
                    pLongPack->uPacketType=0xE0;//包类型    
                    
                    pLongPack->uVersion=nVersion;                        //版本号
                    memcpy(pLongPack->uMacAddress,m_sBuf+4,8);                    //设备ID
                    pLongPack->uPacketTime=0;                                    //数据打包时间                                                                            
                    pLongPack->uOffset=0;                                        //本报数据偏移地址
                    char sName[30]="";
                    if(AfxGetVsp()->GetParaString("setting.ini","UPDATARTU","filename",sName)==-1)
                    {
                        return FALSE;
                    }
                    int nLen=CTools::ReadData(pLongPack->sBuf,sName,0);            //仪表1数据
                    if (nLen==-1)
                    {
                        return FALSE;
                    }
                    pLongPack->uDataLen=ntohs(nLen);                            //本报数据长度
                    pLongPack->uPacketLen=ntohs(27+nLen);                        //包长度
                    pLongPack->uDataTotleLen=ntohl(CTools::GetFSize(sName));    //数据总长
                    
                    m_nDynConf=((pLongPack->uPacketLen&0xff)*0x100)+(pLongPack->uPacketLen>>8);
                    unsigned short uCRC=CTools::CRC16((unsigned char *)&(sBufSend[1]),nLen+25);
                    sBufSend[26+nLen]=LOW_DATA(uCRC);
                    sBufSend[27+nLen]=HIGH_DATA(uCRC);
                    ((CMainFrame *)m_pParent)->m_pSock->Send((unsigned char *)sBufSend,nLen+28,m_Server);
                    //校验和
                    
                }
                //    m_pRTUStaticInfo->ArrayGTBaseInfo
            }
        }
        
    }
    //*************************************************************************
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    return TRUE;
}
BOOL CRtuProcess::ShowRealData()
{
    CString msg="";
    CString hexTostr="";
    char *pData=(char*)m_sBuf;
    //****************************拼凑字符串************************************************
    msg+="**********RTU实时数据定义************\r\n";
    hexTostr.Format("数据版本:%u\r\n",m_pRealData->uVersion);
    msg+=hexTostr;
    hexTostr.Format("上报设备ID:%s\r\n",CTools::LONG64TOSTR(m_pRealData->uMacAddress));
    msg+=hexTostr;
    
    CString strDatas;
    CTools::CalYMDHMSOfSecs(m_pRealData->uPackageTime,strDatas);
    hexTostr.Format("打包时间:%s\r\n",strDatas);
    msg+=hexTostr;
    
    hexTostr.Format("设备数量:%u\r\n",m_pRealData->uInstruCnt);
    msg+=hexTostr;
    int nWell=0,nDev=0;
    pData+=18;
    if (m_pDynInfo!=NULL)
    {
        
        for(int i=0;i<m_pRealData->uInstruCnt;i++)
        {
            if (m_pDynInfo->DeviceMapping.ArrayWell[nWell]==NULL || m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]==NULL)
            {
                return FALSE;
            }
            if (m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]->uDeviceStatus==0x01)
            {
                switch(m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]->uInstType)
                {
                case         INSTRUTYPE_INTEGRATIONLOAD:
                    hexTostr.Format("设备%u  实时加速度:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  井口实时载荷:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    break;
                case        INSTRUTYPE_PRESS:
                    hexTostr.Format("设备%u  实测压力:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    break;
                case        INSTRUTYPE_TEMP:
                    hexTostr.Format("设备%u  温度:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    break;
                case        INSTRUTYPE_ELEC    :
                    hexTostr.Format("设备%u  电流A:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  电流B:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  电流C:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  电压A:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  电压B:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  电压C:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  功率因数:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  有功功率:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  无功功率:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  日耗电:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  总耗电:%u",nDev,CTools::CharToInt((unsigned char *)pData,4));
                    msg+=hexTostr;
                    pData+=4;
                    hexTostr.Format("设备%u  日生产时间:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  累计生产时间:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,4));
                    msg+=hexTostr;
                    pData+=4;
                    break;
                case        INSTRUTYPE_SPEED:
                    hexTostr.Format("设备%u  转速:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    break;
                case        INSTRUTYPE_FLOWMETER:
                    hexTostr.Format("设备%u  瞬时注入量:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  累计注入量:%u",nDev,CTools::CharToInt((unsigned char *)pData,4));
                    msg+=hexTostr;
                    pData+=4;
                    break;
                case        INSTRUTYPE_VALVE:
                    hexTostr.Format("设备%u  阀开度:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  阀门状态:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  日生产时间:%u",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  累计生产时间:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,4));
                    msg+=hexTostr;
                    pData+=4;
                    break;
                case        INSTRUTYPE_TLSENSOR:
                    hexTostr.Format("设备%u  扭矩:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  载荷:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    hexTostr.Format("设备%u  转数:%u\r\n",nDev,CTools::CharToInt((unsigned char *)pData,2));
                    msg+=hexTostr;
                    pData+=2;
                    break;
                case        INSTRUTYPE_RTUEQ:
                    ;
                case        INSTRUTYPE_HANDWRITE:
                    ;
                }
            }
            else if (m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]->uDeviceStatus==0xff)
            {
                hexTostr.Format("设备%u:仪表维护中\r\n",nDev);
                msg+=hexTostr;
                pData+=m_pDynInfo->DeviceMapping.ArrayWell[nWell]->ArrayDevice[nDev]->uItemLen;
            }
            else
            {
                hexTostr.Format("设备%u:仪表停止使用\r\n",nDev);
                msg+=hexTostr;
            }
            
            nDev++;
            if(m_pDynInfo->DeviceMapping.ArrayWell[nWell]->uDeviceCnt==nDev)
            {
                nDev=0;
                nWell++;
            }
        }
    }        
    else
    {
        char sBuf[MAXBYTE]="";
        int nSize=m_pRealData->uPacketLen-((m_pRealData->nDataItem&0x04)?39:19);
        CTools::HexToTxt((unsigned char *)m_sBuf+18,(char *)sBuf,nSize);
        
        hexTostr.Format("实时数据:%s\r\n",sBuf);
        msg+=hexTostr;
    }
    if (m_pRealData->nDataItem&0x04)
    {
        hexTostr.Format("报警信息:%s\r\n",m_pRealData->sAlarmInfo);
    }
    
    //    msg+=hexTostr;
    CMainFrame *pParent=(CMainFrame *)m_pParent;
    pParent->AddAnalysisText(msg);
    return TRUE;
}
BOOL CRtuProcess::SetDynConf()
{
    
    CMainFrame *pMain=(CMainFrame *)m_pParent;
    char *p=m_bufDynConf;
    CDynConf *pDynCof=(CDynConf *)p;
    int nBuf=0;
    //*************************修改上传实时数据周期***************************************
    char zzBuf[10]="";
    memcpy(zzBuf,pDynCof->sWellMark,2);
    
    //    if (strcmp("中",zzBuf)!=0)
    //    {
    //    return 0;
    //    }
    
    if(pDynCof->uReportedRealCycle!=m_WriteWellConf.uReportedRealCycle&& m_WriteWellConf.uReportedRealCycle!=0)
    {
        pDynCof->uReportedRealCycle=m_WriteWellConf.uReportedRealCycle;
        m_bSendConf=TRUE;
        
    }
    else
    {
        //        m_bSendConf = TRUE;
        //        pDynCof->uReportedRealCycle=pMain->m_pSetConf->uReportedRealCycle;
        ;
    }
    
    /*    pDynCof->uResponseTimeout=10;
    pDynCof->uRepeatAmount=3;*/
    //****************************************************
    //    bSend=TRUE;
    //    pDynCof->
    //更改实时数据上传周期
    /*    if (AfxGetVsp()->GetParaInt("setting.ini","WELLCONF","uReportedRealCycle",&nBuf)==-1)
    {
    return FALSE;
    }
    if (nBuf!=0 && nBuf!=pDynCof->uReportedRealCycle && 240>=nBuf>1)
    {
    pDynCof->uReportedRealCycle=nBuf;
    bSend=TRUE;
}*/
    //    日统计开始时间
    nBuf=0;
    
    if (m_WriteWellConf.uStartTime!=0 && m_WriteWellConf.uStartTime!=pDynCof->uStartTime)
    {
        pDynCof->uStartTime=m_WriteWellConf.uStartTime;
        m_bSendConf=TRUE;
    }
    //超时时间
    
    if (m_WriteWellConf.uResponseTimeout!=0 && m_WriteWellConf.uResponseTimeout!=pDynCof->uResponseTimeout)
    {
        pDynCof->uResponseTimeout=m_WriteWellConf.uResponseTimeout;
        m_bSendConf=TRUE;
    }
    //重发次数
    //    nBuf=0;
    if (m_WriteWellConf.uRepeatAmount!=0 && m_WriteWellConf.uRepeatAmount!=pDynCof->uRepeatAmount)
    {
        pDynCof->uRepeatAmount=m_WriteWellConf.uRepeatAmount;
        m_bSendConf=TRUE;
    }
    
    //IPAddr
    
    if (pDynCof->IPAddrB!=inet_addr((char*)(m_WriteWellConf.IPAddrB)))
    {
        pDynCof->IPAddrB=inet_addr((char*)(m_WriteWellConf.IPAddrB));
        m_bSendConf=TRUE;
    }
    if (m_WriteWellConf.PortB!=0 && pDynCof->PortB!=ntohs(m_WriteWellConf.PortB))
    {
        pDynCof->PortB=ntohs(m_WriteWellConf.PortB);
        m_bSendConf=TRUE;
    }
    
    p+=40;
    CWellConf *pWellConf[4];
    for (int i=0;i<pDynCof->uDynConfCnt;i++)
    {
        pWellConf[i]=(CWellConf *)p;
        //    for (int j=0;j<pMain->m_uWellConfCnt;j++)
        //    {
        if(strcmp(pWellConf[i]->sWellName,m_WriteWellConf.sWellMark)==0)
        {
            //功图周期
            if (pWellConf[i]->uCardDiagram!=0  && m_WriteWellConf.uCardDiagram!=0 && m_WriteWellConf.uCardDiagram!=ntohs(pWellConf[i]->uCardDiagram) && (7200>=m_WriteWellConf.uCardDiagram && m_WriteWellConf.uCardDiagram>=300))
            {
                pWellConf[i]->uCardDiagram=ntohs(m_WriteWellConf.uCardDiagram);
                m_bSendConf=TRUE;
            }
            //功图点数
            if (pWellConf[i]->uCardPoint!=0   && m_WriteWellConf.uCardPoint!=0 && m_WriteWellConf.uCardPoint!=pWellConf[i]->uCardPoint && (255>=m_WriteWellConf.uCardPoint && m_WriteWellConf.uCardPoint>=60))
            {
                pWellConf[i]->uCardPoint=m_WriteWellConf.uCardPoint;
                m_bSendConf=TRUE;
            }
            //日配注量
            if (pWellConf[i]->uSetDayFluence!=ntohs(m_WriteWellConf.uSetDayFluence))
            {
                pWellConf[i]->uSetDayFluence=ntohs(m_WriteWellConf.uSetDayFluence);
                m_bSendConf=TRUE;
            }
            //设定温度
            if (pWellConf[i]->uSetDayFluence!=ntohs(m_WriteWellConf.uSetDayFluence))
            {
                pWellConf[i]->uSetDayFluence=ntohs(m_WriteWellConf.uSetDayFluence);
                m_bSendConf=TRUE;
            }
            
            //        }
        }
        p+=35;
    }
    //    CWellConf *pWellConf=(CWellConf *)p;
    //    pWellConf->uCardPoint=212;
    //    pWellConf->uSetDayFluence=ntohs(48);
    //    pWellConf->
    //    pWellConf->uSetTemp=ntohs(1);
    //    memset(pWellConf->sWellName,0,20);
    //    memcpy(pWellConf->sWellName,"GH跃624",7);
    if (m_bSendConf==TRUE)
    {
        m_nDynConf=((pDynCof->uPacketLen&0xff)*0x100)+(pDynCof->uPacketLen>>8);
        unsigned short uCRC=CTools::CRC16((unsigned char *)&(m_bufDynConf),m_nDynConf);
        m_bufDynConf[m_nDynConf]=LOW_DATA(uCRC);
        m_bufDynConf[m_nDynConf+1]=HIGH_DATA(uCRC);
        //        pMain->ResposeConf(m_sBuf+4,m_nDynConf+2,m_Server,0x10,m_bufDynConf);
    }
    return TRUE;
}
BOOL CRtuProcess::AnalysisUpdata()
{

    CMainFrame *pMain=(CMainFrame *)m_pParent;;
    pMain->m_pTcp->NetSend(m_socket,m_sBuf,m_nBuf);
/*    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }
    //    m_sBuf
    CLongPack  *pLongPack;
    //    memcpy((void *)pLongPack,m_sBuf,m_nBuf);
    pLongPack=(CLongPack *)m_sBuf;
    int nBuf=0;
    if(AfxGetVsp()->GetParaInt("setting.ini","UPDATARTU","version",&nBuf)==-1)
    {
        return FALSE;
    }
    char sName[30]="";
    if(AfxGetVsp()->GetParaString("setting.ini","UPDATARTU","filename",sName)==-1)
    {
        return FALSE;
    }
    if (nBuf!=pLongPack->uVersion)
    {
        return FALSE;
    }
    int nLen=CTools::ReadData(pLongPack->sBuf,sName,ntohl(pLongPack->uOffset));
    if (nLen==-1)
    {
        return FALSE;
    }
    //    unsigned short ca=ntohs(pLongPack->uDataLen)-nLen;
    short nPackLen=ntohs(pLongPack->uPacketLen)+nLen;
    pLongPack->uPacketLen=ntohs(nPackLen);
    pLongPack->uDataLen=ntohs(nLen);
    
    m_nDynConf=((pLongPack->uPacketLen&0xff)*0x100)+(pLongPack->uPacketLen>>8);
    unsigned short uCRC=CTools::CRC16((unsigned char *)&(m_sBuf[1]),nLen+25);
    m_sBuf[26+nLen]=LOW_DATA(uCRC);
    m_sBuf[27+nLen]=HIGH_DATA(uCRC);
    ((CMainFrame *)m_pParent)->m_pSock->Send((unsigned char *)m_sBuf,nLen+28,m_Server);
    if (m_pDynInfo->uPacketType!=0xB1)
    {
        ASSERT(FALSE);
    }*/
    
    ZeroMemory(m_sBufUpData,sizeof(m_sBufUpData));
    m_nUpData=0;
    return TRUE;
}
BOOL CRtuProcess::SetUpdata(char *pData,int nSize,SOCKET sock)
{
    m_socket =sock;
    int pianyi=CTools::CharToInt((unsigned char *)(pData+20),4);
    if (pianyi!=0)
    {
        ((CMainFrame *)m_pParent)->m_pSock->Send((unsigned char *)pData,nSize,m_Server);
    }
    else
    {
        memcpy(m_sBufUpData,pData,nSize);
        m_nUpData=nSize;
    }
    return 0;
}