⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show.cpp

📁 七号信令解码器
💻 CPP
字号:

#include "stdafx.h"
#include "show.h"

CShowMsg* CShowMsgList::Add(unsigned char *msgBuf)
{
	CShowMsg* p=new CShowMsg;
	char temp[800];
	CString str;
	memset(temp,0,800);
	int off=(m_msgType==1)? 0 : 2;//is filt or track;
	if(p->PreProcMsg(msgBuf+off))
	{
		if(memcmp(p->mshowmsg.temp,temp,800)!=0)
		{
			str.Format("msgType:%s,\naddr:%s,\ncause:%s",p->mshowmsg.msgtype,p->mshowmsg.acalladd,p->mshowmsg.cause);
			AfxMessageBox(str);
			delete p;
			return NULL;
		}
		if(m_msgType==2)
		{
			p->mshowmsg.msgtracknum=*((short*)msgBuf);
			POSITION pos=FindTrackNumPos(p->mshowmsg.msgtracknum);
			m_list.InsertAfter(pos,p);
		}
		else m_list.AddTail(p);
		return p;
	}
	else delete p;
	return NULL;
}
int CShowMsgList::AddList(unsigned char *msgMultiBuf)
{
	unsigned short msglen,off;
	unsigned short msgsumlen =(*msgMultiBuf + *(msgMultiBuf+1)*256)+2;
    int i=0;
	int offlen=(m_msgType==1)? 0 : 2;//is filt or track;
	int ncount=0;
	for(off=2;off<msgsumlen&&msgMultiBuf[off]!=0xaa;off+=msglen,i++)
	{
		msglen=((msgMultiBuf[off+offlen] + msgMultiBuf[off+offlen+1]*256)&0xfff)+offlen+2;
		if(Add(&msgMultiBuf[off]))
		{
			SetMaxCount(nMaxCount);//delete head item
			ncount++;
		}
	}
	return ncount;
}

