Garmin Fleet Management Controller  2.19.0
CIftaDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CIftaDlg.cpp
5 *
6 * Copyright 2013 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "CIftaDlg.h"
13 #include "util.h"
14 #include "EventId.h"
15 #include <shlobj.h>
16 
17 #pragma comment(lib, "shell32.lib")
18 
19 #if( FMI_SUPPORT_A615 )
20 
21 // CIftaDlg dialog
22 
23 IMPLEMENT_DYNAMIC(CIftaDlg, CDialog)
24 
25 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 CIftaDlg::CIftaDlg(CWnd* pParent, FmiApplicationLayer & aCom)
31  : CDialog(CIftaDlg::IDD, pParent)
32  , mCom( aCom )
33  , mStartDate(COleDateTime::GetCurrentTime())
34  , mStartTime(COleDateTime::GetCurrentTime())
35  , mEndDate(COleDateTime::GetCurrentTime())
36  , mEndTime(COleDateTime::GetCurrentTime())
37  {
38 
39 }
40 
42 {
43 }
44 
45 void CIftaDlg::DoDataExchange(CDataExchange* pDX)
46 {
47 CDialog::DoDataExchange(pDX);
48 DDX_DateTimeCtrl(pDX, IDC_IFTA_START_DATE, mStartDate);
49 DDX_DateTimeCtrl(pDX, IDC_IFTA_START_TIME, mStartTime);
50 DDX_DateTimeCtrl(pDX, IDC_IFTA_END_DATE, mEndDate);
51 DDX_DateTimeCtrl(pDX, IDC_IFTA_END_TIME, mEndTime);
52  }
53 
54 
55 BEGIN_MESSAGE_MAP(CIftaDlg, CDialog)
59 END_MESSAGE_MAP()
60 
61 static time_type convertDateTime( int year, int month, int day, int hour, int minute, int second )
62  {
63  time_type timestamp;
64  time_type time, date;
65  date_time_data_type date_time;
66  date_time.date.year = (uint16) year;
67  date_time.date.month = (uint8) month;
68  date_time.date.day = (uint8) day;
69  date_time.time.hour = (sint16) hour;
70  date_time.time.minute = (uint8) minute;
71  date_time.time.second = (uint8) second;
72  UTIL_convert_time_type_to_seconds( &date_time, &time );
73  UTIL_convert_date_time_to_seconds( &date_time, &date );
74  timestamp = date + time;
75  UTIL_convert_local_to_UTC( &timestamp, &timestamp );
76  return timestamp;
77  }
78 
79 // CIftaDlg message handlers
80 
81 //----------------------------------------------------------------------
85 //----------------------------------------------------------------------
87  {
88  UpdateData();
89 
90  time_type start = convertDateTime(
91  mStartDate.GetYear(), mStartDate.GetMonth(), mStartDate.GetDay(),
92  mStartTime.GetHour(), mStartTime.GetMinute(), mStartTime.GetSecond()
93  );
94 
96  mEndDate.GetYear(), mEndDate.GetMonth(), mEndDate.GetDay(),
97  mEndTime.GetHour(), mEndTime.GetMinute(), mEndTime.GetSecond()
98  );
99 
100  if (start <= end)
101  {
103  memset( &message, 0, sizeof( message ) );
104  message.start_time = start;
105  message.end_time = end;
106  mCom.sendFmiPacket( FMI_IFTA_DATA_FETCH_REQUEST, (uint8*)&message, sizeof( message ) );
107  }
108  }
109 
110 //----------------------------------------------------------------------
114 //----------------------------------------------------------------------
116  {
117  UpdateData();
118 
119  time_type start = convertDateTime(
120  mStartDate.GetYear(), mStartDate.GetMonth(), mStartDate.GetDay(),
121  mStartTime.GetHour(), mStartTime.GetMinute(), mStartTime.GetSecond()
122  );
123 
125  mEndDate.GetYear(), mEndDate.GetMonth(), mEndDate.GetDay(),
126  mEndTime.GetHour(), mEndTime.GetMinute(), mEndTime.GetSecond()
127  );
128 
129  if (start <= end)
130  {
132  memset( &message, 0, sizeof( message ) );
133  message.start_time = start;
134  message.end_time = end;
135  mCom.sendFmiPacket( FMI_IFTA_DATA_DELETE_REQUEST, (uint8*)&message, sizeof( message ) );
136  }
137  }
138 
139 //----------------------------------------------------------------------
142 //----------------------------------------------------------------------
143 afx_msg LRESULT CIftaDlg::OnEventIftaFileTransferReceived( WPARAM, LPARAM )
144 {
145  TCHAR tmpPath[ MAX_PATH-14 ];
146  TCHAR tmpFileName[ MAX_PATH ];
147 
148  memset( tmpPath, 0, sizeof( tmpPath ) );
149  memset( tmpFileName, 0, sizeof( tmpFileName ) );
150 
151  GetTempPath( MAX_PATH-14, tmpPath );
152  GetTempFileName( tmpPath, _T( "IFTA" ), 0, tmpFileName );
153 
154  CString tmpFile( tmpFileName );
155  tmpFile += _T( ".csv" );
156 
157  if( unzip( SAVE_RECEIVED_IFTA_FILE, tmpFile ) )
158  {
159  if( IDYES == MessageBox(
160  _T( "An IFTA data file has been received from the device.\nWould you like to view the contents?" ),
161  _T( "IFTA Data Fetch" ), MB_YESNO | MB_ICONQUESTION
162  ) )
163  {
164  // open up the file with whatever program handles the CSV file type (most likely Excel)
165  // use My Documents as the working dir in hopes that Excel will default to that folder when saving
166  TCHAR myDocs[ MAX_PATH ];
167  if( S_OK == SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocs ) )
168  {
169  ShellExecute( NULL, _T( "open" ), tmpFile, NULL, myDocs, SW_SHOW );
170  }
171  else {
172  ShellExecute( NULL, _T( "open" ), tmpFile, NULL, NULL, SW_SHOW );
173  }
174  }
175  }
176  return 0;
177 }
178 #endif
struct date_time_data_type::_date date
COleDateTime mEndDate
Definition: CIftaDlg.h:49
uint8 second
second (0-59)
Definition: garmin_types.h:162
COleDateTime mStartDate
Definition: CIftaDlg.h:47
uint8 minute
minute (0-59)
Definition: garmin_types.h:161
Data type for the IFTA Data Delete Request Packet ID (0X0008) from server to client.
Definition: fmi.h:2021
#define IDC_IFTA_DATA_DELETE
Definition: resource.h:446
void sendFmiPacket(uint16 aFmiPacketId, uint8 *aFmiPayload, uint8 aFmiPayloadSize)
Send an arbitrary FMI packet.
afx_msg void OnBnClickedDataFetch()
Attempt to fetch IFTA data from the device.
Definition: CIftaDlg.cpp:86
COleDateTime mStartTime
Definition: CIftaDlg.h:48
afx_msg LRESULT OnEventIftaFileTransferReceived(WPARAM, LPARAM)
Attempt to unzip received file and shell open the result.
Definition: CIftaDlg.cpp:143
struct date_time_data_type::_time time
void UTIL_convert_time_type_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a time_type to seconds since midnight.
Definition: util.cpp:295
signed short int sint16
16-bit signed integer
Definition: garmin_types.h:57
Date & time data type with separate fields for month, day, year, hour, minute, and second...
Definition: garmin_types.h:150
#define IDC_IFTA_END_TIME
Definition: resource.h:444
virtual ~CIftaDlg()
Definition: CIftaDlg.cpp:41
Form for interacting with IFTA data on the device.
Definition: CIftaDlg.h:21
Serial communication controller for Garmin and FMI packets.
CString unzip(char *original)
This function will uncompress a file into a new file.
Definition: util.cpp:741
boolean UTIL_convert_date_time_to_seconds(const date_time_data_type *aDateTime, time_type *aSeconds)
Converts a date from from a structure to a Garmin date.
Definition: util.cpp:114
virtual void DoDataExchange(CDataExchange *pDX)
Definition: CIftaDlg.cpp:45
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
#define IDC_IFTA_START_TIME
Definition: resource.h:443
FmiApplicationLayer & mCom
Reference to the FMI communication controller.
Definition: CIftaDlg.h:53
static time_type convertDateTime(int year, int month, int day, int hour, int minute, int second)
Definition: CIftaDlg.cpp:61
uint16 year
Real year (1990 means 1990!)
Definition: garmin_types.h:156
uint8 month
month (1-12)
Definition: garmin_types.h:154
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
#define IDC_IFTA_START_DATE
Definition: resource.h:441
#define IDC_IFTA_END_DATE
Definition: resource.h:442
#define IDC_IFTA_DATA_FETCH
Definition: resource.h:445
Data type for the IFTA Data Fetch Request Packet ID (0X0006) from server to client.
Definition: fmi.h:2006
COleDateTime mEndTime
Definition: CIftaDlg.h:50
afx_msg void OnBnClickedDataDelete()
Attempt to delete IFTA data on the device.
Definition: CIftaDlg.cpp:115
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
uint32 time_type
Absolute time (number of seconds since 12/31/1989 12:00 am UTC)
Definition: garmin_types.h:97
#define SAVE_RECEIVED_IFTA_FILE
sint16 hour
hour (0-65535), range required for correct ETE conversion
Definition: garmin_types.h:160
void UTIL_convert_local_to_UTC(const time_type *aLocalTime, time_type *aUtcTime)
Converts a time_type from local to UTC time.
Definition: util.cpp:549