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

📄 winpskview.cpp

📁 PSK31方式通信C++编写的原代码,可以通过声音传递数据.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{
	CFormView::Dump(dc);
}

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

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//					CWinPSKView message handlers
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//////////////////////////////////////////////////////////////////////
// Called when view screen coordinates have changed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnDraw(CDC* pDC) 
{
	//go recalculate & draw the data plots
	if(m_pCPlotData)
		m_pCPlotData->OnDrawPlot( m_hWnd, this, (CWinPSKDoc*)GetDocument() );
	m_ScreenInitialized = TRUE;
}

//////////////////////////////////////////////////////////////////////
// Called when DLL has new FFT data to display every .256 seconds.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CWinPSKView::OnDataRdy(UINT rxfreq, LONG SqLevel)
{
CWinPSKDoc* pDoc;
	pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	if( (rxfreq != (UINT)m_RxFreq) && !m_fRxFreqEditing && !m_fTxFreqEditing)
	{
		m_RxFreq = (INT)rxfreq;
		pDoc->m_pSettings->m_RxFreq = m_RxFreq;
		UpdateData(FALSE);		//Put changed data into control
		UpdatePlotInfo(PLOT_CHNG_FREQ);
	}
	if(SqLevel < 10 )	//clamp min sq level to 10
		SqLevel = 10;
	m_pSquelchCtrl->SetLevel( SqLevel );
	//go draw the data plots
	if(m_pCPlotData && m_ScreenInitialized)
		m_pCPlotData->DrawPlot();

#if 0
double d1,d2;
INT i1;
CString str;
	i1=fnGetDebugData(&d1,&d2);
	str.Format("%g",d1);
	m_DebugCtrl1.SetWindowText(str);
	str.Format("%g",d2);
	m_DebugCtrl2.SetWindowText(str);
#endif
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Called when DLL has new character to display from rx or tx.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CWinPSKView::OnCharRdy(UINT ch, LONG src)
{
CWinPSKDoc* pDoc = GetDocument();
CString str;
	ASSERT_VALID( pDoc );
	if( src < 0 )		//if src is xmitted char
	{
		if(pDoc->m_pSettings->m_EchoTXText )
		{
			if( !pDoc->m_SatMode)
				pDoc->m_pRcvEdit->OnRcvChar( ch, src);
			pDoc->m_pXmitEdit->UpdateFormats();
		}
	}
	else
	{
		if( pDoc->m_SatMode && (m_ProgramState!=STATE_RX))
			pDoc->m_pRcvEdit->OnRcvChar( ch, -1);
		else
			pDoc->m_pRcvEdit->OnRcvChar( ch, src);
	}
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Called when DLL has new IMD data ready.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CWinPSKView::OnIMDRdy(UINT IMD, LONG chan)
{
CWinPSKDoc* pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	pDoc->m_IMD = IMD;
	if( chan&0x80 )
		pDoc->m_IMD = -(INT)IMD;
	pDoc->m_IMDRdy = TRUE;
	m_IMDDispDelay = 5;
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Called when DLL has new clock error data.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CWinPSKView::OnClkError(UINT error, LONG chan)
{
CWinPSKDoc* pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	pDoc->m_ClkError = error;
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Called when DLL has changed status or has an error.
//////////////////////////////////////////////////////////////////////
afx_msg LRESULT CWinPSKView::OnStatusChange(UINT status, LONG percent)
{
CHAR errstr[50];
CWinPSKDoc* pDoc = GetDocument();
	ASSERT_VALID( pDoc );

	switch(status)
	{
		case DLL_RX_STATUS:
			m_TRCntrl.SetIcon(AfxGetApp()->LoadIcon(IDI_TRRCV));
			if(	m_ProgramState != STATE_RX)
			{
				pDoc->m_pRcvEdit->TXStamp(pDoc->m_pSettings->m_EchoTXText,
									FALSE, pDoc->m_pSettings->m_UseLocalTime);
				pDoc->m_pXmitEdit->ClearSentText();
			}
			m_ProgramState = STATE_RX;
			break;
		case DLL_TX_STATUS:
			if(m_ProgramState != STATE_TUNE)
			{
				m_ProgramState = STATE_TX;
				m_TRCntrl.SetIcon(AfxGetApp()->LoadIcon(IDI_TRXMIT));
			}
			break;
		case DLL_FINISH_STATUS:
			m_TRCntrl.SetIcon(AfxGetApp()->LoadIcon(IDI_TXFINISH));
			m_ProgramState = STATE_FINISH;
			break;
		case DLL_SLOW_STATUS:
			pDoc->m_SoundCardReset = TRUE;
			break;
		case DLL_INWAVEDONE:
		case DLL_OUTWAVEDONE:
			StopDLL();
			break;
		case DLLSTAT_INWAVEFILESTATUS:
			if( percent > pDoc->m_FilePercentDone)
				pDoc->m_FilePercentDone = percent;
			break;
		case DLLSTAT_OUTWAVEFILESTATUS:
			if( percent > pDoc->m_FilePercentDone)
				pDoc->m_FilePercentDone = percent;
			break;
		default:
			if( status )
			{
				fnGetErrorString( errstr );
				AfxMessageBox( errstr);
				if(status==21)		//default soundcardnumber
					pDoc->m_pSettings->m_SoundcardNum = -1;
//				AfxGetMainWnd()->PostMessage(WM_CLOSE);
				m_RunCtrl.SetIcon(AfxGetApp()->LoadIcon(IDI_START));
				m_TRCntrl.EnableWindow(FALSE);
				m_DLLRunning = FALSE;
//				ExitProcess(0);
			}
			break;
	}
	return 0;
}

//////////////////////////////////////////////////////////////////////
// Called when mouse moves in view client window.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if( m_ZoomOK )
	{
		::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,NULL);	//prevent flickering
		if( m_pCPlotData->CurInPlot(point) )
			::SetCursor( m_hCross );
		else
			::SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)m_hOrigCursor);
	}
	CFormView::OnMouseMove(nFlags, point);
}

