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

📄 数据分析器dlg.cpp

📁 数据结构分析工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		charmove(m_c,prebitnum,data,charnum);
	}

	if(k%8)
	{
		charmove(0,prebitnum,data,charnum);
	}

	if(rebitnum>0)
	{
		charmove(0,rebitnum,data,charnum);
		m_c = GetBit(reservertemp,0,rebitnum-1);
	}

}




void CMyDlg::OnAnalyse() 
{
	// TODO: Add your control notification handler code here

	int pos;
	int count;
	int width;
	int type;
	int charnum;
	CString str;
	CString text;
	CString dtext;
	CString hextext;
	CString bintext;

	unsigned long ltemp;

	unsigned char data[100];

	pos = GetFilepos();
	
	m_file = fopen(m_path,"rb");
	if(m_file == NULL)
	{
		return;
	}
	/*定位文件位置*/
	fseek(m_file,pos+m_start,SEEK_SET);


	/*获取行数*/
	count = m_Grid.GetRowCount();

	m_k = 0;
	for(int i=1;i<count;i++)
	{

		/*获取当前行的位数*/
		str = m_Grid.GetItemText(i,3);
		width = atoi(str);

		str = m_Grid.GetItemText(i,2);
		type = atoi(str);

		if(width > 0 && type > 0)
		{

			/*从文件中读位数*/
			GetData(data,width,type);

			

			charnum = width/8;
			if(width%8)
			{
				charnum +=1;
			}

			text.Empty();
			dtext.Empty();
			hextext.Empty();
			bintext.Empty();
			ltemp = 0;
			for(int j=0;j<charnum;j++)
			{
				str.Format("%c",data[j]);
				text+=str;

				if(charnum<=8)
				{
					ltemp = (ltemp<< 8) | data[j];
				

					str.Format("%02X ",data[j]);
					hextext+=str;

					str.Format("%d%d%d%d%d%d%d%d ",(data[j]&0x80)>>7,
						(data[j]&0x40)>>6,(data[j]&0x20)>>5,(data[j]&0x10)>>4,(data[j]&0x08)>>3,
						(data[j]&0x04)>>2,(data[j]&0x02)>>1,(data[j]&0x01));
					bintext+=str;
				}
			}

			dtext.Format("%d",ltemp);

			m_Grid.SetItemText(i,4,text);
			m_Grid.SetItemText(i,5,dtext);
			m_Grid.SetItemText(i,6,hextext);
			m_Grid.SetItemText(i,7,bintext);
		}
	}

	m_Grid.Invalidate();
	fclose(m_file);
}

int CMyDlg::GetFilepos()
{
	int x,y;
	int temp;
	int row,col;
	temp = (3*SHOWLINE_NUM) +2;
	m_datactr.GetSel(x,y);

	row =  x/temp;
	col = ((x%temp)%(3*SHOWLINE_NUM))/3;


	x = row * SHOWLINE_NUM + col;

	return x;

}

int CMyDlg::GetFilepos(int & len)
{
	int x,y;
	int temp;
	temp = (3*SHOWLINE_NUM) + 2;
	m_datactr.GetSel(x,y);

	x = (x/temp)*SHOWLINE_NUM + ((x%temp)%(3*SHOWLINE_NUM))/3;
	y = (y/temp)*SHOWLINE_NUM + ((y%temp)%(3*SHOWLINE_NUM))/3;

	len =  y-x;
	return x;

}

void CMyDlg::DataSave(CString filename)
{

	FILE *fp;
	int count;
	CString str;
	CString text;
	/*打开文件*/

	fp = fopen(filename,"w+");
	if(fp == NULL)
	{
		AfxMessageBox("creat file fail");
		return;
	}

	count = m_Grid.GetRowCount();

	for(int i=1;i<count;i++)
	{
		str= m_Grid.GetItemText(i,1);

		text.Empty();

		text +=str;

		str = m_Grid.GetItemText(i,2);
		text +="," + str;

		str = m_Grid.GetItemText(i,3);
		text +="," + str;

		if(!str.IsEmpty())
		{
			fprintf(fp,"%s\n",text);
		}

	}	

	fclose(fp);
}

void CMyDlg::DataLoad(CString filename)
{
	FILE *fp;
	CString str;
	
	int index;
	int i;

	CString text;
	/*打开文件*/

	fp = fopen(filename,"r+");
	if(fp == NULL)
	{
		AfxMessageBox("open file fail");
		return;
	}


	/*删除所有行*/
	while(m_Grid.GetRowCount()>1)
	{
		m_Grid.DeleteRow(1);
	}

	i=1;

	while(!feof(fp))
	{
		fscanf(fp,"%s\n",str);

		text.Format("%d",i);
		
		m_Grid.InsertRow(text,-1);
		text.Format("%s",str);

		index = text.Find(",",0);
		m_Grid.SetItemText(i,1,text.Left(index));

		text.Delete(0,index+1);
		index = text.Find(",",0);
		m_Grid.SetItemText(i,2,text.Left(index));

		text.Delete(0,index+1);
		m_Grid.SetItemText(i,3,text);


		m_Grid.SetItemText(i,4,"");
		m_Grid.SetItemText(i,5,"");
		m_Grid.SetItemText(i,6,"");
		m_Grid.SetItemText(i,7,"");
		i++;		
	}

	m_Grid.InsertRow("",-1);
	m_Grid.SetRowHeight(i,m_Grid.GetRowHeight(1));

	m_Grid.Invalidate();
	
	
	fclose(fp);
}

void CMyDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	DataSave("c://text.txt");
}

void CMyDlg::OnLoad() 
{
	// TODO: Add your control notification handler code here
	DataLoad("c://text.txt");
}

void CMyDlg::Onbrower2() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(true);
	if(dlg.DoModal()==IDOK)
	{
		m_datafile = dlg.GetPathName();
		this->UpdateData(false);
	}
}

void CMyDlg::OnOpen2() 
{
	// TODO: Add your control notification handler code here
	if(m_datafile.IsEmpty())
	{
		return;
	}

	DataLoad(m_datafile);
}

void CMyDlg::OnSave() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(true);
	if(m_datafile.IsEmpty())
	{
		AfxMessageBox("请输入保存路径");
		return;
	}
	DataSave(m_datafile);
}

void CMyDlg::OnAddline() 
{
	// TODO: Add your control notification handler code here
	int nRow = m_Grid.GetFocusCell().row;
    if (nRow >= 0)
    {
	    m_Grid.InsertRow("", nRow);	
		m_Grid.SetRowHeight(nRow,m_Grid.GetRowHeight(nRow-1));
	    m_Grid.Invalidate();
    }
	else
	{
		m_Grid.InsertRow("", -1);
		m_Grid.SetRowHeight(m_Grid.GetRowCount()-1,m_Grid.GetRowHeight(1));
		m_Grid.Invalidate();
	}
}

void CMyDlg::OnDeleteline() 
{
	// TODO: Add your control notification handler code here
	int nRow = m_Grid.GetFocusCell().row;
    if (nRow >= 0)
    {
		m_Grid.DeleteRow(nRow);
		m_Grid.Invalidate();
    }
}

unsigned char CMyDlg::GetBit(unsigned char c, int s, int e)
{
	unsigned char temp;

	unsigned char t;

	t = 0;

	for(int i=s;i<e;i++)
	{
		t+=1<<i;
	}

	temp = c & t;

	temp = temp >> s;

	return temp;
}

void CMyDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CString str;
	
	
//	str.Format("%02x",GetBit(0x1F,0,6));
	str.Format("%02x",GetFilepos());
	AfxMessageBox(str);
}

void CMyDlg::leftmove(unsigned char * data,int bitnum)
{
	unsigned int temp;

	temp = 0;
	temp = (temp << 8) | data[0];
	temp = (temp << 8) | data[1];
	temp = (temp << 8) | data[2];
	temp = (temp << 8) | data[3];

	temp = temp << bitnum;

	data[0] = (temp & 0xFF000000) >> 24;
	data[1] = (temp & 0x00FF0000) >> 16;
	data[2] = (temp & 0x0000FF00) >> 8;
	data[3] = (temp & 0x000000FF);

	return ;
}
void CMyDlg::rightmove(unsigned char * data,int bitnum)
{
	unsigned int temp;

	temp = 0;
	temp = (temp << 8) | data[0];
	temp = (temp << 8) | data[1];
	temp = (temp << 8) | data[2];
	temp = (temp << 8) | data[3];

	temp = temp >> bitnum;

	data[0] = (temp & 0xFF000000) >> 24;
	data[1] = (temp & 0x00FF0000) >> 16;
	data[2] = (temp & 0x0000FF00) >> 8;
	data[3] = (temp & 0x000000FF);

	return ;
}
void CMyDlg::GetData(unsigned char *data, int bitnum, int type)
{
	/*如果之前有从文件中读出,则直接从m_cc[]数组中 获取 bitnum 位数据*/
	if(m_k == 0)
	{
		memset(m_cc,0,4);
		memset(data,0,4);

		fread(m_cc,type,1,m_file);
		memcpy(data,m_cc,type);

		if(bitnum%8)
		{
			rightmove(data,8 - (bitnum%8));
		}

		m_k = type * 8 - bitnum;
		leftmove(m_cc,bitnum);
		return;
	}
	else if(m_k > 0)
	{
		if(m_k < bitnum)
		{
			AfxMessageBox("数据格式定义出错");
			return;
		}
		memset(data,0,4);
		memcpy(data,m_cc,type);

		if(bitnum%8)
		{
			rightmove(data,8 - (bitnum%8));
		}

		m_k -= bitnum;
		leftmove(m_cc,bitnum);		
	}

}

#if 0
/* CRC 校验函数
*  采用CCITT推荐的16位x16+x12+x5+1(0x1021)。
*  生成2字节的CRC校验和(低字节在前,高字节在后)
*/
UINT16 CRC_verify(UINT8 *P, UINT8 len)	
{

⌨️ 快捷键说明

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