Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

[RFC] refactor meter opcode definitions #41

Closed
andig opened this issue May 14, 2018 · 2 comments
Closed

[RFC] refactor meter opcode definitions #41

andig opened this issue May 14, 2018 · 2 comments

Comments

@andig
Copy link
Collaborator

andig commented May 14, 2018

Currently, a lot of code is used to define meter opcodes (query snips). This could be greatly reduced by specifying standard "opcodes" and define its mapping register per meter. The approach could use e.g. simple structures like this:

iec61850  := map[string]string{
	"VolLocPhsA":       "L1 Voltage (V)",
	"VolLocPhsB":       "L2 Voltage (V)",
	"VolLocPhsC":       "L3 Voltage (V)",
	"AmpLocPhsA":       "L1 Current (A)",
	"AmpLocPhsB":       "L2 Current (A)",
	"AmpLocPhsC":       "L3 Current (A)",
	"WLocPhsA":         "L1 Power (W)",
	"WLocPhsB":         "L2 Power (W)",
	"WLocPhsC":         "L3 Power (W)",
	"AngLocPhsA":       "L1 Cosphi",
	"AngLocPhsB":       "L2 Cosphi",
	"AngLocPhsC":       "L3 Cosphi",
	"TotkWhImportPhsA": "L1 Import (kWh)",
	"TotkWhImportPhsB": "L2 Import (kWh)",
	"TotkWhImportPhsC": "L3 Import (kWh)",
	"TotkWhImport":     "Total Import (kWh)",
	"TotkWhExportPhsA": "L1 Export (kWh)",
	"TotkWhExportPhsB": "L2 Export (kWh)",
	"TotkWhExportPhsC": "L3 Export (kWh)",
	"TotkWhExport":     "Total Export (kWh)",
	"ThdVolPhsA":       "L1 Voltage to neutral THD (%)",
	"ThdVolPhsB":       "L2 Voltage to neutral THD (%)",
	"ThdVolPhsC":       "L3 Voltage to neutral THD (%)",
	"ThdVol":           "Average voltage to neutral THD (%)",
	"Freq":             "Frequency of supply voltages",
}
fmt.Println(iec61850)

Meter definitions would look like this:

sdm := map[string]int{
	"L1Voltage":   0x0000,
	"L2Voltage":   0x0002,
	"L3Voltage":   0x0004,
	"L1Current":   0x0006,
	"L2Current":   0x0008,
	"L3Current":   0x000A,
	"L1Power":     0x000C,
	"L2Power":     0x000E,
	"L3Power":     0x0010,
	"L1Import":    0x015a,
	"L2Import":    0x015c,
	"L3Import":    0x015e,
	"TotalImport": 0x0048,
	"L1Export":    0x0160,
	"L2Export":    0x0162,
	"L3Export":    0x0164,
	"TotalExport": 0x004a,
	"L1Cosphi":    0x001e,
	"L2Cosphi":    0x0020,
	"L3Cosphi":    0x0022,
	// "L1THDCurrent":         0x00F0,
	// "L2THDCurrent":         0x00F2,
	// "L3THDCurrent":         0x00F4,
	// "AvgTHDCurrent":        0x00Fa,
	"L1THDVoltageNeutral":  0x00ea,
	"L2THDVoltageNeutral":  0x00ec,
	"L3THDVoltageNeutral":  0x00ee,
	"AvgTHDVoltageNeutral": 0x00F8,
	"Frequency":            0x0046,
}
fmt.Println(sdm)

janitza := map[string]int{
	"L1Voltage":   0x4A38,
	"L2Voltage":   0x4A3A,
	"L3Voltage":   0x4A3C,
	"L1Current":   0x4A44,
	"L2Current":   0x4A46,
	"L3Current":   0x4A48,
	"L1Power":     0x4A4C,
	"L2Power":     0x4A4E,
	"L3Power":     0x4A50,
	"L1Import":    0x4A76,
	"L2Import":    0x4A78,
	"L3Import":    0x4A7A,
	"TotalImport": 0x4A7C,
	"L1Export":    0x4A7E,
	"L2Export":    0x4A80,
	"L3Export":    0x4A82,
	"TotalExport": 0x4A84,
	"L1Cosphi":    0x4A64,
	"L2Cosphi":    0x4A66,
	"L3Cosphi":    0x4A68,
}
fmt.Println(janitza)

Defining all QuerySnips per meter (Produce())would then be a simple matter of iterating over the struct.

I'd prefer to combine this with a single naming regime for opcodes. UI and APIs currently use IEC61850 (e.g. VolLocPhsA ), code internally relies on more speaking names like L1Voltage. My preference would be the latter for UI, API and source code.

If this is only applied to the new sdm630 daemon this could be considered a non-breaking change. Opinions welcome.

@andig andig changed the title Idea: refactor meter opcode definitions [RFC] refactor meter opcode definitions May 31, 2018
@andig
Copy link
Collaborator Author

andig commented Jul 25, 2018

Partial implementation in #52

@andig
Copy link
Collaborator Author

andig commented Sep 21, 2018

Full implementation in #69

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant