fix skylab json formatting
This commit is contained in:
parent
bcd61321e6
commit
9ec01c39de
|
@ -18,37 +18,37 @@ import (
|
||||||
|
|
||||||
// SkylabFile is a yaml file from skylab.
|
// SkylabFile is a yaml file from skylab.
|
||||||
type SkylabFile struct {
|
type SkylabFile struct {
|
||||||
Packets []PacketDef `yaml:"packets"`
|
Packets []PacketDef `yaml:"packets,omitempty" json:"packets,omitempty"`
|
||||||
Boards []BoardDef `yaml:"boards"`
|
Boards []BoardDef `yaml:"boards,omitempty" json:"boards,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BoardDef struct {
|
type BoardDef struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
Transmit []string `yaml:"transmit"`
|
Transmit []string `yaml:"transmit,omitempty" json:"transmit,omitempty"`
|
||||||
Receive []string `yaml:"receive"`
|
Receive []string `yaml:"receive,omitempty" json:"receive,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// data field.
|
// data field.
|
||||||
type FieldDef struct {
|
type FieldDef struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||||
Units string `yaml:"units"`
|
Units string `yaml:"units,omitempty" json:"units,omitempty"`
|
||||||
Conversion float32 `yaml:"conversion"`
|
Conversion float32 `yaml:"conversion,omitempty" json:"conversion,omitempty"`
|
||||||
Bits []struct {
|
Bits []struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
} `yaml:"bits"`
|
} `yaml:"bits,omitempty" json:"bits,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// a PacketDef is a full can packet.
|
// a PacketDef is a full can packet.
|
||||||
type PacketDef struct {
|
type PacketDef struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
||||||
Id uint32 `yaml:"id"`
|
Id uint32 `yaml:"id,omitempty" json:"id,omitempty"`
|
||||||
Endian string `yaml:"endian"`
|
Endian string `yaml:"endian,omitempty" json:"endian,omitempty"`
|
||||||
Extended bool `yaml:"is_extended"`
|
IsExtended bool `yaml:"is_extended,omitempty" json:"is_extended,omitempty"`
|
||||||
Repeat int `yaml:"repeat"`
|
Repeat int `yaml:"repeat,omitempty" json:"repeat,omitempty"`
|
||||||
Offset int `yaml:"offset"`
|
Offset int `yaml:"offset,omitempty" json:"offset,omitempty"`
|
||||||
Data []FieldDef `yaml:"data"`
|
Data []FieldDef `yaml:"data,omitempty" json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to generate bitfield types.
|
// we need to generate bitfield types.
|
||||||
|
@ -278,13 +278,13 @@ func idToString(p PacketDef) string {
|
||||||
if p.Repeat > 0 {
|
if p.Repeat > 0 {
|
||||||
resp := make([]string, p.Repeat)
|
resp := make([]string, p.Repeat)
|
||||||
for idx := 0; idx < p.Repeat; idx++ {
|
for idx := 0; idx < p.Repeat; idx++ {
|
||||||
resp[idx] = fmt.Sprintf("can.CanID{ Id: 0x%X, Extended: %t }", int(p.Id)+idx*p.Offset, p.Extended)
|
resp[idx] = fmt.Sprintf("can.CanID{ Id: 0x%X, Extended: %t }", int(p.Id)+idx*p.Offset, p.IsExtended)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(resp, ",")
|
return strings.Join(resp, ",")
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("can.CanID{ Id: 0x%X, Extended: %t }", p.Id, p.Extended)
|
return fmt.Sprintf("can.CanID{ Id: 0x%X, Extended: %t }", p.Id, p.IsExtended)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -46,7 +46,7 @@ type {{$structName}} struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *{{$structName}}) CanId() (can.CanID, error) {
|
func (p *{{$structName}}) CanId() (can.CanID, error) {
|
||||||
c := can.CanID{Extended: {{.Extended}}}
|
c := can.CanID{Extended: {{.IsExtended}}}
|
||||||
{{- if .Repeat }}
|
{{- if .Repeat }}
|
||||||
if p.Idx >= {{.Repeat}} {
|
if p.Idx >= {{.Repeat}} {
|
||||||
return c, &UnknownIdError{ {{ printf "0x%X" .Id }} }
|
return c, &UnknownIdError{ {{ printf "0x%X" .Id }} }
|
||||||
|
@ -108,10 +108,10 @@ var idMap = map[can.CanID]bool{
|
||||||
{{ range $p := .Packets -}}
|
{{ range $p := .Packets -}}
|
||||||
{{ if $p.Repeat }}
|
{{ if $p.Repeat }}
|
||||||
{{ range $idx := Nx (int $p.Id) $p.Repeat $p.Offset -}}
|
{{ range $idx := Nx (int $p.Id) $p.Repeat $p.Offset -}}
|
||||||
{ Id: {{ $idx | printf "0x%X"}}, Extended: {{$p.Extended}} }: true,
|
{ Id: {{ $idx | printf "0x%X"}}, Extended: {{$p.IsExtended}} }: true,
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{ Id: {{ $p.Id | printf "0x%X" }}, Extended: {{$p.Extended}} }: true,
|
{ Id: {{ $p.Id | printf "0x%X" }}, Extended: {{$p.IsExtended}} }: true,
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue