forked from AndyWhittaker/FreeScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailDlg.cpp
406 lines (344 loc) · 10.5 KB
/
DetailDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// DetailDlg.cpp : implementation file
//
// (c) 1996-99 Andy Whittaker, Chester, England.
// mail@andywhittaker.com
//
#include "DetailDlg.h"
#include "FreeScan.h"
#include "EnumSer.h" // for EnumerateSerialPorts(...)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDetailDlg property page
CDetailDlg::CDetailDlg(CStatusWriter* pStatusWriter) : CTTPropertyPage(CDetailDlg::IDD), m_pStatusWriter(pStatusWriter)
{
//{{AFX_DATA_INIT(CDetailDlg)
//}}AFX_DATA_INIT
Enumerate(); // Build a list of available serial ports
m_pSupervisor = NULL;
m_bCSVFirstTime = TRUE;
m_bLogFirstTime = TRUE;
// Recall previous settings from the registry.
CWinApp* pApp = AfxGetApp();
m_iModel = pApp->GetProfileInt("Supervisor", "Model", 0);
}
CDetailDlg::~CDetailDlg()
{
// Save our settings to the registry
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt("Supervisor", "Model", m_iModel);
}
void CDetailDlg::DoDataExchange(CDataExchange* pDX)
{
CTTPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDetailDlg)
DDX_Control(pDX, IDC_DELAY, m_WriteDelay);
DDX_Control(pDX, IDC_MPH, m_mph);
DDX_Control(pDX, IDC_KPH, m_kph);
DDX_Control(pDX, IDC_DEGF, m_DegF);
DDX_Control(pDX, IDC_DEGC, m_DegC);
DDX_Control(pDX, IDC_FORCE, m_Force);
DDX_Control(pDX, IDC_COMMENTS, m_Comments);
DDX_Control(pDX, IDC_MODEL, m_Model);
DDX_Control(pDX, IDC_STARTLOG, m_StartLog);
DDX_Control(pDX, IDC_CSV, m_CSV);
DDX_Control(pDX, IDC_RECEIVED, m_Received);
DDX_Control(pDX, IDC_SENT, m_Sent);
DDX_Control(pDX, IDC_STOP, m_Stop);
DDX_Control(pDX, IDC_START, m_Start);
DDX_Control(pDX, IDC_COMSELECT, m_ComSelect);
DDX_Control(pDX, IDC_HIDE, m_Hide);
DDX_Control(pDX, IDC_LISTEN, m_Listen);
DDX_Control(pDX, IDC_INTERACT, m_Interact);
//}}AFX_DATA_MAP
if (m_pSupervisor != NULL) {
Refresh(m_pSupervisor->GetEcuData());
}
}
BEGIN_MESSAGE_MAP(CDetailDlg, CTTPropertyPage)
//{{AFX_MSG_MAP(CDetailDlg)
ON_BN_CLICKED(IDC_STARTLOG, OnStartlog)
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_HIDE, OnHide)
ON_CBN_SELENDOK(IDC_COMSELECT, OnSelendokComselect)
ON_CBN_KILLFOCUS(IDC_COMSELECT, OnKillfocusComselect)
ON_BN_CLICKED(IDC_LISTEN, OnListen)
ON_BN_CLICKED(IDC_INTERACT, OnInteract)
ON_BN_CLICKED(IDC_CSV, OnCsv)
ON_BN_CLICKED(IDC_CSVOPTIONS, OnCsvoptions)
ON_CBN_SELENDOK(IDC_MODEL, OnSelendokModel)
ON_BN_CLICKED(IDC_FORCE, OnForce)
ON_BN_CLICKED(IDC_DEGC, OnDegC)
ON_BN_CLICKED(IDC_DEGF, OnDegF)
ON_BN_CLICKED(IDC_KPH, OnKph)
ON_BN_CLICKED(IDC_MPH, OnMph)
ON_CBN_SELENDOK(IDC_DELAY, OnSelendokDelay)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// Updates all of our controls
void CDetailDlg::Refresh(const CEcuData* const ecuData)
{
CString buf;
// Update bytes sent and received
buf.Format("%d", m_pSupervisor->GetReceivedBytes());
m_Received.SetWindowText(buf);
buf.Format("%d", m_pSupervisor->GetSentBytes());
m_Sent.SetWindowText(buf);
m_Comments.ResetContent(); // Clear protocol comments
// Display the protocol's comments
CString csTemp;
csTemp = ecuData->m_csProtocolComment;
int iIndex=0;
// Format the text in the ListBox.
// This routine correctly handles CR/LF.
while (iIndex != -1)
{
iIndex = csTemp.Find('\n');
m_Comments.AddString(csTemp.SpanExcluding("\n"));
csTemp.Delete(0, iIndex+1);
}
}
// Initialises bits and pieces that need the Supervisor
void CDetailDlg::Init(void)
{
// Restore the model here for our dialog
CString csText;
m_Model.SetCurSel(m_iModel);
m_Model.GetLBText(m_iModel, csText);
csText = "Model " + csText + " selected.";
m_pStatusWriter->WriteStatus(csText);
m_pSupervisor->Init(m_iModel);
// Set the write delay
CString buf;
buf.Format("%d", (DWORD)m_pSupervisor->GetWriteDelay());
m_WriteDelay.SetWindowText(buf);
// Display the current com port in the ComboBox
CString csTemp;
csTemp.Format("COM%d", m_pSupervisor->GetCurrentPort());
m_ComSelect.SetWindowText(csTemp);
Refresh(m_pSupervisor->GetEcuData());
// Set up interact/listen buttons
if (m_pSupervisor->GetInteract())
OnInteract();
else
OnListen();
// Set up DegC/DegF buttons
if (m_pSupervisor->GetCentigrade())
OnDegC();
else
OnDegF();
// Set up mph/kph buttons
if (m_pSupervisor->GetMiles())
OnMph();
else
OnKph();
}
void CDetailDlg::RegisterSupervisor(CSupervisorInterface* const pSupervisor) {
m_pSupervisor = pSupervisor;
}
/////////////////////////////////////////////////////////////////////////////
// CDetailDlg message handlers
void CDetailDlg::OnStartlog()
{
if (m_bLogFirstTime)
{
m_bLogFirstTime = FALSE;
if (!(m_pStatusWriter->StartLog(TRUE)))
m_bLogFirstTime = TRUE;// Call may have failed
else
m_StartLog.SetWindowText(_T("Stop Logging"));
}
else
{
m_bLogFirstTime = TRUE;
m_StartLog.SetWindowText(_T("Log ECU Coms to Disk"));
m_pStatusWriter->StartLog(FALSE);
}
}
void CDetailDlg::OnStart()
{
// ** for tesing only **
// m_pMainDlg->m_pSupervisor->Test(); // test the parser
// return;
m_pSupervisor->Start();
m_Stop.EnableWindow(TRUE); // enable the stop monitoring button
m_Start.SetWindowText(_T("Restart")); // Start monitoring button's text
m_Start.EnableWindow(FALSE); // disable the start monitoring button
m_ComSelect.EnableWindow(FALSE); // Disable COM Port changes
m_Force.EnableWindow(m_pSupervisor->GetInteract());
}
void CDetailDlg::OnStop()
{
m_Start.EnableWindow(TRUE); // enable the start monitoring button
m_Stop.EnableWindow(FALSE); // disable the stop monitoring button
m_ComSelect.EnableWindow(TRUE); // Enable COM Port changes
m_pSupervisor->Stop();
m_Force.EnableWindow(FALSE);
}
// Hides or unhides the status messages window when asked to
void CDetailDlg::OnHide()
{// CButton
m_pStatusWriter->Hide(m_Hide.GetCheck());
}
BOOL CDetailDlg::OnInitDialog()
{
CTTPropertyPage::OnInitDialog();
// Add dialog items that want ToolTip text
m_toolTip.AddTool( GetDlgItem(IDC_STARTLOG), IDC_STARTLOG);
m_toolTip.AddTool( GetDlgItem(IDC_CSV),IDC_CSV);
m_toolTip.AddTool( GetDlgItem(IDC_CSVOPTIONS),IDC_CSVOPTIONS);
m_toolTip.AddTool( GetDlgItem(IDC_START), IDC_START);
m_toolTip.AddTool( GetDlgItem(IDC_STOP), IDC_STOP);
m_toolTip.AddTool( GetDlgItem(IDC_HIDE),IDC_HIDE);
m_toolTip.AddTool( GetDlgItem(IDC_LISTEN),IDC_LISTEN);
m_toolTip.AddTool( GetDlgItem(IDC_INTERACT),IDC_INTERACT);
m_toolTip.AddTool( GetDlgItem(IDC_DELAY),IDC_DELAY);
m_toolTip.AddTool( GetDlgItem(IDC_SENT),IDC_SENT);
m_toolTip.AddTool( GetDlgItem(IDC_RECEIVED),IDC_RECEIVED);
m_toolTip.AddTool( GetDlgItem(IDC_FORCE),IDC_FORCE);
// Set the button state to the state of the messages window
m_Hide.SetCheck(m_pStatusWriter->IsHidden());
m_Start.EnableWindow(m_cuPorts.size() > 1 ? TRUE : FALSE);
m_Stop.EnableWindow(FALSE); // disable the stop monitoring button
if (m_cuPorts.size() > 0) {
m_Start.EnableWindow(TRUE);
} else {
m_Start.EnableWindow(FALSE);
m_pStatusWriter->WriteStatus("No COM ports detected - cannot start");
}
m_ComSelect.ResetContent();
// Fill up the COMBOBOX with our serial ports
for (UINT i=0; i<m_cuPorts.size(); i++)
{
// CComboBox
CString csTemp;
csTemp.Format("COM%d", m_cuPorts[i]);
m_ComSelect.AddString(csTemp);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// Enumerate the serial ports available on this computer
void CDetailDlg::Enumerate(void)
{
TRACE(_T("Enumerating serial ports in this Machine. "));
m_EnumSerial.UsingCreateFile(m_cuPorts);
int i=m_cuPorts.size();
TRACE(_T("Done, %d serial ports found\n"), i);
}
// When the "Com Port Select" combobox is closed, handle the new com port.
void CDetailDlg::OnSelendokComselect()
{//CComboBox
CString csText;
m_ComSelect.GetLBText(m_ComSelect.GetCurSel(),csText);
csText = "Selected " + csText;
m_pStatusWriter->WriteStatus(csText);
m_pSupervisor->SetCurrentPort(m_cuPorts[m_ComSelect.GetCurSel()]);
}
void CDetailDlg::OnKillfocusComselect()
{
// Display the current com port in the ComboBox
CString csTemp;
csTemp.Format("COM%d", m_pSupervisor->GetCurrentPort());
m_ComSelect.SetWindowText(csTemp);
}
// Here is where we set the model of car we've got.
// The model number is the index of the resources in the ComboBox.
// The order of these must match what the supervisor is expecting.
void CDetailDlg::OnSelendokModel()
{
m_iModel = m_Model.GetCurSel();
if (m_cuPorts.size() > 0) {
m_Start.EnableWindow(TRUE);
} else {
m_Start.EnableWindow(FALSE);
m_pStatusWriter->WriteStatus("No COM ports detected - cannot start");
}
m_Stop.EnableWindow(FALSE); // disable the stop monitoring button
Init();
}
// Listen radio button
void CDetailDlg::OnListen()
{
m_Listen.SetCheck(TRUE);
m_Interact.SetCheck(FALSE);
m_pSupervisor->Interact(FALSE);
m_Force.EnableWindow(FALSE);
}
// Interact radio button
void CDetailDlg::OnInteract()
{
m_Listen.SetCheck(FALSE);
m_Interact.SetCheck(TRUE);
m_pSupervisor->Interact(TRUE);
m_Force.EnableWindow(m_Stop.IsWindowEnabled());
}
void CDetailDlg::OnCsv()
{
if (m_bCSVFirstTime)
{
m_bCSVFirstTime = FALSE;
if (!(m_pSupervisor->StartCSVLog(TRUE)))
m_bCSVFirstTime = TRUE;// Call may have failed
else
m_CSV.SetWindowText("Stop");
}
else
{
m_bCSVFirstTime = TRUE;
m_CSV.SetWindowText("Start");
m_pSupervisor->StartCSVLog(FALSE);
}
}
void CDetailDlg::OnCsvoptions()
{
AfxMessageBox("Sorry, not yet implemented");
}
void CDetailDlg::OnForce()
{
m_pSupervisor->ForceDataFromECU();
}
void CDetailDlg::OnDegC()
{
m_DegC.SetCheck(TRUE);
m_DegF.SetCheck(FALSE);
m_pSupervisor->Centigrade(TRUE);
m_pStatusWriter->WriteStatus("Temperatures will be in degrees C");
}
void CDetailDlg::OnDegF()
{
m_DegC.SetCheck(FALSE);
m_DegF.SetCheck(TRUE);
m_pSupervisor->Centigrade(FALSE);
m_pStatusWriter->WriteStatus("Temperatures will be in degrees F");
AfxMessageBox("Please Note: this version only displays Centrigrade in the dashboard");
}
void CDetailDlg::OnKph()
{
m_kph.SetCheck(TRUE);
m_mph.SetCheck(FALSE);
m_pSupervisor->Miles(FALSE);
m_pStatusWriter->WriteStatus("Speeds will be in kph");
}
void CDetailDlg::OnMph()
{
m_kph.SetCheck(FALSE);
m_mph.SetCheck(TRUE);
m_pSupervisor->Miles(TRUE);
m_pStatusWriter->WriteStatus("Speeds will be in mph");
}
// Handles the delay combobox
void CDetailDlg::OnSelendokDelay()
{
CString csText;
int delay;
m_WriteDelay.GetLBText(m_WriteDelay.GetCurSel(), csText);
delay = atoi(csText);
m_pSupervisor->SetWriteDelay(delay);
csText.Format("Write Delay Set to %dmS", delay);
m_pStatusWriter->WriteStatus(csText);
}