//////////////////////////////////////////////////////////////////////
// Called when left mouse button is clicked.
//  Frequency cursor is changed to the mouse position.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnLButtonDown(UINT nFlags, CPoint point) 
{
CWinPSKDoc* pDoc;
	if( m_ZoomOK )
	{
		if(m_pCPlotData->CurInPlot(point) )
		{
			pDoc = GetDocument();
			ASSERT_VALID( pDoc );
			m_fRxFreqEditing = FALSE;
			m_fTxFreqEditing = FALSE;
			m_pCPlotData->SetPlotCursorPos( point.x );
			m_pCPlotData->SetZoom( pDoc->m_pSettings->m_PlotViewState
										[pDoc->m_pSettings->m_TabSel].zoom,FALSE,
						pDoc->m_pSettings->m_FreqMin,
						pDoc->m_pSettings->m_FreqMax );
			UpdatePlotInfo(PLOT_CHNG_MOUSE);
		}
	}
	SetFocus();
	CFormView::OnLButtonDown(nFlags, point);
}

//////////////////////////////////////////////////////////////////////
// Called when right mouse button is clicked.
//  Frequency cursor is changed to the mouse position.
//  Input data is rewinded to the spot in the waterfall or specral view.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnRButtonDown(UINT nFlags, CPoint point) 
{
CWinPSKDoc* pDoc;
	if( m_ZoomOK )
	{
		if(m_pCPlotData->CurInPlot(point) )
		{
			pDoc = GetDocument();
			ASSERT_VALID( pDoc );
			m_fRxFreqEditing = FALSE;
			m_fTxFreqEditing = FALSE;
			m_pCPlotData->SetPlotCursorPos( point.x );
			m_pCPlotData->SetRewindPos( point.y );
			m_pCPlotData->SetZoom( pDoc->m_pSettings->m_PlotViewState
										[pDoc->m_pSettings->m_TabSel].zoom,FALSE,
						pDoc->m_pSettings->m_FreqMin,
						pDoc->m_pSettings->m_FreqMax );
			UpdatePlotInfo(PLOT_CHNG_MOUSE);
		}
	}
	SetFocus();	
	CFormView::OnRButtonDown(nFlags, point);
}


//////////////////////////////////////////////////////////////////////
// Called when Slow fft average button is pushed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnSlowave() 
{
CWinPSKDoc* pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	UpdateData(TRUE);		//Get value from control
	pDoc->m_pSettings->m_fSlowAve = m_fSlowAve;
	pDoc->m_FFTModeChange = TRUE;
}

//////////////////////////////////////////////////////////////////////
// Called when Auto Text check box is changed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnAutotxtsel() 
{
	UpdateData(TRUE);		//Get value from control
	GetDocument()->m_pSettings->m_AutoTxtSel = m_AutoTxtSel;
}

//////////////////////////////////////////////////////////////////////
// Called when AFC button is pushed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnAfc() 
{
CWinPSKDoc* pDoc = GetDocument();
	UpdateData(TRUE);		//Get value from control
	pDoc->m_pSettings->m_UseAFC = m_UseAFC;
	if(m_UseAFC)
	{
		fnSetAFCLimit(pDoc->m_pSettings->m_AFCLimit, RX_CHAN);
		m_SearchRange = SEARCH_RANGE;
	}
	else
	{
		fnSetAFCLimit( 0, RX_CHAN);
		m_SearchRange = 0;
	}
}

