Skip to content

Commit

Permalink
cli-fix: bug removing field placeholder and handling dev fields
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Sep 19, 2024
1 parent f5243b2 commit b8b33bd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/fitconv/fitcsv/csv_to_fit.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (c *CSVToFITConv) convert() error {
if err != nil {
return fmt.Errorf("could not create mesg: num: %q (%d): %w", mesgNum, mesgNum, err)
}
if len(mesg.Fields) == 0 && len(mesg.DeveloperFields) == 0 {
continue
}

if mesg.Num == mesgnum.FieldDescription {
c.fieldDescriptions = append(c.fieldDescriptions, mesgdef.NewFieldDescription(&mesg))
Expand Down Expand Up @@ -199,7 +202,7 @@ func (c *CSVToFITConv) createMesg(num typedef.MesgNum, record []string) (proto.M
}

if len(record) < 6 {
return mesg, nil
return proto.Message{}, nil
}

var dynamicFieldRefs []dynamicFieldRef
Expand Down Expand Up @@ -235,7 +238,7 @@ func (c *CSVToFITConv) createMesg(num typedef.MesgNum, record []string) (proto.M
}
v, err := strconv.ParseUint(digits, 10, 8)
if err != nil {
return mesg, fmt.Errorf("could not parse unknown fieldNum %q: %w", fieldName, err)
return proto.Message{}, fmt.Errorf("could not parse unknown fieldNum %q: %w", fieldName, err)
}
fieldNum = byte(v)
recoverableUnknownField = true
Expand All @@ -246,19 +249,20 @@ func (c *CSVToFITConv) createMesg(num typedef.MesgNum, record []string) (proto.M
if ok {
field, err := c.createField(num, fieldNum, strValue, units, recoverableUnknownField)
if err != nil {
return mesg, fmt.Errorf("could not create field: num: %q (%d): %w", fieldName, fieldNum, err)
return proto.Message{}, fmt.Errorf("could not create field: num: %q (%d): %w", fieldName, fieldNum, err)
}
mesg.Fields = append(mesg.Fields, field)
continue
}

devField, err := c.createDeveloperField(fieldName, strValue, units)
if err != nil {
return mesg, fmt.Errorf("could not create developer field: %w", err)
return proto.Message{}, fmt.Errorf("could not create developer field: %w", err)
}
if devField.Value.Type() != proto.TypeInvalid {
mesg.DeveloperFields = append(mesg.DeveloperFields, devField)
return mesg, nil
continue
// return proto.Message{}, nil
}

// If the field cannot be found in fieldNumLookup and isn't a valid developer field,
Expand All @@ -273,7 +277,7 @@ func (c *CSVToFITConv) createMesg(num typedef.MesgNum, record []string) (proto.M

for _, ref := range dynamicFieldRefs {
if err := c.revertSubFieldSubtitution(&mesg, ref); err != nil {
return mesg, err
return proto.Message{}, err
}
}

Expand Down

0 comments on commit b8b33bd

Please sign in to comment.