Skip to content

Commit

Permalink
Add a fallback for when robot specs were not found
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Jun 21, 2021
1 parent 92b91d2 commit 8811e71
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions internal/simctl/handler_robot_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,31 @@ func (r *RobotSpecHandler) handleRobotSpecs() {
func (r *RobotSpecHandler) updateTeam(team referee.Team, teamName string) {
if r.appliedTeams[team] != teamName {
if spec, ok := r.teamRobotSpecs.Teams[teamName]; ok {
var protoSpecs []*RobotSpecs
for id := 0; id < 16; id++ {
protoSpec := mapRobotSpec(spec)
protoSpec.Id = new(referee.RobotId)
protoSpec.Id.Id = new(uint32)
protoSpec.Id.Team = new(referee.Team)
*protoSpec.Id.Team = team
*protoSpec.Id.Id = uint32(id)
protoSpecs = append(protoSpecs, protoSpec)
}
r.sendConfig(protoSpecs)
r.appliedTeams[team] = teamName
r.applySpecs(team, teamName, spec)
} else if spec, ok := r.teamRobotSpecs.Teams["Unknown"]; ok {
log.Printf("Team %v not found, using fallback", teamName)
r.applySpecs(team, teamName, spec)
} else {
log.Printf("Team %v not found and also no fallback found", teamName)
}
}
}

func (r *RobotSpecHandler) applySpecs(team referee.Team, teamName string, spec RobotSpec) {
var protoSpecs []*RobotSpecs
for id := 0; id < 16; id++ {
protoSpec := mapRobotSpec(spec)
protoSpec.Id = new(referee.RobotId)
protoSpec.Id.Id = new(uint32)
protoSpec.Id.Team = new(referee.Team)
*protoSpec.Id.Team = team
*protoSpec.Id.Id = uint32(id)
protoSpecs = append(protoSpecs, protoSpec)
}
r.sendConfig(protoSpecs)
r.appliedTeams[team] = teamName
}

func (r *RobotSpecHandler) sendConfig(robotSpec []*RobotSpecs) {
log.Printf("Sending robot spec %v", robotSpec)

Expand Down

0 comments on commit 8811e71

Please sign in to comment.