Skip to content

Commit 5d65bf4

Browse files
committed
Exported Types & added comments
1 parent 2d9bd94 commit 5d65bf4

18 files changed

+141
-106
lines changed

a2l/axis_pts_4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AxisPts4 struct {
1616
DatatypeSet bool
1717
IndexIncr indexOrderEnum
1818
IndexIncrSet bool
19-
Addressing addrTypeEnum
19+
Addressing AddrTypeEnum
2020
AddressingSet bool
2121
Values interface{}
2222
ValuesSet bool

a2l/axis_pts_5.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AxisPts5 struct {
1616
DatatypeSet bool
1717
IndexIncr indexOrderEnum
1818
IndexIncrSet bool
19-
Addressing addrTypeEnum
19+
Addressing AddrTypeEnum
2020
AddressingSet bool
2121
Values interface{}
2222
ValuesSet bool

a2l/axis_pts_x.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AxisPtsX struct {
1616
DatatypeSet bool
1717
IndexIncr indexOrderEnum
1818
IndexIncrSet bool
19-
Addressing addrTypeEnum
19+
Addressing AddrTypeEnum
2020
AddressingSet bool
2121
Values interface{}
2222
ValuesSet bool

a2l/axis_pts_y.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AxisPtsY struct {
1616
DatatypeSet bool
1717
IndexIncr indexOrderEnum
1818
IndexIncrSet bool
19-
Addressing addrTypeEnum
19+
Addressing AddrTypeEnum
2020
AddressingSet bool
2121
Values interface{}
2222
ValuesSet bool

a2l/axis_pts_z.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AxisPtsZ struct {
1616
DatatypeSet bool
1717
IndexIncr indexOrderEnum
1818
IndexIncrSet bool
19-
Addressing addrTypeEnum
19+
Addressing AddrTypeEnum
2020
AddressingSet bool
2121
Values interface{}
2222
ValuesSet bool

a2l/axis_rescale_x.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type AxisRescaleX struct {
6363
MaxNumberOfRescalePairsSet bool
6464
IndexIncr indexOrderEnum
6565
IndexIncrSet bool
66-
Adressing addrTypeEnum
66+
Adressing AddrTypeEnum
6767
AdressingSet bool
6868
}
6969

a2l/blob.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/rs/zerolog/log"
88
)
99

10-
//Specification of a binary blob object which has no further semantic interpretation in the MCD system.
11-
//It is just an array of bytes without a conversion method or special record layout.
10+
// Specification of a binary blob object which has no further semantic interpretation in the MCD system.
11+
// It is just an array of bytes without a conversion method or special record layout.
1212
type blob struct {
1313
name string
1414
nameSet bool
@@ -18,7 +18,7 @@ type blob struct {
1818
addressSet bool
1919
size uint32
2020
sizeSet bool
21-
addressType addrTypeEnum
21+
addressType AddrTypeEnum
2222
addressTypeSet bool
2323
annotation []annotation
2424
calibrationAccess calibrationAccessEnum

a2l/ecu_address_extension.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import (
77
"github.com/rs/zerolog/log"
88
)
99

10+
/*
11+
This keyword is used to specify additional address information. For instance it can be
12+
used, to distinguish different address spaces of an ECU (multi-micro controller devices).
13+
ECU_ADDRESS_EXTENSION is an optional keyword of MEASUREMENT, AXIS_PTS
14+
and CHARACTERISTIC.
15+
Some calibration interfaces, such as CCP and XCP need an address extension to
16+
access ECU data. To avoid the need for additional IF_DATA section at calibration
17+
and measurement objects, the keyword ECU_ADDRESS_EXTENSION has been
18+
introduced
19+
*/
1020
type ecuAddressExtension struct {
1121
extension int16
1222
extensionSet bool

a2l/ecu_calibration_offset.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import (
66
"github.com/rs/zerolog/log"
77
)
88

9+
/*
10+
ECU_CALIBRATION_OFFSET is used to describe a fixed address offset when accessing
11+
characteristics in the control unit due to
12+
-near pointers in calibration objects. Some record layouts include near pointers
13+
inside a calibration objects from which the calibration system has to compute the
14+
absolute values by adding the ECU_CALIBRATION_OFFSET (CDAMOS)
15+
-variant coding. Some ECU projects include multiple data sets for different engine or
16+
vehicle projects served by one common ECU. By using the
17+
ECU_CALIBRATION_OFFSET, a selection for project base address can be made
18+
*/
919
type ecuCalibrationOffset struct {
1020
offset string
1121
offsetSet bool

a2l/enums.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,23 +236,23 @@ func parseDataSizeEnum(tok *tokenGenerator) (DataSizeEnum, error) {
236236
return d, err
237237
}
238238

239-
// addrTypeEnum defines which address width is necessary.
240-
type addrTypeEnum string
239+
// AddrTypeEnum defines which address width is necessary.
240+
type AddrTypeEnum string
241241

242242
const (
243-
undefinedAddrtype addrTypeEnum = emptyToken
244-
PBYTE addrTypeEnum = pbyteToken
245-
PWORD addrTypeEnum = pwordToken
246-
PLONG addrTypeEnum = plongToken
247-
PLONGLONG addrTypeEnum = plonLongToken
243+
undefinedAddrtype AddrTypeEnum = emptyToken
244+
PBYTE AddrTypeEnum = pbyteToken
245+
PWORD AddrTypeEnum = pwordToken
246+
PLONG AddrTypeEnum = plongToken
247+
PLONGLONG AddrTypeEnum = plonLongToken
248248
/*DIRECT: If an adjustable or measurable object is defined with indirect addressing
249249
(ADDRESS_TYPE is not DIRECT) and if the used interface does not support indirect
250250
addressing, it is the responsibility of the MC-System to dereference the object’s
251251
address before accessing the data or configuring measurement lists.*/
252-
DIRECT addrTypeEnum = directToken
252+
DIRECT AddrTypeEnum = directToken
253253
)
254254

255-
func parseAddrTypeEnum(tok *tokenGenerator) (addrTypeEnum, error) {
255+
func parseAddrTypeEnum(tok *tokenGenerator) (AddrTypeEnum, error) {
256256
a := undefinedAddrtype
257257
var err error
258258
switch tok.current() {
@@ -304,6 +304,25 @@ func parseByteOrderEnum(tok *tokenGenerator) (ByteOrderEnum, error) {
304304
return b, err
305305
}
306306

307+
func (boe *ByteOrderEnum) String() string {
308+
switch *boe {
309+
case LittleEndian:
310+
return littleEndianToken
311+
case BigEndian:
312+
return bigEndianToken
313+
case MsbLast:
314+
return msbLastToken
315+
case MsbFirst:
316+
return msbFirstToken
317+
case MsbFirstMswLast:
318+
return msbFirstMswLastToken
319+
case MsbLastMswFirst:
320+
return msbLastMswFirstToken
321+
default:
322+
return emptyToken
323+
}
324+
}
325+
307326
type indexOrderEnum string
308327

309328
const (

a2l/fnc_values.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ type FncValues struct {
2929
to this table value or axis point value.
3030
PLONG: The relevant memory location has a 4 byte pointer
3131
to this table value or axis point value.
32+
PLONGLONG: The relevant memory location has a 8 byte pointer
33+
to this table value or axis point value.
3234
DIRECT: The relevant memory location has the first table value
3335
or axis point value, all others follow with incrementing address. */
34-
Addresstype addrTypeEnum
36+
Addresstype AddrTypeEnum
3537
AddresstypeSet bool
3638
}
3739

a2l/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type instance struct {
1515
typeDefNameSet bool
1616
address string
1717
addressSet bool
18-
addressType addrTypeEnum
18+
addressType AddrTypeEnum
1919
annotation []annotation
2020
calibrationAccess calibrationAccessEnum
2121
displayIdentifier DisplayIdentifier

a2l/structure_component.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type structureComponent struct {
1313
typeDefNameSet bool
1414
addressOffset string //uint32
1515
addressOffsetSet bool
16-
addressType addrTypeEnum
16+
addressType AddrTypeEnum
1717
layout layout
1818
matrixDim MatrixDim
1919
symbolTypeLink symbolTypeLink

a2l/type_def_blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type typeDefBlob struct {
1414
longIdentifierSet bool
1515
size uint32
1616
sizeSet bool
17-
addressType addrTypeEnum
17+
addressType AddrTypeEnum
1818
}
1919

2020
func parseTypeDefBlob(tok *tokenGenerator) (typeDefBlob, error) {

a2l/type_def_structure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type typeDefStructure struct {
1414
longIdentifierSet bool
1515
size uint32
1616
sizeSet bool
17-
addressType addrTypeEnum
17+
addressType AddrTypeEnum
1818
consistentExchange consistentExchangeKeyword
1919
structureComponent []structureComponent
2020
symbolTypeLink symbolTypeLink

calib_data.go

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"time"
1919

2020
"github.com/asap2Go/calibrationReader/a2l"
21-
"github.com/x448/float16"
2221

2322
"github.com/asap2Go/calibrationReader/ihex32"
2423

@@ -41,11 +40,6 @@ type CalibrationData struct {
4140
Hex map[uint32]byte
4241
}
4342

44-
// Numeric is used to define all number types used within the generic functions in this module
45-
type Numeric interface {
46-
uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | float16.Float16 | float32 | float64
47-
}
48-
4943
// ReadCalibration takes filepaths to the a2l file and the hex file,
5044
// parses them in parallel and returns a CalibrationData struct
5145
func ReadCalibration(a2lFilePath string, hexFilePath string) (CalibrationData, error) {
@@ -483,7 +477,7 @@ func (cd *CalibrationData) getNextAlignedAddress(address uint32, dte a2l.DataTyp
483477
}
484478
}
485479

486-
// getBytes gets a number of bites (length) from a given address and returns a byte slice
480+
// getBytes gets a number of bytes (length) from a given address and returns a byte slice
487481
// if the address cannot be found an error is returned
488482
func (cd *CalibrationData) getBytes(address uint32, length uint32) ([]byte, error) {
489483
nBytes := length / 8
@@ -505,19 +499,8 @@ func (cd *CalibrationData) getBytes(address uint32, length uint32) ([]byte, erro
505499
return bytes, nil
506500
}
507501

508-
// GetAllValuesFromHex Reads all values for each characteristic and its corresponding record layout from the hex file and converts it to decimal, and physical values.
509-
func (cd *CalibrationData) GetAllValuesFromHex() error {
510-
//for each characteristic get its record layout:
511-
for _, c := range cd.A2l.Project.Modules[cd.ModuleIndex].Characteristics {
512-
var cv CharacteristicValues
513-
cv.characteristic = &c
514-
cd.getValuesFromHex(&cv)
515-
}
516-
return nil
517-
}
518-
519502
// getValuesFromHex Reads all values for ONE specific characteristic and its corresponding record layout from the hex file and converts it to decimal, and physical values.
520-
func (cd *CalibrationData) getValuesFromHex(cv *CharacteristicValues) {
503+
func getValuesFromHex(cv *CharacteristicValues, cd *CalibrationData) {
521504
rl, err := cd.getRecordLayout(cv.characteristic)
522505
if err != nil {
523506
log.Err(err).Msg("record layout for identifier '" + cv.characteristic.Deposit + "' not found")
@@ -596,8 +579,10 @@ func (cd *CalibrationData) getValuesFromHex(cv *CharacteristicValues) {
596579
log.Err(err).Msg("could not get value for distOp5 of characteristic '" + cv.characteristic.Name + "'")
597580
}
598581
case "FncValues":
599-
//interesting part
600-
582+
cv.fncValues, err = cd.getFncValues(rl, &curPos)
583+
if err != nil {
584+
log.Err(err).Msg("could not get value for fncValues of characteristic '" + cv.characteristic.Name + "'")
585+
}
601586
case "Identification":
602587
cv.identificationValue, err = cd.getIdentification(rl, &curPos)
603588
if err != nil {
@@ -666,26 +651,27 @@ func (cd *CalibrationData) getValuesFromHex(cv *CharacteristicValues) {
666651
/*RIP_ADDR_X-Y-Z-4-5-W
667652
are only used to store interpolation results,
668653
so they are not read from hex as there is nothing to read
669-
*/
670654
case "RipAddrW":
671655
case "RipAddrX":
672656
case "RipAddrY":
673657
case "RipAddrZ":
674658
case "RipAddr4":
675659
case "RipAddr5":
660+
676661
/*SRC_ADDR_X-Y-Z-4-5
677662
define a input quantity meaning a measurement that determines which point of an axis is chosen for reading a value from a given characteristic.
678663
e.g. given a curve where the x-Axis is the rpm of the engine and the values are
679664
a defined relative engine load:
680665
x 1000 2000 3000 4000 5000 6000
681666
v 12 27 38 42 49 18
682667
then if the input quantity for this curve would be the measurement of the current rpm of the engine
683-
depending on the rpm a value is chosen.*/
668+
depending on the rpm a value is chosen.
684669
case "SrcAddrX":
685670
case "SrcAddrY":
686671
case "SrcAddrZ":
687672
case "SrcAddr4":
688673
case "SrcAddr5":
674+
*/
689675
case "ShiftOpX":
690676
cv.shiftOpXValue, err = cd.getShiftOpX(rl, &curPos)
691677
if err != nil {
@@ -729,10 +715,55 @@ func (cd *CalibrationData) getValue(curPos *uint32, dte a2l.DataTypeEnum, rl *a2
729715
return bytes, nil
730716
}
731717

732-
func convertNumericToInt[num Numeric](n num) int64 {
733-
return int64(n)
734-
}
735-
736-
func convertNumericToFloat[num Numeric](n num) float64 {
737-
return float64(n)
718+
func (cd *CalibrationData) getFncValues(rl *a2l.RecordLayout, curPos *uint32, cv *CharacteristicValues) (interface{}, error) {
719+
//check access type. DIRECT is the most used. Just read value from a given address.
720+
//in case other access types are set this gets more complicated as either offsets or pointers are leveraged to
721+
//define the position of the calibration objects.
722+
//for VALUE Type: just read one value at curPos
723+
//for higher level objects: read the number of elements defined by the matrix dim or NoAxisPts fields with the direction (row, column, alternate, ...) specified.
724+
//for applicable objects check whether STATIC_RECORD_LAYOUT and STATIC_ ADDRESS_OFFSET are set
725+
//to determine how to read the FNC_Values correctly, this can lead to hard to detect errors when not implemented.
726+
//for now just read the values as they are defined in the A2L file.
727+
if !rl.FncValues.AddresstypeSet {
728+
rl.FncValues.Addresstype = a2l.DIRECT
729+
}
730+
switch rl.FncValues.Addresstype {
731+
case a2l.DIRECT:
732+
valBytes, err := cd.getValue(curPos, a2l.UBYTE, rl)
733+
if err != nil {
734+
log.Err(err).Msg("could not get byte of new adress for fncValues of characteristic '" + cv.characteristic.Name + "'")
735+
return nil, err
736+
}
737+
val, err := cd.convertByteSliceToDatatype(valBytes, a2l.UBYTE)
738+
if err != nil {
739+
log.Err(err).Msg("could not get adress from new adress bytes for fncValues of characteristic '" + cv.characteristic.Name + "'")
740+
return nil, err
741+
}
742+
log.Info().Msg(strconv.FormatFloat(val, 'f', 0, 64))
743+
case a2l.PBYTE:
744+
newAdressBytes, err := cd.getValue(curPos, a2l.UBYTE, rl)
745+
if err != nil {
746+
log.Err(err).Msg("could not get byte of new adress for fncValues of characteristic '" + cv.characteristic.Name + "'")
747+
return nil, err
748+
}
749+
newAdress, err := cd.convertByteSliceToDatatype(newAdressBytes, a2l.UBYTE)
750+
if err != nil {
751+
log.Err(err).Msg("could not get adress from new adress bytes for fncValues of characteristic '" + cv.characteristic.Name + "'")
752+
return nil, err
753+
}
754+
log.Info().Msg(strconv.FormatFloat(newAdress, 'f', 0, 64))
755+
//the address contains an one byte pointer to the first axis point or value
756+
case a2l.PWORD:
757+
//the address contains an two byte pointer to the first axis point or value
758+
case a2l.PLONG:
759+
//the address contains an four byte pointer to the first axis point or value
760+
case a2l.PLONGLONG:
761+
//the address contains an eight byte pointer to the first axis point or value
762+
default:
763+
//no valid address type
764+
err := errors.New("invalid address type for fncValues")
765+
log.Err(err).Msg("invalid address type for fncValues of characteristic '" + cv.characteristic.Name + "'")
766+
return nil, err
767+
}
768+
return nil, nil
738769
}

0 commit comments

Comments
 (0)