Garmin Fleet Management Controller  2.19.0
CGpiQueryDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CGpiQueryDlg.cpp
5 *
6 * Copyright 2008-2011 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CGpiQueryDlg.h"
13 #include "Event.h"
14 
15 IMPLEMENT_DYNAMIC( CGpiQueryDlg, CDialog )
16 
17 BEGIN_MESSAGE_MAP( CGpiQueryDlg, CDialog )
18  ON_BN_CLICKED( IDC_GPIQUERY_BTN_UPDATE, OnBnClickedUpdate )
19  ON_MESSAGE( WM_EVENT( EVENT_FMI_GPI_FILE_INFO_RECEIVED ), OnGpiInfoReceived )
20 END_MESSAGE_MAP()
21 
22 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 CGpiQueryDlg::CGpiQueryDlg
28  (
29  CWnd * aParent,
30  FmiApplicationLayer & aCom
31  )
32  : CDialog( IDD_GPI_QUERY, aParent )
33  , mCom( aCom )
34  , mFileVersion( _T("") )
35  , mFileSize( _T("") )
36 {
37 }
38 
39 //----------------------------------------------------------------------
41 //----------------------------------------------------------------------
43 {
44 }
45 
46 //----------------------------------------------------------------------
49 //----------------------------------------------------------------------
51  (
52  CDataExchange * aDataExchange
53  )
54 {
55  CDialog::DoDataExchange( aDataExchange );
56  DDX_Text( aDataExchange, IDC_GPIQUERY_TXT_VERSION, mFileVersion );
57  DDX_Text( aDataExchange, IDC_GPIQUERY_TXT_SIZE, mFileSize );
58 }
59 
60 //----------------------------------------------------------------------
66 //----------------------------------------------------------------------
68 {
69  CDialog::OnInitDialog();
70 
72  return TRUE;
73 } /* OnInitDialog() */
74 
75 //----------------------------------------------------------------------
79 //----------------------------------------------------------------------
81 {
83 } /* OnBnClickedUpdate() */
84 
85 //----------------------------------------------------------------------
91 //----------------------------------------------------------------------
92 afx_msg LRESULT CGpiQueryDlg::OnGpiInfoReceived( WPARAM, LPARAM )
93 {
94  TCHAR versionString[33]; // 2 * 16 bytes + null terminator
95  char versionHex[33];
96  uint8 versionLength = minval( mCom.mFileVersionLength, 16 );
97 
98  memset( versionString, 0, sizeof( versionString ) );
99  mFileSize.Format( _T(" %d"), mCom.mFileSize );
100  if( UTIL_data_is_printable( (const char*)mCom.mFileVersion, versionLength ) )
101  {
102  MultiByteToWideChar( mCom.mClientCodepage, 0, (char*)mCom.mFileVersion, -1, versionString, versionLength );
103  mFileVersion.Format( _T(" %s"), versionString );
104  }
105  else
106  {
107  memset( versionHex, 0, sizeof( versionHex ) );
108  UTIL_uint8_to_hex( mCom.mFileVersion, versionHex, versionLength );
109  MultiByteToWideChar( mCom.mClientCodepage, 0, versionHex, -1, versionString, sizeof( versionString ) );
110  mFileVersion.Format( _T(" 0x%s"), versionString );
111  }
112  UpdateData( FALSE );
113 
114  return 0;
115 } /* OnGpiInfoReceived() */
CString mFileSize
Contents of the File Size text box.
Definition: CGpiQueryDlg.h:56
Modal dialog allowing the user to query the file version and size of the FMI GPI file on the client d...
Definition: CGpiQueryDlg.h:25
uint8 mFileVersionLength
Number of significant bytes in mFileVersion.
FmiApplicationLayer & mCom
Reference to the FMI communication controller.
Definition: CGpiQueryDlg.h:50
virtual ~CGpiQueryDlg()
Destructor.
#define FALSE
Definition: garmin_types.h:46
#define TRUE
Definition: garmin_types.h:45
afx_msg void OnBnClickedUpdate()
Click handler for the Update button.
#define minval(_x, _y)
The smaller of _x and _y.
Definition: util_macros.h:95
codepage_type mClientCodepage
Code page used for encoding of text fields when communicating with the client.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
Serial communication controller for Garmin and FMI packets.
void UTIL_uint8_to_hex(const uint8 *aData, char *aOutput, uint8 aNumBytes)
Convert from binary to a hexadecimal string.
Definition: util.cpp:376
#define IDC_GPIQUERY_TXT_SIZE
Definition: resource.h:235
uint8 mFileVersion[16]
file version (FMI_GPI_FILE_INFORMATION)
bool UTIL_data_is_printable(const char *aData, int aLength)
Determine whether an array of characters consists only of printable ASCII.
Definition: util.cpp:471
uint32 mFileSize
file size (FMI_GPI_FILE_INFORMATION)
#define IDC_GPIQUERY_TXT_VERSION
Definition: resource.h:236
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
#define IDC_GPIQUERY_BTN_UPDATE
Definition: resource.h:232
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
#define IDD_GPI_QUERY
Definition: resource.h:29
void sendGpiFileInfoRequest()
Send a GPI File Information Request to the client.
BOOL OnInitDialog()
Initialize the dialog.
CString mFileVersion
Contents of the File Version text box.
Definition: CGpiQueryDlg.h:53
afx_msg LRESULT OnGpiInfoReceived(WPARAM, LPARAM)
Handler for the GPI Information Received event.