1 |
26 |
unneback |
//####COPYRIGHTBEGIN####
|
2 |
|
|
//
|
3 |
|
|
// ----------------------------------------------------------------------------
|
4 |
|
|
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
|
5 |
|
|
//
|
6 |
|
|
// This program is part of the eCos host tools.
|
7 |
|
|
//
|
8 |
|
|
// This program is free software; you can redistribute it and/or modify it
|
9 |
|
|
// under the terms of the GNU General Public License as published by the Free
|
10 |
|
|
// Software Foundation; either version 2 of the License, or (at your option)
|
11 |
|
|
// any later version.
|
12 |
|
|
//
|
13 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
14 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
15 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
16 |
|
|
// more details.
|
17 |
|
|
//
|
18 |
|
|
// You should have received a copy of the GNU General Public License along with
|
19 |
|
|
// this program; if not, write to the Free Software Foundation, Inc.,
|
20 |
|
|
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
|
|
//
|
22 |
|
|
// ----------------------------------------------------------------------------
|
23 |
|
|
//
|
24 |
|
|
//####COPYRIGHTEND####
|
25 |
|
|
// LocalPropertiesDialog.cpp : implementation file
|
26 |
|
|
//
|
27 |
|
|
|
28 |
|
|
#include "stdafx.h"
|
29 |
|
|
#include "TestToolRes.h" // main symbols
|
30 |
|
|
#include "LocalPropertiesDialog.h"
|
31 |
|
|
#include "eCosSocket.h"
|
32 |
|
|
#ifdef _DEBUG
|
33 |
|
|
#define new DEBUG_NEW
|
34 |
|
|
#undef THIS_FILE
|
35 |
|
|
static char THIS_FILE[] = __FILE__;
|
36 |
|
|
#endif
|
37 |
|
|
|
38 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
// CLocalPropertiesDialog dialog
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
CLocalPropertiesDialog::CLocalPropertiesDialog(bool bHideX10Controls)
|
43 |
|
|
: CeCosDialog(IDD_TT_PROPERTIES2, NULL),
|
44 |
|
|
m_bHideX10Controls(bHideX10Controls)
|
45 |
|
|
{
|
46 |
|
|
//{{AFX_DATA_INIT(CLocalPropertiesDialog)
|
47 |
|
|
//}}AFX_DATA_INIT
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
void CLocalPropertiesDialog::DoDataExchange(CDataExchange* pDX)
|
52 |
|
|
{
|
53 |
|
|
CeCosDialog::DoDataExchange(pDX);
|
54 |
|
|
if(pDX->m_bSaveAndValidate){
|
55 |
|
|
m_bSerial=(TRUE==((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->GetCheck());
|
56 |
|
|
|
57 |
|
|
CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
|
58 |
|
|
int i=pCombo->GetCurSel();
|
59 |
|
|
pCombo->GetLBText(i, m_strPort.GetBuffer(pCombo->GetLBTextLen(i)));
|
60 |
|
|
m_strPort.ReleaseBuffer();
|
61 |
|
|
|
62 |
|
|
CString strBaud;
|
63 |
|
|
pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
|
64 |
|
|
i=pCombo->GetCurSel();
|
65 |
|
|
pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
|
66 |
|
|
strBaud.ReleaseBuffer();
|
67 |
|
|
m_nBaud=_ttoi(strBaud);
|
68 |
|
|
} else {
|
69 |
|
|
((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(m_bSerial);
|
70 |
|
|
((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(!m_bSerial);
|
71 |
|
|
SetButtons(true);
|
72 |
|
|
|
73 |
|
|
CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
|
74 |
|
|
if(pCombo->GetCount()>0){
|
75 |
|
|
int nSel=0;
|
76 |
|
|
for(int i=0;i<pCombo->GetCount();i++){
|
77 |
|
|
CString strPort;
|
78 |
|
|
pCombo->GetLBText(i, strPort.GetBuffer(pCombo->GetLBTextLen(i)));
|
79 |
|
|
strPort.ReleaseBuffer();
|
80 |
|
|
if(0==strPort.Compare(m_strPort)){
|
81 |
|
|
nSel=i;
|
82 |
|
|
break;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
pCombo->SetCurSel(nSel);
|
86 |
|
|
}
|
87 |
|
|
pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
|
88 |
|
|
int nSel=0;
|
89 |
|
|
for(int i=0;i<pCombo->GetCount();i++){
|
90 |
|
|
CString strBaud;
|
91 |
|
|
pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
|
92 |
|
|
strBaud.ReleaseBuffer();
|
93 |
|
|
if(m_nBaud==_ttoi(strBaud)){
|
94 |
|
|
nSel=i;
|
95 |
|
|
break;
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
pCombo->SetCurSel(nSel);
|
99 |
|
|
}
|
100 |
|
|
//{{AFX_DATA_MAP(CLocalPropertiesDialog)
|
101 |
|
|
DDX_Text(pDX, IDC_TT_LOCALTCPIPHOST, m_strLocalTCPIPHost);
|
102 |
|
|
DDX_Text(pDX, IDC_TT_LOCALTCPIPPORT, m_nLocalTCPIPPort);
|
103 |
|
|
DDV_MinMaxUInt(pDX, m_nLocalTCPIPPort, 1, 65535);
|
104 |
|
|
DDX_CBIndex(pDX, IDC_TT_RESET, m_nReset);
|
105 |
|
|
DDX_Text(pDX, IDC_TT_RESETSTRING, m_strReset);
|
106 |
|
|
//}}AFX_DATA_MAP
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
BEGIN_MESSAGE_MAP(CLocalPropertiesDialog, CeCosDialog)
|
111 |
|
|
//{{AFX_MSG_MAP(CLocalPropertiesDialog)
|
112 |
|
|
ON_BN_CLICKED(IDC_TT_RADIO_SERIAL, OnRadioSerial)
|
113 |
|
|
ON_BN_CLICKED(IDC_TT_RADIO_TCPIP, OnRadioTcpip)
|
114 |
|
|
ON_CBN_SELCHANGE(IDC_TT_RESET, OnSelchangeReset)
|
115 |
|
|
//}}AFX_MSG_MAP
|
116 |
|
|
END_MESSAGE_MAP()
|
117 |
|
|
|
118 |
|
|
/////////////////////////////////////////////////////////////////////////////
|
119 |
|
|
// CLocalPropertiesDialog message handlers
|
120 |
|
|
|
121 |
|
|
void CLocalPropertiesDialog::SetButtons(bool bFromDataExchange)
|
122 |
|
|
{
|
123 |
|
|
if(!bFromDataExchange){
|
124 |
|
|
UpdateData(TRUE);
|
125 |
|
|
}
|
126 |
|
|
GetDlgItem(IDC_TT_LOCAL_PORT)->EnableWindow(m_bSerial);
|
127 |
|
|
GetDlgItem(IDC_TT_BAUD)->EnableWindow(m_bSerial);
|
128 |
|
|
GetDlgItem(IDC_TT_LOCALTCPIPHOST)->EnableWindow(!m_bSerial);
|
129 |
|
|
GetDlgItem(IDC_TT_LOCALTCPIPPORT)->EnableWindow(!m_bSerial);
|
130 |
|
|
static const UINT arIDs[]={IDC_TT_RESETSTRING};
|
131 |
|
|
for(int i=0;i<sizeof arIDs/sizeof arIDs[0];i++){
|
132 |
|
|
GetDlgItem(arIDs[i])->EnableWindow(RESET_X10==m_nReset);
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
BOOL CLocalPropertiesDialog::OnInitDialog()
|
137 |
|
|
{
|
138 |
|
|
if(m_bHideX10Controls){
|
139 |
|
|
// Hide these controls:
|
140 |
|
|
static const UINT arIDs1[]={IDC_TT_STATIC_RESET, IDC_TT_STATIC_METHOD, IDC_TT_RESET};
|
141 |
|
|
for(int i=0;i<sizeof arIDs1/sizeof arIDs1[0];i++){
|
142 |
|
|
GetDlgItem(arIDs1[i])->ShowWindow(SW_HIDE);
|
143 |
|
|
}
|
144 |
|
|
// Move the bottom buttons up
|
145 |
|
|
CRect rect;
|
146 |
|
|
GetDlgItem(IDC_TT_STATIC_RESET)->GetWindowRect(rect);
|
147 |
|
|
ScreenToClient(rect);
|
148 |
|
|
int nTop=rect.top;
|
149 |
|
|
static const arIDs2[]={IDOK, IDCANCEL};
|
150 |
|
|
int nDelta=0;
|
151 |
|
|
for(i=0;i<sizeof arIDs2/sizeof arIDs2[0];i++){
|
152 |
|
|
CWnd *pWnd=GetDlgItem(arIDs2[i]);
|
153 |
|
|
pWnd->GetWindowRect(rect);
|
154 |
|
|
ScreenToClient(rect);
|
155 |
|
|
int nHeight=rect.Height();
|
156 |
|
|
nDelta=rect.top-nTop;
|
157 |
|
|
rect.top=nTop;
|
158 |
|
|
rect.bottom=rect.top+nHeight;
|
159 |
|
|
pWnd->MoveWindow(rect);
|
160 |
|
|
}
|
161 |
|
|
GetWindowRect(rect);
|
162 |
|
|
rect.bottom-=nDelta;
|
163 |
|
|
MoveWindow(rect);
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
CeCosDialog::OnInitDialog();
|
167 |
|
|
CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT);
|
168 |
|
|
TCHAR szPort[]=_T("COMx");
|
169 |
|
|
for(TCHAR c=_TCHAR('1');c<=_TCHAR('8');c++){
|
170 |
|
|
szPort[3]=c;
|
171 |
|
|
pCombo->AddString(szPort);
|
172 |
|
|
}
|
173 |
|
|
UpdateData(false); // because only now has the port combo been populated
|
174 |
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
175 |
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
void CLocalPropertiesDialog::OnRadioSerial()
|
179 |
|
|
{
|
180 |
|
|
((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(FALSE);
|
181 |
|
|
SetButtons();
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
void CLocalPropertiesDialog::OnRadioTcpip()
|
185 |
|
|
{
|
186 |
|
|
((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(FALSE);
|
187 |
|
|
SetButtons();
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
void CLocalPropertiesDialog::OnOK()
|
191 |
|
|
{
|
192 |
|
|
UpdateData();
|
193 |
|
|
|
194 |
|
|
HANDLE handle=CreateFile(m_strPort, GENERIC_READ ,0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL );
|
195 |
|
|
if(INVALID_HANDLE_VALUE!=handle){
|
196 |
|
|
CloseHandle(handle);
|
197 |
|
|
} else if (IDNO==MessageBox(_T("The currently selected serial port is not accessible. Use this setting anyway?"),NULL,MB_YESNO|MB_DEFBUTTON2)){
|
198 |
|
|
return;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
if(!m_bSerial && !CeCosSocket::IsLegalHostPort(CeCosSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort))){
|
202 |
|
|
MessageBox(_T("Please provide a valid host/port combination for TCP/IP connection"));
|
203 |
|
|
} else if (RESET_X10==m_nReset && m_strReset.IsEmpty()){
|
204 |
|
|
MessageBox(_T("Please provide a valid reset string for X10 reset"));
|
205 |
|
|
} else {
|
206 |
|
|
CeCosDialog::OnOK();
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
void CLocalPropertiesDialog::OnSelchangeReset()
|
211 |
|
|
{
|
212 |
|
|
SetButtons();
|
213 |
|
|
}
|