Skip to content

Commit

Permalink
Configure access point via API instead of SSH and remove support for …
Browse files Browse the repository at this point in the history
…second AP.
  • Loading branch information
patfair committed Nov 29, 2023
1 parent f80283f commit a63f3da
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 777 deletions.
82 changes: 11 additions & 71 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type Arena struct {
Database *model.Database
EventSettings *model.EventSettings
accessPoint network.AccessPoint
accessPoint2 network.AccessPoint
networkSwitch *network.Switch
Plc plc.Plc
TbaClient *partner.TbaClient
Expand Down Expand Up @@ -148,71 +147,26 @@ func (arena *Arena) LoadSettings() error {
arena.EventSettings = settings

// Initialize the components that depend on settings.
var accessPoint1WifiStatuses, accessPoint2WifiStatuses [6]*network.TeamWifiStatus
if arena.EventSettings.Ap2TeamChannel == 0 {
accessPoint1WifiStatuses = [6]*network.TeamWifiStatus{
&arena.AllianceStations["R1"].WifiStatus,
&arena.AllianceStations["R2"].WifiStatus,
&arena.AllianceStations["R3"].WifiStatus,
&arena.AllianceStations["B1"].WifiStatus,
&arena.AllianceStations["B2"].WifiStatus,
&arena.AllianceStations["B3"].WifiStatus,
}
} else {
accessPoint1WifiStatuses = [6]*network.TeamWifiStatus{
&arena.AllianceStations["R1"].WifiStatus,
&arena.AllianceStations["R2"].WifiStatus,
&arena.AllianceStations["R3"].WifiStatus,
nil,
nil,
nil,
}
accessPoint2WifiStatuses = [6]*network.TeamWifiStatus{
nil,
nil,
nil,
&arena.AllianceStations["B1"].WifiStatus,
&arena.AllianceStations["B2"].WifiStatus,
&arena.AllianceStations["B3"].WifiStatus,
}
accessPointWifiStatuses := [6]*network.TeamWifiStatus{
&arena.AllianceStations["R1"].WifiStatus,
&arena.AllianceStations["R2"].WifiStatus,
&arena.AllianceStations["R3"].WifiStatus,
&arena.AllianceStations["B1"].WifiStatus,
&arena.AllianceStations["B2"].WifiStatus,
&arena.AllianceStations["B3"].WifiStatus,
}

arena.accessPoint.SetSettings(
1,
settings.ApType == "vivid",
settings.ApAddress,
settings.ApUsername,
settings.ApPassword,
settings.ApTeamChannel,
settings.NetworkSecurityEnabled,
accessPoint1WifiStatuses,
)
arena.accessPoint2.SetSettings(
2,
settings.ApType == "vivid",
settings.Ap2Address,
settings.Ap2Username,
settings.Ap2Password,
settings.Ap2TeamChannel,
settings.ApChannel,
settings.NetworkSecurityEnabled,
accessPoint2WifiStatuses,
accessPointWifiStatuses,
)
arena.networkSwitch = network.NewSwitch(settings.SwitchAddress, settings.SwitchPassword)
arena.Plc.SetAddress(settings.PlcAddress)
arena.TbaClient = partner.NewTbaClient(settings.TbaEventCode, settings.TbaSecretId, settings.TbaSecret)
arena.NexusClient = partner.NewNexusClient(settings.TbaEventCode)

if arena.EventSettings.NetworkSecurityEnabled && arena.MatchState == PreMatch {
if err = arena.accessPoint.ConfigureAdminSettings(); err != nil {
log.Printf("Failed to configure access point admin settings: %s", err.Error())
}
if arena.EventSettings.Ap2TeamChannel != 0 {
if err = arena.accessPoint2.ConfigureAdminSettings(); err != nil {
log.Printf("Failed to configure second access point admin settings: %s", err.Error())
}
}
}

game.MatchTiming.WarmupDurationSec = settings.WarmupDurationSec
game.MatchTiming.AutoDurationSec = settings.AutoDurationSec
game.MatchTiming.PauseDurationSec = settings.PauseDurationSec
Expand Down Expand Up @@ -688,7 +642,6 @@ func (arena *Arena) Run() {
go arena.listenForDriverStations()
go arena.listenForDsUdpPackets()
go arena.accessPoint.Run()
go arena.accessPoint2.Run()
go arena.Plc.Run()

for {
Expand Down Expand Up @@ -827,21 +780,8 @@ func (arena *Arena) setupNetwork(teams [6]*model.Team, isPreload bool) {
}

if arena.EventSettings.NetworkSecurityEnabled {
if arena.EventSettings.Ap2TeamChannel == 0 {
// Only one AP is being used.
if err := arena.accessPoint.ConfigureTeamWifi(teams); err != nil {
log.Printf("Failed to configure team WiFi: %s", err.Error())
}
} else {
// Two APs are being used. Configure the first for the red teams and the second for the blue teams.
if err := arena.accessPoint.ConfigureTeamWifi([6]*model.Team{teams[0], teams[1], teams[2], nil, nil,
nil}); err != nil {
log.Printf("Failed to configure red alliance WiFi: %s", err.Error())
}
if err := arena.accessPoint2.ConfigureTeamWifi([6]*model.Team{nil, nil, nil, teams[3], teams[4],
teams[5]}); err != nil {
log.Printf("Failed to configure blue alliance WiFi: %s", err.Error())
}
if err := arena.accessPoint.ConfigureTeamWifi(teams); err != nil {
log.Printf("Failed to configure team WiFi: %s", err.Error())
}
go func() {
if err := arena.networkSwitch.ConfigureTeamEthernet(teams); err != nil {
Expand Down
12 changes: 2 additions & 10 deletions model/event_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ type EventSettings struct {
TbaSecret string
NexusEnabled bool
NetworkSecurityEnabled bool
ApType string
ApAddress string
ApUsername string
ApPassword string
ApTeamChannel int
Ap2Address string
Ap2Username string
Ap2Password string
Ap2TeamChannel int
ApChannel int
SwitchAddress string
SwitchPassword string
PlcAddress string
Expand Down Expand Up @@ -68,9 +62,7 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
SelectionRound2Order: "L",
SelectionRound3Order: "",
TbaDownloadEnabled: true,
ApType: "linksys",
ApTeamChannel: 157,
Ap2TeamChannel: 0,
ApChannel: 36,
WarmupDurationSec: game.MatchTiming.WarmupDurationSec,
AutoDurationSec: game.MatchTiming.AutoDurationSec,
PauseDurationSec: game.MatchTiming.PauseDurationSec,
Expand Down
3 changes: 1 addition & 2 deletions model/event_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func TestEventSettingsReadWrite(t *testing.T) {
SelectionRound2Order: "L",
SelectionRound3Order: "",
TbaDownloadEnabled: true,
ApType: "linksys",
ApTeamChannel: 157,
ApChannel: 36,
WarmupDurationSec: 0,
AutoDurationSec: 15,
PauseDurationSec: 3,
Expand Down
Loading

0 comments on commit a63f3da

Please sign in to comment.