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

fix(inputs.s7comm): Fix bit queries #14068

Merged
merged 14 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ require (
github.com/redis/go-redis/v9 v9.2.1
github.com/riemann/riemann-go-client v0.5.1-0.20211206220514-f58f10cdce16
github.com/robbiet480/go.nut v0.0.0-20220219091450-bd8f121e1fa1
github.com/robinson/gos7 v0.0.0-20231012111941-bdaa10e92e16
github.com/robinson/gos7 v0.0.0-20231031082500-fb5a72fd499e
github.com/safchain/ethtool v0.3.0
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/sensu/sensu-go/api/core/v2 v2.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2039,8 +2039,8 @@ github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff h1:+6NUiITWwE5q1
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/robinson/gos7 v0.0.0-20231012111941-bdaa10e92e16 h1:bhgGFmhTZpESybQyk+uxZ+dAd3yNSJSano2fN7HGmlA=
github.com/robinson/gos7 v0.0.0-20231012111941-bdaa10e92e16/go.mod h1:AMHIeh1KJ7Xa2RVOMHdv9jXKrpw0D4EWGGQMHLb2doc=
github.com/robinson/gos7 v0.0.0-20231031082500-fb5a72fd499e h1:Ofp6C2iX58K698sGpIXZFp3furntNlhIjeyLkcrAiek=
github.com/robinson/gos7 v0.0.0-20231031082500-fb5a72fd499e/go.mod h1:AMHIeh1KJ7Xa2RVOMHdv9jXKrpw0D4EWGGQMHLb2doc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s=
Expand Down
19 changes: 17 additions & 2 deletions plugins/inputs/s7comm/s7comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ func handleFieldAddress(address string) (*gos7.S7DataItem, converterFunc, error)
}

// Check the amount parameter if any
var extra int
var extra, bit int
switch dtype {
case "X", "S":
case "S":
// We require an extra parameter
x := groups["extra"]
if x == "" {
Expand All @@ -317,6 +317,20 @@ func handleFieldAddress(address string) (*gos7.S7DataItem, converterFunc, error)
if extra < 1 {
return nil, nil, fmt.Errorf("invalid extra parameter %d", extra)
}
case "X":
// We require an extra parameter
x := groups["extra"]
if x == "" {
return nil, nil, errors.New("extra parameter required")
}

bit, err = strconv.Atoi(x)
if err != nil {
return nil, nil, fmt.Errorf("invalid extra parameter: %w", err)
} else if extra < 0 || extra > 7 {
// Ensure bit address is valid
return nil, nil, fmt.Errorf("invalid extra parameter %d, bit address out of range", extra)
phagemann marked this conversation as resolved.
Show resolved Hide resolved
}
default:
if groups["extra"] != "" {
return nil, nil, errors.New("extra parameter specified but not used")
Expand Down Expand Up @@ -348,6 +362,7 @@ func handleFieldAddress(address string) (*gos7.S7DataItem, converterFunc, error)
item := &gos7.S7DataItem{
Area: area,
WordLen: wordlen,
Bit: bit,
DBNumber: areaidx,
Start: start,
Amount: amount,
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/s7comm/s7comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func TestFieldMappings(t *testing.T) {
{
Area: 0x84,
WordLen: 0x01,
Bit: 2,
DBNumber: 5,
Start: 3,
Amount: 1,
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/s7comm/type_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

var helper = &gos7.Helper{}

func determineConversion(dtype string, extra int) converterFunc {
func determineConversion(dtype string, _ int) converterFunc {
phagemann marked this conversation as resolved.
Show resolved Hide resolved
switch dtype {
case "X":
return func(buf []byte) interface{} {
return (buf[0] & (1 << extra)) != 0
return buf[0] != 0
}
case "B":
return func(buf []byte) interface{} {
Expand Down
Loading