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.
235 lines
4.6 KiB
235 lines
4.6 KiB
package ui
|
|
|
|
import (
|
|
"cli-mon/yabl"
|
|
"fmt"
|
|
ui "github.com/gizak/termui/v3"
|
|
"github.com/gizak/termui/v3/widgets"
|
|
)
|
|
|
|
func newHeader() *widgets.Paragraph {
|
|
widget := widgets.NewParagraph()
|
|
widget.Text = "Press q to quit, Press <Left> or <Right> to switch tabs"
|
|
widget.SetRect(0, 0, 50, 1)
|
|
widget.Border = false
|
|
widget.TextStyle.Bg = ui.ColorBlue
|
|
return widget
|
|
}
|
|
|
|
func newConnectorsView() *ui.Grid {
|
|
grid := ui.NewGrid()
|
|
|
|
termWidth, termHeight := ui.TerminalDimensions()
|
|
grid.SetRect(0, headerHeight, termWidth, termHeight)
|
|
|
|
var conn [connectorsCount + 1]*widgets.Paragraph //ui.GridItem
|
|
|
|
for i := 0; i <= connectorsCount; i++ {
|
|
p := widgets.NewParagraph()
|
|
p.Text = fmt.Sprintf("No data: #%2.d", i)
|
|
p.Title = fmt.Sprintf("Connector: #%2.d", i)
|
|
//p.SetRect(0, 0, 50, 30)
|
|
p.TextStyle.Bg = ui.ColorBlue
|
|
p.TextStyle.Fg = ui.ColorWhite
|
|
p.BorderStyle.Fg = ui.ColorYellow
|
|
p.Border = true
|
|
|
|
connUI[i] = p
|
|
conn[i] = p //ui.NewCol(1.0/6, p)
|
|
}
|
|
|
|
grid.Set(
|
|
ui.NewRow(
|
|
1.0/2,
|
|
ui.NewCol(1.0/4, conn[1]),
|
|
ui.NewCol(1.0/4, conn[2]),
|
|
ui.NewCol(1.0/4, conn[3]),
|
|
ui.NewCol(1.0/4, conn[4]),
|
|
),
|
|
ui.NewRow(
|
|
1.0/2,
|
|
ui.NewCol(1.0/4, conn[5]),
|
|
ui.NewCol(1.0/4, conn[6]),
|
|
ui.NewCol(1.0/4, conn[0]),
|
|
),
|
|
)
|
|
|
|
return grid
|
|
}
|
|
|
|
func newContactorsView() *ui.Grid {
|
|
grid := ui.NewGrid()
|
|
|
|
termWidth, termHeight := ui.TerminalDimensions()
|
|
grid.SetRect(0, headerHeight, termWidth, termHeight)
|
|
|
|
var cont [contactorsCount + 1]ui.GridItem
|
|
|
|
//var contactors = make([]ui.GridItem, contactorsCount)
|
|
for i := 1; i <= contactorsCount; i++ {
|
|
p := widgets.NewParagraph()
|
|
p.Text = fmt.Sprintf("No data: #%2.d", i)
|
|
p.Title = fmt.Sprintf("Contactor: #%2.d", i)
|
|
p.Border = false
|
|
p.TextStyle.Bg = ui.ColorBlue
|
|
p.TextStyle.Fg = ui.ColorWhite
|
|
p.BorderStyle.Fg = ui.ColorYellow
|
|
p.Border = true
|
|
|
|
contUI[i] = p
|
|
cont[i] = ui.NewCol(1.0/6, p)
|
|
}
|
|
|
|
grid.Set(
|
|
ui.NewRow(
|
|
1.0/3,
|
|
cont[1],
|
|
cont[2],
|
|
cont[3],
|
|
cont[4],
|
|
cont[5],
|
|
cont[6],
|
|
),
|
|
ui.NewRow(
|
|
1.0/3,
|
|
cont[7],
|
|
cont[8],
|
|
cont[9],
|
|
cont[10],
|
|
cont[11],
|
|
cont[12],
|
|
),
|
|
ui.NewRow(
|
|
1.0/3,
|
|
cont[13],
|
|
cont[14],
|
|
cont[15],
|
|
cont[16],
|
|
cont[17],
|
|
cont[18],
|
|
))
|
|
|
|
//ui.NewRow(1, ui.InterfaceSlice(contactors)...)
|
|
grid.Set()
|
|
|
|
return grid
|
|
}
|
|
|
|
func newContactorsErrView() *widgets.Paragraph {
|
|
p := widgets.NewParagraph()
|
|
p.Text = "No data\n"
|
|
p.Title = "Contactors Errors"
|
|
p.SetRect(5, 5, 55, 15)
|
|
p.BorderStyle.Fg = ui.ColorYellow
|
|
|
|
return p
|
|
}
|
|
|
|
func updateContactorsView(msg *yabl.ContactorInternalState) {
|
|
|
|
p := contUI[msg.GetUnitId()]
|
|
s := msg
|
|
|
|
if s == nil || p == nil {
|
|
return
|
|
}
|
|
|
|
p.Text = fmt.Sprintf(
|
|
"BoardReady: %s\nContactorOn: %s\nUnexpectedState: %s\nIsolated: %s\nDebug: %s",
|
|
s.ContactorReady,
|
|
s.ContactorOn,
|
|
s.UnexpectedState,
|
|
s.Isolated,
|
|
s.DebugEnabled)
|
|
|
|
if s.ContactorReady != nil && *s.ContactorReady == yabl.BOARD_READY_OK {
|
|
p.TextStyle.Bg = ui.ColorClear
|
|
} else {
|
|
p.TextStyle.Bg = ui.ColorRed
|
|
}
|
|
|
|
if s.ContactorOn != nil && *s.ContactorOn == yabl.ON {
|
|
p.TitleStyle.Bg = ui.ColorBlue
|
|
} else {
|
|
p.TitleStyle.Bg = ui.ColorClear
|
|
}
|
|
}
|
|
|
|
var connectorsState [connectorsCount + 1]*yabl.PuPeriphery
|
|
var connectorsEnergy [connectorsCount + 1]*yabl.PuPresentEnergy
|
|
|
|
func updateConnectorsView(action yabl.Action) {
|
|
if action == nil {
|
|
return
|
|
}
|
|
|
|
var unitId = action.GetUnitId()
|
|
|
|
switch msg := action.(type) {
|
|
case *yabl.PuPeriphery:
|
|
connectorsState[unitId] = msg
|
|
case *yabl.PuPresentEnergy:
|
|
connectorsEnergy[unitId] = msg
|
|
}
|
|
|
|
p := connUI[unitId]
|
|
s := connectorsState[unitId]
|
|
e := connectorsEnergy[unitId]
|
|
|
|
if s == nil || e == nil {
|
|
return
|
|
}
|
|
|
|
fstring := "ConnectorInsert %s\n" +
|
|
"ContactorOn %s\n" +
|
|
"ConnectorLocked %s\n" +
|
|
"LineLevel %s\n" +
|
|
"IsolationState %s\n" +
|
|
"ChargingAllowed %s\n" +
|
|
"PwmEnabled %s\n" +
|
|
"CpLineVoltage %s\n" +
|
|
"V2GMode %s\n" +
|
|
"VoltageBefore %s\n" +
|
|
"VoltageAfter %s\n" +
|
|
"PresentCurrent %s"
|
|
|
|
p.Text = fmt.Sprintf(
|
|
fstring,
|
|
s.ConnectorInsert,
|
|
s.ContactorOn,
|
|
s.ConnectorLocked,
|
|
s.CpLineLevel,
|
|
s.IsolationState,
|
|
s.ChargingAllowed,
|
|
s.PwmEnabled,
|
|
s.CpLineVoltage,
|
|
e.V2GMode,
|
|
e.VoltageBefore,
|
|
e.VoltageAfter,
|
|
e.PresentCurrent)
|
|
}
|
|
|
|
func updateContactorsStateView(e *yabl.ContactorInternalErrors) {
|
|
p := contactorsErr
|
|
|
|
if e == nil {
|
|
return
|
|
}
|
|
|
|
p.Text = fmt.Sprintf(
|
|
"BoardReady: %s\nOtherError: %s\nGroupChanged: %s\nUnexpectedFormation: %s\nCpuNotReady: %s\nPuNotReady: %s\nDebug: %s",
|
|
e.BoardReady,
|
|
e.OtherError,
|
|
e.ContactorGroupChanged,
|
|
e.UnexpectedFormation,
|
|
e.CpuNotReady,
|
|
e.PuNotReady,
|
|
e.Debug,
|
|
)
|
|
|
|
if e.BoardReady != nil && *e.BoardReady == yabl.BOARD_READY_OK {
|
|
p.TextStyle.Bg = ui.ColorClear
|
|
} else {
|
|
p.TextStyle.Bg = ui.ColorRed
|
|
}
|
|
}
|
|
|