Compare commits
No commits in common. "419a1ddd72330dd0dff8d81f8e7034a960fc7e5e" and "62d7397e059acd6f035ab2a17a07da439f99b29b" have entirely different histories.
419a1ddd72
...
62d7397e05
@ -26,12 +26,11 @@ image_build(){
|
||||
|
||||
|
||||
printf "\n\nBuild go binary %s\n\n" "${BINARY}.${binary_suffix}"
|
||||
mkdir -p build
|
||||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor ${GOTAGS} -o "build/${BINARY}.${binary_suffix}" ./cmd/${BINARY}/
|
||||
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor -a ${GOTAGS} -o "${BINARY}.${binary_suffix}" ./cmd/${BINARY}/
|
||||
|
||||
buildah --os "$GOOS" --arch "$GOARCH" $VARIANT --name "$containerName" from gcr.io/distroless/static
|
||||
buildah config --user 1234 "$containerName"
|
||||
buildah copy "$containerName" "build/${BINARY}.${binary_suffix}" /go/bin/$BINARY
|
||||
buildah copy "$containerName" "${BINARY}.${binary_suffix}" /go/bin/$BINARY
|
||||
buildah config --entrypoint '["/go/bin/'$BINARY'"]' "${containerName}"
|
||||
|
||||
buildah commit --rm --manifest $IMAGE_NAME "${containerName}" "${containerName}"
|
||||
|
@ -18,6 +18,7 @@ func main() {
|
||||
var mqttBroker, username, password, clientId string
|
||||
var throttleTopic, driveModeTopic, rcThrottleTopic string
|
||||
var minThrottle, maxThrottle float64
|
||||
var debug bool
|
||||
|
||||
err := cli.SetFloat64DefaultValueFromEnv(&minThrottle, "THROTTLE_MIN", DefaultThrottleMin)
|
||||
if err != nil {
|
||||
@ -38,7 +39,7 @@ func main() {
|
||||
flag.StringVar(&rcThrottleTopic, "mqtt-topic-rc-throttle", os.Getenv("MQTT_TOPIC_RC_THROTTLE"), "Mqtt topic that contains RC Throttle value, use MQTT_TOPIC_RC_THROTTLE if args not set")
|
||||
flag.Float64Var(&minThrottle, "throttle-min", minThrottle, "Minimum throttle value, use THROTTLE_MIN if args not set")
|
||||
flag.Float64Var(&maxThrottle, "throttle-max", maxThrottle, "Minimum throttle value, use THROTTLE_MAX if args not set")
|
||||
logLevel := zap.LevelFlag("log", zap.InfoLevel, "log level")
|
||||
flag.BoolVar(&debug, "debug", false, "Display raw value to debug")
|
||||
|
||||
flag.Parse()
|
||||
if len(os.Args) <= 1 {
|
||||
@ -47,7 +48,11 @@ func main() {
|
||||
}
|
||||
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.Level = zap.NewAtomicLevelAt(*logLevel)
|
||||
if debug {
|
||||
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
} else {
|
||||
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
|
||||
}
|
||||
lgr, err := config.Build()
|
||||
if err != nil {
|
||||
log.Fatalf("unable to init logger: %v", err)
|
||||
|
@ -98,26 +98,9 @@ func (p *ThrottlePart) onRCThrottle(_ mqtt.Client, message mqtt.Message) {
|
||||
p.muDriveMode.RLock()
|
||||
defer p.muDriveMode.RUnlock()
|
||||
if p.driveMode == events.DriveMode_USER {
|
||||
zap.S().Debug("publish new throttle value from rc")
|
||||
// Republish same content
|
||||
payload := message.Payload()
|
||||
var throttleMsg events.ThrottleMessage
|
||||
err := proto.Unmarshal(payload, &throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to unmarshall throttle msg to check throttle value: %v", err)
|
||||
return
|
||||
}
|
||||
zap.S().Debugf("publish new throttle value from rc: %v", throttleMsg.GetThrottle())
|
||||
if throttleMsg.GetThrottle() > p.maxThrottle {
|
||||
zap.S().Debugf("throttle upper that max value allowed, patch value from %v to %v", throttleMsg.GetThrottle(), p.maxThrottle)
|
||||
throttleMsg.Throttle = p.maxThrottle
|
||||
payloadPatched, err := proto.Marshal(&throttleMsg)
|
||||
if err != nil {
|
||||
zap.S().Errorf("unable to marshall throttle msg: %v", err)
|
||||
return
|
||||
}
|
||||
publish(p.client, p.throttleTopic, &payloadPatched)
|
||||
return
|
||||
}
|
||||
publish(p.client, p.throttleTopic, &payload)
|
||||
}
|
||||
}
|
||||
|
@ -38,52 +38,47 @@ func TestDefaultThrottle(t *testing.T) {
|
||||
p := NewPart(nil, throttleTopic, driveModeTopic, rcThrottleTopic, minValue, 1., 200)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
maxThrottle float32
|
||||
driveMode events.DriveModeMessage
|
||||
rcThrottle events.ThrottleMessage
|
||||
expectedThrottle events.ThrottleMessage
|
||||
}{
|
||||
{"test1", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}},
|
||||
{"test2", 1., events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{"test3", 1., events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{"test4", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}},
|
||||
{"test5", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
{"test6", 1., events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}},
|
||||
{"limit max throttle on user mode", 0.4, events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.3, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_PILOT}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: minValue, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.5, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.4, Confidence: 1.0}},
|
||||
{events.DriveModeMessage{DriveMode: events.DriveMode_USER}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}, events.ThrottleMessage{Throttle: 0.6, Confidence: 1.0}},
|
||||
}
|
||||
|
||||
go p.Start()
|
||||
defer func() { close(p.cancel) }()
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
p.maxThrottle = c.maxThrottle
|
||||
p.onDriveMode(nil, testtools.NewFakeMessageFromProtobuf(driveModeTopic, &c.driveMode))
|
||||
p.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, &c.rcThrottle))
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
p.onDriveMode(nil, testtools.NewFakeMessageFromProtobuf(driveModeTopic, &c.driveMode))
|
||||
p.onRCThrottle(nil, testtools.NewFakeMessageFromProtobuf(rcThrottleTopic, &c.rcThrottle))
|
||||
|
||||
for i := 3; i >= 0; i-- {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
var msg events.ThrottleMessage
|
||||
muEventsPublished.Lock()
|
||||
err := proto.Unmarshal(eventsPublished[throttleTopic], &msg)
|
||||
if err != nil {
|
||||
t.Errorf("unable to unmarshall response: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
muEventsPublished.Unlock()
|
||||
for i := 3; i >= 0; i-- {
|
||||
|
||||
if msg.GetThrottle() != c.expectedThrottle.GetThrottle() {
|
||||
t.Errorf("bad msg value for mode %v: %v, wants %v", c.driveMode, msg.GetThrottle(), c.expectedThrottle.GetThrottle())
|
||||
}
|
||||
if msg.GetConfidence() != 1. {
|
||||
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
var msg events.ThrottleMessage
|
||||
muEventsPublished.Lock()
|
||||
err := proto.Unmarshal(eventsPublished[throttleTopic], &msg)
|
||||
if err != nil {
|
||||
t.Errorf("unable to unmarshall response: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
})
|
||||
muEventsPublished.Unlock()
|
||||
|
||||
if msg.GetThrottle() != c.expectedThrottle.GetThrottle() {
|
||||
t.Errorf("bad msg value for mode %v: %v, wants %v", c.driveMode, msg.GetThrottle(), c.expectedThrottle.GetThrottle())
|
||||
}
|
||||
if msg.GetConfidence() != 1. {
|
||||
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user