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
jschenke488 committed Oct 29, 2024
1 parent 1393f3b commit 9712a7d
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 @@ -79,6 +79,8 @@ func (arena *Arena) generateArenaStatusMessage() any {
AllianceStations map[string]*AllianceStation
MatchState
CanStartMatch bool
AccessPointStatus string
SwitchStart string
PlcIsHealthy bool
FieldEstop bool
PlcArmorBlockStatuses map[string]bool
Expand All @@ -90,6 +92,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 @@ -78,7 +77,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 All @@ -90,13 +94,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 @@ -88,6 +88,18 @@
.label-scoring[data-ready=true] {
background-color: #0c6;
}
.label-status {
background-color: #e66;
}
.label-status[data-status=BOOTING] {
background-color: #f92;
}
.label-status[data-status=CONFIGURING] {
background-color: #08f;
}
.label-status[data-status=ACTIVE] {
background-color: #0c6;
}
.label-saved-match {
background-color: #999;
}
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 @@ -255,6 +255,9 @@ var 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 @@ -196,13 +196,20 @@
</div>
</div>
</div>
{{if .EventSettings.NetworkSecurityEnabled}}
<h6>Network Status</h6>
<p>
<span class="label label-status" id="accessPointStatus">Access Point</span><br />
<span class="label label-status" id="switchStatus">Switch</span>
</p>
{{end}}
{{if .PlcIsEnabled}}
<p>PLC Status</p>
<h6>PLC Status</h6>
<p>
<span class="label label-scoring" id="plcStatus"></span><br />
<span class="label label-scoring" id="fieldEstop">E-Stop</span>
<span class="label label-scoring" id="plcStatus"></span>
<span class="label label-scoring" id="fieldEstop">E-Stop</span><br />
{{range $name, $status := .PlcArmorBlockStatuses}}
<br /><span class="label label-scoring" id="plc{{$name}}Status">{{$name}}</span>
<span class="label label-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 @@ -154,7 +154,7 @@
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">AP Address</label>
<label class="col-lg-5 control-label">AP Address (specify port 8081 for Linksys APs)</label>
<div class="col-lg-7">
<input type="text" class="form-control" name="apAddress" value="{{.ApAddress}}">
</div>
Expand Down

0 comments on commit 9712a7d

Please sign in to comment.