Garmin Fleet Management Controller  2.19.0
CSendAlertDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CSendAlertDlg.cpp
5 *
6 * Copyright 2013 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "CSendAlertDlg.h"
13 
14 #if( FMI_SUPPORT_A617 )
15 
16 // the FMI struct states that the limit is 15, but we'll allow a greater value for testing
17 #define TIMEOUT_INPUT_MAX 100
18 
19 // CSendAlertDlg dialog
20 
21 IMPLEMENT_DYNAMIC(CSendAlertDlg, CDialog)
22 
23 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
29  : CDialog(CSendAlertDlg::IDD, pParent)
30  , mCom( aCom )
31  , m_uniqueId(0)
32  , m_timeout(0)
33  , m_playSound(FALSE)
34  , m_text(_T(""))
35  , m_textLength(0)
36  {
37 
38 }
39 
41 {
42 }
43 
44 void CSendAlertDlg::DoDataExchange(CDataExchange* pDX)
45 {
46 CDialog::DoDataExchange(pDX);
47 DDX_Text(pDX, IDC_ALERT_UNIQUE_ID, m_uniqueId);
48 DDX_Control(pDX, IDC_ALERT_ICON, m_icon);
49 DDX_Text(pDX, IDC_ALERT_TIMEOUT, m_timeout);
50 DDV_MinMaxInt(pDX, m_timeout, 0, TIMEOUT_INPUT_MAX);
51 DDX_Control(pDX, IDC_ALERT_SEVERITY, m_severity);
52 DDX_Check(pDX, IDC_ALERT_PLAY_SOUND, m_playSound);
53 DDX_Text(pDX, IDC_ALERT_TEXT, m_text);
54 DDX_Text(pDX, IDC_ALERT_TEXT_LENGTH, m_textLength);
55  }
56 
57 
58 BEGIN_MESSAGE_MAP(CSendAlertDlg, CDialog)
59  ON_BN_CLICKED(IDOK, &CSendAlertDlg::OnBnClickedOk)
61 END_MESSAGE_MAP()
62 
63 //----------------------------------------------------------------------
65 //----------------------------------------------------------------------
67  {
68  m_uniqueId = 1;
69  m_icon.SetCurSel( -1 );
70  m_timeout = 1;
71  m_severity.SetCurSel( -1 );
73  m_text = _T( "" );
74  m_textLength = 0;
75  UpdateData( FALSE );
76  }
77 
78 // CSendAlertDlg message handlers
79 
80 //----------------------------------------------------------------------
83 //----------------------------------------------------------------------
85  {
86  CDialog::OnInitDialog();
87 
88  (( CSpinButtonCtrl*) GetDlgItem( IDC_SPIN1 ) )->SetRange( 1, 65535/2 );
89  (( CSpinButtonCtrl*) GetDlgItem( IDC_SPIN2 ) )->SetRange( 0, TIMEOUT_INPUT_MAX );
90 
91  return TRUE;
92  }
93 
94 //----------------------------------------------------------------------
96 //----------------------------------------------------------------------
98  {
99  if( !UpdateData())
100  {
101  return;
102  }
103 
104  fmi_alert_popup_request message;
105  memset( &message, 0, sizeof( message ) );
106  message.unique_id = m_uniqueId;
107  message.play_sound = m_playSound;
108  message.timeout = m_timeout;
109  message.icon = m_icon.GetCurSel();
110  message.severity = m_severity.GetCurSel();
111 
112  WideCharToMultiByte( mCom.mClientCodepage, 0, m_text.GetBuffer(), -1, message.alert_text, sizeof( message.alert_text ), NULL, NULL );
113  message.alert_text[sizeof( message.alert_text ) - 1] = '\0';
114 
115  mCom.sendFmiPacket( FMI_ALERT_POPUP_REQUEST, (uint8*)&message, sizeof( message ) );
116 
117  OnOK();
118  }
119 
120 //----------------------------------------------------------------------
122 //----------------------------------------------------------------------
124  {
125  UpdateData();
126 
127  fmi_alert_popup_request message;
128  char text[ sizeof( message.alert_text ) ];
129  WideCharToMultiByte( mCom.mClientCodepage, 0, m_text.GetBuffer(), -1, text, sizeof( text ), NULL, NULL );
130  text[sizeof( text ) - 1] = '\0';
131 
132  m_textLength = strlen( text );
133 
134  UpdateData( FALSE );
135  }
136 
137 #endif
#define IDC_ALERT_UNIQUE_ID
Definition: resource.h:456
BOOL OnInitDialog()
This function is called when the window is created.
Form for sending A617 alerts to the device.
Definition: CSendAlertDlg.h:10
CComboBox m_icon
Definition: CSendAlertDlg.h:38
void sendFmiPacket(uint16 aFmiPacketId, uint8 *aFmiPayload, uint8 aFmiPayloadSize)
Send an arbitrary FMI packet.
FmiApplicationLayer & mCom
Reference to the FMI communication controller.
Definition: CSendAlertDlg.h:46
afx_msg void OnBnClickedOk()
Validate form, build and send FMI packet to device.
#define FALSE
Definition: garmin_types.h:46
#define TIMEOUT_INPUT_MAX
#define IDC_SPIN1
Definition: resource.h:459
boolean play_sound
Definition: fmi.h:2141
#define TRUE
Definition: garmin_types.h:45
CString m_text
Definition: CSendAlertDlg.h:42
void reset()
reset the form to defaults (since this dialog is long-lived)
codepage_type mClientCodepage
Code page used for encoding of text fields when communicating with the client.
#define IDC_ALERT_SEVERITY
Definition: resource.h:461
Serial communication controller for Garmin and FMI packets.
virtual void DoDataExchange(CDataExchange *pDX)
#define IDC_SPIN2
Definition: resource.h:460
char alert_text[110]
Definition: fmi.h:2142
#define IDC_ALERT_PLAY_SOUND
Definition: resource.h:455
afx_msg void OnEnChangeAlertText()
Update the text length label in response to change in text.
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
#define IDC_ALERT_TIMEOUT
Definition: resource.h:458
CComboBox m_severity
Definition: CSendAlertDlg.h:40
#define IDC_ALERT_ICON
Definition: resource.h:457
virtual ~CSendAlertDlg()
#define IDC_ALERT_TEXT_LENGTH
Definition: resource.h:454
#define IDC_ALERT_TEXT
Definition: resource.h:453
Data type for Alert Popup Request Packet ID (0x1400) from server to client.
Definition: fmi.h:2135