Add hostname as tag

pull/3/head
Terekhin Alexandr 2 years ago
parent 234a50adb2
commit 89bf574dec
Signed by: didinst
GPG Key ID: D2EF94423C23BF12
  1. 2
      cli-mon.go
  2. 9
      ui/amqp.go
  3. 8
      ui/amqp_test.go
  4. 2
      ui/table.go
  5. 46
      ui/ui.go
  6. 52
      yabl/init.go
  7. 31
      yabl/protocol.go
  8. 6
      yabl/strings.go
  9. 7
      yabl/types.go

@ -71,7 +71,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
converter := yabl.NewProtocolConverter() converter := yabl.NewProtocolConverter("")
var display ui.UI var display ui.UI

@ -6,14 +6,11 @@ import (
json "encoding/json" json "encoding/json"
"fmt" "fmt"
amqp "github.com/rabbitmq/amqp091-go" amqp "github.com/rabbitmq/amqp091-go"
"os"
"time" "time"
) )
const exchange = "yabl-newproto-in" const exchange = "yabl-newproto-in"
var hostname, _ = os.Hostname()
type broker struct { type broker struct {
uri string uri string
conn *amqp.Connection conn *amqp.Connection
@ -33,9 +30,9 @@ func (b *broker) Consume(event *yabl.Event) {
route := fmt.Sprintf( route := fmt.Sprintf(
"%s.%s.%s.%d", "%s.%s.%s.%d",
hostname, *event.Tag,
event.ActionName, *event.ActionName,
event.Field, *event.Field,
event.GetUnitId()) event.GetUnitId())
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

@ -17,10 +17,14 @@ func TestNewAmqp(t *testing.T) {
client.Start() client.Start()
now := time.Now() now := time.Now()
field := yabl.FBoardReady
action := yabl.PPuErrors
tag := "localhost"
event := &yabl.Event{ event := &yabl.Event{
Field: yabl.FBoardReady, Tag: &tag,
ActionName: yabl.PPuErrors, Field: &field,
ActionName: &action,
Object: nil, Object: nil,
//unit: 3, //unit: 3,
Updated: &now, Updated: &now,

@ -21,7 +21,7 @@ type key struct {
} }
func (t *table) update(event *yabl.Event) { func (t *table) update(event *yabl.Event) {
if cell, ok := t.views[key{event.ActionName, event.Field, event.GetUnitId()}]; ok { if cell, ok := t.views[key{*event.ActionName, *event.Field, event.GetUnitId()}]; ok {
cell.SetText(fmt.Sprintf("%v", event.Value)) cell.SetText(fmt.Sprintf("%v", event.Value))
} }
} }

@ -67,48 +67,6 @@ func (g *gui) Consume(event *yabl.Event) {
g.convertersErrors.update(event) g.convertersErrors.update(event)
g.cpu.update(event) g.cpu.update(event)
switch event.Object.(type) {
case *yabl.PuPresentEnergy:
break
case *yabl.PuPeriphery:
break
case *yabl.PuDebug:
break
case *yabl.PuErrors:
break
case *yabl.ContactorInternalErrors:
break
case *yabl.ContactorInternalDebug:
break
case *yabl.ContactorInternalState:
break
case *yabl.ContactorsInternalForce:
break
case *yabl.PeripheryState:
break
case *yabl.PeripheryInfo:
break
case *yabl.PeripheryDebug:
break
case *yabl.ConverterPresentEnergy:
break
case *yabl.ConverterErrors:
break
case *yabl.ConverterDebug:
break
case *yabl.CpuPresentEnergy:
break
case *yabl.CpuEnergySettings:
break
case *yabl.CpuErrors:
break
case *yabl.CpuPeriphery:
break
case *yabl.CpuDebug:
break
default:
return
}
g.redraw = true g.redraw = true
} }
@ -241,8 +199,8 @@ func (l log) Consume(event *yabl.Event) {
fmt.Printf( fmt.Printf(
"%v %v.%v [%d] %v\n", "%v %v.%v [%d] %v\n",
event.Updated.Format("Jan _2 15:04:05.000"), event.Updated.Format("Jan _2 15:04:05.000"),
event.ActionName, *event.ActionName,
event.Field, *event.Field,
event.GetUnitId(), event.GetUnitId(),
event.Value) event.Value)
} }

@ -1,7 +1,7 @@
package yabl package yabl
func (c *converter) initialize() { func (c *converter) initialize() {
c.protocolMap = make(map[key]action) c.protocolMap = make(map[key]*action)
for i := uint(1); i <= CONNECTOR_COUNT; i++ { for i := uint(1); i <= CONNECTOR_COUNT; i++ {
key := key{CanIdCpuPresentEnergy, i} key := key{CanIdCpuPresentEnergy, i}
@ -12,7 +12,7 @@ func (c *converter) initialize() {
{length: 10, setter: cpe.setPresentCurrent, name: FPresentCurrent}, {length: 10, setter: cpe.setPresentCurrent, name: FPresentCurrent},
{length: 11, setter: cpe.setPresentVoltage, name: FPresentVoltage}, {length: 11, setter: cpe.setPresentVoltage, name: FPresentVoltage},
} }
c.protocolMap[key] = action{fields: fields, interval: 50, name: PCpuPresentEnergy, object: cpe} c.protocolMap[key] = &action{fields: fields, interval: 50, name: PCpuPresentEnergy, object: cpe}
} }
c.cpuPeripheryInstance = &CpuPeriphery{unit: 0} c.cpuPeripheryInstance = &CpuPeriphery{unit: 0}
@ -21,7 +21,7 @@ func (c *converter) initialize() {
{length: 2, setter: c.cpuPeripheryInstance.setCircuitBreakerInput, name: FCircuitBreakerInput}, {length: 2, setter: c.cpuPeripheryInstance.setCircuitBreakerInput, name: FCircuitBreakerInput},
{length: 2, setter: c.cpuPeripheryInstance.setCircuitBreakerPowerCBInput, name: FCircuitBreakerPowerCBInput}, {length: 2, setter: c.cpuPeripheryInstance.setCircuitBreakerPowerCBInput, name: FCircuitBreakerPowerCBInput},
} }
c.protocolMap[key{CanIdCpuPeriphery, 0}] = action{ c.protocolMap[key{CanIdCpuPeriphery, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PCpuPeriphery, name: PCpuPeriphery,
@ -39,7 +39,7 @@ func (c *converter) initialize() {
{length: 11, setter: ces.setTargetBatteryVoltage, name: FTargetBatteryVoltage}, {length: 11, setter: ces.setTargetBatteryVoltage, name: FTargetBatteryVoltage},
{length: 11, setter: ces.setTargetGoalVoltage, name: FTargetGoalVoltage}, {length: 11, setter: ces.setTargetGoalVoltage, name: FTargetGoalVoltage},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PCpuEnergySettings, object: ces} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PCpuEnergySettings, object: ces}
} }
c.cpuErrorsInstance = &CpuErrors{unit: 0} c.cpuErrorsInstance = &CpuErrors{unit: 0}
@ -63,7 +63,7 @@ func (c *converter) initialize() {
{length: 2, setter: c.cpuErrorsInstance.setContactorInputError, name: FContactorInputError}, {length: 2, setter: c.cpuErrorsInstance.setContactorInputError, name: FContactorInputError},
{length: 2, setter: c.cpuErrorsInstance.setNotReadyPeriphery, name: FNotReadyPeriphery}, {length: 2, setter: c.cpuErrorsInstance.setNotReadyPeriphery, name: FNotReadyPeriphery},
} }
c.protocolMap[key{CanIdCpuErrors, 0}] = action{ c.protocolMap[key{CanIdCpuErrors, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PCpuErrors, name: PCpuErrors,
@ -77,7 +77,7 @@ func (c *converter) initialize() {
{length: 3, setter: c.cpuDebugInstance.setDebugCircuitBreakerOn, name: FDebugCircuitBreakerOn}, {length: 3, setter: c.cpuDebugInstance.setDebugCircuitBreakerOn, name: FDebugCircuitBreakerOn},
{length: 3, setter: c.cpuDebugInstance.setDebugRedButtonSoftware, name: FDebugRedButtonSoftware}, {length: 3, setter: c.cpuDebugInstance.setDebugRedButtonSoftware, name: FDebugRedButtonSoftware},
} }
c.protocolMap[key{CanIdCpuDebug, 0}] = action{ c.protocolMap[key{CanIdCpuDebug, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PCpuDebug, name: PCpuDebug,
@ -94,7 +94,7 @@ func (c *converter) initialize() {
{length: 11, setter: ppe.setVoltageAfter, name: FVoltageAfter}, {length: 11, setter: ppe.setVoltageAfter, name: FVoltageAfter},
{length: 10, setter: ppe.setPresentCurrent, name: FPresentCurrent}, {length: 10, setter: ppe.setPresentCurrent, name: FPresentCurrent},
} }
c.protocolMap[key] = action{fields: fields, interval: 50, name: PPuPresentEnergy, object: ppe} c.protocolMap[key] = &action{fields: fields, interval: 50, name: PPuPresentEnergy, object: ppe}
} }
for i := uint(1); i <= CONNECTOR_COUNT; i++ { for i := uint(1); i <= CONNECTOR_COUNT; i++ {
@ -111,7 +111,7 @@ func (c *converter) initialize() {
{length: 2, setter: pp.setPwmEnabled, name: FPwmEnabled}, {length: 2, setter: pp.setPwmEnabled, name: FPwmEnabled},
{length: 9, setter: pp.setCpLineVoltage, name: FCpLineVoltage}, {length: 9, setter: pp.setCpLineVoltage, name: FCpLineVoltage},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PPuPeriphery, object: pp} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PPuPeriphery, object: pp}
} }
for i := uint(1); i <= CONNECTOR_COUNT; i++ { for i := uint(1); i <= CONNECTOR_COUNT; i++ {
@ -136,7 +136,7 @@ func (c *converter) initialize() {
{length: 2, setter: pe.setOutputCircuitBreakerEnabled, name: FOutputCircuitBreakerEnabled}, {length: 2, setter: pe.setOutputCircuitBreakerEnabled, name: FOutputCircuitBreakerEnabled},
{length: 12, setter: pe.setOutputCircuitBreakerEnabledValue, name: FOutputCircuitBreakerEnabledValue}, {length: 12, setter: pe.setOutputCircuitBreakerEnabledValue, name: FOutputCircuitBreakerEnabledValue},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PPuErrors, object: pe} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PPuErrors, object: pe}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -147,7 +147,7 @@ func (c *converter) initialize() {
{length: 2, setter: pd.setDebugModeOn, name: FDebugModeOn}, {length: 2, setter: pd.setDebugModeOn, name: FDebugModeOn},
{length: 3, setter: pd.setDebugContactorOutputOn, name: FDebugContactorOutputOn}, {length: 3, setter: pd.setDebugContactorOutputOn, name: FDebugContactorOutputOn},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PPuDebug, object: pd} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PPuDebug, object: pd}
} }
for i := uint(1); i <= CONNECTOR_COUNT; i++ { for i := uint(1); i <= CONNECTOR_COUNT; i++ {
@ -160,7 +160,7 @@ func (c *converter) initialize() {
{length: 11, setter: ste.setTargetGoalVoltage, name: FTargetGoalVoltage}, {length: 11, setter: ste.setTargetGoalVoltage, name: FTargetGoalVoltage},
{length: 10, setter: ste.setTargetCurrent, name: FTargetCurrent}, {length: 10, setter: ste.setTargetCurrent, name: FTargetCurrent},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PSeccTargetEnergy, object: ste} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PSeccTargetEnergy, object: ste}
} }
for i := uint(1); i <= CONNECTOR_COUNT; i++ { for i := uint(1); i <= CONNECTOR_COUNT; i++ {
@ -171,7 +171,7 @@ func (c *converter) initialize() {
{length: 3, setter: se.setBoardReady, name: FBoardReady}, {length: 3, setter: se.setBoardReady, name: FBoardReady},
{length: 2, setter: se.setNotReadyLogic, name: FNotReadyLogic}, {length: 2, setter: se.setNotReadyLogic, name: FNotReadyLogic},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PSeccErrors, object: se} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PSeccErrors, object: se}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -182,7 +182,7 @@ func (c *converter) initialize() {
{length: 2, setter: la.setAuthMode, name: FAuthMode}, {length: 2, setter: la.setAuthMode, name: FAuthMode},
{length: 3, setter: la.setAuthState, name: FAuthState}, {length: 3, setter: la.setAuthState, name: FAuthState},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PLogicAuth, object: la} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PLogicAuth, object: la}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -195,7 +195,7 @@ func (c *converter) initialize() {
{length: 11, setter: lem.setVoltageMax, name: FVoltageMax}, {length: 11, setter: lem.setVoltageMax, name: FVoltageMax},
{length: 14, setter: lem.setPowerMax, name: FPowerMax}, {length: 14, setter: lem.setPowerMax, name: FPowerMax},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PLogicEnergyMode, object: lem} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PLogicEnergyMode, object: lem}
} }
c.logicErrorsInstance = &LogicErrors{unit: 0} c.logicErrorsInstance = &LogicErrors{unit: 0}
@ -203,7 +203,7 @@ func (c *converter) initialize() {
{length: 3, setter: c.logicErrorsInstance.setBoardReady, name: FBoardReady}, {length: 3, setter: c.logicErrorsInstance.setBoardReady, name: FBoardReady},
{length: 2, setter: c.logicErrorsInstance.setNotReadySettings, name: FNotReadySettings}, {length: 2, setter: c.logicErrorsInstance.setNotReadySettings, name: FNotReadySettings},
} }
c.protocolMap[key{CanIdLogicErrors, 0}] = action{ c.protocolMap[key{CanIdLogicErrors, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PLogicErrors, name: PLogicErrors,
@ -218,7 +218,7 @@ func (c *converter) initialize() {
{length: 5, setter: lwm.setTargetContactorMode, name: FTargetContactorMode}, {length: 5, setter: lwm.setTargetContactorMode, name: FTargetContactorMode},
{length: 2, setter: lwm.setAvailability, name: FAvailability}, {length: 2, setter: lwm.setAvailability, name: FAvailability},
} }
c.protocolMap[key] = action{ c.protocolMap[key] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PLogicWorkingMode, name: PLogicWorkingMode,
@ -237,7 +237,7 @@ func (c *converter) initialize() {
{length: 2, setter: cis.setIsolated, name: FIsolated}, {length: 2, setter: cis.setIsolated, name: FIsolated},
{length: 2, setter: cis.setDebugEnabled, name: FDebugEnabled}, {length: 2, setter: cis.setDebugEnabled, name: FDebugEnabled},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PContactorInternalState, object: cis} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PContactorInternalState, object: cis}
} }
c.contactorInternalErrorsInstance = &ContactorInternalErrors{unit: 0} c.contactorInternalErrorsInstance = &ContactorInternalErrors{unit: 0}
@ -251,7 +251,7 @@ func (c *converter) initialize() {
{length: 2, setter: c.contactorInternalErrorsInstance.setDebug, name: FDebug}, {length: 2, setter: c.contactorInternalErrorsInstance.setDebug, name: FDebug},
{length: 5, setter: c.contactorInternalErrorsInstance.setPresentContactorMode, name: FPresentContactorMode}, {length: 5, setter: c.contactorInternalErrorsInstance.setPresentContactorMode, name: FPresentContactorMode},
} }
c.protocolMap[key{CanIdContIntErr, 0}] = action{ c.protocolMap[key{CanIdContIntErr, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PContactorInternalErrors, name: PContactorInternalErrors,
@ -263,7 +263,7 @@ func (c *converter) initialize() {
{length: 2, setter: c.contactorsInternalForce.setForceModeEnabled, name: FForceModeEnabled}, {length: 2, setter: c.contactorsInternalForce.setForceModeEnabled, name: FForceModeEnabled},
{length: 4, setter: c.contactorsInternalForce.setForceModeValue, name: FForceModeValue}, {length: 4, setter: c.contactorsInternalForce.setForceModeValue, name: FForceModeValue},
} }
c.protocolMap[key{CanIdContIntForce, 0}] = action{ c.protocolMap[key{CanIdContIntForce, 0}] = &action{
fields: fields, fields: fields,
interval: 1000, interval: 1000,
name: PContactorsInternalForce, name: PContactorsInternalForce,
@ -278,7 +278,7 @@ func (c *converter) initialize() {
{length: 2, setter: cid.setDebugModeOn, name: FDebugModeOn}, {length: 2, setter: cid.setDebugModeOn, name: FDebugModeOn},
{length: 3, setter: cid.setDebugContactorOn, name: FDebugContactorOn}, {length: 3, setter: cid.setDebugContactorOn, name: FDebugContactorOn},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PContactorInternalDebug, object: cid} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PContactorInternalDebug, object: cid}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -309,7 +309,7 @@ func (c *converter) initialize() {
{length: 2, setter: ps.setErrorContactorsInternalCircuitBreaker, name: FErrorContactorsInternalCircuitBreaker}, {length: 2, setter: ps.setErrorContactorsInternalCircuitBreaker, name: FErrorContactorsInternalCircuitBreaker},
{length: 2, setter: ps.setErrorPlcCircuitBreaker, name: FErrorPlcCircuitBreaker}, {length: 2, setter: ps.setErrorPlcCircuitBreaker, name: FErrorPlcCircuitBreaker},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PPeripheryState, object: ps} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PPeripheryState, object: ps}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -323,7 +323,7 @@ func (c *converter) initialize() {
{length: 2, setter: pi.setStateShsnFan, name: FStateShsnFan}, {length: 2, setter: pi.setStateShsnFan, name: FStateShsnFan},
{length: 2, setter: pi.setStateShptFan, name: FStateShptFan}, {length: 2, setter: pi.setStateShptFan, name: FStateShptFan},
} }
c.protocolMap[key] = action{fields: fields, interval: 5000, name: PPeripheryInfo, object: pi} c.protocolMap[key] = &action{fields: fields, interval: 5000, name: PPeripheryInfo, object: pi}
} }
for i := uint(0); i <= CONNECTOR_COUNT; i++ { for i := uint(0); i <= CONNECTOR_COUNT; i++ {
@ -336,7 +336,7 @@ func (c *converter) initialize() {
{length: 3, setter: pd.setDebugShptFan, name: FDebugShptFan}, {length: 3, setter: pd.setDebugShptFan, name: FDebugShptFan},
{length: 3, setter: pd.setDebugIoBoardTestLamp, name: FDebugIoBoardTestLamp}, {length: 3, setter: pd.setDebugIoBoardTestLamp, name: FDebugIoBoardTestLamp},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PPeripheryDebug, object: pd} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PPeripheryDebug, object: pd}
} }
for i := uint(1); i < CONVERTERS_MAX; i++ { for i := uint(1); i < CONVERTERS_MAX; i++ {
@ -349,7 +349,7 @@ func (c *converter) initialize() {
{length: 10, setter: cpe.setPresentCurrent, name: FPresentCurrent}, {length: 10, setter: cpe.setPresentCurrent, name: FPresentCurrent},
{length: 8, setter: cpe.setConnectedOut, name: FConnectedOut}, {length: 8, setter: cpe.setConnectedOut, name: FConnectedOut},
} }
c.protocolMap[key] = action{fields: fields, interval: 500, name: PConverterPresentEnergy, object: cpe} c.protocolMap[key] = &action{fields: fields, interval: 500, name: PConverterPresentEnergy, object: cpe}
} }
for i := uint(1); i < CONVERTERS_MAX; i++ { for i := uint(1); i < CONVERTERS_MAX; i++ {
@ -375,7 +375,7 @@ func (c *converter) initialize() {
{length: 2, setter: ce.setDebugConvEnabled, name: FDebugConvEnabled}, {length: 2, setter: ce.setDebugConvEnabled, name: FDebugConvEnabled},
{length: 2, setter: ce.setDebugConvDisabled, name: FDebugConvDisabled}, {length: 2, setter: ce.setDebugConvDisabled, name: FDebugConvDisabled},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PConverterErrors, object: ce} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PConverterErrors, object: ce}
} }
for i := uint(0); i < CONVERTERS_MAX; i++ { for i := uint(0); i < CONVERTERS_MAX; i++ {
@ -388,7 +388,7 @@ func (c *converter) initialize() {
{length: 11, setter: cd.setDebugTargetVoltage, name: FDebugTargetVoltage}, {length: 11, setter: cd.setDebugTargetVoltage, name: FDebugTargetVoltage},
{length: 10, setter: cd.setDebugTargetCurrent, name: FDebugTargetCurrent}, {length: 10, setter: cd.setDebugTargetCurrent, name: FDebugTargetCurrent},
} }
c.protocolMap[key] = action{fields: fields, interval: 1000, name: PConverterDebug, object: cd} c.protocolMap[key] = &action{fields: fields, interval: 1000, name: PConverterDebug, object: cd}
} }
// set "null" values // set "null" values

