Skip to content

Commit

Permalink
Distinguish AP numbers in logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jschenke488 committed Oct 29, 2024
1 parent d1fe6a8 commit 99750c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (arena *Arena) LoadSettings() error {
}

arena.accessPoint.SetSettings(
1,
settings.ApType == "vivid",
settings.ApAddress,
settings.ApUsername,
Expand All @@ -189,6 +190,7 @@ func (arena *Arena) LoadSettings() error {
accessPoint1WifiStatuses,
)
arena.accessPoint2.SetSettings(
2,
settings.ApType == "vivid",
settings.Ap2Address,
settings.Ap2Username,
Expand Down
21 changes: 13 additions & 8 deletions network/access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
var accessPointInfoLines = []string{"ESSID: ", "Mode: ", "Tx-Power: ", "Signal: ", "Bit Rate: "}

type AccessPoint struct {
apNumber int
isVividType bool
address string
username string
Expand All @@ -56,12 +57,14 @@ type sshOutput struct {
}

func (ap *AccessPoint) SetSettings(
apNumber int,
isVividType bool,
address, username, password string,
teamChannel int,
networkSecurityEnabled bool,
wifiStatuses [6]*TeamWifiStatus,
) {
ap.apNumber = apNumber
ap.isVividType = isVividType
ap.address = address
ap.username = username
Expand Down Expand Up @@ -144,15 +147,15 @@ func (ap *AccessPoint) configureTeams(teams [6]*model.Team) {
for teamIndex < 6 {
config, err := ap.generateTeamAccessPointConfig(teams[teamIndex], teamIndex+1)
if err != nil {
log.Printf("Failed to generate WiFi configuration: %v", err)
log.Printf("Failed to generate WiFi configuration for AP %d: %v", ap.apNumber, err)
}

command := addConfigurationHeader(config)
log.Printf("Configuring access point with command: %s\n", command)
log.Printf("Configuring AP %d with command: %s\n", ap.apNumber, command)

_, err = ap.runCommand(command)
if err != nil {
log.Printf("Error writing team configuration to AP: %v", err)
log.Printf("Error writing team configuration to AP %d: %v", ap.apNumber, err)
retryCount++
time.Sleep(time.Second * accessPointConfigRetryIntervalSec)
continue
Expand All @@ -170,10 +173,12 @@ func (ap *AccessPoint) configureTeams(teams [6]*model.Team) {
}
err := ap.updateTeamWifiStatuses()
if err == nil && ap.configIsCorrectForTeams(teams) {
log.Printf("Successfully configured WiFi after %d attempts.", retryCount)
log.Printf("Successfully configured AP %d Wi-Fi after %d attempts.", ap.apNumber, retryCount)
break
}
log.Printf("WiFi configuration still incorrect after %d attempts; trying again.", retryCount)
log.Printf(
"WiFi configuration still incorrect on AP %d after %d attempts; trying again.", ap.apNumber, retryCount,
)
}
}

Expand Down Expand Up @@ -208,7 +213,7 @@ func (ap *AccessPoint) updateTeamWifiStatuses() error {

output, err := ap.runCommand("iwinfo")
if err == nil {
logWifiInfo(output)
ap.logWifiInfo(output)
err = ap.decodeWifiInfo(output)
}

Expand Down Expand Up @@ -290,7 +295,7 @@ func (ap *AccessPoint) generateTeamAccessPointConfig(team *model.Team, position
}

// Filters the given output from the "iwiinfo" command on the AP and logs the relevant parts.
func logWifiInfo(wifiInfo string) {
func (ap *AccessPoint) logWifiInfo(wifiInfo string) {
lines := strings.Split(wifiInfo, "\n")
var filteredLines []string
for _, line := range lines {
Expand All @@ -301,7 +306,7 @@ func logWifiInfo(wifiInfo string) {
}
}
}
log.Printf("Access point status:\n%s\n", strings.Join(filteredLines, "\n"))
log.Printf("AP %d status:\n%s\n", ap.apNumber, strings.Join(filteredLines, "\n"))
}

// Parses the given output from the "iwinfo" command on the AP and updates the given status structure with the result.
Expand Down

0 comments on commit 99750c5

Please sign in to comment.