Compare commits

..

2 commits

Author SHA1 Message Date
saji d6cd4d3e26 fix tests, add packets stuff for db
Some checks failed
Go / build (push) Failing after 1m45s
2024-02-28 01:07:36 -06:00
saji 3f6db8e5c5 remove fixer 2024-02-28 01:07:36 -06:00
11 changed files with 157 additions and 420 deletions

View file

@ -1,206 +0,0 @@
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"syscall"
"time"
"log/slog"
"github.com/kschamplin/gotelem/skylab"
"github.com/urfave/cli/v2"
)
// fixer resolves four major issues with CAN dumps:
// 1. ISO8601 timestamps
// 2. Unix seconds timestamps
// 3. Missing/broken timestamps (retime)
// 4. missing names
func main() {
app := cli.NewApp()
app.Name = "fixer"
app.Usage = " fix skylabify outputs"
app.ArgsUsage = "<input file>"
app.Description = `fixer fixes four major issues with CAN dumps
1. ISO8601 timestamps --time iso8601
2. Unix seconds timestamps --time seconds
3. Missing/broken timestamps --retime
4. missing names (enabled by default, --no-rename to skip)
`
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "retime",
Usage: "ignore timestamps and retime data based on 200ms heartbeat packet",
},
&cli.StringFlag{
Name: "format",
Usage: "Timestamp format. One of 'iso8601', 'seconds'. Ignored if using retime.",
},
&cli.BoolFlag{
Name: "no-rename",
Usage: "skip changing packet names",
},
&cli.StringFlag{
Name: "output",
Usage: "file to output to. defaults to stdout.",
},
}
app.Before = validateArgs
app.Action = run
app.HideHelp = true
app.Run(os.Args)
}
var allowedFormats = []string{
"iso8601",
"seconds",
}
func checkFormat(input string) bool {
for _, allowed := range allowedFormats {
if input == allowed {
return true
}
}
return false
}
func validateArgs(ctx *cli.Context) error {
if ctx.IsSet("format") {
format := ctx.String("format")
if !checkFormat(format) {
fmt.Printf("invalid format string, got %s, must be one of %s", format, strings.Join(allowedFormats, ", "))
cli.ShowAppHelpAndExit(ctx, int(syscall.EINVAL))
}
}
if ctx.Args().Get(0) == "" {
fmt.Println("missing input file")
cli.ShowAppHelpAndExit(ctx, int(syscall.EINVAL))
}
return nil
}
func run(ctx *cli.Context) (err error) {
path := ctx.Args().Get(0)
var istream *os.File
if path == "-" {
istream = os.Stdin
} else {
istream, err = os.Open(path)
if err != nil {
return
}
}
var ostream *os.File
oFilename := ctx.Args().Get(1)
if oFilename == "" {
ostream = os.Stdout
} else {
ostream, err = os.Create(oFilename)
if err != nil {
return
}
}
iReader := json.NewDecoder(istream)
shouldRetime := ctx.Bool("retime")
// used for retime - increment by 200 ms every time we see a WsrStatusPacket
currentTick := time.Now().UnixMilli()
for {
// read a line of json and fix names if we should.
// FIXME: handle missing trailing newline.
// based on the fomat string, we should parse the data raw...
var res brokenCANMsg
err := iReader.Decode(&res)
// float64 can have issues when represeneting
// unix milliseconds. the JSON decoder supports
// a "Number" struct that can be either.
iReader.UseNumber()
if err != nil {
return err
}
var goodPkt skylab.RawJsonEvent
goodPkt.Data = res.Data
goodPkt.Id = uint32(res.Id)
goodPkt.Name = res.Name
// wait to decode packet before rename.
switch ts := res.Timestamp.(type) {
case json.Number:
// if it contains a decimal.
if strings.Contains(ts.String(), ".") {
// it's a float.
t, _ := ts.Float64()
t = t * 1000
goodPkt.Timestamp = int64(t)
} else {
// it's an int.
t, _ := ts.Int64()
if ctx.String("format") == "seconds" {
t = t * 1000
}
goodPkt.Timestamp = t
}
case string:
// parse as ISO8601
// use unix millis
var t time.Time
err := t.UnmarshalText([]byte(ts))
if err != nil {
panic(err)
}
goodPkt.Timestamp = t.UnixMilli()
}
if shouldRetime {
if goodPkt.Id == uint32(skylab.WsrStatusInformationId) {
// bump the clock 200ms
currentTick += 200
}
goodPkt.Timestamp = currentTick
}
// now, spit it out.
var bEv skylab.BusEvent
bEv.Timestamp = time.UnixMilli(goodPkt.Timestamp)
bEv.Id = goodPkt.Id
bEv.Data, err = skylab.FromJson(goodPkt.Id, goodPkt.Data)
var idErr *skylab.UnknownIdError
if errors.As(err, &idErr) {
// unknown id
slog.Info("unknown id", "err", err)
continue
} else if err != nil {
return err
}
out, err := json.Marshal(&bEv)
if err != nil {
panic(err)
}
fmt.Fprintln(ostream, string(out))
}
}
type brokenCANMsg struct {
Timestamp any `json:"ts"`
Id int32
Name string
Data json.RawMessage
}

View file

@ -28,16 +28,12 @@ type TelemDb struct {
// TelemDbOption lets you customize the behavior of the sqlite database
type TelemDbOption func(*TelemDb) error
// this string is used to open the read-write db.
// the extra options improve performance significantly.
const rwDbPathFmt = "file:%s?_journal_mode=wal&mode=rwc&_txlock=immediate&_timeout=10000"
func OpenTelemDb(path string, options ...TelemDbOption) (tdb *TelemDb, err error) {
// this function is internal use. It actually opens the database, but uses
// a raw path string instead of formatting one like the exported functions.
func openRawDb(rawpath string, options ...TelemDbOption) (tdb *TelemDb, err error) {
tdb = &TelemDb{}
dbStr := fmt.Sprintf(rwDbPathFmt, path)
tdb.db, err = sqlx.Connect("sqlite3", dbStr)
tdb.db, err = sqlx.Connect("sqlite3", rawpath)
if err != nil {
return
}
@ -62,6 +58,17 @@ func OpenTelemDb(path string, options ...TelemDbOption) (tdb *TelemDb, err error
return tdb, err
}
// this string is used to open the read-write db.
// the extra options improve performance significantly.
const rwDbPathFmt = "file:%s?_journal_mode=wal&mode=rwc&_txlock=immediate&_timeout=10000"
// OpenTelemDb opens a new telemetry database at the given path.
func OpenTelemDb(path string, options ...TelemDbOption) (*TelemDb, error) {
dbStr := fmt.Sprintf(rwDbPathFmt, path)
return openRawDb(dbStr, options...)
}
func (tdb *TelemDb) GetVersion() (int, error) {
var version int
err := tdb.db.Get(&version, "PRAGMA user_version")
@ -79,7 +86,10 @@ const sqlInsertEvent =`INSERT INTO "bus_events" (ts, name, data) VALUES `
// AddEvent adds the bus event to the database.
func (tdb *TelemDb) AddEventsCtx(ctx context.Context, events ...skylab.BusEvent) (n int64, err error) {
//
// edge case - zero events.
if len(events) == 0 {
return 0, nil
}
n = 0
tx, err := tdb.db.BeginTx(ctx, nil)
defer tx.Rollback()
@ -109,7 +119,7 @@ func (tdb *TelemDb) AddEventsCtx(ctx context.Context, events ...skylab.BusEvent)
// construct the full statement now
sqlStmt = sqlStmt + strings.Join(inserts[:idx], ",")
stmt, err := tx.PrepareContext(ctx, sqlStmt)
defer stmt.Close()
// defer stmt.Close()
if err != nil {
return
}

View file

@ -1,6 +1,7 @@
package db
import (
"fmt"
"reflect"
"testing"
"time"
@ -19,7 +20,6 @@ func GetRandomBusEvent() skylab.BusEvent {
Timestamp: time.Now(),
Data: &data,
}
ev.Id, _ = data.CANId()
return ev
}
@ -30,11 +30,20 @@ func TestTelemDb(t *testing.T) {
t.Run("test opening database", func(t *testing.T) {
var err error
tdb, err = OpenTelemDb("file::memory:?cache=shared")
// we use the underlying raw database to avoid the options.
tdb, err = openRawDb("file::memory:?cache=shared")
if err != nil {
t.Errorf("could not open db: %v", err)
}
tdb.db.Ping()
res, _ := tdb.db.Query("SELECT name FROM sqlite_master WHERE type='table'")
var table string
for res.Next() {
res.Scan(&table)
fmt.Println(table)
}
})
t.Run("test inserting bus event", func(t *testing.T) {
@ -63,7 +72,7 @@ func TestTelemDb(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tdb.AddEvents(tt.args.events...); (err != nil) != tt.wantErr {
if _, err := tdb.AddEvents(tt.args.events...); (err != nil) != tt.wantErr {
t.Errorf("TelemDb.AddEvents() error = %v, wantErr %v", err, tt.wantErr)
}
})

View file

@ -87,7 +87,7 @@ func RunMigrations(tdb *TelemDb) (finalVer int, err error) {
for _, v := range vers {
if v != expectedVer {
err = errors.New("missing update between")
return
return 0, err
// invalid
}
expectedVer = v + 1
@ -97,35 +97,36 @@ func RunMigrations(tdb *TelemDb) (finalVer int, err error) {
// now apply the mappings based on current ver.
tx, err := tdb.db.Begin()
defer tx.Rollback()
if err != nil {
return
return 0, err
}
for v := currentVer + 1; v <= finalVer; v++ {
// attempt to get the "up" migration.
mMap, ok := migrations[v]
if !ok {
err = errors.New("could not find migration for version")
goto rollback
return 0, err
}
upMigration, ok := mMap["up"]
if !ok {
err = errors.New("could not get up migration")
goto rollback
return 0, err
}
upFile, err := migrationsFs.Open(path.Join("migrations", upMigration.FileName))
if err != nil {
goto rollback
return 0, err
}
upStmt, err := io.ReadAll(upFile)
if err != nil {
goto rollback
return 0, err
}
// open the file name
// execute the file.
_, err = tx.Exec(string(upStmt))
if err != nil {
goto rollback
return 0, err
}
}
@ -134,8 +135,4 @@ func RunMigrations(tdb *TelemDb) (finalVer int, err error) {
err = tdb.SetVersion(finalVer)
return
// yeah, we use goto. Deal with it.
rollback:
tx.Rollback()
return
}

View file

@ -0,0 +1,2 @@
DROP TABLE "packet_definitions";
DROP TABLE "field_definitions";

View file

@ -0,0 +1,13 @@
CREATE TABLE "packet_definitions" (
"name" TEXT NOT NULL,
"description" TEXT,
"id" INTEGER NOT NULL,
);
CREATE TABLE "field_definitions" (
"name" TEXT NOT NULL,
"subname" TEXT, -- if the data type is a bitfield, we can use subname to identify the bit.
"packet_name" TEXT NOT NULL,
"type" TEXT NOT NULL,
FOREIGN KEY("packet_name") REFERENCES packet_definitions(name)
);

3
internal/db/packets.go Normal file
View file

@ -0,0 +1,3 @@
package db
// This file implements Packet modelling, which allows us to look up fields by name

View file

@ -1,4 +1,4 @@
// generated by gen_skylab.go at 2024-02-12 10:42:55.884248761 -0600 CST m=+0.003327461 DO NOT EDIT!
// generated by gen_skylab.go at 2024-02-27 19:26:47.373116343 -0600 CST m=+0.002925968 DO NOT EDIT!
package skylab

View file

@ -28,8 +28,7 @@ func TestJSONBmsMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -64,8 +63,7 @@ func TestJSONBatteryStatus(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -100,8 +98,7 @@ func TestJSONBmsKillReason(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -136,8 +133,7 @@ func TestJSONBmsModuleMinMax(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -172,8 +168,7 @@ func TestJSONBmsSoc(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -208,8 +203,7 @@ func TestJSONBmsCapacity(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -244,8 +238,7 @@ func TestJSONBmsCurrentlimit(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -280,8 +273,7 @@ func TestJSONBmsFanInfo(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -316,8 +308,7 @@ func TestJSONBmsSetMinFanSpeed(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -352,8 +343,7 @@ func TestJSONBmsModule(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -388,8 +378,7 @@ func TestJSONBmsChargerResponse(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -424,8 +413,7 @@ func TestJSONChassisIsolationFault(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -460,8 +448,7 @@ func TestJSONBmsImdInfo(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -496,8 +483,7 @@ func TestJSONDashboardPedalPercentages(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -532,8 +518,7 @@ func TestJSONCarState(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -568,8 +553,7 @@ func TestJSONDashboardPedalFault(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -604,8 +588,7 @@ func TestJSONDashboardSystemTimeoutTest(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -640,8 +623,7 @@ func TestJSONCarSpeed(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -676,8 +658,7 @@ func TestJSONFlightComputerLvBoardDisconnectCounts(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -712,8 +693,7 @@ func TestJSONFlightComputerHvBoardDisconnectCounts(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -748,8 +728,7 @@ func TestJSONFlightComputerInternalState(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -784,8 +763,7 @@ func TestJSONPowerToDrive(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -820,8 +798,7 @@ func TestJSONArrayPower(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -856,8 +833,7 @@ func TestJSONArrayEnergy(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -892,8 +868,7 @@ func TestJSONArrayEnergyReset(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -928,8 +903,7 @@ func TestJSONVisionTurnSignalsCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -964,8 +938,7 @@ func TestJSONVisionBrakeLightsCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1000,8 +973,7 @@ func TestJSONVisionHeadlightsCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1036,8 +1008,7 @@ func TestJSONVisionHornCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1072,8 +1043,7 @@ func TestJSONVisionArrayLatchesCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1108,8 +1078,7 @@ func TestJSONVisionRearviewCommand(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1144,8 +1113,7 @@ func TestJSONTrackerEnable(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1180,8 +1148,7 @@ func TestJSONDistanceTraveled(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1216,8 +1183,7 @@ func TestJSONChargerState(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1252,8 +1218,7 @@ func TestJSONChargerBmsRequest(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1288,8 +1253,7 @@ func TestJSONChargerCurrentVoltage(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1324,8 +1288,7 @@ func TestJSONChargerPower(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1360,8 +1323,7 @@ func TestJSONThunderstruckControlMessage(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1396,8 +1358,7 @@ func TestJSONVisionStatusFront(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1432,8 +1393,7 @@ func TestJSONVisionStatusRear(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1468,8 +1428,7 @@ func TestJSONLightsFrontId(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1504,8 +1463,7 @@ func TestJSONLightsBackId(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1540,8 +1498,7 @@ func TestJSONVisionId(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1576,8 +1533,7 @@ func TestJSONSteeringPressCount1(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1612,8 +1568,7 @@ func TestJSONSteeringPressCount2(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1648,8 +1603,7 @@ func TestJSONSteeringButtonColors1(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1684,8 +1638,7 @@ func TestJSONSteeringButtonColors2(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1720,8 +1673,7 @@ func TestJSONSteeringHorn(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1756,8 +1708,7 @@ func TestJSONThunderstruckStatusMessage(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1792,8 +1743,7 @@ func TestJSONTrackerData(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1828,8 +1778,7 @@ func TestJSONTritiumMotorDriveL(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1864,8 +1813,7 @@ func TestJSONTritiumMotorPowerL(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1900,8 +1848,7 @@ func TestJSONTritiumResetL(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1936,8 +1883,7 @@ func TestJSONTritiumMotorDriveR(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -1972,8 +1918,7 @@ func TestJSONTritiumMotorPowerR(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2008,8 +1953,7 @@ func TestJSONTritiumResetR(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2044,8 +1988,7 @@ func TestJSONBmsAhSet(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2080,8 +2023,7 @@ func TestJSONBmsWhSet(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2116,8 +2058,7 @@ func TestJSONBmsKill(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2152,8 +2093,7 @@ func TestJSONTelemetryRtcReset(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2188,8 +2128,7 @@ func TestJSONWsrIdentification(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2224,8 +2163,7 @@ func TestJSONWsrStatusInformation(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2260,8 +2198,7 @@ func TestJSONWsrBusMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2296,8 +2233,7 @@ func TestJSONWsrVelocity(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2332,8 +2268,7 @@ func TestJSONWsrPhaseCurrent(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2368,8 +2303,7 @@ func TestJSONWsrMotorVoltageVector(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2404,8 +2338,7 @@ func TestJSONWsrMotorCurrentVector(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2440,8 +2373,7 @@ func TestJSONWsrMotorBackemf(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2476,8 +2408,7 @@ func TestJSONWsr15165VoltageRail(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2512,8 +2443,7 @@ func TestJSONWsr2512VoltageRail(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2548,8 +2478,7 @@ func TestJSONWsrHeatsinkMotorTemp(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2584,8 +2513,7 @@ func TestJSONWsrDspBoardTemp(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2620,8 +2548,7 @@ func TestJSONWsrReserved(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2656,8 +2583,7 @@ func TestJSONWsrOdometerBusAmphoursMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2692,8 +2618,7 @@ func TestJSONWsrSlipSpeedMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2728,8 +2653,7 @@ func TestJSONWslIdentification(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2764,8 +2688,7 @@ func TestJSONWslStatusInformation(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2800,8 +2723,7 @@ func TestJSONWslBusMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2836,8 +2758,7 @@ func TestJSONWslVelocity(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2872,8 +2793,7 @@ func TestJSONWslPhaseCurrent(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2908,8 +2828,7 @@ func TestJSONWslMotorVoltageVector(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2944,8 +2863,7 @@ func TestJSONWslMotorCurrentVector(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -2980,8 +2898,7 @@ func TestJSONWslMotorBackemf(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3016,8 +2933,7 @@ func TestJSONWsl15165VoltageRail(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3052,8 +2968,7 @@ func TestJSONWsl2512VoltageRail(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3088,8 +3003,7 @@ func TestJSONWslHeatsinkMotorTemp(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3124,8 +3038,7 @@ func TestJSONWslDspBoardTemp(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3160,8 +3073,7 @@ func TestJSONWslOdometerBusAmphoursMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3196,8 +3108,7 @@ func TestJSONWslReserved(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}
@ -3232,8 +3143,7 @@ func TestJSONWslSlipSpeedMeasurement(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}

View file

@ -29,8 +29,7 @@ func TestJSON{{$structName}}(t *testing.T) {
t.Fatal(err)
}
id, _ := v.CANId()
p, err := FromJson(id, rawData)
p, err := FromJson(v.String(), rawData)
if err != nil {
t.Fatal(err)
}

View file

@ -7,7 +7,7 @@ import (
"net"
"testing"
"github.com/kschamplin/gotelem"
"github.com/kschamplin/gotelem/internal/can"
)
func TestCanSocket(t *testing.T) {
@ -43,9 +43,9 @@ func TestCanSocket(t *testing.T) {
defer sock.Close()
// make a packet.
testFrame := &gotelem.Frame{
Id: 0x123,
Kind: gotelem.CanSFFFrame,
testFrame := &can.Frame{
Id: can.CanID{Id: 0x123, Extended: false},
Kind: can.CanDataFrame,
Data: []byte{0, 1, 2, 3, 4, 5, 6, 7},
}
err := sock.Send(testFrame)
@ -61,9 +61,9 @@ func TestCanSocket(t *testing.T) {
defer sock.Close()
defer rsock.Close()
testFrame := &gotelem.Frame{
Id: 0x234,
Kind: gotelem.CanSFFFrame,
testFrame := &can.Frame{
Id: can.CanID{Id: 0x234, Extended: false},
Kind: can.CanDataFrame,
Data: []byte{0, 1, 2, 3, 4, 5, 6, 7},
}
_ = sock.Send(testFrame)