2019-12-29 17:39:08 +00:00
package main
import (
"flag"
"github.com/cyrilix/robocar-base/cli"
"github.com/cyrilix/robocar-display/part"
2020-01-19 16:15:05 +00:00
"github.com/cyrilix/robocar-display/video"
2019-12-29 17:39:08 +00:00
"log"
"os"
)
const (
2019-12-31 16:22:28 +00:00
DefaultClientId = "robocar-display"
2019-12-29 17:39:08 +00:00
)
func main ( ) {
var mqttBroker , username , password , clientId string
2020-01-19 16:15:05 +00:00
var framePath string
var fps int
2020-01-04 14:01:10 +00:00
var frameTopic , objectsTopic , roadTopic string
var withObjects , withRoad bool
2019-12-29 17:39:08 +00:00
mqttQos := cli . InitIntFlag ( "MQTT_QOS" , 0 )
_ , mqttRetain := os . LookupEnv ( "MQTT_RETAIN" )
cli . InitMqttFlags ( DefaultClientId , & mqttBroker , & username , & password , & clientId , & mqttQos , & mqttRetain )
flag . StringVar ( & frameTopic , "mqtt-topic-frame" , os . Getenv ( "MQTT_TOPIC_FRAME" ) , "Mqtt topic that contains frame to display, use MQTT_TOPIC_FRAME if args not set" )
2020-01-19 16:15:05 +00:00
flag . StringVar ( & framePath , "frame-path" , "" , "Directory path where to read jpeg frame to inject in frame topic" )
flag . IntVar ( & fps , "frame-per-second" , 25 , "Video frame per second of frame to publish" )
2020-01-04 14:01:10 +00:00
2019-12-31 16:22:28 +00:00
flag . StringVar ( & objectsTopic , "mqtt-topic-objects" , os . Getenv ( "MQTT_TOPIC_OBJECTS" ) , "Mqtt topic that contains detected objects, use MQTT_TOPIC_OBJECTS if args not set" )
flag . BoolVar ( & withObjects , "with-objects" , false , "Display detected objects" )
2019-12-29 17:39:08 +00:00
2020-01-04 14:01:10 +00:00
flag . StringVar ( & roadTopic , "mqtt-topic-road" , os . Getenv ( "MQTT_TOPIC_ROAD" ) , "Mqtt topic that contains road description, use MQTT_TOPIC_ROAD if args not set" )
flag . BoolVar ( & withRoad , "with-road" , false , "Display detected road" )
2019-12-29 17:39:08 +00:00
flag . Parse ( )
if len ( os . Args ) <= 1 {
flag . PrintDefaults ( )
os . Exit ( 1 )
}
client , err := cli . Connect ( mqttBroker , username , password , clientId )
if err != nil {
log . Fatalf ( "unable to connect to mqtt bus: %v" , err )
}
defer client . Disconnect ( 50 )
2020-01-19 16:15:05 +00:00
if framePath != "" {
camera , err := video . NewCameraFake ( client , frameTopic , framePath , fps )
if err != nil {
log . Fatalf ( "unable to load fake camera: %v" , err )
}
if err = camera . Start ( ) ; err != nil {
log . Fatalf ( "unable to start fake camera: %v" , err )
}
defer camera . Stop ( )
}
2020-01-04 14:01:10 +00:00
p := part . NewPart ( client , frameTopic ,
objectsTopic , roadTopic ,
withObjects , withRoad )
2019-12-29 17:39:08 +00:00
defer p . Stop ( )
cli . HandleExit ( p )
err = p . Start ( )
if err != nil {
log . Fatalf ( "unable to start service: %v" , err )
}
}