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

📄 pathsimview.cpp

📁 信道仿真源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PathSimView.cpp : implementation of the CPathSimView class
//////////////////////////////////////////////////////////////////////
// Copyright 2000.    Moe Wheatley AE4JY  <ae4jy@mindspring.com>
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
////

#include "stdafx.h"
#include "PathSim.h"
#include "PathSimDoc.h"
#include "PathSimView.h"
#include "InDlg.h"
#include "OutDlg.h"

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

#ifdef TESTMODE
extern double testfreq;
extern double gDebug1;
extern double gDebug2;
extern INT iDebug3;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPathSimView

IMPLEMENT_DYNCREATE(CPathSimView, CFormView)

BEGIN_MESSAGE_MAP(CPathSimView, CFormView)
	//{{AFX_MSG_MAP(CPathSimView)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_INSELECT, OnInselect)
	ON_BN_CLICKED(IDC_OUTSELECT, OnOutselect)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SNRSPIN, OnDeltaposSnrspin)
	ON_EN_KILLFOCUS(IDC_EDITTITLE, OnKillfocusEdittitle)
	ON_EN_KILLFOCUS(IDC_EDITRUNTIME, OnKillfocusEditruntime)
	ON_BN_CLICKED(IDC_USEDELAYSTART, OnUsedelaystart)
	ON_EN_KILLFOCUS(IDC_STARTEDIT_HOUR, OnKillfocusStarteditHour)
	ON_EN_KILLFOCUS(IDC_STARTEDIT_MIN, OnKillfocusStarteditMin)
	ON_EN_KILLFOCUS(IDC_EDITDELAY1, OnKillfocusEditdelay1)
	ON_EN_KILLFOCUS(IDC_EDITDELAY2, OnKillfocusEditdelay2)
	ON_EN_KILLFOCUS(IDC_EDITOFFSET0, OnKillfocusEditoffset0)
	ON_EN_KILLFOCUS(IDC_EDITOFFSET1, OnKillfocusEditoffset1)
	ON_EN_KILLFOCUS(IDC_EDITOFFSET2, OnKillfocusEditoffset2)
	ON_EN_KILLFOCUS(IDC_EDITSNR, OnKillfocusEditsnr)
	ON_BN_CLICKED(IDC_AWGNONOFF, OnPathChange)
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_PATHONOFF0, OnPathChange)
	ON_BN_CLICKED(IDC_PATHONOFF1, OnPathChange)
	ON_BN_CLICKED(IDC_PATHONOFF2, OnPathChange)
	ON_EN_KILLFOCUS(IDC_EDITSPREAD0, OnKillfocusEditspread0)
	ON_EN_KILLFOCUS(IDC_EDITSPREAD1, OnKillfocusEditspread1)
	ON_EN_KILLFOCUS(IDC_EDITSPREAD2, OnKillfocusEditspread2)
	//}}AFX_MSG_MAP
	ON_MESSAGE( MSG_DATARDY, OnDataRdy)
	ON_MESSAGE( MSG_DONE, OnDone)
	ON_MESSAGE( MSG_ERROR, OnError)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPathSimView construction/destruction

CPathSimView::CPathSimView()
	: CFormView(CPathSimView::IDD)
{
	//{{AFX_DATA_INIT(CPathSimView)
	m_AWGNOn = FALSE;
	m_Path0On = FALSE;
	m_Path1On = FALSE;
	m_Path2On = FALSE;
	m_Offset0 = 0.0;
	m_Offset1 = 0.0;
	m_Offset2 = 0.0;
	m_Delay1 = 0.0;
	m_Delay2 = 0.0;
	m_SimTitle = _T("");
	m_TimeLimit = 1;
	m_UseDelayStart = FALSE;
	m_DelayStartHour = 0;
	m_DelayStartMin = 0;
	m_DiskFree = _T("");
	m_DiskNeeded = _T("");
	m_SNRSetValue = 0;
	m_Spread0 = 1.0;
	m_Spread1 = 1.0;
	m_Spread2 = 1.0;
	//}}AFX_DATA_INIT
	m_pCPlotData = NULL;
	m_pCIOCntrl = NULL;
}

CPathSimView::~CPathSimView()
{
}

