Skip to content

Commit

Permalink
Make the mpc configurable. And support option stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-prommersberger authored and sthelen-enqs committed Oct 25, 2024
1 parent f818149 commit a82f86c
Show file tree
Hide file tree
Showing 6 changed files with 1,126 additions and 378 deletions.
199 changes: 199 additions & 0 deletions usecases/api/mu_mpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package api

import (
"github.com/enbility/eebus-go/api"
"github.com/enbility/spine-go/model"
"time"
)

// Actor: Monitoring Unit
// UseCase: Monitoring of Power Consumption
type MuMPCInterface interface {
// ------------------------- Getters ------------------------- //

// Scenario 1

// get the momentary active power consumption or production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
Power() (float64, error)

// get the momentary active power consumption or production per phase
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
PowerPerPhase() ([]float64, error)

// Scenario 2

// get the total feed in energy
//
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
EnergyProduced() (float64, error)

// get the total feed in energy
//
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
EnergyConsumed() (float64, error)

// Scenario 3

// get the momentary phase specific current consumption or production
//
// - positive values are used for consumption
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
CurrentPerPhase() ([]float64, error)

// Scenario 4

// get the phase specific voltage details
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
VoltagePerPhase() ([]float64, error)

// Scenario 5

// get frequency
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
Frequency() (float64, error)

// ------------------------- Setters ------------------------- //

// use Update to update the measurement data
// use it like this:
//
// mpc.Update(
// mpc.UpdateDataPowerTotal(1000, nil, nil),
// mpc.UpdateDataPowerPhaseA(500, nil, nil),
// ...
// )
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
Update(data ...api.MeasurementDataForID) error

// Scenario 1

// use UpdateDataPowerTotal in Update to set the momentary active power consumption or production
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataPowerTotal(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataPowerPhaseA in Update to set the momentary active power consumption or production per phase
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataPowerPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataPowerPhaseB in Update to set the momentary active power consumption or production per phase
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataPowerPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataPowerPhaseC in Update to set the momentary active power consumption or production per phase
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataPowerPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// Scenario 2

// use UpdateDataEnergyConsumed in Update to set the total feed in energy
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
// The evaluationStart and End are optional and can be nil (both must be set to be used)
UpdateDataEnergyConsumed(
value float64,
timestamp *time.Time,
valueState *model.MeasurementValueStateType,
evaluationStart *time.Time,
evaluationEnd *time.Time,
) api.MeasurementDataForID

// use UpdateDataEnergyProduced in Update to set the total feed in energy
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
// The evaluationStart and End are optional and can be nil (both must be set to be used)
UpdateDataEnergyProduced(
value float64,
timestamp *time.Time,
valueState *model.MeasurementValueStateType,
evaluationStart *time.Time,
evaluationEnd *time.Time,
) api.MeasurementDataForID

// Scenario 3

// use UpdateDataCurrentPhaseA in Update to set the momentary phase specific current consumption or production
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataCurrentPhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataCurrentPhaseB in Update to set the momentary phase specific current consumption or production
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataCurrentPhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataCurrentPhaseC in Update to set the momentary phase specific current consumption or production
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataCurrentPhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// Scenario 4

// use UpdateDataVoltagePhaseA in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataVoltagePhaseB in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataVoltagePhaseC in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataVoltagePhaseAToB in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseAToB(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataVoltagePhaseBToC in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseBToC(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// use UpdateDataVoltagePhaseCToA in Update to set the phase specific voltage details
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataVoltagePhaseCToA(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID

// Scenario 5

// use AcFrequency in Update to set the frequency
// The timestamp is optional and can be nil
// The valueState shall be set if it differs from the normal valueState otherwise it can be nil
UpdateDataFrequency(value float64, timestamp *time.Time, valueState *model.MeasurementValueStateType) api.MeasurementDataForID
}
95 changes: 95 additions & 0 deletions usecases/mu/mpc/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package mpc

import (
"github.com/enbility/spine-go/model"
"strings"
)

type ConnectedPhases string

const ConnectedPhasesA ConnectedPhases = "a"
const ConnectedPhasesB ConnectedPhases = "b"
const ConnectedPhasesC ConnectedPhases = "c"
const ConnectedPhasesAB ConnectedPhases = "ab"
const ConnectedPhasesBC ConnectedPhases = "bc"
const ConnectedPhasesCA ConnectedPhases = "ac"
const ConnectedPhasesABC ConnectedPhases = "abc"

// MonitorPowerConfig is the configuration for the monitor use case
// This config is required by the mpc use case and must be used in mpc.NewMPC
type MonitorPowerConfig struct {
ConnectedPhases ConnectedPhases // The phases that are measured

ValueSourceTotal *model.MeasurementValueSourceType // The source of the values from the acPowerTotal (not optional)
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values from the acPower for phase A (shall be set if the phase is supported)
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values from the acPower for phase B (shall be set if the phase is supported)
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values from the acPower for phase C (shall be set if the phase is supported)

ValueConstraintsTotal *model.MeasurementConstraintsDataType // The constraints for the acPowerTotal (optional can be nil)
ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the acPower for phase A (optional can be nil)
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the acPower for phase B (optional can be nil)
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the acPower for phase C (optional can be nil)
}

// MonitorEnergyConfig is the configuration for the monitor use case
// If this config is passed via NewMPC, the use case will support energy monitoring as specified
type MonitorEnergyConfig struct {
ValueSourceProduction *model.MeasurementValueSourceType // The source of the production values (if this is set, the use case will support production) (optional can be nil)
ValueConstraintsProduction *model.MeasurementConstraintsDataType // The constraints for the production values (optional can be nil) (needs ProductionValueSource to be set)

ValueSourceConsumption *model.MeasurementValueSourceType // The source of the consumption values (if this is set, the use case will support consumption) (optional can be nil)
ValueConstraintsConsumption *model.MeasurementConstraintsDataType // The constraints for the consumption values (optional can be nil) (needs ConsumptionValueSource to be set)
}

// MonitorCurrentConfig is the configuration for the monitor use case
// If this config is passed via NewMPC, the use case will support current monitoring
// The current phases will be the same as specified in MonitorPowerConfig
type MonitorCurrentConfig struct {
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values for phase A (shall be set if the phase is supported)
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values for phase B (shall be set if the phase is supported)
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values for phase C (shall be set if the phase is supported)

ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the current for phase A (optional can be nil) (needs ValueSourcePhaseA to be set)
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the current for phase B (optional can be nil) (needs ValueSourcePhaseB to be set)
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the current for phase C (optional can be nil) (needs ValueSourcePhaseC to be set)
}

// MonitorVoltageConfig is the configuration for the monitor use case
// If this config is passed via NewMPC, the use case will support voltage monitoring
// The voltage phases will be the same as specified in MonitorPowerConfig
type MonitorVoltageConfig struct {
ValueSourcePhaseA *model.MeasurementValueSourceType // The source of the values for phase A (shall be set if the phase is supported)
ValueSourcePhaseB *model.MeasurementValueSourceType // The source of the values for phase B (shall be set if the phase is supported)
ValueSourcePhaseC *model.MeasurementValueSourceType // The source of the values for phase C (shall be set if the phase is supported)

ValueConstraintsPhaseA *model.MeasurementConstraintsDataType // The constraints for the voltage for phase A (optional can be nil) (needs ValueSourcePhaseA to be set)
ValueConstraintsPhaseB *model.MeasurementConstraintsDataType // The constraints for the voltage for phase B (optional can be nil) (needs ValueSourcePhaseB to be set)
ValueConstraintsPhaseC *model.MeasurementConstraintsDataType // The constraints for the voltage for phase C (optional can be nil) (needs ValueSourcePhaseC to be set)

SupportPhaseToPhase bool // If the use case shall support phase to phase voltage monitoring
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)
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)
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)

ValueConstraintsPhaseAToB *model.MeasurementConstraintsDataType // The constraints for the voltage for phase A to B (optional can be nil) (needs ValueSourcePhaseAToB to be set)
ValueConstraintsPhaseBToC *model.MeasurementConstraintsDataType // The constraints for the voltage for phase B to C (optional can be nil) (needs ValueSourcePhaseBToC to be set)
ValueConstraintsPhaseCToA *model.MeasurementConstraintsDataType // The constraints for the voltage for phase C to A (optional can be nil) (needs ValueSourcePhaseCToA to be set)
}

// MonitorFrequencyConfig is the configuration for the monitor use case
type MonitorFrequencyConfig struct {
ValueSource *model.MeasurementValueSourceType // The source of the values (not optional)
ValueConstraints *model.MeasurementConstraintsDataType // The constraints for the frequency values (optional can be nil)
}

func (c *MonitorPowerConfig) SupportsPhases(phase []string) bool {
phasesString := string(c.ConnectedPhases)
supports := true
for _, p := range phase {
if !strings.Contains(phasesString, p) {
supports = false
break
}
}
return supports
}
Loading

0 comments on commit a82f86c

Please sign in to comment.