-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
2022 lines (1997 loc) · 132 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.IO.Pipes;
using System.Windows.Forms.VisualStyles;
using System.Runtime.InteropServices.ComTypes;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Diagnostics.Eventing.Reader;
namespace PSA_CVM2
{
public partial class Form1 : Form
{
public string serialData;
public string mileage;
public string BSI = ">752:652";
public string CodingKeyBSI;
public string CVM = ">74A:64A";
public string CodingKeyCVM;
public string DAE = ">6B5:695";
public string CodingKeyDAE;
public string AAS = ">75D:65D";
public string CodingKeyAAS;
public string ARTIV = ">6B6:696";
public string CodingKeyARTIV;
public string COMBINE = ">75F:65F";
public string CodingKeyCOMBINE;
public string TELEMAT = ">764:664";
public string CodingKeyTELEMAT;
public string INJ = ">6A8:688";
public string CodingKeyINJ;
public string BVA = ">6A9:689";
public string CodingKeyBVA;
public string ABRASR = ">6AD:68D";
public string CodingKeyABRASR;
private string zone;
public Form1()
{
InitializeComponent();
UpdateCOMPortList();
}
private void UpdateCOMPortList()
{
comboBoxCOM.Items.Clear();
String[] ports = SerialPort.GetPortNames(); //przypisanie aktywnego nr portu COM
foreach (String x in ports)
comboBoxCOM.Items.Add(x);
int val = comboBoxCOM.Items.Count;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " Found " + val.ToString() + " device(s)" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
if (val > 0)
{
comboBoxCOM.SelectedIndex = 0;
}
}
private void ButtonSearchCOM_Click(object sender, EventArgs e)
{
UpdateCOMPortList();
}
private void ButtonStart_Click(object sender, EventArgs e)
{
if (comboBoxCOM.Text == string.Empty)
{
textBoxInfo.Text = "COM port not selected";
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " COM port not selected" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
else if (comboBoxCOM.Text != string.Empty)
{
if (comboBoxCOM.Visible == true)
{
spArduino.PortName = comboBoxCOM.Text; // Potwierdzenie wyszukania odpowiedniego portu COM
try
{
spArduino.Open();
}
catch
{
textBoxInfo.Text = "COM port is not accesible";
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " COM port is not accesible" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
return;
}
}
buttonStart.Enabled = false;
buttonStop.Enabled = true;
buttonSearchCOM.Enabled = false;
buttonIdentifyVIN.Enabled = true;
textBoxInfo.Text = "Connected to Interface";
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " Connected to Interface" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
}
private void ButtonStop_Click(object sender, EventArgs e)
{
spArduino.WriteLine(String.Format("82"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 82") + Environment.NewLine;
spArduino.WriteLine(String.Format("1001"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1001") + Environment.NewLine;
spArduino.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
buttonSearchCOM.Enabled = true;
buttonIdentifyVIN.Enabled = false;
LockIdentification();
LockCodingBSI();
LockCodingCVM();
LockCodingDAE();
LockCodingAAS();
LockCodingARTIV();
LockCodingCOMBINE();
LockCodingTELEMAT();
LockCodingINJ();
LockCodingBVA();
textBoxVin.Clear();
textBoxInfo.Text = "Disconnected";
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " Disconnected" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
public async void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort spArduino = (SerialPort)sender;
serialData = spArduino.ReadLine();
}
private void ButtonClearLog_Click(object sender, EventArgs e)
{
richTextBoxLog.Clear();
}
public void ButtonIdentifyVIN_Click(object sender, EventArgs e)
{
textBoxVin.Clear();
string odpowiedz = ConnectModuleUDS(BSI);
if (odpowiedz.Substring(0, 4) == "5003")
{
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
Vinbsi();
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
else
{
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " Not connected to car" + Environment.NewLine;
textBoxInfo.Text = "Not connected to car";
MessageBox.Show("Not connected to car");
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
}
public void Vinbsi()
{
string odebraneVIN = ReadZoneUDS("F190");
string toRemove = "62F190"; // procedura usuwania polecania CAN z ciagu danych do wyświetlenia VIN
string result = string.Empty;
int s = odebraneVIN.IndexOf(toRemove);
if (s >= 0)
{
result = odebraneVIN.Remove(s, toRemove.Length); // Wynik obciecia polecenia CAN w formie Ciągu danych
}
String byteStr = result; // zmiana ciagu danych na tabelę bajtów
int ileBajtow = byteStr.Length / 2;
byte[] tab = new byte[ileBajtow];
for (int j = 0; j < ileBajtow; j++)
{
String wyodrebnione = byteStr.Substring(j * 2, 2);
byte b = Convert.ToByte(wyodrebnione, 16);
tab[j] = b;
string hexValues = Convert.ToString(tab[j]);
int value = Convert.ToInt32(hexValues); // konwertowanie ASCII do TEKSTU VIN
string stringValue = Char.ConvertFromUtf32(value);
char charValue = (char)value;
string VIN1 = charValue.ToString();
textBoxVin.AppendText(VIN1);
if (textBoxVin.TextLength == 17)
{
string mileage = ReadZoneUDS("DBA2").Substring(6,8);
textBoxmileage.Text = Convert.ToInt32(mileage, 16) / 10 + " km";
UnlockIdentification();
if (!Directory.Exists(@"Logs"))
{ Directory.CreateDirectory("Logs"); }
string path = @"Logs\Log-" + textBoxVin.Text + "-" + textBoxmileage.Text + ".txt";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Log");
}
}
}
}
}
private void LockIdentification()
{
buttonIdentifyVIN.Enabled = false;
buttonIdentifyBSI.Enabled = false;
buttonIdentifyCVM.Enabled = false;
buttonIdentifyDAE.Enabled = false;
buttonIdentifyAAS.Enabled = false;
buttonIdentifyARTIV.Enabled = false;
buttonIdentifyCOMBINE.Enabled = false;
buttonIdentifyTELEMAT.Enabled = false;
buttonIdentifyINJ.Enabled = false;
buttonIdentifyBVA.Enabled = false;
buttonReadFaults.Enabled = false;
buttonClearFaults.Enabled = false;
}
private void UnlockIdentification()
{
buttonIdentifyVIN.Enabled = true;
buttonIdentifyBSI.Enabled = true;
buttonIdentifyCVM.Enabled = true;
buttonIdentifyDAE.Enabled = true;
buttonIdentifyAAS.Enabled = true;
buttonIdentifyARTIV.Enabled = true;
buttonIdentifyCOMBINE.Enabled = true;
buttonIdentifyTELEMAT.Enabled = true;
buttonIdentifyINJ.Enabled = true;
buttonIdentifyBVA.Enabled = true;
buttonReadFaults.Enabled = true;
buttonClearFaults.Enabled = true;
}
private void UnlockCodingBSI()
{
buttonReadZoneBSI.Enabled = true;
buttonStartCodingBSI.Enabled = true;
buttonWriteZoneBSI.Enabled = true;
}
private void LockCodingBSI()
{
buttonReadZoneBSI.Enabled = false;
buttonStartCodingBSI.Enabled = false;
buttonWriteZoneBSI.Enabled = false;
}
private void UnlockCodingCVM()
{
buttonReadCodingCVM.Enabled = true;
buttonReadZoneCVM.Enabled = true;
buttonWriteCodingCVM.Enabled = true;
}
private void LockCodingCVM()
{
buttonReadCodingCVM.Enabled = false;
buttonReadZoneCVM.Enabled = false;
buttonWriteCodingCVM.Enabled = false;
}
private void UnlockCodingDAE()
{
buttonReadCodingDAE.Enabled = true;
buttonWriteCodingDAE.Enabled = true;
buttonReadZoneDAE.Enabled = true;
}
private void LockCodingDAE()
{
buttonReadCodingDAE.Enabled = false;
buttonWriteCodingDAE.Enabled = false;
buttonReadZoneDAE.Enabled = false;
}
private void UnlockCodingAAS()
{
buttonReadZoneAAS.Enabled = true;
buttonReadCodingAAS.Enabled = true;
buttonWriteCodingAAS.Enabled = true;
}
private void LockCodingAAS()
{
buttonReadZoneAAS.Enabled = false;
buttonReadCodingAAS.Enabled = false;
buttonWriteCodingAAS.Enabled = false;
}
private void UnlockCodingARTIV()
{
buttonReadZoneARTIV.Enabled = true;
buttonReadCodingARTIV.Enabled = true;
buttonWriteCodingARTIV.Enabled = true;
}
private void LockCodingARTIV()
{
buttonReadZoneARTIV.Enabled = false;
buttonReadCodingARTIV.Enabled = false;
buttonWriteCodingARTIV.Enabled = false;
}
private void UnlockCodingCOMBINE()
{
buttonReadZoneCOMBINE.Enabled = true;
}
private void LockCodingCOMBINE()
{
buttonReadZoneCOMBINE.Enabled = false;
}
private void UnlockCodingTELEMAT()
{
buttonReadZoneTELEMAT.Enabled = true;
buttonWriteCodingTELEMAT.Enabled = true;
}
private void LockCodingTELEMAT()
{
buttonReadZoneTELEMAT.Enabled = false;
buttonWriteCodingTELEMAT.Enabled = false;
}
private void UnlockCodingINJ()
{
buttonReadZoneINJ.Enabled = true;
}
private void LockCodingINJ()
{
buttonReadZoneINJ.Enabled = false;
}
private void UnlockCodingBVA()
{
buttonReadZoneBVA.Enabled = true;
}
private void LockCodingBVA()
{
buttonReadZoneBVA.Enabled = false;
}
private string ConnectModuleUDS(string type)
{
textBoxInfo.Clear();
spArduino.WriteLine(String.Format("1001"));
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1001") + Environment.NewLine;
spArduino.WriteLine(String.Format(type));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " " + String.Format(type) + Environment.NewLine;
Task.Delay(10).Wait();
spArduino.WriteLine(String.Format("1003"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1003") + Environment.NewLine;
Task.Delay(50).Wait();
spArduino.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
string odpowiedz = serialData;
return odpowiedz;
}
private string ConnectModuleKWPHAB(string type)
{
textBoxInfo.Clear();
spArduino.WriteLine(String.Format("1001"));
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1001") + Environment.NewLine;
Thread.Sleep(100);
spArduino.WriteLine(String.Format(type));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " " + String.Format(type) + Environment.NewLine;
Thread.Sleep(100);
spArduino.WriteLine(String.Format("10C0"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 10C0") + Environment.NewLine;
Thread.Sleep(500);
string odpowiedz = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
return odpowiedz;
}
private string ConnectModuleKWP(string type)
{
textBoxInfo.Clear();
spArduino.WriteLine(String.Format("1001"));
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1001") + Environment.NewLine;
Thread.Sleep(100);
spArduino.WriteLine(String.Format(type));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " " + String.Format(type) + Environment.NewLine;
Thread.Sleep(100);
spArduino.WriteLine(String.Format("81"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 81") + Environment.NewLine;
Thread.Sleep(500);
string odpowiedz = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
return odpowiedz;
}
private string ReadZoneUDS(string zone)
{
spArduino.WriteLine("22" + zone);
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " > 22" + zone + Environment.NewLine;
Thread.Sleep(500);
string odpowiedz = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odpowiedz + Environment.NewLine;
return odpowiedz;
}
private string WriteZoneUDS(string zone,string value)
{
spArduino.WriteLine("2E" + zone + value);
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " > 2E" + zone + value + Environment.NewLine;
Thread.Sleep(500);
string odpowiedz = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odpowiedz + Environment.NewLine;
return odpowiedz;
}
private string ReadZoneKWP(string zone)
{
spArduino.WriteLine("21" + zone);
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " > 21" + zone + Environment.NewLine;
Thread.Sleep(500);
string odpowiedz = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odpowiedz + Environment.NewLine;
return odpowiedz;
}
public void ButtonIdentifyBSI_Click(object sender, EventArgs e)
{
richTextBoxLog.Text += Environment.NewLine + "Connecting to BSI" + Environment.NewLine;
string odpowiedz = ConnectModuleUDS(BSI);
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
string odebraneBSIZA = ReadZoneUDS("F080");
string odebraneBSIZI = ReadZoneUDS("F0FE");
string[] RefBSIZI = { odebraneBSIZI.Substring(18, 6), odebraneBSIZI.Substring(26, 2), odebraneBSIZI.Substring(28, 2), odebraneBSIZI.Substring(30, 2), odebraneBSIZI.Substring(32, 6), odebraneBSIZI.Substring(46, 2), odebraneBSIZI.Substring(48, 6) };
textBoxSWBSI.Text = "96" + RefBSIZI[6] + "80";
textBoxHWBSI.Text = odebraneBSIZA.Substring(20, 10);
int TD = Convert.ToInt32(RefBSIZI[4].Substring(0, 2), 16);
int TM = Convert.ToInt32(RefBSIZI[4].Substring(2, 2), 16);
int TY = Convert.ToInt32(RefBSIZI[4].Substring(4, 2), 16);
string TDstring = TD.ToString();
string TMstring = TM.ToString();
string TYstring = "20" + TY.ToString();
if (RefBSIZI[4].Substring(0, 2) == "FF")
{
TDstring = RefBSIZI[4].Substring(0, 2);
TMstring = RefBSIZI[4].Substring(2, 2);
TYstring = RefBSIZI[4].Substring(4, 2);
}
string typbsi = odebraneBSIZI.Substring(14, 4);// wydobycie z ciągu sekcji 4 bajtów typu modułu z odebranych danych
textBoxTypBSI.Text = typbsi;
if (typbsi == "13B3")
{ // warunek przypisania typu modułu do kodu Bajtowego
textBoxTypBSI.Text = "DELPHI BSI2010_EV";
richTextBoxLog.Text += Environment.NewLine + "BSI: " + string.Format(textBoxTypBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefBSIZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefBSIZI[2]) +"." + string.Format(RefBSIZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefBSIZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefBSIZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefBSIZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefBSIZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
CodingKeyBSI = "B4E0";
UnlockCodingBSI();
}
else if (typbsi == "06B3")
{
textBoxTypBSI.Text = "VALEO NOx";
richTextBoxLog.Text += Environment.NewLine + "BSI: " + string.Format(textBoxTypBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefBSIZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefBSIZI[2]) + "." + string.Format(RefBSIZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefBSIZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefBSIZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefBSIZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefBSIZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingBSI();
}
else if (typbsi == "0DB3")
{
textBoxTypBSI.Text = "CONTINENTAL Q0x";
richTextBoxLog.Text += Environment.NewLine + "BSI: " + string.Format(textBoxTypBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefBSIZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefBSIZI[2]) + "." + string.Format(RefBSIZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefBSIZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefBSIZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefBSIZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefBSIZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingBSI();
}
else
{
textBoxTypBSI.Text = "Unknown " + typbsi;
richTextBoxLog.Text += Environment.NewLine + "BSI: " + string.Format(textBoxTypBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefBSIZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefBSIZI[2]) + "." + string.Format(RefBSIZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefBSIZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWBSI.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefBSIZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefBSIZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefBSIZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingBSI();
}
}
public void ButtonReadZoneBSI_Click(object sender, EventArgs e)
{
if (textBoxZoneBSI.Text != "")
{
spArduino.WriteLine(String.Format("1003")); // Otwarcie sesji diagnostycznej
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1003");
Thread.Sleep(100);
string odebrane3 = ReadZoneUDS(textBoxZoneBSI.Text);
string toRemove = "62" + textBoxZoneBSI.Text;
string result2 = string.Empty; // obcięcie polecenia CN do wyświetlenia w textbox - to juz znamy z opisu VIN
int s = odebrane3.IndexOf(toRemove); // Zapis string.Empty lub string = ""; to to samo
if (s >= 0)
{
result2 = odebrane3.Remove(s, toRemove.Length);
}
textBoxZoneValueBSI.Text = result2; // wyświetlenie wartości kodowania w textbox
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
if (textBoxZoneValueBSI.Text == "") // sposób wyświetlnia w polu INFO warunki wystapienia zdarzeń
{
textBoxInfo.Text = "No coding in this zone";
}
}
else
{
textBoxInfo.Text = "Please select zone";
}
}
public void ButtonStartCodingBSI_Click(object sender, EventArgs e)
{
spArduino.WriteLine(String.Format(":" + String.Format(CodingKeyBSI) + ":03:03"));
Thread.Sleep(100);
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > :" + String.Format(CodingKeyBSI) + ":03:03");
}
private void ButtonWriteZoneBSI_Click(object sender, EventArgs e)
{
if (textBoxZoneNewValueBSI.Text == "")
{
textBoxInfo.Text = "New coding not written";
}
else if (textBoxZoneValueBSI.Text == textBoxZoneNewValueBSI.Text)
{
textBoxInfo.Text = "Coding wasn't changed";
}
else if (textBoxZoneValueBSI.Text != textBoxZoneNewValueBSI.Text)
{
WriteZoneUDS(textBoxZoneBSI.Text, textBoxZoneNewValueBSI.Text);
}
}
public void ButtonIdentifyCVM_Click(object sender, EventArgs e)
{
richTextBoxLog.Text += Environment.NewLine + "Connecting to CVM" + Environment.NewLine;
string odpowiedz = ConnectModuleUDS(CVM);
if (odpowiedz.Substring(0, 2) == "OK")
{
string message = "Module not installed in car";
textBoxInfo.Text = message;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " " + String.Format(message) + Environment.NewLine;
buttonIdentifyCVM.Enabled = false;
MessageBox.Show(message);
}
else
{
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
string odebraneCVMZA = ReadZoneUDS("F080");
string odebraneCVMZI = ReadZoneUDS("F0FE");
string[] RefCVMZI = { odebraneCVMZI.Substring(18, 6), odebraneCVMZI.Substring(26, 2), odebraneCVMZI.Substring(28, 2), odebraneCVMZI.Substring(30, 2), odebraneCVMZI.Substring(32, 6), odebraneCVMZI.Substring(46, 2), odebraneCVMZI.Substring(48, 6) };
textBoxSWCVM.Text = "96" + RefCVMZI[6] + "80";
textBoxHWCVM.Text = odebraneCVMZA.Substring(20, 10);
int TD = Convert.ToInt32(RefCVMZI[4].Substring(0, 2), 16);
int TM = Convert.ToInt32(RefCVMZI[4].Substring(2, 2), 16);
int TY = Convert.ToInt32(RefCVMZI[4].Substring(4, 2), 16);
string TDstring = TD.ToString();
string TMstring = TM.ToString();
string TYstring = "20" + TY.ToString();
if (RefCVMZI[4].Substring(0, 2) == "FF")
{
TDstring = RefCVMZI[4].Substring(0, 2);
TMstring = RefCVMZI[4].Substring(2, 2);
TYstring = RefCVMZI[4].Substring(4, 2);
}
string typcvm = odebraneCVMZA.Substring(47, 3); // wydobycie z ciągu sekcji 4 bajtów typu BSI z odebranych danych
textBoxTypCVM.Text = typcvm;
if (typcvm == "199")
{ // warunek przypisania typu BSI do kodu Bajtowego
textBoxTypCVM.Text = "CVM_2";
richTextBoxLog.Text += Environment.NewLine + "CVM: " + string.Format(textBoxTypCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefCVMZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefCVMZI[2]) + "." + string.Format(RefCVMZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefCVMZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefCVMZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefCVMZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefCVMZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
CodingKeyCVM = "E2E5";
UnlockCodingCVM();
}
else if (typcvm == "179")
{
textBoxTypCVM.Text = "CVM_3";
richTextBoxLog.Text += Environment.NewLine + "CVM: " + string.Format(textBoxTypCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefCVMZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefCVMZI[2]) + "." + string.Format(RefCVMZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefCVMZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefCVMZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefCVMZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefCVMZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
CodingKeyCVM = "E2E5";
UnlockCodingCVM();
}
else
{
textBoxTypCVM.Text = "Unknown " + typcvm;
richTextBoxLog.Text += Environment.NewLine + "CVM: " + string.Format(textBoxTypCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefCVMZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefCVMZI[2]) + "." + string.Format(RefCVMZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefCVMZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefCVMZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefCVMZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefCVMZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingCVM();
}
}
}
private void ButtonReadCodingCVM_Click(object sender, EventArgs e)
{
if (textBoxTypCVM.Text == "CVM_2")
{
string odebraneCodingCVM = ReadZoneUDS("2100");
string toRemove3 = String.Format("622100");
int s2 = odebraneCodingCVM.IndexOf(toRemove3);
string resultCodingCVM = odebraneCodingCVM.Remove(s2, toRemove3.Length);
textBoxCVMCoding.Text = resultCodingCVM;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
else if (textBoxTypCVM.Text == "CVM_3")
{
string odebraneCodingCVM = ReadZoneUDS("2101");
string toRemove3 = String.Format("622101");
int s2 = odebraneCodingCVM.IndexOf(toRemove3);
string resultCodingCVM = odebraneCodingCVM.Remove(s2, toRemove3.Length);
textBoxCVMCoding.Text = resultCodingCVM;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
spArduino.WriteLine(String.Format("1001")); // reset komunikacji
Thread.Sleep(100);
}
public void ButtonWriteCodingCVM_Click(object sender, EventArgs e)
{
if (textBoxCVMNewCoding.Text == "")
{
textBoxInfo.Text = "New coding not written";
}
else if (textBoxCVMCoding.Text == textBoxCVMNewCoding.Text)
{
textBoxInfo.Text = "Coding wasn't changed";
}
else if (textBoxCVMCoding.Text != textBoxCVMNewCoding.Text)
{
if (textBoxTypCVM.Text == "CVM_2")
{
zone = "2100";
}
else if (textBoxTypCVM.Text == "CVM_3")
{
zone = "2101";
}
spArduino.WriteLine(":" + CodingKeyCVM + ":03:03");
Thread.Sleep(100);
string odebrane = serialData;
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane + Environment.NewLine;
if (odebrane.Substring(0, 4) == "6704")
{
string command = "2E" + String.Format(zone) + textBoxCVMNewCoding.Text;
spArduino.WriteLine(String.Format(command));
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " > " + String.Format(command) + Environment.NewLine;
Thread.Sleep(100);
string odebrane3 = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane3 + Environment.NewLine;
//wyslac ramke 2E2901FD000000010101 aby nie bylo bledu B1003 zabezpieczonego kodowania
Thread.Sleep(200);
spArduino.WriteLine("2E2901FD000000010101");
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " > 2E290100000000010101" + Environment.NewLine;
Thread.Sleep(100);
string odebrane4 = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane4 + Environment.NewLine;
}
else
{
textBoxInfo.Text = "Coding conditions not met";
}
}
}
private void ButtonReadZoneCVM_Click(object sender, EventArgs e)
{
if (textBoxZoneCVM.Text != "")
{
spArduino.WriteLine(String.Format("1003")); // Otwarcie sesji diagnostycznej
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1003");
Thread.Sleep(100);
string odebrane3 = ReadZoneUDS(textBoxZoneCVM.Text);
string toRemove = "62" + textBoxZoneCVM.Text;
string result2 = string.Empty; // obcięcie polecenia CN do wyświetlenia w textbox - to juz znamy z opisu VIN
int s = odebrane3.IndexOf(toRemove); // Zapis string.Empty lub string = ""; to to samo
if (s >= 0)
{
result2 = odebrane3.Remove(s, toRemove.Length);
}
textBoxZoneValueCVM.Text = result2; // wyświetlenie wartości kodowania w textbox
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
if (textBoxZoneValueCVM.Text == "") // sposób wyświetlnia w polu INFO warunki wystapienia zdarzeń
{
textBoxInfo.Text = "No coding in this zone";
}
}
else
{
textBoxInfo.Text = "Please select zone";
}
}
public void ButtonIdentifyDAE_Click(object sender, EventArgs e)
{
richTextBoxLog.Text += Environment.NewLine + "Connecting to DAE" + Environment.NewLine;
string odpowiedz = ConnectModuleKWP(DAE);
if (odpowiedz.Substring(0, 2) == "C1")
{
string odebraneDAEZA = ReadZoneKWP("80");
string odebraneDAEZI = ReadZoneKWP("FE");
string[] RefDAEZA = { odebraneDAEZA.Substring(4, 10), odebraneDAEZA.Substring(16, 2), odebraneDAEZA.Substring(18, 10), odebraneDAEZA.Substring(28, 4) };
string[] RefDAEZI = { odebraneDAEZI.Substring(16, 6), odebraneDAEZI.Substring(24, 2), odebraneDAEZI.Substring(26, 4), odebraneDAEZI.Substring(30, 6), odebraneDAEZI.Substring(44, 2), odebraneDAEZI.Substring(46, 6) };
textBoxSWDAE.Text = "96" + RefDAEZI[5] + "80";
textBoxTypDAE.Text = "DAE_BVH2";
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Software Version: " + RefDAEZA[3].Substring(0, 2) + "." + RefDAEZA[3].Substring(2, 2) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2].Substring(0, 2)) + "." + string.Format(RefDAEZI[2].Substring(2, 2)) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[4]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + Convert.ToInt32(RefDAEZI[3].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[3].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[3].Substring(4, 2), 16) + Environment.NewLine;
//richTextBoxLog.Text += "HW: " + string.Format(textBoxHWCVM.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
CodingKeyDAE = "2305";
UnlockCodingDAE();
}
else
{
odpowiedz = ConnectModuleUDS(DAE);
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + String.Format(odpowiedz) + Environment.NewLine;
string odebraneDAEZA = ReadZoneUDS("F080");
string odebraneDAEZI = ReadZoneUDS("F0FE");
string[] RefDAEZI = { odebraneDAEZI.Substring(18, 6), odebraneDAEZI.Substring(26, 2), odebraneDAEZI.Substring(28, 2), odebraneDAEZI.Substring(30, 2), odebraneDAEZI.Substring(32, 6), odebraneDAEZI.Substring(46, 2), odebraneDAEZI.Substring(48, 6) };
textBoxSWDAE.Text = "96" + RefDAEZI[6] + "80";
textBoxHWDAE.Text = odebraneDAEZA.Substring(20, 10);
int TD = Convert.ToInt32(RefDAEZI[4].Substring(0, 2), 16);
int TM = Convert.ToInt32(RefDAEZI[4].Substring(2, 2), 16);
int TY = Convert.ToInt32(RefDAEZI[4].Substring(4, 2), 16);
string TDstring = TD.ToString();
string TMstring = TM.ToString();
string TYstring = "20" + TY.ToString();
if (RefDAEZI[4].Substring(0, 2) == "FF")
{
TDstring = RefDAEZI[4].Substring(0, 2);
TMstring = RefDAEZI[4].Substring(2, 2);
TYstring = RefDAEZI[4].Substring(4, 2);
}
string typdae = odebraneDAEZI.Substring(14, 4);// wydobycie z ciągu sekcji 4 bajtów typu modułu z odebranych danych
textBoxTypDAE.Text = typdae;
if (typdae == "796C")
{
textBoxTypDAE.Text = "DAE_UDS";
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2]) + "." + string.Format(RefDAEZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingDAE();
}
else if (typdae == "136A")
{
textBoxTypDAE.Text = "?";
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2]) + "." + string.Format(RefDAEZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingDAE();
}
else if (typdae == "215B")
{
textBoxTypDAE.Text = "GEP_UDS";
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2]) + "." + string.Format(RefDAEZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingDAE();
}
else if (typdae == "215D")
{
textBoxTypDAE.Text = "DAE_UDS";
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2]) + "." + string.Format(RefDAEZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingDAE();
}
else
{
textBoxTypDAE.Text = "Unknown " + typdae;
richTextBoxLog.Text += Environment.NewLine + "DAE: " + string.Format(textBoxTypDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefDAEZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefDAEZI[2]) + "." + string.Format(RefDAEZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefDAEZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWDAE.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefDAEZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefDAEZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefDAEZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
UnlockCodingDAE();
}
}
}
public void ButtonReadCodingDAE_Click(object sender, EventArgs e)
{
if (textBoxTypDAE.Text == "DAE_BVH2")
{
string odebrane = ReadZoneKWP("A0");
string toRemove4 = String.Format("61A0");
int s2 = odebrane.IndexOf(toRemove4); // Zapis string.Empty lub string = ""; to to samo
string CodingDAE = odebrane.Remove(s2, toRemove4.Length);
textBoxDAECoding.Text = CodingDAE;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
else if (textBoxTypDAE.Text == "DAE_UDS")
{
string odebrane = ReadZoneUDS("2101");
string toRemove4 = String.Format("622101");
int s2 = odebrane.IndexOf(toRemove4); // Zapis string.Empty lub string = ""; to to samo
string CodingDAE = odebrane.Remove(s2, toRemove4.Length);
textBoxDAECoding.Text = CodingDAE;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
else
{
textBoxInfo.Text = "Select zone";
richTextBoxLog.Text += Environment.NewLine + "Select zone" + Environment.NewLine;
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
}
}
private void ButtonReadZoneDAE_Click(object sender, EventArgs e)
{
if (textBoxZoneDAE.Text != "")
{
spArduino.WriteLine(String.Format("1003")); // Otwarcie sesji diagnostycznej
richTextBoxLog.Text += Environment.NewLine + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 1003");
Thread.Sleep(100);
string odebrane3 = ReadZoneUDS(textBoxZoneDAE.Text);
string toRemove = "62" + textBoxZoneDAE.Text;
string result2 = string.Empty; // obcięcie polecenia CN do wyświetlenia w textbox - to juz znamy z opisu VIN
int s = odebrane3.IndexOf(toRemove); // Zapis string.Empty lub string = ""; to to samo
if (s >= 0)
{
result2 = odebrane3.Remove(s, toRemove.Length);
}
textBoxZoneValueDAE.Text = result2; // wyświetlenie wartości kodowania w textbox
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
if (textBoxZoneValueDAE.Text == "") // sposób wyświetlnia w polu INFO warunki wystapienia zdarzeń
{
textBoxInfo.Text = "No coding in this zone";
}
}
else
{
textBoxInfo.Text = "Please select zone";
}
}
public void ButtonWriteCodingDAE_Click(object sender, EventArgs e)
{
spArduino.WriteLine(String.Format("81"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > 81") + Environment.NewLine;
Thread.Sleep(500);
string odebrane = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane + Environment.NewLine;
spArduino.WriteLine(String.Format(":" + CodingKeyDAE + ":83:C0"));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" >:" + CodingKeyDAE + ":83:C0") + Environment.NewLine;
Thread.Sleep(500);
string odebrane1 = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane1 + Environment.NewLine;
string str = "34A00000000605" + textBoxNewCodingDAE.Text + "FD000000";
byte[] BTS = StringToByteArray(str);
ushort calc_crc = Crc16_x25(BTS, BTS.Length);
calc_crc = (ushort)ROL(calc_crc, 8);
richTextBoxLog.Text += $"CRC16-x25 : {calc_crc.ToString("X")}" + Environment.NewLine;
string CodingMessage = str + calc_crc.ToString("X");
spArduino.WriteLine(String.Format(CodingMessage));
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + String.Format(" > ") + CodingMessage + Environment.NewLine;
Thread.Sleep(500);
string odebrane2 = serialData;
richTextBoxLog.Text += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " < " + odebrane2 + Environment.NewLine;
}
public void ButtonIdentifyAAS_Click(object sender, EventArgs e)
{
richTextBoxLog.Text += Environment.NewLine + "Connecting to AAS" + Environment.NewLine;
ConnectModuleUDS(AAS);
string odebraneAASZA = ReadZoneUDS("F080");
string odebraneAASZI = ReadZoneUDS("F0FE");
string[] RefAASZI = { odebraneAASZI.Substring(18, 6), odebraneAASZI.Substring(26, 2), odebraneAASZI.Substring(28, 2), odebraneAASZI.Substring(30, 2), odebraneAASZI.Substring(32, 6), odebraneAASZI.Substring(46, 2), odebraneAASZI.Substring(48, 6) };
textBoxSWAAS.Text = "96" + RefAASZI[6] + "80";
textBoxHWAAS.Text = odebraneAASZA.Substring(20, 10);
int TD = Convert.ToInt32(RefAASZI[4].Substring(0, 2), 16);
int TM = Convert.ToInt32(RefAASZI[4].Substring(2, 2), 16);
int TY = Convert.ToInt32(RefAASZI[4].Substring(4, 2), 16);
string TDstring = TD.ToString();
string TMstring = TM.ToString();
string TYstring = "20" + TY.ToString();
if (RefAASZI[4].Substring(0, 2) == "FF")
{
TDstring = RefAASZI[4].Substring(0, 2);
TMstring = RefAASZI[4].Substring(2, 2);
TYstring = RefAASZI[4].Substring(4, 2);
}
string typAAS = odebraneAASZA.Substring(46, 4); // wydobycie z ciągu sekcji 4 bajtów typu BSI z odebranych danych
textBoxTypAAS.Text = typAAS;
if (typAAS == "2199")
{
textBoxTypAAS.Text = "AAS_UDS_G5";
richTextBoxLog.Text += Environment.NewLine + "AAS: " + string.Format(textBoxTypAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefAASZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefAASZI[2]) + "." + string.Format(RefAASZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefAASZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefAASZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefAASZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefAASZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
// string CodingKeyAAS = "0000";
UnlockCodingAAS();
}
else if (typAAS == "8199")
{ // warunek przypisania typu BSI do kodu Bajtowego
textBoxTypAAS.Text = "CPK_UDS_G5";
richTextBoxLog.Text += Environment.NewLine + "AAS: " + string.Format(textBoxTypAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefAASZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefAASZI[2]) + "." + string.Format(RefAASZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefAASZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefAASZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefAASZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefAASZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
CodingKeyAAS = "D1F5";
UnlockCodingAAS();
}
else if (typAAS == "4599")
{
textBoxTypAAS.Text = "AAS_G4";
richTextBoxLog.Text += Environment.NewLine + "AAS: " + string.Format(textBoxTypAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefAASZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefAASZI[2]) + "." + string.Format(RefAASZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefAASZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefAASZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefAASZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefAASZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
// string CodingKeyAAS = "xxxx";
UnlockCodingAAS();
}
else if (typAAS == "FFFF")
{
textBoxTypAAS.Text = "AAS_UDS_G6";
richTextBoxLog.Text += Environment.NewLine + "AAS: " + string.Format(textBoxTypAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefAASZI[1] + Environment.NewLine;
richTextBoxLog.Text += "Calibration Reference: " + string.Format(textBoxSWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Edition(Hex): " + string.Format(RefAASZI[2]) + "." + string.Format(RefAASZI[3]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission Counter:" + string.Format(RefAASZI[5]) + Environment.NewLine;
richTextBoxLog.Text += "Teletransmission date: " + string.Format(TDstring) + "." + string.Format(TMstring) + "." + string.Format(TYstring) + Environment.NewLine;
richTextBoxLog.Text += "Hardware Number: " + string.Format(textBoxHWAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Production date: " + Convert.ToInt32(RefAASZI[0].Substring(0, 2), 16) + "." + Convert.ToInt32(RefAASZI[0].Substring(2, 2), 16) + ".20" + Convert.ToInt32(RefAASZI[0].Substring(4, 2), 16);
richTextBoxLog.SelectionStart = richTextBoxLog.Text.Length;
// string CodingKeyAAS = "B6F0";
UnlockCodingAAS();
}
else
{
textBoxTypAAS.Text = "Unknown " + typAAS;
richTextBoxLog.Text += Environment.NewLine + "AAS: " + string.Format(textBoxTypAAS.Text) + Environment.NewLine;
richTextBoxLog.Text += "Calibration Version: " + RefAASZI[1] + Environment.NewLine;