Skip to content

Commit

Permalink
Revert "Remove 2nd AP, fix AP channel setting, fix error with team wi…
Browse files Browse the repository at this point in the history
…fi status"

This reverts commit 7310a6d.
  • Loading branch information
jschenke488 committed Oct 24, 2024
1 parent d0ec0c2 commit 62a29a1
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 40 deletions.
60 changes: 36 additions & 24 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Arena struct {
Database *model.Database
EventSettings *model.EventSettings
accessPoint network.AccessPoint
accessPoint2 network.AccessPoint
networkSwitch *network.Switch
dnsMasq *network.DnsMasq
Plc plc.Plc
Expand Down Expand Up @@ -84,13 +85,12 @@ type Arena struct {
}

type AllianceStation struct {
DsConn *DriverStationConnection
Ethernet bool
Astop bool
Estop bool
Bypass bool
Team *model.Team
WifiStatus network.TeamWifiStatus
DsConn *DriverStationConnection
Ethernet bool
Astop bool
Estop bool
Bypass bool
Team *model.Team
}

// Creates the arena and sets it to its initial state.
Expand Down Expand Up @@ -148,26 +148,24 @@ func (arena *Arena) LoadSettings() error {
arena.EventSettings = settings

// Initialize the components that depend on settings.
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(
settings.ApAddress,
settings.ApPassword,
settings.ApChannel,
settings.NetworkSecurityEnabled,
accessPointWifiStatuses,
)
arena.accessPoint.SetSettings(settings.ApAddress, settings.ApUsername, settings.ApPassword,
settings.ApTeamChannel, settings.ApAdminChannel, settings.ApAdminWpaKey, settings.NetworkSecurityEnabled)

Check failure on line 152 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

too many arguments in call to arena.accessPoint.SetSettings

Check failure on line 152 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

too many arguments in call to arena.accessPoint.SetSettings
arena.accessPoint2.SetSettings(settings.Ap2Address, settings.Ap2Username, settings.Ap2Password,
settings.Ap2TeamChannel, 0, "", settings.NetworkSecurityEnabled)

Check failure on line 154 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

too many arguments in call to arena.accessPoint2.SetSettings

Check failure on line 154 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

too many arguments in call to arena.accessPoint2.SetSettings
arena.networkSwitch = network.NewSwitch(settings.SwitchAddress, settings.SwitchPassword)
arena.dnsMasq = network.NewDnsMasq()
arena.Plc.SetAddress(settings.PlcAddress)
arena.TbaClient = partner.NewTbaClient(settings.TbaEventCode, settings.TbaSecretId, settings.TbaSecret)

if arena.EventSettings.NetworkSecurityEnabled && arena.MatchState == PreMatch {
if err = arena.accessPoint.ConfigureAdminWifi(); err != nil {

Check failure on line 161 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

arena.accessPoint.ConfigureAdminWifi undefined (type network.AccessPoint has no field or method ConfigureAdminWifi)

Check failure on line 161 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

arena.accessPoint.ConfigureAdminWifi undefined (type network.AccessPoint has no field or method ConfigureAdminWifi)
log.Printf("Failed to configure admin WiFi: %s", err.Error())
}
if err = arena.accessPoint2.ConfigureAdminWifi(); err != nil {

Check failure on line 164 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

arena.accessPoint2.ConfigureAdminWifi undefined (type network.AccessPoint has no field or method ConfigureAdminWifi)

Check failure on line 164 in field/arena.go

View workflow job for this annotation

GitHub Actions / test

arena.accessPoint2.ConfigureAdminWifi undefined (type network.AccessPoint has no field or method ConfigureAdminWifi)
log.Printf("Failed to configure admin WiFi: %s", err.Error())
}
}

game.MatchTiming.WarmupDurationSec = settings.WarmupDurationSec
game.MatchTiming.AutoDurationSec = settings.AutoDurationSec
game.MatchTiming.PauseDurationSec = settings.PauseDurationSec
Expand Down Expand Up @@ -572,6 +570,7 @@ 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 @@ -682,8 +681,21 @@ func (arena *Arena) preLoadNextMatch() {
// Asynchronously reconfigures the networking hardware for the new set of teams.
func (arena *Arena) setupNetwork(teams [6]*model.Team) {
if arena.EventSettings.NetworkSecurityEnabled {
if err := arena.accessPoint.ConfigureTeamWifi(teams); err != nil {
log.Printf("Failed to configure team WiFi: %s", err.Error())
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())
}
}
go func() {
if err := arena.networkSwitch.ConfigureTeamEthernet(teams); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions field/arena_notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ func (arena *Arena) generateAllianceStationDisplayModeMessage() interface{} {

func (arena *Arena) generateArenaStatusMessage() interface{} {
// Convert AP team wifi network status array to a map by station for ease of client use.
teamWifiStatuses := make(map[string]*network.TeamWifiStatus)
teamWifiStatuses := make(map[string]network.TeamWifiStatus)
for i, station := range []string{"R1", "R2", "R3", "B1", "B2", "B3"} {
teamWifiStatuses[station] = arena.accessPoint.TeamWifiStatuses[i]
if arena.EventSettings.Ap2TeamChannel == 0 || i < 3 {
teamWifiStatuses[station] = arena.accessPoint.TeamWifiStatuses[i]

Check failure on line 82 in field/arena_notifiers.go

View workflow job for this annotation

GitHub Actions / test

cannot use arena.accessPoint.TeamWifiStatuses[i] (variable of type *network.TeamWifiStatus) as network.TeamWifiStatus value in assignment

Check failure on line 82 in field/arena_notifiers.go

View workflow job for this annotation

GitHub Actions / test

cannot use arena.accessPoint.TeamWifiStatuses[i] (variable of type *network.TeamWifiStatus) as network.TeamWifiStatus value in assignment
} else {
teamWifiStatuses[station] = arena.accessPoint2.TeamWifiStatuses[i]

Check failure on line 84 in field/arena_notifiers.go

View workflow job for this annotation

GitHub Actions / test

cannot use arena.accessPoint2.TeamWifiStatuses[i] (variable of type *network.TeamWifiStatus) as network.TeamWifiStatus value in assignment

Check failure on line 84 in field/arena_notifiers.go

View workflow job for this annotation

GitHub Actions / test

cannot use arena.accessPoint2.TeamWifiStatuses[i] (variable of type *network.TeamWifiStatus) as network.TeamWifiStatus value in assignment
}
}

startMatchErr := arena.checkCanStartMatch()
Expand All @@ -89,7 +93,7 @@ func (arena *Arena) generateArenaStatusMessage() interface{} {
return &struct {
MatchId int
AllianceStations map[string]*AllianceStation
TeamWifiStatuses map[string]*network.TeamWifiStatus
TeamWifiStatuses map[string]network.TeamWifiStatus
MatchState
CanStartMatch bool
CanStartMatchReason string
Expand Down
13 changes: 11 additions & 2 deletions model/event_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ type EventSettings struct {
ApAddress string
ApUsername string
ApPassword string
ApChannel int
ApTeamChannel int
ApAdminChannel int
ApAdminWpaKey string
Ap2Address string
Ap2Username string
Ap2Password string
Ap2TeamChannel int
SwitchAddress string
SwitchPassword string
PlcAddress string
Expand Down Expand Up @@ -52,7 +58,10 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
SelectionRound2Order: "L",
SelectionRound3Order: "",
TBADownloadEnabled: true,
ApChannel: 36,
ApTeamChannel: 157,
ApAdminChannel: 0,
ApAdminWpaKey: "1234Five",
Ap2TeamChannel: 0,
WarmupDurationSec: game.MatchTiming.WarmupDurationSec,
AutoDurationSec: game.MatchTiming.AutoDurationSec,
PauseDurationSec: game.MatchTiming.PauseDurationSec,
Expand Down
73 changes: 63 additions & 10 deletions templates/setup_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,37 @@
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">AP Channel</label>
<label class="col-lg-5 control-label">AP Team Channel (5GHz)</label>
<div class="col-lg-7">
<select class="form-control" name="apChannel" value="{{.ApChannel}}">
<option{{if eq .ApChannel 36}} selected{{end}}>36</option>
<option{{if eq .ApChannel 40}} selected{{end}}>40</option>
<option{{if eq .ApChannel 44}} selected{{end}}>44</option>
<option{{if eq .ApChannel 48}} selected{{end}}>48</option>
<option{{if eq .ApChannel 149}} selected{{end}}>149</option>
<option{{if eq .ApChannel 153}} selected{{end}}>153</option>
<option{{if eq .ApChannel 157}} selected{{end}}>157</option>
<option{{if eq .ApChannel 161}} selected{{end}}>161</option>
<select class="form-control" name="apTeamChannel" value="{{.ApTeamChannel}}">
<option{{if eq .ApTeamChannel 36}} selected{{end}}>36</option>
<option{{if eq .ApTeamChannel 40}} selected{{end}}>40</option>
<option{{if eq .ApTeamChannel 44}} selected{{end}}>44</option>
<option{{if eq .ApTeamChannel 48}} selected{{end}}>48</option>
<option{{if eq .ApTeamChannel 149}} selected{{end}}>149</option>
<option{{if eq .ApTeamChannel 153}} selected{{end}}>153</option>
<option{{if eq .ApTeamChannel 157}} selected{{end}}>157</option>
<option{{if eq .ApTeamChannel 161}} selected{{end}}>161</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">AP Admin Channel (2.4GHz)</label>
<div class="col-lg-7">
<select class="form-control" name="apAdminChannel" value="{{.ApAdminChannel}}">
<option{{if eq .ApAdminChannel 0}} selected{{end}}>Disabled</option>
<option{{if eq .ApAdminChannel 1}} selected{{end}}>1</option>
<option{{if eq .ApAdminChannel 6}} selected{{end}}>6</option>
<option{{if eq .ApAdminChannel 11}} selected{{end}}>11</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">AP Admin WPA Key</label>
<div class="col-lg-7">
<input type="password" class="form-control" name="apAdminWpaKey" value="{{.ApAdminWpaKey}}">
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Switch Address</label>
<div class="col-lg-7">
Expand All @@ -198,6 +215,42 @@
<input type="password" class="form-control" name="switchPassword" value="{{.SwitchPassword}}">
</div>
</div>
<p>If you have a second access point available and want to use one for each alliance to increase available
bandwidth, configure the second one below.</p>
<div class="form-group">
<label class="col-lg-5 control-label">Second AP Address</label>
<div class="col-lg-7">
<input type="text" class="form-control" name="ap2Address" value="{{.Ap2Address}}">
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Second AP Username</label>
<div class="col-lg-7">
<input type="text" class="form-control" name="ap2Username" value="{{.Ap2Username}}">
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Second AP Password</label>
<div class="col-lg-7">
<input type="password" class="form-control" name="ap2Password" value="{{.Ap2Password}}">
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Second AP Team Channel (5GHz)</label>
<div class="col-lg-7">
<select class="form-control" name="ap2TeamChannel" value="{{.Ap2TeamChannel}}">
<option{{if eq .Ap2TeamChannel 0}} selected{{end}}>Disabled</option>
<option{{if eq .Ap2TeamChannel 36}} selected{{end}}>36</option>
<option{{if eq .Ap2TeamChannel 40}} selected{{end}}>40</option>
<option{{if eq .Ap2TeamChannel 44}} selected{{end}}>44</option>
<option{{if eq .Ap2TeamChannel 48}} selected{{end}}>48</option>
<option{{if eq .Ap2TeamChannel 149}} selected{{end}}>149</option>
<option{{if eq .Ap2TeamChannel 153}} selected{{end}}>153</option>
<option{{if eq .Ap2TeamChannel 157}} selected{{end}}>157</option>
<option{{if eq .Ap2TeamChannel 161}} selected{{end}}>161</option>
</select>
</div>
</div>
</fieldset>
<fieldset>
<legend>PLC</legend>
Expand Down
13 changes: 12 additions & 1 deletion web/setup_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
eventSettings.ApAddress = r.PostFormValue("apAddress")
eventSettings.ApUsername = r.PostFormValue("apUsername")
eventSettings.ApPassword = r.PostFormValue("apPassword")
eventSettings.ApChannel, _ = strconv.Atoi(r.PostFormValue("apChannel"))
eventSettings.ApTeamChannel, _ = strconv.Atoi(r.PostFormValue("apTeamChannel"))
eventSettings.ApAdminChannel, _ = strconv.Atoi(r.PostFormValue("apAdminChannel"))
eventSettings.ApAdminWpaKey = r.PostFormValue("apAdminWpaKey")
eventSettings.Ap2Address = r.PostFormValue("ap2Address")
eventSettings.Ap2Username = r.PostFormValue("ap2Username")
eventSettings.Ap2Password = r.PostFormValue("ap2Password")
eventSettings.Ap2TeamChannel, _ = strconv.Atoi(r.PostFormValue("ap2TeamChannel"))
eventSettings.SwitchAddress = r.PostFormValue("switchAddress")
eventSettings.SwitchPassword = r.PostFormValue("switchPassword")
eventSettings.PlcAddress = r.PostFormValue("plcAddress")
Expand All @@ -76,6 +82,11 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
eventSettings.TeleopDurationSec, _ = strconv.Atoi(r.PostFormValue("teleopDurationSec"))
eventSettings.WarningRemainingDurationSec, _ = strconv.Atoi(r.PostFormValue("warningRemainingDurationSec"))

if eventSettings.Ap2TeamChannel != 0 && eventSettings.Ap2TeamChannel == eventSettings.ApTeamChannel {
web.renderSettings(w, r, "Cannot use same channel for both access points.")
return
}

err := web.arena.Database.UpdateEventSettings(eventSettings)
if err != nil {
handleWebErr(w, err)
Expand Down

0 comments on commit 62a29a1

Please sign in to comment.