Reject connections in a way driver's stations are happier about

Doing it this way allows tethering while FMS is running for robots which
aren't in the current match.
This commit is contained in:
Brian Silverman
2017-04-15 14:14:16 -07:00
parent 94c6929f2b
commit c486b0b0c2

View File

@@ -284,19 +284,20 @@ func ListenForDriverStations() {
teamId := int(packet[3])<<8 + int(packet[4])
// Check to see if the team is supposed to be on the field, and notify the DS accordingly.
assignedStation := mainArena.getAssignedAllianceStation(teamId)
if assignedStation == "" {
log.Printf("Rejecting connection from Team %d, who is not in the current match, soon.", teamId)
go func() {
// Wait a second and then close it so it doesn't chew up bandwidth constantly trying to reconnect.
time.Sleep(time.Second)
tcpConn.Close()
}()
continue
}
var assignmentPacket [5]byte
assignmentPacket[0] = 0 // Packet size
assignmentPacket[1] = 3 // Packet size
assignmentPacket[2] = 25 // Packet type
assignedStation := mainArena.getAssignedAllianceStation(teamId)
if assignedStation == "" {
log.Printf("Rejecting connection from Team %d, who is not in the current match.", teamId)
assignmentPacket[3] = 0
assignmentPacket[4] = 2
tcpConn.Write(assignmentPacket[:])
tcpConn.Close()
continue
}
log.Printf("Accepting connection from Team %d in station %s.", teamId, assignedStation)
assignmentPacket[3] = allianceStationPositionMap[assignedStation]
assignmentPacket[4] = 0