Skip to content

Commit b2ab906

Browse files
committed
Exported A2l & Hex from calib_data and changed SystemConstants to hashmap
Changed A2l & Hex from calibrationReader into exported fields so they are available for preliminary testing outside the library. Also changed SystemConstants from slice to a hashmap so theyx can be searched more efficiently.
1 parent e011758 commit b2ab906

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

a2l/mod_par.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type modPar struct {
2222
noOfInterfaces noOfInterfaces
2323
phoneNo phoneNo
2424
supplier supplier
25-
systemConstant []systemConstant
25+
SystemConstants map[string]systemConstant
2626
user user
2727
version version
2828
}
@@ -139,7 +139,7 @@ forLoop:
139139
log.Err(err).Msg("modPar systemConstant could not be parsed")
140140
break forLoop
141141
}
142-
mp.systemConstant = append(mp.systemConstant, buf)
142+
mp.SystemConstants[buf.name] = buf
143143
log.Info().Msg("modPar systemConstant successfully parsed")
144144
case userToken:
145145
mp.user, err = parseUser(tok)

calib_data.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import (
2626
"github.com/rs/zerolog/log"
2727
)
2828

29-
//CalibrationData contains the parsed structs from the a2l as well as the byte data from the hex file
30-
//that are parsed by ReadCalibration()
29+
// CalibrationData contains the parsed structs from the a2l as well as the byte data from the hex file
30+
// that are parsed by ReadCalibration()
3131
type CalibrationData struct {
32-
a2l a2l.A2L
33-
hex map[uint32]byte
32+
A2l a2l.A2L
33+
Hex map[uint32]byte
3434
}
3535

36-
//ReadCalibration takes filepaths to the a2l file and the hex file,
37-
//parses them in parallel and returns a CalibrationData struct
36+
// ReadCalibration takes filepaths to the a2l file and the hex file,
37+
// parses them in parallel and returns a CalibrationData struct
3838
func ReadCalibration(a2lFilePath string, hexFilePath string) (CalibrationData, error) {
3939
var err error
4040
var cd CalibrationData
@@ -66,13 +66,13 @@ func ReadCalibration(a2lFilePath string, hexFilePath string) (CalibrationData, e
6666
}
6767
return cd, firstErr
6868
}
69-
cd.a2l = <-a2lChan
70-
cd.hex = <-hexChan
69+
cd.A2l = <-a2lChan
70+
cd.Hex = <-hexChan
7171
return cd, nil
7272
}
7373

74-
//readA2L is a helper function intended to be run in a separate go routine to call the a2l parser
75-
//in order to be able to parse hex and a2l in parallel
74+
// readA2L is a helper function intended to be run in a separate go routine to call the a2l parser
75+
// in order to be able to parse hex and a2l in parallel
7676
func readA2L(wg *sync.WaitGroup, ca chan a2l.A2L, ce chan error, a2lFilePath string) {
7777
defer wg.Done()
7878
a, err := a2l.ParseFromFile(a2lFilePath)
@@ -87,8 +87,8 @@ func readA2L(wg *sync.WaitGroup, ca chan a2l.A2L, ce chan error, a2lFilePath str
8787
}
8888
}
8989

90-
//readHex is a helper function intended to be run in a separate go routine to call the hex parser
91-
//in order to be able to parse hex and a2l in parallel
90+
// readHex is a helper function intended to be run in a separate go routine to call the hex parser
91+
// in order to be able to parse hex and a2l in parallel
9292
func readHex(wg *sync.WaitGroup, ch chan map[uint32]byte, ce chan error, hexFilePath string) {
9393
defer wg.Done()
9494
if strings.Contains(strings.ToLower(hexFilePath), ".hex") {
@@ -122,7 +122,7 @@ func readHex(wg *sync.WaitGroup, ch chan map[uint32]byte, ce chan error, hexFile
122122

123123
}
124124

125-
//configureLogger adds a file logger, resets previous log file and does some formatting
125+
// configureLogger adds a file logger, resets previous log file and does some formatting
126126
func configureLogger() error {
127127
var err error
128128
var file *os.File
@@ -149,7 +149,7 @@ func (cd *CalibrationData) getObjectsByIdent(ident string) []interface{} {
149149
var buf interface{}
150150
var exists bool
151151

152-
for _, m := range cd.a2l.Project.Modules {
152+
for _, m := range cd.A2l.Project.Modules {
153153
buf, exists = m.AxisPts[ident]
154154
if exists {
155155
calibrationObjects = append(calibrationObjects, buf)

calib_data_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func BenchmarkReadCalibration(b *testing.B) {
2222
if err != nil {
2323
log.Err(err).Msg("failed reading calibration")
2424
} else {
25-
log.Info().Str("project name", cd.a2l.Project.Name).Msg("finished parsing")
26-
log.Info().Int("length of data in hex file", len(cd.hex)).Msg("finished parsing")
25+
log.Info().Str("project name", cd.A2l.Project.Name).Msg("finished parsing")
26+
log.Info().Int("length of data in hex file", len(cd.Hex)).Msg("finished parsing")
2727
log.Warn().Msg("time for parsing bench files: " + fmt.Sprint(elapsed.Milliseconds()))
2828
}
2929
cd, err = CalibrationData{}, nil
@@ -43,8 +43,8 @@ func TestReadCalibration(t *testing.T) {
4343
log.Err(err).Msg("failed reading calibration")
4444
t.Fatalf("failed parsing with error: %s.", err)
4545
} else {
46-
log.Info().Str("project name", cd.a2l.Project.Name).Msg("finished parsing")
47-
log.Info().Int("length of data in hex file", len(cd.hex)).Msg("finished parsing")
46+
log.Info().Str("project name", cd.A2l.Project.Name).Msg("finished parsing")
47+
log.Info().Int("length of data in hex file", len(cd.Hex)).Msg("finished parsing")
4848
log.Warn().Msg("time for parsing test files: " + fmt.Sprint(elapsed.Milliseconds()))
4949
startTime := time.Now()
5050
//find object in a2l struct

0 commit comments

Comments
 (0)