Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E3DC native implementation #13413

Merged
merged 39 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cf0c7a0
Add E3DC native implementation
andig Apr 12, 2024
66c8218
wip
andig Apr 12, 2024
0eb2be8
wip
andig Apr 12, 2024
b280e45
wip
andig Apr 12, 2024
2841d0e
wip
andig Apr 12, 2024
3475916
Fix sign, prepare for capacity
andig Apr 13, 2024
27eb212
Update meter/e3dc.go
andig Apr 14, 2024
a3bce87
Add EMS_REQ_POWER_ADD, TAG_BAT_REQ_SPECIFICATION
andig Apr 19, 2024
5bf2b9c
Add capacity request
andig Apr 19, 2024
58c7f3b
Simplify
andig Apr 19, 2024
71fb97e
wip
andig Apr 19, 2024
dafc202
wip
andig Apr 19, 2024
0b46eef
wip
andig Apr 19, 2024
42a1301
wip
andig Apr 19, 2024
1ed54c8
wip
andig Apr 19, 2024
029d9bd
wip
andig Apr 19, 2024
acaf87e
SendMultiple
andig Apr 19, 2024
bbc0f77
wip
andig Apr 19, 2024
1f43447
Merge branch 'master' into feat/e3dc
andig Apr 21, 2024
0816251
Add template
andig Apr 21, 2024
ddeebd6
Add battery mode
andig Apr 21, 2024
6e26fcb
wip
andig Apr 21, 2024
a29fda0
wip
andig Apr 21, 2024
6d3e65c
wip
andig Apr 21, 2024
46dfcdf
Fix template name
andig Apr 21, 2024
993b9e3
Fix uri
andig Apr 21, 2024
bb0dcb3
wip
andig Apr 21, 2024
f95adb9
wip
andig Apr 24, 2024
cf9fbc8
Use log writer
andig Apr 25, 2024
02bef4c
Set debug level
andig Apr 25, 2024
ce83e05
Add battery charge
andig Apr 25, 2024
595b685
Add error handling
andig Apr 25, 2024
5561098
wip
andig Apr 25, 2024
22468fb
Merge branch 'master' into feat/e3dc
andig Apr 25, 2024
c3cdbef
wip
andig Apr 25, 2024
9e12027
Fix uint32
andig Apr 26, 2024
1b28e1a
Fix type
andig Apr 26, 2024
2ea1883
Configurable discharge limit
andig Apr 27, 2024
1edad5c
wip
andig Apr 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ require (
github.com/samber/lo v1.39.0
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/smallnest/chanx v1.2.0
github.com/spali/go-rscp v0.1.2
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/jwalterweatherman v1.1.0
Expand All @@ -90,12 +91,14 @@ require (
github.com/writeas/go-strip-markdown/v2 v2.1.1
gitlab.com/bboehmke/sunny v0.16.0
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.21.0
golang.org/x/crypto/x509roots/fallback v0.0.0-20240318092723-b91329d961d4
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
golang.org/x/net v0.22.0
golang.org/x/oauth2 v0.18.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.19.0
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -109,9 +112,11 @@ require (
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/azihsoyn/rijndael256 v0.0.0-20200316065338-d14eefa2b66b // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cstockton/go-conv v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.16.0 // indirect
Expand Down Expand Up @@ -177,18 +182,17 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/teivah/onecontext v1.3.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/tools v0.19.0
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/aws/aws-sdk-go v1.51.6 h1:Ld36dn9r7P9IjU8WZSaswQ8Y/XUCRpewim5980DwYiU=
github.com/aws/aws-sdk-go v1.51.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/azihsoyn/rijndael256 v0.0.0-20200316065338-d14eefa2b66b h1:/2dABok/UswXOj5rjbR5bZ411ApGBq1pAEZdy5rvFrY=
github.com/azihsoyn/rijndael256 v0.0.0-20200316065338-d14eefa2b66b/go.mod h1:ef+2vMUkiKcy2Tz7HykB01KbgUnkK4gQKq4ZeR4RYVs=
github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw=
github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw=
github.com/basvdlei/gotsmart v0.0.3 h1:7hrI6btBc8dmFzzHRDkr9Xl87PvrrOT43DzbsTFqMk8=
Expand Down Expand Up @@ -97,6 +99,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cstockton/go-conv v1.0.0 h1:zj/q/0MpQ/97XfiC9glWiohO8lhgR4TTnHYZifLTv6I=
github.com/cstockton/go-conv v1.0.0/go.mod h1:HuiHkkRgOA0IoBNPC7ysG7kNpjDYlgM7Kj62yQPxjy4=
github.com/dave/jennifer v1.6.1 h1:T4T/67t6RAA5AIV6+NP8Uk/BIsXgDoqEowgycdQQLuk=
github.com/dave/jennifer v1.6.1/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -191,6 +195,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA=
github.com/goburrow/serial v0.1.0/go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
Expand Down Expand Up @@ -618,6 +624,10 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spali/go-rscp v0.1.2 h1:uw2zEYg1ChPlTqnEJA3NYSgaXGcFMn6fK4jvlTTQTFA=
github.com/spali/go-rscp v0.1.2/go.mod h1:86hwp+MJ83mim+fnSNqadWOo3FYpZnkx8fBBY5JTVNM=
github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127 h1:YDqvwAH/l3S4ZULmKlUYszPyLBjHq73CLuUPU+2jJeE=
github.com/spali/go-slicereader v0.0.0-20201122145524-8e262e1a5127/go.mod h1:nf5bOq6n8UugtmQiD3l0BzkE5VP4NvyngFZVkH3ZzgM=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
Expand Down
130 changes: 130 additions & 0 deletions meter/e3dc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package meter

import (
"time"

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/templates"
"github.com/spali/go-rscp/rscp"
"github.com/spf13/cast"
)

type E3dc struct {
// capacity float64
usage templates.Usage // TODO check if we really want to depend on templates
conn *rscp.Client
}

func init() {
registry.Add("e3dc-2", NewE3dcFromConfig)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateE3dc -b *E3dc -r api.Meter -t "api.Battery,Soc,func() (float64, error)"

func NewE3dcFromConfig(other map[string]interface{}) (api.Meter, error) {
cc := struct {
capacity `mapstructure:",squash"`
Usage templates.Usage
Address string
Port uint16
Username string
Password string
Key string
Timeout time.Duration
}{
Timeout: request.Timeout,
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

cfg := rscp.ClientConfig{
Address: cc.Address,
Port: cc.Port,
Username: cc.Username,
Password: cc.Password,
Key: cc.Key,
ConnectionTimeout: cc.Timeout,
SendTimeout: cc.Timeout,
ReceiveTimeout: cc.Timeout,
}

return NewE3dc(cc.Usage, cfg)
}

func NewE3dc(usage templates.Usage, cfg rscp.ClientConfig) (api.Meter, error) {
// util.NewLogger("e3dc")
conn, err := rscp.NewClient(cfg)
if err != nil {
return nil, err
}

res := &E3dc{
usage: usage,
conn: conn,
}

// decorate api.BatterySoc
var batterySoc func() (float64, error)
// var batteryCapacity func() float64
if usage == templates.UsageBattery {
batterySoc = res.batterySoc
// batteryCapacity = res.batteryCapacity

// const TAG_BAT_REQ_SPECIFICATION = rscp.Tag(0x03000043)
// msg, err := res.conn.Send(*rscp.NewMessage(TAG_BAT_REQ_SPECIFICATION, nil))
// if err != nil {
// return nil, err
// }

// cap, err := cast.ToFloat64E(msg.Value)
// if err != nil {
// return nil, err
// }

// res.capacity = cap / 1e3
}

return decorateE3dc(res, batterySoc), nil
}

func (m *E3dc) CurrentPower() (float64, error) {
var tag rscp.Tag
sign := 1.0

switch m.usage {
case templates.UsageGrid:
tag = rscp.EMS_REQ_POWER_GRID
sign = -1
andig marked this conversation as resolved.
Show resolved Hide resolved
case templates.UsagePV:
andig marked this conversation as resolved.
Show resolved Hide resolved
tag = rscp.EMS_REQ_POWER_PV
case templates.UsageBattery:
tag = rscp.EMS_REQ_POWER_BAT
sign = -1
default:
return 0, api.ErrNotAvailable
}

res, err := m.conn.Send(*rscp.NewMessage(tag, nil))
if err != nil {
return 0, err
}

val, err := cast.ToFloat64E(res.Value)
return sign * val, err
}

// func (m *E3dc) batteryCapacity() float64 {
// return m.capacity
// }

func (m *E3dc) batterySoc() (float64, error) {
res, err := m.conn.Send(*rscp.NewMessage(rscp.EMS_REQ_BAT_SOC, nil))
if err != nil {
return 0, err
}
return cast.ToFloat64E(res.Value)
}
35 changes: 35 additions & 0 deletions meter/e3dc_decorators.go

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

11 changes: 0 additions & 11 deletions util/templates/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ import (
"dario.cat/mergo"
)

type Usage int

//go:generate enumer -type Usage -trimprefix Usage -transform=lower
const (
UsageGrid Usage = iota
UsagePV
UsageBattery
UsageCharge
UsageAux
)

const (
ParamUsage = "usage"
ParamModbus = "modbus"
Expand Down
12 changes: 12 additions & 0 deletions util/templates/usage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package templates

type Usage int

//go:generate enumer -type Usage -trimprefix Usage -transform=lower -text
const (
UsageGrid Usage = iota
UsagePV
UsageBattery
UsageCharge
UsageAux
)
14 changes: 13 additions & 1 deletion util/templates/usage_enumer.go

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