@ -3,6 +3,7 @@ package yabl
import ( import (
can "cli-mon/can" can "cli-mon/can"
"encoding/binary" "encoding/binary"
"os"
time "time" time "time"
) )
@ -27,7 +28,8 @@ type key struct {
} }
type converter struct { type converter struct {
protocolMap map[key]action tag string
protocolMap map[key]*action
cpuPresentEnergyArray [CONNECTOR_MAX]*CpuPresentEnergy cpuPresentEnergyArray [CONNECTOR_MAX]*CpuPresentEnergy
cpuPeripheryInstance *CpuPeriphery cpuPeripheryInstance *CpuPeriphery
cpuEnergySettingsArray [CONNECTOR_MAX]*CpuEnergySettings cpuEnergySettingsArray [CONNECTOR_MAX]*CpuEnergySettings
@ -60,8 +62,15 @@ type Converter interface {
CheckTimeouts(isOffline bool) ([]*Event, bool) CheckTimeouts(isOffline bool) ([]*Event, bool)
} }
func NewProtocolConverter() Converter { func NewProtocolConverter(tag string) Converter {
c := &converter{} if len(tag) == 0 {
tag = os.Getenv("HOSTNAME")
if len(tag) == 0 {
tag, _ = os.Hostname()
}
}
c := &converter{tag: tag}
c.initialize() c.initialize()
return c return c
} }
@ -86,9 +95,10 @@ func (c *converter) EventsFromFrame(frame *can.CanFrame) ([]*Event, bool) {
obj := f.setter(val) obj := f.setter(val)
event := &Event{ event := &Event{
Field: f.name, Tag: &c.tag,
ActionName: param.name, Field: &f.name,
Object: param.object, ActionName: &param.name,
Object: &param.object,
unit: unit(unitId), unit: unit(unitId),
Updated: frame.Date, Updated: frame.Date,
Value: obj, Value: obj,
@ -148,9 +158,10 @@ func (c *converter) CheckTimeouts(isOffline bool) ([]*Event, bool) {
} }
event := &Event{ event := &Event{
Field: fld.name, Tag: &c.tag,
ActionName: param.name, Field: &fld.name,
Object: param.object, ActionName: &param.name,
Object: &param.object,
unit: unit(k.unitId), unit: unit(k.unitId),
Updated: &deadline, Updated: &deadline,
Value: nil, Value: nil,
@ -169,7 +180,7 @@ func (c *converter) CheckTimeouts(isOffline bool) ([]*Event, bool) {
return events, events != nil return events, events != nil
} }
func getMaxTime(protocolMap *map[key]action) time.Time { func getMaxTime(protocolMap *map[key]*action) time.Time {
now := time.Unix(0, 0) now := time.Unix(0, 0)
for _, param := range *protocolMap { for _, param := range *protocolMap {

@ -218,12 +218,14 @@ func (c ConnectedOut8bitType) String() string {
func (u *Event) MarshalJSON() ([]byte, error) { func (u *Event) MarshalJSON() ([]byte, error) {
return json.Marshal(struct { return json.Marshal(struct {
Host *string
Unit uint Unit uint
ActionName AName ActionName *AName
Field FName Field *FName
Updated *time.Time Updated *time.Time
Value string Value string
}{ }{
Host: u.Tag,
Unit: u.GetUnitId(), Unit: u.GetUnitId(),
ActionName: u.ActionName, ActionName: u.ActionName,
Field: u.Field, Field: u.Field,

@ -13,9 +13,10 @@ type Action interface {
type Event struct { type Event struct {
unit unit
ActionName AName Tag *string
Field FName ActionName *AName
Object Action Field *FName
Object *Action //TODO Actually obj, or copy on event generation time?
Updated *time.Time Updated *time.Time
Value any Value any
} }

Loading…
Cancel
Save