Skip to content

Commit

Permalink
fix: fitgen's factory and mesgdef on evaluating scale offset (#481)
Browse files Browse the repository at this point in the history
* fix: factory and mesgdef on evaluatin scale and offset

* fitgen: generate factory and mesgdef
  • Loading branch information
muktihari authored Oct 5, 2024
1 parent 9dc160f commit 21f4b2d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions factory/factory_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions internal/cmd/fitgen/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,14 @@ func (b *Builder) makeFieldBases(message parser.Message) string {
if array := field.Array != ""; array {
strbuf.WriteString(fmt.Sprintf("Array: %t, %s", array, makeArrayComment(field.Array)))
}
strbuf.WriteString(fmt.Sprintf("Scale: %g,", scaleOrDefault(field.Scales, 0))) // first index or default
if offset := offsetOrDefault(field.Offsets, 0); offset != 0 {
strbuf.WriteString(fmt.Sprintf("Offset: %g,", offset)) // first index or default
// Scale and offset do not apply for field that has more than one components
if len(field.Components) > 1 {
strbuf.WriteString(fmt.Sprintf("Scale: %d,", 1))
} else {
strbuf.WriteString(fmt.Sprintf("Scale: %g,", scaleOrDefault(field.Scales, 0))) // first index or default
if offset := offsetOrDefault(field.Offsets, 0); offset != 0 {
strbuf.WriteString(fmt.Sprintf("Offset: %g,", offset)) // first index or default
}
}
if accumulate := accumulateOrDefault(field.Accumulate, 0); accumulate {
strbuf.WriteString(fmt.Sprintf("Accumulate: %t,", accumulate))
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/fitgen/profile/mesgdef/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ func (b *Builder) Build() ([]generator.Data, error) {
field.InvalidValue += fmt.Sprintf("&& %s != \"\"", field.ComparableValue)
}

if len(parserField.Scales) <= 1 { // Multiple scales only for components
// Scale and offset do not apply for field that has more than one components
if len(parserField.Components) > 1 {
field.Scale, field.Offset = 1, 0
} else {
field.Scale = scaleOrDefault(parserField.Scales, 0)
}

if len(parserField.Offsets) <= 1 { // Multiple offsets only for components
field.Offset = offsetOrDefault(parserField.Offsets, 0)
}

Expand Down

0 comments on commit 21f4b2d

Please sign in to comment.