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

📄 pager.cpp

📁 reed solomon编码/解码工具
💻 CPP
字号:
// PageR.cpp : implementation file
//

#include "stdafx.h"
#include "dlg.h"
#include "PageR.h"
#include "common.h"

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

extern Mapping errors,erasures;
extern unsigned char message[msgLEN], code[codeLEN];
extern CString msg;
extern int parityNum;
/////////////////////////////////////////////////////////////////////////////
// CPageR dialog


CPageR::CPageR(CWnd* pParent /*=NULL*/)
	: CDialog(CPageR::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPageR)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CPageR::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageR)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageR, CDialog)
	//{{AFX_MSG_MAP(CPageR)
	ON_BN_CLICKED(IDC_BUTTON_Err, OnBUTTONErr)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageR message handlers

BOOL CPageR::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rc(0, 0, 0, 0);
	
	GetParent()->GetClientRect(&rc);
	((CTabCtrl*)GetParent())->AdjustRect(false, &rc); 
	
	MoveWindow(&rc);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPageR::OnBUTTONErr() 
{
	// TODO: Add your control notification handler code here
	
	/* Introduce a byte error at LOC */
	int n = errors.Count();
	for (int i=0; i<n; i++) {
		code[errors.getKey(i) -1] ^= errors.getValue(i);
	}
	n = erasures.Count();
	for (i=0; i<n; i++) {
		code[erasures.getKey(i) -1] ^= erasures.getValue(i);
	}

	CString str;
	str.Empty();
	int len = msg.GetLength();

	for (i = 0; i < len; i++) {
		message[i] = code[i];
		CString temp;
		temp.Empty();
		temp.Format("%#x", code[i]);
		str += temp;
		if ((i+1)%6 == 0) {
			str += "\r\n";
		}else {
			str += " ";
		}
	}
	CEdit * pEd = (CEdit*)this->GetDlgItem(IDC_EDIT_BINARY);
	pEd->SetWindowText(str);
	pEd = (CEdit*)this->GetDlgItem(IDC_EDIT_TEXT);
	str = CString(message);
	pEd->SetWindowText(str);
}

void CPageR::Correct()
{
	CString str;
	str.Empty();
	CEdit * pEd = (CEdit*)this->GetDlgItem(IDC_EDIT_CODE);

	if (erasures.Count() + 2 * errors.Count() > parityNum) {
		str = "Cannot handle so many errors!!!";
		pEd->SetWindowText(str);
		return;
	}
	int msglen = msg.GetLength();
	int ML = msglen + parityNum;

	int size = erasures.Count();
	for (int i = 0; i < size; i++)
		erasures.setKey(i, ML-erasures.getKey(i));

	decode_data(code, ML);

	/* check if syndrome is all zeros */
	if (check_syndrome () != 0) {
		if (correct_errors_erasures (code, ML))
			str = CString(LPCTSTR(code), msglen);
		else
			str = "Cannot handle so many errors!!!";
	}
	pEd->SetWindowText(str);
}

⌨️ 快捷键说明

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