void CShowMsgList::DeleteAllItem()
{
	int ncount=m_list.GetCount();
	for(int i=0;i<ncount;i++)delete m_list.RemoveHead();
}
CShowMsgList& CShowMsgList::operator=(CShowMsgList* pMsgList)
{
	DeleteAllItem();
	(*this)+=pMsgList;
	return *this;
}
CShowMsgList& CShowMsgList::operator+=(CShowMsgList* pMsgList)
{
	nMaxCount=pMsgList->nMaxCount;
	m_msgType=pMsgList->m_msgType;
	int nMax=nMaxCount-this->GetCount();

	int ncount=pMsgList->GetCount();
	if(ncount>nMax)ncount=nMax;
	CShowMsg* pMsg;
	for(int i=0;i<ncount;i++)
	{
		pMsg=new CShowMsg;
		(*pMsg)=pMsgList->GetItemFromIndex(i);
		m_list.AddTail(pMsg);
	}
	return *this;
}
int CShowMsgList::Insert(int nCurSelItem,BOOL bInsertAfter,CShowMsgList &msgList)
{
	int index=GetCount();
	nMaxCount=msgList.nMaxCount;
	m_msgType=msgList.m_msgType;
	int nMax=nMaxCount-this->GetCount();
	if(nCurSelItem<0||nCurSelItem>=GetCount())
	{
		(*this)+=&msgList;
		return index;
	}
	else if(bInsertAfter)
	{
		POSITION pos=m_list.FindIndex(nCurSelItem);
		if(pos==NULL) return -1;
		int ncount=msgList.GetCount();
		if(ncount>nMax)ncount=nMax;
		CShowMsg* pMsg;
		for(int i=0;i<ncount;i++)
		{
			pMsg=new CShowMsg;
			(*pMsg)=msgList.GetItemFromIndex(i);
			pos=m_list.InsertAfter(pos,pMsg);
		}
	}
	else
	{
		POSITION pos=m_list.FindIndex(nCurSelItem);
		if(pos==NULL) return -1;
		int ncount=msgList.GetCount();
		if(ncount>nMax)ncount=nMax;
		CShowMsg* pMsg;
		for(int i=0;i<ncount;i++)
		{
			pMsg=new CShowMsg;
			(*pMsg)=msgList.GetItemFromIndex(i);
			pos=m_list.InsertBefore(pos,pMsg);
		}
	}
	return (bInsertAfter) ? (nCurSelItem+1): nCurSelItem;
}
CString CShowMsgList::GetLengthText()
{
	CString strs[12];
	CString str;
	CString strHead="索引  链路     时间       后向  前向     DPC      OPC      消息类型        号码          原因";
	for(int i=0;i<m_list.GetCount()&&i<1000;i++)
	{
		if(i%10==0)
		{
			str+="\r\n";
			str+=strHead;
			str+="\r\n";
		}
		GetMsgStr(strs,i);
		for(int j=0;j<12;j++)
		{
			str+=strs[j];
			str+="  ";
			if(j>6&&strs[j].GetLength()<20)
			{
				for(int k=0;k<20-strs[j].GetLength();k++)str+="  ";
			}
		}
		str+="\r\n";
	}
	return str;
}
int CShowMsgList::GetMsgStr(CString *strs,int index)
{
	CShowMsg* showMsg=GetItemFromIndex(index);
	strs[0].Format("%04d",index);
	strs[1].Format("%03d",showMsg->mshowmsg.linkid/2);
	strs[2].Format("%02d:%02d:%02d.%03d",showMsg->mshowmsg.timeofm/60,showMsg->mshowmsg.timeofm%60,showMsg->mshowmsg.timeofs/1000,showMsg->mshowmsg.timeofs%1000);
	strs[3].Format("%1d.%02xh",showMsg->mshowmsg.bib,showMsg->mshowmsg.bsn);
	strs[4].Format("%1d.%02xh",showMsg->mshowmsg.fib,showMsg->mshowmsg.fsn);
	unsigned char *p=showMsg->mshowmsg.dpc;
	int pc=p[0]+p[1]*256+p[2]*256*256;
	strs[5].Format("%06xh",pc);
	p=showMsg->mshowmsg.opc;
	pc=p[0]+p[1]*256+p[2]*256*256;
	strs[6].Format("%06xh",pc);
	strs[7].Format("%04xh",showMsg->mshowmsg.cic);

	strs[8]=showMsg->mshowmsg.msgtype;
	strs[9]=showMsg->mshowmsg.acalladd;
	strs[10]=showMsg->mshowmsg.cause;
	if(m_msgType==2)//track
	{
		return (showMsg->mshowmsg.msgtracknum%2) ? (showMsg->mshowmsg.linkid%2) : 2+(showMsg->mshowmsg.linkid%2);
	}
	return showMsg->mshowmsg.linkid%2;
}
CString CShowMsgList::GetMsgStr(int index)
{
	CShowMsg* showMsg=GetItemFromIndex(index);
	CString str,msgstr;
	str.Format("index:%04d",index);
	msgstr+=str+"\r\n";
	str.Format("Link:%03d",showMsg->mshowmsg.linkid/2);
	msgstr+=str+"\r\n";
	str.Format("Time:%02d:%02d:%02d.%03d",showMsg->mshowmsg.timeofm/60,showMsg->mshowmsg.timeofm%60,showMsg->mshowmsg.timeofs/1000,showMsg->mshowmsg.timeofs%1000);
	msgstr+=str+"\r\n";
	str.Format("BSN :%1d.%02xh",showMsg->mshowmsg.bib,showMsg->mshowmsg.bsn);
	msgstr+=str+"\r\n";
	str.Format("FSN :%1d.%02xh",showMsg->mshowmsg.fib,showMsg->mshowmsg.fsn);
	msgstr+=str+"\r\n";
	unsigned char *p=showMsg->mshowmsg.dpc;
	int pc=p[0]+p[1]*256+p[2]*256*256;
	str.Format("DPC :%06xh",pc);
	msgstr+=str+"\r\n";
	p=showMsg->mshowmsg.opc;
	pc=p[0]+p[1]*256+p[2]*256*256;
	str.Format("OPC :%06xh",pc);
	msgstr+=str+"\r\n";
	str.Format("CIC :%04xh",showMsg->mshowmsg.cic);
	msgstr+=str+"\r\n\r\n消息类型:  ";

	str=showMsg->mshowmsg.msgtype;
	msgstr+=str+"\r\n\r\n呼叫地址:  ";
	str=showMsg->mshowmsg.acalladd;
	msgstr+=str+"\r\n\r\n原因:  ";
	str=showMsg->mshowmsg.cause;
	msgstr+=str+"\r\n";
	if(m_msgType==2)//track
	{
		return (showMsg->mshowmsg.msgtracknum%2) ? (showMsg->mshowmsg.linkid%2) : 2+(showMsg->mshowmsg.linkid%2);
	}
	return msgstr;
}

