Skip to content

Commit 8b2af68

Browse files
committed
feature: Allow sending API Input via CI interface instead of WebSocket
1 parent 7416fac commit 8b2af68

File tree

4 files changed

+62
-29
lines changed

4 files changed

+62
-29
lines changed

internal/app/ci/ci.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ci
22

33
import (
4+
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/engine"
45
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/sslconn"
56
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
67
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/tracker"
@@ -13,19 +14,23 @@ import (
1314
type Handler func(time.Time, *tracker.TrackerWrapperPacket) *state.Referee
1415

1516
type Server struct {
16-
address string
17-
listener net.Listener
18-
conn net.Conn
19-
latestTime time.Time
20-
tickChan chan time.Time
21-
mutex sync.Mutex
22-
TrackerConsumer func(*tracker.TrackerWrapperPacket)
17+
address string
18+
listener net.Listener
19+
conn net.Conn
20+
latestTime time.Time
21+
tickChan chan time.Time
22+
mutex sync.Mutex
23+
gcEngine *engine.Engine
2324
}
2425

2526
func NewServer(address string) *Server {
2627
return &Server{address: address, tickChan: make(chan time.Time, 1)}
2728
}
2829

30+
func (s *Server) SetEngine(engine *engine.Engine) {
31+
s.gcEngine = engine
32+
}
33+
2934
func (s *Server) Start() {
3035
go s.listen(s.address)
3136
}
@@ -76,7 +81,19 @@ func (s *Server) serve(conn net.Conn) {
7681
}
7782

7883
if input.TrackerPacket != nil {
79-
s.TrackerConsumer(input.TrackerPacket)
84+
s.gcEngine.ProcessTrackerFrame(input.TrackerPacket)
85+
}
86+
87+
for _, in := range input.ApiInputs {
88+
if in.Change != nil {
89+
s.gcEngine.Enqueue(in.Change)
90+
}
91+
if in.ResetMatch != nil && *in.ResetMatch {
92+
s.gcEngine.ResetMatch()
93+
}
94+
if in.ConfigDelta != nil {
95+
s.gcEngine.UpdateConfig(in.ConfigDelta)
96+
}
8097
}
8198

8299
if input.Timestamp != nil {

internal/app/ci/ssl_gc_ci.pb.go

Lines changed: 33 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/app/gc/gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *GameController) Start() {
7272
c.messageGenerator.MessageConsumer = c.ciServer.SendMessage
7373
c.gcEngine.SetTimeProvider(c.ciServer.Time)
7474
c.gcEngine.SetTickChanProvider(c.ciServer.TickChanProvider)
75-
c.ciServer.TrackerConsumer = c.gcEngine.ProcessTrackerFrame
75+
c.ciServer.SetEngine(c.gcEngine)
7676
c.ciServer.Start()
7777
}
7878

proto/ssl_gc_ci.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ syntax = "proto2";
33
option go_package = "github.com/RoboCup-SSL/ssl-game-controller/internal/app/ci";
44

55
import "ssl_vision_wrapper_tracked.proto";
6+
import "ssl_gc_api.proto";
67
import "ssl_gc_referee_message.proto";
78

89
// The input format to the GC
@@ -11,6 +12,8 @@ message CiInput {
1112
optional int64 timestamp = 1;
1213
// New tracker packet with ball and robot data
1314
optional TrackerWrapperPacket tracker_packet = 2;
15+
// (UI) API input
16+
repeated Input api_inputs = 3;
1417
}
1518

1619
// The output format of the GC response

0 commit comments

Comments
 (0)