Skip to content

Commit

Permalink
Implement block-specific point definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jan 10, 2020
1 parent 72e24d7 commit b3bf0d8
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 214 deletions.
28 changes: 14 additions & 14 deletions meters/measurement_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions meters/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ const (
HeatSinkTemp

// Strings
String1Current
String1Voltage
String1Power
String1Energy
String2Current
String2Voltage
String2Power
String2Energy
String3Current
String3Voltage
String3Power
String3Energy
DCCurrentS1
DCVoltageS1
DCPowerS1
DCEnergyS1
DCCurrentS2
DCVoltageS2
DCPowerS2
DCEnergyS2
DCCurrentS3
DCVoltageS3
DCPowerS3
DCEnergyS3

// Battery
ChargeState
Expand Down Expand Up @@ -218,18 +218,18 @@ var iec = map[Measurement][]string{
DCVoltage: {"DC Voltage", "V"},
DCPower: {"DC Power", "W"},
HeatSinkTemp: {"Heat Sink Temperature", "°C"},
String1Current: {"String 1 Current", "A"},
String1Voltage: {"String 1 Voltage", "V"},
String1Power: {"String 1 Power", "W"},
String1Energy: {"String 1 Energy", "kWh"},
String2Current: {"String 2 Current", "A"},
String2Voltage: {"String 2 Voltage", "V"},
String2Power: {"String 2 Power", "W"},
String2Energy: {"String 2 Energy", "kWh"},
String3Current: {"String 3 Current", "A"},
String3Voltage: {"String 3 Voltage", "V"},
String3Power: {"String 3 Power", "W"},
String3Energy: {"String 3 Energy", "kWh"},
DCCurrentS1: {"String 1 Current", "A"},
DCVoltageS1: {"String 1 Voltage", "V"},
DCPowerS1: {"String 1 Power", "W"},
DCEnergyS1: {"String 1 Generation", "kWh"},
DCCurrentS2: {"String 2 Current", "A"},
DCVoltageS2: {"String 2 Voltage", "V"},
DCPowerS2: {"String 2 Power", "W"},
DCEnergyS2: {"String 2 Generation", "kWh"},
DCCurrentS3: {"String 3 Current", "A"},
DCVoltageS3: {"String 3 Voltage", "V"},
DCPowerS3: {"String 3 Power", "W"},
DCEnergyS3: {"String 3 Generation", "kWh"},
ChargeState: {"Charge State", "%"},
BatteryVoltage: {"Battery Voltage", "V"},
}
Expand Down
236 changes: 105 additions & 131 deletions meters/sunspec/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sunspec

import (
sunspec "github.com/andig/gosunspec"
"github.com/andig/gosunspec/models/model101"
"github.com/andig/gosunspec/models/model103"
"github.com/andig/gosunspec/models/model124"
Expand All @@ -10,152 +11,125 @@ import (
"github.com/volkszaehler/mbmd/meters"
)

var modelPoints = map[int][]string{
// model- and block-specific opcode measurement mapping
var modelMap = map[sunspec.ModelId]map[int]map[string]meters.Measurement{
// single phase inverter
model101.ModelID: {
model101.A,
model101.AphA,
model101.PhVphA,
model101.Hz,
model101.W,
model101.VA,
model101.VAr,
model101.PF,
model101.WH,
model101.DCA,
model101.DCV,
model101.DCW,
model101.TmpCab,
0: {
model101.A: meters.Current,
model101.AphA: meters.CurrentL1,
model101.PhVphA: meters.VoltageL1,
model101.Hz: meters.Frequency,
model101.W: meters.Power,
model101.VA: meters.ApparentPower,
model101.VAr: meters.ReactivePower,
model101.PF: meters.Cosphi,
model101.WH: meters.Export,
model101.DCA: meters.DCCurrent,
model101.DCV: meters.DCVoltage,
model101.DCW: meters.DCPower,
model101.TmpCab: meters.HeatSinkTemp,
},
},
// three phase inverter
model103.ModelID: {
model103.A,
model103.AphA,
model103.AphB,
model103.AphC,
model103.PhVphA,
model103.PhVphB,
model103.PhVphC,
model103.Hz,
model103.W,
model103.VA,
model103.VAr,
model103.PF,
model103.WH,
model103.DCA,
model103.DCV,
model103.DCW,
model103.TmpCab,
0: {
model103.A: meters.Current,
model103.AphA: meters.CurrentL1,
model103.AphB: meters.CurrentL2,
model103.AphC: meters.CurrentL3,
model103.PhVphA: meters.VoltageL1,
model103.PhVphB: meters.VoltageL2,
model103.PhVphC: meters.VoltageL3,
model103.Hz: meters.Frequency,
model103.W: meters.Power,
model103.VA: meters.ApparentPower,
model103.VAr: meters.ReactivePower,
model103.PF: meters.Cosphi,
model103.WH: meters.Export,
model103.DCA: meters.DCCurrent,
model103.DCV: meters.DCVoltage,
model103.DCW: meters.DCPower,
model103.TmpCab: meters.HeatSinkTemp,
},
},
// MPPT strings
model160.ModelID: {
model160.DCA,
model160.DCV,
model160.DCW,
model160.DCWH,
1: {
model160.DCA: meters.DCCurrentS1,
model160.DCV: meters.DCVoltageS1,
model160.DCW: meters.DCPowerS1,
model160.DCWH: meters.DCEnergyS1,
},
2: {
model160.DCA: meters.DCCurrentS2,
model160.DCV: meters.DCVoltageS2,
model160.DCW: meters.DCPowerS2,
model160.DCWH: meters.DCEnergyS2,
},
3: {
model160.DCA: meters.DCCurrentS3,
model160.DCV: meters.DCVoltageS3,
model160.DCW: meters.DCPowerS3,
model160.DCWH: meters.DCEnergyS3,
},
},
// wye-connect three phase (abcn) meter
model203.ModelID: {
model203.A,
model203.AphA,
model203.AphB,
model203.AphC,
model203.Hz,
model203.PF,
model203.PFphA,
model203.PFphB,
model203.PFphC,
model203.PhV,
model203.PhVphA,
model203.PhVphB,
model203.PhVphC,
model203.TotWhExp,
model203.TotWhExpPhA,
model203.TotWhExpPhB,
model203.TotWhExpPhC,
model203.TotWhImp,
model203.TotWhImpPhA,
model203.TotWhImpPhB,
model203.TotWhImpPhC,
model203.VA,
model203.VAR,
model203.VARphA,
model203.VARphB,
model203.VARphC,
model203.VAphA,
model203.VAphB,
model203.VAphC,
model203.W,
model203.WphA,
model203.WphB,
model203.WphC,
0: {
model203.A: meters.Current,
model203.AphA: meters.CurrentL1,
model203.AphB: meters.CurrentL2,
model203.AphC: meters.CurrentL3,
model203.Hz: meters.Frequency,
model203.PF: meters.Cosphi,
model203.PFphA: meters.CosphiL1,
model203.PFphB: meters.CosphiL2,
model203.PFphC: meters.CosphiL3,
model203.PhV: meters.Voltage,
model203.PhVphA: meters.VoltageL1,
model203.PhVphB: meters.VoltageL2,
model203.PhVphC: meters.VoltageL3,
model203.TotWhExp: meters.Export,
model203.TotWhExpPhA: meters.ExportL1,
model203.TotWhExpPhB: meters.ExportL2,
model203.TotWhExpPhC: meters.ExportL3,
model203.TotWhImp: meters.Import,
model203.TotWhImpPhA: meters.ImportL1,
model203.TotWhImpPhB: meters.ImportL2,
model203.TotWhImpPhC: meters.ImportL3,
model203.VA: meters.ApparentPower,
model203.VAR: meters.ReactivePower,
model203.VARphA: meters.ReactivePowerL1,
model203.VARphB: meters.ReactivePowerL2,
model203.VARphC: meters.ReactivePowerL3,
model203.VAphA: meters.CurrentL1,
model203.VAphB: meters.CurrentL2,
model203.VAphC: meters.CurrentL3,
model203.W: meters.Power,
model203.WphA: meters.PowerL1,
model203.WphB: meters.PowerL2,
model203.WphC: meters.PowerL3,
},
},
// storage
model124.ModelID: {
model124.ChaState,
model124.InBatV,
0: {
model124.ChaState: meters.ChargeState,
model124.InBatV: meters.BatteryVoltage,
},
},
}

var opcodeMap = map[string]meters.Measurement{
model103.A: meters.Current,
model103.AphA: meters.CurrentL1,
model103.AphB: meters.CurrentL2,
model103.AphC: meters.CurrentL3,
model103.DCA: meters.DCCurrent,
model103.DCV: meters.DCVoltage,
model103.DCW: meters.DCPower,
model103.Hz: meters.Frequency,
model103.PF: meters.Cosphi,
model103.PhVphA: meters.VoltageL1,
model103.PhVphB: meters.VoltageL2,
model103.PhVphC: meters.VoltageL3,
model103.TmpCab: meters.HeatSinkTemp,
model103.VA: meters.ApparentPower,
model103.VAr: meters.ReactivePower,
model103.W: meters.Power,
model103.WH: meters.Export,
model124.ChaState: meters.ChargeState,
model124.InBatV: meters.BatteryVoltage,
// model160.DCA: meters.String1DCCurrent,
// model160.DCV: meters.String1DCVoltage,
// model160.DCW: meters.String1DCPower,
model160.DCWH: meters.String1Energy,
// model160.DCA: meters.String2DCCurrent,
// model160.DCV: meters.String2DCVoltage,
// model160.DCW: meters.String2DCPower,
// model160.DCWH: meters.String2DCEnergy,
model203.PFphA: meters.CosphiL1,
model203.PFphB: meters.CosphiL2,
model203.PFphC: meters.CosphiL3,
model203.PhV: meters.Voltage,
model203.TotWhExp: meters.Export,
model203.TotWhExpPhA: meters.ExportL1,
model203.TotWhExpPhB: meters.ExportL2,
model203.TotWhExpPhC: meters.ExportL3,
model203.TotWhImp: meters.Import,
model203.TotWhImpPhA: meters.ImportL1,
model203.TotWhImpPhB: meters.ImportL2,
model203.TotWhImpPhC: meters.ImportL3,
model203.VAphA: meters.ApparentPowerL1,
model203.VAphB: meters.ApparentPowerL2,
model203.VAphC: meters.ApparentPowerL3,
model203.VAR: meters.ReactivePower,
model203.VARphA: meters.ReactivePowerL1,
model203.VARphB: meters.ReactivePowerL2,
model203.VARphC: meters.ReactivePowerL3,
model203.WphA: meters.PowerL1,
model203.WphB: meters.PowerL2,
model203.WphC: meters.PowerL3,
}

var dividerMap = map[meters.Measurement]float64{
meters.Export: 1000,
meters.ExportL1: 1000,
meters.ExportL2: 1000,
meters.ExportL3: 1000,
meters.Import: 1000,
meters.ImportL1: 1000,
meters.ImportL2: 1000,
meters.ImportL3: 1000,
meters.Export: 1000,
meters.ExportL1: 1000,
meters.ExportL2: 1000,
meters.ExportL3: 1000,
meters.Import: 1000,
meters.ImportL1: 1000,
meters.ImportL2: 1000,
meters.ImportL3: 1000,
meters.DCEnergyS1: 1000,
meters.DCEnergyS2: 1000,
meters.DCEnergyS3: 1000,
}
Loading

0 comments on commit b3bf0d8

Please sign in to comment.