diff --git a/cmd/skylabify/skylabify.go b/cmd/skylabify/skylabify.go index 56163cc..57144b5 100644 --- a/cmd/skylabify/skylabify.go +++ b/cmd/skylabify/skylabify.go @@ -94,11 +94,9 @@ func run(ctx *cli.Context) (err error) { segments := strings.Split(dumpLine, " ") var cd skylab.BusEvent - // this is cursed but easiest way to get a float from a string. - var unixSeconds, unixNanos int64 - fmt.Sscanf(segments[0], "(%d.%d)", &unixSeconds, &unixNanos) - slog.Info("hihi hi", "time", unixSeconds) - cd.Timestamp = time.Unix(unixSeconds, unixNanos) + var unixSeconds, unixMicros int64 + fmt.Sscanf(segments[0], "(%d.%d)", &unixSeconds, &unixMicros) + cd.Timestamp = time.Unix(unixSeconds, unixMicros*1000) // the canlog does usec precision for the decimal part. // this is for the latter part, we need to split id/data hexes := strings.Split(segments[2], "#") diff --git a/skylab/skylab.go b/skylab/skylab.go index 3bfde31..12b0411 100644 --- a/skylab/skylab.go +++ b/skylab/skylab.go @@ -86,7 +86,7 @@ func ToCanFrame(p Packet) (id uint32, data []byte, err error) { // internal structure for partially decoding json object. // includes type RawJsonEvent struct { - Timestamp uint32 `json:"ts" db:"ts"` + Timestamp int64 `json:"ts" db:"ts"` Id uint32 `json:"id"` Name string `json:"name"` Data json.RawMessage `json:"data"` @@ -102,8 +102,8 @@ type BusEvent struct { func (e *BusEvent) MarshalJSON() (b []byte, err error) { // create the underlying raw event j := &RawJsonEvent{ - Timestamp: uint32(e.Timestamp.UnixMilli()), - Id: uint32(e.Id), + Timestamp: e.Timestamp.UnixMilli(), + Id: e.Id, Name: e.Data.String(), } // now we use the magic Packet -> map[string]interface{} function @@ -125,7 +125,7 @@ func (e *BusEvent) UnmarshalJSON(b []byte) error { return err } - e.Timestamp = time.UnixMilli(int64(j.Timestamp)) + e.Timestamp = time.UnixMilli(j.Timestamp) e.Id = j.Id e.Data, err = FromJson(j.Id, j.Data)