mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-10 06:06:47 -04:00
Enable using one access point for each alliance.
This commit is contained in:
@@ -17,6 +17,10 @@ CREATE TABLE event_settings (
|
||||
apteamchannel int,
|
||||
apadminchannel int,
|
||||
apadminwpakey VARCHAR(255),
|
||||
ap2address VARCHAR(255),
|
||||
ap2username VARCHAR(255),
|
||||
ap2password VARCHAR(255),
|
||||
ap2teamchannel int,
|
||||
switchaddress VARCHAR(255),
|
||||
switchpassword VARCHAR(255),
|
||||
plcaddress VARCHAR(255),
|
||||
|
||||
@@ -43,6 +43,7 @@ type Arena struct {
|
||||
Database *model.Database
|
||||
EventSettings *model.EventSettings
|
||||
accessPoint network.AccessPoint
|
||||
accessPoint2 network.AccessPoint
|
||||
networkSwitch *network.Switch
|
||||
Plc plc.Plc
|
||||
TbaClient *partner.TbaClient
|
||||
@@ -134,6 +135,8 @@ func (arena *Arena) LoadSettings() error {
|
||||
// Initialize the components that depend on settings.
|
||||
arena.accessPoint.SetSettings(settings.ApAddress, settings.ApUsername, settings.ApPassword,
|
||||
settings.ApTeamChannel, settings.ApAdminChannel, settings.ApAdminWpaKey, settings.NetworkSecurityEnabled)
|
||||
arena.accessPoint2.SetSettings(settings.Ap2Address, settings.Ap2Username, settings.Ap2Password,
|
||||
settings.Ap2TeamChannel, 0, "", settings.NetworkSecurityEnabled)
|
||||
arena.networkSwitch = network.NewSwitch(settings.SwitchAddress, settings.SwitchPassword)
|
||||
arena.Plc.SetAddress(settings.PlcAddress)
|
||||
arena.TbaClient = partner.NewTbaClient(settings.TbaEventCode, settings.TbaSecretId, settings.TbaSecret)
|
||||
@@ -142,6 +145,9 @@ func (arena *Arena) LoadSettings() error {
|
||||
if err = arena.accessPoint.ConfigureAdminWifi(); err != nil {
|
||||
log.Printf("Failed to configure admin WiFi: %s", err.Error())
|
||||
}
|
||||
if err = arena.accessPoint2.ConfigureAdminWifi(); err != nil {
|
||||
log.Printf("Failed to configure admin WiFi: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
game.HabDockingThreshold = settings.HabDockingThreshold
|
||||
@@ -484,6 +490,7 @@ func (arena *Arena) Run() {
|
||||
go arena.listenForDriverStations()
|
||||
go arena.listenForDsUdpPackets()
|
||||
go arena.accessPoint.Run()
|
||||
go arena.accessPoint2.Run()
|
||||
go arena.Plc.Run()
|
||||
|
||||
for {
|
||||
@@ -542,17 +549,28 @@ func (arena *Arena) assignTeam(teamId int, station string) error {
|
||||
// Asynchronously reconfigures the networking hardware for the new set of teams.
|
||||
func (arena *Arena) setupNetwork() {
|
||||
if arena.EventSettings.NetworkSecurityEnabled {
|
||||
err := arena.accessPoint.ConfigureTeamWifi(arena.AllianceStations["R1"].Team,
|
||||
arena.AllianceStations["R2"].Team, arena.AllianceStations["R3"].Team, arena.AllianceStations["B1"].Team,
|
||||
arena.AllianceStations["B2"].Team, arena.AllianceStations["B3"].Team)
|
||||
if 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(arena.AllianceStations["R1"].Team,
|
||||
arena.AllianceStations["R2"].Team, arena.AllianceStations["R3"].Team, arena.AllianceStations["B1"].Team,
|
||||
arena.AllianceStations["B2"].Team, arena.AllianceStations["B3"].Team); 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(arena.AllianceStations["R1"].Team,
|
||||
arena.AllianceStations["R2"].Team, arena.AllianceStations["R3"].Team, nil, nil, nil); err != nil {
|
||||
log.Printf("Failed to configure red alliance WiFi: %s", err.Error())
|
||||
}
|
||||
if err := arena.accessPoint2.ConfigureTeamWifi(nil, nil, nil, arena.AllianceStations["B1"].Team,
|
||||
arena.AllianceStations["B2"].Team, arena.AllianceStations["B3"].Team); err != nil {
|
||||
log.Printf("Failed to configure blue alliance WiFi: %s", err.Error())
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
err := arena.networkSwitch.ConfigureTeamEthernet(arena.AllianceStations["R1"].Team,
|
||||
if err := arena.networkSwitch.ConfigureTeamEthernet(arena.AllianceStations["R1"].Team,
|
||||
arena.AllianceStations["R2"].Team, arena.AllianceStations["R3"].Team, arena.AllianceStations["B1"].Team,
|
||||
arena.AllianceStations["B2"].Team, arena.AllianceStations["B3"].Team)
|
||||
if err != nil {
|
||||
arena.AllianceStations["B2"].Team, arena.AllianceStations["B3"].Team); err != nil {
|
||||
log.Printf("Failed to configure team Ethernet: %s", err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -80,7 +80,11 @@ 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)
|
||||
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]
|
||||
} else {
|
||||
teamWifiStatuses[station] = arena.accessPoint2.TeamWifiStatuses[i]
|
||||
}
|
||||
}
|
||||
|
||||
return &struct {
|
||||
|
||||
@@ -23,6 +23,10 @@ type EventSettings struct {
|
||||
ApTeamChannel int
|
||||
ApAdminChannel int
|
||||
ApAdminWpaKey string
|
||||
Ap2Address string
|
||||
Ap2Username string
|
||||
Ap2Password string
|
||||
Ap2TeamChannel int
|
||||
SwitchAddress string
|
||||
SwitchPassword string
|
||||
PlcAddress string
|
||||
@@ -45,6 +49,7 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
|
||||
eventSettings.ApTeamChannel = 157
|
||||
eventSettings.ApAdminChannel = 0
|
||||
eventSettings.ApAdminWpaKey = "1234Five"
|
||||
eventSettings.Ap2TeamChannel = 0
|
||||
eventSettings.HabDockingThreshold = 15
|
||||
|
||||
err = database.eventSettingsMap.Insert(eventSettings)
|
||||
|
||||
@@ -195,6 +195,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>
|
||||
|
||||
@@ -62,12 +62,21 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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")
|
||||
eventSettings.AdminPassword = r.PostFormValue("adminPassword")
|
||||
eventSettings.HabDockingThreshold, _ = strconv.Atoi(r.PostFormValue("habDockingThreshold"))
|
||||
|
||||
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.SaveEventSettings(eventSettings)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
|
||||
Reference in New Issue
Block a user