-
Notifications
You must be signed in to change notification settings - Fork 0
/
t7_footer.go
147 lines (126 loc) · 3.41 KB
/
t7_footer.go
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
package symbol
import (
"encoding/binary"
"log"
)
func (t7 *T7File) clearPiArea() {
const startPosition = 0x07FE00
if len(t7.data) <= startPosition {
return
}
for i := startPosition; i < len(t7.data); i++ {
(t7.data)[i] = 0xFF
}
log.Println("Footer cleared")
}
func (t7 *T7File) createPiArea() {
log.Println("Creating new footer")
pos := len(t7.data) - 1
pos = t7.writeFooterString(pos, 0x91, t7.vehicleIDNr)
pos = t7.writeFooterString(pos, 0x94, t7.partNumber)
pos = t7.writeFooterString(pos, 0x95, t7.softwareVersion)
pos = t7.writeFooterString(pos, 0x97, t7.carDescription)
pos = t7.writeFooterString(pos, 0x9A, t7.dateModified)
if t7.symbolTableChecksumDetected {
pos = t7.writeFooterInt(pos, 0x9C, t7.sramOffset)
}
if t7.symbolTableMarkerDetected {
pos = t7.writeFooterInt(pos, 0x9B, t7.symbolTableAddress)
}
if t7.f2ChecksumDetected {
pos = t7.writeFooterIntx(pos, 0xF2, t7.checksumF2)
}
pos = t7.writeFooterIntx(pos, 0xFB, t7.checksumFB)
pos = t7.writeFooterInt(pos, 0xFC, t7.bottomOfFlash)
pos = t7.writeFooterInt(pos, 0xFD, t7.romChecksumType)
pos = t7.writeFooterIntx(pos, 0xFE, t7.fwLength)
pos = t7.writeFooterBytes(pos, 0xFA, t7.lastModifiedBy)
pos = t7.writeFooterString(pos, 0x92, t7.immobilizerID)
pos = t7.writeFooterString(pos, 0x93, t7.ecuHardwareNr)
pos = t7.writeFooterInt16(pos, 0xF8, t7.valueF8)
pos = t7.writeFooterInt16(pos, 0xF7, t7.valueF7)
pos = t7.writeFooterInt16(pos, 0xF6, t7.valueF6)
pos = t7.writeFooterInt16(pos, 0xF5, t7.valueF5)
pos = t7.writeFooterString(pos, 0x90, t7.chassisID)
pos = t7.writeFooterString(pos, 0x99, t7.testserialnr)
pos = t7.writeFooterString(pos, 0x98, t7.engineType)
t7.writeFooterBytes(pos, 0xF9, []byte{t7.romChecksumError})
// log.Printf("pos: %d, %X", pos, t7.data[0x07FE00:])
}
func (t7 *T7File) writeFooter(pos int, h T7HeaderField) int {
t7.data[pos] = h.Length
pos--
t7.data[pos] = h.ID
for i := 0; i < int(h.Length); i++ {
t7.data[pos-int(h.Length)+i] = h.Data[int(h.Length-1)-i]
}
pos -= int(h.Length + 1)
return pos
}
func (t7 *T7File) writeFooterBytes(pos int, id byte, value []byte) int {
h := T7HeaderField{
ID: id,
Length: byte(len(value)),
Data: value,
}
return t7.writeFooter(pos, h)
}
func (t7 *T7File) writeFooterString(pos int, id byte, value string) int {
h := T7HeaderField{
ID: id,
Length: byte(len(value)),
Data: []byte(value),
}
return t7.writeFooter(pos, h)
}
func (t7 *T7File) writeFooterInt(pos int, id byte, value int) int {
h := T7HeaderField{
ID: id,
Length: 4,
Data: make([]byte, 4),
}
binary.BigEndian.PutUint32(h.Data, uint32(value))
t7.data[pos] = h.Length
pos--
t7.data[pos] = h.ID
pos--
t7.data[pos] = h.Data[3]
pos--
t7.data[pos] = h.Data[2]
pos--
t7.data[pos] = h.Data[1]
pos--
t7.data[pos] = h.Data[0]
pos--
return pos
}
func (t7 *T7File) writeFooterIntx(pos int, id byte, value int) int {
h := T7HeaderField{
ID: id,
Length: 4,
Data: make([]byte, 4),
}
binary.BigEndian.PutUint32(h.Data, uint32(value))
t7.data[pos] = h.Length
pos--
t7.data[pos] = h.ID
pos--
t7.data[pos] = h.Data[0]
pos--
t7.data[pos] = h.Data[1]
pos--
t7.data[pos] = h.Data[2]
pos--
t7.data[pos] = h.Data[3]
pos--
return pos
}
func (t7 *T7File) writeFooterInt16(pos int, id byte, value int) int {
h := T7HeaderField{
ID: id,
Length: 2,
Data: make([]byte, 2),
}
binary.LittleEndian.PutUint16(h.Data, uint16(value))
return t7.writeFooter(pos, h)
}