Small CLI monitoring tool to decode proprietary [...] protocol and display info in human readable representation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ycli-mon/ui/connectors.go

140 lines
4.4 KiB

package ui
import (
"cli-mon/yabl"
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
const connectorCount = 6
type cTable struct {
tview.Table
voltageBefore [connectorCount + 1]*tview.TableCell
voltageAfter [connectorCount + 1]*tview.TableCell
presentCurrent [connectorCount + 1]*tview.TableCell
connectorInsert [connectorCount + 1]*tview.TableCell
contactorClosed [connectorCount + 1]*tview.TableCell
connectorLocked [connectorCount + 1]*tview.TableCell
cpLevel [connectorCount + 1]*tview.TableCell
isolationState [connectorCount + 1]*tview.TableCell
chargingAllowed [connectorCount + 1]*tview.TableCell
pwmEnabled [connectorCount + 1]*tview.TableCell
cpAccurate [connectorCount + 1]*tview.TableCell
debugModeOn [connectorCount + 1]*tview.TableCell
debugContactorOutOn [connectorCount + 1]*tview.TableCell
boardReady [connectorCount + 1]*tview.TableCell
}
func (t *cTable) updatePU(id uint, field yabl.FName, value any) {
var view *tview.TableCell
switch field {
case yabl.FVoltageBefore:
view = t.voltageBefore[id]
case yabl.FVoltageAfter:
view = t.voltageAfter[id]
case yabl.FPresentCurrent:
view = t.presentCurrent[id]
case yabl.FConnectorInsert:
view = t.connectorInsert[id]
case yabl.FContactorOn:
view = t.contactorClosed[id]
case yabl.FConnectorLocked:
view = t.connectorLocked[id]
case yabl.FCpLineLevel:
view = t.cpLevel[id]
case yabl.FIsolationState:
view = t.isolationState[id]
case yabl.FChargingAllowed:
view = t.chargingAllowed[id]
case yabl.FPwmEnabled:
view = t.pwmEnabled[id]
case yabl.FCpLineVoltage:
view = t.cpAccurate[id]
case yabl.FDebugModeOn:
view = t.debugModeOn[id]
case yabl.FDebugContactorOutputOn:
view = t.debugContactorOutOn[id]
}
if view != nil {
view.SetText(fmt.Sprintf("%v", value))
}
}
func (t *cTable) updatePuErrors(obj *yabl.PuErrors) {
id := obj.GetUnitId()
ready := t.boardReady[id]
ready.SetText(fmt.Sprintf("%v", obj.BoardReady))
if *obj.BoardReady != yabl.BOARD_READY_OK {
ready.SetBackgroundColor(tcell.ColorDarkRed)
} else {
ready.SetBackgroundColor(tcell.ColorDefault)
}
}
func newConnectorsGrid() *cTable {
t := &cTable{}
t.Box = tview.NewBox()
t.SetBorderColor(tview.Styles.GraphicsColor)
t.SetSeparator(' ')
t.SetContent(nil)
t.SetTitle("Connectors")
t.SetBorders(true)
t.SetBorder(true)
t.SetCell(1, 0, tview.NewTableCell("voltageBefore"))
t.SetCell(2, 0, tview.NewTableCell("voltageAfter"))
t.SetCell(3, 0, tview.NewTableCell("presentCurrent"))
t.SetCell(4, 0, tview.NewTableCell("connectorInsert"))
t.SetCell(5, 0, tview.NewTableCell("contactorClosed"))
t.SetCell(6, 0, tview.NewTableCell("connectorLocked"))
t.SetCell(7, 0, tview.NewTableCell("cpLevel"))
t.SetCell(8, 0, tview.NewTableCell("isolationState"))
t.SetCell(9, 0, tview.NewTableCell("chargingAllowed"))
t.SetCell(10, 0, tview.NewTableCell("pwmEnabled"))
t.SetCell(11, 0, tview.NewTableCell("cpAccurate"))
t.SetCell(12, 0, tview.NewTableCell("debugModeOn"))
t.SetCell(13, 0, tview.NewTableCell("debugContactorOutOn"))
t.SetCell(14, 0, tview.NewTableCell("boardReady"))
for i := 1; i <= 6; i++ {
t.SetCell(0, i, tview.NewTableCell(fmt.Sprintf("Connector %d", i)).SetExpansion(2))
t.voltageBefore[i] = tview.NewTableCell("")
t.voltageAfter[i] = tview.NewTableCell("")
t.presentCurrent[i] = tview.NewTableCell("")
t.connectorInsert[i] = tview.NewTableCell("")
t.contactorClosed[i] = tview.NewTableCell("")
t.connectorLocked[i] = tview.NewTableCell("")
t.cpLevel[i] = tview.NewTableCell("")
t.isolationState[i] = tview.NewTableCell("")
t.chargingAllowed[i] = tview.NewTableCell("")
t.pwmEnabled[i] = tview.NewTableCell("")
t.cpAccurate[i] = tview.NewTableCell("")
t.debugModeOn[i] = tview.NewTableCell("")
t.debugContactorOutOn[i] = tview.NewTableCell("")
t.boardReady[i] = tview.NewTableCell("")
t.SetCell(1, i, t.voltageBefore[i])
t.SetCell(2, i, t.voltageAfter[i])
t.SetCell(3, i, t.presentCurrent[i])
t.SetCell(4, i, t.connectorInsert[i])
t.SetCell(5, i, t.contactorClosed[i])
t.SetCell(6, i, t.connectorLocked[i])
t.SetCell(7, i, t.cpLevel[i])
t.SetCell(8, i, t.isolationState[i])
t.SetCell(9, i, t.chargingAllowed[i])
t.SetCell(10, i, t.pwmEnabled[i])
t.SetCell(11, i, t.cpAccurate[i])
t.SetCell(12, i, t.debugModeOn[i])
t.SetCell(13, i, t.debugContactorOutOn[i])
t.SetCell(14, i, t.boardReady[i])
}
return t
}