📄 rsdlg.cpp
字号:
// RSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test.h"
#include "RSDlg.h"
#include "EnDe_Code.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRSDlg dialog
CRSDlg::CRSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRSDlg)
m_ResData = _T("");
m_RSCode = _T("");
//}}AFX_DATA_INIT
data=NULL;
}
void CRSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRSDlg)
DDX_Control(pDX, IDC_EDIT_RSCODE, m_edCode);
DDX_Text(pDX, IDC_EDIT_RESDATA, m_ResData);
DDX_Text(pDX, IDC_EDIT_RSCODE, m_RSCode);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRSDlg, CDialog)
//{{AFX_MSG_MAP(CRSDlg)
ON_BN_CLICKED(IDC_BUTTON_RSCODE, OnButtonRscode)
ON_BN_CLICKED(IDC_BUTTON_INITDATA, OnButtonInitdata)
ON_BN_CLICKED(IDC_BUTTON_RSDECODE, OnButtonRsdecode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRSDlg message handlers
void CRSDlg::OnButtonRscode()
{
// TODO: Add your control notification handler code here
if(!data)
return ;
CEnDe_Code code;
code.encode(data);
CString lineno;
m_RSCode.Empty();
for(int i=1;i<NN+2;i++)
{
// TRACE("data[%d]:%d\n",i,data[i-1]);
m_RSCode+=ByteToBit(data[i-1]);
if(i%4==0)
{
lineno.Format(" %d\r\n",i/4);
m_RSCode+=lineno;
}
}
UpdateData(FALSE);
// free(data);
// data=NULL;
}
void CRSDlg::OnButtonInitdata()
{
// TODO: Add your control notification handler code here
CString lineno;
data=(BYTE *)malloc(sizeof(BYTE)*(NN+1));
if(!data) return ;
m_ResData.Empty();
for(int i=1;i<KK+1;i++)
{
data[i-1]=i%255;
m_ResData+=ByteToBit(data[i-1]);
if(i%4==0)
{
lineno.Format(" %d\r\n",i/4);
m_ResData+=lineno;
}
}
// for(i=KK;i<NN+1;i++)
// data[i]=0;
UpdateData(FALSE);
}
CString CRSDlg::ByteToBit(BYTE byte)
{
BYTE mask=128;
CString bits;
bits="";
for(int i=0;i<8;i++)
{
if(byte&mask)
bits+="1";
else
bits+="0";
mask>>=1;
// TRACE("mask:%\n",mask);
}
bits+=" ";
return bits;
}
void CRSDlg::OnButtonRsdecode()
{
// TODO: Add your control notification handler code here
if(data==NULL) return;
ReceiveData();
CEnDe_Code code;
code.decode(data);
CString lineno;
m_RSCode="";
UpdateData(FALSE);
Sleep(2000);
for(int i=1;i<NN+2;i++)
{
TRACE("data[%d]:%d\n",i,data[i-1]);
m_RSCode+=ByteToBit(data[i-1]);
if(i%4==0)
{
lineno.Format(" %d\r\n",i/4);
m_RSCode+=lineno;
}
}
UpdateData(FALSE);
}
void CRSDlg::ReceiveData()
{
int i,j;
CString strLine;
TCHAR szLine[MAX_PATH];
for(i=0;i<NN+1;i++)
data[i]=0;
UpdateData(TRUE);
for(i=0;i<64;i++)
{
strLine="";
m_edCode.GetLine(i,szLine);
strLine=szLine;
for(j=0;j<4;j++)
{
data[i*4+j]=BitsToByte(strLine.Mid(9*j,8));
TRACE("%s\n",strLine.Mid(9*j,8));
}
}
}
BYTE CRSDlg::BitsToByte(CString bits8)
{
BYTE byte=0;
BYTE mask=128;
for(int i=0;i<8;i++)
{
if(bits8.GetAt(i)=='1')
byte|=mask;
mask>>=1;
}
return byte;
}
BOOL CRSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CEdit *pWnd=(CEdit *)GetDlgItem(IDC_EDIT_RESDATA);
pWnd->SetReadOnly(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -