SysConfig.cpp 8.89 KB
// SysConfig.cpp : implementation file
//

#include "stdafx.h"
#include "BlueFlashTool.h"
#include "SysConfig.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSysConfig dialog


CSysConfig::CSysConfig(CWnd* pParent /*=NULL*/)
	: CDialog(CSysConfig::IDD, pParent)
	, mystrSNHeader(_T(""))
	, myintBandrate(_T("921600"))
	, myAllowSave(true)
	, myintStart(0)
	, myintEnd(0)
{
	//{{AFX_DATA_INIT(CSysConfig)
	mystrFilePathUsb = _T("");
	mystrFilePathEar = _T("");
	mystrSnEnd = _T("");
	mystrSnStart = _T("");
	//}}AFX_DATA_INIT
}


void CSysConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSysConfig)
	//	DDX_Control(pDX, IDC_COMPORT_EAR01, mylistEar01);
	//	DDX_Control(pDX, IDC_COMPORT_EAR02, mylistEar02);
	//	DDX_Control(pDX, IDC_COMPORT_EAR03, mylistEar03);
	//	DDX_Control(pDX, IDC_COMPORT_EAR04, mylistEar04);
	//	DDX_Control(pDX, IDC_COMPORT_EAR05, mylistEar05);
	//	DDX_Control(pDX, IDC_COMPORT_EAR06, mylistEar06);
	//	DDX_Control(pDX, IDC_COMPORT_EAR07, mylistEar07);
	//	DDX_Control(pDX, IDC_COMPORT_EAR08, mylistEar08);
	//	DDX_Control(pDX, IDC_COMPORT_EAR09, mylistEar09);
	//	DDX_Control(pDX, IDC_COMPORT_EAR10, mylistEar10);
	//	DDX_Control(pDX, IDC_COMPORT_USB01, mylistUsb01);
	//	DDX_Control(pDX, IDC_COMPORT_USB02, mylistUsb02);
	//	DDX_Control(pDX, IDC_COMPORT_USB03, mylistUsb03);
	//	DDX_Control(pDX, IDC_COMPORT_USB04, mylistUsb04);
	//	DDX_Control(pDX, IDC_COMPORT_USB05, mylistUsb05);
	//	DDX_Control(pDX, IDC_COMPORT_USB06, mylistUsb06);
	//	DDX_Control(pDX, IDC_COMPORT_USB07, mylistUsb07);
	//	DDX_Control(pDX, IDC_COMPORT_USB08, mylistUsb08);
	//	DDX_Control(pDX, IDC_COMPORT_USB09, mylistUsb09);
	//	DDX_Control(pDX, IDC_COMPORT_USB10, mylistUsb10);
	DDX_Control(pDX, IDC_COMBO_STEAM, mylistStreambit);
	DDX_Control(pDX, IDC_COMBO_STOPBIT, mylistStopbit);
	DDX_Control(pDX, IDC_COMBO_DATABIT, mylistDatabit);
	DDX_Control(pDX, IDC_COMBO_CHECK, mylistCheck);
	DDX_Control(pDX, IDC_CHECK_SAME_SN, myCheckSameSn);
	DDX_Text(pDX, IDC_EDIT_USB_PATH, mystrFilePathUsb);
	DDX_Text(pDX, IDC_EDIT_EAR_PATH, mystrFilePathEar);
	DDX_Text(pDX, IDC_EDIT_SN_END, mystrSnEnd);
	DDX_Text(pDX, IDC_EDIT_SN_START, mystrSnStart);
	//}}AFX_DATA_MAP
	DDX_Text(pDX, IDC_EDIT_SN_HEADER, mystrSNHeader);
	DDV_MaxChars(pDX, mystrSnStart, 5);
	DDV_MaxChars(pDX, mystrSnEnd, 5);
	DDX_CBString(pDX, IDC_COMBO_BAND, myintBandrate);
	DDX_Control(pDX, IDC_CHECK_SAME_BTNAME, myCheckSameBtname);
	DDX_Control(pDX, IDC_CHECK_FLASH_ONE_BIN, mycheckAllOneBin);
	DDX_Text(pDX, IDC_EDIT_BIN_START, myintStart);
	DDV_MinMaxInt(pDX, myintStart, 0, 65535);
	DDX_Text(pDX, IDC_EDIT_BIN_END, myintEnd);
	DDV_MinMaxInt(pDX, myintEnd, 0, 65535);
}


BEGIN_MESSAGE_MAP(CSysConfig, CDialog)
	//{{AFX_MSG_MAP(CSysConfig)
	ON_BN_CLICKED(IDC_CHECK_SAME_SN, OnCheckSameSn)
	ON_BN_CLICKED(IDC_BUTTON_SECPATH_EAR, OnButtonSecpathEar)
	ON_BN_CLICKED(IDC_BUTTON_SECPATH_USB, OnButtonSecpathUsb)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDOK, &CSysConfig::OnBnClickedOk)
	ON_BN_CLICKED(IDC_CHECK_SAME_BTNAME, &CSysConfig::OnBnClickedCheckSameBtname)
	ON_BN_CLICKED(IDC_CHECK_FLASH_ONE_BIN, &CSysConfig::OnBnClickedCheckFlashOneBin)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSysConfig message handlers

void CSysConfig::OnCheckSameSn() 
{
	// TODO: Add your control notification handler code here
#ifdef __TOPWELL_EDIT_SN_ENABLE__
	g_AppMainData.if_same_sn = myCheckSameSn.GetCheck();
	GetDlgItem(IDC_EDIT_SN_START)->EnableWindow(!g_AppMainData.if_same_sn);
	GetDlgItem(IDC_EDIT_SN_END)->EnableWindow(!g_AppMainData.if_same_sn);
	GetDlgItem(IDC_EDIT_SN_HEADER)->EnableWindow(!g_AppMainData.if_same_sn);
#endif
}

void CSysConfig::OnBnClickedCheckSameBtname()
{
#ifdef __TOPWELL_EDIT_SN_ENABLE__
	g_AppMainData.if_same_btname = myCheckSameBtname.GetCheck();
	GetDlgItem(IDC_EDIT_BTNAME_START)->EnableWindow(!g_AppMainData.if_same_btname);
	GetDlgItem(IDC_EDIT_BTNAME_END)->EnableWindow(!g_AppMainData.if_same_btname);
	GetDlgItem(IDC_EDIT_BTNAME_HEADER)->EnableWindow(!g_AppMainData.if_same_btname);
#endif
}

BOOL CSysConfig::OnInitDialog() 
{
	int loop = 0,loop2 = 0;
	int index_inserted;
	CString strComname,strCommConfiged;
	CDialog::OnInitDialog();

#ifdef __TOPWELL_EDIT_SN_ENABLE__
	 //数据初始化
	mystrSNHeader.Format("%s",g_AppMainData.SN_head);
	mystrSnStart.Format("%05d",g_AppMainData.SN_cur);
	mystrSnEnd.Format("%05d",g_AppMainData.SN_end);
#endif
	mylistCheck.SetCurSel(g_AppMainData.com_config.bcheck);
	mylistDatabit.SetCurSel(3);
	mylistStopbit.SetCurSel(0);
	mylistStreambit.SetCurSel(0);

#ifdef __TOPWELL_EDIT_SN_ENABLE__
	//UI 初始化
	myCheckSameSn.SetCheck(g_AppMainData.if_same_sn);

	GetDlgItem(IDC_EDIT_SN_START)->EnableWindow(!g_AppMainData.if_same_sn);
	GetDlgItem(IDC_EDIT_SN_END)->EnableWindow(!g_AppMainData.if_same_sn);
	GetDlgItem(IDC_EDIT_SN_HEADER)->EnableWindow(!g_AppMainData.if_same_sn);

	myCheckSameBtname.SetCheck(FALSE);

	myCheckSameBtname.EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_BTNAME_START)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_BTNAME_END)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_BTNAME_HEADER)->EnableWindow(FALSE);
#endif

	mylistCheck.EnableWindow(FALSE);
	mylistDatabit.EnableWindow(FALSE);
	mylistStopbit.EnableWindow(FALSE);
	mylistStreambit.EnableWindow(FALSE);
#ifdef __TOPWELL_EDIT_SN_ENABLE__
	mystrFilePathEar = g_AppMainData.FilePathEar;
	mystrFilePathUsb = g_AppMainData.FilePathUsb;
#endif
	if (g_AppMainData.firstID_binfile == g_AppMainData.lastID_binfile)
	{
		mycheckAllOneBin.SetCheck(1);
		GetDlgItem(IDC_EDIT_BIN_START)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_BIN_END)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_EDIT_BIN_START)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_BIN_END)->EnableWindow(TRUE);
		myintStart = g_AppMainData.firstID_binfile;
		myintEnd = g_AppMainData.lastID_binfile;

	}
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSysConfig::OnButtonSecpathEar() 
{
    // TODO: Add your control notification handler code here
    char szFilter[]="bin files(*.*)|*.*";
    CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ENABLESIZING|0x10000000, szFilter, this);
    dlg.m_ofn.lpstrTitle = _T("选择耳机软件...");
    if(dlg.DoModal() == IDOK)
        mystrFilePathEar = dlg.GetPathName();
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_EAR_PATH);
    pEdit->SetWindowText(mystrFilePathEar);
	
}

void CSysConfig::OnButtonSecpathUsb() 
{
    // TODO: Add your control notification handler code here
    char szFilter[]="bin files(*.*)|*.*";
    CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ENABLESIZING|0x10000000, szFilter, this);
    dlg.m_ofn.lpstrTitle = _T("选择发射器软件...");
    if(dlg.DoModal() == IDOK)
        mystrFilePathUsb = dlg.GetPathName();
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_USB_PATH);
    pEdit->SetWindowText(mystrFilePathUsb);
	
}

void CSysConfig::OnBnClickedOk()
{
	int loop = 0;
	UpdateData(TRUE);
	if (myAllowSave == false)
	{
		MessageBox("请核对端口配置参数是否有误", "Warning");
		return;
	}
#ifdef __TOPWELL_EDIT_SN_ENABLE__
	if (!myCheckSameSn.GetCheck())
	{
		if (mystrSnStart.GetLength()<5 ||mystrSnEnd.GetLength()<5 )
		{
			MessageBox("序号太短", "Warning");
			return;
		}
		if (mystrSnStart == mystrSnEnd)
		{
			MessageBox("结束序号与起始序号不能相同", "Warning");
			return;
		}
		char *p_SnStart = mystrSnStart.GetBuffer(5);
		char *p_SnEnd = mystrSnEnd.GetBuffer(5);
		g_AppMainData.SN_start = atoi(p_SnStart);
		g_AppMainData.SN_end = atoi(p_SnEnd);
		g_AppMainData.SN_cur = g_AppMainData.SN_start;
		g_AppMainData.if_same_sn = TRUE;
	}
	else
	{
		g_AppMainData.if_same_sn = FALSE;
	}

	g_AppMainData.if_same_sn = myCheckSameSn.GetCheck();
	g_AppMainData.com_config.aBandrate=atoi(myintBandrate.GetBuffer(0));
	g_AppMainData.com_config.bcheck = mylistCheck.GetCurSel();
	g_AppMainData.com_config.cdatabit = mylistDatabit.GetCurSel();
	g_AppMainData.com_config.dstopbit = mylistStopbit.GetCurSel();
	g_AppMainData.com_config.estreambit = mylistStreambit.GetCurSel();
#endif
	if (mystrFilePathEar == "")
	{
		MessageBox("未选择耳机软件", "Warning");
	}
	if (mystrFilePathUsb == "")
	{
		MessageBox("未选择发射器软件", "Warning");
	}
#ifdef __TOPWELL_EDIT_SN_ENABLE__
	g_AppMainData.FilePathEar = mystrFilePathEar;
	g_AppMainData.FilePathUsb = mystrFilePathUsb;
#endif
	g_pmainapp->SaveConfigs();


	CDialog::OnOK();
}


void CSysConfig::OnBnClickedCheckFlashOneBin()
{
	if (mycheckAllOneBin.GetCheck())
	{
		GetDlgItem(IDC_EDIT_BIN_START)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_BIN_END)->EnableWindow(FALSE);
		myintStart = myintEnd = 0;
		MessageBox("需要下载的软件命名为RX_0000.bin或者TX_0000.bin");
	}
	else
	{
		GetDlgItem(IDC_EDIT_BIN_START)->EnableWindow(TRUE);
		GetDlgItem(IDC_EDIT_BIN_END)->EnableWindow(TRUE);
		myintStart = 0;
		myintEnd = 30000;


	}
	UpdateData(FALSE);
}