robocar-simulator/cmd/rc-simulator/rc-simultator.go

52 lines
1.2 KiB
Go
Raw Normal View History

2020-09-20 21:16:06 +00:00
package main
import (
"flag"
"github.com/cyrilix/robocar-base/cli"
"github.com/cyrilix/robocar-simulator/pkg/gateway"
log "github.com/sirupsen/logrus"
2020-09-20 21:16:06 +00:00
"os"
)
const DefaultClientId = "robocar-simulator"
2020-09-20 21:16:06 +00:00
func main() {
var mqttBroker, username, password, clientId, topicFrame string
2020-09-20 21:16:06 +00:00
var address string
var debug bool
2020-09-20 21:16:06 +00:00
mqttQos := cli.InitIntFlag("MQTT_QOS", 0)
_, mqttRetain := os.LookupEnv("MQTT_RETAIN")
cli.InitMqttFlags(DefaultClientId, &mqttBroker, &username, &password, &clientId, &mqttQos, &mqttRetain)
flag.StringVar(&topicFrame, "events-topic-frame", os.Getenv("MQTT_TOPIC"), "Mqtt topic to events gateway frames, use MQTT_TOPIC_FRAME if args not set")
2020-09-20 21:16:06 +00:00
flag.StringVar(&address, "simulator-address", "127.0.0.1:9091", "Simulator address")
flag.BoolVar(&debug, "debug", false, "Debug logs")
2020-09-20 21:16:06 +00:00
flag.Parse()
if len(os.Args) <= 1 {
flag.PrintDefaults()
os.Exit(1)
}
if debug {
log.SetLevel(log.DebugLevel)
}
2020-09-20 21:16:06 +00:00
client, err := cli.Connect(mqttBroker, username, password, clientId)
if err != nil {
log.Fatalf("unable to connect to events broker: %v", err)
2020-09-20 21:16:06 +00:00
}
defer client.Disconnect(10)
c := gateway.New(address)
2020-09-20 21:16:06 +00:00
defer c.Stop()
cli.HandleExit(c)
err = c.Start()
if err != nil {
log.Fatalf("unable to start service: %v", err)
}
}