mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if arena.EventSettings.PlcAddress != "" {
|
if arena.Plc.IsEnabled() {
|
||||||
if !arena.Plc.IsHealthy {
|
if !arena.Plc.IsHealthy {
|
||||||
return fmt.Errorf("Cannot start match while PLC is not healthy.")
|
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())
|
assert.Nil(t, arena.checkCanStartMatch())
|
||||||
|
|
||||||
// Check PLC constraints.
|
// Check PLC constraints.
|
||||||
arena.EventSettings.PlcAddress = "1.2.3.4"
|
arena.Plc.SetAddress("1.2.3.4")
|
||||||
err = arena.checkCanStartMatch()
|
err = arena.checkCanStartMatch()
|
||||||
if assert.NotNil(t, err) {
|
if assert.NotNil(t, err) {
|
||||||
assert.Contains(t, err.Error(), "Cannot start match while PLC is not healthy")
|
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())
|
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.
|
// Loops indefinitely to read inputs from and write outputs to PLC.
|
||||||
func (plc *Plc) Run() {
|
func (plc *Plc) Run() {
|
||||||
for {
|
for {
|
||||||
if plc.handler == nil {
|
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.
|
// No PLC is configured; just allow the loop to continue to simulate inputs and outputs.
|
||||||
plc.IsHealthy = false
|
plc.IsHealthy = false
|
||||||
} else {
|
} else {
|
||||||
@@ -137,13 +142,13 @@ func (plc *Plc) Run() {
|
|||||||
|
|
||||||
// Returns the state of the field emergency stop button (true if e-stop is active).
|
// Returns the state of the field emergency stop button (true if e-stop is active).
|
||||||
func (plc *Plc) GetFieldEstop() bool {
|
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).
|
// 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) {
|
func (plc *Plc) GetTeamEstops() ([3]bool, [3]bool) {
|
||||||
var redEstops, blueEstops [3]bool
|
var redEstops, blueEstops [3]bool
|
||||||
if plc.address != "" {
|
if plc.IsEnabled() {
|
||||||
redEstops[0] = !plc.inputs[redEstop1]
|
redEstops[0] = !plc.inputs[redEstop1]
|
||||||
redEstops[1] = !plc.inputs[redEstop2]
|
redEstops[1] = !plc.inputs[redEstop2]
|
||||||
redEstops[2] = !plc.inputs[redEstop3]
|
redEstops[2] = !plc.inputs[redEstop3]
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
<p><span class="label label-scoring" id="refereeScoreStatus">Referee</span><br />
|
<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="redScoreStatus"></span><br />
|
||||||
<span class="label label-scoring" id="blueScoreStatus"></span></p>
|
<span class="label label-scoring" id="blueScoreStatus"></span></p>
|
||||||
{{if .EventSettings.PlcAddress}}
|
{{if .PlcIsEnabled}}
|
||||||
<p>PLC Status</p>
|
<p>PLC Status</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="label label-scoring" id="plcStatus"></span><br />
|
<span class="label label-scoring" id="plcStatus"></span><br />
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{if eq .EventSettings.PlcAddress ""}}
|
{{if not .PlcIsEnabled}}
|
||||||
<div id="elements">
|
<div id="elements">
|
||||||
<div class="scoring-section">
|
<div class="scoring-section">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -71,12 +71,13 @@ func (web *Web) matchPlayHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
isReplay := matchResult != nil
|
isReplay := matchResult != nil
|
||||||
data := struct {
|
data := struct {
|
||||||
*model.EventSettings
|
*model.EventSettings
|
||||||
|
PlcIsEnabled bool
|
||||||
MatchesByType map[string]MatchPlayList
|
MatchesByType map[string]MatchPlayList
|
||||||
CurrentMatchType string
|
CurrentMatchType string
|
||||||
Match *model.Match
|
Match *model.Match
|
||||||
AllowSubstitution bool
|
AllowSubstitution bool
|
||||||
IsReplay 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}
|
web.arena.CurrentMatch.ShouldAllowSubstitution(), isReplay}
|
||||||
err = template.ExecuteTemplate(w, "base", data)
|
err = template.ExecuteTemplate(w, "base", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ func (web *Web) scoringPanelHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
data := struct {
|
data := struct {
|
||||||
*model.EventSettings
|
*model.EventSettings
|
||||||
|
PlcIsEnabled bool
|
||||||
Alliance string
|
Alliance string
|
||||||
}{web.arena.EventSettings, alliance}
|
}{web.arena.EventSettings, web.arena.Plc.IsEnabled(), alliance}
|
||||||
err = template.ExecuteTemplate(w, "base_no_navbar", data)
|
err = template.ExecuteTemplate(w, "base_no_navbar", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleWebErr(w, err)
|
handleWebErr(w, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user