-
Notifications
You must be signed in to change notification settings - Fork 2
/
distOp.go
113 lines (106 loc) · 4.04 KB
/
distOp.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"
)
// getDistOpX retrieves the distance operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getDistOpX(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.DistOpX.DatatypeSet {
err := errors.New("distOpX datatype not set")
log.Err(err).Msg("could not retrieve distOpX value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.DistOpX.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve distOpX value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.DistOpX.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve distOpX value")
return 0, err
}
*curPos += uint32(rl.DistOpX.Datatype.GetDatatypeLength())
return int64(val), err
}
// getDistOpY retrieves the distance operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getDistOpY(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.DistOpY.DatatypeSet {
err := errors.New("distOpY datatype not set")
log.Err(err).Msg("could not retrieve distOpY value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.DistOpY.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve distOpY value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.DistOpY.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve distOpY value")
return 0, err
}
*curPos += uint32(rl.DistOpY.Datatype.GetDatatypeLength())
return int64(val), err
}
// getDistOpZ retrieves the distance operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getDistOpZ(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.DistOpZ.DatatypeSet {
err := errors.New("distOpZ datatype not set")
log.Err(err).Msg("could not retrieve distOpZ value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.DistOpZ.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve distOpZ value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.DistOpZ.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve distOpZ value")
return 0, err
}
*curPos += uint32(rl.DistOpZ.Datatype.GetDatatypeLength())
return int64(val), err
}
// getDistOp4 retrieves the distance operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getDistOp4(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.DistOp4.DatatypeSet {
err := errors.New("distOp4 datatype not set")
log.Err(err).Msg("could not retrieve distOp4 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.DistOp4.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve distOp4 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.DistOp4.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve distOp4 value")
return 0, err
}
*curPos += uint32(rl.DistOp4.Datatype.GetDatatypeLength())
return int64(val), err
}
// getDistOp5 retrieves the distance operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getDistOp5(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.DistOp5.DatatypeSet {
err := errors.New("distOp5 datatype not set")
log.Err(err).Msg("could not retrieve distOp5 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.DistOp5.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve distOp5 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.DistOp5.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve distOp5 value")
return 0, err
}
*curPos += uint32(rl.DistOp5.Datatype.GetDatatypeLength())
return int64(val), err
}