Garmin Fleet Management Controller  2.19.0
CSelectCommPortDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CSelectCommPortDlg.cpp
5 *
6 * Copyright 2008-2016 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CSelectCommPortDlg.h"
13 #include "SerialPort.h"
14 #include "TcpIpPort.h"
15 
16 IMPLEMENT_DYNAMIC( CSelectCommPortDlg, CDialog )
17 
18 BEGIN_MESSAGE_MAP( CSelectCommPortDlg, CDialog )
19  ON_BN_CLICKED( IDOK, OnBnClickedOk )
20  ON_BN_CLICKED( IDCANCEL, OnBnClickedCancel )
21 END_MESSAGE_MAP()
22 
23 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 CSelectCommPortDlg::CSelectCommPortDlg
28  (
29  CWnd * aParent
30  )
31  : CDialog( IDD_SELECT_PORT, aParent )
32  , mSelectedPortIndex( 0 )
33 {
34 }
35 
36 //----------------------------------------------------------------------
38 //----------------------------------------------------------------------
40 {
41 }
42 
43 //----------------------------------------------------------------------
46 //----------------------------------------------------------------------
48  (
49  CDataExchange * aDataExchange
50  )
51 {
52  CDialog::DoDataExchange( aDataExchange );
53 
54  DDX_CBIndex( aDataExchange, IDC_COMPORT_CBO_PORT, mSelectedPortIndex );
55 }
56 
57 //----------------------------------------------------------------------
65 //----------------------------------------------------------------------
67 {
68  CDialog::OnInitDialog();
69  CComboBox * portList = (CComboBox *)GetDlgItem( IDC_COMPORT_CBO_PORT );
70  portList->ResetContent();
71 
72  std::list<CString> portNames;
73  SerialPort::getPortList( portNames );
74 
75  std::list<CString>::const_iterator iter;
76  for( iter = portNames.begin(); iter != portNames.end(); iter++ )
77  {
78  portList->AddString( iter->GetString() );
79  }
80 
81  portList->SetCurSel( 0 );
82 
83  return TRUE;
84 } /* OnInitDialog() */
85 
86 //----------------------------------------------------------------------
89 //----------------------------------------------------------------------
91 {
92  UpdateData( TRUE );
93  CComboBox * portList = (CComboBox *)GetDlgItem( IDC_COMPORT_CBO_PORT );
94  CString portName;
95 
96  portList->GetLBText( mSelectedPortIndex, portName );
97 
98  CString tcpSocket( TCP_PORT_NAME );
99  if( portName.Compare( tcpSocket ) == 0 )
100  {
101  // Open TCP Port
102  if( TcpIpPort::initTcpPort() )
103  {
104  OnOK();
105  }
106  else
107  {
108  ::MessageBox( m_hWnd, SerialPort::getInstance()->getLastError(), _T("Error"), MB_OK );
109  }
110  }
111  else
112  {
113  if( SerialPort::initSerialPort( portName ) )
114  {
115  OnOK();
116  }
117  else
118  {
119  ::MessageBox( m_hWnd, SerialPort::getInstance()->getLastError(), _T("Error"), MB_OK );
120  }
121  }
122 } /* OnBnClickedOk() */
123 
124 //----------------------------------------------------------------------
127 //----------------------------------------------------------------------
129 {
130  OnCancel();
131 }
#define TCP_PORT_NAME
Definition: SerialPort.h:23
static bool initSerialPort(const CString &aPortName)
Initializes the port passed in.
Definition: SerialPort.cpp:96
afx_msg void OnBnClickedCancel()
Click handler for the Cancel button.
virtual ~CSelectCommPortDlg()
Destructor.
Modal dialog allowing the user to select the port to use to communicate with the client.
#define TRUE
Definition: garmin_types.h:45
afx_msg void OnBnClickedOk()
Click handler for the OK button.
BOOL OnInitDialog()
Initialize the dialog.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
#define IDD_SELECT_PORT
Definition: resource.h:35
static SerialPort * getInstance()
Get the one and only serial port object.
Definition: SerialPort.cpp:36
static void getPortList(std::list< CString > &aList)
Get the list of serial ports.
Definition: SerialPort.cpp:60
#define IDC_COMPORT_CBO_PORT
Definition: resource.h:184
static bool initTcpPort()
Definition: TcpIpPort.cpp:23
int mSelectedPortIndex
Index of the selected port in the drop down.