// CdtZf.cpp: implementation of the CZFCasco class. // ////////////////////////////////////////////////////////////////////// #include "zfCasco.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CZFCasco::CZFCasco() { this->m_popt_train = NULL; } CZFCasco::~CZFCasco() { } void CZFCasco::PrtBuf(uint8 *buf, int len) { char prttmp[3000] = { "" }; int i = 0, n = 0, k = len;//1000 if (len<1000) { for (i = 0; i1000) { for (i = 0; i<1000; i++) sprintf(prttmp + 3 * i, "%02x ", buf[i + 1000 * n]); PrintLog(LOG_INFORMATION, prttmp); n++; k -= 1000; } prttmp[3000 - 2] = '\n'; } } void CZFCasco::readini() { char* home = getenv("FEPROOT"); if (home == NULL) { PrintLog(LOG_ERROR, "环境变量未设置"); return; } char filename[512]; #if defined(__unix) sprintf(filename, "%s%s", home, "/cfg/atsredis.ini"); #else sprintf(filename, "%s%s", home, "\\cfg\\atsredis.ini"); #endif CReadConf readconf; readconf.ReadString("LoginInfo", "redis_ip", redisip, filename, "192.168.2.47"); redisport = readconf.ReadLong("LoginInfo", "redis_port", filename, "6379"); } //规约参数设置函数,负责初始化规约接口对象和规约 void CZFCasco::Init(S_PROTOCOLCFG * pcfg) { int i = 0; PRawCtrl = pcfg->PRawCtrl; pRxBuf = pcfg->pRxBuf; pTxBuf = pcfg->pTxBuf; pCmdMem = pcfg->pCmdMem; pRtu = pcfg->pRtu; pLink = pcfg->pLink; pTable = pcfg->pTable; pZfDataCtrl = pcfg->pZfDataCtrl; // pHis = pcfg->pHis; bInited = 0; bFas = 0; bEmcs = 0; bScada = 0; bIdle = 0; //初始化该规约的参数 m_SysId = 0xff; // StaNums=13;//车站数 memset(winHan, 0, sizeof(winHan)); memset(zfFas, 0, sizeof(zfFas)); memset(zfScada, 0, sizeof(zfScada)); memset(zfEmcs, 0, sizeof(zfEmcs)); memset(Fas, 0, sizeof(Fas)); memset(ScadaZone, 0, sizeof(ScadaZone)); memset(Emcs, 0, sizeof(Emcs)); memset(zfYX, 0, sizeof(zfYX)); memset(zfYCmx, 0, sizeof(zfYCmx)); m_RcvTimeOuts = pLink->GetRxTimeouts(); if (m_RcvTimeOuts <= 0) m_RcvTimeOuts = 10; m_CallAllData = pLink->GetAllDataScanInterval();//Planned计划列车运行信息*60 if (m_CallAllData <= 0) m_CallAllData = 3600; m_CallKWH = pLink->GetKwhScanInterval();//Practical实际列车运行信息 if (m_CallKWH <= 0) m_CallKWH = 10; sint32 rtuno = pLink->GetRtuNo(); m_SyncTime = pRtu->GetSyncTimeInt(rtuno) * 60; m_LastSendTime = 0; m_LastCallAllTime = 0; m_LastCallKWHTime = 0; m_LastSynctime = 0; cnt_sequence = 0; for (i = 0; iGetYxNum(rtuno); i++)PRawCtrl->PutAYx(rtuno, i, 0); for (i = 0; iGetYcNum(rtuno); i++)PRawCtrl->PutAYc(rtuno, i, 0); readini(); } uint8 CZFCasco::GetZf() { sint32 rtuno = pLink->GetRtuNo(); bFas = 0; bEmcs = 0; bScada = 0; int i = 0, j = 0; uint8 ret = 0; uint16 YxNum, YcNum; S_RDB_ZFYx *yxinfo; CEasyList * pYxList = pZfDataCtrl->GetYxStructList(); YxNum = pYxList->GetListLen(); S_RDB_ZFYc *ycinfo; CEasyList * pYcList = pZfDataCtrl->GetYcStructList(); YcNum = pYcList->GetListLen(); if (!bInited) { for (i = 0; iVal; yxinfo->OldVal = yxinfo->Val; yxinfo->qds/*chgFlag*/ = 0x80; //FAS if (yxinfo->YxNo >= 1 && yxinfo->YxNo <= 30) { zfFas[i] = yxinfo->Val; Fas[i] = 2 - (yxinfo->Val & 1); // PRawCtrl->PutAYx(rtuno,i,zfFas[i]); } //SCADA if (yxinfo->YxNo >= 31 && yxinfo->YxNo <= 200) zfScada[i - 30] = yxinfo->Val; //EMCS if (yxinfo->YxNo >= 201 && yxinfo->YxNo <= 344) zfEmcs[i - 200] = yxinfo->Val; } //1500MX for (i = 0; iVal>30)zfYCmx[i]=1; else zfYCmx[i]=0; ycinfo->OldVal=ycinfo->Val; ycinfo->qds/*chgFlag*/ = 0x80; } bInited=1; ret=0;//fas-scada-emcs均需发送给ats zfScadaToATS(zfYCmx,zfScada,120);//12段 zfEmcsToATS(zfEmcs,48*3); } else { for(int i=0;iOldVal=yxinfo->Val; yxinfo->qds/*chgFlag*/ = 0x80; if(yxinfo->YxNo>=1 && yxinfo->YxNo<=30){ if(yxinfo->Val!=zfYX[i]){ zfFas[i]=yxinfo->Val; zfYX[i]=yxinfo->Val; Fas[i]=2-(yxinfo->Val & 1); bFas++; } } //SCADA if(yxinfo->YxNo>=31 && yxinfo->YxNo<=200){ if(yxinfo->Val!=zfYX[i]){ zfScada[i-30]=yxinfo->Val; zfYX[i]=yxinfo->Val; bScada++; } } //EMCS if(yxinfo->YxNo>=201 && yxinfo->YxNo<=344){ if(yxinfo->Val!=zfYX[i]){ zfEmcs[i-200]=yxinfo->Val; zfYX[i]=yxinfo->Val; bEmcs++; } } } //1500MX for(i=0;iVal>=30 && zfYCmx[i]==0) { zfYCmx[i]=1;bScada++;} if(ycinfo->Val<30 && zfYCmx[i]==1) { zfYCmx[i]=0;bScada++;} ycinfo->OldVal=ycinfo->Val; ycinfo->qds/*chgFlag*/ = 0x80; } ret=0x80; if(bFas>0) ret+=1; if(bScada>0){ ret+=2;zfScadaToATS(zfYCmx,zfScada,120);} if(bEmcs>0){ ret+=4;zfEmcsToATS(zfEmcs,48*3);} } return ret; } //yc-13个牵降所直流母线带电有无;yx-直流开关、闸刀状态 //12段触网 -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 // ELZ-ZJJ,-ZDB,-DSH,-CYR,-QPS,-HJR,-ZXS,-JSR,-XYR,-PLR,-NBL,-HQS void CZFCasco::zfScadaToATS(uint8 *yc,uint8 *yx,int len) { //len-116 int i=0,j=0,k=0,tmp=0; //ELZ-ZJJ if((yc[0]>0 && yx[0]>0 && yx[0+2]>0) || (yc[0+1]>0 && yx[10]>0 && yx[10+4]>0))//XX ScadaZone[0][1]=1; else ScadaZone[0][1]=0; if((yc[0]>0 && yx[1]>0 && yx[1+2]>0) || (yc[0+1]>0 && yx[10+1]>0 && yx[10+1+4]>0))//SX ScadaZone[0][2]=1; else ScadaZone[0][2]=0; //ZJJ-ZDB---NBL 10 for(i=0;i0 && yx[10+10*i+2]>0 && yx[10+10*i+2+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)]>0 && yx[10+10*(i+1)+4]>0)) ScadaZone[1+i][1]=1; else ScadaZone[1+i][1]=0; //SX if((yc[1+i]>0 && yx[10+10*i+3]>0 && yx[10+10*i+3+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)+1]>0 && yx[10+10*(i+1)+1+4]>0)) ScadaZone[1+i][2]=1; else ScadaZone[1+i][2]=0; } i=10; //NBL-HQS if((yc[1+i]>0 && yx[10+10*i+2]>0 && yx[10+10*i+2+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)]>0 && yx[10+10*(i+1)+2]>0)) ScadaZone[1+i][1]=1; else ScadaZone[1+i][1]=0; if((yc[1+i]>0 && yx[10+10*i+3]>0 && yx[10+10*i+3+4]>0) || (yc[1+i+1]>0 && yx[10+10*(i+1)+1]>0 && yx[10+10*(i+1)+1+2]>0)) ScadaZone[1+i][2]=1; else ScadaZone[1+i][2]=0; //ZJJ-ZJT if(yc[1]>0 && yx[10*12+4]>0 && yx[10*12+4+2]>0) ScadaZone[1][0]=1;//in else ScadaZone[1][0]=0; if(yc[1]>0 && yx[10*12+4+1]>0 && yx[10*12+4+2+1]>0) ScadaZone[1][3]=1;//out else ScadaZone[1][3]=0; //ZJT if(yc[13]>0 && yx[10*13+0]>0 && yx[10*13+7]>0) ScadaZone[12][0]=1; else ScadaZone[12][0]=0; if(yc[13]>0 && yx[10*13+1]>0 && yx[10*13+7+1]>0) ScadaZone[12][1]=1; else ScadaZone[12][1]=0; if(yc[13]>0 && yx[10*13+2]>0 && yx[10*13+7+2]>0) ScadaZone[12][2]=1; else ScadaZone[12][2]=0; if(yc[13]>0 && yx[10*13+3]>0 && yx[10*13+7+3]>0) ScadaZone[12][3]=1; else ScadaZone[12][3]=0; if(yc[13]>0 && yx[10*13+4]>0 && yx[10*13+7+4]>0) ScadaZone[13][0]=1; else ScadaZone[13][0]=0; if(yc[13]>0 && yx[10*13+5]>0) ScadaZone[13][1]=1; else ScadaZone[13][1]=0; if(yc[13]>0 && yx[10*13+6]>0 && yx[10*13+7+6]>0) ScadaZone[13][2]=1; else ScadaZone[13][2]=0; //联络刀检查//0-9 for(i=0;i0){ if(ScadaZone[i][1]!=ScadaZone[i+1][1]){ ScadaZone[i+1][1]=ScadaZone[i][1]=1;} } //SX if(yx[10*(i+1)+9]>0){ if(ScadaZone[i][2]!=ScadaZone[i+1][2]){ ScadaZone[i+1][2]=ScadaZone[i][2]=1;} } } //9-0 for(i=len/10-2-1;i>=0;i--) { //XX if(yx[10*(i+1)+8]>0){ if(ScadaZone[i][1]!=ScadaZone[i+1][1]){ ScadaZone[i+1][1]=ScadaZone[i][1]=1;} } //SX if(yx[10*(i+1)+9]>0){ if(ScadaZone[i][2]!=ScadaZone[i+1][2]){ ScadaZone[i+1][2]=ScadaZone[i][2]=1;} } } //ZJJ-ZJT联络刀 if(yx[128]>0){//2151 if(ScadaZone[1][0]!=ScadaZone[1][1]){ ScadaZone[1][1]=ScadaZone[1][0]=1;} } if(yx[129]>0){//2162 if(ScadaZone[1][3]!=ScadaZone[1][2]){ ScadaZone[1][2]=ScadaZone[1][3]=1;} } //ZJT联络刀 if(yx[144+2]>0){//ZT03 if(ScadaZone[12][0]!=ScadaZone[12][2]){ ScadaZone[12][2]=ScadaZone[12][0]=1;} } if(yx[144+2+1]>0){//ZT04 if(ScadaZone[12][1]!=ScadaZone[12][3]){ ScadaZone[12][3]=ScadaZone[12][1]=1;} } if(yx[144+2+2]>0){//ZT05 if(ScadaZone[12][3]!=ScadaZone[13][0]){ ScadaZone[13][0]=ScadaZone[12][3]=1;} } if(yx[144+2+3]>0){//ZT06 if(ScadaZone[13][0]!=ScadaZone[13][2]){ ScadaZone[13][2]=ScadaZone[13][0]=1;} } if(yx[144+2+2]>0){//ZT05 if(ScadaZone[12][3]!=ScadaZone[13][0]){ ScadaZone[13][0]=ScadaZone[12][3]=1;} } if(yx[144+2+1]>0){//ZT04 if(ScadaZone[12][1]!=ScadaZone[12][3]){ ScadaZone[12][3]=ScadaZone[12][1]=1;} } if(yx[144+2]>0){//ZT03 if(ScadaZone[12][0]!=ScadaZone[12][2]){ ScadaZone[12][2]=ScadaZone[12][0]=1;} } if(yx[144+0]>0){//ZT01-chu if(ScadaZone[13][0]>0)ScadaZone[14][0]=1; else ScadaZone[14][0]=0; } else ScadaZone[14][0]=0; if(yx[144+1]>0){//ZT02-ru if(ScadaZone[12][2]>0)ScadaZone[14][1]=1; else ScadaZone[14][1]=0; } else ScadaZone[14][1]=0; //ELZ-L01-L02 if(ScadaZone[0][1]>0 && yx[4]>0)ScadaZone[0][0]=1; else ScadaZone[0][0]=0; if(ScadaZone[0][2]>0 && yx[5]>0)ScadaZone[0][3]=1; else ScadaZone[0][3]=0; if(ScadaZone[0][0]+ScadaZone[0][3]<1) {ScadaZone[0][0]=0;ScadaZone[0][3]=0;} else {ScadaZone[0][0]=1;ScadaZone[0][3]=1;} //ZDB-DSH-L03-L04 if(ScadaZone[2][1]>0 && yx[6]>0)ScadaZone[3][0]=1; else ScadaZone[3][0]=0; if(ScadaZone[2][2]>0 && yx[7]>0)ScadaZone[3][3]=1; else ScadaZone[3][3]=0; if(ScadaZone[3][0]+ScadaZone[3][3]<1) {ScadaZone[3][0]=0;ScadaZone[3][3]=0;} else {ScadaZone[3][0]=1;ScadaZone[3][3]=1;} //QPS-HJR-L05-L06 if(ScadaZone[5][1]>0 && yx[8]>0)ScadaZone[6][0]=1; else ScadaZone[6][0]=0; if(ScadaZone[5][2]>0 && yx[9]>0)ScadaZone[6][3]=1; else ScadaZone[6][3]=0; if(ScadaZone[6][0]+ScadaZone[6][3]<1) {ScadaZone[6][0]=0;ScadaZone[6][3]=0;} else {ScadaZone[6][0]=1;ScadaZone[6][3]=1;} sint32 rtuno = pLink->GetRtuNo(); //1有电2无电0未知 /* for(i=0;iPutAYx(rtuno,i*4+j+1,ScadaZone[i][j]&1); } }*/ } void CZFCasco::zfEmcsToATS(uint8 *buf,int len) { sint32 rtuno = pLink->GetRtuNo(); //up-dn-stop int i=0,num=len/3; for(i=0;iPutAYx(rtuno,i*3+0+81,buf[3*i+0]); // PRawCtrl->PutAYx(rtuno,i*3+1+81,buf[3*i+1]); // PRawCtrl->PutAYx(rtuno,i*3+2+81,buf[3*i+2]); //Status-1on2off0unknown if(buf[3*i+0]+buf[3*i+1]==1 && buf[3*i+2]<=0) Emcs[i][0]=1;//run-100-010 else if(buf[3*i+0]+buf[3*i+1]==0 && buf[3*i+2]>0) Emcs[i][0]=2;//stop-001 else Emcs[i][0]=0;//unknown //Director-1up2dn0unknown if(buf[3*i+0]>0 && buf[3*i+1]<=0 && buf[3*i+2]<=0 )Emcs[i][1]=1;//up else if(buf[3*i+1]>0 && buf[3*i+0]<=0 && buf[3*i+2]<=0 )Emcs[i][1]=2;//dn else Emcs[i][1]=0; } } sint32 CZFCasco::TxProc() { uint8 ret=GetZf(); sint32 nowtime = GetNowSecond(); E_RAW_ComStat commstatus = pLink->GetCommStatus(); if( commstatus !=CMST_TX_CNT && commstatus !=CMST_NORMAL) return 0; if((nowtime - m_LastSendTime) >= 5)//5sPolling {ret=0;} if(ret==0){ IscsAtsFasInfo(); IscsAtsScadaInfo(); IscsAtsEmcsInfo(); pLink->RegisterFrm(FRAME_TX_SUC); } else{ if(ret&1>0){ IscsAtsFasInfo(); } if(ret&2){ IscsAtsScadaInfo(); } if(ret&4){ IscsAtsEmcsInfo(); } pLink->RegisterFrm(FRAME_TX_SUC); } if((nowtime - m_LastSendTime) >= 5)//5sPolling { MsgPolling(); //bInited=0; pLink->RegisterFrm(FRAME_TX_SUC); pLink->SetCommStatus(CMST_RX_CNT); } if((nowtime - m_LastCallAllTime) > m_CallAllData) {//请求当天行车计划信息 // IscsAtsPlannedTrain(); pLink->RegisterFrm(FRAME_TX_SUC); // pLink->SetCommStatus(CMST_RX_CNT); } if(( nowtime - m_LastCallKWHTime)>m_CallKWH) {//请求实际行车计划信息 // IscsAtsPracticalTrain(); pLink->RegisterFrm(FRAME_TX_SUC); // pLink->SetCommStatus(CMST_RX_CNT); } return 1; } sint32 CZFCasco::RxProc() { int xx=0; E_RAW_ComStat commstatus = pLink->GetCommStatus(); sint32 rtuno = pLink->GetRtuNo(); uint8 rtuaddr = pRtu->GetRtuAddr(rtuno); uint8 buf[80000]; int datalen = 0 ,datanum =0,dlen=0; memset(buf,0,sizeof(buf)); sint32 buflen=pRxBuf->GetReadableSize(); datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE); int nowtime=GetNowSecond(); if ( commstatus==CMST_RX_CNT && (nowtime-m_LastSendTime) >= m_RcvTimeOuts) { //超时不重发,直接跳到下一个终端 if(buflen>0)pRxBuf->Move(buflen); pLink->RegisterFrm(FRAME_RX_TIMEOUT); pLink->SetCommStatus(CMST_TX_CNT); m_LastSendTime=0; PrintLog(LOG_VIOLATION,"数据超时\n"); return -1; } if(buflen<6){ return 0; } dlen=buf[2]+buf[1]*256+3; while(buf[0]==m_SysId && datalen>=buf[2]+buf[1]*256+3 && buf[2]+buf[1]*256<=1025) //第一位为0xff 这帧数据没有后续帧 规约完整读取到了这帧数据 { xx=0; switch(buf[7]+buf[6]*256) //判断这帧数据的消息ID类型 { case 0x0FA0://4000//0x1001:// RxAtsTrainLocation(buf); //列车位置信息 break; case 0x1005://0x1002:// RxAtsBlockInfo(buf); //列车阻塞信息 break; case 0x1006://0x1003:// //if(buf[2]+buf[1]*256>10) switch(buf[9]+buf[8]*256) { case 0x1101://start break; case 0x1102://content RxAtsPlannedTrain(buf); //计划列车运行信息 break; case 0x1103://end break; default: break; } break; case 0x1007://0x1004://PracticalTrain //if(buf[2]+buf[1]*256>10) switch(buf[9]+buf[8]*256) { case 0x1101://start break; case 0x1102://content RxAtsPracticalTrain(buf); break; case 0x1103://end break; default: break; } break; case 0x1008://0x1005://DynamicTrain RxAtsDynamicTrain(buf); break; case 0x1009://0x2002://Request PlannedTrain break; case 0x100A://0x2003://Request PracticalTrain break; case 0x2001://0x2004://fas break; case 0x2002://0x2005://scada break; case 0x2003://0x2006://bas break; case 0x3001://MessagePolling break; default: PrintLog(LOG_VIOLATION," FromATS Error Type %02x %02x\n",buf[6],buf[7]); xx=1; pRxBuf->Move(1); buflen-=1; datalen-=1; datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE); break; } if(xx>0)break; // if(datalen>0){ if(buf[7]+buf[6]*256!=0x1007 || buf[7]+buf[6]*256!=0x1006 || buf[7]+buf[6]*256!=0x3001) { PrintLog(LOG_INFORMATION,"RTU%d收到MsgID%02x%02x,buflen=%d,datalen=%d--<<",rtuno,buf[6],buf[7],buf[2]+buf[1]*256+3,datalen); // PrtBuf(buf,buf[2]+buf[1]*256+3); } //PrintLog(LOG_INFORMATION,"BeforeMove:buf[0]=%02x%02x%02x,buf[%d]=%02x%02x%02x\n",buf[0],buf[1],buf[2],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3+1],buf[buf[2]+buf[1]*256+3+2]); pRxBuf->Move(buf[2]+buf[1]*256+3); buflen-=buf[2]+buf[1]*256+3; datalen-=buf[2]+buf[1]*256+3; datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE); //PrintLog(LOG_INFORMATION,"AfterMove:buf[0]=%02x%02x%02x,buf[%d]=%02x%02x%02x\n",buf[0],buf[1],buf[2],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3],buf[2]+buf[1]*256+3,buf[buf[2]+buf[1]*256+3+1],buf[buf[2]+buf[1]*256+3+2]); //buflen=pRxBuf->GetReadableSize(); pLink->RegisterFrm(FRAME_RX_SUC); pLink->SetCommStatus(CMST_TX_CNT); } while(buflen>0 && (buf[0]!=m_SysId || (buf[0]==m_SysId && buf[2]+buf[1]*256>1025))) { PrintLog(LOG_INFORMATION,"-1");PrtBuf(buf,1); pRxBuf->Move(1); buflen=pRxBuf->GetReadableSize(); datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE); } return 1; } sint32 CZFCasco::GetNowSecond() { CSeTime SE_T; TCriterionTime tmptime;//sint32 SE_T.GetNow(&tmptime); return (sint32)tmptime; } void CZFCasco::IscsAtsPlannedTrain() { uint8 conLen=StaNums*2; uint8 txbuff[8]; uint8 len=0, tLen=5; memset(txbuff,0,8); if(cnt_sequence>=65535) cnt_sequence=0; else cnt_sequence++; //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen / 0x100;//L Total Lenth txbuff[len++]=tLen % 0x100;//H txbuff[len++]=0;//Multi-Flag //////////////////////////// txbuff[len++]=0;//msgID len + content len txbuff[len++]=2;// txbuff[len++]=4105/0x100;//0x20;//H msgID 4105 txbuff[len++]=4105%0x100;//0x02;//L msgID //content pLink->RegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); pLink->SetCommStatus(CMST_RX_CNT); m_LastCallAllTime = GetNowSecond(); PrintLog(LOG_INFORMATION,"ISCS->ATS Send PlannedTrain MsgID = 0x2002"); // PrtBuf(txbuff,len); } void CZFCasco::IscsAtsPracticalTrain() { uint8 conLen=StaNums*2; uint8 txbuff[8]; uint8 len=0,tLen=5; memset(txbuff,0,8); if(cnt_sequence>=65535) cnt_sequence=0; else cnt_sequence++; //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen/0x100;//H Total Lenth txbuff[len++]=tLen%0x100;//L txbuff[len++]=0;//Multi-Flag //////////////////////////// txbuff[len++]=0;//msgID len + content len txbuff[len++]=2;// txbuff[len++]=4106/0x100;//0x20;//H msgID 4106 txbuff[len++]=4106%0x100;//0x03;//L msgID //content pLink->RegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); pLink->SetCommStatus(CMST_RX_CNT); m_LastCallKWHTime = GetNowSecond(); PrintLog(LOG_INFORMATION,"ISCS->ATS Send PracticalTrain MsgID = 0x2003"); // PrtBuf(txbuff,len); } void CZFCasco::IscsAtsFasInfo() { uint8 conLen=StaNums*2; //13*2 uint8 txbuff[35]; uint8 len=0,tLen; memset(txbuff,0,sizeof(txbuff)); if(cnt_sequence>=65535) //计数 cnt_sequence=0; else cnt_sequence++; tLen=1+2+(2+1+conLen); //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen/0x100;//H Total Lenth txbuff[len++]=tLen%0x100;//L txbuff[len++]=0;//Multi-Flag ////////////////////////////MsgLen2+MsgID2+MsgContent txbuff[len++]=(2+1+conLen)/0x100;//msgID len + content len txbuff[len++]=(2+1+conLen)%0x100; txbuff[len++]=8193/0x100;//0x20;//H msgID 8193 txbuff[len++]=8193%0x100;//0x04;//L msgID //content txbuff[len++]=StaNums;//Number of Stations for(int i=0;iRegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); // pLink->SetCommStatus(CMST_RX_CNT); m_LastSendTime = GetNowSecond(); PrintLog(LOG_INFORMATION,"ISCS->ATS Send FasInfo MsgID = 0x2004"); // PrtBuf(txbuff,len); } void CZFCasco::IscsAtsScadaInfo() { int conLen=15*4; uint8 txbuff[210]; uint8 len=0,tLen; memset(txbuff,0,sizeof(txbuff)); if(cnt_sequence>=65535) cnt_sequence=0; else cnt_sequence++; tLen=1+2+(2+2+conLen*3); //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen/0x100;//H Total Lenth txbuff[len++]=tLen%0x100;//L txbuff[len++]=0;//Multi-Flag //////////////////////////// txbuff[len++]=(2+2+conLen*3)/0x100;//msgID len + content len txbuff[len++]=(2+2+conLen*3)%0x100; txbuff[len++]=8194/0x100;//0x20;//H msgID 8194 txbuff[len++]=8194%0x100;//0x05;//L msgID txbuff[len++]=(conLen)/0x100;//H msgID txbuff[len++]=(conLen)%0x100;//L msgID //content for(int i=0;i<12+3;i++){ for(int j=0;j<4;j++){ txbuff[len++]=(j+4*i+1)/0x100;//H txbuff[len++]=(j+4*i+1)%0x100;//L txbuff[len++]=2-ScadaZone[i][j];//Status:0-unknown;1-On;2-Off } } pLink->RegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); // pLink->SetCommStatus(CMST_RX_CNT); m_LastSendTime = GetNowSecond(); PrintLog(LOG_INFORMATION,"ISCS->ATS Send ScadaInfo MsgID = 0x2005"); // PrtBuf(txbuff,len); } //ATS-CASCO先高字节-后低字节 void CZFCasco::IscsAtsEmcsInfo() { uint8 conLen=48*3;//风机数 uint8 txbuff[210]; uint8 len=0,tLen; memset(txbuff,0,sizeof(txbuff)); if(cnt_sequence>=65535) cnt_sequence=0; else cnt_sequence++; tLen=1+2+(2+2+conLen/3*4); //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen/0x100;//H Total Lenth txbuff[len++]=tLen%0x100;//L txbuff[len++]=0;//Multi-Flag //////////////////////////// txbuff[len++]=(2+2+conLen/3*4)/0x100;//msgID len + content len txbuff[len++]=(2+2+conLen/3*4)%0x100; txbuff[len++]=8195/0x100;//0x20;//H msgID 8195 txbuff[len++]=8195%0x100;//0x06;//L msgID txbuff[len++]=(conLen/3)/0x100;//H msgID txbuff[len++]=(conLen/3)%0x100;//L msgID //content for(int i=0;iRegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); // pLink->SetCommStatus(CMST_RX_CNT); m_LastSendTime = GetNowSecond(); PrintLog(LOG_INFORMATION,"ISCS->ATS Send EmcsInfo MsgID = 0x2006"); // PrtBuf(txbuff,len); } void CZFCasco::MsgPolling() { uint8 conLen=0; uint8 txbuff[8]; uint16 len=0,tLen; memset(txbuff,0,8); if(cnt_sequence>=65535) cnt_sequence=0; else cnt_sequence++; tLen=1+2+(2+conLen); //7bytes Head txbuff[len++]=m_SysId;//SystemID txbuff[len++]=tLen/0x100;//H Total Lenth txbuff[len++]=tLen%0x100;//L txbuff[len++]=0;//Multi-Flag //////////////////////////// txbuff[len++]=0;//msgID len + content len txbuff[len++]=2;// txbuff[len++]=0x30;//H msgID txbuff[len++]=0x01;//L msgID //content no pLink->RegisterFrm(FRAME_TX_SUC); pTxBuf->Write(txbuff,len); pLink->SetCommStatus(CMST_RX_CNT); m_LastSendTime = GetNowSecond(); // PrintLog(LOG_INFORMATION,"ISCS->ATS Send MsgPolling MsgID = 0x3001"); // PrtBuf(txbuff,len); } uint8 CZFCasco::RxAtsTrainLocation(uint8 *buf) {//ATS 每隔 10 秒发送一次当前的全部列车信息 int i=0,j=0; sint32 rtuno = pLink->GetRtuNo(); //Dir:0上行1下行2未知;Stat bit0计划车bit2-3:00准点10晚点11unknown PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS Location Tcnt=%d",buf[6],buf[7],buf[8]); for(i=0;iPutAYc(rtuno,buf[20+12*i]+buf[19+12*i]*256,buf[10+12*i]+buf[9+12*i]*256); //车次窗编号点——>列车车体号 winHan[buf[20+12*i]+buf[19+12*i]*256]=buf[10+12*i]+buf[9+12*i]*256; //将当前车次窗下的列车车体号记录到winHan[]中 for(j=100;j<1500;j++) {if(winHan[j]>0 && buf[10+12*i]+buf[9+12*i]*256==winHan[j] && j!=buf[20+12*i]+buf[19+12*i]*256) winHan[j]=0; PRawCtrl->PutAYc(rtuno,j,0); //清除上一次当前列车车体号所在的车次窗号的记录 } } return 1; } uint8 CZFCasco::RxAtsBlockInfo(uint8 *buf) {//Block ATS 实时发送 //洞口2-3,6-7,10-11不管 //风井3-4,4-5,5-6,12-13 int i=0,j=0,dnWin=0,upWin=0;//dn-1;up-0 sint32 rtuno = pLink->GetRtuNo(); PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS Block Tcnt=%d",buf[6],buf[7],buf[8]); if(buf[8]==0){//noBlock,reset0 for(i=0;i<20;i++){ PRawCtrl->PutAYc(rtuno,2*i+1,0); PRawCtrl->PutAYc(rtuno,2*i+2,0); PRawCtrl->PutAYx(rtuno,2*i+1,0); PRawCtrl->PutAYx(rtuno,2*i+2,0); } } for(i=0;iPutAYc(rtuno,2*(min(buf[14+8*i],buf[15+8*i]))-buf[13+8*i],buf[10+8*i]+buf[9+8*i]*256); //AI点位号双数记录上行、单数记录下行 值为车体号 PRawCtrl->PutAYx(rtuno,2*(min(buf[14+8*i],buf[15+8*i]))-buf[13+8*i],1); //DI点位号双数记录上行、单数记录下行 值为是否阻塞(1阻塞) } } return 1; } uint8 CZFCasco::RxAtsPlannedTrain(uint8 *buf) {//ATS 链路建立成功主动发送一次,计划有变动ATS主动发送当天计划信息 PrintLog(LOG_INFORMATION,"0x%02x%02xATS->ISCS PlannedTrain TableID%d Tripcnt=%d TrainId%d%d DesID=%d\n", buf[6],buf[7],buf[11]+buf[10]*256,buf[12],buf[14]+buf[13]*256,buf[16]+buf[15]*256,buf[18]+buf[17]*256); int num=0; /* for(int j=0;jISCS PracticalTrain GroupID%d Reccnt=%d\n", buf[6],buf[7],buf[11]+buf[10]*256,buf[13]+buf[12]*256); /* for(int i=0;iISCS DynamicTrain GroupID%d-TrainID%d:%d-SeviceID%d-DesID%d-Dir%d-Type%d-StaID%d-PlatID%d-%c\n", buf[6],buf[7],buf[9]+buf[8]*256,buf[11]+buf[10]*256,buf[13]+buf[12]*256,buf[15]+buf[14]*256,buf[17]+buf[16]*256 ,buf[18],buf[19],buf[20],buf[22]+buf[21]*256,buf[27]); //13*2 Station Platform//预留20车站*2 sint32 rtuno = pLink->GetRtuNo(); switch(buf[27]){//每个车站按2站台YC,到站显示列车编号GroupID,离站=0 case 'a'://2*(StaID-1)+(Dir-1)//dn-1;up-2 PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],buf[9]+buf[8]*256); break; case 'd': PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],0); break; default: PRawCtrl->PutAYc(rtuno,40+2*(buf[20]-1)+buf[18],0); break; } if (((buf[22] + buf[21] * 256 == 1) || (buf[22] + buf[21] * 256 == 2)) && buf[20] != 14 && buf[20] != 15 && buf[20] != 36 && buf[20] != 37 && buf[20] != 39) { PrintLog(LOG_INFORMATION, "ip:%s port:%d \n",redisip,redisport); this->m_popt_train = new CTrainDataOpt; this->m_popt_train->SetSeverAddr(redisip, redisport); TrainsInfo redisdata; memset(&redisdata, 0, sizeof(TrainsInfo)); switch (buf[20]) { case 1:strcpy(redisdata.group, "ELZ"); break; case 2:strcpy(redisdata.group, "ZJJ"); break; case 3:strcpy(redisdata.group, "DSH"); break; case 4:strcpy(redisdata.group, "CYR"); break; case 5:strcpy(redisdata.group, "QPS"); break; case 6:strcpy(redisdata.group, "HJR"); break; case 7:strcpy(redisdata.group, "ZXS"); break; case 8:strcpy(redisdata.group, "JSR"); break; case 9:strcpy(redisdata.group, "NXJ"); break; case 10:strcpy(redisdata.group, "XYR"); break; case 11:strcpy(redisdata.group, "PLR"); break; case 12:strcpy(redisdata.group, "NBL"); break; case 13:strcpy(redisdata.group, "HQS"); break; // case 14:strcpy(redisdata.group, "ZJJD"); break; // case 15:strcpy(redisdata.group, "XJD"); break; case 16:strcpy(redisdata.group, "XCZ"); break; // case 36:strcpy(redisdata.group, "ZJJD_TT"); break; // case 37:strcpy(redisdata.group, "ZJJD_TT"); break; // case 39:strcpy(redisdata.group, "XJD_TT"); break; default: strcpy(redisdata.group, ""); break; } switch (buf[17] + buf[16] * 256) { case 1:strcpy(redisdata.groupend, "ELZ"); break; case 11:strcpy(redisdata.groupend, "ELZ"); break; case 91:strcpy(redisdata.groupend, "ELZ"); break; case 2:strcpy(redisdata.groupend, "ZJJ"); break; case 62:strcpy(redisdata.groupend, "ZJJ"); break; case 61:strcpy(redisdata.groupend, "ZJJ"); break; case 70:strcpy(redisdata.groupend, "ZJJ"); break; case 71:strcpy(redisdata.groupend, "ZJJ"); break; case 3:strcpy(redisdata.groupend, "DSH"); break; case 63:strcpy(redisdata.groupend, "DSH"); break; case 64:strcpy(redisdata.groupend, "HJR"); break; case 65:strcpy(redisdata.groupend, "HJR"); break; case 66:strcpy(redisdata.groupend, "HJR"); break; case 80:strcpy(redisdata.groupend, "HJR"); break; case 81:strcpy(redisdata.groupend, "HJR"); break; case 7:strcpy(redisdata.groupend, "ZXS"); break; case 67:strcpy(redisdata.groupend, "ZXS"); break; case 9:strcpy(redisdata.groupend, "NXJ"); break; case 88:strcpy(redisdata.groupend, "NXJ"); break; case 68:strcpy(redisdata.groupend, "NXJ"); break; case 72:strcpy(redisdata.groupend, "NXJ"); break; case 73:strcpy(redisdata.groupend, "NXJ"); break; case 12:strcpy(redisdata.groupend, "NBL"); break; case 69:strcpy(redisdata.groupend, "NBL"); break; case 13:strcpy(redisdata.groupend, "HQS"); break; case 14:strcpy(redisdata.groupend, "HQS"); break; case 60:strcpy(redisdata.groupend, "XCZ"); break; default: strcpy(redisdata.groupend, ""); break; } redisdata.trainsno = buf[9] + buf[8] * 256; redisdata.srvno = buf[15] + buf[14] * 256; //服务号 redisdata.direction = 0; if (buf[18] == 1) redisdata.direction = 2; if (buf[18] == 2) redisdata.direction = 1; // redisdata.direction = 2 - buf[18]; if (buf[27] == 0x61) { redisdata.state = 1; redisdata.arrivet = buf[23] * 256 * 256 * 256 + buf[24] * 256 * 256 + buf[25] * 256 + buf[26]; redisdata.departuret = 0; } if (buf[27] == 0x64) { redisdata.state = 2; redisdata.arrivet = 0; redisdata.departuret = buf[23] * 256 * 256 * 256 + buf[24] * 256 * 256 + buf[25] * 256 + buf[26]; } redisdata.platlocation = (buf[22] + buf[21] * 256) - 1; redisdata.jumpsta = 0; int redisflag = this->m_popt_train->PutTrainsInfo(redisdata); if (redisflag == 0) PrintLog(LOG_ERROR, "记点数据存入redis失败\n"); if (redisflag == 1) PrintLog(LOG_INFORMATION, "记点数据存入redis成功\n"); if (redisflag == 2) PrintLog(LOG_ERROR, "丢弃此记点数据,由于方向未知\n"); if (redisflag == -1) PrintLog(LOG_ERROR, "redis连接失败\n"); delete this->m_popt_train; this->m_popt_train = NULL; } return 1; } #ifdef __unix extern "C" CProtocol* CreateProtocol(char *defpara) #else extern "C" __declspec(dllexport) CProtocol* CreateProtocol(char *defpara) #endif { CProtocol *pEpv = new CZFCasco; return pEpv; } /* From To MessageID MsgID Content ATS ISCS TrainLocation 0x1001 1+12n ATS ISCS BlockInfo 0x1002 1+8n ATS ISCS PlannedTrainData 0x1003 5+n*(8+16m) ATS ISCS PracticalTrainData 0x1004 6+25n ATS ISCS DynamicTrainData 0x1005 ATS ISCS DataStart 0x1101 2 ATS ISCS DataContent 0x1102 ATS ISCS DataEnd 0x1103 2 ISCS ATS RequestPlannedTrainData 0x2002 2 ISCS ATS RequestPracticalTrainData 0x2003 2 ISCS ATS FASinfo 0x2004 1+StaNums*2 ISCS ATS SCADAinfo 0x2005 2+14*4 ISCS ATS BASinfo 0x2006 2+4n ATS/ISCS ISCS/ATS MessagePolling 0x3001 */