Skip to content

Commit

Permalink
Add status indicators for the access point and switch to the match pl…
Browse files Browse the repository at this point in the history
…ay screen.
  • Loading branch information
patfair committed Jun 4, 2024
1 parent a739e9b commit 0d8324d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions field/arena_notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (arena *Arena) generateArenaStatusMessage() any {
AllianceStations map[string]*AllianceStation
MatchState
CanStartMatch bool
AccessPointStatus string
SwitchStatus string
PlcIsHealthy bool
FieldEStop bool
PlcArmorBlockStatuses map[string]bool
Expand All @@ -94,6 +96,8 @@ func (arena *Arena) generateArenaStatusMessage() any {
arena.AllianceStations,
arena.MatchState,
arena.checkCanStartMatch() == nil,
arena.accessPoint.Status,
arena.networkSwitch.Status,
arena.Plc.IsHealthy(),
arena.Plc.GetFieldEStop(),
arena.Plc.GetArmorBlockStatuses(),
Expand Down
3 changes: 1 addition & 2 deletions network/access_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
)

const (
accessPointApiPort = 8081
accessPointPollPeriodSec = 1
)

Expand Down Expand Up @@ -77,7 +76,7 @@ func (ap *AccessPoint) SetSettings(
networkSecurityEnabled bool,
wifiStatuses [6]*TeamWifiStatus,
) {
ap.apiUrl = fmt.Sprintf("http://%s:%d", address, accessPointApiPort)
ap.apiUrl = fmt.Sprintf("http://%s", address)
ap.password = password
ap.channel = channel
ap.networkSecurityEnabled = networkSecurityEnabled
Expand Down
6 changes: 6 additions & 0 deletions network/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Switch struct {
mutex sync.Mutex
configBackoffDuration time.Duration
configPauseDuration time.Duration
Status string
}

var ServerIpAddress = "10.0.100.5" // The DS will try to connect to this address only.
Expand All @@ -49,6 +50,7 @@ func NewSwitch(address, password string) *Switch {
password: password,
configBackoffDuration: switchConfigBackoffDurationSec * time.Second,
configPauseDuration: switchConfigPauseDurationSec * time.Second,
Status: "UNKNOWN",
}
}

Expand All @@ -57,6 +59,7 @@ func (sw *Switch) ConfigureTeamEthernet(teams [6]*model.Team) error {
// Make sure multiple configurations aren't being set at the same time.
sw.mutex.Lock()
defer sw.mutex.Unlock()
sw.Status = "CONFIGURING"

// Remove old team VLANs to reset the switch state.
removeTeamVlansCommand := ""
Expand All @@ -67,6 +70,7 @@ func (sw *Switch) ConfigureTeamEthernet(teams [6]*model.Team) error {
}
_, err := sw.runConfigCommand(removeTeamVlansCommand)
if err != nil {
sw.Status = "ERROR"
return err
}
time.Sleep(sw.configPauseDuration)
Expand Down Expand Up @@ -114,13 +118,15 @@ func (sw *Switch) ConfigureTeamEthernet(teams [6]*model.Team) error {
if len(addTeamVlansCommand) > 0 {
_, err = sw.runConfigCommand(addTeamVlansCommand)
if err != nil {
sw.Status = "ERROR"
return err
}
}

// Give some time for the configuration to take before another one can be attempted.
time.Sleep(sw.configBackoffDuration)

sw.Status = "ACTIVE"
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions network/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func TestConfigureSwitch(t *testing.T) {
sw := NewSwitch("127.0.0.1", "password")
assert.Equal(t, "UNKNOWN", sw.Status)
sw.port = 9050
sw.configBackoffDuration = time.Millisecond
sw.configPauseDuration = time.Millisecond
Expand All @@ -33,6 +34,7 @@ func TestConfigureSwitch(t *testing.T) {
assert.Nil(t, sw.ConfigureTeamEthernet([6]*model.Team{nil, nil, nil, nil, nil, nil}))
assert.Equal(t, expectedResetCommand, command1)
assert.Equal(t, "", command2)
assert.Equal(t, "ACTIVE", sw.Status)

// Should configure one team if only one is present.
sw.port += 1
Expand Down
12 changes: 12 additions & 0 deletions static/css/cheesy-arena.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@
.badge-scoring[data-ready=true] {
background-color: #0c6;
}
.badge-status {
background-color: #e66;
}
.badge-status[data-status=BOOTING] {
background-color: #f92;
}
.badge-status[data-status=CONFIGURING] {
background-color: #08f;
}
.badge-status[data-status=ACTIVE] {
background-color: #0c6;
}
.badge-saved-match {
background-color: #666;
}
Expand Down
3 changes: 3 additions & 0 deletions static/js/match_play.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ const handleArenaStatus = function(data) {
break;
}

$("#accessPointStatus").attr("data-status", data.AccessPointStatus);
$("#switchStatus").attr("data-status", data.SwitchStatus);

if (data.PlcIsHealthy) {
$("#plcStatus").text("Connected");
$("#plcStatus").attr("data-ready", true);
Expand Down
15 changes: 11 additions & 4 deletions templates/match_play.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,20 @@ <h6>Scoring</h6>
<p><span class="badge badge-scoring" id="refereeScoreStatus">Referee</span><br />
<span class="badge badge-scoring" id="redScoreStatus"></span><br />
<span class="badge badge-scoring" id="blueScoreStatus"></span></p>
{{if .EventSettings.NetworkSecurityEnabled}}
<h6>Network Status</h6>
<p>
<span class="badge badge-status" id="accessPointStatus">Access Point</span><br />
<span class="badge badge-status" id="switchStatus">Switch</span>
</p>
{{end}}
{{if .PlcIsEnabled}}
<p>PLC Status</p>
<h6>PLC Status</h6>
<p>
<span class="badge badge-scoring" id="plcStatus"></span><br />
<span class="badge badge-scoring" id="fieldEStop">E-Stop</span>
<span class="badge badge-scoring" id="plcStatus"></span>
<span class="badge badge-scoring" id="fieldEStop">E-Stop</span><br />
{{range $name, $status := .PlcArmorBlockStatuses}}
<br /><span class="badge badge-scoring" id="plc{{$name}}Status">{{$name}}</span>
<span class="badge badge-scoring" id="plc{{$name}}Status">{{$name}}</span>
{{end}}
</p>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/setup_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
</div>
</div>
<div class="row mb-3">
<label class="col-lg-6 control-label">AP Address</label>
<label class="col-lg-6 control-label">AP Address (specify port 8081 for Linksys APs)</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="apAddress" value="{{.ApAddress}}">
</div>
Expand Down

0 comments on commit 0d8324d

Please sign in to comment.