Skip to content

Commit

Permalink
Fix sunspec configuration (#185)
Browse files Browse the repository at this point in the history
andig authored May 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 71a4afa commit a511449
Showing 6 changed files with 27 additions and 21 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -359,7 +359,6 @@ type: ...
uri/device/id: ...
register:
address: 40070
length: 2 # read length in words
type: holding # holding or input
decode: int32 # int16|32|64, uint16|32|64, float32|64 and u|int32s + float32s
scale: -1 # floating point factor applied to result, e.g. for kW to W conversion
1 change: 0 additions & 1 deletion evcc.dist.yaml
Original file line number Diff line number Diff line change
@@ -87,7 +87,6 @@ meters:
id: 1
register: # manual register configuration
address: 40070
length: 2
type: holding
decode: int32
scale: -1 # reverse direction
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ require (
github.com/spf13/viper v1.6.3
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed
github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 // indirect
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -251,8 +251,8 @@ github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQ
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed h1:oC2QZlpY+AbEPn/8TWvO4FiXrk9uHhCyT24b6wwa/JA=
github.com/volkszaehler/mbmd v0.0.0-20200524120609-c683601720ed/go.mod h1:MmglPXoZJOT0r+tWwAjaaRWmuopdQOq2tWxbL9zvuxE=
github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a h1:OURwSCpbOBMInNnNE7rmyDpvx/mK7CgZo2UhU6HDvRY=
github.com/volkszaehler/mbmd v0.0.0-20200524133250-a64175ed6a8a/go.mod h1:MmglPXoZJOT0r+tWwAjaaRWmuopdQOq2tWxbL9zvuxE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
37 changes: 23 additions & 14 deletions provider/modbus.go
Original file line number Diff line number Diff line change
@@ -46,6 +46,29 @@ func NewModbusFromConfig(log *util.Logger, typ string, other map[string]interfac
var device meters.Device
var op modbus.Operation

if cc.Value != "" && cc.Register.Decode != "" {
log.FATAL.Fatalf("config: modbus cannot have value and register both")
}

// model + value configured
if cc.Value != "" {
if err := modbus.ParseOperation(device, cc.Value, &op); err != nil {
log.FATAL.Fatalf("config: invalid value %s", cc.Value)
}

// if sunspec reading configured make sure model is defined or device won't be initalized
if op.SunSpec.Point != "" && cc.Model == "" {
cc.Model = "SunSpec"
}
}

// register configured
if cc.Register.Decode != "" {
if op.MBMD, err = modbus.RegisterOperation(cc.Register); err != nil {
log.TRACE.Fatal(err)
}
}

// model configured
if cc.Model != "" {
device, err = modbus.NewDevice(log, cc.Model, *cc.RTU)
@@ -65,20 +88,6 @@ func NewModbusFromConfig(log *util.Logger, typ string, other map[string]interfac
log.FATAL.Fatal(err)
}

// model + value configured
if cc.Value != "" {
if err := modbus.ParseOperation(device, cc.Value, &op); err != nil {
log.FATAL.Fatalf("invalid value %s", cc.Value)
}
}

// register configured
if cc.Register.Decode != "" {
if op.MBMD, err = modbus.RegisterOperation(cc.Register); err != nil {
log.TRACE.Fatal(err)
}
}

if cc.Scale == 0 {
cc.Scale = 1
}
3 changes: 1 addition & 2 deletions util/modbus/modbus.go
Original file line number Diff line number Diff line change
@@ -195,8 +195,7 @@ type Operation struct {
func ParseOperation(dev meters.Device, measurement string, op *Operation) (err error) {
// if measurement cannot be parsed it could be SunSpec model/block/point
if op.MBMD.IEC61850, err = meters.MeasurementString(measurement); err != nil {
opSunSpec := &SunSpecOperation{}
opSunSpec.Model, opSunSpec.Block, opSunSpec.Point, err = ParsePoint(measurement)
op.SunSpec.Model, op.SunSpec.Block, op.SunSpec.Point, err = ParsePoint(measurement)
return err
}

0 comments on commit a511449

Please sign in to comment.