mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Add Plc.IsEnabled() method and refactor places that were checking settings directly to use it instead.
This commit is contained in:
@@ -647,7 +647,7 @@ func (arena *Arena) checkCanStartMatch() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if arena.EventSettings.PlcAddress != "" {
|
||||
if arena.Plc.IsEnabled() {
|
||||
if !arena.Plc.IsHealthy {
|
||||
return fmt.Errorf("Cannot start match while PLC is not healthy.")
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ func TestArenaCheckCanStartMatch(t *testing.T) {
|
||||
assert.Nil(t, arena.checkCanStartMatch())
|
||||
|
||||
// Check PLC constraints.
|
||||
arena.EventSettings.PlcAddress = "1.2.3.4"
|
||||
arena.Plc.SetAddress("1.2.3.4")
|
||||
err = arena.checkCanStartMatch()
|
||||
if assert.NotNil(t, err) {
|
||||
assert.Contains(t, err.Error(), "Cannot start match while PLC is not healthy")
|
||||
}
|
||||
arena.Plc.IsHealthy = true
|
||||
arena.Plc.SetAddress("")
|
||||
assert.Nil(t, arena.checkCanStartMatch())
|
||||
}
|
||||
|
||||
|
||||
11
plc/plc.go
11
plc/plc.go
@@ -87,11 +87,16 @@ func (plc *Plc) SetAddress(address string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the PLC is enabled in the configurations.
|
||||
func (plc *Plc) IsEnabled() bool {
|
||||
return plc.address != ""
|
||||
}
|
||||
|
||||
// Loops indefinitely to read inputs from and write outputs to PLC.
|
||||
func (plc *Plc) Run() {
|
||||
for {
|
||||
if plc.handler == nil {
|
||||
if plc.address == "" {
|
||||
if !plc.IsEnabled() {
|
||||
// No PLC is configured; just allow the loop to continue to simulate inputs and outputs.
|
||||
plc.IsHealthy = false
|
||||
} else {
|
||||
@@ -137,13 +142,13 @@ func (plc *Plc) Run() {
|
||||
|
||||
// Returns the state of the field emergency stop button (true if e-stop is active).
|
||||
func (plc *Plc) GetFieldEstop() bool {
|
||||
return plc.address != "" && !plc.inputs[fieldEstop]
|
||||
return plc.IsEnabled() && !plc.inputs[fieldEstop]
|
||||
}
|
||||
|
||||
// Returns the state of the red and blue driver station emergency stop buttons (true if e-stop is active).
|
||||
func (plc *Plc) GetTeamEstops() ([3]bool, [3]bool) {
|
||||
var redEstops, blueEstops [3]bool
|
||||
if plc.address != "" {
|
||||
if plc.IsEnabled() {
|
||||
redEstops[0] = !plc.inputs[redEstop1]
|
||||
redEstops[1] = !plc.inputs[redEstop2]
|
||||
redEstops[2] = !plc.inputs[redEstop3]
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
<p><span class="label label-scoring" id="refereeScoreStatus">Referee</span><br />
|
||||
<span class="label label-scoring" id="redScoreStatus"></span><br />
|
||||
<span class="label label-scoring" id="blueScoreStatus"></span></p>
|
||||
{{if .EventSettings.PlcAddress}}
|
||||
{{if .PlcIsEnabled}}
|
||||
<p>PLC Status</p>
|
||||
<p>
|
||||
<span class="label label-scoring" id="plcStatus"></span><br />
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if eq .EventSettings.PlcAddress ""}}
|
||||
{{if not .PlcIsEnabled}}
|
||||
<div id="elements">
|
||||
<div class="scoring-section">
|
||||
<div>
|
||||
|
||||
@@ -71,12 +71,13 @@ func (web *Web) matchPlayHandler(w http.ResponseWriter, r *http.Request) {
|
||||
isReplay := matchResult != nil
|
||||
data := struct {
|
||||
*model.EventSettings
|
||||
PlcIsEnabled bool
|
||||
MatchesByType map[string]MatchPlayList
|
||||
CurrentMatchType string
|
||||
Match *model.Match
|
||||
AllowSubstitution bool
|
||||
IsReplay bool
|
||||
}{web.arena.EventSettings, matchesByType, currentMatchType, web.arena.CurrentMatch,
|
||||
}{web.arena.EventSettings, web.arena.Plc.IsEnabled(), matchesByType, currentMatchType, web.arena.CurrentMatch,
|
||||
web.arena.CurrentMatch.ShouldAllowSubstitution(), isReplay}
|
||||
err = template.ExecuteTemplate(w, "base", data)
|
||||
if err != nil {
|
||||
|
||||
@@ -39,8 +39,9 @@ func (web *Web) scoringPanelHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
data := struct {
|
||||
*model.EventSettings
|
||||
Alliance string
|
||||
}{web.arena.EventSettings, alliance}
|
||||
PlcIsEnabled bool
|
||||
Alliance string
|
||||
}{web.arena.EventSettings, web.arena.Plc.IsEnabled(), alliance}
|
||||
err = template.ExecuteTemplate(w, "base_no_navbar", data)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
|
||||
Reference in New Issue
Block a user