unsigned char * CShowMsgList::GetMsgBufFromIndex(int id)
{
	POSITION pos=m_list.FindIndex(id);
	if(pos) return m_list.GetAt(pos)->mshowmsg.pBuf;
	return NULL;
}
CShowMsg* CShowMsgList::GetItemFromIndex(int id)
{
	POSITION pos=m_list.FindIndex(id);
	if(pos) return m_list.GetAt(pos);
	return NULL;
}
BOOL CShowMsgList::DeleteItemFromIndex(int id)
{
	POSITION pos=m_list.FindIndex(id);
	if(pos==NULL)return FALSE;
	delete m_list.GetAt(pos);
	m_list.RemoveAt(pos);
	return TRUE;
}
CShowMsgList::~CShowMsgList()
{
	DeleteAllItem();
}
CShowMsgList::CShowMsgList()
{
	nMaxCount=5000;
	m_msgType=-1;
}
int CShowMsgList::GetMsgType()
{
	return m_msgType;
}
void CShowMsgList::SetMsgType(int msgType)
{
	m_msgType=msgType;
}
void CShowMsgList::SetMaxCount(int v)
{
	if(v>0)nMaxCount=v;
	if(m_list.GetCount()>nMaxCount)
	{
		int ncount=m_list.GetCount()-nMaxCount;
		for(int i=0;i<ncount;i++)
		{
			delete m_list.RemoveHead();
		}
	}
}
int CShowMsgList::GetCount()
{
	return m_list.GetCount();
}
/*******************************************************************
			msg file format
file have 20 block,every block len is 0xffff,block struct define like follow:
				system
5 file flag  2 file block flag (ffff)2 block len  2 msg len 2 cannel 4 msg time
             time: 1 2 minute 3 4 millonsecond
				instructment
5 file flag  2 file block flag (ffff)2 block len 5 save file time 2 msg len 1 cannel 5 msg time
			 block len=0x2000  block count =buf[5+0x2000-1](0-7), 
             time: 1 hour 2 minute 3 second 4,5 millonsecond
区别:仪表每块分为8个子块.注意时间上的区别
********************************************************************/

void CShowMsgList::SerializeMsgFile(CArchive& ar)
{
	BYTE *pBuf=new BYTE[0xffff];
	BYTE csFlag[]="GSM82";
	int len,sumlen=0,nblock=0;
	if (ar.IsStoring())
	{
		pBuf[0]=0xff;
		pBuf[1]=0xff;
		BYTE *pMsg;
		ar.Write(csFlag,5);
		for(POSITION pos=m_list.GetHeadPosition();pos!=NULL&&nblock<20;)
		{
			pMsg=m_list.GetNext(pos)->mshowmsg.pBuf;
			len=pMsg[0]+pMsg[1]*256+2;
			memcpy(&pBuf[4+sumlen],pMsg,len);
			sumlen+=len;
			if(sumlen>0xffff-300||pos==NULL)
			{
				memset(&pBuf[5+sumlen],0,0xffff-sumlen-5);
				pBuf[4+sumlen]=0xaa;
				pBuf[2]=sumlen%256;
				pBuf[3]=sumlen/256;
				ar.Write(pBuf,0xffff);
				sumlen=0;
				nblock++;
			}
		}
	}
	else
	{
		CString str="GSM08";
		ar.Read(csFlag,5);
		if(str==csFlag)
		{
			while(1)
			{
				sumlen=ar.Read(pBuf,0xffff);
				if(sumlen>0)AddList(&pBuf[2]);
				if(sumlen!=0xffff)break;
			}
		}
	}
	delete pBuf;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -