fix timestamps once and for all
This commit is contained in:
parent
a36e1478bc
commit
c68dff9d40
|
@ -94,11 +94,9 @@ func run(ctx *cli.Context) (err error) {
|
||||||
segments := strings.Split(dumpLine, " ")
|
segments := strings.Split(dumpLine, " ")
|
||||||
|
|
||||||
var cd skylab.BusEvent
|
var cd skylab.BusEvent
|
||||||
// this is cursed but easiest way to get a float from a string.
|
var unixSeconds, unixMicros int64
|
||||||
var unixSeconds, unixNanos int64
|
fmt.Sscanf(segments[0], "(%d.%d)", &unixSeconds, &unixMicros)
|
||||||
fmt.Sscanf(segments[0], "(%d.%d)", &unixSeconds, &unixNanos)
|
cd.Timestamp = time.Unix(unixSeconds, unixMicros*1000) // the canlog does usec precision for the decimal part.
|
||||||
slog.Info("hihi hi", "time", unixSeconds)
|
|
||||||
cd.Timestamp = time.Unix(unixSeconds, unixNanos)
|
|
||||||
|
|
||||||
// this is for the latter part, we need to split id/data
|
// this is for the latter part, we need to split id/data
|
||||||
hexes := strings.Split(segments[2], "#")
|
hexes := strings.Split(segments[2], "#")
|
||||||
|
|
|
@ -86,7 +86,7 @@ func ToCanFrame(p Packet) (id uint32, data []byte, err error) {
|
||||||
// internal structure for partially decoding json object.
|
// internal structure for partially decoding json object.
|
||||||
// includes
|
// includes
|
||||||
type RawJsonEvent struct {
|
type RawJsonEvent struct {
|
||||||
Timestamp uint32 `json:"ts" db:"ts"`
|
Timestamp int64 `json:"ts" db:"ts"`
|
||||||
Id uint32 `json:"id"`
|
Id uint32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Data json.RawMessage `json:"data"`
|
Data json.RawMessage `json:"data"`
|
||||||
|
@ -102,8 +102,8 @@ type BusEvent struct {
|
||||||
func (e *BusEvent) MarshalJSON() (b []byte, err error) {
|
func (e *BusEvent) MarshalJSON() (b []byte, err error) {
|
||||||
// create the underlying raw event
|
// create the underlying raw event
|
||||||
j := &RawJsonEvent{
|
j := &RawJsonEvent{
|
||||||
Timestamp: uint32(e.Timestamp.UnixMilli()),
|
Timestamp: e.Timestamp.UnixMilli(),
|
||||||
Id: uint32(e.Id),
|
Id: e.Id,
|
||||||
Name: e.Data.String(),
|
Name: e.Data.String(),
|
||||||
}
|
}
|
||||||
// now we use the magic Packet -> map[string]interface{} function
|
// now we use the magic Packet -> map[string]interface{} function
|
||||||
|
@ -125,7 +125,7 @@ func (e *BusEvent) UnmarshalJSON(b []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Timestamp = time.UnixMilli(int64(j.Timestamp))
|
e.Timestamp = time.UnixMilli(j.Timestamp)
|
||||||
e.Id = j.Id
|
e.Id = j.Id
|
||||||
e.Data, err = FromJson(j.Id, j.Data)
|
e.Data, err = FromJson(j.Id, j.Data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue