Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 002c487

Browse files
committed
Update DemoCEM
- Set default values for LPCServer - Properly register RemoteSKI - Add console logging
1 parent 6e5928b commit 002c487

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

cmd/democem/democem.go

+78-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package democem
22

33
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/enbility/cemd/api"
48
"github.com/enbility/cemd/cem"
59
"github.com/enbility/cemd/ucevsecc"
610
"github.com/enbility/cemd/uclpcserver"
@@ -10,13 +14,16 @@ import (
1014

1115
type DemoCem struct {
1216
cem *cem.Cem
17+
18+
remoteSki string
1319
}
1420

15-
func NewDemoCem(configuration *eebusapi.Configuration) *DemoCem {
16-
demo := &DemoCem{}
21+
func NewDemoCem(configuration *eebusapi.Configuration, remoteSki string) *DemoCem {
22+
demo := &DemoCem{
23+
remoteSki: remoteSki,
24+
}
1725

18-
noLogging := &logging.NoLogging{}
19-
demo.cem = cem.NewCEM(configuration, demo, demo.deviceEventCB, noLogging)
26+
demo.cem = cem.NewCEM(configuration, demo, demo.deviceEventCB, demo)
2027

2128
return demo
2229
}
@@ -29,10 +36,77 @@ func (d *DemoCem) Setup() error {
2936
lpcs := uclpcserver.NewUCLPC(d.cem.Service, d.entityEventCB)
3037
d.cem.AddUseCase(lpcs)
3138

39+
if err := lpcs.SetLoadControlLimit(api.LoadLimit{
40+
IsChangeable: true,
41+
IsActive: false,
42+
Value: 0,
43+
}); err != nil {
44+
logging.Log().Debug(err)
45+
}
46+
if err := lpcs.SetContractualConsumptionNominalMax(22000); err != nil {
47+
logging.Log().Debug(err)
48+
}
49+
if err := lpcs.SetFailsafeConsumptionActivePowerLimit(4300, true); err != nil {
50+
logging.Log().Debug(err)
51+
}
52+
if err := lpcs.SetFailsafeDurationMinimum(time.Hour*2, true); err != nil {
53+
logging.Log().Debug(err)
54+
}
55+
3256
evsecc := ucevsecc.NewUCEVSECC(d.cem.Service, d.entityEventCB)
3357
d.cem.AddUseCase(evsecc)
3458

59+
d.cem.Service.RegisterRemoteSKI(d.remoteSki, true)
60+
3561
d.cem.Start()
3662

3763
return nil
3864
}
65+
66+
// Logging interface
67+
68+
func (d *DemoCem) Trace(args ...interface{}) {
69+
d.print("TRACE", args...)
70+
}
71+
72+
func (d *DemoCem) Tracef(format string, args ...interface{}) {
73+
d.printFormat("TRACE", format, args...)
74+
}
75+
76+
func (d *DemoCem) Debug(args ...interface{}) {
77+
d.print("DEBUG", args...)
78+
}
79+
80+
func (d *DemoCem) Debugf(format string, args ...interface{}) {
81+
d.printFormat("DEBUG", format, args...)
82+
}
83+
84+
func (d *DemoCem) Info(args ...interface{}) {
85+
d.print("INFO ", args...)
86+
}
87+
88+
func (d *DemoCem) Infof(format string, args ...interface{}) {
89+
d.printFormat("INFO ", format, args...)
90+
}
91+
92+
func (d *DemoCem) Error(args ...interface{}) {
93+
d.print("ERROR", args...)
94+
}
95+
96+
func (d *DemoCem) Errorf(format string, args ...interface{}) {
97+
d.printFormat("ERROR", format, args...)
98+
}
99+
100+
func (d *DemoCem) currentTimestamp() string {
101+
return time.Now().Format("2006-01-02 15:04:05")
102+
}
103+
104+
func (d *DemoCem) print(msgType string, args ...interface{}) {
105+
value := fmt.Sprintln(args...)
106+
fmt.Printf("%s %s %s", d.currentTimestamp(), msgType, value)
107+
}
108+
109+
func (d *DemoCem) printFormat(msgType, format string, args ...interface{}) {
110+
value := fmt.Sprintf(format, args...)
111+
fmt.Println(d.currentTimestamp(), msgType, value)
112+
}

cmd/main.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/enbility/cemd/cmd/democem"
1717
eebusapi "github.com/enbility/eebus-go/api"
1818
"github.com/enbility/ship-go/cert"
19+
"github.com/enbility/ship-go/mdns"
1920
"github.com/enbility/spine-go/model"
2021
)
2122

@@ -65,10 +66,10 @@ func main() {
6566
}
6667

6768
configuration, err := eebusapi.NewConfiguration(
68-
"Demo",
69-
"Demo",
70-
"HEMS",
71-
"123456789",
69+
"eSystems",
70+
"eSystems",
71+
"Wallbox",
72+
"00000573",
7273
model.DeviceTypeTypeEnergyManagementSystem,
7374
[]model.EntityTypeType{model.EntityTypeTypeCEM},
7475
*port,
@@ -80,13 +81,17 @@ func main() {
8081
return
8182
}
8283

84+
configuration.SetAlternateIdentifier("eSystems-Wallbox-00000573")
85+
configuration.SetMdnsProviderSelection(mdns.MdnsProviderSelectionGoZeroConfOnly)
86+
8387
if iface != nil && *iface != "" {
8488
ifaces := []string{*iface}
8589

8690
configuration.SetInterfaces(ifaces)
8791
}
8892

89-
demo := democem.NewDemoCem(configuration)
93+
demo := democem.NewDemoCem(configuration, *remoteSki)
94+
9095
if err := demo.Setup(); err != nil {
9196
fmt.Println("Error setting up cem: ", err)
9297
return

0 commit comments

Comments
 (0)