-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshiftOp.go
113 lines (106 loc) · 4.08 KB
/
shiftOp.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"
)
// getShiftOpX retrieves the shift operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getShiftOpX(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.ShiftOpX.DatatypeSet {
err := errors.New("shiftOpX datatype not set")
log.Err(err).Msg("could not retrieve shiftOpX value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.ShiftOpX.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpX value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.ShiftOpX.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpX value")
return 0, err
}
*curPos += uint32(rl.ShiftOpX.Datatype.GetDatatypeLength())
return int64(val), err
}
// getShiftOpY retrieves the shift operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getShiftOpY(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.ShiftOpY.DatatypeSet {
err := errors.New("shiftOpY datatype not set")
log.Err(err).Msg("could not retrieve shiftOpY value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.ShiftOpY.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpY value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.ShiftOpY.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpY value")
return 0, err
}
*curPos += uint32(rl.ShiftOpY.Datatype.GetDatatypeLength())
return int64(val), err
}
// getShiftOpZ retrieves the shift operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getShiftOpZ(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.ShiftOpZ.DatatypeSet {
err := errors.New("shiftOpZ datatype not set")
log.Err(err).Msg("could not retrieve shiftOpZ value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.ShiftOpZ.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpZ value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.ShiftOpZ.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOpZ value")
return 0, err
}
*curPos += uint32(rl.ShiftOpZ.Datatype.GetDatatypeLength())
return int64(val), err
}
// / getShiftOp4 retrieves the shift operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getShiftOp4(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.ShiftOp4.DatatypeSet {
err := errors.New("shiftOp4 datatype not set")
log.Err(err).Msg("could not retrieve shiftOp4 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.ShiftOp4.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOp4 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.ShiftOp4.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOp4 value")
return 0, err
}
*curPos += uint32(rl.ShiftOp4.Datatype.GetDatatypeLength())
return int64(val), err
}
// getShiftOp5 retrieves the shift operator according to its layout specified within the record layout and their values as calibrated in the hex file
func (cd *CalibrationData) getShiftOp5(rl *a2l.RecordLayout, curPos *uint32) (int64, error) {
if !rl.ShiftOp5.DatatypeSet {
err := errors.New("shiftOp5 datatype not set")
log.Err(err).Msg("could not retrieve shiftOp5 value")
return 0, err
}
bufBytes, err := cd.getValue(curPos, rl.ShiftOp5.Datatype, rl)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOp5 value")
return 0, err
}
val, err := cd.convertByteSliceToDatatype(bufBytes, rl.ShiftOp5.Datatype)
if err != nil {
log.Err(err).Msg("could not retrieve shiftOp5 value")
return 0, err
}
*curPos += uint32(rl.ShiftOp5.Datatype.GetDatatypeLength())
return int64(val), err
}