refactor: mv arduino package to pkg dir
This commit is contained in:
parent
164445b16c
commit
18b1bd13db
@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/cyrilix/robocar-arduino/arduino"
|
"github.com/cyrilix/robocar-arduino/pkg/arduino"
|
||||||
"github.com/cyrilix/robocar-base/cli"
|
"github.com/cyrilix/robocar-base/cli"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"log"
|
"log"
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/tarm/serial"
|
"github.com/tarm/serial"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -61,18 +60,18 @@ func NewPart(client mqtt.Client, name string, baud int, throttleTopic, steeringT
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Part) Start() error {
|
func (a *Part) Start() error {
|
||||||
log.Printf("start arduino part")
|
zap.S().Info("start arduino part")
|
||||||
go a.publishLoop()
|
go a.publishLoop()
|
||||||
for {
|
for {
|
||||||
buff := bufio.NewReader(a.serial)
|
buff := bufio.NewReader(a.serial)
|
||||||
line, err := buff.ReadString('\n')
|
line, err := buff.ReadString('\n')
|
||||||
if err == io.EOF || line == "" {
|
if err == io.EOF || line == "" {
|
||||||
log.Println("remote connection closed")
|
zap.S().Error("remote connection closed")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if !serialLineRegex.MatchString(line) {
|
if !serialLineRegex.MatchString(line) {
|
||||||
log.Printf("invalid line: '%v'", line)
|
zap.S().Errorf("invalid line: '%v'", line)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
values := strings.Split(strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), ",")
|
values := strings.Split(strings.TrimSuffix(strings.TrimSuffix(line, "\n"), "\r"), ",")
|
||||||
@ -94,12 +93,12 @@ func (a *Part) updateValues(values []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Part) Stop() {
|
func (a *Part) Stop() {
|
||||||
log.Printf("stop ArduinoPart")
|
zap.S().Info("stop ArduinoPart")
|
||||||
close(a.cancel)
|
close(a.cancel)
|
||||||
switch s := a.serial.(type) {
|
switch s := a.serial.(type) {
|
||||||
case io.ReadCloser:
|
case io.ReadCloser:
|
||||||
if err := s.Close(); err != nil {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user