fix(inputs.s7comm): Fix bit queries (#14068)
This commit is contained in:
parent
2d8416cca9
commit
19c3d26d79
2
go.mod
2
go.mod
|
|
@ -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
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -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=
|
||||
|
|
|
|||
|
|
@ -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 == "" {
|
||||
|
|
@ -317,6 +317,21 @@ 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)
|
||||
}
|
||||
if bit < 0 || bit > 7 {
|
||||
// Ensure bit address is valid
|
||||
return nil, nil, fmt.Errorf("invalid extra parameter: bit address %d out of range", bit)
|
||||
}
|
||||
default:
|
||||
if groups["extra"] != "" {
|
||||
return nil, nil, errors.New("extra parameter specified but not used")
|
||||
|
|
@ -348,6 +363,7 @@ func handleFieldAddress(address string) (*gos7.S7DataItem, converterFunc, error)
|
|||
item := &gos7.S7DataItem{
|
||||
Area: area,
|
||||
WordLen: wordlen,
|
||||
Bit: bit,
|
||||
DBNumber: areaidx,
|
||||
Start: start,
|
||||
Amount: amount,
|
||||
|
|
@ -355,7 +371,7 @@ func handleFieldAddress(address string) (*gos7.S7DataItem, converterFunc, error)
|
|||
}
|
||||
|
||||
// Determine the type converter function
|
||||
f := determineConversion(dtype, extra)
|
||||
f := determineConversion(dtype)
|
||||
return item, f, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -258,6 +258,7 @@ func TestFieldMappings(t *testing.T) {
|
|||
{
|
||||
Area: 0x84,
|
||||
WordLen: 0x01,
|
||||
Bit: 2,
|
||||
DBNumber: 5,
|
||||
Start: 3,
|
||||
Amount: 1,
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import (
|
|||
|
||||
var helper = &gos7.Helper{}
|
||||
|
||||
func determineConversion(dtype string, extra int) converterFunc {
|
||||
func determineConversion(dtype string) converterFunc {
|
||||
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{} {
|
||||
|
|
|
|||
Loading…
Reference in New Issue