Garmin Fleet Management Controller  2.19.0
CDriverIdAndStatusDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CDriverIdAndStatusDlg.cpp
5 *
6 * Copyright 2008-2012 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CDriverIdAndStatusDlg.h"
13 #include "Event.h"
14 #include "util.h"
15 #include "CDriverLoginDlg.h"
16 
17 using namespace std;
18 
19 IMPLEMENT_DYNAMIC( CDriverIdAndStatusDlg, CDialog )
20 
21 BEGIN_MESSAGE_MAP( CDriverIdAndStatusDlg, CDialog )
22  ON_WM_TIMER()
23  ON_EN_CHANGE( IDC_DRVRINFO_EDIT_NEW_ID, OnEnChangeEditDriverId )
24  ON_BN_CLICKED( IDC_DRVRINFO_BTN_SEND_STATUS, OnBnClickedSendDriverStatus )
25  ON_BN_CLICKED( IDC_DRVRINFO_BTN_SEND_ID, OnBnClickedSendDriverId )
26  ON_BN_CLICKED( IDC_DRVRINFO_BTN_GET_ID, OnBnClickedRefreshDriverId )
27  ON_BN_CLICKED( IDC_DRVRINFO_BTN_GET_STATUS, OnBnClickedRefreshDriverStatus )
28  ON_EN_CHANGE( IDC_DRVRINFO_EDIT_STATUS_ID, OnEnChangeEditSet )
29  ON_EN_CHANGE( IDC_DRVRINFO_EDIT_STATUS_TEXT, OnEnChangeEditSet )
30  ON_BN_CLICKED( IDC_DRVRINFO_BTN_DELETE_STATUS, OnBnClickedDelete )
31  ON_BN_CLICKED( IDC_DRVRINFO_BTN_ADD_STATUS, OnBnClickedSendDriverStatusItem )
32  ON_BN_CLICKED( IDOK, OnBnClickedOk )
33  ON_CBN_SELENDOK( IDC_DRVRINFO_CBO_IDX, OnIndexChanged )
34  ON_EN_SETFOCUS( IDC_DRVRINFO_EDIT_NEW_ID, OnEnSetfocusDriverIdEdit )
35  ON_EN_KILLFOCUS( IDC_DRVRINFO_EDIT_NEW_ID, OnEnKillfocusDriverIdEdit )
36  ON_EN_SETFOCUS( IDC_DRVRINFO_EDIT_STATUS_TEXT, OnEnSetfocusStatusEdit )
37  ON_EN_KILLFOCUS( IDC_DRVRINFO_EDIT_STATUS_TEXT, OnEnKillfocusStatusEdit )
38  ON_EN_SETFOCUS( IDC_DRVRINFO_EDIT_STATUS_ID, OnEnSetfocusStatusEdit )
39  ON_EN_KILLFOCUS( IDC_DRVRINFO_EDIT_STATUS_ID, OnEnKillfocusStatusEdit )
40  ON_LBN_SELCHANGE( IDC_DRVRINFO_LST_STATUS, OnLbnSelchangeStatuslist )
41  ON_MESSAGE( WM_EVENT( EVENT_FMI_DRIVER_ID_CHANGED ), OnDriverIdChanged )
42  ON_MESSAGE( WM_EVENT( EVENT_FMI_DRIVER_STATUS_CHANGED ), OnDriverStatusChanged )
43  ON_MESSAGE( WM_EVENT( EVENT_FMI_DRIVER_STATUS_LIST_CHANGED ), OnDriverStatusListChanged )
44 #if( FMI_SUPPORT_A607 )
45  ON_BN_CLICKED( IDC_DRVRINFO_BTN_EDIT_LOGINS, OnBnClickedEditLogins )
46 #endif
47 END_MESSAGE_MAP()
48 
49 //----------------------------------------------------------------------
53 //----------------------------------------------------------------------
54 CDriverIdAndStatusDlg::CDriverIdAndStatusDlg
55  (
56  CWnd * aParent,
57  FmiApplicationLayer & aCom
58  )
59  : CDialog( IDD_DRIVER_ID_STATUS, aParent )
60  , mCom( aCom )
61  , mCurrentDriverId( _T("") )
62  , mCurrentDriverStatus( _T("") )
63  , mNewDriverId( _T("") )
64  , mSelectedListIndex( 0 )
65  , mNewDriverStatusId( _T("") )
66  , mNewDriverStatusText( _T("") )
67  , mIndex( 0 )
68 {
69 }
70 
71 //----------------------------------------------------------------------
73 //----------------------------------------------------------------------
75 {
76 }
77 
78 //----------------------------------------------------------------------
81 //----------------------------------------------------------------------
83  (
84  CDataExchange * aDataExchange
85  )
86 {
87  CDialog::DoDataExchange( aDataExchange );
88  DDX_Text( aDataExchange, IDC_DRVRINFO_TXT_CURRENT_ID, mCurrentDriverId );
89  DDX_Text( aDataExchange, IDC_DRVRINFO_TXT_CURRENT_STATUS, mCurrentDriverStatus );
90  DDX_Text( aDataExchange, IDC_DRVRINFO_EDIT_NEW_ID, mNewDriverId );
91  DDX_CBIndex( aDataExchange, IDC_DRVRINFO_CBO_IDX, mIndex );
92  DDX_Control( aDataExchange, IDC_DRVRINFO_LST_STATUS, mDriverStatusList );
93  DDX_LBIndex( aDataExchange, IDC_DRVRINFO_LST_STATUS, mSelectedListIndex );
94  DDX_Text( aDataExchange, IDC_DRVRINFO_EDIT_STATUS_ID, mNewDriverStatusId );
95  DDX_Text( aDataExchange, IDC_DRVRINFO_EDIT_STATUS_TEXT, mNewDriverStatusText );
96 }
97 
98 //----------------------------------------------------------------------
104 //----------------------------------------------------------------------
106 {
107  CDialog::OnInitDialog();
108 
109  updateListBox();
110 #if( FMI_SUPPORT_A607 )
111  if( mCom.mUseMultipleDrivers )
112  {
113  GetDlgItem( IDC_DRVRINFO_LBL_IDX )->EnableWindow( TRUE );
114  GetDlgItem( IDC_DRVRINFO_CBO_IDX )->EnableWindow( TRUE );
115 
116  for( uint8 i = 0; i < FMI_DRIVER_COUNT; i++ )
117  {
118  mCom.sendA607DriverIdRequest( i );
119  mCom.sendA607DriverStatusRequest( i );
120  }
121  }
122  else
123 #endif
124  {
125  GetDlgItem( IDC_DRVRINFO_LBL_IDX )->EnableWindow( FALSE );
126  GetDlgItem( IDC_DRVRINFO_CBO_IDX )->EnableWindow( FALSE );
127  mCom.sendDriverIdRequest();
128  mCom.sendDriverStatusRequest();
129  }
130 
131  SetWindowPos( NULL, 250, 600, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
132  return TRUE;
133 } /* OnInitDialog() */
134 
135 //----------------------------------------------------------------------
138 //----------------------------------------------------------------------
140 {
141  FileBackedMap<ClientListItem>::const_iterator it = mCom.mDriverStatuses.begin();
142  CString listItem;
143 
144  //must keep track of where the list was scrolled to
145  //since we reset content we must reinitialize these
146  int selectedIndex = mDriverStatusList.GetCurSel();
147  int topIndex = mDriverStatusList.GetTopIndex();
148 
149  mDriverStatusList.ResetContent();
150  //loop through ids and add to status list
151  for(; it != mCom.mDriverStatuses.end(); it++ )
152  {
153  if( it->second.isValid() )
154  {
155  listItem.Format( _T("%d - %s"), it->first, it->second.getCurrentName() );
156  mDriverStatusList.AddString( listItem );
157  }
158  }
159 
160  //reset scroll and selection
161  mDriverStatusList.SetCurSel( selectedIndex );
162  mDriverStatusList.SetTopIndex( topIndex );
163 } /* updateListBox() */
164 
165 //----------------------------------------------------------------------
169 //----------------------------------------------------------------------
170 afx_msg LPARAM CDriverIdAndStatusDlg::OnDriverStatusListChanged( WPARAM, LPARAM )
171 {
172  updateListBox();
173 
174  return 0;
175 }
176 
177 //----------------------------------------------------------------------
182 //----------------------------------------------------------------------
184  (
185  WPARAM aIndex,
186  LPARAM
187  )
188 {
189  if( aIndex == (WPARAM) mIndex )
190  {
191  //This displays the driver ID, but does
192  //not request it.
193  //When the dialog is initialized, it requests both.
194  //The client should send messages to mCom if they are updated.
195  TCHAR driverId[50];
196  MultiByteToWideChar( mCom.mClientCodepage, 0, mCom.mDriverId[ aIndex ], -1, driverId, 50 );
197  driverId[49] = '\0';
198  mCurrentDriverId.Format( _T("%s"), driverId );
199  UpdateData( FALSE );
200  }
201 
202  return 0;
203 }
204 
205 //----------------------------------------------------------------------
210 //----------------------------------------------------------------------
211 afx_msg LPARAM CDriverIdAndStatusDlg::OnDriverStatusChanged( WPARAM aIndex, LPARAM )
212 {
213  if( aIndex == (WPARAM) mIndex )
214  {
215  //This displays the driver status, but does
216  //not request it.
217  //When the dialog is initialized, it requests both.
218  //The client should send messages to mCom if they are updated.
219  TCHAR driverStatus[50];
220  MultiByteToWideChar( mCom.mClientCodepage, 0, mCom.mDriverStatus[ aIndex ], -1, driverStatus, 50 );
221  driverStatus[49] = '\0';
222  mCurrentDriverStatus.Format( _T(" %s"), driverStatus );
223  UpdateData( FALSE );
224  }
225 
226  return 0;
227 } /* OnDriverStatusListChanged() */
228 
229 //----------------------------------------------------------------------
234 //----------------------------------------------------------------------
236 {
237  UpdateData( TRUE );
238  if( mNewDriverId != "" )
239  GetDlgItem( IDC_DRVRINFO_BTN_SEND_ID )->EnableWindow( TRUE );
240  else
241  GetDlgItem( IDC_DRVRINFO_BTN_SEND_ID )->EnableWindow( FALSE );
242 } /* OnEnChangeEditDriverId() */
243 
244 //----------------------------------------------------------------------
250 //----------------------------------------------------------------------
252 {
253  int selectedIndex = mDriverStatusList.GetCurSel();
254  if( selectedIndex >= 0 && selectedIndex < mDriverStatusList.GetCount() )
255  {
256  uint32 driverStatusId = mCom.mDriverStatuses.getKeyAt( selectedIndex );
257  ClientListItem& driverStatusItem = mCom.mDriverStatuses.get( driverStatusId );
258 
259  mNewDriverStatusId.Format( _T("%u"), driverStatusId );
260  mNewDriverStatusText.Format( _T("%s"), driverStatusItem.getCurrentName() );
261  UpdateData( FALSE );
262  GetDlgItem( IDC_DRVRINFO_BTN_DELETE_STATUS )->EnableWindow( TRUE );
263  }
264  else
265  {
266  GetDlgItem( IDC_DRVRINFO_BTN_DELETE_STATUS )->EnableWindow( FALSE );
267  }
268  mDriverStatusList.SetCurSel( selectedIndex );
269 }
270 
271 //----------------------------------------------------------------------
274 //----------------------------------------------------------------------
276 {
277  UpdateData( TRUE );
278  if( mSelectedListIndex >= 0 )
279  {
280  uint32 driverStatusId = mCom.mDriverStatuses.getKeyAt( mSelectedListIndex );
281 #if( FMI_SUPPORT_A607 )
282  mCom.sendA607DriverStatusUpdate( driverStatusId, (uint8) mIndex );
283 #else
284  mCom.sendDriverStatusUpdate( driverStatusId );
285 #endif
286  }
287 } /* OnBnClickedSendDriverStatus() */
288 
289 //----------------------------------------------------------------------
292 //----------------------------------------------------------------------
294 {
295  char driverId[50];
296 
297  UpdateData( TRUE );
298  WideCharToMultiByte( mCom.mClientCodepage, 0, mNewDriverId, -1, driverId, 50, NULL, NULL );
299  driverId[49] = '\0';
300 #if( FMI_SUPPORT_A607 )
301  mCom.sendA607DriverIdUpdate( driverId, (uint8) mIndex );
302 #else
303  mCom.sendDriverIdUpdate( driverId );
304 #endif
305 } /* OnBnClickedSendDriverId */
306 
307 //----------------------------------------------------------------------
310 //----------------------------------------------------------------------
312 {
313 #if( FMI_SUPPORT_A607 )
314  if( mCom.mUseMultipleDrivers )
315  {
316  mCom.sendA607DriverIdRequest( (uint8) mIndex );
317  }
318  else
319 #endif
320  {
321  mCom.sendDriverIdRequest();
322  }
323 } /* OnBnClickedRefreshDriverId() */
324 
325 //----------------------------------------------------------------------
328 //----------------------------------------------------------------------
330 {
331 #if( FMI_SUPPORT_A607 )
332  if( mCom.mUseMultipleDrivers )
333  {
334  mCom.sendA607DriverStatusRequest( (uint8) mIndex );
335  }
336  else
337 #endif
338  {
339  mCom.sendDriverStatusRequest();
340  }
341 } /* OnBnClickedRefreshDriverStatus() */
342 
343 //----------------------------------------------------------------------
349 //----------------------------------------------------------------------
351 {
352  BOOL fieldsValid = TRUE;
353 #if !SKIP_VALIDATION
354  char idBuffer[11];
355  UpdateData( TRUE );
356 
357  memset( idBuffer, 0, sizeof( idBuffer ) );
358  if( 0 == WideCharToMultiByte
359  (
360  CP_ACP,
361  0,
362  mNewDriverStatusId.GetBuffer(),
363  mNewDriverStatusId.GetLength(),
364  idBuffer,
365  sizeof( idBuffer ),
366  NULL, NULL
367  ) )
368  {
369  fieldsValid = FALSE;
370  }
371  else if( !UTIL_data_is_uint32( idBuffer ) )
372  {
373  fieldsValid = FALSE;
374  }
375 
376  if( mNewDriverStatusText.GetLength() == 0 ||
377  mNewDriverStatusText.GetLength() >= 50 )
378  {
379  fieldsValid = FALSE;
380  }
381 #endif
382  GetDlgItem( IDC_DRVRINFO_BTN_ADD_STATUS )->EnableWindow( fieldsValid );
383 } /* OnEnChangeEditSet() */
384 
385 //----------------------------------------------------------------------
389 //----------------------------------------------------------------------
391 {
392  UpdateData( TRUE );
393  if( mSelectedListIndex >= 0 && (uint32) mSelectedListIndex < mCom.mDriverStatuses.validCount() )
394  {
395  uint32 driverStatusId = mCom.mDriverStatuses.getKeyAt( mSelectedListIndex );
396  mCom.sendDeleteDriverStatusListItem( driverStatusId );
397  }
398 } /* OnBnClickedDelete() */
399 
400 //----------------------------------------------------------------------
405 //----------------------------------------------------------------------
407 {
408  UpdateData( TRUE );
409  uint32 id = _tstoi( mNewDriverStatusId.GetBuffer() );
410 
411  mCom.sendDriverStatusListItem( id, mNewDriverStatusText );
412 } /* OnBnClickedSendDriverStatusItem() */
413 
414 //----------------------------------------------------------------------
417 //----------------------------------------------------------------------
419 {
420  DestroyWindow();
421 } /* OnBnClickedOk */
422 
423 //----------------------------------------------------------------------
426 //----------------------------------------------------------------------
428 {
429  UpdateData( TRUE );
430  OnDriverIdChanged( mIndex, NULL );
431  OnDriverStatusChanged( mIndex, NULL );
432 } /* OnIndexChanged */
433 
434 //----------------------------------------------------------------------
437 //----------------------------------------------------------------------
439 {
440  DestroyWindow();
441 } /* OnCancel */
442 
443 //----------------------------------------------------------------------
445 //----------------------------------------------------------------------
447 {
448  CDialog::PostNcDestroy();
450 } /* PostNcDestroy() */
451 
452 //----------------------------------------------------------------------
456 //----------------------------------------------------------------------
458 {
459  SendMessage( DM_SETDEFID, IDC_DRVRINFO_BTN_SEND_ID );
460 }
461 
462 //----------------------------------------------------------------------
466 //----------------------------------------------------------------------
468 {
469  SendMessage( DM_SETDEFID, IDOK );
470 }
471 
472 //----------------------------------------------------------------------
477 //----------------------------------------------------------------------
479 {
480  SendMessage( DM_SETDEFID, IDC_DRVRINFO_BTN_ADD_STATUS );
481 }
482 
483 //----------------------------------------------------------------------
487 //----------------------------------------------------------------------
489 {
490  SendMessage( DM_SETDEFID, IDOK );
491 }
492 
493 #if( FMI_SUPPORT_A607 )
494 //----------------------------------------------------------------------
497 //----------------------------------------------------------------------
499 {
500  CDriverLoginDlg * dlg = new CDriverLoginDlg( this, mCom );
501  dlg->Create( IDD_DRIVER_LOGINS );
502  dlg->ShowWindow( SW_SHOW );
503 }
504 #endif
afx_msg void OnIndexChanged()
Selection handler for the driver index combo.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
const_iterator begin()
Iterator positioned at the first element in the map.
Definition: FileBackedMap.h:59
#define IDC_DRVRINFO_EDIT_NEW_ID
Definition: resource.h:203
afx_msg LPARAM OnDriverIdChanged(WPARAM aIndex, LPARAM)
Event handler for the FMI_EVENT_DRIVER_ID_CHANGED event generated by FmiApplicationLayer.
afx_msg void OnBnClickedEditLogins()
Click handler for the Driver Logins button.
#define IDC_DRVRINFO_LST_STATUS
Definition: resource.h:220
#define IDC_DRVRINFO_BTN_EDIT_LOGINS
Definition: resource.h:223
#define IDC_DRVRINFO_TXT_CURRENT_STATUS
Definition: resource.h:222
afx_msg void OnEnKillfocusStatusEdit()
Kill Focus handler for the Driver Status edit box.
void updateListBox()
Update the driver status list box from the map of items owned by FmiApplicationLayer.
bool UTIL_data_is_uint32(const char *aData)
Determine whether an array of characters consists only of numeric, and that the value when converted ...
Definition: util.cpp:495
#define IDC_DRVRINFO_TXT_CURRENT_ID
Definition: resource.h:221
CString getCurrentName() const
Get the current name of this item.
STL namespace.
afx_msg void OnEnChangeEditSet()
Edit handler for the Add/Update Status group.
#define IDC_DRVRINFO_BTN_ADD_STATUS
Definition: resource.h:196
afx_msg void OnBnClickedSendDriverStatus()
Click handler for the Send (Driver Status) button.
afx_msg void OnEnSetfocusStatusEdit()
Set Focus handler for the Add/Update Status edit boxes.
const_iterator end()
Iterator positioned after the last element in the map.
Definition: FileBackedMap.h:67
afx_msg void OnBnClickedRefreshDriverStatus()
Click handler for the Refresh (Driver Status) button.
#define FALSE
Definition: garmin_types.h:46
#define IDC_DRVRINFO_EDIT_STATUS_ID
Definition: resource.h:204
#define TRUE
Definition: garmin_types.h:45
afx_msg void OnLbnSelchangeStatuslist()
Selection Changed event handler for the status list.
#define IDC_DRVRINFO_CBO_IDX
Definition: resource.h:202
#define IDC_DRVRINFO_BTN_DELETE_STATUS
Definition: resource.h:197
afx_msg void OnBnClickedSendDriverId()
Click handler for the Send (Driver ID) button.
afx_msg void OnBnClickedSendDriverStatusItem()
Click handler for the Send (Driver Status Item) button.
#define FMI_DRIVER_COUNT
Number of supported drivers.
Definition: fmi.h:147
Serial communication controller for Garmin and FMI packets.
Modeless dialog allowing the user to query and update Driver ID and Status on the client...
Stores the name associated with a list item that is sent to the client.
BOOL OnInitDialog()
Initialize the dialog.
#define IDC_DRVRINFO_EDIT_STATUS_TEXT
Definition: resource.h:205
void PostNcDestroy()
Perform final cleanup after the dialog window is destroyed.
afx_msg void OnBnClickedDelete()
Click handler for the Delete (Driver Status Item) button.
#define IDC_DRVRINFO_BTN_SEND_ID
Definition: resource.h:200
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
afx_msg void OnBnClickedOk()
Click handler for the OK (Close) button.
#define IDC_DRVRINFO_LBL_IDX
Definition: resource.h:214
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
afx_msg void OnCancel()
Handles the Cancel action.
afx_msg LPARAM OnDriverStatusListChanged(WPARAM, LPARAM)
Event handler for the FMI_EVENT_DRIVER_STATUS_LIST_CHANGED event generated by FmiApplicationLayer.
#define IDC_DRVRINFO_BTN_GET_STATUS
Definition: resource.h:199
Dialog allowing the user to manage canned responses.
#define IDD_DRIVER_LOGINS
Definition: resource.h:47
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
afx_msg LPARAM OnDriverStatusChanged(WPARAM aIndex, LPARAM)
Event handler for the FMI_EVENT_DRIVER_STATUS_CHANGED event generated by FmiApplicationLayer.
afx_msg void OnEnKillfocusDriverIdEdit()
Kill Focus handler for the Driver ID edit box.
afx_msg void OnBnClickedRefreshDriverId()
Click handler for the Refresh (Driver ID) button.
#define IDC_DRVRINFO_BTN_SEND_STATUS
Definition: resource.h:201
afx_msg void OnEnChangeEditDriverId()
Edit event handler for the Driver ID edit box.
#define IDC_DRVRINFO_BTN_GET_ID
Definition: resource.h:198
virtual ~CDriverIdAndStatusDlg()
Destructor.
#define IDD_DRIVER_ID_STATUS
Definition: resource.h:26
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
afx_msg void OnEnSetfocusDriverIdEdit()
Set Focus handler for the Driver ID edit box.