parent
f00c743160
commit
6f83643247
@ -1,140 +0,0 @@ |
||||
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 |
||||
} |
@ -0,0 +1,174 @@ |
||||
package ui |
||||
|
||||
import "cli-mon/yabl" |
||||
|
||||
var pu = []key{ |
||||
{yabl.PPuPresentEnergy, yabl.FVoltageBefore, 1}, |
||||
{yabl.PPuPresentEnergy, yabl.FVoltageAfter, 2}, |
||||
{yabl.PCpuPresentEnergy, yabl.FPresentVoltage, 3}, |
||||
{yabl.PPuPresentEnergy, yabl.FPresentCurrent, 4}, |
||||
{yabl.PCpuPresentEnergy, yabl.FPresentCurrent, 5}, |
||||
{yabl.PPuPeriphery, yabl.FConnectorInsert, 6}, |
||||
{yabl.PPuPeriphery, yabl.FDebugContactorOn, 7}, |
||||
{yabl.PPuPeriphery, yabl.FConnectorLocked, 8}, |
||||
{yabl.PPuPeriphery, yabl.FCpLineLevel, 9}, |
||||
{yabl.PPuPeriphery, yabl.FIsolationState, 10}, |
||||
{yabl.PPuPeriphery, yabl.FChargingAllowed, 11}, |
||||
{yabl.PPuPeriphery, yabl.FPwmEnabled, 12}, |
||||
{yabl.PPuPeriphery, yabl.FCpLineVoltage, 13}, |
||||
{yabl.PCpuEnergySettings, yabl.FTargetBatteryVoltage, 14}, |
||||
{yabl.PCpuEnergySettings, yabl.FTargetGoalVoltage, 15}, |
||||
{yabl.PCpuEnergySettings, yabl.FPowerMax, 16}, |
||||
{yabl.PCpuEnergySettings, yabl.FCurrentMax, 17}, |
||||
{yabl.PCpuEnergySettings, yabl.FVoltageMax, 18}, |
||||
{yabl.PPuDebug, yabl.FDebugModeOn, 19}, |
||||
{yabl.PPuDebug, yabl.FDebugContactorOutputOn, 20}, |
||||
{yabl.PPuErrors, yabl.FBoardReady, 21}, |
||||
} |
||||
|
||||
var pu_errors = []key{ |
||||
{yabl.PPuErrors, yabl.FBoardReady, 1}, |
||||
{yabl.PPuErrors, yabl.FOtherError, 2}, |
||||
{yabl.PPuErrors, yabl.FIncorrectVoltage, 3}, |
||||
{yabl.PPuErrors, yabl.FIncorrectVoltageValue, 4}, |
||||
{yabl.PPuErrors, yabl.FIncorrectCurrent, 5}, |
||||
{yabl.PPuErrors, yabl.FIncorrectCurrentValue, 6}, |
||||
{yabl.PPuErrors, yabl.FIsolationBroken, 7}, |
||||
{yabl.PPuErrors, yabl.FCpLineBroken, 8}, |
||||
{yabl.PPuErrors, yabl.FCpLineGap69, 9}, |
||||
{yabl.PPuErrors, yabl.FCableReady, 10}, |
||||
{yabl.PPuErrors, yabl.FNotReadyCpu, 11}, |
||||
{yabl.PPuErrors, yabl.FNotReadySecc, 12}, |
||||
{yabl.PPuErrors, yabl.FContactorOutputError, 13}, |
||||
{yabl.PPuErrors, yabl.FDebugContactorOutputEnabled, 14}, |
||||
{yabl.PPuErrors, yabl.FOutputCircuitBreakerEnabled, 15}, |
||||
{yabl.PPuDebug, yabl.FDebugModeOn, 16}, |
||||
{yabl.PPuDebug, yabl.FDebugContactorOutputOn, 17}, |
||||
} |
||||
|
||||
var contactors_errors = []key{ |
||||
{yabl.PContactorInternalErrors, yabl.FBoardReady, 1}, |
||||
{yabl.PContactorInternalErrors, yabl.FOtherError, 2}, |
||||
{yabl.PContactorInternalErrors, yabl.FContactorGroupChanged, 3}, |
||||
{yabl.PContactorInternalErrors, yabl.FUnexpectedFormation, 4}, |
||||
{yabl.PContactorInternalErrors, yabl.FCpuNotReady, 5}, |
||||
{yabl.PContactorInternalErrors, yabl.FPuNotReady, 6}, |
||||
{yabl.PContactorInternalErrors, yabl.FDebug, 7}, |
||||
{yabl.PContactorInternalErrors, yabl.FPresentContactorMode, 8}, |
||||
{yabl.PContactorsInternalForce, yabl.FForceModeEnabled, 9}, |
||||
{yabl.PContactorsInternalForce, yabl.FForceModeValue, 10}, |
||||
{yabl.PContactorInternalDebug, yabl.FDebugModeOn, 11}, |
||||
} |
||||
|
||||
var contactors_state = []key{ |
||||
{yabl.PContactorInternalState, yabl.FContactorReady, 1}, |
||||
{yabl.PContactorInternalState, yabl.FContactorOn, 2}, |
||||
{yabl.PContactorInternalState, yabl.FUnexpectedState, 3}, |
||||
{yabl.PContactorInternalState, yabl.FIsolated, 4}, |
||||
{yabl.PContactorInternalState, yabl.FDebugEnabled, 5}, |
||||
{yabl.PContactorInternalDebug, yabl.FDebugContactorOn, 6}, |
||||
} |
||||
|
||||
var periphery_state = []key{ |
||||
{yabl.PPeripheryState, yabl.FErrorShakeSensor, 1}, |
||||
{yabl.PPeripheryState, yabl.FErrorCoolingGroup, 2}, |
||||
{yabl.PPeripheryState, yabl.FOtherError, 3}, |
||||
{yabl.PPeripheryState, yabl.FDebugShptFanEnabled, 4}, |
||||
{yabl.PPeripheryState, yabl.FDebugIoBoardTestLampEnabled, 5}, |
||||
{yabl.PPeripheryInfo, yabl.FStateShptFan, 6}, |
||||
{yabl.PPeripheryDebug, yabl.FDebugShptFan, 7}, |
||||
{yabl.PPeripheryDebug, yabl.FDebugIoBoardTestLamp, 8}, |
||||
} |
||||
|
||||
var periphery_station_state = []key{ |
||||
{yabl.PPeripheryState, yabl.FOtherErrorSeverity, 1}, |
||||
{yabl.PPeripheryState, yabl.FOtherError, 2}, |
||||
{yabl.PPeripheryState, yabl.FPeripheryErrorCoolingGroup, 3}, |
||||
{yabl.PPeripheryState, yabl.FErrorFireEmergency, 4}, |
||||
{yabl.PPeripheryState, yabl.FErrorFireEmergencyRun, 5}, |
||||
{yabl.PPeripheryState, yabl.FErrorFireEmergencyControl, 6}, |
||||
{yabl.PPeripheryState, yabl.FErrorOvervoltageIn, 7}, |
||||
{yabl.PPeripheryState, yabl.FPeripheryErrorPowerSupply, 8}, |
||||
{yabl.PPeripheryState, yabl.FErrorFan, 9}, |
||||
{yabl.PPeripheryState, yabl.FErrorOvervoltageOut, 10}, |
||||
{yabl.PPeripheryState, yabl.FErrorStateRemoteMode, 11}, |
||||
{yabl.PPeripheryState, yabl.FDebugShsnFanEnabled, 12}, |
||||
{yabl.PPeripheryState, yabl.FDebugShptFanEnabled, 13}, |
||||
{yabl.PPeripheryState, yabl.FDebugIoBoardTestLampEnabled, 14}, |
||||
{yabl.PPeripheryState, yabl.FErrorFireEmergencyCircuitBreaker, 15}, |
||||
{yabl.PPeripheryState, yabl.FErrorExtLightCircuitBreaker, 16}, |
||||
{yabl.PPeripheryState, yabl.FErrorIndicationCircuitBreaker, 17}, |
||||
{yabl.PPeripheryState, yabl.FErrorLowVoltagePowerCircuitBreaker, 18}, |
||||
{yabl.PPeripheryState, yabl.FErrorContactorsInternalCircuitBreaker, 19}, |
||||
{yabl.PPeripheryState, yabl.FErrorPlcCircuitBreaker, 20}, |
||||
{yabl.PPeripheryInfo, yabl.FInfoDoorOpen, 21}, |
||||
{yabl.PPeripheryInfo, yabl.FTempAirIn, 22}, |
||||
{yabl.PPeripheryInfo, yabl.FTempAirOut, 23}, |
||||
{yabl.PPeripheryInfo, yabl.FStateShsnFan, 24}, |
||||
{yabl.PPeripheryDebug, yabl.FDebugModeOn, 25}, |
||||
{yabl.PPeripheryDebug, yabl.FDebugShsnFan, 26}, |
||||
} |
||||
|
||||
var converters = []key{ |
||||
{yabl.PConverterPresentEnergy, yabl.FPresentVoltage, 1}, |
||||
{yabl.PConverterPresentEnergy, yabl.FPresentCurrent, 2}, |
||||
{yabl.PConverterPresentEnergy, yabl.FConnectedOut, 3}, |
||||
{yabl.PConverterErrors, yabl.FBoardReady, 4}, |
||||
{yabl.PConverterErrors, yabl.FOtherError, 5}, |
||||
{yabl.PConverterErrors, yabl.FNotConnectedOut, 6}, |
||||
{yabl.PConverterErrors, yabl.FNoCommunicationConverter, 7}, |
||||
{yabl.PConverterErrors, yabl.FNoCommunicationPuConverter, 8}, |
||||
{yabl.PConverterPresentEnergy, yabl.FV2gMode, 9}, |
||||
{yabl.PConverterErrors, yabl.FDebugConvEnabled, 10}, |
||||
{yabl.PConverterErrors, yabl.FDebugConvDisabled, 11}, |
||||
{yabl.PConverterDebug, yabl.FDebugModeOn, 12}, |
||||
{yabl.PConverterDebug, yabl.FDebugEnergyOn, 13}, |
||||
{yabl.PConverterDebug, yabl.FDebugTargetVoltage, 14}, |
||||
{yabl.PConverterDebug, yabl.FDebugTargetCurrent, 15}, |
||||
} |
||||
|
||||
var converters_errors = []key{ |
||||
{yabl.PConverterErrors, yabl.FBoardReady, 1}, |
||||
{yabl.PConverterErrors, yabl.FOtherError, 2}, |
||||
{yabl.PConverterErrors, yabl.FNotConnectedOut, 3}, |
||||
{yabl.PConverterErrors, yabl.FNoCommunicationConverter, 4}, |
||||
{yabl.PConverterErrors, yabl.FNoCommunicationPuConverter, 5}, |
||||
{yabl.PConverterErrors, yabl.FInputGridVoltageHigh, 6}, |
||||
{yabl.PConverterErrors, yabl.FInputGridVoltageLow, 7}, |
||||
{yabl.PConverterErrors, yabl.FOutputGridVoltageHigh, 8}, |
||||
{yabl.PConverterErrors, yabl.FOutputGridVoltageLow, 9}, |
||||
{yabl.PConverterErrors, yabl.FInputGridVoltage, 10}, |
||||
{yabl.PConverterErrors, yabl.FOutputGridVoltage, 11}, |
||||
{yabl.PConverterErrors, yabl.FShortCircuit, 12}, |
||||
{yabl.PConverterErrors, yabl.FOverHeat, 13}, |
||||
{yabl.PConverterErrors, yabl.FFanBroken, 14}, |
||||
{yabl.PConverterErrors, yabl.FOtherHardwareError, 15}, |
||||
} |
||||
|
||||
var cpu = []key{ |
||||
{yabl.PCpuErrors, yabl.FBoardReady, 1}, |
||||
{yabl.PCpuErrors, yabl.FOtherError, 2}, |
||||
{yabl.PCpuErrors, yabl.FRedButtonHard, 3}, |
||||
{yabl.PCpuErrors, yabl.FRedButtonSoft, 4}, |
||||
{yabl.PCpuErrors, yabl.FModulesGone, 5}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageHighErr, 6}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageHighWarn, 7}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageLowWarn, 8}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageLowErr, 9}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageLow, 10}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageHigh, 11}, |
||||
{yabl.PCpuErrors, yabl.FGridVoltageEmpty, 12}, |
||||
{yabl.PCpuErrors, yabl.FNotReadySecc, 13}, |
||||
{yabl.PCpuErrors, yabl.FNotReadyPu, 14}, |
||||
{yabl.PCpuErrors, yabl.FNotReadyContactors, 15}, |
||||
{yabl.PCpuErrors, yabl.FDebugConvertersEnabled, 16}, |
||||
{yabl.PCpuErrors, yabl.FContactorInputError, 17}, |
||||
{yabl.PCpuErrors, yabl.FNotReadyPeriphery, 18}, |
||||
{yabl.PCpuPeriphery, yabl.FContactorInput, 19}, |
||||
{yabl.PCpuPeriphery, yabl.FCircuitBreakerInput, 20}, |
||||
{yabl.PCpuPeriphery, yabl.FCircuitBreakerPowerCBInput, 21}, |
||||
{yabl.PCpuDebug, yabl.FDebugModeOn, 22}, |
||||
{yabl.PCpuDebug, yabl.FDebugContactorInputOn, 23}, |
||||
{yabl.PCpuDebug, yabl.FDebugCircuitBreakerOn, 24}, |
||||
{yabl.PCpuDebug, yabl.FDebugRedButtonSoftware, 25}, |
||||
} |
@ -0,0 +1,96 @@ |
||||
package ui |
||||
|
||||
import ( |
||||
"cli-mon/yabl" |
||||
"fmt" |
||||
tview "github.com/rivo/tview" |
||||
"reflect" |
||||
) |
||||
|
||||
type table struct { |
||||
tview.Table |
||||
views map[key]*tview.TableCell |
||||
content []key |
||||
} |
||||
|
||||
type key struct { |
||||
action yabl.AName |
||||
field yabl.FName |
||||
id uint |
||||
} |
||||
|
||||
func (t *table) update(event *yabl.Event) { |
||||
if cell, ok := t.views[key{event.ActionName, event.Field, event.GetUnitId()}]; ok { |
||||
cell.SetText(fmt.Sprintf("%v", event.Value)) |
||||
} |
||||
} |
||||
|
||||
func (t *table) header(header string) *table { |
||||
t.SetTitle(header) |
||||
return t |
||||
} |
||||
|
||||
func (t *table) columns(name string, cols int) *table { |
||||
for i := 1; i <= cols; i++ { |
||||
t.SetCell(0, i, tview.NewTableCell(fmt.Sprintf("%s %d", name, i)).SetExpansion(2)) |
||||
} |
||||
return t |
||||
} |
||||
|
||||
func (t *table) rows(name string, rows int) *table { |
||||
for i := 1; i <= rows; i++ { |
||||
t.SetCell(i, 0, tview.NewTableCell(fmt.Sprintf("%s %d", name, i))) //.SetExpansion(2))
|
||||
} |
||||
return t |
||||
} |
||||
|
||||
func newTable(params []key, min, max int, invert bool, short bool) *table { |
||||
t := &table{} |
||||
t.Box = tview.NewBox() |
||||
t.SetBorderColor(tview.Styles.GraphicsColor) |
||||
t.SetSeparator(' ') |
||||
t.SetContent(nil) |
||||
t.SetBorders(true) |
||||
t.SetBorder(true) |
||||
|
||||
t.views = make(map[key]*tview.TableCell) |
||||
|
||||
for _, param := range params { |
||||
for i := min; i <= max; i++ { |
||||
k := param |
||||
k.id = uint(i) |
||||
cell := tview.NewTableCell("") |
||||
t.views[k] = cell |
||||
var col = i |
||||
if min == 0 { |
||||
col++ |
||||
} |
||||
if !invert { |
||||
t.SetCell(int(param.id), col, cell) |
||||
} else { |
||||
t.SetCell(col, int(param.id), cell) |
||||
} |
||||
|
||||
} |
||||
var desc string |
||||
if short { |
||||
desc = fmt.Sprintf("%s", param.field) |
||||
} else { |
||||
desc = fmt.Sprintf("%s.%s", param.action, param.field) |
||||
} |
||||
|
||||
if !invert { |
||||
t.SetCell(int(param.id), 0, tview.NewTableCell(desc)) |
||||
} else { |
||||
t.SetCell(0, int(param.id), tview.NewTableCell(desc)) |
||||
} |
||||
} |
||||
|
||||
return t |
||||
} |
||||
|
||||
func getField(v yabl.Action, field yabl.FName) interface{} { |
||||
r := reflect.ValueOf(v) |
||||
f := reflect.Indirect(r).FieldByName(string(field)) |
||||
return f.Interface() |
||||
} |
Loading…
Reference in new issue