diff --git a/cmd/rc-arduino/rc-arduino.go b/cmd/rc-arduino/rc-arduino.go index 0dae20b..b431ac6 100644 --- a/cmd/rc-arduino/rc-arduino.go +++ b/cmd/rc-arduino/rc-arduino.go @@ -2,7 +2,7 @@ package main import ( "flag" - "github.com/cyrilix/robocar-arduino/arduino" + "github.com/cyrilix/robocar-arduino/pkg/arduino" "github.com/cyrilix/robocar-base/cli" "go.uber.org/zap" "log" diff --git a/arduino/arduino.go b/pkg/arduino/arduino.go similarity index 96% rename from arduino/arduino.go rename to pkg/arduino/arduino.go index c4d3c8b..9a75229 100644 --- a/arduino/arduino.go +++ b/pkg/arduino/arduino.go @@ -8,7 +8,6 @@ import ( "github.com/tarm/serial" "go.uber.org/zap" "io" - "log" "regexp" "strconv" "strings" @@ -61,18 +60,18 @@ func NewPart(client mqtt.Client, name string, baud int, throttleTopic, steeringT } func (a *Part) Start() error { - log.Printf("start arduino part") + zap.S().Info("start arduino part") go a.publishLoop() for { buff := bufio.NewReader(a.serial) line, err := buff.ReadString('\n') if err == io.EOF || line == "" { - log.Println("remote connection closed") + zap.S().Error("remote connection closed") break } if !serialLineRegex.MatchString(line) { - log.Printf("invalid line: '%v'", line) + zap.S().Errorf("invalid line: '%v'", line) continue } values := strings.Split(strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), ",") @@ -94,12 +93,12 @@ func (a *Part) updateValues(values []string) { } func (a *Part) Stop() { - log.Printf("stop ArduinoPart") + zap.S().Info("stop ArduinoPart") close(a.cancel) switch s := a.serial.(type) { case io.ReadCloser: if err := s.Close(); err != nil { - log.Fatalf("unable to close serial port: %v", err) + zap.S().Fatalf("unable to close serial port: %v", err) } } } diff --git a/arduino/arduino_test.go b/pkg/arduino/arduino_test.go similarity index 100% rename from arduino/arduino_test.go rename to pkg/arduino/arduino_test.go