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

📄 pam编码器dlg.cpp

📁 PCM编码器:实现每秒8000取样。保存为EXCEL和TXT文件
💻 CPP
字号:
// pam编码器Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "pam编码器.h"
#include "pam编码器Dlg.h"
#include"stdio.h"
#include"iomanip.h"
#include"math.h"
#include"time.h"
#include"fstream.h"
#include"iostream.h"
#include <sys/types.h>
#include <sys/timeb.h>
int code1[9];

#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()

/////////////////////////////////////////////////////////////////////////////
// CPamDlg dialog

CPamDlg::CPamDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPamDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPamDlg)
	a=0.0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPamDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPamDlg)
	DDX_Text(pDX, IDC_EDIT1, a);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPamDlg, CDialog)
	//{{AFX_MSG_MAP(CPamDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
	ON_COMMAND(ID_MENUITEM32772, OnMenuitem32772)
	ON_COMMAND(ID_MENUITEM32773, OnMenuitem32773)
	ON_COMMAND(ID_MENUITEM32775, OnMenuitem32775)
	ON_COMMAND(ID_MENUITEM32774, OnMenuitem32774)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPamDlg message handlers

BOOL CPamDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
		CMenu menu;
	menu.LoadMenu(IDR_MENU1);   
    SetMenu(&menu);
	menu.Detach();  

	// 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
    //CEdit::IDC_EDIT1.SetWindowText("");
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPamDlg::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 CPamDlg::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 CPamDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPamDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
	GetDlgItem(IDC1)->SetWindowText("时间t");
    GetDlgItem(IDC2)->SetWindowText("时间");
    GetDlgItem(IDC_3)->SetWindowText("当前为编码操作每秒取值8000个");
	
}

void CPamDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(false);

	GetDlgItem(IDC1)->SetWindowText("输入一个8位码");
	GetDlgItem(IDC2)->SetWindowText("二进制码");
    GetDlgItem(IDC_3)->SetWindowText("当前为解码操作");
}
void dlm(int n)          //段落码
{
switch(n)
{
case 0:code1[1]=0;code1[2]=0;code1[3]=0;break;
case 1:code1[1]=0;code1[2]=0;code1[3]=1;break;
       case 2:code1[1]=0;code1[2]=1;code1[3]=0;break;
case 3:code1[1]=0;code1[2]=1;code1[3]=1;break;
       case 4:code1[1]=1;code1[2]=0;code1[3]=0;break;
case 5:code1[1]=1;code1[2]=0;code1[3]=1;break;
       case 6:code1[1]=1;code1[2]=1;code1[3]=0;break;
case 7:code1[1]=1;code1[2]=1;code1[3]=1;break;
default:break;
}
}
void dnm(int x,int m,int n)       //段内码
{
int l=(x-m)/n;
switch(l)
{
case 0:code1[4]=0;code1[5]=0;code1[6]=0;code1[7]=0;break;
case 1:code1[4]=0;code1[5]=0;code1[6]=0;code1[7]=1;break;
       case 2:code1[4]=0;code1[5]=0;code1[6]=1;code1[7]=0;break;
case 3:code1[4]=0;code1[5]=0;code1[6]=1;code1[7]=1;break;
       case 4:code1[4]=0;code1[5]=1;code1[6]=0;code1[7]=0;break;
case 5:code1[4]=0;code1[5]=1;code1[6]=0;code1[7]=1;break;
       case 6:code1[4]=0;code1[5]=1;code1[6]=1;code1[7]=0;break;
case 7:code1[4]=0;code1[5]=1;code1[6]=1;code1[7]=1;break;
       case 8:code1[4]=1;code1[5]=0;code1[6]=0;code1[7]=0;break;
case 9:code1[4]=1;code1[5]=0;code1[6]=0;code1[7]=1;break;
       case 10:code1[4]=1;code1[5]=0;code1[6]=1;code1[7]=0;break;
case 11:code1[4]=1;code1[5]=0;code1[6]=1;code1[7]=1;break;
       case 12:code1[4]=1;code1[5]=1;code1[6]=0;code1[7]=0;break;
case 13:code1[4]=1;code1[5]=1;code1[6]=0;code1[7]=1;break;
       case 14:code1[4]=1;code1[5]=1;code1[6]=1;code1[7]=0;break;
case 15:code1[4]=1;code1[5]=1;code1[6]=1;code1[7]=1;break;
       default:break;
}
}

void CPamDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(a<0.0)MessageBox("请输入大于0的数");

long int c,temp;char *tmpbuf;
time_t Nowtime;
Nowtime=time(0);CString str,str1;CString str2,str3;
CButton *pBtn1= (CButton *)GetDlgItem( IDC_RADIO3 ) ; 
CButton *pBtn2= (CButton *)GetDlgItem( IDC_RADIO4 ) ; 


	for(int i=0;i<a*8000;i++)    
     
     {
	 




	  if(pBtn1->GetCheck() == 1)
		 temp=cos(Nowtime+i/10.0)*128*16;
       if(pBtn2->GetCheck() == 1)
         temp=sin(Nowtime+i/10.0)*128*16;
      if(temp>0) 
       code1[0]=1;
      else     {code1[0]=0;temp=fabs(temp);}
      if(temp>=0 && temp<16) {dlm(0);dnm(temp,0,1);}
      if(temp>=16 && temp<32) {dlm(1);dnm(temp,16,1);}
      if(temp>=32 && temp<64) {dlm(2);dnm(temp,32,2);}
      if(temp>=64 && temp<128) {dlm(3);dnm(temp,64,4);}
      if(temp>=128 && temp<256) {dlm(4);dnm(temp,128,8);}
      if(temp>=256 && temp<512) {dlm(5);dnm(temp,256,16);}
      if(temp>=512 && temp<1024) {dlm(6);dnm(temp,512,32);}
      if(temp>=1024 && temp<2048) {dlm(7);dnm(temp,1024,64);}
      tmpbuf=ctime(&Nowtime);str2=tmpbuf;
	  if(pBtn1->GetCheck() == 1)
	  str3.Format("%d",int(cos(Nowtime+i/8.0)*128*16));
       if(pBtn2->GetCheck() == 1)
     str3.Format("%d",int(sin(Nowtime+i/8.0)*128*16));
	    
     str1.Format( "%d%d%d%d%d%d%d%d\n ",code1[0],code1[1],code1[2],code1[3],code1[4],code1[5],code1[6],code1[7]);
      
	 str.Format("%s      %s        %s\r\n",str2,str1,str3);
      ((CListBox*)GetDlgItem(IDC_LIST1) ) -> AddString(str);
	  if(i>0&&(i%8000==0))Nowtime++;
		 
	  

     //m_strEdit = m_strEdit + str; 
	 //UpdateData(FALSE);
	 }


  

	

	
}

int jdlm(int x,int y[8])       //解段落码
{
     int a;
     switch(x)
     {
     case 0:a=0;y[0]=1;break;
     case 1:a=16;y[1]=1;break;
     case 2:a=32;y[2]=2;break;
     case 3:a=64;y[3]=4;break;
     case 4:a=128;y[4]=8;break;
     case 5:a=256;y[5]=16;break;
     case 6:a=512;y[6]=32;break;
     case 7:a=1024;y[7]=64;break;
     default:break;
     }
     //printf("起点:%d\n间隔:%d\n",a,y[x]);
     return (a);
}

void CPamDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
UpdateData();	
int i,c,m;float t;CString m_strEdit;
double n;int b;


int code2[8];
int s[8];
	int r;r=a;


for(i=0;i<8;i++)
{
     code2[i]=r%10;
     r=r/10;
}
c=code2[4]+code2[5]*2+code2[6]*4;
m=jdlm(c,s);         //调用解段落码子函数
n=code2[0]+code2[1]*2+code2[2]*4+code2[3]*8+0.5;
t=m+n*s[c];
if(code2[7]==0)
     t=-t;m_strEdit.Format("%f\r\n",t);
((CListBox*)GetDlgItem(IDC_LIST1) ) -> AddString(m_strEdit);

UpdateData(false);


	
}

void CPamDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
UpdateData(); 
fstream f1; 
f1.open("1.txt",ios::in|ios::out); 
if(!f1) 
{ 
MessageBox("打不开","提示",0); 
return; 
}
     CListBox *pListBox=(CListBox*)GetDlgItem(IDC_LIST1); 

CString str, str2;
   int n;
   for (int i=0;i < pListBox->GetCount();i++)
   {
      n = pListBox->GetTextLen( i );
      pListBox->GetText( i, str.GetBuffer(n) );
      str.ReleaseBuffer();

      str2.Format(_T("item %d %s"),i,str.GetBuffer(0));
      
      f1<<str2;
   }


  

	
}

void CPamDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here

    CListBox   *pListBox=(CListBox*)GetDlgItem(IDC_LIST1);   
    pListBox->ResetContent();
	
}

void CPamDlg::OnRadio3() 
{
	// TODO: Add your control notification handler code here

	
}

void CPamDlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here


}

void CPamDlg::OnMenuitem32771() 
{
	// TODO: Add your command handler code here
	UpdateData(); 
fstream f1; 
f1.open("1.txt",ios::in|ios::out); 
if(!f1) 
{ 
MessageBox("打不开","提示",0); 
return; 
}
     CListBox *pListBox=(CListBox*)GetDlgItem(IDC_LIST1); 

CString str, str2;
   int n;
   for (int i=0;i < pListBox->GetCount();i++)
   {
      n = pListBox->GetTextLen( i );
      pListBox->GetText( i, str.GetBuffer(n) );
      str.ReleaseBuffer();

      str2.Format(_T("item %d %s"),i,str.GetBuffer(0));
      
      f1<<str2;
}
	
}

void CPamDlg::OnMenuitem32772() 
{
	// TODO: Add your command handler code here
	EndDialog(IDD_PAM_DIALOG);
	
}

void CPamDlg::OnMenuitem32773() 
{
	// TODO: Add your command handler code here
	MessageBox
             ("06网络工程    姓名:李林忆 云柳   学号: 16  48  ");
				return;
	
}

void CPamDlg::OnMenuitem32775() 
{
	// TODO: Add your command handler code here
GetDlgItem(IDC_RADIO4)->EnableWindow(false);
GetDlgItem(IDC_RADIO3)->EnableWindow(false);
GetDlgItem(IDC_BUTTON3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(false);

	GetDlgItem(IDC1)->SetWindowText("输入一个8位码");
	GetDlgItem(IDC2)->SetWindowText("二进制码");
    GetDlgItem(IDC_3)->SetWindowText("当前为解码操作");
	
}

void CPamDlg::OnMenuitem32774() 
{
	// TODO: Add your command handler code here
GetDlgItem(IDC_RADIO4)->EnableWindow(true);
GetDlgItem(IDC_RADIO3)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
	GetDlgItem(IDC1)->SetWindowText("时间t");
    GetDlgItem(IDC2)->SetWindowText("时间");
    GetDlgItem(IDC_3)->SetWindowText("当前为编码操作每秒取值8000个");

	
}

⌨️ 快捷键说明

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