//////////////////////////////////////////////////////////////////////
// Called when left mouse button is DOUBLE clicked.
//  Frequency is cursor changed to the mouse position and the view is
//  centered about the cursor.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
CWinPSKDoc* pDoc;
	if( m_ZoomOK )
	{
		if(m_pCPlotData->CurInPlot(point) )
		{
			pDoc = GetDocument();
			ASSERT_VALID( pDoc );
			m_pCPlotData->SetPlotCursorPos( point.x );
			m_pCPlotData->SetZoom( pDoc->m_pSettings->m_PlotViewState
										[pDoc->m_pSettings->m_TabSel].zoom,FALSE,
						pDoc->m_pSettings->m_FreqMin,
						pDoc->m_pSettings->m_FreqMax );
			UpdatePlotInfo(PLOT_CHNG_MOUSE);
			m_pCPlotData->SetZoom(pDoc->m_pSettings->
							m_PlotViewState[pDoc->m_pSettings->m_TabSel].zoom,TRUE,
							pDoc->m_pSettings->m_FreqMin,
							pDoc->m_pSettings->m_FreqMax );
		}
	}
	CFormView::OnLButtonDblClk(nFlags, point);
}


//////////////////////////////////////////////////////////////////////
// Called when plot select tabs are clicked.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnSelchangeDisplaytab(NMHDR* pNMHDR, LRESULT* pResult) 
{
	INT tab = m_DispTabCtrl.GetCurSel();
	CWinPSKDoc* pDoc = GetDocument();
	ASSERT_VALID( pDoc );
	//save old tab state
	pDoc->m_pSettings->m_PlotViewState[pDoc->m_pSettings->m_TabSel].xcur =
							m_pCPlotData->GetPlotCursorIndex();
	pDoc->m_pSettings->m_PlotViewState[pDoc->m_pSettings->m_TabSel].zoom =
							m_pCPlotData->GetZoom();
	pDoc->m_pSettings->m_TabSel = tab;	// save new tab
	if( (tab == FFT_DISPVIEW ) || (tab == WATERFALL_DISPVIEW ) )
		m_ZoomOK = TRUE;
	else
		m_ZoomOK = FALSE;
	if( m_ZoomOK )
	{
		m_pCPlotData->SetPlotCursorIndex( pDoc->m_pSettings->m_PlotViewState[tab].xcur );
		m_pCPlotData->SetZoom( pDoc->m_pSettings->m_PlotViewState[tab].zoom,TRUE,
								pDoc->m_pSettings->m_FreqMin,
								pDoc->m_pSettings->m_FreqMax );
	}
	UpdatePlotInfo(PLOT_CHNG_ZOOM);
	UpdatePlotInfo(PLOT_CHNG_FREQ);
	UpdateData(FALSE);					//Put changed data into control
	m_pCPlotData->ClearBuffers();
	pDoc->m_FFTModeChange = TRUE;
	*pResult = 0;
}

//////////////////////////////////////////////////////////////////////
// Called when zoom spin control is clicked.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnDeltaposZoom(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	ChngZoom( -pNMUpDown->iDelta );
	*pResult = 0;
}


//////////////////////////////////////////////////////////////////////
// Called when RX freq edit box gets focus.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnSetfocusRxfreq() 
{
	m_fRxFreqEditing = TRUE;
}

//////////////////////////////////////////////////////////////////////
// Called when center frequency edit control is changed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnKillfocusRxfreq() 
{
CWinPSKDoc* pDoc = GetDocument();
	UpdateData(TRUE);		//Get value from control
	if(m_RxFreq < IndexToFreq( m_pCPlotData->GetXmin()) )
		m_RxFreq = IndexToFreq( m_pCPlotData->GetXmin());
	if(m_RxFreq > IndexToFreq( m_pCPlotData->GetXmax()) )
		m_RxFreq = IndexToFreq( m_pCPlotData->GetXmax());
	pDoc->m_pSettings->m_RxFreq = m_RxFreq;
	fnSetRXFrequency(m_RxFreq, 0, RX_CHAN);
	UpdateData(FALSE);		//Put changed data into control
	UpdatePlotInfo(PLOT_CHNG_FREQ);
	UpdatePlotInfo(PLOT_CHNG_ZOOM);
	m_fRxFreqEditing = FALSE;
	m_fTxFreqEditing = FALSE;
}


