Skip to content

Commit 37dfc5b

Browse files
committed
updated readme and added method to get system constants
1 parent b237644 commit 37dfc5b

File tree

4 files changed

+68
-40
lines changed

4 files changed

+68
-40
lines changed

README.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,60 @@
11
# calibrationReader
22
[![Go Report Card](https://goreportcard.com/badge/github.com/asap2Go/calibrationReader)](https://goreportcard.com/report/github.com/asap2Go/calibrationReader) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e19560faf3484ccb88922ad3548b19ad)](https://www.codacy.com/gh/asap2Go/calibrationReader/dashboard?utm_source=github.com&utm_medium=referral&utm_content=asap2Go/calibrationReader&utm_campaign=Badge_Grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/e19560faf3484ccb88922ad3548b19ad)](https://www.codacy.com/gh/asap2Go/calibrationReader/dashboard?utm_source=github.com&utm_medium=referral&utm_content=asap2Go/calibrationReader&utm_campaign=Badge_Coverage) [![Go](https://github.com/asap2Go/calibrationReader/actions/workflows/go-build-test-and-license.yml/badge.svg)](https://github.com/asap2Go/calibrationReader/actions/workflows/go-build-test-and-license.yml) [![CodeQL](https://github.com/asap2Go/calibrationReader/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/asap2Go/calibrationReader/actions/workflows/codeql-analysis.yml) [![Go Reference](https://pkg.go.dev/badge/github.com/asap2Go/calibrationReader.svg)](https://pkg.go.dev/github.com/asap2Go/calibrationReader)
33
## Scope
4-
The calibrationReader package reads characteristics, system constants, measurement definitions etc. from an a2l file and correlates it with the data from a corresponding hex oder s19 file. It is build to cover the ASAM MCD 2MC specification in its current version 1.7.1
5-
As of now th package only uses the metadata part of the ASAM MCD 2MC standard. The interface descriptions which are used to communicate with an ECU and are defined in the AML datastructure are not within the scope of this package.
4+
The calibrationReader package reads characteristics, system constants, measurement definitions etc.
5+
from an a2l file and correlates it with the data from a corresponding hex oder s19 file.
6+
It is build to cover the ASAM MCD 2MC specification in its current version 1.7.1
7+
As of now the package only uses the metadata part of the ASAM MCD 2MC standard.
8+
The interface descriptions which are used to communicate with an ECU
9+
and are defined in the AML datastructure are not within the scope of this package.
610

711
## Current capablilites
8-
Right now the package can parse a2l-files as well as the corresponding IntelHex32 or Motorola S19 files.
9-
And it is quite fast at that. Currently a real world A2L(80MB) with its corresponding Hex File(10MB) will be parsed in less than a second.
12+
Right now the package can parse a2l-files as well as the corresponding IntelHex32 or Motorola S19 files.
13+
And it is quite fast at that. Currently a real world A2L(80MB) with its corresponding Hex File(10MB) will be parsed in less than a second.
1014
### and what is still left to do
11-
The package still lacks the last bit of work which is implementing the methods for axis_pts, axis_descr, record_layout and fnc_values in order to understand the memory layout and position of a specific characteristic.
12-
This is the next point on my list as everything else seems to be quite stable now.
13-
Once implemented version 1.0 will be released.
15+
The package still lacks the last bit of work which is implementing the methods for axis_pts, axis_descr, record_layout and fnc_values
16+
in order to understand the memory layout and position of a specific characteristic.
17+
This currently worked on as everything else seems to be quite stable now.
18+
Once completely implemented version 1.0 will be released.
1419

1520
## Usage
16-
This is only a preliminary explanation on how to access the datastructures as the API will be formalized when version 1.0 releases with the full scope of the package implemented.
21+
This is only a preliminary explanation on how to access the datastructures
22+
as the API will be formalized when version 1.0 releases with the full scope of the package implemented.
1723

18-
`calibrationData, err := ReadCalibration(a2lFilePath, hexFilePath)`
24+
`calibrationData, err := ReadCalibration(a2lFilePath, hexFilePath)`
1925

20-
parses an a2l and hex file into datastructures.
21-
All relevant information e.g. Record Layouts, Measurements, Characterstics, etc.
22-
are part of a module which is in turn part of the Project whithin the a2l data structure.
23-
An a2l file can contain several modules but in most real world applications only contains one.
24-
So indexOfModuleInProject (see below) can basically assumed to be 0.
25-
`mod := calibrationData.a2l.Project.Modules[indexOfModuleInProject]`
26+
parses an a2l and hex file into datastructures.
27+
All relevant information e.g. Record Layouts, Measurements, Characterstics, etc.
28+
are part of a module which is in turn part of the Project whithin the a2l data structure.
29+
An a2l file can contain several modules but in most real world applications only contains one.
30+
So indexOfModuleInProject (see below) can basically assumed to be 0.
31+
In the future this will be solved more elegantly with a cd.SetModule method.
32+
So the user can define the module he is going to work on.
2633

27-
All datastructures that are directly below a module within the a2l data structure hierarchy are accessible through maps by their identifiers.
34+
`mod := calibrationData.A2l.Project.Modules[indexOfModuleInProject]`
2835

29-
To access System Constants:
30-
`sc, exists := mod.SystemConstants["NameOfSystemConstant"]`
36+
Most datastructures that are directly below a module
37+
within the a2l data structure hierarchy are accessible through maps by their identifiers.
3138

32-
To access Characteristics:
33-
`c, exists := mod.Characteristics["NameOfCharacteristic"]`
39+
To access System Constants:
3440

35-
and so on.
41+
`sc, exists := mod.SystemConstants["NameOfSystemConstant"]`
3642

37-
To access a specific memory location in the hex-file (contains a single byte):
38-
`b, exists := calibrationData.hex[12345]`
43+
To access Characteristics:
44+
45+
`c, exists := mod.Characteristics["NameOfCharacteristic"]`
46+
47+
and so on.
48+
49+
To access a specific memory location in the hex-file (contains a single byte):
50+
51+
`b, exists := calibrationData.hex[12345]`
3952

4053
## Disclaimer
41-
I am a mechanical engineer, so any code you see might not be up to the standards of true/correct/modern/acceptable software development ;)
42-
Feedback is always appreciated.
54+
I am a mechanical engineer, so any code you see might not be up to the standards of true/correct/modern/acceptable software development ;)
55+
Feedback is always appreciated.
4356

