Nil value instead zero by default

refactor
Terekhin Alexandr 2 years ago
parent 5d2c7e12fe
commit e42d3b5722
Signed by: didinst
GPG Key ID: D2EF94423C23BF12
  1. 4
      cli-mon.go
  2. 6
      ui/view.go
  3. 8
      yabl/init.go
  4. 10
      yabl/protocol.go
  5. 912
      yabl/setters.go
  6. 2
      yabl/strings.go
  7. 304
      yabl/types.go

@ -46,8 +46,8 @@ func main() {
ui.InitCliApp(messages) ui.InitCliApp(messages)
} else { } else {
for msg := range messages { for msg := range messages {
val := getField(msg.Object, msg.Field) // val := getField(msg.Object, msg.Field)
fmt.Printf("%v %v.%v [%d] %v\n", msg.Updated.Format("Jan _2 15:04:05.000"), msg.ActionName, msg.Field, msg.UnitId, val) fmt.Printf("%v %v.%v [%d] %v\n", msg.Updated.Format("Jan _2 15:04:05.000"), msg.ActionName, msg.Field, msg.UnitId, msg.Value)
} }
} }
} }

@ -142,13 +142,13 @@ func updateContactorsView(msg *yabl.ContactorInternalState) {
s.Isolated, s.Isolated,
s.DebugEnabled) s.DebugEnabled)
if s.ContactorReady == yabl.BOARD_READY_OK { if s.ContactorReady != nil && *s.ContactorReady == yabl.BOARD_READY_OK {
p.TextStyle.Bg = ui.ColorClear p.TextStyle.Bg = ui.ColorClear
} else { } else {
p.TextStyle.Bg = ui.ColorRed p.TextStyle.Bg = ui.ColorRed
} }
if s.ContactorOn == yabl.ON { if s.ContactorOn != nil && *s.ContactorOn == yabl.ON {
p.TitleStyle.Bg = ui.ColorBlue p.TitleStyle.Bg = ui.ColorBlue
} else { } else {
p.TitleStyle.Bg = ui.ColorClear p.TitleStyle.Bg = ui.ColorClear
@ -227,7 +227,7 @@ func updateContactorsStateView(e *yabl.ContactorInternalErrors) {
e.Debug, e.Debug,
) )
if e.BoardReady == yabl.BOARD_READY_OK { if e.BoardReady != nil && *e.BoardReady == yabl.BOARD_READY_OK {
p.TextStyle.Bg = ui.ColorClear p.TextStyle.Bg = ui.ColorClear
} else { } else {
p.TextStyle.Bg = ui.ColorRed p.TextStyle.Bg = ui.ColorRed

@ -379,10 +379,10 @@ func initialize() {
cd := &ConverterDebug{UnitId: i} cd := &ConverterDebug{UnitId: i}
converterDebugArray[i] = cd converterDebugArray[i] = cd
fields = []*field{ fields = []*field{
{length: 3, setter: cd.setDebugModeOn, name: FDebugModeOn}, {length: 2, setter: cd.setDebugModeOn, name: FDebugModeOn},
{length: 4, setter: cd.setDebugEnergyOn, name: FDebugEnergyOn}, {length: 3, setter: cd.setDebugEnergyOn, name: FDebugEnergyOn},
{length: 2, setter: cd.setDebugTargetVoltage, name: FDebugTargetVoltage}, {length: 11, setter: cd.setDebugTargetVoltage, name: FDebugTargetVoltage},
{length: 2, setter: cd.setDebugTargetCurrent, name: FDebugTargetCurrent}, {length: 10, setter: cd.setDebugTargetCurrent, name: FDebugTargetCurrent},
} }
protocolMap[key] = action{fields: fields, interval: 1000, name: PConverterDebug, object: cd} protocolMap[key] = action{fields: fields, interval: 1000, name: PConverterDebug, object: cd}
} }

@ -41,6 +41,7 @@ type Event struct {
Field FName Field FName
Object Action Object Action
Updated time.Time Updated time.Time
Value any
} }
type action struct { type action struct {
@ -52,16 +53,12 @@ type action struct {
type field struct { type field struct {
length uint8 length uint8
setter func(uint64 uint64) setter func(uint64 uint64) any
value uint64 value uint64
last time.Time last time.Time
name FName name FName
} }
func newField(length uint8, setter func(uint64 uint64), name FName) *field {
return &field{length: length, setter: setter, name: name, value: ^uint64(0)}
}
type key struct { type key struct {
canId uint32 canId uint32
unitId uint unitId uint
@ -119,13 +116,14 @@ func StartProtocolParsing(frames <-chan *can.CanFrame) <-chan *Event {
f.last = now f.last = now
if f.value != val { if f.value != val {
f.value = val f.value = val
f.setter(val) obj := f.setter(val)
result <- &Event{ result <- &Event{
Field: f.name, Field: f.name,
ActionName: param.name, ActionName: param.name,
Object: param.object, Object: param.object,
UnitId: unitId, UnitId: unitId,
Updated: now, Updated: now,
Value: obj,
} }
} }
} }

File diff suppressed because it is too large Load Diff

@ -192,7 +192,7 @@ func (d DebugSwitchModeType) String() string {
case DEBUG_SWITCH_MODE_PERMANENT_ON: case DEBUG_SWITCH_MODE_PERMANENT_ON:
return "PERMANENT_ON" return "PERMANENT_ON"
default: default:
panic("DebugSwitchModeType not defended") return fmt.Sprintf("DebugSwitchModeType_%d", d)
} }
} }

@ -2,252 +2,252 @@ package yabl
type ContactorInternalState struct { type ContactorInternalState struct {
UnitId uint UnitId uint
ContactorReady BoardReadyType ContactorReady *BoardReadyType
ContactorOn BooleanType ContactorOn *BooleanType
UnexpectedState ErrorType UnexpectedState *ErrorType
Isolated ErrorType Isolated *ErrorType
DebugEnabled BooleanType DebugEnabled *BooleanType
} }
type ContactorInternalErrors struct { type ContactorInternalErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
OtherError ContactorInternalOtherErrorType OtherError *ContactorInternalOtherErrorType
ContactorGroupChanged ContactorGroupChangedType ContactorGroupChanged *ContactorGroupChangedType
UnexpectedFormation ContactorInternalOtherErrorType UnexpectedFormation *ContactorInternalOtherErrorType
CpuNotReady ErrorType CpuNotReady *ErrorType
PuNotReady ErrorType PuNotReady *ErrorType
Debug BooleanType Debug *BooleanType
PresentContactorMode ContactorModeType PresentContactorMode *ContactorModeType
} }
type ContactorsInternalForce struct { type ContactorsInternalForce struct {
UnitId uint UnitId uint
ForceModeEnabled BooleanType ForceModeEnabled *BooleanType
ForceModeValue ForceModeType ForceModeValue *ForceModeType
} }
type ContactorInternalDebug struct { type ContactorInternalDebug struct {
UnitId uint UnitId uint
DebugModeOn BooleanType DebugModeOn *BooleanType
DebugContactorOn DebugSwitchModeType DebugContactorOn *DebugSwitchModeType
} }
type PuPresentEnergy struct { type PuPresentEnergy struct {
UnitId uint UnitId uint
V2GMode V2GModeType V2GMode *V2GModeType
VoltageBefore Voltage11BitType VoltageBefore *Voltage11BitType
VoltageAfter Voltage11BitType VoltageAfter *Voltage11BitType
PresentCurrent Current10BitType PresentCurrent *Current10BitType
} }
type PuPeriphery struct { type PuPeriphery struct {
UnitId uint UnitId uint
ConnectorInsert BooleanType ConnectorInsert *BooleanType
ContactorOn BooleanType ContactorOn *BooleanType
ConnectorLocked BooleanType ConnectorLocked *BooleanType
CpLineLevel CpLineLevelType CpLineLevel *CpLineLevelType
IsolationState IsolationStateType IsolationState *IsolationStateType
ChargingAllowed BooleanType ChargingAllowed *BooleanType
PwmEnabled BooleanType PwmEnabled *BooleanType
CpLineVoltage Voltage9BitType CpLineVoltage *Voltage9BitType
} }
type LogicAuth struct { type LogicAuth struct {
UnitId uint UnitId uint
AuthMode AuthModeType AuthMode *AuthModeType
AuthState AuthStateType AuthState *AuthStateType
} }
type LogicEnergyMode struct { type LogicEnergyMode struct {
UnitId uint UnitId uint
V2gMode V2GModeType V2gMode *V2GModeType
CurrentMax Current10BitType CurrentMax *Current10BitType
VoltageMax Voltage11BitType VoltageMax *Voltage11BitType
PowerMax Power14BitType PowerMax *Power14BitType
} }
type LogicErrors struct { type LogicErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
NotReadySettings ErrorType NotReadySettings *ErrorType
} }
type LogicWorkingMode struct { type LogicWorkingMode struct {
UnitId uint UnitId uint
TargetContactorMode ContactorModeType TargetContactorMode *ContactorModeType
Availability BooleanType Availability *BooleanType
} }
type CpuPresentEnergy struct { type CpuPresentEnergy struct {
UnitId uint UnitId uint
PowerDirectionMode V2GModeType PowerDirectionMode *V2GModeType
PresentCurrent Current10BitType PresentCurrent *Current10BitType
PresentVoltage Voltage11BitType PresentVoltage *Voltage11BitType
} }
type CpuPeriphery struct { type CpuPeriphery struct {
UnitId uint UnitId uint
ContactorInput BooleanType ContactorInput *BooleanType
CircuitBreakerInput BooleanType CircuitBreakerInput *BooleanType
CircuitBreakerPowerCBInput BooleanType CircuitBreakerPowerCBInput *BooleanType
} }
type CpuEnergySettings struct { type CpuEnergySettings struct {
UnitId uint UnitId uint
CurrentMax Current10BitType CurrentMax *Current10BitType
VoltageMax Voltage11BitType VoltageMax *Voltage11BitType
PowerMax Power14BitType PowerMax *Power14BitType
TargetBatteryVoltage Voltage11BitType TargetBatteryVoltage *Voltage11BitType
TargetGoalVoltage Voltage11BitType TargetGoalVoltage *Voltage11BitType
} }
type CpuErrors struct { type CpuErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
OtherError OtherError4BitType OtherError *OtherError4BitType
RedButtonHard ErrorType RedButtonHard *ErrorType
RedButtonSoft ErrorType RedButtonSoft *ErrorType
ModulesGone ErrorType ModulesGone *ErrorType
GridVoltageHighErr ErrorType GridVoltageHighErr *ErrorType
GridVoltageHighWarn ErrorType GridVoltageHighWarn *ErrorType
GridVoltageLowWarn ErrorType GridVoltageLowWarn *ErrorType
GridVoltageLowErr ErrorType GridVoltageLowErr *ErrorType
GridVoltageLow Voltage11BitType GridVoltageLow *Voltage11BitType
GridVoltageHigh Voltage11BitType GridVoltageHigh *Voltage11BitType
GridVoltageEmpty ErrorType GridVoltageEmpty *ErrorType
NotReadySecc ErrorType NotReadySecc *ErrorType
NotReadyPu ErrorType NotReadyPu *ErrorType
NotReadyContactors ErrorType NotReadyContactors *ErrorType
DebugConvertersEnabled ErrorType DebugConvertersEnabled *ErrorType
ContactorInputError ErrorType ContactorInputError *ErrorType
NotReadyPeriphery ErrorType NotReadyPeriphery *ErrorType
} }
type CpuDebug struct { type CpuDebug struct {
UnitId uint UnitId uint
DebugModeOn BooleanType DebugModeOn *BooleanType
DebugContactorInputOn DebugSwitchModeType DebugContactorInputOn *DebugSwitchModeType
DebugCircuitBreakerOn DebugSwitchModeType DebugCircuitBreakerOn *DebugSwitchModeType
DebugRedButtonSoftware DebugSwitchModeType DebugRedButtonSoftware *DebugSwitchModeType
} }
type PuErrors struct { type PuErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
OtherError OtherError4BitType OtherError *OtherError4BitType
IncorrectVoltage ErrorType IncorrectVoltage *ErrorType
IncorrectVoltageValue Voltage11BitType IncorrectVoltageValue *Voltage11BitType
IncorrectCurrent ErrorType IncorrectCurrent *ErrorType
IncorrectCurrentValue Current10BitType IncorrectCurrentValue *Current10BitType
IsolationBroken ErrorType IsolationBroken *ErrorType
CpLineBroken ErrorType CpLineBroken *ErrorType
CpLineGap69 ErrorType CpLineGap69 *ErrorType
CableReady BoardReadyType CableReady *BoardReadyType
NotReadyCpu ErrorType NotReadyCpu *ErrorType
NotReadySecc ErrorType NotReadySecc *ErrorType
ContactorOutputError ErrorType ContactorOutputError *ErrorType
DebugContactorOutputEnabled BooleanType DebugContactorOutputEnabled *BooleanType
OutputCircuitBreakerEnabled ErrorType OutputCircuitBreakerEnabled *ErrorType
OutputCircuitBreakerEnabledValue SignedVoltage12bitType OutputCircuitBreakerEnabledValue *SignedVoltage12bitType
} }
type PuDebug struct { type PuDebug struct {
UnitId uint UnitId uint
DebugModeOn BooleanType DebugModeOn *BooleanType
DebugContactorOutputOn DebugSwitchModeType DebugContactorOutputOn *DebugSwitchModeType
} }
type SeccTargetEnergy struct { type SeccTargetEnergy struct {
UnitId uint UnitId uint
TargetChargingAllow BooleanType TargetChargingAllow *BooleanType
TargetBatteryVoltage Voltage11BitType TargetBatteryVoltage *Voltage11BitType
TargetGoalVoltage Voltage11BitType TargetGoalVoltage *Voltage11BitType
TargetCurrent Current10BitType TargetCurrent *Current10BitType
} }
type SeccErrors struct { type SeccErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
NotReadyLogic ErrorType NotReadyLogic *ErrorType
} }
type PeripheryState struct { type PeripheryState struct {
UnitId uint UnitId uint
OtherErrorSeverity BoardReadyType OtherErrorSeverity *BoardReadyType
OtherError OtherError4BitType OtherError *OtherError4BitType
ErrorShakeSensor ErrorType ErrorShakeSensor *ErrorType
ErrorCoolingGroup ErrorType ErrorCoolingGroup *ErrorType
PeripheryErrorCoolingGroup ErrorType PeripheryErrorCoolingGroup *ErrorType
ErrorFireEmergency ErrorType ErrorFireEmergency *ErrorType
ErrorFireEmergencyRun ErrorType ErrorFireEmergencyRun *ErrorType
ErrorFireEmergencyControl ErrorType ErrorFireEmergencyControl *ErrorType
ErrorOvervoltageIn ErrorType ErrorOvervoltageIn *ErrorType
PeripheryErrorPowerSupply ErrorType PeripheryErrorPowerSupply *ErrorType
ErrorFan ErrorType ErrorFan *ErrorType
ErrorOvervoltageOut ErrorType ErrorOvervoltageOut *ErrorType
ErrorStateRemoteMode ErrorType ErrorStateRemoteMode *ErrorType
DebugShsnFanEnabled BooleanType DebugShsnFanEnabled *BooleanType
DebugShptFanEnabled BooleanType DebugShptFanEnabled *BooleanType
DebugIoBoardTestLampEnabled BooleanType DebugIoBoardTestLampEnabled *BooleanType
ErrorFireEmergencyCircuitBreaker ErrorType ErrorFireEmergencyCircuitBreaker *ErrorType
ErrorExtLightCircuitBreaker ErrorType ErrorExtLightCircuitBreaker *ErrorType
ErrorIndicationCircuitBreaker ErrorType ErrorIndicationCircuitBreaker *ErrorType
ErrorLowVoltagePowerCircuitBreaker ErrorType ErrorLowVoltagePowerCircuitBreaker *ErrorType
ErrorContactorsInternalCircuitBreaker ErrorType ErrorContactorsInternalCircuitBreaker *ErrorType
ErrorPlcCircuitBreaker ErrorType ErrorPlcCircuitBreaker *ErrorType
} }
type PeripheryInfo struct { type PeripheryInfo struct {
UnitId uint UnitId uint
InfoDoorOpen BooleanType InfoDoorOpen *BooleanType
TempAirIn SignedAirTemp8BitType TempAirIn *SignedAirTemp8BitType
TempAirOut SignedAirTemp8BitType TempAirOut *SignedAirTemp8BitType
StateShsnFan BooleanType StateShsnFan *BooleanType
StateShptFan BooleanType StateShptFan *BooleanType
} }
type PeripheryDebug struct { type PeripheryDebug struct {
UnitId uint UnitId uint
DebugModeOn BooleanType DebugModeOn *BooleanType
DebugShsnFan DebugSwitchModeType DebugShsnFan *DebugSwitchModeType
DebugShptFan DebugSwitchModeType DebugShptFan *DebugSwitchModeType
DebugIoBoardTestLamp DebugSwitchModeType DebugIoBoardTestLamp *DebugSwitchModeType
} }
type ConverterPresentEnergy struct { type ConverterPresentEnergy struct {
UnitId uint UnitId uint
V2gMode V2GModeType V2gMode *V2GModeType
PresentVoltage Voltage11BitType PresentVoltage *Voltage11BitType
PresentCurrent Current10BitType PresentCurrent *Current10BitType
ConnectedOut ConnectedOut8bitType ConnectedOut *ConnectedOut8bitType
} }
type ConverterErrors struct { type ConverterErrors struct {
UnitId uint UnitId uint
BoardReady BoardReadyType BoardReady *BoardReadyType
OtherError OtherError4BitType OtherError *OtherError4BitType
NotConnectedOut ErrorType NotConnectedOut *ErrorType
NoCommunicationConverter ErrorType NoCommunicationConverter *ErrorType
NoCommunicationPuConverter ErrorType NoCommunicationPuConverter *ErrorType
InputGridVoltageHigh ErrorType InputGridVoltageHigh *ErrorType
InputGridVoltageLow ErrorType InputGridVoltageLow *ErrorType
OutputGridVoltageHigh ErrorType OutputGridVoltageHigh *ErrorType
OutputGridVoltageLow ErrorType OutputGridVoltageLow *ErrorType
InputGridVoltage Voltage11BitType InputGridVoltage *Voltage11BitType
OutputGridVoltage Voltage11BitType OutputGridVoltage *Voltage11BitType
ShortCircuit ErrorType ShortCircuit *ErrorType
OverHeat ErrorType OverHeat *ErrorType
FanBroken ErrorType FanBroken *ErrorType
OtherHardwareError ErrorType OtherHardwareError *ErrorType
DebugConvEnabled BooleanType DebugConvEnabled *BooleanType
DebugConvDisabled BooleanType DebugConvDisabled *BooleanType
} }
type ConverterDebug struct { type ConverterDebug struct {
UnitId uint UnitId uint
DebugModeOn BooleanType DebugModeOn *BooleanType
DebugEnergyOn DebugSwitchModeType DebugEnergyOn *DebugSwitchModeType
DebugTargetVoltage Voltage11BitType DebugTargetVoltage *Voltage11BitType
DebugTargetCurrent Current10BitType DebugTargetCurrent *Current10BitType
} }

Loading…
Cancel
Save