2020-09-20 21:16:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"github.com/cyrilix/robocar-base/cli"
|
2021-01-15 10:12:21 +00:00
|
|
|
"github.com/cyrilix/robocar-simulator/pkg/gateway"
|
|
|
|
log"github.com/sirupsen/logrus"
|
2020-09-20 21:16:06 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2021-01-15 10:12:21 +00:00
|
|
|
const DefaultClientId = "robocar-simulator"
|
2020-09-20 21:16:06 +00:00
|
|
|
|
|
|
|
func main() {
|
2021-01-15 10:12:21 +00:00
|
|
|
var mqttBroker, username, password, clientId, topicFrame string
|
2020-09-20 21:16:06 +00:00
|
|
|
var address string
|
2021-01-15 10:12:21 +00:00
|
|
|
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)
|
|
|
|
|
2021-01-15 10:12:21 +00:00
|
|
|
flag.StringVar(&topicFrame, "mqtt-topic-frame", os.Getenv("MQTT_TOPIC"), "Mqtt topic to publish 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")
|
2021-01-15 10:12:21 +00:00
|
|
|
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)
|
|
|
|
}
|
2021-01-15 10:12:21 +00:00
|
|
|
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 mqtt broker: %v", err)
|
|
|
|
}
|
|
|
|
defer client.Disconnect(10)
|
|
|
|
|
|
|
|
|
2021-01-15 10:12:21 +00:00
|
|
|
c := gateway.New(gateway.NewMqttPublisher(client, topicFrame, "", ""), 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)
|
|
|
|
}
|
|
|
|
}
|