Garmin Fleet Management Controller  2.19.0
CSendSensorDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CSendSensorDlg.cpp
5 *
6 * Copyright 2014 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include <sstream>
13 #include <fstream>
14 #include "CSendSensorDlg.h"
15 
16 #if( FMI_SUPPORT_A617 )
17 
18 IMPLEMENT_DYNAMIC(CSendSensorDlg, CDialog)
19 
20 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
26  : CDialog(CSendSensorDlg::IDD, pParent)
27  , mCom( aCom )
28  , m_action(0)
29  , m_uniqueId(0)
30  , m_sortOrder(0)
31  , m_playSound(FALSE)
32  , m_recordInHistory(FALSE)
33  , m_name(_T(""))
34  , m_nameLength(0)
35  , m_status(_T(""))
36  , m_statusLength(0)
37  , m_description(_T(""))
38  , m_descriptionLength(0)
39  {
40 
41 }
42 
44 {
45 }
46 
47 void CSendSensorDlg::DoDataExchange(CDataExchange* pDX)
48 {
49 CDialog::DoDataExchange(pDX);
50 DDX_Text(pDX, IDC_SENSOR_UNIQUE_ID, m_uniqueId);
51 DDX_Text(pDX, IDC_SENSOR_SORT_ORDER, m_sortOrder);
52 DDX_Control(pDX, IDC_SENSOR_ICON, m_icon);
53 DDX_Control(pDX, IDC_SENSOR_SEVERITY, m_severity);
54 DDX_Check(pDX, IDC_SENSOR_PLAY_SOUND, m_playSound);
56 DDX_Text(pDX, IDC_SENSOR_NAME, m_name);
57 DDX_Text(pDX, IDC_SENSOR_NAME_LENGTH, m_nameLength);
58 DDX_Text(pDX, IDC_SENSOR_STATUS, m_status);
62  }
63 
64 
65 BEGIN_MESSAGE_MAP(CSendSensorDlg, CDialog)
69  ON_LBN_SELCHANGE( IDC_SENSOR_LIST, &CSendSensorDlg::RefreshList)
73 END_MESSAGE_MAP()
74 
75 //----------------------------------------------------------------------
77 //----------------------------------------------------------------------
79  {
80  m_action = 0;
81  m_uniqueId = 1;
82  m_icon.SetCurSel( -1 );
83  m_severity.SetCurSel( -1 );
84  m_sortOrder = 1;
87  m_name = _T( "" );
88  m_nameLength = 0;
89  m_status = _T( "" );
90  m_statusLength = 0;
91  m_description = _T( "" );
93  UpdateData( FALSE );
94  }
95 
96 // CSendSensorDlg message handlers
97 
98 //----------------------------------------------------------------------
101 //----------------------------------------------------------------------
103  {
104  CDialog::OnInitDialog();
105 
106  (( CSpinButtonCtrl*) GetDlgItem( IDC_SPIN1 ) )->SetRange( 1, 65535/2 );
107  (( CSpinButtonCtrl*) GetDlgItem( IDC_SPIN2 ) )->SetRange( 1, 256 );
108 
109  RefreshList();
110 
111  return TRUE;
112  }
113 
115  {
116  reset();
117 
118  CListBox* lb = ( CListBox*) GetDlgItem( IDC_SENSOR_LIST );
119  int selectedIndex = lb->GetCurSel();
120  int topIndex = lb->GetTopIndex();
121  lb->ResetContent();
122  if( !mSensorList.mSensorIndexInList.empty() )
123  {
124  std::map<uint8,uint32>::const_iterator it = mSensorList.mSensorIndexInList.begin();
125  for( it; it != mSensorList.mSensorIndexInList.end(); it++ )
126  {
127  //if( mSensorList.mSensors.get( it->second ).isValid() )
128  // {
129  lb->AddString( ( LPCTSTR( mSensorList.mSensors.get( it->second ).getCurrentName() ) ) );
130  // }
131  }
132 
133  if( selectedIndex == -1 )
134  selectedIndex = 0;
135 
136  if ( mSensorList.mSensors.validCount() > 0 )
137  {
138  std::map<uint8,uint32>::const_iterator it = mSensorList.mSensorIndexInList.begin();
139  for( int i = 0; i < selectedIndex; i++ )
140  {
141  it++;
142  }
143  SensorListItem item = mSensorList.mSensors.get( it->second );
144 
145  CString s;
146  s.Format(_T("%d"), item.getUniqueId());
147  GetDlgItem( IDC_SENSOR_UNIQUE_ID )->SetWindowTextW( s );
148  s.Format(_T("%d"), item.getDisplayIndex());
149  GetDlgItem( IDC_SENSOR_SORT_ORDER )->SetWindowTextW( s );
150  m_icon.SetCurSel( item.getIcon() );
151  GetDlgItem( IDC_SENSOR_NAME )->SetWindowText( item.getCurrentName() );
152  m_nameLength = item.getCurrentName().GetLength();
153 
154  if( item.getNumUpdates() > 0 )
155  {
156  CString s( item.getStatus() );
157  GetDlgItem( IDC_SENSOR_STATUS )->SetWindowTextW( s );
158  s.Format(_T("%d"), strlen( item.getStatus() ));
159  GetDlgItem( IDC_SENSOR_STATUS_LENGTH )->SetWindowTextW( s );
160  CString s2( item.getDescription() );
161  GetDlgItem( IDC_SENSOR_DESCRIPTION )->SetWindowTextW( s2 );
162  s.Format(_T("%d"), strlen( item.getDescription() ));
163  GetDlgItem( IDC_SENSOR_DESCR_LENGTH )->SetWindowTextW( s );
164  m_severity.SetCurSel( item.getSeverity() );
165  ((CButton*)GetDlgItem( IDC_SENSOR_PLAY_SOUND ))->SetCheck( item.getPlaySound() );
166  ((CButton*)GetDlgItem( IDC_SENSOR_RECORD_IN_HISTORY ))->SetCheck( item.getRecordSensor() );
167  }
168  }
169  lb->SetCurSel( selectedIndex );
170  lb->SetTopIndex( topIndex );
171  }
172  UpdateData();
173  }
174 
175 //----------------------------------------------------------------------
177 //----------------------------------------------------------------------
179  {
180  UpdateData();
181 
182  SensorListItem listItem;
184  memset( &config, 0, sizeof( config ) );
185  config.change_id = GetTickCount();
186  config.unique_id = m_uniqueId;
187  config.display_index = m_sortOrder;
188  config.icon = m_icon.GetCurSel();
189  listItem.setCurrentName( m_name );
190 
191  WideCharToMultiByte( mCom.mClientCodepage, 0, m_name.GetBuffer(), -1, config.name, sizeof( config.name ), NULL, NULL );
192  config.name[sizeof( config.name ) - 1] = '\0';
193 
194  mCom.sendFmiPacket( FMI_SENSOR_CONFIG_REQUEST, (uint8*)&config, sizeof( config ) );
195 
196  //set Clientlist properties
197  listItem.setId( config.unique_id );
198 
199  listItem.setConfig( config );
200  listItem.setParent( &mSensorList.mSensors );
201  listItem.setValid();
202  mSensorList.add( listItem );
203 
204  RefreshList();
205  }
206 
208  {
209  UpdateData();
210 
212  memset( &update, 0, sizeof( update ) );
213  update.change_id = GetTickCount();
214  update.unique_id = m_uniqueId;
215  update.severity = m_severity.GetCurSel();
216  update.play_sound = m_playSound;
218  WideCharToMultiByte( mCom.mClientCodepage, 0, m_status.GetBuffer(), -1, update.status, sizeof( update.status ), NULL, NULL );
219  update.status[sizeof( update.status ) - 1] = '\0';
220  WideCharToMultiByte( mCom.mClientCodepage, 0, m_description.GetBuffer(), -1, update.description, sizeof( update.description ), NULL, NULL );
221  update.description[sizeof( update.description ) - 1] = '\0';
222 
223  mCom.sendFmiPacket( FMI_SENSOR_UPDATE_REQUEST, (uint8*)&update, sizeof( update ) );
224 
226 
227  for( iter = mSensorList.mSensors.begin(); iter != mSensorList.mSensors.end(); iter++ )
228  {
229  if( mSensorList.mSensors.get( iter->first ).getUniqueId() == update.unique_id )
230  {
231  mSensorList.mSensors.get( iter->first ).setUpdate( update );
232  mSensorList.mSensors.save();
233  }
234  }
235 
236  RefreshList();
237  }
238 
240  {
242  memset( &message, 0, sizeof( message ) );
243  message.change_id = GetTickCount();
244  message.unique_id = m_uniqueId;
245 
246  mCom.sendFmiPacket( FMI_SENSOR_DELETE_REQUEST, (uint8*)&message, sizeof( message ) );
247 
248  mSensorList.mSensors.remove( m_uniqueId );
249  mSensorList.mSensorIndexInList.erase( m_sortOrder );
250 
251  RefreshList();
252  }
253 
254 //----------------------------------------------------------------------
256 //----------------------------------------------------------------------
258  {
259  UpdateData();
260 
262  char text[ sizeof( message.name ) ];
263  WideCharToMultiByte( mCom.mClientCodepage, 0, m_name.GetBuffer(), -1, text, sizeof( text ), NULL, NULL );
264  text[sizeof( text ) - 1] = '\0';
265 
266  m_nameLength = strlen( text );
267 
268  UpdateData( FALSE );
269  }
270 
271 //----------------------------------------------------------------------
273 //----------------------------------------------------------------------
275  {
276  UpdateData();
277 
279  char text[ sizeof( message.status ) ];
280  WideCharToMultiByte( mCom.mClientCodepage, 0, m_status.GetBuffer(), -1, text, sizeof( text ), NULL, NULL );
281  text[sizeof( text ) - 1] = '\0';
282 
283  m_statusLength = strlen( text );
284 
285  UpdateData( FALSE );
286  }
287 
288 //----------------------------------------------------------------------
290 //----------------------------------------------------------------------
292  {
293  UpdateData();
294 
296  char text[ sizeof( message.description ) ];
297  WideCharToMultiByte( mCom.mClientCodepage, 0, m_description.GetBuffer(), -1, text, sizeof( text ), NULL, NULL );
298  text[sizeof( text ) - 1] = '\0';
299 
300  m_descriptionLength = strlen( text );
301 
302  UpdateData( FALSE );
303  }
304 
305 #endif
virtual ~CSendSensorDlg()
boolean getPlaySound() const
Get the play sound setting.
#define IDC_DELETE2
Definition: resource.h:496
uint32 getNumUpdates() const
Get the number of updates submitted.
void setId(const key_type &aId)
Set item&#39;s ID.
#define IDC_SENSOR_ICON
Definition: resource.h:472
afx_msg void RefreshList()
#define IDC_SENSOR_PLAY_SOUND
Definition: resource.h:474
void reset()
reset the form to defaults (since this dialog is long-lived)
Data type for Update Sensor Request Packet ID (0x1406) from server to client.
Definition: fmi.h:2184
boolean getRecordSensor() const
Get the record sensor setting.
#define IDC_SENSOR_DESCR_LENGTH
Definition: resource.h:466
#define IDC_SENSOR_NAME_LENGTH
Definition: resource.h:468
#define IDC_SENSOR_STATUS
Definition: resource.h:463
CString getCurrentName() const
Get the current name of this item.
void sendFmiPacket(uint16 aFmiPacketId, uint8 *aFmiPayload, uint8 aFmiPayloadSize)
Send an arbitrary FMI packet.
#define IDC_SENSOR_RECORD_IN_HISTORY
Definition: resource.h:475
Data structure to hold details of an A617 sensor that the server needs to keep.
#define FALSE
Definition: garmin_types.h:46
#define IDC_SENSOR_SEVERITY
Definition: resource.h:473
void setValid(BOOL aValid=TRUE)
Set this item as valid.
#define IDC_SENSOR_STATUS_LENGTH
Definition: resource.h:464
#define IDC_SPIN1
Definition: resource.h:459
#define TRUE
Definition: garmin_types.h:45
#define IDC_SENSOR_NAME
Definition: resource.h:467
CComboBox m_severity
codepage_type mClientCodepage
Code page used for encoding of text fields when communicating with the client.
afx_msg void OnEnChangeSensorDescription()
Update the description length label in response to change in description.
char description[110]
Definition: fmi.h:2193
afx_msg void OnBnClickedDelete()
void setCurrentName(CString aName)
Set the current name of the sensor.
Data type for Delete Sensor Request Packet ID (0x1404) from server to client.
Definition: fmi.h:2176
Serial communication controller for Garmin and FMI packets.
FmiApplicationLayer & mCom
Reference to the FMI communication controller.
uint8 getDisplayIndex() const
Get display index.
afx_msg void OnBnClickedCreate()
Validate form, build and send appropriate FMI packet to device.
#define IDC_SPIN2
Definition: resource.h:460
#define IDC_SENSOR_LIST
Definition: resource.h:484
CComboBox m_icon
#define IDC_UPDATE3
Definition: resource.h:495
afx_msg void OnEnChangeSensorStatus()
Update the status length label in response to change in status.
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
#define IDC_CREATE2
Definition: resource.h:494
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
uint32 getUniqueId() const
Get the unique id.
uint8 getSeverity() const
Get the severity.
afx_msg void OnEnChangeSensorName()
Update the name length label in response to change in name.
#define IDC_SENSOR_UNIQUE_ID
Definition: resource.h:471
afx_msg void OnBnClickedUpdate()
#define IDC_SENSOR_DESCRIPTION
Definition: resource.h:465
BOOL OnInitDialog()
This function is called when the window is created.
Form for sending A617 sensor popups to the device.
Data type for Configure Sensor Request Packet ID (0x1402) from server to client.
Definition: fmi.h:2155
const char * getStatus() const
Get the status.
uint16 getIcon() const
Get icon.
void setConfig(fmi_sensor_config_request aConfig)
Set the sensor.
void setParent(FileBackedMap< SensorListItem > *aParent)
Set the parent.
const char * getDescription() const
Get the description.
CString m_description
SensorList mSensorList
#define IDC_SENSOR_SORT_ORDER
Definition: resource.h:477
virtual void DoDataExchange(CDataExchange *pDX)