-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
1608 lines (1547 loc) · 67.7 KB
/
frmMain.cs
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Decompiled with JetBrains decompiler
// Type: J2534.frmECMTECH
// Assembly: ECM-TECH Suite, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null
// MVID: B30416E2-D8D0-4434-82C3-04779BF15D87
// Assembly location: D:\Users\Vida\Desktop\ME7 suite\ME7 Suite.exe
// from the Openmoose project on GITHUB
//slightly modified by JJ, private bool BitBashConnect() -- press connect button and it send a CANPacket and tries to save 1000 packets (no luck here)
using J2534.Checksums;
using J2534.Display;
using J2534.Flash;
using J2534.Flash.ECU;
using J2534.Logging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
namespace J2534
{
public class frmMain : Form
{
private byte[] readout = new byte[0];
private byte[] ramReadout = new byte[0];
public readonly string HKCU_RUN = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
public readonly string APP_KEY = "Software\\" + Application.ProductName;
private byte[] binFile;
private int flashTime;
private ToolComm dice;
private ECUProgrammer eProg;
private bool flash512;
private bool p80;
private long logTime;
private ECULogger logger;
private int numLogSessions;
private frmMain.StateObjClass StateObj;
private Utility.ModifyRegistry.ModifyRegistry regedit;
[Obfuscation(Exclude = true, Feature = "default", StripAfterObfuscation = false)]
private ECUParameters eParams;
[Obfuscation(Exclude = true, Feature = "default", StripAfterObfuscation = false)]
private ECUVariables eVars;
private CultureInfo culture;
private StreamWriter logFile;
private IContainer components;
private System.Windows.Forms.Timer flashTimer;
private Button but_connectdice;
private ComboBox comboBox_J2534_devices;
private Button cmdDetectDevices;
private MenuStrip menuMain;
private ToolStripMenuItem fileToolStripMenuItem;
private ColorDialog colorDialog1;
private System.Windows.Forms.Timer readTimer;
private ToolStripMenuItem resetServiceReminderToolStripMenuItem;
private TabControl tabControl1;
private TabPage tabPage1;
private ProgressBar progressFlash;
private Button cmdRead;
private Button cmdFlash;
private Button cmdReset;
private TextBox txtBin;
private Label lblTime;
private TabPage tabPage2;
private CheckBox chkPSI;
private GroupBox groupBox1;
private Label vitals_custom;
private Label label_custom;
private Label vitals_retard;
private Label label6;
private Label vitals_fuelpressure;
private Label label5;
private Label vitals_lambda;
private Label label3;
private Label vitals_boost;
private Label label1;
private ComboBox comboBox_xmlparams;
private Label lblLogTime;
private CheckBox chkshowvitals;
private Button cmdStopLogging;
private Button cmdStartLogging;
private Button cmdChooseLog;
private TextBox txtParamsFile;
private TextBox txtLogFile;
private Button but_chooseparams;
private System.Windows.Forms.Timer logTimer;
private Label label2;
private Label label4;
private TabPage tabPage3;
private Label label7;
private TabPage tabPage4;
private Label label8;
private Label label9;
private ToolStripMenuItem aboutToolStripMenuItem;
public frmMain()
{
this.InitializeComponent();
this.culture = CultureInfo.CreateSpecificCulture("en-GB");
Thread.CurrentThread.CurrentCulture = this.culture;
Thread.CurrentThread.CurrentUICulture = this.culture;
this.eParams = new ECUParameters();
this.eVars = new ECUVariables();
this.dice = new ToolComm();
}
private void openBINFile()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Volvo ME7 BIN File (*.bin)|*.bin";
if (openFileDialog.ShowDialog() != DialogResult.OK)
return;
long num1 = new FileInfo(openFileDialog.FileName).Length / 1024L;
switch (num1)
{
case 512:
case 1024:
this.txtBin.Text = openFileDialog.FileName;
this.flash512 = num1 == 512L;
try
{
VolvoChecksumUpdater volvoChecksumUpdater = new VolvoChecksumUpdater(openFileDialog.FileName);
if (!volvoChecksumUpdater.updateChecksums(true))
{
if (!volvoChecksumUpdater.updateChecksums(false))
{
int num2 = (int) MessageBox.Show("Unknown error updating checksums!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
Environment.Exit(3);
}
else
{
int num3 = (int) MessageBox.Show("Checksums updated!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
this.binFile = File.ReadAllBytes(openFileDialog.FileName);
break;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
break;
}
default:
int num4 = (int) MessageBox.Show("Incorrect File Size!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
break;
}
}
private void saveBINFile()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "ECU Binary (*.bin)|*.bin";
if (saveFileDialog.ShowDialog() != DialogResult.OK)
return;
this.txtBin.Text = saveFileDialog.FileName;
}
private void flashTimer_Tick(object sender, EventArgs e)
{
this.lblTime.Text = "Flash Time: " + this.flashTime.ToString();
lock (new object())
{
this.progressFlash.Value = this.flashTime > this.progressFlash.Maximum ? this.progressFlash.Maximum : this.flashTime;
if (this.eProg.doneFlashing)
{
this.flashTimer.Stop();
this.changeButtonState(true);
this.lblTime.Text = "Done Flashing!";
this.progressFlash.Value = 0;
}
}
++this.flashTime;
}
private void cmdFlash_Click(object sender, EventArgs e)
{
if (!this.dice.DeviceOpen)
{
int num1 = (int) MessageBox.Show("Please connect the J2534 Cable first.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
this.openBINFile();
if (this.txtBin.Text == "")
{
int num2 = (int) MessageBox.Show("Please choose a BIN file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else if (MessageBox.Show("Key MUST be in POS II with the engine NOT running. Are you ready?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
this.txtBin.Text = "";
}
else
{
this.flashTime = 0;
this.changeButtonState(false);
int length = this.binFile.Length;
if (this.binFile[length - 1] != (byte) 131 || this.binFile[length - 2] != (byte) 131)
{
int num3 = (int) MessageBox.Show("This is not a valid BIN file for this platform.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
this.changeButtonState(true);
this.txtBin.Text = "";
}
else
{
if (this.flash512)
this.progressFlash.Maximum = 56;
this.eProg = new ECUProgrammer(this.dice, VolvoECUCommands.sbl, this.binFile, this.flash512, this.p80);
this.eProg.startFlash();
this.flashTimer.Start();
}
}
}
}
private void cmdDetectDevices_Click(object sender, EventArgs e)
{
this.updateDevices();
}
private void updateDevices()
{
List<J2534Device> installedDevices = ToolComm.getInstalledDevices();
if (installedDevices.Count == 0)
{
int num = (int) MessageBox.Show("Could not find any installed J2534 devices.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
this.comboBox_J2534_devices.DataSource = (object) installedDevices;
}
private void Form1_Load(object sender, EventArgs e)
{
var resources = new System.Resources.ResourceManager(typeof(frmMain));
var image = (Bitmap)resources.GetObject("moosepic");
tabPage1.BackgroundImage = image;
this.updateDevices();
this.regedit = new Utility.ModifyRegistry.ModifyRegistry();
this.txtParamsFile.Text = this.getECUParams();
try
{
if (this.txtParamsFile.Text.Equals(""))
return;
if (this.txtParamsFile.Text.Split('.')[this.txtParamsFile.Text.Split('.').Length - 1].Equals("xml"))
{
this.parseParameters();
this.SetComboXML();
}
else
{
this.txtParamsFile.Text = "";
this.setECUParams("");
}
}
catch (Exception ex)
{
this.txtParamsFile.Text = "";
this.setECUParams("");
Console.WriteLine(ex.ToString());
}
}
public void processReqs(string msgs)
{
foreach (ECUVariable eVar in (List<ECUVariable>) this.eVars)
{
try
{
if (eVar.word)
{
string input = msgs.Substring(0, 4);
msgs = msgs.Substring(4);
eVar.value = eVar.getHexValueFromString(input);
}
else
{
string input = msgs.Substring(0, 2);
msgs = msgs.Substring(2);
eVar.value = eVar.getHexValueFromString(input);
}
}
catch (Exception ex)
{
eVar.value = (ushort) 0;
ex.ToString();
}
}
}
private void cmdStopLogging_Click(object sender, EventArgs e)
{
// this.dice.sendMsg(new CANPacket(ECULoggingCommands.msgCANRequestRecordSetStop), CANChannel.HS);
//if (this.logger.hs_Logging)
// this.logger.recs_req = false;
this.logFile.Close();
//string[] strArray = this.txtLogFile.Text.Split(new string[1]
//{
// ".csv"
//}, StringSplitOptions.None);
//if (strArray.Length != 0)
// this.txtLogFile.Text = strArray[0] + "_" + (object) this.numLogSessions + ".csv";
//else
// this.txtLogFile.Text = "";
try
{
this.logTimer.Stop();
this.stopTimer();
this.lblLogTime.Text = "Log Time: " + this.getLogTimeSeconds(false) + "sec";
this.logTime = 0L;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
// this.logger.clearReqs();
this.changeButtonState(true);
this.cmdStopLogging.Enabled = false;
this.cmdStartLogging.Enabled = true;
}
private void comboBox_xmlparams_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.eVars == null)
return;
string varVal = this.comboBox_xmlparams.SelectedValue.ToString();
List<ECUVariable> list = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>) (x => x.name.Contains(varVal))).ToList<ECUVariable>();
if (list.Count <= 0)
return;
this.label_custom.Text = list[0].name + " (" + list[0].units + ")";
}
private void licenseManagerToolStripMenuItem_Click_1(object sender, EventArgs e)
{
}
private string getECUParams()
{
this.regedit.BaseRegistryKey = Registry.CurrentUser;
this.regedit.SubKey = this.APP_KEY;
return this.regedit.Read("ECUParams");
}
private bool getReadLatch()
{
this.regedit.BaseRegistryKey = Registry.CurrentUser;
this.regedit.SubKey = this.APP_KEY;
string str = this.regedit.Read("ReadLatch");
try
{
return bool.Parse(str);
}
catch (Exception ex)
{
return false;
}
}
private bool setReadLatch(bool readOut)
{
this.regedit.BaseRegistryKey = Registry.CurrentUser;
this.regedit.SubKey = this.APP_KEY;
return this.regedit.Write("ReadLatch", (object) readOut.ToString());
}
private bool setECUParams(string ecuparams)
{
this.regedit.BaseRegistryKey = Registry.CurrentUser;
this.regedit.SubKey = this.APP_KEY;
return this.regedit.Write("ECUParams", (object) ecuparams);
}
private void txtLogFile_TextChanged(object sender, EventArgs e)
{
if (this.txtLogFile.Text.Equals(""))
this.cmdStartLogging.Enabled = false;
else
this.cmdStartLogging.Enabled = true;
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
int num = (int) MessageBox.Show("CAN Toolbox and Flashing Suite, by John Currie (c) 2016 " + Application.CompanyName, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
private static readonly CANPacket msgCANReadECMCustom = new CANPacket(new byte[8]{
(byte) 22,
(byte) 2,
(byte) 24,
(byte) 25,
(byte) 26,
(byte) 27,
(byte) 28,
(byte) 29
});
private bool BitBashConnect()
{
//send custom message once
this.dice.setHSBaud(BaudRate.CAN_500000);
this.dice.setJ2534Device(ToolComm.getInstalledDevices()[this.comboBox_J2534_devices.SelectedIndex]);
if (!this.dice.connect())
return false;
uint msgid1 = 0;
uint msgid2 = 0;
this.dice.startPeriodicMsg(ModuleProgrammer.msgCANTesterPresent, ref msgid1, 1000U, CANChannel.HS);
Thread.Sleep(1200);
bool flag = this.dice.sendMsgCheckDiagResponse(msgCANReadECMCustom, CANChannel.HS, (byte)249);
// if (!flag)
// {
// this.dice.stopPeriodicMsg(msgid1, CANChannel.HS);
// this.dice.disconnect();
// this.dice.setHSBaud(BaudRate.CAN_250000);
// if (!this.dice.connect())
// return false;
// Thread.Sleep(2200);
// this.dice.startPeriodicMsg(ModuleProgrammer.msgCANTesterPresent, ref msgid1, 1000U, CANChannel.HS);
// this.dice.startPeriodicMsg(ModuleProgrammer.msgCANTesterPresent, ref msgid2, 1000U, CANChannel.MS);
// Thread.Sleep(1200);
// flag = this.dice.sendMsgCheckDiagResponse(VolvoECUCommands.msgCANReadECMSerial, CANChannel.HS, (byte) 249);
// }
// this.dice.stopPeriodicMsg(msgid1, CANChannel.HS);
// if (this.dice.getHSBaud() == BaudRate.CAN_250000)
// this.dice.stopPeriodicMsg(msgid2, CANChannel.MS);
return flag;
}
private void but_connectdice_Click(object sender, EventArgs e)
{
this.changeButtonState(true); //toegevoegd om te loggen
bool flag = this.BitBashConnect();
switch (this.dice.getHSBaud())
{
case BaudRate.CAN_250000:
this.progressFlash.Maximum = 114;
break;
case BaudRate.CAN_500000:
this.progressFlash.Maximum = 81;
break;
}
// if (flag)
{
this.but_connectdice.Enabled = false;
this.cmdReset.Enabled = true;
this.comboBox_J2534_devices.Enabled = false;
this.cmdDetectDevices.Enabled = false;
this.changeButtonState(true);
}
// else
// {
// int num = (int) MessageBox.Show("DiCE is not connected", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
// try
// {
// this.dice.disconnect();
// }
// catch (Exception ex)
// {
// }
// this.dice = new ToolComm();
// }
}
private void but_chooseparams_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Volvo XML Parameter Files (*.xml)|*.xml";
if (openFileDialog.ShowDialog() != DialogResult.OK)
return;
this.txtParamsFile.Text = openFileDialog.FileName;
this.setECUParams(openFileDialog.FileName);
this.parseParameters();
if (this.eVars == null)
return;
this.SetComboXML();
}
private void parseParameters()
{
if (this.txtParamsFile.Text.Equals(""))
{
int num1 = (int) MessageBox.Show("Please choose a parameters file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
try
{
this.deserializeXML();
}
catch (Exception ex)
{
int num2 = (int) MessageBox.Show("Error in parameters file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
}
private void SetComboXML()
{
try
{
this.comboBox_xmlparams.DisplayMember = "var_txt";
this.comboBox_xmlparams.ValueMember = "var";
this.comboBox_xmlparams.DataSource = (object) this.eParams.ecuVars.Select(x => new
{
var_txt = x.name,
var = x.name
}).ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void deserializeXML()
{
if (this.eVars == null)
{
this.txtParamsFile.Text = "";
this.setECUParams("");
int num = (int) MessageBox.Show("Error parsing parameters file!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
try
{
this.eParams = XmlSerializer.ReadObject(this.txtParamsFile.Text);
this.eVars = this.eParams.ecuVars;
}
catch (Exception ex)
{
}
}
private void cmdChooseLog_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "CSV Files (*.csv)|*.csv";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
this.txtLogFile.Text = saveFileDialog.FileName.ToString();
else
this.txtLogFile.Text = "";
}
private void cmdStartLogging_Click(object sender, EventArgs e)
{
try
{
if (this.txtLogFile.Text.Equals(""))
{
int num = (int) MessageBox.Show("Please choose a log file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
// this.logger = new ECULogger(this.dice, this.eParams);
// if (!this.p80)
// new DIMComm(this.dice, true).sendMessage("Logging...");
// this.parseParameters();
// this.logger.sendReqs();
List<CANPacket> canPacketSniff;
// do
//{
uint maxNumMsgs = 1000;
uint timeout = 1000;
canPacketSniff = this.dice.ReadResponse(CANChannel.HS, ref maxNumMsgs, timeout);
//}
this.logFile = new StreamWriter(this.txtLogFile.Text, false);
//if (this.eParams.displayTime)
this.logFile.Write("Time (sec),");
string test;
test = "dummy";
this.logFile.Write(test);
foreach (CANPacket boodschap in canPacketSniff )
{
// if (eVar.desc.Equals("") || eVar.units.Equals(""))
// this.logFile.Write(eVar.name + ",");
// else
this.logFile.Write(boodschap.getLoggingDataString());
this.logFile.Write(test);
this.logFile.WriteLine();
}
this.logFile.Write("hellom,hlleh");
this.logFile.Write("hellasdfasdfasdfasdfom,hlleasdfasdfasdfasdfasdfasdfasdfh");
this.logFile.WriteLine();
//this.logTimer.Start();
//this.startTimer();
//this.changeButtonState(false);
this.cmdStartLogging.Enabled = false;
this.cmdStopLogging.Enabled = true;
++this.numLogSessions;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void logTimer_Tick_1(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = this.culture;
Thread.CurrentThread.CurrentUICulture = this.culture;
string result = "";
if (!this.logger.requestRecords(ref result))
return;
this.processReqs(result);
if (this.eParams.displayTime)
this.logFile.Write(this.getLogTimeSeconds(true) + ",");
foreach (ECUVariable eVar in (List<ECUVariable>) this.eVars)
{
int num = (int) eVar.value;
if (eVar.signed)
num = !eVar.word ? (int) (sbyte) eVar.value : (int) (short) eVar.value;
double dbValue = (double) num * eVar.factor + eVar.offset;
eVar.result = this.logger.getDoublePrecision(dbValue, eVar.precision);
this.logFile.Write(eVar.result + ",");
}
this.logFile.WriteLine();
this.lblLogTime.Text = "Log Time: " + this.getLogTimeSeconds(false) + "sec";
if (!this.chkshowvitals.Checked)
return;
List<ECUVariable> list1 = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>) (x => x.name.Contains("pvdkds_w"))).ToList<ECUVariable>();
if (list1.Count > 0)
{
if (this.chkPSI.Checked)
{
double num = (double.Parse(list1[0].result) - 1000.0) / 68.9475729;
this.vitals_boost.Text = this.logger.getDoublePrecision(num > 0.0 ? num : 0.0, list1[0].precision);
}
else
this.vitals_boost.Text = list1[0].result.ToString();
}
this.vitals_lambda.Text = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>) (x => x.name.Contains("lamsoni_w"))).ToList<ECUVariable>()[0].result.ToString();
List<ECUVariable> list2 = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>) (x => x.name.Contains("wkrm"))).ToList<ECUVariable>();
if (list2.Count > 0)
this.vitals_retard.Text = list2[0].result.ToString();
List<ECUVariable> list4 = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>)(x => x.name.Contains("pistnd_w"))).ToList<ECUVariable>();
if (list2.Count > 0)
this.vitals_fuelpressure.Text = list4[0].result.ToString();
List<ECUVariable> list3 = this.eVars.Where<ECUVariable>((Func<ECUVariable, bool>) (x => x.name.Contains(this.comboBox_xmlparams.SelectedValue.ToString()))).ToList<ECUVariable>();
if (list3.Count <= 0)
return;
this.vitals_custom.Text = list3[0].result.ToString();
}
private void startTimer()
{
this.StateObj = new frmMain.StateObjClass();
this.StateObj.TimerCanceled = false;
this.StateObj.lf = this.logFile;
this.StateObj.TimerReference = new System.Threading.Timer(new TimerCallback(this.TimerTask), (object) this.StateObj, 0, 100);
}
private void stopTimer()
{
try
{
this.StateObj.TimerCanceled = true;
}
catch (Exception ex)
{
ex.ToString();
}
}
private void TimerTask(object StateObj)
{
frmMain.StateObjClass stateObjClass = (frmMain.StateObjClass) StateObj;
Interlocked.Increment(ref this.logTime);
if (!stateObjClass.TimerCanceled)
return;
stateObjClass.TimerReference.Dispose();
}
private string getLogTimeSeconds(bool withMillis)
{
if (withMillis)
return ((double) this.logTime / 10.0).ToString("0.000");
return (this.logTime / 10L).ToString();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this.dice.DeviceOpen)
return;
this.dice.disconnectFinal();
}
private List<CANPacket> createSBLList()
{
List<CANPacket> canPacketList = new List<CANPacket>();
int num1 = 0;
while (num1 < VolvoECUCommands.sbl.Length)
{
CANPacket canPacket = new CANPacket(VolvoECUCommands.msgCANSendDataPrefix);
byte[] mData = new byte[6];
int num2 = VolvoECUCommands.sbl.Length - num1;
for (int index = 0; index < 6; ++index)
mData[index] = num2 < index + 1 ? (byte) 0 : VolvoECUCommands.sbl[num1 + index];
canPacket.setMsgData(mData);
canPacketList.Add(canPacket);
num1 += 6;
}
return canPacketList;
}
private void changeButtonState(bool setEnabled)
{
this.cmdFlash.Enabled = setEnabled;
this.cmdRead.Enabled = setEnabled;
this.cmdReset.Enabled = setEnabled;
this.cmdStartLogging.Enabled = setEnabled;
this.cmdStopLogging.Enabled = setEnabled;
this.resetServiceReminderToolStripMenuItem.Enabled = setEnabled;
}
private List<CANPacket> createData8kList()
{
List<CANPacket> canPacketList = new List<CANPacket>();
int num1 = 32768;
while (num1 < 57344)
{
CANPacket canPacket = new CANPacket(VolvoECUCommands.msgCANSendDataPrefix);
byte[] mData = new byte[6];
int num2 = this.binFile.Length - num1;
for (int index = 0; index < 6; ++index)
mData[index] = num2 < index + 1 ? (byte) 0 : this.binFile[num1 + index];
canPacket.setMsgData(mData);
canPacketList.Add(canPacket);
num1 += 6;
}
return canPacketList;
}
private List<CANPacket> createData10kList()
{
List<CANPacket> canPacketList = new List<CANPacket>();
int num1 = 65536;
while (num1 < 1048576)
{
CANPacket canPacket = new CANPacket(VolvoECUCommands.msgCANSendDataPrefix);
byte[] mData = new byte[6];
int num2 = this.binFile.Length - num1;
for (int index = 0; index < 6; ++index)
mData[index] = num2 < index + 1 ? (byte) 0 : this.binFile[num1 + index];
canPacket.setMsgData(mData);
canPacketList.Add(canPacket);
num1 += 6;
}
return canPacketList;
}
public int getHexValueFromString(string input)
{
if (input.Contains<char>('x'))
input = input.Split('x')[1];
if (input.Length == 2)
return (int) this.getAddressFromString(input)[0];
if (input.Length == 4)
{
byte[] addressFromString = this.getAddressFromString(input);
return (int) addressFromString[1] + (int) (ushort) ((uint) addressFromString[0] * 256U);
}
if (input.Length != 8)
throw new Exception();
byte[] addressFromString1 = this.getAddressFromString(input);
return (int) addressFromString1[3] + (int) addressFromString1[2] * 256 + (int) addressFromString1[1] * 65536 + (int) addressFromString1[0] * 16777216;
}
private byte[] getAddressFromString(string input)
{
if (input.Contains<char>('x'))
input = input.Split('x')[1];
byte[] numArray = new byte[input.Length / 2];
char[] charArray = input.ToCharArray();
int index = 0;
while (index < charArray.Length)
{
numArray[index / 2] = (byte) (16U * (uint) this.getByteFromChar(charArray[index]));
numArray[index / 2] += this.getByteFromChar(charArray[index + 1]);
index += 2;
}
return numArray;
}
private byte getByteFromChar(char c)
{
switch (c)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'A':
case 'a':
return 10;
case 'B':
case 'b':
return 11;
case 'C':
case 'c':
return 12;
case 'D':
case 'd':
return 13;
case 'E':
case 'e':
return 14;
case 'F':
case 'f':
return 15;
default:
return 0;
}
}
private void licenseManagerToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void cmdReset_Click(object sender, EventArgs e)
{
if (this.eProg != null)
return;
this.eProg = new ECUProgrammer(this.dice, (byte[]) null, (byte[]) null, false, this.p80);
this.eProg.sendReset();
if (!this.p80)
new DIMComm(this.dice, false).setTime();
this.eProg = (ECUProgrammer) null;
}
private void cmdRead_Click(object sender, EventArgs e)
{
this.saveBINFile();
if (this.txtBin.Text == "")
{
int num1 = (int) MessageBox.Show("Please choose a BIN file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else if (!this.dice.DeviceOpen)
{
int num2 = (int) MessageBox.Show("Please connect the DiCE first.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else if (MessageBox.Show("Is the key in pos II with the engine NOT running?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
this.txtBin.Text = "";
}
else
{
this.flashTime = 0;
this.changeButtonState(false);
this.eProg = new ECUProgrammer(this.dice, VolvoECUCommands.sbl, (byte[]) null, this.flash512, this.p80);
new Thread((ThreadStart) (() =>
{
this.eProg.sendModuleReset();
this.eProg.sendSilence();
this.eProg.startPBL();
this.eProg.startSBL(VolvoECUCommands.sbl, true);
this.readout = this.eProg.readECU(false);
this.ramReadout = this.eProg.readECU(true);
this.eProg.sendReset();
Thread.Sleep(2000);
if (this.p80)
return;
new DIMComm(this.dice, false).setTime();
})).Start();
this.progressFlash.Maximum = 861;
this.readTimer.Start();
}
}
private void readTimer_Tick(object sender, EventArgs e)
{
this.lblTime.Text = "Read Time: " + this.flashTime.ToString();
lock (new object())
{
this.progressFlash.Value = this.flashTime > this.progressFlash.Maximum ? this.progressFlash.Maximum : this.flashTime;
if (this.eProg.doneFlashing)
{
this.readTimer.Stop();
this.progressFlash.Value = this.progressFlash.Maximum;
string str = this.txtBin.Text;
int length1 = str.LastIndexOf(".");
if (length1 >= 0)
str = str.Substring(0, length1);
if (this.ramReadout != null)
File.WriteAllBytes(str + "_RAM.bin", this.ramReadout);
if (this.readout == null)
{
int num = (int) MessageBox.Show("Error reading file!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
this.changeButtonState(true);
return;
}
if (this.readout.Length == 4)
{
if (ECUProgrammer.checkArrayEq(this.readout, new byte[4]
{
(byte) 68,
(byte) 69,
(byte) 78,
(byte) 89
}))
{
int num = (int) MessageBox.Show("This file cannot be read! An attempt to read and save the RAM was made.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
this.changeButtonState(true);
return;
}
}
//VolvoChecksumUpdater volvoChecksumUpdater = new VolvoChecksumUpdater(this.readout);
int length2 = this.readout.Length;
if (this.readout[length2 - 1] != (byte) 131 || this.readout[length2 - 2] != (byte) 131) //|| !volvoChecksumUpdater.updateChecksums(true))
{
int num = (int) MessageBox.Show("This file is corrupt. Please contact the distributor.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
this.changeButtonState(true);
this.txtBin.Text = "";
return;
}
File.WriteAllBytes(this.txtBin.Text, this.readout);
this.changeButtonState(true);
this.setReadLatch(true);
this.lblTime.Text = "Done Reading!";
this.progressFlash.Value = 0;
}
}
++this.flashTime;
}
private void resetServiceReminderToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!this.dice.DeviceOpen)
{
int num1 = (int) MessageBox.Show("Please connect the DiCE first.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
if (MessageBox.Show("Would you like to reset the SRI?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes || MessageBox.Show("Is the key in pos II with the engine NOT running?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
return;
this.eProg = new ECUProgrammer(this.dice, (byte[]) null, (byte[]) null, this.flash512, this.p80);
if (!new DIMComm(this.dice, false).resetSRI())
{
int num2 = (int) MessageBox.Show("Failed to reset the service indicator!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
int num3 = (int) MessageBox.Show("Service indicator reset!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.flashTimer = new System.Windows.Forms.Timer(this.components);
this.but_connectdice = new System.Windows.Forms.Button();
this.comboBox_J2534_devices = new System.Windows.Forms.ComboBox();
this.menuMain = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.resetServiceReminderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.readTimer = new System.Windows.Forms.Timer(this.components);
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label4 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.progressFlash = new System.Windows.Forms.ProgressBar();
this.cmdRead = new System.Windows.Forms.Button();
this.cmdFlash = new System.Windows.Forms.Button();