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

📄 receiveinfo.cpp

📁 一个canbus通讯软件源代码
💻 CPP
字号:
// ReceiveInfo.cpp: implementation of the CReceiveInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "test.h"
#include "ReceiveInfo.h"



#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

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

CReceiveInfo::CReceiveInfo()
{

	m_strTagID="";
	m_dwordReaderID=0;
	m_lgCount=0;
	m_tmLastTime.GetTime();
}

CReceiveInfo::~CReceiveInfo()
{

}

BOOL CReceiveInfo::SetInfo(VCI_CAN_OBJ constFrameinfo)
{
	CString strTempTagID="";
	CString strTempChange;
	CString str,str1,tempstrerro,tmpstr;
    m_wordMax=0;
	m_wordMin=0;
	m_wordInterval=0;



    if(constFrameinfo.DataLen>8)
		constFrameinfo.DataLen=8;
	for(int j=0;j<constFrameinfo.DataLen;j++)
					{
						strTempChange.Format("%02x",constFrameinfo.Data[j]);
						strTempTagID+=strTempChange;
					}
	m_strTagID=strTempTagID;
	DWORD wordtemp=constFrameinfo.ID;
	m_dwordReaderID=wordtemp>>18;
	if (m_dwordReaderID==0)
	{
		str="";
		str1="";
		for(int j=0;j<8;j++)
		{
			tempstrerro.Format("%02x",constFrameinfo.Data[j]);
			str+=tempstrerro;
		}
		for( j=0;j<3;j++)
		{
			tempstrerro.Format("%02x",constFrameinfo.Reserved[j]);
			str1+=tempstrerro;
		}
		tmpstr.Format("ID:\t%d\nTimeStamp:\t%d\nTimeFlag:\t%d\nSendType:\t%d\nRemoteFlag:\t%d\n\
ExternFlag:\t%d\nDataLen:\t%d\nData:\t%s\nReserved:\t%s\n",constFrameinfo.ID,constFrameinfo.TimeStamp,
		constFrameinfo.TimeFlag,constFrameinfo.SendType,constFrameinfo.RemoteFlag,constFrameinfo.ExternFlag,
		constFrameinfo.DataLen,str,str1);
	WriteErroLog(tmpstr);
	}


	m_lgCount=1;
	m_tmLastTime=CTime::GetCurrentTime();
	m_tmFirstTime=m_tmLastTime;
	if (constFrameinfo.ID & 128)
		m_nstate=1;
	else
	    m_nstate=0;
	m_bShow=true;
	return TRUE;


}

BOOL CReceiveInfo::FindAndChange(VCI_CAN_OBJ constFrameinfo)
{
	CString str,str1,tempstrerro,tmpstr;
	CString strTempTagID="";
	CString strTempChange;
	DWORD dwordtempID;
	CTime timetemp;
	CTimeSpan timetemp2;
//	LONGLONG longsum; 
	if(constFrameinfo.DataLen>8)
		constFrameinfo.DataLen=8;
	for(int j=0;j<constFrameinfo.DataLen;j++)
	{
		 strTempChange.Format("%02x",constFrameinfo.Data[j]);
		 strTempTagID+=strTempChange;
	}
	dwordtempID=(DWORD)constFrameinfo.ID>>18;





	if (strTempTagID.Compare(m_strTagID)==0 && dwordtempID==m_dwordReaderID)
	{
		m_lgCount++;
	
		timetemp=CTime::GetCurrentTime();
		timetemp2=timetemp - m_tmLastTime;
		m_wordInterval=timetemp2.GetTotalSeconds();
		m_tmLastTime=timetemp;
		if (m_wordInterval>m_wordMax)
			m_wordMax=m_wordInterval;
		
		if (m_wordMin==0 || m_wordInterval<m_wordMin)
			m_wordMin=m_wordInterval;

		if (constFrameinfo.ID & 128)
			m_nstate=1;
		else
			m_nstate=0;
		m_bShow=true;






		return true;
	} 
	else
	{
		return false;
	}

}

void CReceiveInfo::WriteErroLog(CString conststrerro)
{
		CStdioFile   file;
		CString      filepath;
		CString   filestr;
		CString  strtemp;
		char   szBuffer[MAX_PATH];
		int    itemp;
         CTime  TimeTemp;
		 TimeTemp=CTime::GetCurrentTime();
		 GetModuleFileName(AfxGetInstanceHandle(), szBuffer, MAX_PATH); 
		filepath=szBuffer;
		itemp=filepath.ReverseFind('\\');
		filepath.Format("%s\\ErroReceive.txt",filepath.Left(itemp));
		if(   !file.Open(filepath,CFile::modeReadWrite) )  
		{   
			if (!file.Open(filepath,CFile::modeCreate|CFile::modeWrite))
			{
				AfxMessageBox("can   not   open   file!");   
			 return; 
			}
			   
		}   
		strtemp=TimeTemp.Format( "%c" );

        filestr.Format("%sDay:%s\n\n\n",conststrerro,strtemp);
	    file.SeekToEnd();
		file.WriteString(filestr);   
  
		 file.Close();

}

⌨️ 快捷键说明

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