// FSK.cpp : implementation file
//

#include "stdafx.h"
#include "PeakTech_4055MV_4060.h"
#include "FSK.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFSK dialog


CFSK::CFSK(CWnd* pParent /*=NULL*/)
	: CDialog(CFSK::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFSK)
	m_fskFreq = 4000.0;
	m_fskRate = 1000.0;
	//}}AFX_DATA_INIT
}


void CFSK::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFSK)
	DDX_Control(pDX, IDC_FSKSTATE, m_comOutput);
	DDX_Control(pDX, IDC_FSKSOURCE, m_comSource);
	DDX_Control(pDX, IDC_FSKRATEUNIT, m_comRate);
	DDX_Control(pDX, IDC_FSKFREQUNIT, m_comFreq);
	DDX_Text(pDX, IDC_FSKFREQ, m_fskFreq);
	DDX_Text(pDX, IDC_FSKRATE, m_fskRate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFSK, CDialog)
	//{{AFX_MSG_MAP(CFSK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFSK message handlers

BOOL CFSK::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here		
	m_comFreq.SetCurSel(2);
	m_comRate.SetCurSel(1);
	m_comSource.SetCurSel(0);
	m_comOutput.SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFSK::Send()
{
  char *ptr;
	CString str,str_rate,str_freq,str_source,str_output;
	m_comFreq.GetWindowText(str_freq);
	m_comRate.GetWindowText(str_rate);
	m_comSource.GetWindowText(str_source);
	m_comOutput.GetWindowText(str_output);
	ULONG len;
	ptr = (char*)malloc(1024);
	UpdateData();	
	str.Format("FSKey:STATe %s",str_output);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=str + "\r\n";

	Sleep(300);
	str.Format("FSKey:INTernal:RATE %f%s",m_fskRate,str_rate);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
m_str=m_str+str + "\r\n";

	Sleep(200);
	Sleep(100);
	str.Format("FSKey:FREQuency %f%s",m_fskFreq,str_freq);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str=m_str+str +"\r\n";

	Sleep(100);
	str.Format("FSKey:SOURce %s",str_source);
	strcpy(ptr, str);
	strcat(ptr, "\n");
	len = strlen(ptr);
	CH375WriteData(0, ptr, &len);
	m_str=m_str+str + "\r\n";
    free(ptr);
}
