From 2dceb3927e9f69065a199fb8f0332f8174ec158b Mon Sep 17 00:00:00 2001 From: saji Date: Sun, 28 May 2023 19:39:03 -0500 Subject: [PATCH] skylab: rework interface --- broker.go | 93 +- cmd/gotelem/cli/client.go | 24 +- cmd/gotelem/cli/server.go | 20 +- cmd/gotelem/cli/socketcan.go | 37 +- cmd/skylabify/skylabify.go | 3 +- frame.go | 3 - go.mod | 1 + skylab/make_skylab.go | 77 +- skylab/skylab.go | 79 +- skylab/skylab_gen.go | 488 +++++----- skylab/skylab_gen_test.go | 913 +++++++----------- skylab/skylab_msgp.go | 18 + frame_gen.go => skylab/skylab_msgp_gen.go | 359 +++---- .../skylab_msgp_gen_test.go | 66 +- skylab/templates/golang.go.tmpl | 28 +- skylab/templates/golang_tests.go.tmpl | 11 +- skylab_logger.go | 58 -- 17 files changed, 921 insertions(+), 1357 deletions(-) create mode 100644 skylab/skylab_msgp.go rename frame_gen.go => skylab/skylab_msgp_gen.go (51%) rename frame_gen_test.go => skylab/skylab_msgp_gen_test.go (73%) delete mode 100644 skylab_logger.go diff --git a/broker.go b/broker.go index 1c2ba33..4c44fb1 100644 --- a/broker.go +++ b/broker.go @@ -2,104 +2,29 @@ package gotelem import ( "errors" - "fmt" "sync" + "github.com/kschamplin/gotelem/skylab" "golang.org/x/exp/slog" ) -type BrokerRequest struct { - Source string // the name of the sender - Msg Frame // the message to send -} -type BrokerClient struct { - Name string // the name of the client - Ch chan Frame // the channel to send frames to this client -} -type Broker struct { - subs map[string]chan Frame - - publishCh chan BrokerRequest - - subsCh chan BrokerClient - unsubCh chan BrokerClient -} - - -// Start runs the broker and sends messages to the subscribers (but not the sender) -func (b *Broker) Start() { - - for { - select { - case newClient := <-b.subsCh: - b.subs[newClient.Name] = newClient.Ch - case req := <-b.publishCh: - for name, ch := range b.subs { - if name == req.Source { - continue // don't send to ourselves. - } - // a kinda-inelegant non-blocking push. - // if we can't do it, we just drop it. this should ideally never happen. - select { - case ch <- req.Msg: - default: - fmt.Printf("we dropped a packet to dest %s", name) - } - } - case clientToRemove := <-b.unsubCh: - close(b.subs[clientToRemove.Name]) - delete(b.subs, clientToRemove.Name) - } - } -} - -func (b *Broker) Publish(name string, msg Frame) { - breq := BrokerRequest{ - Source: name, - Msg: msg, - } - b.publishCh <- breq -} - -func (b *Broker) Subscribe(name string) <-chan Frame { - ch := make(chan Frame, 3) - - bc := BrokerClient{ - Name: name, - Ch: ch, - } - b.subsCh <- bc - return ch -} - -func (b *Broker) Unsubscribe(name string) { - bc := BrokerClient{ - Name: name, - } - b.unsubCh <- bc -} - - - - type JBroker struct { - subs map[string] chan CANDumpEntry // contains the channel for each subsciber + subs map[string]chan skylab.BusEvent // contains the channel for each subsciber - logger *slog.Logger - lock sync.RWMutex + logger *slog.Logger + lock sync.RWMutex bufsize int // size of chan buffer in elements. } - func NewBroker(bufsize int, logger *slog.Logger) *JBroker { return &JBroker{ - subs: make(map[string]chan CANDumpEntry), - logger: logger, + subs: make(map[string]chan skylab.BusEvent), + logger: logger, bufsize: bufsize, } } -func (b *JBroker) Subscribe(name string) (ch chan CANDumpEntry, err error) { +func (b *JBroker) Subscribe(name string) (ch chan skylab.BusEvent, err error) { // get rw lock. b.lock.Lock() defer b.lock.Unlock() @@ -108,7 +33,7 @@ func (b *JBroker) Subscribe(name string) (ch chan CANDumpEntry, err error) { return nil, errors.New("name already in use") } b.logger.Info("new subscriber", "name", name) - ch = make(chan CANDumpEntry, b.bufsize) + ch = make(chan skylab.BusEvent, b.bufsize) b.subs[name] = ch return @@ -121,7 +46,7 @@ func (b *JBroker) Unsubscribe(name string) { delete(b.subs, name) } -func (b *JBroker) Publish(sender string, message CANDumpEntry) { +func (b *JBroker) Publish(sender string, message skylab.BusEvent) { b.lock.RLock() defer b.lock.RUnlock() for name, ch := range b.subs { diff --git a/cmd/gotelem/cli/client.go b/cmd/gotelem/cli/client.go index b5a0ca8..de27081 100644 --- a/cmd/gotelem/cli/client.go +++ b/cmd/gotelem/cli/client.go @@ -3,28 +3,26 @@ package cli import ( "fmt" + imgui "github.com/AllenDang/cimgui-go" "github.com/kschamplin/gotelem" "github.com/kschamplin/gotelem/mprpc" "github.com/urfave/cli/v2" - imgui "github.com/AllenDang/cimgui-go" ) - func init() { subCmds = append(subCmds, clientCmd) } - var clientCmd = &cli.Command{ - Name: "client", - Aliases: []string{"c"}, - Usage: "interact with a gotelem server", + Name: "client", + Aliases: []string{"c"}, + Usage: "interact with a gotelem server", ArgsUsage: "[server url]", Flags: []cli.Flag{ &cli.BoolFlag{ - Name: "gui", + Name: "gui", Aliases: []string{"g"}, - Usage: "start a local TUI", + Usage: "start a local TUI", }, }, Description: ` @@ -33,9 +31,8 @@ Connects to a gotelem server or relay. Can be used to Action: client, } - func loop() { - imgui.ShowDemoWindow() + imgui.ShowDemoWindow() } func client(ctx *cli.Context) error { @@ -45,13 +42,8 @@ func client(ctx *cli.Context) error { return nil } - // the client should connect to a TCP server and listen to packets. -func CANFrameHandler(f *gotelem.Frame) (*mprpc.RPCEmpty, error){ +func CANFrameHandler(f *gotelem.Frame) (*mprpc.RPCEmpty, error) { fmt.Printf("got frame, %v\n", f) return nil, nil } - -var initialRPCHandlers = map[string]mprpc.ServiceFunc{ - "can": mprpc.MakeService(CANFrameHandler), -} diff --git a/cmd/gotelem/cli/server.go b/cmd/gotelem/cli/server.go index e56a929..e1c9e17 100644 --- a/cmd/gotelem/cli/server.go +++ b/cmd/gotelem/cli/server.go @@ -37,11 +37,9 @@ var serveCmd = &cli.Command{ Action: serve, } - // FIXME: naming // this is a server handler for i.e tcp socket, http server, socketCAN, xbee, // etc. we can register them in init() functions. -type testThing func(cCtx *cli.Context, broker *gotelem.Broker, logger *slog.Logger) (err error) type service interface { fmt.Stringer @@ -58,12 +56,6 @@ var serveThings = []service{ &rpcService{}, } - -func deriveLogger (oldLogger *slog.Logger, svc service) (newLogger *slog.Logger) { - newLogger = oldLogger.With("svc", svc.String()) - return -} - func serve(cCtx *cli.Context) error { // TODO: output both to stderr and a file. logger := slog.New(slog.NewTextHandler(os.Stderr)) @@ -85,14 +77,11 @@ func serve(cCtx *cli.Context) error { }(svc, logger) } - wg.Wait() - return nil } - type rpcService struct { } @@ -162,8 +151,7 @@ func (c *CanLoggerService) String() string { func (c *CanLoggerService) Status() { } - -func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) { +func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) { rxCh, err := broker.Subscribe("canDump") if err != nil { return err @@ -171,7 +159,7 @@ func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l t := time.Now() fname := fmt.Sprintf("candump_%d-%02d-%02dT%02d.%02d.%02d.txt", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) - + l.Info("logging to file", "filename", fname) f, err := os.Create(fname) @@ -194,7 +182,6 @@ func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l } } - // XBeeService provides data over an Xbee device, either by serial or TCP // based on the url provided in the xbee flag. see the description for details. type XBeeService struct { @@ -207,7 +194,6 @@ func (x *XBeeService) String() string { func (x *XBeeService) Status() { } - func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *slog.Logger) (err error) { if cCtx.String("xbee") == "" { logger.Info("not using xbee") @@ -245,7 +231,5 @@ func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger * } } - } } - diff --git a/cmd/gotelem/cli/socketcan.go b/cmd/gotelem/cli/socketcan.go index 710178e..b138a18 100644 --- a/cmd/gotelem/cli/socketcan.go +++ b/cmd/gotelem/cli/socketcan.go @@ -17,10 +17,10 @@ import ( // It is an example of the modular architecture of the command line and server stack. var canDevFlag = &cli.StringFlag{ - Name: "can", - Aliases: []string{"c"}, - Usage: "CAN device string", - EnvVars: []string{"CAN_DEVICE"}, + Name: "can", + Aliases: []string{"c"}, + Usage: "CAN device string", + EnvVars: []string{"CAN_DEVICE"}, } // this function sets up the `serve` flags and services that use socketCAN @@ -37,10 +37,9 @@ func init() { subCmds = append(subCmds, socketCANCmd) } - type socketCANService struct { name string - sock socketcan.CanSocket + sock *socketcan.CanSocket } func (s *socketCANService) Status() { @@ -66,13 +65,13 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log go vcanTest(cCtx.String("can")) } - sock, err := socketcan.NewCanSocket(cCtx.String("can")) + s.sock, err = socketcan.NewCanSocket(cCtx.String("can")) if err != nil { logger.Error("error opening socket", "err", err) return } - defer sock.Close() - s.name = sock.Name() + defer s.sock.Close() + s.name = s.sock.Name() // connect to the broker rxCh, err := broker.Subscribe("socketCAN") @@ -81,13 +80,12 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log } defer broker.Unsubscribe("socketCAN") - // make a channel to receive socketCAN frames. rxCan := make(chan gotelem.Frame) go func() { for { - pkt, err := sock.Recv() + pkt, err := s.sock.Recv() if err != nil { logger.Warn("error receiving CAN packet", "err", err) } @@ -99,13 +97,13 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log for { select { case msg := <-rxCh: - - id, d, _ := skylab.CanSend(msg.Data) + + id, d, _ := skylab.ToCanFrame(msg.Data) frame.Id = id frame.Data = d - sock.Send(&frame) + s.sock.Send(&frame) case msg := <-rxCan: p, err := skylab.FromCanFrame(msg.Id, msg.Data) @@ -113,10 +111,10 @@ func (s *socketCANService) Start(cCtx *cli.Context, broker *gotelem.JBroker, log logger.Warn("error parsing can packet", "id", msg.Id) continue } - cde := gotelem.CANDumpEntry{ + cde := skylab.BusEvent{ Timestamp: float64(time.Now().UnixNano()) / 1e9, - Id: uint64(msg.Id), - Data: p, + Id: uint64(msg.Id), + Data: p, } broker.Publish("socketCAN", cde) case <-cCtx.Done(): @@ -161,14 +159,13 @@ func vcanTest(devname string) { Id: 0.2, } - id, data, err := skylab.CanSend(&testPkt) + id, data, err := skylab.ToCanFrame(&testPkt) testFrame := gotelem.Frame{ - Id: id, + Id: id, Data: data, Kind: gotelem.CanSFFFrame, } - for { slog.Info("sending test packet") sock.Send(&testFrame) diff --git a/cmd/skylabify/skylabify.go b/cmd/skylabify/skylabify.go index b1fee59..0dd1bd7 100644 --- a/cmd/skylabify/skylabify.go +++ b/cmd/skylabify/skylabify.go @@ -12,7 +12,6 @@ import ( "strings" "syscall" - "github.com/kschamplin/gotelem" "github.com/kschamplin/gotelem/skylab" "github.com/urfave/cli/v2" ) @@ -92,7 +91,7 @@ func run(ctx *cli.Context) (err error) { segments := strings.Split(dumpLine, " ") - var cd gotelem.CANDumpEntry + var cd skylab.BusEvent // this is cursed but easiest way to get a float from a string. fmt.Sscanf(segments[0], "(%g)", &cd.Timestamp) diff --git a/frame.go b/frame.go index 20e6255..10b9f2d 100644 --- a/frame.go +++ b/frame.go @@ -6,7 +6,6 @@ // by writing "adapters" to various devices/formats (xbee, sqlite, network socket, socketcan) package gotelem - // Frame represents a protocol-agnostic CAN frame. The Id can be standard or extended, // but if it is extended, the Kind should be EFF. type Frame struct { @@ -15,7 +14,6 @@ type Frame struct { Kind Kind } -//go:generate msgp type CANFrame interface { Id() uint32 Data() []byte @@ -58,4 +56,3 @@ type CanTransciever interface { CanSink CanSource } - diff --git a/go.mod b/go.mod index b6ced54..c2f2194 100644 --- a/go.mod +++ b/go.mod @@ -20,4 +20,5 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/stretchr/testify v1.8.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/skylab/make_skylab.go b/skylab/make_skylab.go index 483d15e..9f4ff2e 100644 --- a/skylab/make_skylab.go +++ b/skylab/make_skylab.go @@ -18,14 +18,13 @@ import ( // SkylabFile is a yaml file from skylab. type SkylabFile struct { Packets []PacketDef - Boards []BoardSpec - + Boards []BoardSpec } type BoardSpec struct { - Name string + Name string Transmit []string - Recieve []string + Recieve []string } // data field. @@ -80,8 +79,12 @@ var typeSizeMap = map[string]uint{ "bitfield": 1, } +func MapType(ctype string) string { + return typeMap[ctype] +} + func (d *DataField) ToStructMember(parentName string) string { - + if d.Type == "bitfield" { bfStructName := parentName + toCamelInitCase(d.Name, true) return toCamelInitCase(d.Name, true) + " " + bfStructName @@ -96,32 +99,31 @@ func (d *DataField) MakeMarshal(offset int) string { if d.Type == "uint8_t" || d.Type == "int8_t" { return fmt.Sprintf("b[%d] = p.%s", offset, fieldName) } else if d.Type == "bitfield" { - return fmt.Sprintf("b[%d] = p.%s.Marshal()", offset,fieldName) + return fmt.Sprintf("b[%d] = p.%s.MarshalByte()", offset, fieldName) } else if d.Type == "float" { return fmt.Sprintf("float32ToBytes(b[%d:], p.%s, false)", offset, fieldName) - } else if t ,ok := typeMap[d.Type]; ok { + } else if t, ok := typeMap[d.Type]; ok { // it's uint or int of some kind, use endian to write it. if strings.HasPrefix(t, "i") { // this means it's a signed integer. // encoding/binary does not support putting signed ints, instead // we should cast it to unsigned and then use the unsigned int functions. return fmt.Sprintf("binary.LittleEndian.PutU%s(b[%d:], u%s(p.%s))", t, offset, t, fieldName) - } + } return fmt.Sprintf("binary.LittleEndian.Put%s(b[%d:], p.%s)", toCamelInitCase(t, true), offset, fieldName) } return "panic(\"failed to do it\")\n" } - func (d *DataField) MakeUnmarshal(offset int) string { fieldName := toCamelInitCase(d.Name, true) if d.Type == "uint8_t" || d.Type == "int8_t" { return fmt.Sprintf("p.%s = b[%d]", fieldName, offset) } else if d.Type == "bitfield" { - return fmt.Sprintf("p.%s.Unmarshal(b[%d])", fieldName, offset) + return fmt.Sprintf("p.%s.UnmarshalByte(b[%d])", fieldName, offset) } else if d.Type == "float" { return fmt.Sprintf("p.%s = float32FromBytes(b[%d:], false)", fieldName, offset) @@ -134,14 +136,12 @@ func (d *DataField) MakeUnmarshal(offset int) string { // encoding/binary does not support putting signed ints, instead // we should cast it to unsigned and then use the unsigned int functions. return fmt.Sprintf("p.%s = %s(binary.LittleEndian.U%s(b[%d:]))", fieldName, t, t, offset) - } + } return fmt.Sprintf("p.%s = binary.LittleEndian.%s(b[%d:])", fieldName, toCamelInitCase(t, true), offset) } panic("unhandled type") } - - func (p PacketDef) CalcSize() int { // makes a function that returns the size of the code. @@ -153,7 +153,6 @@ func (p PacketDef) CalcSize() int { return size } - func (p PacketDef) MakeMarshal() string { var buf strings.Builder @@ -170,14 +169,12 @@ func (p PacketDef) MakeMarshal() string { offset += int(typeSizeMap[val.Type]) } - return buf.String() } func (p PacketDef) MakeUnmarshal() string { var buf strings.Builder - var offset int = 0 for _, val := range p.Data { @@ -190,7 +187,6 @@ func (p PacketDef) MakeUnmarshal() string { return buf.String() } - // stolen camelCaser code. initCase = true means CamelCase, false means camelCase func toCamelInitCase(s string, initCase bool) string { s = strings.TrimSpace(s) @@ -228,29 +224,28 @@ func toCamelInitCase(s string, initCase bool) string { return n.String() } -// N takes a start and stop value and returns a stream of +// N takes a start and stop value and returns a stream of // [start, end), including the starting value but excluding the end value. func N(start, end int) (stream chan int) { - stream = make(chan int) - go func() { - for i := start; i < end; i++ { - stream <- i - } - close(stream) - }() - return + stream = make(chan int) + go func() { + for i := start; i < end; i++ { + stream <- i + } + close(stream) + }() + return } - // Nx takes a start, a quantity, and an offset and returns a stream // of `times` values which count from start and increment by `offset` each // time. -func Nx (start, times, offset int) (elems []int) { +func Nx(start, times, offset int) (elems []int) { elems = make([]int, times) for i := 0; i < times; i++ { - elems[i] = start + offset * i + elems[i] = start + offset*i } - return + return } // dumb function for type conversion between uint32 to integer @@ -259,10 +254,10 @@ func uint32ToInt(i uint32) (o int) { return int(i) } - // strJoin is a remapping of strings.Join so that we can use // it in a pipeline. -// {{.Names | strJoin ", " }} +// +// {{.Names | strJoin ", " }} func strJoin(delim string, elems []string) string { return strings.Join(elems, delim) } @@ -277,7 +272,6 @@ func mapf(format string, els []int) []string { return resp } - func main() { // read path as the first arg, glob it for yamls, read each yaml into a skylabFile. // then take each skylab file, put all the packets into one big array. @@ -312,15 +306,16 @@ func main() { v.Boards = append(v.Boards, newFile.Boards...) } - // we add any functions mapping we need here. + // we add any functions mapping we need here. fnMap := template.FuncMap{ "camelCase": toCamelInitCase, - "Time": time.Now, - "N": N, - "Nx": Nx, - "int": uint32ToInt, - "strJoin": strJoin, - "mapf": mapf, + "Time": time.Now, + "N": N, + "Nx": Nx, + "int": uint32ToInt, + "strJoin": strJoin, + "mapf": mapf, + "maptype": MapType, } tmpl, err := template.New("golang.go.tmpl").Funcs(fnMap).ParseGlob("templates/*.go.tmpl") @@ -336,7 +331,6 @@ func main() { } err = tmpl.Execute(f, v) - if err != nil { panic(err) } @@ -354,4 +348,3 @@ func main() { tests.Execute(testF, v) } - diff --git a/skylab/skylab.go b/skylab/skylab.go index f1de48f..ae43071 100644 --- a/skylab/skylab.go +++ b/skylab/skylab.go @@ -61,7 +61,7 @@ type Sizer interface { } // CanSend takes a packet and makes CAN framing data. -func CanSend(p Packet) (id uint32, data []byte, err error) { +func ToCanFrame(p Packet) (id uint32, data []byte, err error) { id, err = p.CANId() if err != nil { @@ -71,29 +71,86 @@ func CanSend(p Packet) (id uint32, data []byte, err error) { return } -// ---- JSON encoding business ---- +// ---- other wire encoding business ---- -type JSONPacket struct { - Id uint32 - Data json.RawMessage +// internal structure for partially decoding json object. +type jsonRawEvent struct { + Timestamp float64 + Id uint32 + Name string + Data json.RawMessage } -func ToJson(p Packet) (*JSONPacket, error) { - - d, err := json.Marshal(p) +// BusEvent is a timestamped Skylab packet designed to be serialized. +type BusEvent struct { + Timestamp float64 `json:"ts"` + Id uint64 `json:"id"` + Name string `json:"name"` + Data Packet `json:"data"` +} +// FIXME: handle Name field. +func (e *BusEvent) MarshalJSON() (b []byte, err error) { + // create the underlying raw event + j := &jsonRawEvent{ + Timestamp: e.Timestamp, + Id: uint32(e.Id), + } + // now we use the magic Packet -> map[string]interface{} function + j.Data, err = json.Marshal(e.Data) if err != nil { return nil, err } - id, err := p.CANId() + return json.Marshal(j) + +} + +func (e *BusEvent) UnmarshalJSON(b []byte) error { + var jRaw *jsonRawEvent + + err := json.Unmarshal(b, jRaw) + + if err != nil { + return err + } + + e.Timestamp = jRaw.Timestamp + e.Id = uint64(jRaw.Id) + e.Data, err = FromJson(jRaw.Id, jRaw.Data) + + return err +} + +// FIXME: handle name field. +func (e *BusEvent) MarshalMsg(b []byte) ([]byte, error) { + + // we need to send the bytes as a []byte instead of + // an object like the JSON one (lose self-documenting) + data, err := e.Data.MarshalPacket() if err != nil { return nil, err } + rawEv := &msgpRawEvent{ + Timestamp: e.Timestamp, + Id: uint32(e.Id), + Data: data, + } - jp := &JSONPacket{Id: id, Data: d} + return rawEv.MarshalMsg(b) +} - return jp, nil +func (e *BusEvent) UnmarshalMsg(b []byte) ([]byte, error) { + rawEv := &msgpRawEvent{} + remain, err := rawEv.UnmarshalMsg(b) + if err != nil { + return remain, err + } + e.Timestamp = rawEv.Timestamp + e.Id = uint64(rawEv.Id) + e.Data, err = FromCanFrame(rawEv.Id, rawEv.Data) + + return remain, err } // we need to be able to parse the JSON as well. this is done using the diff --git a/skylab/skylab_gen.go b/skylab/skylab_gen.go index 9d98d01..2346992 100644 --- a/skylab/skylab_gen.go +++ b/skylab/skylab_gen.go @@ -1,4 +1,4 @@ -// generated by gen_skylab.go at 2023-05-22 12:15:36.401199868 -0500 CDT m=+0.002809501 DO NOT EDIT! +// generated by gen_skylab.go at 2023-05-28 19:37:49.492566781 -0500 CDT m=+0.002675778 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, errors.New("unknown id") } switch id { case 0x10: @@ -576,355 +576,353 @@ func FromCanFrame(id uint32, data []byte) (Packet, error) { return res, nil } - return nil, errors.New("failed to match Id, something is really wrong!") + return nil, errors.New("failed to match Id, something is really wrong") } -func FromJson (raw []byte) (Packet, error) { - // attempt to parse the JSON to a JSONPacket - jp := &JSONPacket{} - err := json.Unmarshal(raw, jp) - if err != nil { - return nil, err + +func FromJson (id uint32, raw []byte) (Packet, error) { + if !idMap[id] { + return nil, errors.New("unknown id") } - switch jp.Id { + switch id { case 0x10: var res = &BmsMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x11: var res = &BatteryStatus{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x12: var res = &BmsKillReason{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x13: var res = &BmsModuleMinMax{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x14: var res = &BmsSoc{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x15: var res = &BmsCapacity{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x18: var res = &BmsCurrentlimit{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x19: var res = &BmsFanInfo{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x1B: var res = &BmsSetMinFanSpeed{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F: var res = &BmsModule{} - err := json.Unmarshal(jp.Data, res) - res.Idx = jp.Id - 0x1C + err := json.Unmarshal(raw, res) + res.Idx = id - 0x1C return res, err case 0x75: var res = &BmsChargerResponse{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x290: var res = &DashboardPedalPercentages{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x291: var res = &CarState{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x292: var res = &DashboardPedalFault{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x299: var res = &DashboardSystemTimeoutTest{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x29A: var res = &CarSpeed{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x29B: var res = &FlightComputerLvBoardDisconnectCounts{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x29C: var res = &FlightComputerHvBoardDisconnectCounts{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x29D: var res = &FlightComputerInternalState{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x19E: var res = &PowerToDrive{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x19F: var res = &ArrayPower{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B0: var res = &VisionTurnSignalsCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B1: var res = &VisionBrakeLightsCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B2: var res = &VisionHeadlightsCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B3: var res = &VisionHornCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B4: var res = &VisionArrayLatchesCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B5: var res = &VisionRearviewCommand{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x610, 0x611, 0x612, 0x613, 0x614, 0x615: var res = &TrackerEnable{} - err := json.Unmarshal(jp.Data, res) - res.Idx = jp.Id - 0x610 + err := json.Unmarshal(raw, res) + res.Idx = id - 0x610 return res, err case 0x200: var res = &DistanceTraveled{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x573: var res = &ChargerState{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x74: var res = &ChargerBmsRequest{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x576: var res = &ChargerCurrentVoltage{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x577: var res = &ChargerPower{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x18E54024: var res = &ThunderstruckControlMessage{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B6: var res = &VisionStatusFront{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x2B7: var res = &VisionStatusRear{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x300: var res = &LightsFrontId{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x301: var res = &LightsBackId{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x302: var res = &VisionId{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x240: var res = &SteeringPressCount1{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x250: var res = &SteeringPressCount2{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x241: var res = &SteeringButtonColors1{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x251: var res = &SteeringButtonColors2{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x242: var res = &SteeringHorn{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x18EB2440: var res = &ThunderstruckStatusMessage{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x600, 0x601, 0x602, 0x603, 0x604, 0x605: var res = &TrackerData{} - err := json.Unmarshal(jp.Data, res) - res.Idx = jp.Id - 0x600 + err := json.Unmarshal(raw, res) + res.Idx = id - 0x600 return res, err case 0x121: var res = &TritiumMotorDrive{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x122: var res = &TritiumMotorPower{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x123: var res = &TritiumReset{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x16: var res = &BmsAhSet{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x17: var res = &BmsWhSet{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x1A: var res = &BmsKill{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x700: var res = &TelemetryRtcReset{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x140: var res = &WsrIdentification{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x141: var res = &WsrStatusInformation{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x142: var res = &WsrBusMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x143: var res = &WsrVelocity{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x144: var res = &WsrPhaseCurrent{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x145: var res = &WsrMotorVoltageVector{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x146: var res = &WsrMotorCurrentVector{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x147: var res = &WsrMotorBackemf{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x148: var res = &Wsr15165VoltageRail{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x149: var res = &Wsr2512VoltageRail{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x14B: var res = &WsrHeatsinkMotorTemp{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x14C: var res = &WsrDspBoardTemp{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x14D: var res = &WsrReserved{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x14E: var res = &WsrOdometerBusAmphoursMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x157: var res = &WsrSlipSpeedMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x100: var res = &WslIdentification{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x101: var res = &WslStatusInformation{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x102: var res = &WslBusMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x103: var res = &WslVelocity{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x104: var res = &WslPhaseCurrent{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x105: var res = &WslMotorVoltageVector{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x106: var res = &WslMotorCurrentVector{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x107: var res = &WslMotorBackemf{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x108: var res = &Wsl15165VoltageRail{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x109: var res = &Wsl2512VoltageRail{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x10B: var res = &WslHeatsinkMotorTemp{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x10C: var res = &WslDspBoardTemp{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x10E: var res = &WslOdometerBusAmphoursMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x10D: var res = &WslReserved{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err case 0x117: var res = &WslSlipSpeedMeasurement{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err } - return nil, errors.New("aaa") + return nil, errors.New("failed to match id") } @@ -979,7 +977,7 @@ type BatteryStatusBatteryState struct { Killed bool `json:"killed"` } -func (p *BatteryStatusBatteryState) Marshal() byte { +func (p *BatteryStatusBatteryState) MarshalByte() byte { var b byte if p.Startup { b |= 1 << 0 @@ -1005,7 +1003,7 @@ func (p *BatteryStatusBatteryState) Marshal() byte { return b } -func (p *BatteryStatusBatteryState) Unmarshal(b byte) { +func (p *BatteryStatusBatteryState) UnmarshalByte(b byte) { p.Startup = (b & (1 << 0)) != 0 p.Precharge = (b & (1 << 1)) != 0 p.Discharging = (b & (1 << 2)) != 0 @@ -1026,7 +1024,7 @@ type BatteryStatusContactorState struct { ChargerPreContactor bool `json:"charger_pre_contactor"` } -func (p *BatteryStatusContactorState) Marshal() byte { +func (p *BatteryStatusContactorState) MarshalByte() byte { var b byte if p.BatteryHighContactor { b |= 1 << 0 @@ -1055,7 +1053,7 @@ func (p *BatteryStatusContactorState) Marshal() byte { return b } -func (p *BatteryStatusContactorState) Unmarshal(b byte) { +func (p *BatteryStatusContactorState) UnmarshalByte(b byte) { p.BatteryHighContactor = (b & (1 << 0)) != 0 p.BatteryLowContactor = (b & (1 << 1)) != 0 p.BatteryVicorContactor = (b & (1 << 2)) != 0 @@ -1075,7 +1073,7 @@ type BatteryStatusLvChannelStatus struct { MainPowerActive bool `json:"main_power_active"` } -func (p *BatteryStatusLvChannelStatus) Marshal() byte { +func (p *BatteryStatusLvChannelStatus) MarshalByte() byte { var b byte if p.AuxFault { b |= 1 << 0 @@ -1098,7 +1096,7 @@ func (p *BatteryStatusLvChannelStatus) Marshal() byte { return b } -func (p *BatteryStatusLvChannelStatus) Unmarshal(b byte) { +func (p *BatteryStatusLvChannelStatus) UnmarshalByte(b byte) { p.AuxFault = (b & (1 << 0)) != 0 p.MainFault = (b & (1 << 1)) != 0 p.AuxPowerValid = (b & (1 << 2)) != 0 @@ -1118,7 +1116,7 @@ type BatteryStatusLvControlStatus struct { StartButton bool `json:"start_button"` } -func (p *BatteryStatusLvControlStatus) Marshal() byte { +func (p *BatteryStatusLvControlStatus) MarshalByte() byte { var b byte if p.AuxVicorEnable { b |= 1 << 0 @@ -1147,7 +1145,7 @@ func (p *BatteryStatusLvControlStatus) Marshal() byte { return b } -func (p *BatteryStatusLvControlStatus) Unmarshal(b byte) { +func (p *BatteryStatusLvControlStatus) UnmarshalByte(b byte) { p.AuxVicorEnable = (b & (1 << 0)) != 0 p.BatVicorEnable = (b & (1 << 1)) != 0 p.AuxRelayHeld = (b & (1 << 2)) != 0 @@ -1177,19 +1175,19 @@ func (p *BatteryStatus) Size() uint { func (p *BatteryStatus) MarshalPacket() ([]byte, error) { b := make([]byte, 4) - b[0] = p.BatteryState.Marshal() - b[1] = p.ContactorState.Marshal() - b[2] = p.LvChannelStatus.Marshal() - b[3] = p.LvControlStatus.Marshal() + b[0] = p.BatteryState.MarshalByte() + b[1] = p.ContactorState.MarshalByte() + b[2] = p.LvChannelStatus.MarshalByte() + b[3] = p.LvControlStatus.MarshalByte() return b, nil } func (p *BatteryStatus) UnmarshalPacket(b []byte) error { - p.BatteryState.Unmarshal(b[0]) - p.ContactorState.Unmarshal(b[1]) - p.LvChannelStatus.Unmarshal(b[2]) - p.LvControlStatus.Unmarshal(b[3]) + p.BatteryState.UnmarshalByte(b[0]) + p.ContactorState.UnmarshalByte(b[1]) + p.LvChannelStatus.UnmarshalByte(b[2]) + p.LvControlStatus.UnmarshalByte(b[3]) return nil } @@ -1207,7 +1205,7 @@ type BmsKillReasonReason1 struct { COMMFAIL bool `json:"COMM_FAIL"` } -func (p *BmsKillReasonReason1) Marshal() byte { +func (p *BmsKillReasonReason1) MarshalByte() byte { var b byte if p.OVERVOLT { b |= 1 << 0 @@ -1227,7 +1225,7 @@ func (p *BmsKillReasonReason1) Marshal() byte { return b } -func (p *BmsKillReasonReason1) Unmarshal(b byte) { +func (p *BmsKillReasonReason1) UnmarshalByte(b byte) { p.OVERVOLT = (b & (1 << 0)) != 0 p.UNDERVOLT = (b & (1 << 1)) != 0 p.OVERTEMP = (b & (1 << 2)) != 0 @@ -1244,7 +1242,7 @@ type BmsKillReasonReason2 struct { AUXOVERUNDER bool `json:"AUX_OVER_UNDER"` } -func (p *BmsKillReasonReason2) Marshal() byte { +func (p *BmsKillReasonReason2) MarshalByte() byte { var b byte if p.HARDWARE { b |= 1 << 0 @@ -1267,7 +1265,7 @@ func (p *BmsKillReasonReason2) Marshal() byte { return b } -func (p *BmsKillReasonReason2) Unmarshal(b byte) { +func (p *BmsKillReasonReason2) UnmarshalByte(b byte) { p.HARDWARE = (b & (1 << 0)) != 0 p.KILLPACKET = (b & (1 << 1)) != 0 p.UKNOWN = (b & (1 << 2)) != 0 @@ -1295,8 +1293,8 @@ func (p *BmsKillReason) Size() uint { func (p *BmsKillReason) MarshalPacket() ([]byte, error) { b := make([]byte, 8) - b[0] = p.Reason1.Marshal() - b[1] = p.Reason2.Marshal() + b[0] = p.Reason1.MarshalByte() + b[1] = p.Reason2.MarshalByte() binary.LittleEndian.PutUint16(b[2:], p.Module) float32ToBytes(b[4:], p.Value, false) @@ -1304,8 +1302,8 @@ func (p *BmsKillReason) MarshalPacket() ([]byte, error) { } func (p *BmsKillReason) UnmarshalPacket(b []byte) error { - p.Reason1.Unmarshal(b[0]) - p.Reason2.Unmarshal(b[1]) + p.Reason1.UnmarshalByte(b[0]) + p.Reason2.UnmarshalByte(b[1]) p.Module = binary.LittleEndian.Uint16(b[2:]) p.Value = float32FromBytes(b[4:], false) @@ -1594,7 +1592,7 @@ type BmsChargerResponseResponseFlags struct { ChargingReady bool `json:"charging_ready"` } -func (p *BmsChargerResponseResponseFlags) Marshal() byte { +func (p *BmsChargerResponseResponseFlags) MarshalByte() byte { var b byte if p.ChargingReady { b |= 1 << 0 @@ -1602,7 +1600,7 @@ func (p *BmsChargerResponseResponseFlags) Marshal() byte { return b } -func (p *BmsChargerResponseResponseFlags) Unmarshal(b byte) { +func (p *BmsChargerResponseResponseFlags) UnmarshalByte(b byte) { p.ChargingReady = (b & (1 << 0)) != 0 } @@ -1622,13 +1620,13 @@ func (p *BmsChargerResponse) Size() uint { func (p *BmsChargerResponse) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.ResponseFlags.Marshal() + b[0] = p.ResponseFlags.MarshalByte() return b, nil } func (p *BmsChargerResponse) UnmarshalPacket(b []byte) error { - p.ResponseFlags.Unmarshal(b[0]) + p.ResponseFlags.UnmarshalByte(b[0]) return nil } @@ -1751,7 +1749,7 @@ type DashboardSystemTimeoutTestFlagSet0 struct { RearMpptDisconnected bool `json:"rear_mppt_disconnected"` } -func (p *DashboardSystemTimeoutTestFlagSet0) Marshal() byte { +func (p *DashboardSystemTimeoutTestFlagSet0) MarshalByte() byte { var b byte if p.SteeringDisconnected { b |= 1 << 0 @@ -1780,7 +1778,7 @@ func (p *DashboardSystemTimeoutTestFlagSet0) Marshal() byte { return b } -func (p *DashboardSystemTimeoutTestFlagSet0) Unmarshal(b byte) { +func (p *DashboardSystemTimeoutTestFlagSet0) UnmarshalByte(b byte) { p.SteeringDisconnected = (b & (1 << 0)) != 0 p.VisionFrontDisconnected = (b & (1 << 1)) != 0 p.VisionRearDisconnected = (b & (1 << 2)) != 0 @@ -1807,13 +1805,13 @@ func (p *DashboardSystemTimeoutTest) Size() uint { func (p *DashboardSystemTimeoutTest) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.FlagSet0.Marshal() + b[0] = p.FlagSet0.MarshalByte() return b, nil } func (p *DashboardSystemTimeoutTest) UnmarshalPacket(b []byte) error { - p.FlagSet0.Unmarshal(b[0]) + p.FlagSet0.UnmarshalByte(b[0]) return nil } @@ -1955,7 +1953,7 @@ type FlightComputerInternalStateBms struct { FirstPacketReceived bool `json:"first_packet_received"` } -func (p *FlightComputerInternalStateBms) Marshal() byte { +func (p *FlightComputerInternalStateBms) MarshalByte() byte { var b byte if p.BatteryKill { b |= 1 << 0 @@ -1969,7 +1967,7 @@ func (p *FlightComputerInternalStateBms) Marshal() byte { return b } -func (p *FlightComputerInternalStateBms) Unmarshal(b byte) { +func (p *FlightComputerInternalStateBms) UnmarshalByte(b byte) { p.BatteryKill = (b & (1 << 0)) != 0 p.CellsInChargingThreshold = (b & (1 << 1)) != 0 p.FirstPacketReceived = (b & (1 << 2)) != 0 @@ -1979,7 +1977,7 @@ type FlightComputerInternalStateCharger struct { ProximityDetected bool `json:"proximity_detected"` } -func (p *FlightComputerInternalStateCharger) Marshal() byte { +func (p *FlightComputerInternalStateCharger) MarshalByte() byte { var b byte if p.ProximityDetected { b |= 1 << 0 @@ -1987,7 +1985,7 @@ func (p *FlightComputerInternalStateCharger) Marshal() byte { return b } -func (p *FlightComputerInternalStateCharger) Unmarshal(b byte) { +func (p *FlightComputerInternalStateCharger) UnmarshalByte(b byte) { p.ProximityDetected = (b & (1 << 0)) != 0 } @@ -1995,7 +1993,7 @@ type FlightComputerInternalStatePhoton3 struct { Enable bool `json:"enable"` } -func (p *FlightComputerInternalStatePhoton3) Marshal() byte { +func (p *FlightComputerInternalStatePhoton3) MarshalByte() byte { var b byte if p.Enable { b |= 1 << 0 @@ -2003,7 +2001,7 @@ func (p *FlightComputerInternalStatePhoton3) Marshal() byte { return b } -func (p *FlightComputerInternalStatePhoton3) Unmarshal(b byte) { +func (p *FlightComputerInternalStatePhoton3) UnmarshalByte(b byte) { p.Enable = (b & (1 << 0)) != 0 } @@ -2012,7 +2010,7 @@ type FlightComputerInternalStateWavesculptor struct { RegenEnable bool `json:"regen_enable"` } -func (p *FlightComputerInternalStateWavesculptor) Marshal() byte { +func (p *FlightComputerInternalStateWavesculptor) MarshalByte() byte { var b byte if p.SendingReset { b |= 1 << 0 @@ -2023,7 +2021,7 @@ func (p *FlightComputerInternalStateWavesculptor) Marshal() byte { return b } -func (p *FlightComputerInternalStateWavesculptor) Unmarshal(b byte) { +func (p *FlightComputerInternalStateWavesculptor) UnmarshalByte(b byte) { p.SendingReset = (b & (1 << 0)) != 0 p.RegenEnable = (b & (1 << 1)) != 0 } @@ -2033,7 +2031,7 @@ type FlightComputerInternalStateInternal struct { BrakePedalDisconnect bool `json:"brake_pedal_disconnect"` } -func (p *FlightComputerInternalStateInternal) Marshal() byte { +func (p *FlightComputerInternalStateInternal) MarshalByte() byte { var b byte if p.AccelPedalDisconnect { b |= 1 << 0 @@ -2044,7 +2042,7 @@ func (p *FlightComputerInternalStateInternal) Marshal() byte { return b } -func (p *FlightComputerInternalStateInternal) Unmarshal(b byte) { +func (p *FlightComputerInternalStateInternal) UnmarshalByte(b byte) { p.AccelPedalDisconnect = (b & (1 << 0)) != 0 p.BrakePedalDisconnect = (b & (1 << 1)) != 0 } @@ -2069,21 +2067,21 @@ func (p *FlightComputerInternalState) Size() uint { func (p *FlightComputerInternalState) MarshalPacket() ([]byte, error) { b := make([]byte, 5) - b[0] = p.Bms.Marshal() - b[1] = p.Charger.Marshal() - b[2] = p.Photon3.Marshal() - b[3] = p.Wavesculptor.Marshal() - b[4] = p.Internal.Marshal() + b[0] = p.Bms.MarshalByte() + b[1] = p.Charger.MarshalByte() + b[2] = p.Photon3.MarshalByte() + b[3] = p.Wavesculptor.MarshalByte() + b[4] = p.Internal.MarshalByte() return b, nil } func (p *FlightComputerInternalState) UnmarshalPacket(b []byte) error { - p.Bms.Unmarshal(b[0]) - p.Charger.Unmarshal(b[1]) - p.Photon3.Unmarshal(b[2]) - p.Wavesculptor.Unmarshal(b[3]) - p.Internal.Unmarshal(b[4]) + p.Bms.UnmarshalByte(b[0]) + p.Charger.UnmarshalByte(b[1]) + p.Photon3.UnmarshalByte(b[2]) + p.Wavesculptor.UnmarshalByte(b[3]) + p.Internal.UnmarshalByte(b[4]) return nil } @@ -2180,7 +2178,7 @@ type VisionTurnSignalsCommandLights struct { Spare3 bool `json:"spare_3"` } -func (p *VisionTurnSignalsCommandLights) Marshal() byte { +func (p *VisionTurnSignalsCommandLights) MarshalByte() byte { var b byte if p.LeftTurnSignal { b |= 1 << 0 @@ -2200,7 +2198,7 @@ func (p *VisionTurnSignalsCommandLights) Marshal() byte { return b } -func (p *VisionTurnSignalsCommandLights) Unmarshal(b byte) { +func (p *VisionTurnSignalsCommandLights) UnmarshalByte(b byte) { p.LeftTurnSignal = (b & (1 << 0)) != 0 p.RightTurnSignal = (b & (1 << 1)) != 0 p.Spare1 = (b & (1 << 2)) != 0 @@ -2224,13 +2222,13 @@ func (p *VisionTurnSignalsCommand) Size() uint { func (p *VisionTurnSignalsCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.Lights.Marshal() + b[0] = p.Lights.MarshalByte() return b, nil } func (p *VisionTurnSignalsCommand) UnmarshalPacket(b []byte) error { - p.Lights.Unmarshal(b[0]) + p.Lights.UnmarshalByte(b[0]) return nil } @@ -2247,7 +2245,7 @@ type VisionBrakeLightsCommandLights struct { Spare3 bool `json:"spare_3"` } -func (p *VisionBrakeLightsCommandLights) Marshal() byte { +func (p *VisionBrakeLightsCommandLights) MarshalByte() byte { var b byte if p.BrakeLights { b |= 1 << 0 @@ -2264,7 +2262,7 @@ func (p *VisionBrakeLightsCommandLights) Marshal() byte { return b } -func (p *VisionBrakeLightsCommandLights) Unmarshal(b byte) { +func (p *VisionBrakeLightsCommandLights) UnmarshalByte(b byte) { p.BrakeLights = (b & (1 << 0)) != 0 p.Spare1 = (b & (1 << 1)) != 0 p.Spare2 = (b & (1 << 2)) != 0 @@ -2287,13 +2285,13 @@ func (p *VisionBrakeLightsCommand) Size() uint { func (p *VisionBrakeLightsCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.Lights.Marshal() + b[0] = p.Lights.MarshalByte() return b, nil } func (p *VisionBrakeLightsCommand) UnmarshalPacket(b []byte) error { - p.Lights.Unmarshal(b[0]) + p.Lights.UnmarshalByte(b[0]) return nil } @@ -2311,7 +2309,7 @@ type VisionHeadlightsCommandLights struct { Spare3 bool `json:"spare_3"` } -func (p *VisionHeadlightsCommandLights) Marshal() byte { +func (p *VisionHeadlightsCommandLights) MarshalByte() byte { var b byte if p.Headlights { b |= 1 << 0 @@ -2331,7 +2329,7 @@ func (p *VisionHeadlightsCommandLights) Marshal() byte { return b } -func (p *VisionHeadlightsCommandLights) Unmarshal(b byte) { +func (p *VisionHeadlightsCommandLights) UnmarshalByte(b byte) { p.Headlights = (b & (1 << 0)) != 0 p.HighBeams = (b & (1 << 1)) != 0 p.Spare1 = (b & (1 << 2)) != 0 @@ -2356,14 +2354,14 @@ func (p *VisionHeadlightsCommand) Size() uint { func (p *VisionHeadlightsCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 5) - b[0] = p.Lights.Marshal() + b[0] = p.Lights.MarshalByte() float32ToBytes(b[1:], p.Brightness, false) return b, nil } func (p *VisionHeadlightsCommand) UnmarshalPacket(b []byte) error { - p.Lights.Unmarshal(b[0]) + p.Lights.UnmarshalByte(b[0]) p.Brightness = float32FromBytes(b[1:], false) return nil @@ -2379,7 +2377,7 @@ type VisionHornCommandHorn struct { Spare bool `json:"spare"` } -func (p *VisionHornCommandHorn) Marshal() byte { +func (p *VisionHornCommandHorn) MarshalByte() byte { var b byte if p.Horn { b |= 1 << 0 @@ -2390,7 +2388,7 @@ func (p *VisionHornCommandHorn) Marshal() byte { return b } -func (p *VisionHornCommandHorn) Unmarshal(b byte) { +func (p *VisionHornCommandHorn) UnmarshalByte(b byte) { p.Horn = (b & (1 << 0)) != 0 p.Spare = (b & (1 << 1)) != 0 } @@ -2411,13 +2409,13 @@ func (p *VisionHornCommand) Size() uint { func (p *VisionHornCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.Horn.Marshal() + b[0] = p.Horn.MarshalByte() return b, nil } func (p *VisionHornCommand) UnmarshalPacket(b []byte) error { - p.Horn.Unmarshal(b[0]) + p.Horn.UnmarshalByte(b[0]) return nil } @@ -2432,7 +2430,7 @@ type VisionArrayLatchesCommandArrayLatches struct { ArrayRear bool `json:"array_rear"` } -func (p *VisionArrayLatchesCommandArrayLatches) Marshal() byte { +func (p *VisionArrayLatchesCommandArrayLatches) MarshalByte() byte { var b byte if p.ArrayFront { b |= 1 << 0 @@ -2443,7 +2441,7 @@ func (p *VisionArrayLatchesCommandArrayLatches) Marshal() byte { return b } -func (p *VisionArrayLatchesCommandArrayLatches) Unmarshal(b byte) { +func (p *VisionArrayLatchesCommandArrayLatches) UnmarshalByte(b byte) { p.ArrayFront = (b & (1 << 0)) != 0 p.ArrayRear = (b & (1 << 1)) != 0 } @@ -2464,13 +2462,13 @@ func (p *VisionArrayLatchesCommand) Size() uint { func (p *VisionArrayLatchesCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.ArrayLatches.Marshal() + b[0] = p.ArrayLatches.MarshalByte() return b, nil } func (p *VisionArrayLatchesCommand) UnmarshalPacket(b []byte) error { - p.ArrayLatches.Unmarshal(b[0]) + p.ArrayLatches.UnmarshalByte(b[0]) return nil } @@ -2486,7 +2484,7 @@ type VisionRearviewCommandCameras struct { Rear bool `json:"rear"` } -func (p *VisionRearviewCommandCameras) Marshal() byte { +func (p *VisionRearviewCommandCameras) MarshalByte() byte { var b byte if p.Left { b |= 1 << 0 @@ -2500,7 +2498,7 @@ func (p *VisionRearviewCommandCameras) Marshal() byte { return b } -func (p *VisionRearviewCommandCameras) Unmarshal(b byte) { +func (p *VisionRearviewCommandCameras) UnmarshalByte(b byte) { p.Left = (b & (1 << 0)) != 0 p.Right = (b & (1 << 1)) != 0 p.Rear = (b & (1 << 2)) != 0 @@ -2522,13 +2520,13 @@ func (p *VisionRearviewCommand) Size() uint { func (p *VisionRearviewCommand) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.Cameras.Marshal() + b[0] = p.Cameras.MarshalByte() return b, nil } func (p *VisionRearviewCommand) UnmarshalPacket(b []byte) error { - p.Cameras.Unmarshal(b[0]) + p.Cameras.UnmarshalByte(b[0]) return nil } @@ -2612,7 +2610,7 @@ type ChargerStateStateFlags struct { ChargerPlugged bool `json:"charger_plugged"` } -func (p *ChargerStateStateFlags) Marshal() byte { +func (p *ChargerStateStateFlags) MarshalByte() byte { var b byte if p.ChargerPlugged { b |= 1 << 0 @@ -2620,7 +2618,7 @@ func (p *ChargerStateStateFlags) Marshal() byte { return b } -func (p *ChargerStateStateFlags) Unmarshal(b byte) { +func (p *ChargerStateStateFlags) UnmarshalByte(b byte) { p.ChargerPlugged = (b & (1 << 0)) != 0 } @@ -2635,7 +2633,7 @@ type ChargerStateFault struct { BATTERYCANTIMEOUT bool `json:"BATTERY_CAN_TIMEOUT"` } -func (p *ChargerStateFault) Marshal() byte { +func (p *ChargerStateFault) MarshalByte() byte { var b byte if p.CHARGEROVERVOLT { b |= 1 << 0 @@ -2664,7 +2662,7 @@ func (p *ChargerStateFault) Marshal() byte { return b } -func (p *ChargerStateFault) Unmarshal(b byte) { +func (p *ChargerStateFault) UnmarshalByte(b byte) { p.CHARGEROVERVOLT = (b & (1 << 0)) != 0 p.CHARGEROVERTEMP = (b & (1 << 1)) != 0 p.CHARGERCANTIMEOUT = (b & (1 << 2)) != 0 @@ -2696,18 +2694,18 @@ func (p *ChargerState) Size() uint { func (p *ChargerState) MarshalPacket() ([]byte, error) { b := make([]byte, 8) - b[0] = p.StateFlags.Marshal() + b[0] = p.StateFlags.MarshalByte() binary.LittleEndian.PutUint16(b[1:], p.ChargerMaxTemp) - b[3] = p.Fault.Marshal() + b[3] = p.Fault.MarshalByte() float32ToBytes(b[4:], p.ChargingCurrent, false) return b, nil } func (p *ChargerState) UnmarshalPacket(b []byte) error { - p.StateFlags.Unmarshal(b[0]) + p.StateFlags.UnmarshalByte(b[0]) p.ChargerMaxTemp = binary.LittleEndian.Uint16(b[1:]) - p.Fault.Unmarshal(b[3]) + p.Fault.UnmarshalByte(b[3]) p.ChargingCurrent = float32FromBytes(b[4:], false) return nil @@ -2722,7 +2720,7 @@ type ChargerBmsRequestRequestFlags struct { ChargingRequested bool `json:"charging_requested"` } -func (p *ChargerBmsRequestRequestFlags) Marshal() byte { +func (p *ChargerBmsRequestRequestFlags) MarshalByte() byte { var b byte if p.ChargingRequested { b |= 1 << 0 @@ -2730,7 +2728,7 @@ func (p *ChargerBmsRequestRequestFlags) Marshal() byte { return b } -func (p *ChargerBmsRequestRequestFlags) Unmarshal(b byte) { +func (p *ChargerBmsRequestRequestFlags) UnmarshalByte(b byte) { p.ChargingRequested = (b & (1 << 0)) != 0 } @@ -2750,13 +2748,13 @@ func (p *ChargerBmsRequest) Size() uint { func (p *ChargerBmsRequest) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.RequestFlags.Marshal() + b[0] = p.RequestFlags.MarshalByte() return b, nil } func (p *ChargerBmsRequest) UnmarshalPacket(b []byte) error { - p.RequestFlags.Unmarshal(b[0]) + p.RequestFlags.UnmarshalByte(b[0]) return nil } @@ -2896,7 +2894,7 @@ type VisionStatusFrontLights struct { Spare3 bool `json:"spare_3"` } -func (p *VisionStatusFrontLights) Marshal() byte { +func (p *VisionStatusFrontLights) MarshalByte() byte { var b byte if p.LeftTurnSignal { b |= 1 << 0 @@ -2925,7 +2923,7 @@ func (p *VisionStatusFrontLights) Marshal() byte { return b } -func (p *VisionStatusFrontLights) Unmarshal(b byte) { +func (p *VisionStatusFrontLights) UnmarshalByte(b byte) { p.LeftTurnSignal = (b & (1 << 0)) != 0 p.RightTurnSignal = (b & (1 << 1)) != 0 p.BrakeLights = (b & (1 << 2)) != 0 @@ -2941,7 +2939,7 @@ type VisionStatusFrontHorn struct { Spare bool `json:"spare"` } -func (p *VisionStatusFrontHorn) Marshal() byte { +func (p *VisionStatusFrontHorn) MarshalByte() byte { var b byte if p.Horn { b |= 1 << 0 @@ -2952,7 +2950,7 @@ func (p *VisionStatusFrontHorn) Marshal() byte { return b } -func (p *VisionStatusFrontHorn) Unmarshal(b byte) { +func (p *VisionStatusFrontHorn) UnmarshalByte(b byte) { p.Horn = (b & (1 << 0)) != 0 p.Spare = (b & (1 << 1)) != 0 } @@ -2963,7 +2961,7 @@ type VisionStatusFrontCameras struct { Rear bool `json:"rear"` } -func (p *VisionStatusFrontCameras) Marshal() byte { +func (p *VisionStatusFrontCameras) MarshalByte() byte { var b byte if p.Left { b |= 1 << 0 @@ -2977,7 +2975,7 @@ func (p *VisionStatusFrontCameras) Marshal() byte { return b } -func (p *VisionStatusFrontCameras) Unmarshal(b byte) { +func (p *VisionStatusFrontCameras) UnmarshalByte(b byte) { p.Left = (b & (1 << 0)) != 0 p.Right = (b & (1 << 1)) != 0 p.Rear = (b & (1 << 2)) != 0 @@ -2990,7 +2988,7 @@ type VisionStatusFrontArrayLatches struct { ArrayRear1 bool `json:"array_rear_1"` } -func (p *VisionStatusFrontArrayLatches) Marshal() byte { +func (p *VisionStatusFrontArrayLatches) MarshalByte() byte { var b byte if p.ArrayFront0 { b |= 1 << 0 @@ -3007,7 +3005,7 @@ func (p *VisionStatusFrontArrayLatches) Marshal() byte { return b } -func (p *VisionStatusFrontArrayLatches) Unmarshal(b byte) { +func (p *VisionStatusFrontArrayLatches) UnmarshalByte(b byte) { p.ArrayFront0 = (b & (1 << 0)) != 0 p.ArrayFront1 = (b & (1 << 1)) != 0 p.ArrayRear0 = (b & (1 << 2)) != 0 @@ -3033,19 +3031,19 @@ func (p *VisionStatusFront) Size() uint { func (p *VisionStatusFront) MarshalPacket() ([]byte, error) { b := make([]byte, 4) - b[0] = p.Lights.Marshal() - b[1] = p.Horn.Marshal() - b[2] = p.Cameras.Marshal() - b[3] = p.ArrayLatches.Marshal() + b[0] = p.Lights.MarshalByte() + b[1] = p.Horn.MarshalByte() + b[2] = p.Cameras.MarshalByte() + b[3] = p.ArrayLatches.MarshalByte() return b, nil } func (p *VisionStatusFront) UnmarshalPacket(b []byte) error { - p.Lights.Unmarshal(b[0]) - p.Horn.Unmarshal(b[1]) - p.Cameras.Unmarshal(b[2]) - p.ArrayLatches.Unmarshal(b[3]) + p.Lights.UnmarshalByte(b[0]) + p.Horn.UnmarshalByte(b[1]) + p.Cameras.UnmarshalByte(b[2]) + p.ArrayLatches.UnmarshalByte(b[3]) return nil } @@ -3066,7 +3064,7 @@ type VisionStatusRearLights struct { Spare3 bool `json:"spare_3"` } -func (p *VisionStatusRearLights) Marshal() byte { +func (p *VisionStatusRearLights) MarshalByte() byte { var b byte if p.LeftTurnSignal { b |= 1 << 0 @@ -3095,7 +3093,7 @@ func (p *VisionStatusRearLights) Marshal() byte { return b } -func (p *VisionStatusRearLights) Unmarshal(b byte) { +func (p *VisionStatusRearLights) UnmarshalByte(b byte) { p.LeftTurnSignal = (b & (1 << 0)) != 0 p.RightTurnSignal = (b & (1 << 1)) != 0 p.BrakeLights = (b & (1 << 2)) != 0 @@ -3111,7 +3109,7 @@ type VisionStatusRearHorn struct { Spare bool `json:"spare"` } -func (p *VisionStatusRearHorn) Marshal() byte { +func (p *VisionStatusRearHorn) MarshalByte() byte { var b byte if p.Horn { b |= 1 << 0 @@ -3122,7 +3120,7 @@ func (p *VisionStatusRearHorn) Marshal() byte { return b } -func (p *VisionStatusRearHorn) Unmarshal(b byte) { +func (p *VisionStatusRearHorn) UnmarshalByte(b byte) { p.Horn = (b & (1 << 0)) != 0 p.Spare = (b & (1 << 1)) != 0 } @@ -3133,7 +3131,7 @@ type VisionStatusRearCameras struct { Rear bool `json:"rear"` } -func (p *VisionStatusRearCameras) Marshal() byte { +func (p *VisionStatusRearCameras) MarshalByte() byte { var b byte if p.Left { b |= 1 << 0 @@ -3147,7 +3145,7 @@ func (p *VisionStatusRearCameras) Marshal() byte { return b } -func (p *VisionStatusRearCameras) Unmarshal(b byte) { +func (p *VisionStatusRearCameras) UnmarshalByte(b byte) { p.Left = (b & (1 << 0)) != 0 p.Right = (b & (1 << 1)) != 0 p.Rear = (b & (1 << 2)) != 0 @@ -3160,7 +3158,7 @@ type VisionStatusRearArrayLatches struct { ArrayRear1 bool `json:"array_rear_1"` } -func (p *VisionStatusRearArrayLatches) Marshal() byte { +func (p *VisionStatusRearArrayLatches) MarshalByte() byte { var b byte if p.ArrayFront0 { b |= 1 << 0 @@ -3177,7 +3175,7 @@ func (p *VisionStatusRearArrayLatches) Marshal() byte { return b } -func (p *VisionStatusRearArrayLatches) Unmarshal(b byte) { +func (p *VisionStatusRearArrayLatches) UnmarshalByte(b byte) { p.ArrayFront0 = (b & (1 << 0)) != 0 p.ArrayFront1 = (b & (1 << 1)) != 0 p.ArrayRear0 = (b & (1 << 2)) != 0 @@ -3203,19 +3201,19 @@ func (p *VisionStatusRear) Size() uint { func (p *VisionStatusRear) MarshalPacket() ([]byte, error) { b := make([]byte, 4) - b[0] = p.Lights.Marshal() - b[1] = p.Horn.Marshal() - b[2] = p.Cameras.Marshal() - b[3] = p.ArrayLatches.Marshal() + b[0] = p.Lights.MarshalByte() + b[1] = p.Horn.MarshalByte() + b[2] = p.Cameras.MarshalByte() + b[3] = p.ArrayLatches.MarshalByte() return b, nil } func (p *VisionStatusRear) UnmarshalPacket(b []byte) error { - p.Lights.Unmarshal(b[0]) - p.Horn.Unmarshal(b[1]) - p.Cameras.Unmarshal(b[2]) - p.ArrayLatches.Unmarshal(b[3]) + p.Lights.UnmarshalByte(b[0]) + p.Horn.UnmarshalByte(b[1]) + p.Cameras.UnmarshalByte(b[2]) + p.ArrayLatches.UnmarshalByte(b[3]) return nil } @@ -3844,7 +3842,7 @@ type BmsKillKillType struct { KILLHARD bool `json:"KILL_HARD"` } -func (p *BmsKillKillType) Marshal() byte { +func (p *BmsKillKillType) MarshalByte() byte { var b byte if p.KILLHARD { b |= 1 << 0 @@ -3852,7 +3850,7 @@ func (p *BmsKillKillType) Marshal() byte { return b } -func (p *BmsKillKillType) Unmarshal(b byte) { +func (p *BmsKillKillType) UnmarshalByte(b byte) { p.KILLHARD = (b & (1 << 0)) != 0 } @@ -3872,13 +3870,13 @@ func (p *BmsKill) Size() uint { func (p *BmsKill) MarshalPacket() ([]byte, error) { b := make([]byte, 1) - b[0] = p.KillType.Marshal() + b[0] = p.KillType.MarshalByte() return b, nil } func (p *BmsKill) UnmarshalPacket(b []byte) error { - p.KillType.Unmarshal(b[0]) + p.KillType.UnmarshalByte(b[0]) return nil } @@ -3981,7 +3979,7 @@ type WsrStatusInformationLimitFlags struct { Reserved bool `json:"reserved"` } -func (p *WsrStatusInformationLimitFlags) Marshal() byte { +func (p *WsrStatusInformationLimitFlags) MarshalByte() byte { var b byte if p.OutputVoltagePwm { b |= 1 << 0 @@ -4010,7 +4008,7 @@ func (p *WsrStatusInformationLimitFlags) Marshal() byte { return b } -func (p *WsrStatusInformationLimitFlags) Unmarshal(b byte) { +func (p *WsrStatusInformationLimitFlags) UnmarshalByte(b byte) { p.OutputVoltagePwm = (b & (1 << 0)) != 0 p.MotorCurrent = (b & (1 << 1)) != 0 p.Velocity = (b & (1 << 2)) != 0 @@ -4032,7 +4030,7 @@ type WsrStatusInformationErrorFlags0 struct { DesaturationFault bool `json:"desaturation_fault"` } -func (p *WsrStatusInformationErrorFlags0) Marshal() byte { +func (p *WsrStatusInformationErrorFlags0) MarshalByte() byte { var b byte if p.HardwareOverCurrent { b |= 1 << 0 @@ -4061,7 +4059,7 @@ func (p *WsrStatusInformationErrorFlags0) Marshal() byte { return b } -func (p *WsrStatusInformationErrorFlags0) Unmarshal(b byte) { +func (p *WsrStatusInformationErrorFlags0) UnmarshalByte(b byte) { p.HardwareOverCurrent = (b & (1 << 0)) != 0 p.SoftwareOverCurrent = (b & (1 << 1)) != 0 p.DcBusOverVoltage = (b & (1 << 2)) != 0 @@ -4083,7 +4081,7 @@ type WsrStatusInformationErrorFlags1 struct { Reserved15 bool `json:"reserved_15"` } -func (p *WsrStatusInformationErrorFlags1) Marshal() byte { +func (p *WsrStatusInformationErrorFlags1) MarshalByte() byte { var b byte if p.MotorOverSpeed { b |= 1 << 0 @@ -4112,7 +4110,7 @@ func (p *WsrStatusInformationErrorFlags1) Marshal() byte { return b } -func (p *WsrStatusInformationErrorFlags1) Unmarshal(b byte) { +func (p *WsrStatusInformationErrorFlags1) UnmarshalByte(b byte) { p.MotorOverSpeed = (b & (1 << 0)) != 0 p.Reserved9 = (b & (1 << 1)) != 0 p.Reserved10 = (b & (1 << 2)) != 0 @@ -4144,10 +4142,10 @@ func (p *WsrStatusInformation) Size() uint { func (p *WsrStatusInformation) MarshalPacket() ([]byte, error) { b := make([]byte, 8) - b[0] = p.LimitFlags.Marshal() + b[0] = p.LimitFlags.MarshalByte() b[1] = p.LimitFlagsReserved - b[2] = p.ErrorFlags0.Marshal() - b[3] = p.ErrorFlags1.Marshal() + b[2] = p.ErrorFlags0.MarshalByte() + b[3] = p.ErrorFlags1.MarshalByte() binary.LittleEndian.PutUint16(b[4:], p.ActiveMotor) binary.LittleEndian.PutUint16(b[6:], p.Reserved) @@ -4155,10 +4153,10 @@ func (p *WsrStatusInformation) MarshalPacket() ([]byte, error) { } func (p *WsrStatusInformation) UnmarshalPacket(b []byte) error { - p.LimitFlags.Unmarshal(b[0]) + p.LimitFlags.UnmarshalByte(b[0]) p.LimitFlagsReserved = b[1] - p.ErrorFlags0.Unmarshal(b[2]) - p.ErrorFlags1.Unmarshal(b[3]) + p.ErrorFlags0.UnmarshalByte(b[2]) + p.ErrorFlags1.UnmarshalByte(b[3]) p.ActiveMotor = binary.LittleEndian.Uint16(b[4:]) p.Reserved = binary.LittleEndian.Uint16(b[6:]) @@ -4695,7 +4693,7 @@ type WslStatusInformationLimitFlags struct { Reserved bool `json:"reserved"` } -func (p *WslStatusInformationLimitFlags) Marshal() byte { +func (p *WslStatusInformationLimitFlags) MarshalByte() byte { var b byte if p.OutputVoltagePwm { b |= 1 << 0 @@ -4724,7 +4722,7 @@ func (p *WslStatusInformationLimitFlags) Marshal() byte { return b } -func (p *WslStatusInformationLimitFlags) Unmarshal(b byte) { +func (p *WslStatusInformationLimitFlags) UnmarshalByte(b byte) { p.OutputVoltagePwm = (b & (1 << 0)) != 0 p.MotorCurrent = (b & (1 << 1)) != 0 p.Velocity = (b & (1 << 2)) != 0 @@ -4746,7 +4744,7 @@ type WslStatusInformationErrorFlags0 struct { DesaturationFault bool `json:"desaturation_fault"` } -func (p *WslStatusInformationErrorFlags0) Marshal() byte { +func (p *WslStatusInformationErrorFlags0) MarshalByte() byte { var b byte if p.HardwareOverCurrent { b |= 1 << 0 @@ -4775,7 +4773,7 @@ func (p *WslStatusInformationErrorFlags0) Marshal() byte { return b } -func (p *WslStatusInformationErrorFlags0) Unmarshal(b byte) { +func (p *WslStatusInformationErrorFlags0) UnmarshalByte(b byte) { p.HardwareOverCurrent = (b & (1 << 0)) != 0 p.SoftwareOverCurrent = (b & (1 << 1)) != 0 p.DcBusOverVoltage = (b & (1 << 2)) != 0 @@ -4797,7 +4795,7 @@ type WslStatusInformationErrorFlags1 struct { Reserved15 bool `json:"reserved_15"` } -func (p *WslStatusInformationErrorFlags1) Marshal() byte { +func (p *WslStatusInformationErrorFlags1) MarshalByte() byte { var b byte if p.MotorOverSpeed { b |= 1 << 0 @@ -4826,7 +4824,7 @@ func (p *WslStatusInformationErrorFlags1) Marshal() byte { return b } -func (p *WslStatusInformationErrorFlags1) Unmarshal(b byte) { +func (p *WslStatusInformationErrorFlags1) UnmarshalByte(b byte) { p.MotorOverSpeed = (b & (1 << 0)) != 0 p.Reserved9 = (b & (1 << 1)) != 0 p.Reserved10 = (b & (1 << 2)) != 0 @@ -4858,10 +4856,10 @@ func (p *WslStatusInformation) Size() uint { func (p *WslStatusInformation) MarshalPacket() ([]byte, error) { b := make([]byte, 8) - b[0] = p.LimitFlags.Marshal() + b[0] = p.LimitFlags.MarshalByte() b[1] = p.LimitFlagsReserved - b[2] = p.ErrorFlags0.Marshal() - b[3] = p.ErrorFlags1.Marshal() + b[2] = p.ErrorFlags0.MarshalByte() + b[3] = p.ErrorFlags1.MarshalByte() binary.LittleEndian.PutUint16(b[4:], p.ActiveMotor) binary.LittleEndian.PutUint16(b[6:], p.Reserved) @@ -4869,10 +4867,10 @@ func (p *WslStatusInformation) MarshalPacket() ([]byte, error) { } func (p *WslStatusInformation) UnmarshalPacket(b []byte) error { - p.LimitFlags.Unmarshal(b[0]) + p.LimitFlags.UnmarshalByte(b[0]) p.LimitFlagsReserved = b[1] - p.ErrorFlags0.Unmarshal(b[2]) - p.ErrorFlags1.Unmarshal(b[3]) + p.ErrorFlags0.UnmarshalByte(b[2]) + p.ErrorFlags1.UnmarshalByte(b[3]) p.ActiveMotor = binary.LittleEndian.Uint16(b[4:]) p.Reserved = binary.LittleEndian.Uint16(b[6:]) diff --git a/skylab/skylab_gen_test.go b/skylab/skylab_gen_test.go index fb36793..68d4be6 100644 --- a/skylab/skylab_gen_test.go +++ b/skylab/skylab_gen_test.go @@ -22,17 +22,14 @@ func TestMarshalUnmarshalBmsMeasurement(t *testing.T) { func TestJSONBmsMeasurement(t *testing.T) { v := &BmsMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -61,17 +58,14 @@ func TestMarshalUnmarshalBatteryStatus(t *testing.T) { func TestJSONBatteryStatus(t *testing.T) { v := &BatteryStatus{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -100,17 +94,14 @@ func TestMarshalUnmarshalBmsKillReason(t *testing.T) { func TestJSONBmsKillReason(t *testing.T) { v := &BmsKillReason{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -139,17 +130,14 @@ func TestMarshalUnmarshalBmsModuleMinMax(t *testing.T) { func TestJSONBmsModuleMinMax(t *testing.T) { v := &BmsModuleMinMax{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -178,17 +166,14 @@ func TestMarshalUnmarshalBmsSoc(t *testing.T) { func TestJSONBmsSoc(t *testing.T) { v := &BmsSoc{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -217,17 +202,14 @@ func TestMarshalUnmarshalBmsCapacity(t *testing.T) { func TestJSONBmsCapacity(t *testing.T) { v := &BmsCapacity{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -256,17 +238,14 @@ func TestMarshalUnmarshalBmsCurrentlimit(t *testing.T) { func TestJSONBmsCurrentlimit(t *testing.T) { v := &BmsCurrentlimit{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -295,17 +274,14 @@ func TestMarshalUnmarshalBmsFanInfo(t *testing.T) { func TestJSONBmsFanInfo(t *testing.T) { v := &BmsFanInfo{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -334,17 +310,14 @@ func TestMarshalUnmarshalBmsSetMinFanSpeed(t *testing.T) { func TestJSONBmsSetMinFanSpeed(t *testing.T) { v := &BmsSetMinFanSpeed{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -373,17 +346,14 @@ func TestMarshalUnmarshalBmsModule(t *testing.T) { func TestJSONBmsModule(t *testing.T) { v := &BmsModule{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -412,17 +382,14 @@ func TestMarshalUnmarshalBmsChargerResponse(t *testing.T) { func TestJSONBmsChargerResponse(t *testing.T) { v := &BmsChargerResponse{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -451,17 +418,14 @@ func TestMarshalUnmarshalDashboardPedalPercentages(t *testing.T) { func TestJSONDashboardPedalPercentages(t *testing.T) { v := &DashboardPedalPercentages{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -490,17 +454,14 @@ func TestMarshalUnmarshalCarState(t *testing.T) { func TestJSONCarState(t *testing.T) { v := &CarState{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -529,17 +490,14 @@ func TestMarshalUnmarshalDashboardPedalFault(t *testing.T) { func TestJSONDashboardPedalFault(t *testing.T) { v := &DashboardPedalFault{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -568,17 +526,14 @@ func TestMarshalUnmarshalDashboardSystemTimeoutTest(t *testing.T) { func TestJSONDashboardSystemTimeoutTest(t *testing.T) { v := &DashboardSystemTimeoutTest{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -607,17 +562,14 @@ func TestMarshalUnmarshalCarSpeed(t *testing.T) { func TestJSONCarSpeed(t *testing.T) { v := &CarSpeed{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -646,17 +598,14 @@ func TestMarshalUnmarshalFlightComputerLvBoardDisconnectCounts(t *testing.T) { func TestJSONFlightComputerLvBoardDisconnectCounts(t *testing.T) { v := &FlightComputerLvBoardDisconnectCounts{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -685,17 +634,14 @@ func TestMarshalUnmarshalFlightComputerHvBoardDisconnectCounts(t *testing.T) { func TestJSONFlightComputerHvBoardDisconnectCounts(t *testing.T) { v := &FlightComputerHvBoardDisconnectCounts{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -724,17 +670,14 @@ func TestMarshalUnmarshalFlightComputerInternalState(t *testing.T) { func TestJSONFlightComputerInternalState(t *testing.T) { v := &FlightComputerInternalState{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -763,17 +706,14 @@ func TestMarshalUnmarshalPowerToDrive(t *testing.T) { func TestJSONPowerToDrive(t *testing.T) { v := &PowerToDrive{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -802,17 +742,14 @@ func TestMarshalUnmarshalArrayPower(t *testing.T) { func TestJSONArrayPower(t *testing.T) { v := &ArrayPower{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -841,17 +778,14 @@ func TestMarshalUnmarshalVisionTurnSignalsCommand(t *testing.T) { func TestJSONVisionTurnSignalsCommand(t *testing.T) { v := &VisionTurnSignalsCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -880,17 +814,14 @@ func TestMarshalUnmarshalVisionBrakeLightsCommand(t *testing.T) { func TestJSONVisionBrakeLightsCommand(t *testing.T) { v := &VisionBrakeLightsCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -919,17 +850,14 @@ func TestMarshalUnmarshalVisionHeadlightsCommand(t *testing.T) { func TestJSONVisionHeadlightsCommand(t *testing.T) { v := &VisionHeadlightsCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -958,17 +886,14 @@ func TestMarshalUnmarshalVisionHornCommand(t *testing.T) { func TestJSONVisionHornCommand(t *testing.T) { v := &VisionHornCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -997,17 +922,14 @@ func TestMarshalUnmarshalVisionArrayLatchesCommand(t *testing.T) { func TestJSONVisionArrayLatchesCommand(t *testing.T) { v := &VisionArrayLatchesCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1036,17 +958,14 @@ func TestMarshalUnmarshalVisionRearviewCommand(t *testing.T) { func TestJSONVisionRearviewCommand(t *testing.T) { v := &VisionRearviewCommand{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1075,17 +994,14 @@ func TestMarshalUnmarshalTrackerEnable(t *testing.T) { func TestJSONTrackerEnable(t *testing.T) { v := &TrackerEnable{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1114,17 +1030,14 @@ func TestMarshalUnmarshalDistanceTraveled(t *testing.T) { func TestJSONDistanceTraveled(t *testing.T) { v := &DistanceTraveled{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1153,17 +1066,14 @@ func TestMarshalUnmarshalChargerState(t *testing.T) { func TestJSONChargerState(t *testing.T) { v := &ChargerState{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1192,17 +1102,14 @@ func TestMarshalUnmarshalChargerBmsRequest(t *testing.T) { func TestJSONChargerBmsRequest(t *testing.T) { v := &ChargerBmsRequest{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1231,17 +1138,14 @@ func TestMarshalUnmarshalChargerCurrentVoltage(t *testing.T) { func TestJSONChargerCurrentVoltage(t *testing.T) { v := &ChargerCurrentVoltage{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1270,17 +1174,14 @@ func TestMarshalUnmarshalChargerPower(t *testing.T) { func TestJSONChargerPower(t *testing.T) { v := &ChargerPower{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1309,17 +1210,14 @@ func TestMarshalUnmarshalThunderstruckControlMessage(t *testing.T) { func TestJSONThunderstruckControlMessage(t *testing.T) { v := &ThunderstruckControlMessage{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1348,17 +1246,14 @@ func TestMarshalUnmarshalVisionStatusFront(t *testing.T) { func TestJSONVisionStatusFront(t *testing.T) { v := &VisionStatusFront{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1387,17 +1282,14 @@ func TestMarshalUnmarshalVisionStatusRear(t *testing.T) { func TestJSONVisionStatusRear(t *testing.T) { v := &VisionStatusRear{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1426,17 +1318,14 @@ func TestMarshalUnmarshalLightsFrontId(t *testing.T) { func TestJSONLightsFrontId(t *testing.T) { v := &LightsFrontId{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1465,17 +1354,14 @@ func TestMarshalUnmarshalLightsBackId(t *testing.T) { func TestJSONLightsBackId(t *testing.T) { v := &LightsBackId{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1504,17 +1390,14 @@ func TestMarshalUnmarshalVisionId(t *testing.T) { func TestJSONVisionId(t *testing.T) { v := &VisionId{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1543,17 +1426,14 @@ func TestMarshalUnmarshalSteeringPressCount1(t *testing.T) { func TestJSONSteeringPressCount1(t *testing.T) { v := &SteeringPressCount1{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1582,17 +1462,14 @@ func TestMarshalUnmarshalSteeringPressCount2(t *testing.T) { func TestJSONSteeringPressCount2(t *testing.T) { v := &SteeringPressCount2{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1621,17 +1498,14 @@ func TestMarshalUnmarshalSteeringButtonColors1(t *testing.T) { func TestJSONSteeringButtonColors1(t *testing.T) { v := &SteeringButtonColors1{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1660,17 +1534,14 @@ func TestMarshalUnmarshalSteeringButtonColors2(t *testing.T) { func TestJSONSteeringButtonColors2(t *testing.T) { v := &SteeringButtonColors2{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1699,17 +1570,14 @@ func TestMarshalUnmarshalSteeringHorn(t *testing.T) { func TestJSONSteeringHorn(t *testing.T) { v := &SteeringHorn{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1738,17 +1606,14 @@ func TestMarshalUnmarshalThunderstruckStatusMessage(t *testing.T) { func TestJSONThunderstruckStatusMessage(t *testing.T) { v := &ThunderstruckStatusMessage{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1777,17 +1642,14 @@ func TestMarshalUnmarshalTrackerData(t *testing.T) { func TestJSONTrackerData(t *testing.T) { v := &TrackerData{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1816,17 +1678,14 @@ func TestMarshalUnmarshalTritiumMotorDrive(t *testing.T) { func TestJSONTritiumMotorDrive(t *testing.T) { v := &TritiumMotorDrive{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1855,17 +1714,14 @@ func TestMarshalUnmarshalTritiumMotorPower(t *testing.T) { func TestJSONTritiumMotorPower(t *testing.T) { v := &TritiumMotorPower{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1894,17 +1750,14 @@ func TestMarshalUnmarshalTritiumReset(t *testing.T) { func TestJSONTritiumReset(t *testing.T) { v := &TritiumReset{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1933,17 +1786,14 @@ func TestMarshalUnmarshalBmsAhSet(t *testing.T) { func TestJSONBmsAhSet(t *testing.T) { v := &BmsAhSet{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -1972,17 +1822,14 @@ func TestMarshalUnmarshalBmsWhSet(t *testing.T) { func TestJSONBmsWhSet(t *testing.T) { v := &BmsWhSet{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2011,17 +1858,14 @@ func TestMarshalUnmarshalBmsKill(t *testing.T) { func TestJSONBmsKill(t *testing.T) { v := &BmsKill{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2050,17 +1894,14 @@ func TestMarshalUnmarshalTelemetryRtcReset(t *testing.T) { func TestJSONTelemetryRtcReset(t *testing.T) { v := &TelemetryRtcReset{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2089,17 +1930,14 @@ func TestMarshalUnmarshalWsrIdentification(t *testing.T) { func TestJSONWsrIdentification(t *testing.T) { v := &WsrIdentification{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2128,17 +1966,14 @@ func TestMarshalUnmarshalWsrStatusInformation(t *testing.T) { func TestJSONWsrStatusInformation(t *testing.T) { v := &WsrStatusInformation{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2167,17 +2002,14 @@ func TestMarshalUnmarshalWsrBusMeasurement(t *testing.T) { func TestJSONWsrBusMeasurement(t *testing.T) { v := &WsrBusMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2206,17 +2038,14 @@ func TestMarshalUnmarshalWsrVelocity(t *testing.T) { func TestJSONWsrVelocity(t *testing.T) { v := &WsrVelocity{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2245,17 +2074,14 @@ func TestMarshalUnmarshalWsrPhaseCurrent(t *testing.T) { func TestJSONWsrPhaseCurrent(t *testing.T) { v := &WsrPhaseCurrent{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2284,17 +2110,14 @@ func TestMarshalUnmarshalWsrMotorVoltageVector(t *testing.T) { func TestJSONWsrMotorVoltageVector(t *testing.T) { v := &WsrMotorVoltageVector{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2323,17 +2146,14 @@ func TestMarshalUnmarshalWsrMotorCurrentVector(t *testing.T) { func TestJSONWsrMotorCurrentVector(t *testing.T) { v := &WsrMotorCurrentVector{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2362,17 +2182,14 @@ func TestMarshalUnmarshalWsrMotorBackemf(t *testing.T) { func TestJSONWsrMotorBackemf(t *testing.T) { v := &WsrMotorBackemf{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2401,17 +2218,14 @@ func TestMarshalUnmarshalWsr15165VoltageRail(t *testing.T) { func TestJSONWsr15165VoltageRail(t *testing.T) { v := &Wsr15165VoltageRail{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2440,17 +2254,14 @@ func TestMarshalUnmarshalWsr2512VoltageRail(t *testing.T) { func TestJSONWsr2512VoltageRail(t *testing.T) { v := &Wsr2512VoltageRail{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2479,17 +2290,14 @@ func TestMarshalUnmarshalWsrHeatsinkMotorTemp(t *testing.T) { func TestJSONWsrHeatsinkMotorTemp(t *testing.T) { v := &WsrHeatsinkMotorTemp{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2518,17 +2326,14 @@ func TestMarshalUnmarshalWsrDspBoardTemp(t *testing.T) { func TestJSONWsrDspBoardTemp(t *testing.T) { v := &WsrDspBoardTemp{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2557,17 +2362,14 @@ func TestMarshalUnmarshalWsrReserved(t *testing.T) { func TestJSONWsrReserved(t *testing.T) { v := &WsrReserved{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2596,17 +2398,14 @@ func TestMarshalUnmarshalWsrOdometerBusAmphoursMeasurement(t *testing.T) { func TestJSONWsrOdometerBusAmphoursMeasurement(t *testing.T) { v := &WsrOdometerBusAmphoursMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2635,17 +2434,14 @@ func TestMarshalUnmarshalWsrSlipSpeedMeasurement(t *testing.T) { func TestJSONWsrSlipSpeedMeasurement(t *testing.T) { v := &WsrSlipSpeedMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2674,17 +2470,14 @@ func TestMarshalUnmarshalWslIdentification(t *testing.T) { func TestJSONWslIdentification(t *testing.T) { v := &WslIdentification{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2713,17 +2506,14 @@ func TestMarshalUnmarshalWslStatusInformation(t *testing.T) { func TestJSONWslStatusInformation(t *testing.T) { v := &WslStatusInformation{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2752,17 +2542,14 @@ func TestMarshalUnmarshalWslBusMeasurement(t *testing.T) { func TestJSONWslBusMeasurement(t *testing.T) { v := &WslBusMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2791,17 +2578,14 @@ func TestMarshalUnmarshalWslVelocity(t *testing.T) { func TestJSONWslVelocity(t *testing.T) { v := &WslVelocity{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2830,17 +2614,14 @@ func TestMarshalUnmarshalWslPhaseCurrent(t *testing.T) { func TestJSONWslPhaseCurrent(t *testing.T) { v := &WslPhaseCurrent{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2869,17 +2650,14 @@ func TestMarshalUnmarshalWslMotorVoltageVector(t *testing.T) { func TestJSONWslMotorVoltageVector(t *testing.T) { v := &WslMotorVoltageVector{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2908,17 +2686,14 @@ func TestMarshalUnmarshalWslMotorCurrentVector(t *testing.T) { func TestJSONWslMotorCurrentVector(t *testing.T) { v := &WslMotorCurrentVector{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2947,17 +2722,14 @@ func TestMarshalUnmarshalWslMotorBackemf(t *testing.T) { func TestJSONWslMotorBackemf(t *testing.T) { v := &WslMotorBackemf{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -2986,17 +2758,14 @@ func TestMarshalUnmarshalWsl15165VoltageRail(t *testing.T) { func TestJSONWsl15165VoltageRail(t *testing.T) { v := &Wsl15165VoltageRail{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3025,17 +2794,14 @@ func TestMarshalUnmarshalWsl2512VoltageRail(t *testing.T) { func TestJSONWsl2512VoltageRail(t *testing.T) { v := &Wsl2512VoltageRail{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3064,17 +2830,14 @@ func TestMarshalUnmarshalWslHeatsinkMotorTemp(t *testing.T) { func TestJSONWslHeatsinkMotorTemp(t *testing.T) { v := &WslHeatsinkMotorTemp{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3103,17 +2866,14 @@ func TestMarshalUnmarshalWslDspBoardTemp(t *testing.T) { func TestJSONWslDspBoardTemp(t *testing.T) { v := &WslDspBoardTemp{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3142,17 +2902,14 @@ func TestMarshalUnmarshalWslOdometerBusAmphoursMeasurement(t *testing.T) { func TestJSONWslOdometerBusAmphoursMeasurement(t *testing.T) { v := &WslOdometerBusAmphoursMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3181,17 +2938,14 @@ func TestMarshalUnmarshalWslReserved(t *testing.T) { func TestJSONWslReserved(t *testing.T) { v := &WslReserved{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } @@ -3220,17 +2974,14 @@ func TestMarshalUnmarshalWslSlipSpeedMeasurement(t *testing.T) { func TestJSONWslSlipSpeedMeasurement(t *testing.T) { v := &WslSlipSpeedMeasurement{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } diff --git a/skylab/skylab_msgp.go b/skylab/skylab_msgp.go new file mode 100644 index 0000000..de18675 --- /dev/null +++ b/skylab/skylab_msgp.go @@ -0,0 +1,18 @@ +package skylab + +//go:generate msgp -unexported + +// internal structure for handling +type msgpRawEvent struct { + Timestamp float64 `msg:"ts"` + Id uint32 `msg:"id"` + Data []byte `msg:"data"` +} + +// internal structure to represent a raw can packet over the network. +// this is what's sent over the solar car to lead xbee connection +// for brevity while still having some robustness. +type msgpRawPacket struct { + Id uint32 `msg:"id"` + Data []byte `msg:"data"` +} diff --git a/frame_gen.go b/skylab/skylab_msgp_gen.go similarity index 51% rename from frame_gen.go rename to skylab/skylab_msgp_gen.go index 2baf6af..02ef345 100644 --- a/frame_gen.go +++ b/skylab/skylab_msgp_gen.go @@ -1,4 +1,4 @@ -package gotelem +package skylab // Code generated by github.com/tinylib/msgp DO NOT EDIT. @@ -7,7 +7,7 @@ import ( ) // DecodeMsg implements msgp.Decodable -func (z *CanFilter) DecodeMsg(dc *msgp.Reader) (err error) { +func (z *msgpRawEvent) DecodeMsg(dc *msgp.Reader) (err error) { var field []byte _ = field var zb0001 uint32 @@ -24,181 +24,24 @@ func (z *CanFilter) DecodeMsg(dc *msgp.Reader) (err error) { return } switch msgp.UnsafeString(field) { - case "Id": + case "ts": + z.Timestamp, err = dc.ReadFloat64() + if err != nil { + err = msgp.WrapError(err, "Timestamp") + return + } + case "id": z.Id, err = dc.ReadUint32() if err != nil { err = msgp.WrapError(err, "Id") return } - case "Mask": - z.Mask, err = dc.ReadUint32() - if err != nil { - err = msgp.WrapError(err, "Mask") - return - } - case "Inverted": - z.Inverted, err = dc.ReadBool() - if err != nil { - err = msgp.WrapError(err, "Inverted") - return - } - default: - err = dc.Skip() - if err != nil { - err = msgp.WrapError(err) - return - } - } - } - return -} - -// EncodeMsg implements msgp.Encodable -func (z CanFilter) EncodeMsg(en *msgp.Writer) (err error) { - // map header, size 3 - // write "Id" - err = en.Append(0x83, 0xa2, 0x49, 0x64) - if err != nil { - return - } - err = en.WriteUint32(z.Id) - if err != nil { - err = msgp.WrapError(err, "Id") - return - } - // write "Mask" - err = en.Append(0xa4, 0x4d, 0x61, 0x73, 0x6b) - if err != nil { - return - } - err = en.WriteUint32(z.Mask) - if err != nil { - err = msgp.WrapError(err, "Mask") - return - } - // write "Inverted" - err = en.Append(0xa8, 0x49, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64) - if err != nil { - return - } - err = en.WriteBool(z.Inverted) - if err != nil { - err = msgp.WrapError(err, "Inverted") - return - } - return -} - -// MarshalMsg implements msgp.Marshaler -func (z CanFilter) MarshalMsg(b []byte) (o []byte, err error) { - o = msgp.Require(b, z.Msgsize()) - // map header, size 3 - // string "Id" - o = append(o, 0x83, 0xa2, 0x49, 0x64) - o = msgp.AppendUint32(o, z.Id) - // string "Mask" - o = append(o, 0xa4, 0x4d, 0x61, 0x73, 0x6b) - o = msgp.AppendUint32(o, z.Mask) - // string "Inverted" - o = append(o, 0xa8, 0x49, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64) - o = msgp.AppendBool(o, z.Inverted) - return -} - -// UnmarshalMsg implements msgp.Unmarshaler -func (z *CanFilter) UnmarshalMsg(bts []byte) (o []byte, err error) { - var field []byte - _ = field - var zb0001 uint32 - zb0001, bts, err = msgp.ReadMapHeaderBytes(bts) - if err != nil { - err = msgp.WrapError(err) - return - } - for zb0001 > 0 { - zb0001-- - field, bts, err = msgp.ReadMapKeyZC(bts) - if err != nil { - err = msgp.WrapError(err) - return - } - switch msgp.UnsafeString(field) { - case "Id": - z.Id, bts, err = msgp.ReadUint32Bytes(bts) - if err != nil { - err = msgp.WrapError(err, "Id") - return - } - case "Mask": - z.Mask, bts, err = msgp.ReadUint32Bytes(bts) - if err != nil { - err = msgp.WrapError(err, "Mask") - return - } - case "Inverted": - z.Inverted, bts, err = msgp.ReadBoolBytes(bts) - if err != nil { - err = msgp.WrapError(err, "Inverted") - return - } - default: - bts, err = msgp.Skip(bts) - if err != nil { - err = msgp.WrapError(err) - return - } - } - } - o = bts - return -} - -// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z CanFilter) Msgsize() (s int) { - s = 1 + 3 + msgp.Uint32Size + 5 + msgp.Uint32Size + 9 + msgp.BoolSize - return -} - -// DecodeMsg implements msgp.Decodable -func (z *Frame) DecodeMsg(dc *msgp.Reader) (err error) { - var field []byte - _ = field - var zb0001 uint32 - zb0001, err = dc.ReadMapHeader() - if err != nil { - err = msgp.WrapError(err) - return - } - for zb0001 > 0 { - zb0001-- - field, err = dc.ReadMapKeyPtr() - if err != nil { - err = msgp.WrapError(err) - return - } - switch msgp.UnsafeString(field) { - case "Id": - z.Id, err = dc.ReadUint32() - if err != nil { - err = msgp.WrapError(err, "Id") - return - } - case "Data": + case "data": z.Data, err = dc.ReadBytes(z.Data) if err != nil { err = msgp.WrapError(err, "Data") return } - case "Kind": - { - var zb0002 uint8 - zb0002, err = dc.ReadUint8() - if err != nil { - err = msgp.WrapError(err, "Kind") - return - } - z.Kind = Kind(zb0002) - } default: err = dc.Skip() if err != nil { @@ -211,10 +54,20 @@ func (z *Frame) DecodeMsg(dc *msgp.Reader) (err error) { } // EncodeMsg implements msgp.Encodable -func (z *Frame) EncodeMsg(en *msgp.Writer) (err error) { +func (z *msgpRawEvent) EncodeMsg(en *msgp.Writer) (err error) { // map header, size 3 - // write "Id" - err = en.Append(0x83, 0xa2, 0x49, 0x64) + // write "ts" + err = en.Append(0x83, 0xa2, 0x74, 0x73) + if err != nil { + return + } + err = en.WriteFloat64(z.Timestamp) + if err != nil { + err = msgp.WrapError(err, "Timestamp") + return + } + // write "id" + err = en.Append(0xa2, 0x69, 0x64) if err != nil { return } @@ -223,8 +76,8 @@ func (z *Frame) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Id") return } - // write "Data" - err = en.Append(0xa4, 0x44, 0x61, 0x74, 0x61) + // write "data" + err = en.Append(0xa4, 0x64, 0x61, 0x74, 0x61) if err != nil { return } @@ -233,37 +86,27 @@ func (z *Frame) EncodeMsg(en *msgp.Writer) (err error) { err = msgp.WrapError(err, "Data") return } - // write "Kind" - err = en.Append(0xa4, 0x4b, 0x69, 0x6e, 0x64) - if err != nil { - return - } - err = en.WriteUint8(uint8(z.Kind)) - if err != nil { - err = msgp.WrapError(err, "Kind") - return - } return } // MarshalMsg implements msgp.Marshaler -func (z *Frame) MarshalMsg(b []byte) (o []byte, err error) { +func (z *msgpRawEvent) MarshalMsg(b []byte) (o []byte, err error) { o = msgp.Require(b, z.Msgsize()) // map header, size 3 - // string "Id" - o = append(o, 0x83, 0xa2, 0x49, 0x64) + // string "ts" + o = append(o, 0x83, 0xa2, 0x74, 0x73) + o = msgp.AppendFloat64(o, z.Timestamp) + // string "id" + o = append(o, 0xa2, 0x69, 0x64) o = msgp.AppendUint32(o, z.Id) - // string "Data" - o = append(o, 0xa4, 0x44, 0x61, 0x74, 0x61) + // string "data" + o = append(o, 0xa4, 0x64, 0x61, 0x74, 0x61) o = msgp.AppendBytes(o, z.Data) - // string "Kind" - o = append(o, 0xa4, 0x4b, 0x69, 0x6e, 0x64) - o = msgp.AppendUint8(o, uint8(z.Kind)) return } // UnmarshalMsg implements msgp.Unmarshaler -func (z *Frame) UnmarshalMsg(bts []byte) (o []byte, err error) { +func (z *msgpRawEvent) UnmarshalMsg(bts []byte) (o []byte, err error) { var field []byte _ = field var zb0001 uint32 @@ -280,28 +123,24 @@ func (z *Frame) UnmarshalMsg(bts []byte) (o []byte, err error) { return } switch msgp.UnsafeString(field) { - case "Id": + case "ts": + z.Timestamp, bts, err = msgp.ReadFloat64Bytes(bts) + if err != nil { + err = msgp.WrapError(err, "Timestamp") + return + } + case "id": z.Id, bts, err = msgp.ReadUint32Bytes(bts) if err != nil { err = msgp.WrapError(err, "Id") return } - case "Data": + case "data": z.Data, bts, err = msgp.ReadBytesBytes(bts, z.Data) if err != nil { err = msgp.WrapError(err, "Data") return } - case "Kind": - { - var zb0002 uint8 - zb0002, bts, err = msgp.ReadUint8Bytes(bts) - if err != nil { - err = msgp.WrapError(err, "Kind") - return - } - z.Kind = Kind(zb0002) - } default: bts, err = msgp.Skip(bts) if err != nil { @@ -315,59 +154,135 @@ func (z *Frame) UnmarshalMsg(bts []byte) (o []byte, err error) { } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z *Frame) Msgsize() (s int) { - s = 1 + 3 + msgp.Uint32Size + 5 + msgp.BytesPrefixSize + len(z.Data) + 5 + msgp.Uint8Size +func (z *msgpRawEvent) Msgsize() (s int) { + s = 1 + 3 + msgp.Float64Size + 3 + msgp.Uint32Size + 5 + msgp.BytesPrefixSize + len(z.Data) return } // DecodeMsg implements msgp.Decodable -func (z *Kind) DecodeMsg(dc *msgp.Reader) (err error) { - { - var zb0001 uint8 - zb0001, err = dc.ReadUint8() +func (z *msgpRawPacket) DecodeMsg(dc *msgp.Reader) (err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, err = dc.ReadMapHeader() + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, err = dc.ReadMapKeyPtr() if err != nil { err = msgp.WrapError(err) return } - (*z) = Kind(zb0001) + switch msgp.UnsafeString(field) { + case "id": + z.Id, err = dc.ReadUint32() + if err != nil { + err = msgp.WrapError(err, "Id") + return + } + case "data": + z.Data, err = dc.ReadBytes(z.Data) + if err != nil { + err = msgp.WrapError(err, "Data") + return + } + default: + err = dc.Skip() + if err != nil { + err = msgp.WrapError(err) + return + } + } } return } // EncodeMsg implements msgp.Encodable -func (z Kind) EncodeMsg(en *msgp.Writer) (err error) { - err = en.WriteUint8(uint8(z)) +func (z *msgpRawPacket) EncodeMsg(en *msgp.Writer) (err error) { + // map header, size 2 + // write "id" + err = en.Append(0x82, 0xa2, 0x69, 0x64) if err != nil { - err = msgp.WrapError(err) + return + } + err = en.WriteUint32(z.Id) + if err != nil { + err = msgp.WrapError(err, "Id") + return + } + // write "data" + err = en.Append(0xa4, 0x64, 0x61, 0x74, 0x61) + if err != nil { + return + } + err = en.WriteBytes(z.Data) + if err != nil { + err = msgp.WrapError(err, "Data") return } return } // MarshalMsg implements msgp.Marshaler -func (z Kind) MarshalMsg(b []byte) (o []byte, err error) { +func (z *msgpRawPacket) MarshalMsg(b []byte) (o []byte, err error) { o = msgp.Require(b, z.Msgsize()) - o = msgp.AppendUint8(o, uint8(z)) + // map header, size 2 + // string "id" + o = append(o, 0x82, 0xa2, 0x69, 0x64) + o = msgp.AppendUint32(o, z.Id) + // string "data" + o = append(o, 0xa4, 0x64, 0x61, 0x74, 0x61) + o = msgp.AppendBytes(o, z.Data) return } // UnmarshalMsg implements msgp.Unmarshaler -func (z *Kind) UnmarshalMsg(bts []byte) (o []byte, err error) { - { - var zb0001 uint8 - zb0001, bts, err = msgp.ReadUint8Bytes(bts) +func (z *msgpRawPacket) UnmarshalMsg(bts []byte) (o []byte, err error) { + var field []byte + _ = field + var zb0001 uint32 + zb0001, bts, err = msgp.ReadMapHeaderBytes(bts) + if err != nil { + err = msgp.WrapError(err) + return + } + for zb0001 > 0 { + zb0001-- + field, bts, err = msgp.ReadMapKeyZC(bts) if err != nil { err = msgp.WrapError(err) return } - (*z) = Kind(zb0001) + switch msgp.UnsafeString(field) { + case "id": + z.Id, bts, err = msgp.ReadUint32Bytes(bts) + if err != nil { + err = msgp.WrapError(err, "Id") + return + } + case "data": + z.Data, bts, err = msgp.ReadBytesBytes(bts, z.Data) + if err != nil { + err = msgp.WrapError(err, "Data") + return + } + default: + bts, err = msgp.Skip(bts) + if err != nil { + err = msgp.WrapError(err) + return + } + } } o = bts return } // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message -func (z Kind) Msgsize() (s int) { - s = msgp.Uint8Size +func (z *msgpRawPacket) Msgsize() (s int) { + s = 1 + 3 + msgp.Uint32Size + 5 + msgp.BytesPrefixSize + len(z.Data) return } diff --git a/frame_gen_test.go b/skylab/skylab_msgp_gen_test.go similarity index 73% rename from frame_gen_test.go rename to skylab/skylab_msgp_gen_test.go index c7d8481..a28665a 100644 --- a/frame_gen_test.go +++ b/skylab/skylab_msgp_gen_test.go @@ -1,4 +1,4 @@ -package gotelem +package skylab // Code generated by github.com/tinylib/msgp DO NOT EDIT. @@ -9,8 +9,8 @@ import ( "github.com/tinylib/msgp/msgp" ) -func TestMarshalUnmarshalCanFilter(t *testing.T) { - v := CanFilter{} +func TestMarshalUnmarshalmsgpRawEvent(t *testing.T) { + v := msgpRawEvent{} bts, err := v.MarshalMsg(nil) if err != nil { t.Fatal(err) @@ -32,8 +32,8 @@ func TestMarshalUnmarshalCanFilter(t *testing.T) { } } -func BenchmarkMarshalMsgCanFilter(b *testing.B) { - v := CanFilter{} +func BenchmarkMarshalMsgmsgpRawEvent(b *testing.B) { + v := msgpRawEvent{} b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { @@ -41,8 +41,8 @@ func BenchmarkMarshalMsgCanFilter(b *testing.B) { } } -func BenchmarkAppendMsgCanFilter(b *testing.B) { - v := CanFilter{} +func BenchmarkAppendMsgmsgpRawEvent(b *testing.B) { + v := msgpRawEvent{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) b.SetBytes(int64(len(bts))) @@ -53,8 +53,8 @@ func BenchmarkAppendMsgCanFilter(b *testing.B) { } } -func BenchmarkUnmarshalCanFilter(b *testing.B) { - v := CanFilter{} +func BenchmarkUnmarshalmsgpRawEvent(b *testing.B) { + v := msgpRawEvent{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() b.SetBytes(int64(len(bts))) @@ -67,17 +67,17 @@ func BenchmarkUnmarshalCanFilter(b *testing.B) { } } -func TestEncodeDecodeCanFilter(t *testing.T) { - v := CanFilter{} +func TestEncodeDecodemsgpRawEvent(t *testing.T) { + v := msgpRawEvent{} var buf bytes.Buffer msgp.Encode(&buf, &v) m := v.Msgsize() if buf.Len() > m { - t.Log("WARNING: TestEncodeDecodeCanFilter Msgsize() is inaccurate") + t.Log("WARNING: TestEncodeDecodemsgpRawEvent Msgsize() is inaccurate") } - vn := CanFilter{} + vn := msgpRawEvent{} err := msgp.Decode(&buf, &vn) if err != nil { t.Error(err) @@ -91,8 +91,8 @@ func TestEncodeDecodeCanFilter(t *testing.T) { } } -func BenchmarkEncodeCanFilter(b *testing.B) { - v := CanFilter{} +func BenchmarkEncodemsgpRawEvent(b *testing.B) { + v := msgpRawEvent{} var buf bytes.Buffer msgp.Encode(&buf, &v) b.SetBytes(int64(buf.Len())) @@ -105,8 +105,8 @@ func BenchmarkEncodeCanFilter(b *testing.B) { en.Flush() } -func BenchmarkDecodeCanFilter(b *testing.B) { - v := CanFilter{} +func BenchmarkDecodemsgpRawEvent(b *testing.B) { + v := msgpRawEvent{} var buf bytes.Buffer msgp.Encode(&buf, &v) b.SetBytes(int64(buf.Len())) @@ -122,8 +122,8 @@ func BenchmarkDecodeCanFilter(b *testing.B) { } } -func TestMarshalUnmarshalFrame(t *testing.T) { - v := Frame{} +func TestMarshalUnmarshalmsgpRawPacket(t *testing.T) { + v := msgpRawPacket{} bts, err := v.MarshalMsg(nil) if err != nil { t.Fatal(err) @@ -145,8 +145,8 @@ func TestMarshalUnmarshalFrame(t *testing.T) { } } -func BenchmarkMarshalMsgFrame(b *testing.B) { - v := Frame{} +func BenchmarkMarshalMsgmsgpRawPacket(b *testing.B) { + v := msgpRawPacket{} b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { @@ -154,8 +154,8 @@ func BenchmarkMarshalMsgFrame(b *testing.B) { } } -func BenchmarkAppendMsgFrame(b *testing.B) { - v := Frame{} +func BenchmarkAppendMsgmsgpRawPacket(b *testing.B) { + v := msgpRawPacket{} bts := make([]byte, 0, v.Msgsize()) bts, _ = v.MarshalMsg(bts[0:0]) b.SetBytes(int64(len(bts))) @@ -166,8 +166,8 @@ func BenchmarkAppendMsgFrame(b *testing.B) { } } -func BenchmarkUnmarshalFrame(b *testing.B) { - v := Frame{} +func BenchmarkUnmarshalmsgpRawPacket(b *testing.B) { + v := msgpRawPacket{} bts, _ := v.MarshalMsg(nil) b.ReportAllocs() b.SetBytes(int64(len(bts))) @@ -180,17 +180,17 @@ func BenchmarkUnmarshalFrame(b *testing.B) { } } -func TestEncodeDecodeFrame(t *testing.T) { - v := Frame{} +func TestEncodeDecodemsgpRawPacket(t *testing.T) { + v := msgpRawPacket{} var buf bytes.Buffer msgp.Encode(&buf, &v) m := v.Msgsize() if buf.Len() > m { - t.Log("WARNING: TestEncodeDecodeFrame Msgsize() is inaccurate") + t.Log("WARNING: TestEncodeDecodemsgpRawPacket Msgsize() is inaccurate") } - vn := Frame{} + vn := msgpRawPacket{} err := msgp.Decode(&buf, &vn) if err != nil { t.Error(err) @@ -204,8 +204,8 @@ func TestEncodeDecodeFrame(t *testing.T) { } } -func BenchmarkEncodeFrame(b *testing.B) { - v := Frame{} +func BenchmarkEncodemsgpRawPacket(b *testing.B) { + v := msgpRawPacket{} var buf bytes.Buffer msgp.Encode(&buf, &v) b.SetBytes(int64(buf.Len())) @@ -218,8 +218,8 @@ func BenchmarkEncodeFrame(b *testing.B) { en.Flush() } -func BenchmarkDecodeFrame(b *testing.B) { - v := Frame{} +func BenchmarkDecodemsgpRawPacket(b *testing.B) { + v := msgpRawPacket{} var buf bytes.Buffer msgp.Encode(&buf, &v) b.SetBytes(int64(buf.Len())) diff --git a/skylab/templates/golang.go.tmpl b/skylab/templates/golang.go.tmpl index 3cdef18..f7b6756 100644 --- a/skylab/templates/golang.go.tmpl +++ b/skylab/templates/golang.go.tmpl @@ -11,7 +11,7 @@ type {{$bfname}} struct { {{- end}} } -func (p *{{$bfname}}) Marshal() byte { +func (p *{{$bfname}}) MarshalByte() byte { var b byte {{- range $idx, $el := .Bits}} {{- $bitName := camelCase $el.Name true}} @@ -22,7 +22,7 @@ func (p *{{$bfname}}) Marshal() byte { return b } -func (p *{{$bfname}}) Unmarshal(b byte) { +func (p *{{$bfname}}) UnmarshalByte(b byte) { {{- range $idx, $el := .Bits}} {{- $bitName := camelCase $el.Name true }} p.{{$bitName}} = (b & (1 << {{ $idx }})) != 0 @@ -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, errors.New("unknown id") } switch id { {{- range $p := .Packets }} @@ -133,34 +133,32 @@ func FromCanFrame(id uint32, data []byte) (Packet, error) { {{- end}} } - return nil, errors.New("failed to match Id, something is really wrong!") + return nil, errors.New("failed to match Id, something is really wrong") } -func FromJson (raw []byte) (Packet, error) { - // attempt to parse the JSON to a JSONPacket - jp := &JSONPacket{} - err := json.Unmarshal(raw, jp) - if err != nil { - return nil, err + +func FromJson (id uint32, raw []byte) (Packet, error) { + if !idMap[id] { + return nil, errors.New("unknown id") } - switch jp.Id { + switch id { {{- range $p := .Packets }} {{- if $p.Repeat }} case {{ Nx (int $p.Id) $p.Repeat $p.Offset | mapf "0x%X" | strJoin ", " -}}: var res = &{{camelCase $p.Name true}}{} - err := json.Unmarshal(jp.Data, res) - res.Idx = jp.Id - {{ $p.Id | printf "0x%X" }} + err := json.Unmarshal(raw, res) + res.Idx = id - {{ $p.Id | printf "0x%X" }} return res, err {{- else }} case {{ $p.Id | printf "0x%X" }}: var res = &{{camelCase $p.Name true}}{} - err := json.Unmarshal(jp.Data, res) + err := json.Unmarshal(raw, res) return res, err {{- end }} {{- end }} } - return nil, errors.New("aaa") + return nil, errors.New("failed to match id") } {{range .Packets -}} diff --git a/skylab/templates/golang_tests.go.tmpl b/skylab/templates/golang_tests.go.tmpl index fedf567..238ce61 100644 --- a/skylab/templates/golang_tests.go.tmpl +++ b/skylab/templates/golang_tests.go.tmpl @@ -23,17 +23,14 @@ func TestMarshalUnmarshal{{$structName}}(t *testing.T) { func TestJSON{{$structName}}(t *testing.T) { v := &{{$structName}}{} - jp, err := ToJson(v) + + rawData, err := json.Marshal(v) if err != nil { t.Fatal(err) } - rawData, err := json.Marshal(jp) - if err != nil { - t.Fatal(err) - } - - p, err := FromJson(rawData) + id, _ := v.CANId() + p, err := FromJson(id, rawData) if err != nil { t.Fatal(err) } diff --git a/skylab_logger.go b/skylab_logger.go deleted file mode 100644 index 946d743..0000000 --- a/skylab_logger.go +++ /dev/null @@ -1,58 +0,0 @@ -package gotelem - -import ( - "encoding/json" - "fmt" - "os" - "time" - - "github.com/kschamplin/gotelem/skylab" -) - -// CanWriter -type CanWriter struct { - output *os.File - cd CANDumpEntry - jsonBuf []byte -} - -// send writes the frame to the file. -func (cw *CanWriter) Send(f *Frame) (err error) { - cw.cd.Timestamp = float64(time.Now().Unix()) - - cw.cd.Id = uint64(f.Id) - - cw.cd.Data, err = skylab.FromCanFrame(f.Id, f.Data) - - if err != nil { - return - } - out, err := json.Marshal(cw.cd) - if err != nil { - return - } - fmt.Fprintln(cw.output, string(out)) - return err -} - -func (cw *CanWriter) Close() error { - return cw.output.Close() -} - -func OpenCanWriter(name string) (*CanWriter, error) { - f, err := os.Create(name) - if err != nil { - return nil, err - } - - cw := &CanWriter{ - output: f, - } - return cw, nil -} - -type CANDumpEntry struct { - Timestamp float64 `json:"ts"` - Id uint64 `json:"id"` - Data skylab.Packet `json:"data"` -}