Skip to content

Commit a82f86c

Browse files
nils-prommersbergersthelen-enqs
authored andcommitted
Make the mpc configurable. And support option stuff.
1 parent f818149 commit a82f86c

File tree

6 files changed

+1126
-378
lines changed

6 files changed

+1126
-378
lines changed

usecases/api/mu_mpc.go

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package api
2+
3+
import (
4+
"github.com/enbility/eebus-go/api"
5+
"github.com/enbility/spine-go/model"
6+
"time"
7+
)
8+
9+
// Actor: Monitoring Unit
10+
// UseCase: Monitoring of Power Consumption
11+
type MuMPCInterface interface {
12+
// ------------------------- Getters ------------------------- //
13+
14+
// Scenario 1
15+
16+
// get the momentary active power consumption or production
17+
//
18+
// possible errors:
19+
// - ErrMissingData if the id is not available
20+
// - and others
21+
Power() (float64, error)
22+
23+
// get the momentary active power consumption or production per phase
24+
//
25+
// possible errors:
26+
// - ErrMissingData if the id is not available
27+
// - and others
28+
PowerPerPhase() ([]float64, error)
29+
30+
// Scenario 2
31+
32+
// get the total feed in energy
33+
//
34+
// - negative values are used for production
35+
//
36+
// possible errors:
37+
// - ErrMissingData if the id is not available
38+
// - and others
39+
EnergyProduced() (float64, error)
40+
41+
// get the total feed in energy
42+
//
43+
// - negative values are used for production
44+
//
45+
// possible errors:
46+
// - ErrMissingData if the id is not available
47+
// - and others
48+
EnergyConsumed() (float64, error)
49+
50+
// Scenario 3
51+
52+
// get the momentary phase specific current consumption or production
53+
//
54+
// - positive values are used for consumption
55+
// - negative values are used for production
56+
//
57+
// possible errors:
58+
// - ErrMissingData if the id is not available
59+
// - and others
60+
CurrentPerPhase() ([]float64, error)
61+
62+
// Scenario 4
63+
64+
// get the phase specific voltage details
65+
//
66+
// possible errors:
67+
// - ErrMissingData if the id is not available
68+
// - and others
69+
VoltagePerPhase() ([]float64, error)
70+
71+
// Scenario 5
72+
73+
// get frequency
74+
//
75+
// possible errors:
76+
// - ErrMissingData if the id is not available
77+
// - and others
78+
Frequency() (float64, error)
79+
80+
// ------------------------- Setters ------------------------- //
81+
82+
// use Update to update the measurement data
83+
// use it like this:
84+
//
85+
// mpc.Update(
86+
// mpc.UpdateDataPowerTotal(1000, nil, nil),
87+
// mpc.UpdateDataPowerPhaseA(500, nil, nil),
88+
// ...
89+
// )
90+
//
91+
// possible errors:
92+
// - ErrMissingData if the id is not available
93+
// - and others
94+
Update(data ...api.MeasurementDataForID) error
95+
96+
// Scenario 1
97+
98+
// use UpdateDataPowerTotal in Update to set the momentary active power consumption or production
99+
// The timestamp is optional and can be nil
100+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
101+
UpdateDataPowerTotal(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
102+
103+
// use UpdateDataPowerPhaseA in Update to set the momentary active power consumption or production per phase
104+
// The timestamp is optional and can be nil
105+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
106+
UpdateDataPowerPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
107+
108+
// use UpdateDataPowerPhaseB in Update to set the momentary active power consumption or production per phase
109+
// The timestamp is optional and can be nil
110+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
111+
UpdateDataPowerPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
112+
113+
// use UpdateDataPowerPhaseC in Update to set the momentary active power consumption or production per phase
114+
// The timestamp is optional and can be nil
115+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
116+
UpdateDataPowerPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
117+
118+
// Scenario 2
119+
120+
// use UpdateDataEnergyConsumed in Update to set the total feed in energy
121+
// The timestamp is optional and can be nil
122+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
123+
// The evaluationStart and End are optional and can be nil (both must be set to be used)
124+
UpdateDataEnergyConsumed(
125+
value float64,
126+
timestamp *time.Time,
127+
valueState *model.MeasurementValueStateType,
128+
evaluationStart *time.Time,
129+
evaluationEnd *time.Time,
130+
) api.MeasurementDataForID
131+
132+
// use UpdateDataEnergyProduced in Update to set the total feed in energy
133+
// The timestamp is optional and can be nil
134+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
135+
// The evaluationStart and End are optional and can be nil (both must be set to be used)
136+
UpdateDataEnergyProduced(
137+
value float64,
138+
timestamp *time.Time,
139+
valueState *model.MeasurementValueStateType,
140+
evaluationStart *time.Time,
141+
evaluationEnd *time.Time,
142+
) api.MeasurementDataForID
143+
144+
// Scenario 3
145+
146+
// use UpdateDataCurrentPhaseA in Update to set the momentary phase specific current consumption or production
147+
// The timestamp is optional and can be nil
148+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
149+
UpdateDataCurrentPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
150+
151+
// use UpdateDataCurrentPhaseB in Update to set the momentary phase specific current consumption or production
152+
// The timestamp is optional and can be nil
153+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
154+
UpdateDataCurrentPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
155+
156+
// use UpdateDataCurrentPhaseC in Update to set the momentary phase specific current consumption or production
157+
// The timestamp is optional and can be nil
158+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
159+
UpdateDataCurrentPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
160+
161+
// Scenario 4
162+
163+
// use UpdateDataVoltagePhaseA in Update to set the phase specific voltage details
164+
// The timestamp is optional and can be nil
165+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
166+
UpdateDataVoltagePhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
167+
168+
// use UpdateDataVoltagePhaseB in Update to set the phase specific voltage details
169+
// The timestamp is optional and can be nil
170+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
171+
UpdateDataVoltagePhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
172+
173+
// use UpdateDataVoltagePhaseC in Update to set the phase specific voltage details
174+
// The timestamp is optional and can be nil
175+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
176+
UpdateDataVoltagePhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
177+
178+
// use UpdateDataVoltagePhaseAToB in Update to set the phase specific voltage details
179+
// The timestamp is optional and can be nil
180+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
181+
UpdateDataVoltagePhaseAToB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
182+
183+
// use UpdateDataVoltagePhaseBToC in Update to set the phase specific voltage details
184+
// The timestamp is optional and can be nil
185+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
186+
UpdateDataVoltagePhaseBToC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
187+
188+
// use UpdateDataVoltagePhaseCToA in Update to set the phase specific voltage details
189+
// The timestamp is optional and can be nil
190+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
191+
UpdateDataVoltagePhaseCToA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
192+
193+
// Scenario 5
194+
195+
// use AcFrequency in Update to set the frequency
196+
// The timestamp is optional and can be nil
197+
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
198+
UpdateDataFrequency(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
199+
}

usecases/mu/mpc/config.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package mpc
2+
3+
import (
4+
"github.com/enbility/spine-go/model"
5+
"strings"
6+
)
7+
8+
type ConnectedPhases string
9+
10+
const ConnectedPhasesA ConnectedPhases = "a"
11+
const ConnectedPhasesB ConnectedPhases = "b"
12+
const ConnectedPhasesC ConnectedPhases = "c"
13+
const ConnectedPhasesAB ConnectedPhases = "ab"
14+
const ConnectedPhasesBC ConnectedPhases = "bc"
15+
const ConnectedPhasesCA ConnectedPhases = "ac"
16+
const ConnectedPhasesABC ConnectedPhases = "abc"
17+
18+
// MonitorPowerConfig is the configuration for the monitor use case
19+
// This config is required by the mpc use case and must be used in mpc.NewMPC
20+
type MonitorPowerConfig struct {
21+
ConnectedPhases ConnectedPhases // The phases that are measured
22+
23+
ValueSourceTotal *model.MeasurementValueSourceType // The source of the values from the acPowerTotal (not optional)
24+
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values from the acPower for phase A (shall be set if the phase is supported)
25+
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values from the acPower for phase B (shall be set if the phase is supported)
26+
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values from the acPower for phase C (shall be set if the phase is supported)
27+
28+
ValueConstraintsTotal *model.MeasurementConstraintsDataType // The constraints for the acPowerTotal (optional can be nil)
29+
ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the acPower for phase A (optional can be nil)
30+
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the acPower for phase B (optional can be nil)
31+
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the acPower for phase C (optional can be nil)
32+
}
33+
34+
// MonitorEnergyConfig is the configuration for the monitor use case
35+
// If this config is passed via NewMPC, the use case will support energy monitoring as specified
36+
type MonitorEnergyConfig struct {
37+
ValueSourceProduction *model.MeasurementValueSourceType // The source of the production values (if this is set, the use case will support production) (optional can be nil)
38+
ValueConstraintsProduction *model.MeasurementConstraintsDataType // The constraints for the production values (optional can be nil) (needs ProductionValueSource to be set)
39+
40+
ValueSourceConsumption *model.MeasurementValueSourceType // The source of the consumption values (if this is set, the use case will support consumption) (optional can be nil)
41+
ValueConstraintsConsumption *model.MeasurementConstraintsDataType // The constraints for the consumption values (optional can be nil) (needs ConsumptionValueSource to be set)
42+
}
43+
44+
// MonitorCurrentConfig is the configuration for the monitor use case
45+
// If this config is passed via NewMPC, the use case will support current monitoring
46+
// The current phases will be the same as specified in MonitorPowerConfig
47+
type MonitorCurrentConfig struct {
48+
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values for phase A (shall be set if the phase is supported)
49+
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values for phase B (shall be set if the phase is supported)
50+
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values for phase C (shall be set if the phase is supported)
51+
52+
ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the current for phase A (optional can be nil) (needs ValueSourcePhaseA to be set)
53+
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the current for phase B (optional can be nil) (needs ValueSourcePhaseB to be set)
54+
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the current for phase C (optional can be nil) (needs ValueSourcePhaseC to be set)
55+
}
56+
57+
// MonitorVoltageConfig is the configuration for the monitor use case
58+
// If this config is passed via NewMPC, the use case will support voltage monitoring
59+
// The voltage phases will be the same as specified in MonitorPowerConfig
60+
type MonitorVoltageConfig struct {
61+
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values for phase A (shall be set if the phase is supported)
62+
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values for phase B (shall be set if the phase is supported)
63+
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values for phase C (shall be set if the phase is supported)
64+
65+
ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the voltage for phase A (optional can be nil) (needs ValueSourcePhaseA to be set)
66+
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the voltage for phase B (optional can be nil) (needs ValueSourcePhaseB to be set)
67+
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the voltage for phase C (optional can be nil) (needs ValueSourcePhaseC to be set)
68+
69+
SupportPhaseToPhase bool // If the use case shall support phase to phase voltage monitoring
70+
ValueSourcePhaseAToB *model.MeasurementValueSourceType // The source of the values for phase A to B (shall be set if the phases are supported and SupportPhaseToPhase is true)
71+
ValueSourcePhaseBToC *model.MeasurementValueSourceType // The source of the values for phase B to C (shall be set if the phases are supported and SupportPhaseToPhase is true)
72+
ValueSourcePhaseCToA *model.MeasurementValueSourceType // The source of the values for phase C to A (shall be set if the phases are supported and SupportPhaseToPhase is true)
73+
74+
ValueConstraintsPhaseAToB *model.MeasurementConstraintsDataType // The constraints for the voltage for phase A to B (optional can be nil) (needs ValueSourcePhaseAToB to be set)
75+
ValueConstraintsPhaseBToC *model.MeasurementConstraintsDataType // The constraints for the voltage for phase B to C (optional can be nil) (needs ValueSourcePhaseBToC to be set)
76+
ValueConstraintsPhaseCToA *model.MeasurementConstraintsDataType // The constraints for the voltage for phase C to A (optional can be nil) (needs ValueSourcePhaseCToA to be set)
77+
}
78+
79+
// MonitorFrequencyConfig is the configuration for the monitor use case
80+
type MonitorFrequencyConfig struct {
81+
ValueSource *model.MeasurementValueSourceType // The source of the values (not optional)
82+
ValueConstraints *model.MeasurementConstraintsDataType // The constraints for the frequency values (optional can be nil)
83+
}
84+
85+
func (c *MonitorPowerConfig) SupportsPhases(phase []string) bool {
86+
phasesString := string(c.ConnectedPhases)
87+
supports := true
88+
for _, p := range phase {
89+
if !strings.Contains(phasesString, p) {
90+
supports = false
91+
break
92+
}
93+
}
94+
return supports
95+
}

0 commit comments

Comments
 (0)