Garmin Fleet Management Controller  2.19.0
CTxtMsgNewDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CTxtMsgNewDlg.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 "CTxtMsgNewDlg.h"
14 
15 IMPLEMENT_DYNAMIC( CTxtMsgNewDlg, CDialog )
16 
17 BEGIN_MESSAGE_MAP( CTxtMsgNewDlg, CDialog )
18  ON_BN_CLICKED( IDOK, OnBnClickedOk )
19  ON_CBN_SELCHANGE( IDC_MSGNEW_CBO_PROTOCOL, OnCbnSelChangeMsgProtocol )
20  ON_EN_CHANGE( IDC_MSGNEW_EDIT_MSG_ID, OnEnChangeEditFields )
21  ON_EN_CHANGE( IDC_MSGNEW_EDIT_MESSAGE_TEXT, OnEnChangeEditFields )
22 END_MESSAGE_MAP()
23 
24 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
29 CTxtMsgNewDlg::CTxtMsgNewDlg
30  (
31  CWnd * aParent,
32  FmiApplicationLayer & aCom
33  )
34  : CDialog( IDD_TXT_MSG_NEW, aParent )
35  , mCom( aCom )
36  , mMessageText( _T("") )
37  , mMessageProtocol( 0 )
38 #if FMI_SUPPORT_A602
39  , mMessageId( _T("") )
40 #endif
41 #if FMI_SUPPORT_A604
42  , mMessageType( A604_MESSAGE_TYPE_NORMAL )
43  , mDisplayImmediately( FALSE )
44 #endif
45 {
46 }
47 
48 //----------------------------------------------------------------------
50 //----------------------------------------------------------------------
52 {
53 }
54 
55 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
60  (
61  CDataExchange * aDataExchange
62  )
63 {
64  CDialog::DoDataExchange( aDataExchange );
65  DDX_Text( aDataExchange, IDC_MSGNEW_EDIT_MESSAGE_TEXT, mMessageText );
66  DDX_CBIndex( aDataExchange, IDC_MSGNEW_CBO_PROTOCOL, mMessageProtocol );
67 #if FMI_SUPPORT_A602
68  DDX_Text( aDataExchange, IDC_MSGNEW_EDIT_MSG_ID, mMessageId );
69 #endif
70 #if( FMI_SUPPORT_A604 )
71  DDX_Check( aDataExchange, IDC_MSGNEW_CHK_DISP_IMMED, mDisplayImmediately );
72 #endif
73 }
74 
75 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
82 {
83  CDialog::OnInitDialog();
84 
85  CComboBox * comboBox = (CComboBox *)GetDlgItem( IDC_MSGNEW_CBO_PROTOCOL );
86 
87 // This must match the MessageProtocolType private enum.
88 #if( FMI_SUPPORT_A611 )
89  comboBox->AddString( _T("A611 - Long Text Message") );
90  comboBox->AddString( _T("A611 - Canned Response Long Text Message") );
91 #endif
92 #if( FMI_SUPPORT_A604 )
93  comboBox->AddString( _T("A604 - Open Text Message") );
94  comboBox->AddString( _T("A604 - Canned Response Text Message") );
95 #endif
96 #if( FMI_SUPPORT_A602 )
97  comboBox->AddString( _T("A602 - Open Text Message") );
98  comboBox->AddString( _T("A602 - Simple Okay Acknowledge") );
99  comboBox->AddString( _T("A602 - Yes/No Confirmation") );
100 #endif
101 #if( FMI_SUPPORT_LEGACY )
102  comboBox->AddString( _T("Legacy Text Message") );
103 #endif
104 
105  ASSERT( comboBox->GetCount() == MESSAGE_PROTOCOL_CNT );
106  comboBox->SetCurSel( 0 );
107  updateDlgFields( 0 );
108 
109 return TRUE;
110 } /* OnInitDialog() */
111 
112 //----------------------------------------------------------------------
119 //----------------------------------------------------------------------
121 {
122  UpdateData( TRUE );
123  char messageText[TEXT_MSG_BUFFER_MAX_SIZE];
124  uint32 maxLength = TEXT_MSG_MAX_SIZE;
125 
126 #if( FMI_SUPPORT_A602 )
127  MessageId messageId;
128 #endif
129 
130 #if( FMI_SUPPORT_A611 )
133  {
134  maxLength = LONG_TEXT_MSG_MAX_SIZE;
135  }
136 #endif
137 
138  WideCharToMultiByte( mCom.mClientCodepage, 0, mMessageText.GetBuffer(), -1, messageText, maxLength, NULL, NULL );
139  messageText[maxLength - 1] = '\0';
140 
141 #if( FMI_SUPPORT_A602 )
142  messageId = MessageId( mMessageId, mCom.mClientCodepage );
143 #endif
144 
145 #if( FMI_SUPPORT_A602 )
146  // if message ID was left blank for a protocol that has a
147  // message ID, ask the user to confirm that a blank message
148  // ID is really desired; if the user selects No, don't send
149  // the message
150  if( 0 == messageId.getIdSize() &&
151  (
152 #if( FMI_SUPPORT_A611 )
155 #endif
156 #if( FMI_SUPPORT_A604 )
159 #endif
162  ) )
163  {
164  int response;
165  response = MessageBox
166  (
167  _T("The message ID field is empty. If you continue, message status will not be available for this message. Do you want to continue?"),
168  _T("Message ID Is Empty"),
169  MB_YESNO
170  );
171  if( IDNO == response )
172  {
173  return;
174  }
175  }
176 #endif
177 
178 #if( FMI_SUPPORT_A604 )
179  //set the mMessageType based on the user options
180  if( mDisplayImmediately )
182  else
184 #endif
185 
186  //see which protocol was selected and send appropriately
187  switch( mMessageProtocol )
188  {
189 #if( FMI_SUPPORT_A611 )
191  if( !mCom.sendA611LongTextMessage( messageText, messageId, mMessageType ) )
192  {
193  MessageBox
194  (
195  _T("A long text message is already in progress. Wait until it has completed before sending another."),
196  _T("Message Already in Progress"), MB_OK
197  );
198  return;
199  }
200  break;
202  {
203  CSelectCannedResponseDlg dlg( messageId, messageText, mMessageType, this, mCom );
204  if( dlg.DoModal() == IDCANCEL )
205  return;
206  }
207  break;
208 #endif
209 #if( FMI_SUPPORT_A604 )
210  case A604_OPEN_MESSAGE_PROTOCOL: //A604 open
211  mCom.sendA604TextMessage( messageText, messageId, mMessageType );
212  break;
213  case A604_CANNED_RESPONSE_MESSAGE_PROTOCOL: // Canned Response
214  {
215  CSelectCannedResponseDlg dlg( messageId, messageText, mMessageType, this, mCom );
216  if( dlg.DoModal() == IDCANCEL )
217  return;
218  }
219  break;
220 #endif
221 #if( FMI_SUPPORT_A602 )
222  case A602_OPEN_MESSAGE_PROTOCOL: //A602 Open
223  mCom.sendA602TextMessage( FMI_ID_SERVER_OPEN_TXT_MSG, messageText, messageId );
224  break;
225  case A602_OK_ACK_MESSAGE_PROTOCOL: //Okay Ack
226  mCom.sendA602TextMessage( FMI_ID_SERVER_OK_ACK_TXT_MSG, messageText, messageId );
227  break;
228  case A602_YES_NO_ACK_MESSAGE_PROTOCOL: //Yes/No Ack
229  mCom.sendA602TextMessage( FMI_ID_SERVER_YES_NO_CONFIRM_MSG, messageText, messageId );
230  break;
231 #endif
232 #if( FMI_SUPPORT_LEGACY )
233  case LEGACY_TEXT_MESSAGE_PROTOCOL: // Legacy text message
234  mCom.sendLegacyTextMessage( messageText );
235  break;
236 #endif
237  default:
238  MessageBox
239  (
240  _T("The message type you have selected is not available."),
241  _T("Unsupported"), MB_OK
242  );
243  return;
244  break;
245  }
246 
247  OnOK();
248 } /* OnBnClickedOk() */
249 
250 //----------------------------------------------------------------------
254 //----------------------------------------------------------------------
256 {
257  UpdateData( TRUE );
259 }
260 
261 //----------------------------------------------------------------------
268 //----------------------------------------------------------------------
270  (
271  int aSelectedProtocol
272  )
273 {
274  switch( aSelectedProtocol )
275  {
276 #if( FMI_SUPPORT_A611 )
278  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( TRUE );
279  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
280  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
281  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
282  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
283  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(1000 characters max)") );
284  break;
286  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( TRUE );
287  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_SHOW );
288  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
289  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
290  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
291  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(1000 characters max)") );
292  break;
293 #endif
294 #if( FMI_SUPPORT_A604 )
296  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( TRUE );
297  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
298  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
299  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
300  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
301  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
302  break;
304  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( TRUE );
305  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_SHOW );
306  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
307  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
308  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
309  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
310  break;
311 #endif
312 #if( FMI_SUPPORT_A602 )
314  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( FALSE );
315  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
316  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( FALSE );
317  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( FALSE );
318  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( FALSE );
319  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
320  break;
322  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( FALSE );
323  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
324  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
325  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
326  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
327  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
328  break;
330  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( FALSE );
331  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
332  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( TRUE );
333  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( TRUE );
334  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( TRUE );
335  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
336  break;
337 #endif
338 #if( FMI_SUPPORT_LEGACY )
339  case LEGACY_TEXT_MESSAGE_PROTOCOL:
340  GetDlgItem( IDC_MSGNEW_CHK_DISP_IMMED )->EnableWindow( FALSE );
341  GetDlgItem( IDC_MSGNEW_LBL_CANRSP_HINT )->ShowWindow( SW_HIDE );
342  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID )->EnableWindow( FALSE );
343  GetDlgItem( IDC_MSGNEW_LBL_MSG_ID_HINT )->EnableWindow( FALSE );
344  GetDlgItem( IDC_MSGNEW_EDIT_MSG_ID )->EnableWindow( FALSE );
345  GetDlgItem( IDC_MSGNEW_LBL_MSG_TEXT_HINT )->SetWindowText( _T("(200 characters max)") );
346  break;
347 #endif
348  }
349 
351 
352 } /* updateDlgFields() */
353 
354 //----------------------------------------------------------------------
359 //----------------------------------------------------------------------
361 {
362  BOOL formValid = TRUE;
363 
364 #if( !( SKIP_VALIDATION ) )
365  UpdateData( TRUE );
366 #if( FMI_SUPPORT_A604 )
368 #if( FMI_SUPPORT_A611 )
370 #endif
371  ) && ( mMessageId == "" ) )
372  {
373  formValid = FALSE;
374  }
375 #endif
376  if( ( mMessageText.GetLength() == 0 ) ||
377  ( mMessageText.GetLength() >= TEXT_MSG_MAX_SIZE
378 #if( FMI_SUPPORT_A611 )
381  ( mMessageText.GetLength() >= LONG_TEXT_MSG_MAX_SIZE
382 #endif
383  ) )
384  {
385  formValid = FALSE;
386  }
387 #endif
388 
389  if( formValid )
390  {
391  GetDlgItem( IDOK )->EnableWindow( TRUE );
392  }
393  else
394  {
395  GetDlgItem( IDOK )->EnableWindow( FALSE );
396  }
397 
398 } /* OnEnChangeEditFields */
#define IDC_MSGNEW_EDIT_MSG_ID
Definition: resource.h:266
#define IDC_MSGNEW_LBL_MSG_ID
Definition: resource.h:269
#define TEXT_MSG_BUFFER_MAX_SIZE
The maximum size of any text message, in bytes.
Definition: fmi.h:172
#define IDC_MSGNEW_LBL_CANRSP_HINT
Definition: resource.h:267
BOOL OnInitDialog()
Initialize the dialog.
void updateDlgFields(int aSelectedProtocol)
Enable/disable controls as appropriate for the selected protocol.
#define LONG_TEXT_MSG_MAX_SIZE
Maximum number of bytes in an A611 Long Text Message.
Definition: fmi.h:164
MessageProtocolType mMessageProtocol
Index of the selected message protocol.
Definition: CTxtMsgNewDlg.h:92
#define IDC_MSGNEW_EDIT_MESSAGE_TEXT
Definition: resource.h:265
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
virtual ~CTxtMsgNewDlg()
Destructor.
afx_msg void OnCbnSelChangeMsgProtocol()
Selection Changed handler for the Protocol combo box.
#define FALSE
Definition: garmin_types.h:46
void sendA602TextMessage(fmi_id_type aFmiPacketId, char *aMessageText, const MessageId &aMessageId)
Send a server to client text message, for all A602 FMI protocols.
bool sendA611LongTextMessage(const char *aMessageText, const MessageId &aMessageId, uint8 aMessageType)
Send an A611 server to client long text message.
afx_msg void OnBnClickedOk()
Click handler for the OK button.
FmiApplicationLayer & mCom
Pointer to the main app dialog.
Definition: CTxtMsgNewDlg.h:86
#define IDC_MSGNEW_CHK_DISP_IMMED
Definition: resource.h:264
#define IDD_TXT_MSG_NEW
Definition: resource.h:41
#define TRUE
Definition: garmin_types.h:45
#define IDC_MSGNEW_LBL_MSG_ID_HINT
Definition: resource.h:270
Dialog allowing the user to select the canned responses that are allowed for a particular message...
#define IDC_MSGNEW_LBL_MSG_TEXT_HINT
Definition: resource.h:271
#define IDC_MSGNEW_CBO_PROTOCOL
Definition: resource.h:263
codepage_type mClientCodepage
Code page used for encoding of text fields when communicating with the client.
Serial communication controller for Garmin and FMI packets.
#define FMI_SUPPORT_A611
If true, app was built with support for A611 protocols.
Definition: fmi.h:57
uint8 mMessageType
Value to use on the message_type member of the A604 text message.
uint8 getIdSize() const
Return the size of the message ID.
Definition: MessageId.cpp:152
#define TEXT_MSG_MAX_SIZE
Maximum payload of a single text message, in bytes.
Definition: fmi.h:160
afx_msg void OnEnChangeEditFields()
Edit Change handler for all edit boxes on the dialog.
BOOL mDisplayImmediately
If TRUE, the "Display Immediately" box is checked.
CString mMessageText
Contents of the Message Text edit box.
Definition: CTxtMsgNewDlg.h:89
void sendA604TextMessage(const char *aMessageText, const MessageId &aMessageId, uint8 aMessageType=A604_MESSAGE_TYPE_NORMAL)
Send an A604 server to client open text message.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
CString mMessageId
Contents of the Message ID edit box.
Definition: CTxtMsgNewDlg.h:96
Encapsulation of a message ID.
Definition: MessageId.h:26
Modal dialog allowing the user to send a text message to the client.
Definition: CTxtMsgNewDlg.h:30