//////////////////////////////////////////////////////////////////////
// Called when TX freq edit box gets focus.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnSetfocusTxfreq() 
{
	m_fTxFreqEditing = TRUE;
}

//////////////////////////////////////////////////////////////////////
// Called when TX freq edit box Mode is changed.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnTxFreqMode() 
{
CWinPSKDoc* pDoc = GetDocument();
	if(pDoc->m_pSettings->m_TxOffsetMode )
	{
		pDoc->m_pSettings->m_TxOffsetMode = FALSE;
		m_TxFreqModeCtrl.SetWindowText( _T("Tx Freq") );
		m_TxDisp = pDoc->m_pSettings->m_TxFreq;
	}
	else
	{
		pDoc->m_pSettings->m_TxOffsetMode = TRUE;
		m_TxFreqModeCtrl.SetWindowText( _T("TxOffset") );
		m_TxDisp = pDoc->m_pSettings->m_TxFreqOffset;
	}
	UpdateData(FALSE);		//Put changed data into control
}
//////////////////////////////////////////////////////////////////////
// Called when TX freq edit box loses focus.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnKillfocusTxfreq() 
{
CWinPSKDoc* pDoc = GetDocument();
	UpdateData(TRUE);		//Get value from control
	if(pDoc->m_pSettings->m_TxOffsetMode )
	{
		if(m_TxDisp < -100 )
			m_TxDisp = -100;
		if(m_TxDisp > 100 )
			m_TxDisp = 100;
		pDoc->m_pSettings->m_TxFreqOffset = m_TxDisp;
	}
	else
	{
		if(m_TxDisp< IndexToFreq( m_pCPlotData->GetXmin()) )
			m_TxDisp = IndexToFreq( m_pCPlotData->GetXmin());
		if(m_TxDisp>IndexToFreq( m_pCPlotData->GetXmax()) )
			m_TxDisp = IndexToFreq( m_pCPlotData->GetXmax() );
		pDoc->m_pSettings->m_TxFreq = m_TxDisp;
	}
	UpdateData(FALSE);		//Put changed data into control
	m_fRxFreqEditing = FALSE;
	m_fTxFreqEditing = FALSE;

}

//////////////////////////////////////////////////////////////////////
// Called when TX freq Spin control is touched.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnDeltaposTxfreqspin(NMHDR* pNMHDR, LRESULT* pResult) 
{
CWinPSKDoc* pDoc = GetDocument();
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	m_TxDisp -= pNMUpDown->iDelta;
	if(pDoc->m_pSettings->m_TxOffsetMode )
	{
		if(m_TxDisp < -100 )
			m_TxDisp = -100;
		if(m_TxDisp > 100 )
			m_TxDisp = 100;
		pDoc->m_pSettings->m_TxFreqOffset = m_TxDisp;
	}
	else
	{
		if(m_TxDisp < IndexToFreq( m_pCPlotData->GetXmin()) )
			m_TxDisp = IndexToFreq( m_pCPlotData->GetXmin());
		if(m_TxDisp > IndexToFreq( m_pCPlotData->GetXmax()) )
			m_TxDisp = IndexToFreq( m_pCPlotData->GetXmax());
		pDoc->m_pSettings->m_TxFreq = m_TxDisp;
	}
	UpdateData(FALSE);		//Put changed data into control
	*pResult = 0;
	m_fRxFreqEditing = FALSE;
	m_fTxFreqEditing = FALSE;
}

//////////////////////////////////////////////////////////////////////
// Called when center frequency spin control is clicked.
//////////////////////////////////////////////////////////////////////
void CWinPSKView::OnDeltaposRxFreqspin(NMHDR* pNMHDR, LRESULT* pResult) 
{
CWinPSKDoc* pDoc = GetDocument();
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	if( !m_UseAFC)
	{
		m_RxFreq -= pNMUpDown->iDelta;
		if(m_RxFreq < IndexToFreq( m_pCPlotData->GetXmin()) )
			m_RxFreq = IndexToFreq( m_pCPlotData->GetXmin());
		if(m_RxFreq > IndexToFreq( m_pCPlotData->GetXmax()) )
			m_RxFreq = IndexToFreq( m_pCPlotData->GetXmax());
		pDoc->m_pSettings->m_RxFreq = m_RxFreq;
		fnSetRXFrequency( m_RxFreq, 0, RX_CHAN);
		UpdateData(FALSE);		//Put changed data into control
		UpdatePlotInfo(PLOT_CHNG_FREQ);

⌨️ 快捷键说明

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