Skip to content

Commit

Permalink
updated readme and added method to get system constants
Browse files Browse the repository at this point in the history
  • Loading branch information
asap2Go committed Nov 4, 2022
1 parent b237644 commit 37dfc5b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 40 deletions.
69 changes: 41 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
# calibrationReader
[![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)
## Scope
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
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.
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
As of now the 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.

## Current capablilites
Right now the package can parse a2l-files as well as the corresponding IntelHex32 or Motorola S19 files.
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.
Right now the package can parse a2l-files as well as the corresponding IntelHex32 or Motorola S19 files.
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.
### and what is still left to do
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.
This is the next point on my list as everything else seems to be quite stable now.
Once implemented version 1.0 will be released.
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.
This currently worked on as everything else seems to be quite stable now.
Once completely implemented version 1.0 will be released.

## Usage
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.
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.

`calibrationData, err := ReadCalibration(a2lFilePath, hexFilePath)`
`calibrationData, err := ReadCalibration(a2lFilePath, hexFilePath)`

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

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

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

To access Characteristics:
`c, exists := mod.Characteristics["NameOfCharacteristic"]`
To access System Constants:

and so on.
`sc, exists := mod.SystemConstants["NameOfSystemConstant"]`

To access a specific memory location in the hex-file (contains a single byte):
`b, exists := calibrationData.hex[12345]`
To access Characteristics:

`c, exists := mod.Characteristics["NameOfCharacteristic"]`

and so on.

To access a specific memory location in the hex-file (contains a single byte):

`b, exists := calibrationData.hex[12345]`

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

## Dependencies and Licensing
The only dependency outside the go standard library is currently zerolog.
The package is - and will always be - released under MIT license.
Feel free to do with it what you want :)
The only dependency outside the go standard library is currently zerolog.
The package is - and will always be - released under MIT license.
Feel free to do with it what you want :)
2 changes: 1 addition & 1 deletion a2l/mod_par.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ forLoop:
log.Err(err).Msg("modPar systemConstant could not be parsed")
break forLoop
}
mp.SystemConstants[buf.name] = buf
mp.SystemConstants[buf.Name] = buf
log.Info().Msg("modPar systemConstant successfully parsed")
case userToken:
mp.user, err = parseUser(tok)
Expand Down
22 changes: 11 additions & 11 deletions a2l/system_constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

type SystemConstant struct {
name string
nameSet bool
value string
valueSet bool
Name string
NameSet bool
Value string
ValueSet bool
}

func parseSystemConstant(tok *tokenGenerator) (SystemConstant, error) {
Expand All @@ -21,19 +21,19 @@ forLoop:
tok.next()
if tok.current() == emptyToken {
err = errors.New("unexpected end of file")
log.Err(err).Msg("systemConstant: " + sc.name + " could not be parsed")
log.Err(err).Msg("systemConstant: " + sc.Name + " could not be parsed")
break forLoop
} else if isKeyword(tok.current()) {
err = errors.New("unexpected token " + tok.current())
log.Err(err).Msg("systemConstant could not be parsed")
break forLoop
} else if !sc.nameSet {
sc.name = tok.current()
sc.nameSet = true
} else if !sc.NameSet {
sc.Name = tok.current()
sc.NameSet = true
log.Info().Msg("systemConstant name successfully parsed")
} else if !sc.valueSet {
sc.value = tok.current()
sc.valueSet = true
} else if !sc.ValueSet {
sc.Value = tok.current()
sc.ValueSet = true
log.Info().Msg("systemConstant value successfully parsed")
break forLoop
}
Expand Down
15 changes: 15 additions & 0 deletions record_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ func (cd *CalibrationData) getSystemConstant(ident string) (a2l.SystemConstant,
return s, nil
}

func (cd *CalibrationData) getSystemConstantValue(ident string) (string, error) {
sc, err := cd.getSystemConstant(ident)
if err != nil {
log.Err(err).Msg("could not get value of system constant")
return "", err
}
var val string
if !sc.ValueSet {
err = errors.New("no value defined in system constant " + sc.Name)
log.Err(err).Msg("could not get value of system constant")
return "", err
}
return val, nil
}

func (cd *CalibrationData) getCharacteristicValueBinary(c a2l.Characteristic) (interface{}, error) {
var err error
rl, err := cd.getRecordLayout(c)
Expand Down

0 comments on commit 37dfc5b

Please sign in to comment.