wip: fix skylabify unknown id crash?
This commit is contained in:
parent
0e8904ebec
commit
2dd6031bdd
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/kschamplin/gotelem/skylab"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slog"
|
||||
)
|
||||
|
||||
// this command can be used to decode candump logs and dump json output.
|
||||
|
@ -112,7 +113,11 @@ func run(ctx *cli.Context) (err error) {
|
|||
|
||||
// parse the data []byte to a skylab packet
|
||||
cd.Data, err = skylab.FromCanFrame(uint32(cd.Id), rawData)
|
||||
if err != nil {
|
||||
var idErr *skylab.UnknownIdError
|
||||
if errors.As(err, &idErr) {
|
||||
// unknown id
|
||||
slog.Info("unknown id", "err", err)
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package skylab
|
|||
import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
// this is needed so that we can run make_skylab.go
|
||||
|
@ -162,3 +163,12 @@ func (e *BusEvent) UnmarshalMsg(b []byte) ([]byte, error) {
|
|||
|
||||
// we need to be able to parse the JSON as well. this is done using the
|
||||
// generator since we can use the switch/case thing since it's the fastest
|
||||
|
||||
|
||||
type UnknownIdError struct {
|
||||
id uint64
|
||||
}
|
||||
|
||||
func (e *UnknownIdError) Error() string {
|
||||
return fmt.Sprintf("unknown id: %x", e.id)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// generated by gen_skylab.go at 2023-05-30 21:59:25.165613242 -0500 CDT m=+0.002722998 DO NOT EDIT!
|
||||
// generated by gen_skylab.go at 2023-06-27 20:32:07.43630691 -0500 CDT m=+0.003975675 DO NOT EDIT!
|
||||
|
||||
package skylab
|
||||
|
||||
|
@ -236,7 +236,7 @@ var idMap = map[uint32]bool{
|
|||
// If the CAN ID is unknown, it will return an error.
|
||||
func FromCanFrame(id uint32, data []byte) (Packet, error) {
|
||||
if !idMap[id] {
|
||||
return nil, errors.New("unknown id")
|
||||
return nil, &UnknownIdError{ id }
|
||||
}
|
||||
switch id {
|
||||
case 0x10:
|
||||
|
@ -1559,7 +1559,7 @@ type BmsModule struct {
|
|||
|
||||
func (p *BmsModule) CANId() (uint32, error) {
|
||||
if p.Idx >= 36 {
|
||||
return 0, errors.New("invalid packet index")
|
||||
return 0, &UnknownIdError{ 0x1C }
|
||||
}
|
||||
return 0x1C + p.Idx, nil
|
||||
}
|
||||
|
@ -2546,7 +2546,7 @@ type TrackerEnable struct {
|
|||
|
||||
func (p *TrackerEnable) CANId() (uint32, error) {
|
||||
if p.Idx >= 6 {
|
||||
return 0, errors.New("invalid packet index")
|
||||
return 0, &UnknownIdError{ 0x610 }
|
||||
}
|
||||
return 0x610 + p.Idx, nil
|
||||
}
|
||||
|
@ -3636,7 +3636,7 @@ type TrackerData struct {
|
|||
|
||||
func (p *TrackerData) CANId() (uint32, error) {
|
||||
if p.Idx >= 6 {
|
||||
return 0, errors.New("invalid packet index")
|
||||
return 0, &UnknownIdError{ 0x600 }
|
||||
}
|
||||
return 0x600 + p.Idx, nil
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ type {{$structName}} struct {
|
|||
func (p *{{$structName}}) CANId() (uint32, error) {
|
||||
{{- if .Repeat }}
|
||||
if p.Idx >= {{.Repeat}} {
|
||||
return 0, errors.New("invalid packet index")
|
||||
return 0, &UnknownIdError{ {{ printf "0x%X" .Id }} }
|
||||
}
|
||||
return {{ printf "0x%X" .Id }} + p.Idx, nil
|
||||
{{- else }}
|
||||
|
@ -114,7 +114,7 @@ var idMap = map[uint32]bool{
|
|||
// If the CAN ID is unknown, it will return an error.
|
||||
func FromCanFrame(id uint32, data []byte) (Packet, error) {
|
||||
if !idMap[id] {
|
||||
return nil, errors.New("unknown id")
|
||||
return nil, &UnknownIdError{ id }
|
||||
}
|
||||
switch id {
|
||||
{{- range $p := .Packets }}
|
||||
|
|
Loading…
Reference in a new issue