Garmin Fleet Management Controller  2.19.0
CCommErrorDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CCommErrorDlg.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CCommErrorDlg.h"
13 #include "CSelectCommPortDlg.h"
14 #include "CFmiPcAppDlg.h"
15 
16 IMPLEMENT_DYNAMIC( CCommErrorDlg, CDialog )
17 
18 BEGIN_MESSAGE_MAP( CCommErrorDlg, CDialog )
19  ON_BN_CLICKED( IDC_ERROR_BTN_EXIT, OnBnClickedExit )
20  ON_BN_CLICKED( IDC_ERROR_BTN_CHANGE_PORT, OnBnClickedChangeCom )
21  ON_BN_CLICKED( IDC_ERROR_BTN_RETRY, OnBnClickedRetry )
22 END_MESSAGE_MAP()
23 
24 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 CCommErrorDlg::CCommErrorDlg
35  (
36  TCHAR * aErrorMessage,
37  BOOL aIsPortDown,
38  CWnd * aParent,
39  FmiApplicationLayer & aCom
40  )
41  : CDialog( IDD_ERROR, aParent )
42  , mMessageText( _T("") )
43  , mCom( aCom )
44 {
45  mMessageText.Format( _T("%s"), aErrorMessage );
46  mComPortDown = aIsPortDown;
47 }
48 
49 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
53 {
54 }
55 
56 //----------------------------------------------------------------------
59 //----------------------------------------------------------------------
61  (
62  CDataExchange * aDataExchange
63  )
64 {
65  CDialog::DoDataExchange( aDataExchange );
66  DDX_Text( aDataExchange, IDC_ERROR_TXT_MESSAGE, mMessageText );
67 }
68 
69 //----------------------------------------------------------------------
77 //----------------------------------------------------------------------
79 {
80  CDialog::OnInitDialog();
81 
82  if( mComPortDown )
83  {
84  GetDlgItem( IDOK )->ShowWindow( SW_HIDE );
85  GetDlgItem( IDC_ERROR_BTN_EXIT )->ShowWindow( SW_SHOW );
86  GetDlgItem( IDC_ERROR_BTN_RETRY )->ShowWindow( SW_SHOW );
87  GetDlgItem( IDC_ERROR_BTN_CHANGE_PORT )->ShowWindow( SW_SHOW );
88  }
89  return TRUE;
90 } /* OnInitDialog() */
91 
92 //----------------------------------------------------------------------
96 //----------------------------------------------------------------------
98 {
99  EnumThreadWindows( GetCurrentThreadId(), OnCloseHelper, 0 );
100  mComPortDown = FALSE; //change so we can call OnCancel
101  OnCancel();
102 }
103 
104 //----------------------------------------------------------------------
113 //----------------------------------------------------------------------
114 BOOL CALLBACK CCommErrorDlg::OnCloseHelper
115  (
116  HWND hWndParent,
117  LPARAM /*lParam*/
118  )
119 {
120  ::SendMessage(hWndParent, WM_CLOSE, 0, 0);
121  return TRUE;
122 }
123 
124 //----------------------------------------------------------------------
128 //----------------------------------------------------------------------
130 {
131  if( !mComPortDown )
132  {
133  CDialog::OnCancel();
134  }
135 }
136 
137 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
143 {
144 #if( FMI_SUPPORT_A602 )
145  mCom.sendEnable();
146 #else
147  mCom.clearError();
148 #endif
149 
150  OnOK();
151 }
152 
153 //----------------------------------------------------------------------
157 //----------------------------------------------------------------------
159 {
160  CSelectCommPortDlg dlg( this );
161  if( IDOK == dlg.DoModal() )
162  {
164  }
165 }
166 
167 //----------------------------------------------------------------------
175 //----------------------------------------------------------------------
177 {
179  CDialog::PostNcDestroy();
180 }
181 
afx_msg void OnBnClickedRetry()
Click handler for the Retry button.
afx_msg void OnBnClickedChangeCom()
Click handler for the Change Port button.
void OnCancel()
Cancel action handler.
#define IDC_ERROR_BTN_RETRY
Definition: resource.h:226
virtual ~CCommErrorDlg()
Destructor.
#define IDC_ERROR_BTN_EXIT
Definition: resource.h:225
Modal dialog allowing the user to select the port to use to communicate with the client.
void PostNcDestroy()
Called by MFC after the window has been destroyed; performs final termination activities.
#define IDD_ERROR
Definition: resource.h:27
#define FALSE
Definition: garmin_types.h:46
#define IDC_ERROR_TXT_MESSAGE
Definition: resource.h:227
CString mMessageText
The message to display to the user.
Definition: CCommErrorDlg.h:54
void sendEnable(uint16 *aFeatureCodes=NULL, uint8 aFeatureCount=0)
Transmit an FMI Enable packet, and clear any error state.
static BOOL CALLBACK OnCloseHelper(HWND hWndParent, LPARAM lParam)
Helper for EnumThreadWindows call.
#define TRUE
Definition: garmin_types.h:45
BOOL OnInitDialog()
Initialize the dialog.
BOOL mComPortDown
If TRUE, communication is down and the serial port will need to be reinitialized to continue...
Definition: CCommErrorDlg.h:58
Serial communication controller for Garmin and FMI packets.
void clearError()
Clear any communication error.
Modal dialog displaying a communication error.
Definition: CCommErrorDlg.h:22
afx_msg void OnBnClickedExit()
Click handler for the Exit button.
#define IDC_ERROR_BTN_CHANGE_PORT
Definition: resource.h:224
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
FmiApplicationLayer & mCom
The FMI communication controller.
Definition: CCommErrorDlg.h:61
static void post(EventId aEventId, uint32 aEventData=0, void *aEventDataPtr=NULL, BOOL handleNow=FALSE)
Posts a message to all windows that have registered to get events.
Definition: Event.cpp:67