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

📄 jidia2dlg.cpp

📁 2/3前向纠错编码FEC,用VC++写成,(通信新技术及其实验
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// jidia2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "jidia2.h"
#include "jidia2Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJidia2Dlg dialog

CJidia2Dlg::CJidia2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CJidia2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CJidia2Dlg)
	m_display1 = _T("");
	m_display2 = _T("");
	m_display3 = _T("");
    str=_T("");
	strin0=_T("");
	strin1=_T("");
	strin2=_T("");
	m_display = _T("");
	s=_T("");
 s0= _T("");
 s1=_T("");
 s2=_T("");
 s3=_T("");
 s4=_T("");
 sjiama=_T("");

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CJidia2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	
	//{{AFX_DATA_MAP(CJidia2Dlg)
	DDX_Text(pDX, IDC_DISPLAY1, m_display1);
	DDX_Text(pDX, IDC_DISPLAY2, m_display2);
	DDX_Text(pDX, IDC_DISPLAY3, m_display3);
	DDX_Text(pDX, IDC_DISPLAY, m_display);
	DDV_MaxChars(pDX,m_display1,3);
    DDV_MaxChars(pDX,m_display2,5);
    DDV_MaxChars(pDX,m_display3,10);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CJidia2Dlg, CDialog)
	//{{AFX_MSG_MAP(CJidia2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_BIANMA, OnButtonBianma)
	ON_BN_CLICKED(IDC_BUTTON_QINGKONG, OnButtonQingkong)
	ON_BN_CLICKED(IDC_BUTTON_YIMA, OnButtonYima)
	ON_EN_CHANGE(IDC_DISPLAY1, OnChangeDisplay1)
	ON_EN_CHANGE(IDC_DISPLAY2, OnChangeDisplay2)
	ON_EN_CHANGE(IDC_DISPLAY3, OnChangeDisplay3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJidia2Dlg message handlers

BOOL CJidia2Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
/*m_display1 = _T("");
	m_display2 = _T("");
	m_display3 = _T("");
    str=_T("");
	strin0=_T("");
	strin1=_T("");
	strin2=_T("");
	m_display = _T("");
	*/
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CJidia2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CJidia2Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CJidia2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CJidia2Dlg::OnButtonBianma() 
{ 
jisuanstr(); 
	m_display3=str;
	jisuanm_display2();
	m_display2=s;
m_display=m_display+"编码前的二进制信息序列为(MSB-->LSB):         "+m_display3+
"                     经2/3FEC编码后的二进制信息序列为(MSB-->LSB):"+m_display2+"  "+m_display3+"                   ";

	UpdateData(false);

	return;
	// TODO: Add your control notification handler code here
	
}

//DEL void CJidia2Dlg::OnButtonFuyuan() 
//DEL {m_display3=str;
//DEL m_display2=s;
//DEL UpdateData(false);
//DEL 	// TODO: Add your control notification handler code here
//DEL 	
//DEL }

void CJidia2Dlg::OnButtonQingkong() 
{
	m_display=_T("");
	UpdateData(false);// TODO: Add your control notification handler code here
	
}

void CJidia2Dlg::OnButtonYima() 
{
	str1=m_display3;
	str=m_display3;
	jisuanm_display2();
strin=m_display2;
//////判断新码的校验位与给出的校验位的相同与不同
	if(m_display2.GetAt(0)==s.GetAt(0))
		x0=0;else x0=1;//相同为0不同为1
if(m_display2.GetAt(1)==s.GetAt(1))
		x1=0;else x1=1;
if(m_display2.GetAt(2)==s.GetAt(2))
		x2=0;else x2=1;
if(m_display2.GetAt(3)==s.GetAt(3))
		x3=0;else x3=1;
if(m_display2.GetAt(4)==s.GetAt(4))
		x4=0;else x4=1;

if(x0==1&&x1==0&&x2==0&&x3==0&&x4==0)//第1位不同,表示第1位错,并纠错,1位校验位的最高位
{m_scuowei='1';
if(strin.GetAt(0)=='0')
strin.SetAt(0,'1');
else strin.SetAt(0,'0');
}
else if(x0==0&&x1==1&&x2==0&&x3==0&&x4==0)//第2位不同,表示第2位错,并纠错,
{m_scuowei='2';
if(strin.GetAt(1)=='0')
strin.SetAt(1,'1');
else strin.SetAt(1,'0');
}
else if(x0==0&&x1==0&&x2==1&&x3==0&&x4==0)//第3位不同,表示第3位错,并纠错,
{m_scuowei='3';
if(strin.GetAt(2)=='0')
strin.SetAt(2,'1');
else strin.SetAt(2,'0');
}
else if(x0==0&&x1==0&&x2==0&&x3==1&&x4==0)//第4位不同,表示第4位错,并纠错,
{m_scuowei='4';
if(strin.GetAt(3)=='0')
strin.SetAt(3,'1');
else strin.SetAt(3,'0');
}
else if(x0==0&&x1==0&&x2==0&&x3==0&&x4==1)//第5位不同,表示第5位错,并纠错,
{m_scuowei='5';
if(strin.GetAt(4)=='0')
strin.SetAt(4,'1');
else strin.SetAt(4,'0');
}

else if(x0==1&&x1==0&&x2==1&&x3==0&&x4==1)//第1,3,5位不同,表示第6位错,并纠错,
{m_scuowei='6';
if(str1.GetAt(0)=='0')
str1.SetAt(0,'1');
else str1.SetAt(0,'0');
}
else if(x0==1&&x1==1&&x2==1&&x3==1&&x4==1)//第1,2,3,4,5位不同,表示第7位错,并纠错,
{m_scuowei='7';
if(str1.GetAt(1)=='0')
str1.SetAt(1,'1');
else str1.SetAt(1,'0');
}
else if(x0==1&&x1==1&&x2==0&&x3==1&&x4==0)//第1,2,4位不同,表示第8位错,并纠错,
{m_scuowei='8';
if(str1.GetAt(2)=='0')
str1.SetAt(2,'1');
else str1.SetAt(2,'0');
}

else if(x0==0&&x1==1&&x2==1&&x3==0&&x4==1)//第2,3,5位不同,表示第9位错,并纠错,
{m_scuowei='9';
if(str1.GetAt(3)=='0')
str1.SetAt(3,'1');
else str1.SetAt(3,'0');
}
else if(x0==1&&x1==0&&x2==0&&x3==1&&x4==1)//第1,4,5位不同,表示第10位错,并纠错,
{m_scuowei="10";
if(str1.GetAt(4)=='0')
str1.SetAt(4,'1');
else str1.SetAt(4,'0');
}
else if(x0==1&&x1==1&&x2==1&&x3==0&&x4==0)//第1,2,3位不同,表示第11位错,并纠错,
{m_scuowei="11";
if(str1.GetAt(5)=='0')
str1.SetAt(5,'1');
else str1.SetAt(5,'0');
}

else if(x0==0&&x1==1&&x2==1&&x3==1&&x4==0)//第2,3,4位不同,表示第12位错,并纠错,
{m_scuowei="12";
if(str1.GetAt(6)=='0')
str1.SetAt(6,'1');
else str1.SetAt(6,'0');
}
else if(x0==0&&x1==0&&x2==1&&x3==1&&x4==1)//第3,4,5位不同,表示第13位错,并纠错,
{m_scuowei="13";
if(str1.GetAt(7)=='0')
str1.SetAt(7,'1');
else str1.SetAt(7,'0');
}
else if(x0==1&&x1==0&&x2==1&&x3==1&&x4==0)//第1,3,4位不同,表示第14位错,并纠错,
{m_scuowei="14";
if(str1.GetAt(8)=='0')
str1.SetAt(8,'1');
else str1.SetAt(8,'0');
}
else if(x0==0&&x1==1&&x2==0&&x3==1&&x4==1)//第2,4,5位不同,表示第8位错,并纠错,
{m_scuowei="15";
if(str1.GetAt(9)=='0')
str1.SetAt(9,'1');
else str1.SetAt(9,'0');
}
else if(x0==0&&x1==0&&x2==0&&x3==0&&x4==0)//无错
m_scuowei='0';
else m_scuowei=_T("");
//////////////无错
if(m_scuowei=='0')
{sjiama=m_display3;
jiama();
m_display=m_display+"信道传输正确 或 产生不可检错的误码序列!接收序列为:"+m_display2+m_display3+
"              译码结果为:   "+m_display3+"    十六进制结果为:"+sjiama0+"                      ";}
////////////////////无法检错
else if(m_scuowei==_T(""))
{sjiama=m_display3;
jiama();
m_display=m_display+"信道传输产生2位或2位以上错码!超出2/3FEC码纠错范围,不可纠错!译码结果为:"+m_display3+"    十六进制结果为:"+sjiama0;}
////////////////////有错
else {sjiama=str1;
jiama();
m_display=m_display+"信道传输产生1位错码!可纠错!该码位于第"+m_scuowei+"位,译码结果为:"+str1+"   十六进制结果为:"+sjiama0;}
UpdateData(false);

	// TODO: Add your control notification handler code here
	
}

void CJidia2Dlg::OnChangeDisplay1() 
{UpdateData(true);
	// TODO: If this is a RICHEDIT control, the control will not

⌨️ 快捷键说明

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