-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoffsetOp.go
113 lines (106 loc) · 4.03 KB
/
offsetOp.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
package calibrationReader
import (
"errors"
"github.com/asap2Go/calibrationReader/a2l"
"github.com/rs/zerolog/log"
)
// getOffsetX retrieves the offset operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getOffsetX(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.OffsetX.DatatypeSet {
err := errors.New("offsetX datatype not set")
log.Err(err).Msg("could not retrieve offsetX value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.OffsetX.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve offsetX value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.OffsetX.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve offsetX value")
return 0, err
}
*curPos += uint32(rl.OffsetX.Datatype.GetDatatypeLength())
return int64(val), err
}
// getOffsetY retrieves the offset operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getOffsetY(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.OffsetY.DatatypeSet {
err := errors.New("offsetY datatype not set")
log.Err(err).Msg("could not retrieve offsetY value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.OffsetY.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve offsetY value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.OffsetY.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve offsetY value")
return 0, err
}
*curPos += uint32(rl.OffsetY.Datatype.GetDatatypeLength())
return int64(val), err
}
// getOffsetZ retrieves the offset operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getOffsetZ(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.OffsetZ.DatatypeSet {
err := errors.New("offsetZ datatype not set")
log.Err(err).Msg("could not retrieve offsetZ value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.OffsetZ.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve offsetZ value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.OffsetZ.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve offsetZ value")
return 0, err
}
*curPos += uint32(rl.OffsetZ.Datatype.GetDatatypeLength())
return int64(val), err
}
// getOffset4 retrieves the offset operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getOffset4(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.Offset4.DatatypeSet {
err := errors.New("offset4 datatype not set")
log.Err(err).Msg("could not retrieve offset4 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.Offset4.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve offset4 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.Offset4.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve offset4 value")
return 0, err
}
*curPos += uint32(rl.Offset4.Datatype.GetDatatypeLength())
return int64(val), err
}
// getOffset5 retrieves the offset operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getOffset5(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.Offset5.DatatypeSet {
err := errors.New("offset5 datatype not set")
log.Err(err).Msg("could not retrieve offset5 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.Offset5.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve offset5 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.Offset5.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve offset5 value")
return 0, err
}
*curPos += uint32(rl.Offset5.Datatype.GetDatatypeLength())
return int64(val), err
}