Skip to content

Commit fb76685

Browse files
committed
Add additional cmd parameters
1 parent 52f263d commit fb76685

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

cmd/ssl-game-controller/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ package main
22

33
import (
44
"flag"
5+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/config"
56
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/controller"
67
"github.com/gobuffalo/packr"
78
"log"
89
"net/http"
910
)
1011

1112
var address = flag.String("address", "localhost:8081", "The address on which the UI and API is served")
13+
var visionAddress = flag.String("visionAddress", "", "The address (ip+port) from which vision packages are received")
14+
var publishAddress = flag.String("publishAddress", "", "The address (ip+port) to which referee command should be sent")
15+
var timeAcquisitionMode = flag.String("timeAcquisitionMode", "", "The time acquisitionMode to use (system, ci, vision)")
16+
17+
const configFileName = "config/ssl-game-controller.yaml"
1218

1319
func main() {
1420
flag.Parse()
@@ -23,7 +29,19 @@ func main() {
2329
}
2430

2531
func setupGameController() {
26-
gameController := controller.NewGameController()
32+
cfg := config.LoadConfig(configFileName)
33+
34+
if visionAddress != nil && *visionAddress != "" {
35+
cfg.Network.VisionAddress = *visionAddress
36+
}
37+
if publishAddress != nil && *publishAddress != "" {
38+
cfg.Network.PublishAddress = *publishAddress
39+
}
40+
if timeAcquisitionMode != nil && *timeAcquisitionMode != "" {
41+
cfg.TimeAcquisitionMode = config.TimeAcquisitionMode(*timeAcquisitionMode)
42+
}
43+
44+
gameController := controller.NewGameController(cfg)
2745
gameController.Run()
2846
// serve the bidirectional web socket
2947
http.HandleFunc("/api/control", gameController.ApiServer.WsHandler)

internal/app/config/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/pkg/errors"
55
"gopkg.in/yaml.v2"
66
"io/ioutil"
7+
"log"
78
"os"
89
"path/filepath"
910
"time"
@@ -196,3 +197,18 @@ func DefaultControllerConfig() (c Controller) {
196197

197198
return
198199
}
200+
201+
// loadConfig loads the controller config
202+
func LoadConfig(configFileName string) Controller {
203+
cfg, err := LoadControllerConfig(configFileName)
204+
if err != nil {
205+
log.Printf("Could not load config: %v", err)
206+
err = cfg.WriteTo(configFileName)
207+
if err != nil {
208+
log.Printf("Failed to write a default config file to %v: %v", configFileName, err)
209+
} else {
210+
log.Println("New default config has been written to ", configFileName)
211+
}
212+
}
213+
return cfg
214+
}

internal/app/controller/controller.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"time"
1414
)
1515

16-
const configFileName = "config/ssl-game-controller.yaml"
17-
1816
// GameController controls a game
1917
type GameController struct {
2018
Config config.Controller
@@ -33,11 +31,11 @@ type GameController struct {
3331
VisionReceiver *vision.Receiver
3432
}
3533

36-
// NewGameController creates a new RefBox
37-
func NewGameController() (c *GameController) {
34+
// NewGameController creates a new GameController
35+
func NewGameController(cfg config.Controller) (c *GameController) {
3836

3937
c = new(GameController)
40-
c.Config = loadConfig()
38+
c.Config = cfg
4139
c.Publisher = NewPublisher(c.Config.Network.PublishAddress)
4240
c.ApiServer = ApiServer{}
4341
c.ApiServer.Consumer = c
@@ -218,18 +216,3 @@ func (c *GameController) OnNewEvent(event Event) {
218216
c.publish()
219217
}
220218
}
221-
222-
// loadConfig loads the controller config
223-
func loadConfig() config.Controller {
224-
cfg, err := config.LoadControllerConfig(configFileName)
225-
if err != nil {
226-
log.Printf("Could not load config: %v", err)
227-
err = cfg.WriteTo(configFileName)
228-
if err != nil {
229-
log.Printf("Failed to write a default config file to %v: %v", configFileName, err)
230-
} else {
231-
log.Println("New default config has been written to ", configFileName)
232-
}
233-
}
234-
return cfg
235-
}

0 commit comments

Comments
 (0)