4457
## Dependencies and Licensing
45-
The only dependency outside the go standard library is currently zerolog.
46-
The package is - and will always be - released under MIT license.
47-
Feel free to do with it what you want :)
58+
The only dependency outside the go standard library is currently zerolog.
59+
The package is - and will always be - released under MIT license.
60+
Feel free to do with it what you want :)

a2l/mod_par.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ forLoop:
140140
log.Err(err).Msg("modPar systemConstant could not be parsed")
141141
break forLoop
142142
}
143-
mp.SystemConstants[buf.name] = buf
143+
mp.SystemConstants[buf.Name] = buf
144144
log.Info().Msg("modPar systemConstant successfully parsed")
145145
case userToken:
146146
mp.user, err = parseUser(tok)

a2l/system_constant.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
)
88

99
type SystemConstant struct {
10-
name string
11-
nameSet bool
12-
value string
13-
valueSet bool
10+
Name string
11+
NameSet bool
12+
Value string
13+
ValueSet bool
1414
}
1515

1616
func parseSystemConstant(tok *tokenGenerator) (SystemConstant, error) {
@@ -21,19 +21,19 @@ forLoop:
2121
tok.next()
2222
if tok.current() == emptyToken {
2323
err = errors.New("unexpected end of file")
24-
log.Err(err).Msg("systemConstant: " + sc.name + " could not be parsed")
24+
log.Err(err).Msg("systemConstant: " + sc.Name + " could not be parsed")
2525
break forLoop
2626
} else if isKeyword(tok.current()) {
2727
err = errors.New("unexpected token " + tok.current())
2828
log.Err(err).Msg("systemConstant could not be parsed")
2929
break forLoop
30-
} else if !sc.nameSet {
31-
sc.name = tok.current()
32-
sc.nameSet = true
30+
} else if !sc.NameSet {
31+
sc.Name = tok.current()
32+
sc.NameSet = true
3333
log.Info().Msg("systemConstant name successfully parsed")
34-
} else if !sc.valueSet {
35-
sc.value = tok.current()
36-
sc.valueSet = true
34+
} else if !sc.ValueSet {
35+
sc.Value = tok.current()
36+
sc.ValueSet = true
3737
log.Info().Msg("systemConstant value successfully parsed")
3838
break forLoop
3939
}

record_manager.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ func (cd *CalibrationData) getSystemConstant(ident string) (a2l.SystemConstant,
1818
return s, nil
1919
}
2020

21+
func (cd *CalibrationData) getSystemConstantValue(ident string) (string, error) {
22+
sc, err := cd.getSystemConstant(ident)
23+
if err != nil {
24+
log.Err(err).Msg("could not get value of system constant")
25+
return "", err
26+
}
27+
var val string
28+
if !sc.ValueSet {
29+
err = errors.New("no value defined in system constant " + sc.Name)
30+
log.Err(err).Msg("could not get value of system constant")
31+
return "", err
32+
}
33+
return val, nil
34+
}
35+
2136
func (cd *CalibrationData) getCharacteristicValueBinary(c a2l.Characteristic) (interface{}, error) {
2237
var err error
2338
rl, err := cd.getRecordLayout(c)

0 commit comments

Comments
 (0)