[driveMode] Adjust throttle on driveMode events

This commit is contained in:
2019-12-27 17:42:10 +01:00
parent 83056fb0f1
commit c1286d2246
8 changed files with 184 additions and 48 deletions

View File

@ -3,6 +3,7 @@ package cli
import (
"flag"
"fmt"
"github.com/cyrilix/robocar-base/service"
MQTT "github.com/eclipse/paho.mqtt.golang"
"log"
"os"
@ -49,12 +50,7 @@ func SetFloat64DefaultValueFromEnv(value *float64, key string, defaultValue floa
return nil
}
type Part interface {
Start() error
Stop()
}
func HandleExit(p Part) {
func HandleExit(p service.Part) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Kill, os.Interrupt, syscall.SIGTERM)

33
vendor/github.com/cyrilix/robocar-base/service/part.go generated vendored Normal file
View File

@ -0,0 +1,33 @@
package service
import (
"fmt"
mqtt "github.com/eclipse/paho.mqtt.golang"
"log"
)
func StopService(name string, client mqtt.Client, topics ...string) {
log.Printf("Stop %s service", name)
token := client.Unsubscribe(topics...)
token.Wait()
if token.Error() != nil {
log.Printf("unable to unsubscribe service: %v", token.Error())
}
client.Disconnect(50)
}
func RegisterCallback(client mqtt.Client, topic string, callback mqtt.MessageHandler) error {
log.Printf("Register callback on topic %v", topic)
token := client.Subscribe(topic, 0, callback)
token.Wait()
if token.Error() != nil {
return fmt.Errorf("unable to register callback on topic %s: %v", topic, token.Error())
}
return nil
}
type Part interface {
Start() error
Stop()
}

3
vendor/modules.txt vendored
View File

@ -1,6 +1,7 @@
# github.com/cyrilix/robocar-base v0.0.0-20191227142243-e35d6f13814e
# github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2
github.com/cyrilix/robocar-base/cli
github.com/cyrilix/robocar-base/mqttdevice
github.com/cyrilix/robocar-base/service
github.com/cyrilix/robocar-base/testtools
github.com/cyrilix/robocar-base/types
# github.com/eclipse/paho.mqtt.golang v1.2.0