void CPathSimView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPathSimView)
	DDX_Control(pDX, IDC_NOISERMS, m_NoiseRMSCtrl);
	DDX_Control(pDX, IDC_SIGRMS, m_SigRMSCtrl);
	DDX_Control(pDX, IDC_SIGNALGAIN, m_SignalGainCtrl);
	DDX_Control(pDX, IDC_AWGNGAIN, m_AWGNGainCtrl);
	DDX_Control(pDX, IDC_TESTTEXT1, m_TestTextCtrl1);
	DDX_Control(pDX, IDC_TESTTEXT2, m_TestTextCtrl2);
	DDX_Control(pDX, IDC_FFTFREQ, m_FFTFreqCtrl);
	DDX_Control(pDX, IDC_BYPASS2, m_Bypass2Ctrl);
	DDX_Control(pDX, IDC_BYPASS1, m_Bypass1Ctrl);
	DDX_Control(pDX, IDC_OUT_FILE, m_OutFileCtrl);
	DDX_Control(pDX, IDC_OUT_INFO, m_OutInfoCtrl);
	DDX_Control(pDX, IDC_IN_FILE, m_InFileCtrl);
	DDX_Control(pDX, IDC_IN_INFO, m_InInfoCtrl);
	DDX_Control(pDX, IDC_STOP, m_StopCtrl);
	DDX_Control(pDX, IDC_START, m_StartCtrl);
	DDX_Check(pDX, IDC_AWGNONOFF, m_AWGNOn);
	DDX_Check(pDX, IDC_PATHONOFF0, m_Path0On);
	DDX_Check(pDX, IDC_PATHONOFF1, m_Path1On);
	DDX_Check(pDX, IDC_PATHONOFF2, m_Path2On);
	DDX_Text(pDX, IDC_EDITOFFSET0, m_Offset0);
	DDV_MinMaxDouble(pDX, m_Offset0, -1000., 1000.);
	DDX_Text(pDX, IDC_EDITOFFSET1, m_Offset1);
	DDV_MinMaxDouble(pDX, m_Offset1, -1000., 1000.);
	DDX_Text(pDX, IDC_EDITOFFSET2, m_Offset2);
	DDV_MinMaxDouble(pDX, m_Offset2, -1000., 1000.);
	DDX_Text(pDX, IDC_EDITDELAY1, m_Delay1);
	DDV_MinMaxDouble(pDX, m_Delay1, 0., 50.);
	DDX_Text(pDX, IDC_EDITDELAY2, m_Delay2);
	DDV_MinMaxDouble(pDX, m_Delay2, 0., 50.);
	DDX_Text(pDX, IDC_EDITTITLE, m_SimTitle);
	DDV_MaxChars(pDX, m_SimTitle, 40);
	DDX_Text(pDX, IDC_EDITRUNTIME, m_TimeLimit);
	DDV_MinMaxInt(pDX, m_TimeLimit, 0, 500);
	DDX_Check(pDX, IDC_USEDELAYSTART, m_UseDelayStart);
	DDX_Text(pDX, IDC_STARTEDIT_HOUR, m_DelayStartHour);
	DDV_MinMaxInt(pDX, m_DelayStartHour, 0, 23);
	DDX_Text(pDX, IDC_STARTEDIT_MIN, m_DelayStartMin);
	DDV_MinMaxInt(pDX, m_DelayStartMin, 0, 59);
	DDX_Text(pDX, IDC_DISKFREE, m_DiskFree);
	DDX_Text(pDX, IDC_DISKNEEDED, m_DiskNeeded);
	DDX_Text(pDX, IDC_EDITSNR, m_SNRSetValue);
	DDX_Text(pDX, IDC_EDITSPREAD0, m_Spread0);
	DDV_MinMaxDouble(pDX, m_Spread0, 0., 30.);
	DDX_Text(pDX, IDC_EDITSPREAD1, m_Spread1);
	DDV_MinMaxDouble(pDX, m_Spread1, 0., 30.);
	DDX_Text(pDX, IDC_EDITSPREAD2, m_Spread2);
	DDV_MinMaxDouble(pDX, m_Spread2, 0., 30.);
	//}}AFX_DATA_MAP
}

