diff --git a/canlink/canclient.go b/canlink/canclient.go index 1d6387e..41a04c7 100644 --- a/canlink/canclient.go +++ b/canlink/canclient.go @@ -190,5 +190,3 @@ func (c *CanClient) StopTracking() (map[uint32]int, error) { func (c *CanClient) IsTracking() bool { return c.tracking } - - diff --git a/canlink/canlink_test.go b/canlink/canlink_test.go index 0d049ee..1b5cd06 100644 --- a/canlink/canlink_test.go +++ b/canlink/canlink_test.go @@ -28,7 +28,7 @@ func TestTracer(t *testing.T) { defer teardown(t, tracer, logger) time.Sleep(5 * time.Second) - + } func setup(t *testing.T) (*Tracer, *zap.Logger, func(*testing.T, *Tracer, *zap.Logger)) { @@ -66,7 +66,7 @@ func setup(t *testing.T) (*Tracer, *zap.Logger, func(*testing.T, *Tracer, *zap.L logger, conn, WithBusName(_busName), - WithWriters(writers)) + WithWriters(writers)) err = tracer.Open(ctx) if err != nil { @@ -96,4 +96,4 @@ func setup(t *testing.T) (*Tracer, *zap.Logger, func(*testing.T, *Tracer, *zap.L } return tracer, logger, teardown -} \ No newline at end of file +} diff --git a/canlink/tracer.go b/canlink/tracer.go index b583f6f..a237f0b 100644 --- a/canlink/tracer.go +++ b/canlink/tracer.go @@ -6,8 +6,8 @@ import ( "net" "time" - "github.com/macformula/hil/utils" "github.com/macformula/hil/canlink/writer" + "github.com/macformula/hil/utils" "github.com/pkg/errors" "go.einride.tech/can/pkg/socketcan" "go.uber.org/zap" @@ -32,8 +32,8 @@ type Tracer struct { isRunning bool receiver *socketcan.Receiver - traceDir string - writers []writer.WriterIface + traceDir string + writers []writer.WriterIface canInterface string timeout time.Duration diff --git a/canlink/writer/constants.go b/canlink/writer/constants.go index 03540a5..43871d7 100644 --- a/canlink/writer/constants.go +++ b/canlink/writer/constants.go @@ -2,7 +2,7 @@ package writer const ( _decimal = 10 - + // format for 24-hour clock with minutes, seconds, and 4 digits // of precision after decimal (period and colon delimiter) _messageTimeFormat = "15:04:05.0000" @@ -12,4 +12,4 @@ const ( // format for year, month and day with two digits each (period delimiter) _filenameDateFormat = "2006-01-02" -) \ No newline at end of file +) diff --git a/canlink/writer/converttostring.go b/canlink/writer/converttostring.go index d83d7ab..8ce8863 100644 --- a/canlink/writer/converttostring.go +++ b/canlink/writer/converttostring.go @@ -1,15 +1,15 @@ package writer import ( - "strings" "fmt" "strconv" + "strings" "encoding/json" "go.uber.org/zap" ) -// Converts timestamped frames into strings for file writing +// Converts timestamped frames into strings for file writing func convertToAscii(l *zap.Logger, timestampedFrame *TimestampedFrame) string { var builder strings.Builder @@ -43,13 +43,13 @@ func convertToAscii(l *zap.Logger, timestampedFrame *TimestampedFrame) string { return builder.String() } -// Converts timestamped frames into strings for file writing +// Converts timestamped frames into strings for file writing func convertToJson(l *zap.Logger, timestampedFrame *TimestampedFrame) string { jsonObject := map[string]interface{}{ - "time": timestampedFrame.Time.Format(_messageTimeFormat), - "id": strconv.FormatUint(uint64(timestampedFrame.Frame.ID), _decimal), + "time": timestampedFrame.Time.Format(_messageTimeFormat), + "id": strconv.FormatUint(uint64(timestampedFrame.Frame.ID), _decimal), "frameLength": strconv.FormatUint(uint64(timestampedFrame.Frame.Length), _decimal), - "bytes": timestampedFrame.Frame.Data, + "bytes": timestampedFrame.Frame.Data, } jsonData, err := json.Marshal(jsonObject) @@ -57,5 +57,5 @@ func convertToJson(l *zap.Logger, timestampedFrame *TimestampedFrame) string { l.Error(err.Error()) } - return string(jsonData) -} \ No newline at end of file + return string(jsonData) +} diff --git a/canlink/writer/timestampedframe.go b/canlink/writer/timestampedframe.go index 0eb53f6..ca822c1 100644 --- a/canlink/writer/timestampedframe.go +++ b/canlink/writer/timestampedframe.go @@ -8,4 +8,4 @@ import ( type TimestampedFrame struct { Frame can.Frame Time time.Time -} \ No newline at end of file +} diff --git a/canlink/writer/tracewriters.go b/canlink/writer/tracewriters.go index 1d6faa3..1c84ca8 100644 --- a/canlink/writer/tracewriters.go +++ b/canlink/writer/tracewriters.go @@ -4,4 +4,4 @@ type WriterIface interface { CreateTraceFile(traceDir string, busName string) error WriteFrameToFile(frame *TimestampedFrame) error CloseTraceFile() error -} \ No newline at end of file +} diff --git a/canlink/writer/tracewriters_test.go b/canlink/writer/tracewriters_test.go index b4f41a5..a0469d5 100644 --- a/canlink/writer/tracewriters_test.go +++ b/canlink/writer/tracewriters_test.go @@ -25,11 +25,11 @@ func TestJsonConvertToString(t *testing.T) { ) time := time.Date(2024, time.November, 27, 10, 30, 45, 0, time.Local) - timestampedFrame := TimestampedFrame{ + timestampedFrame := TimestampedFrame{ Frame: can.Frame{ - ID: 12, + ID: 12, Length: 8, - Data: [8]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, + Data: [8]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, }, Time: time, } @@ -68,13 +68,12 @@ func TestAsciiConvertToString(t *testing.T) { ".asc", ) - time := time.Date(2024, time.November, 27, 10, 30, 45, 0, time.Local) - timestampedFrame := TimestampedFrame{ + timestampedFrame := TimestampedFrame{ Frame: can.Frame{ - ID: 12, + ID: 12, Length: 8, - Data: [8]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, + Data: [8]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, }, Time: time, } @@ -95,4 +94,4 @@ func TestAsciiConvertToString(t *testing.T) { %v; want %v`, output, expected) } -} \ No newline at end of file +} diff --git a/canlink/writer/utils.go b/canlink/writer/utils.go index 7e72e7c..7e59e8d 100644 --- a/canlink/writer/utils.go +++ b/canlink/writer/utils.go @@ -31,5 +31,3 @@ func createEmptyTraceFile(dir string, busName string, fileSuffix string) (*os.Fi return file, nil } - - diff --git a/canlink/writer/writer.go b/canlink/writer/writer.go index 07c1456..9ebc1a5 100644 --- a/canlink/writer/writer.go +++ b/canlink/writer/writer.go @@ -2,29 +2,29 @@ package writer import ( "os" - - "go.uber.org/zap" + "github.com/pkg/errors" + "go.uber.org/zap" ) // Responsible for managing the trace file type Writer struct { - traceFile *os.File - fileExtention string + traceFile *os.File + fileExtention string convertToString func(*zap.Logger, *TimestampedFrame) string - l *zap.Logger + l *zap.Logger } func NewWriter(l *zap.Logger, fileExtention string) *Writer { convertToStringMapping := map[string]func(*zap.Logger, *TimestampedFrame) string{ - ".jsonl": convertToJson, - ".asc": convertToAscii, - } + ".jsonl": convertToJson, + ".asc": convertToAscii, + } return &Writer{ - l: l, - fileExtention: fileExtention, + l: l, + fileExtention: fileExtention, convertToString: convertToStringMapping[fileExtention], - traceFile: nil, + traceFile: nil, } } @@ -42,22 +42,21 @@ func (w *Writer) CreateTraceFile(traceDir string, busName string) error { func (w *Writer) WriteFrameToFile(frame *TimestampedFrame) error { line := w.convertToString(w.l, frame) - _, err := w.traceFile.WriteString(line) - if err != nil { + _, err := w.traceFile.WriteString(line) + if err != nil { w.l.Info("cannot write to file") - return errors.Wrap(err, "writing to trace file") - } + return errors.Wrap(err, "writing to trace file") + } _, err = w.traceFile.WriteString("\n") - if err != nil { + if err != nil { w.l.Info("cannot write to file") - return errors.Wrap(err, "writing to trace file") - } + return errors.Wrap(err, "writing to trace file") + } return nil } - func (w *Writer) CloseTraceFile() error { err := w.traceFile.Close() if err != nil { @@ -66,4 +65,4 @@ func (w *Writer) CloseTraceFile() error { } return nil -} \ No newline at end of file +}