Skip to content

Commit eaf97be

Browse files
committed
Bugfix: Correctly convert stage time for referee message
1 parent 2857cba commit eaf97be

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/app/publish/messagegenerator.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/engine"
55
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
66
"github.com/golang/protobuf/ptypes"
7+
"github.com/golang/protobuf/ptypes/duration"
78
"time"
89
)
910

@@ -99,10 +100,10 @@ func (g *MessageGenerator) StateToRefereeMessage(matchState *state.State) (r *st
99100
*r.CommandTimestamp = g.commandTimestamp
100101
*r.PacketTimestamp = uint64(time.Now().UnixNano() / 1000)
101102
*r.Stage = *matchState.Stage
102-
*r.StageTimeLeft = matchState.StageTimeLeft.Nanos / 1000
103+
*r.StageTimeLeft = microseconds(*matchState.StageTimeLeft)
103104
*r.BlueTeamOnPositiveHalf = *matchState.TeamInfo(state.Team_BLUE).OnPositiveHalf
104105
r.NextCommand = mapCommand(matchState.NextCommand)
105-
*r.CurrentActionTimeRemaining = int32(matchState.CurrentActionTimeRemaining.Seconds)*1_000_000 + matchState.CurrentActionTimeRemaining.Nanos/1000
106+
*r.CurrentActionTimeRemaining = microseconds(*matchState.CurrentActionTimeRemaining)
106107

107108
updateTeam(r.Yellow, matchState.TeamInfo(state.Team_YELLOW))
108109
updateTeam(r.Blue, matchState.TeamInfo(state.Team_BLUE))
@@ -173,3 +174,7 @@ func unsigned(v int) uint32 {
173174
}
174175
return uint32(v)
175176
}
177+
178+
func microseconds(dur duration.Duration) int32 {
179+
return int32(dur.Seconds)*1_000_000 + dur.Nanos/1000
180+
}

0 commit comments

Comments
 (0)