BOOL CPathSimView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CPathSimView::OnInitialUpdate()
{
CWnd* pWnd;
CRect cr;
CPathSimDoc* pDoc = GetDocument();
CString str;
	ASSERT_VALID( pDoc);
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	//instantiate display data plotting and processing  objects
	if(!m_pCPlotData)
		m_pCPlotData = new CPlotData();	//initialize Data plotting resources
	ASSERT(m_pCPlotData);
	pWnd = GetDlgItem( IDC_PLOTFREQ );
	ASSERT_VALID(pWnd);					//give view client area to Plot object
	pWnd->GetClientRect( cr );
	m_pCPlotData->SetFreqPlotSize(cr); 
	pWnd = GetDlgItem( IDC_PLOTTIME );
	ASSERT_VALID(pWnd);					//give view client area to Plot object
	pWnd->GetClientRect( cr );
	m_pCPlotData->SetTimePlotSize(cr); 

	m_StartCtrl.EnableWindow(TRUE);
	m_StopCtrl.EnableWindow(FALSE);

	if(!m_pCIOCntrl)
		m_pCIOCntrl = new CIOCntrl();
	m_pCIOCntrl->StopIO();
// update info from document
	m_SimTitle = pDoc->m_SimTitle;
	m_TimeLimit = pDoc->m_TimeLimit/60;
	if(m_TimeLimit<=0)
	{
		m_TimeLimit = 1;
		pDoc->m_TimeLimit = 60;
	}
	m_UseDelayStart = pDoc->m_UseDelayStart;
	m_DelayStartHour = pDoc->m_DelayStartHour;
	m_DelayStartMin = pDoc->m_DelayStartMin;
	m_Delay1 = pDoc->m_Delay1;
	m_Delay2 = pDoc->m_Delay2;
	m_Offset0 = pDoc->m_Offset0;
	m_Offset1 = pDoc->m_Offset1;
	m_Offset2 = pDoc->m_Offset2;
	m_SNRSetValue = pDoc->m_SNRSetValue;
	m_pCIOCntrl->SetSNRValue(m_SNRSetValue);
	m_AWGNOn = pDoc->m_AWGNOn;
	m_Path0On = pDoc->m_Path0On;
	m_Path1On = pDoc->m_Path1On;
	m_Path2On = pDoc->m_Path2On;
	if(pDoc->m_InputSelect == USE_WAVEFILE)
	{
		m_InInfoCtrl.SetWindowText(	pDoc->m_InFileInfo );
		m_InFileCtrl.SetWindowText(	pDoc->m_InFileName );
		pDoc->m_InFileLength = pDoc->GetInputFileLength();

		if( pDoc->m_TimeLimit > ((UINT)pDoc->m_InFileLength/8000)+1 )
		{
			pDoc->m_TimeLimit = (pDoc->m_InFileLength/8000)+1;
			m_TimeLimit = pDoc->m_TimeLimit/60;
		}
	}
	else
	{
		m_InFileCtrl.SetWindowText(	_T("SoundCard") );
		m_InInfoCtrl.SetWindowText(	_T("8KHz, 16Bit,Mono"));
	}
	if(pDoc->m_OutputSelect == USE_WAVEFILE)
	{
		str = pDoc->m_OutFileName;
		if(pDoc->m_AppendTitle)
			str.Replace( _T("."),  _T("''Title''.") );
		m_OutFileCtrl.SetWindowText( str );
		m_OutInfoCtrl.SetWindowText( _T("") );
	}
	else
	{
		m_OutFileCtrl.SetWindowText( _T("SoundCard") );
		m_OutInfoCtrl.SetWindowText( _T("8KHz, 16Bit,Mono"));
	}	pDoc->m_SimState = SIMSTATE_OFF;
	m_Spread0 = pDoc->m_Spread0;
	m_Spread1 = pDoc->m_Spread1;
	m_Spread2 = pDoc->m_Spread2;
	UpdateData(FALSE);
	EnableAllCtrls(TRUE);
	OnPathChange();
	UpdateDiskInfo();

}

/////////////////////////////////////////////////////////////////////////////
// CPathSimView diagnostics

#ifdef _DEBUG
void CPathSimView::AssertValid() const
{
	CFormView::AssertValid();
}

void CPathSimView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CPathSimDoc* CPathSimView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPathSimDoc)));
	return (CPathSimDoc*)m_pDocument;
}
#endif //_DEBUG

void CPathSimView::UpdateDiskInfo()
{
CPathSimDoc* pDoc;
	pDoc = GetDocument();
	pDoc->GetDiskInfo( m_DiskFree, m_DiskNeeded);
	UpdateData(FALSE);
}


/////////////////////////////////////////////////////////////////////////////
// CPathSimView message handlers

void CPathSimView::OnDestroy() 
{
	if(m_pCPlotData)
	{
		delete m_pCPlotData;
		m_pCPlotData = NULL;
	}
	if(m_pCIOCntrl)
	{
		m_pCIOCntrl->StopIO();
		delete m_pCIOCntrl;
		m_pCIOCntrl = NULL;
	}		
	CFormView::OnDestroy();
}

void CPathSimView::OnDraw(CDC* pDC) 
{
CPathSimDoc* pDoc = (CPathSimDoc*)GetDocument();
	//go recalculate & draw the data plots
	if(m_pCPlotData)
		m_pCPlotData->OnDrawPlot( m_hWnd, this, pDoc, m_pCIOCntrl );
}

void CPathSimView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if( m_pCPlotData->CurInFreqPlot(point) )
	{
		CString str;
		INT freq = m_pCPlotData->GetCursFreq( point );
		str.Format(_T("%d Hz"),freq);
		m_FFTFreqCtrl.SetWindowText( str);
	}
	CFormView::OnMouseMove(nFlags, point);
}


//////////////////////////////////////////////////////////////////////
// Called when the process has new FFT data to display every .256 seconds.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CPathSimView::OnDataRdy(UINT x, LONG y)
{
CPathSimDoc* pDoc;
CString str;
double Ngain, Sgain;
	pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	m_pCIOCntrl->ReadGains(Ngain, Sgain);
	str.Format("%g",Ngain );
	m_AWGNGainCtrl.SetWindowText( str);
	str.Format("%g", Sgain );
	m_SignalGainCtrl.SetWindowText( str);
	str.Format("%g", pDoc->m_SigRMS );
	m_SigRMSCtrl.SetWindowText( str);
	str.Format("%g", pDoc->m_NoiseRMS );
	m_NoiseRMSCtrl.SetWindowText( str);

#ifdef TESTMODE
	
	str.Format("%g", gDebug1);
	m_TestTextCtrl1.SetWindowText( str);
	str.Format("%g", gDebug2);

⌨️ 快捷键说明

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