|
|
|
@@ -1,17 +1,16 @@
|
|
|
|
package sver
|
|
|
|
package sver
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"udi/config"
|
|
|
|
"udi/config"
|
|
|
|
"udi/handlers/handler"
|
|
|
|
|
|
|
|
"udi/database"
|
|
|
|
"udi/database"
|
|
|
|
|
|
|
|
"udi/handlers/handler"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type SingleValueExtractorRegexHandler struct {
|
|
|
|
type SingleValueExtractorRegexHandler struct {
|
|
|
|
handler.CommonHandler
|
|
|
|
handler.CommonHandler
|
|
|
|
ready bool
|
|
|
|
ready bool
|
|
|
|
@@ -32,12 +31,12 @@ type localConfig struct {
|
|
|
|
device string
|
|
|
|
device string
|
|
|
|
valueFrom string
|
|
|
|
valueFrom string
|
|
|
|
valuePart int
|
|
|
|
valuePart int
|
|
|
|
|
|
|
|
valueType string
|
|
|
|
unitFrom string
|
|
|
|
unitFrom string
|
|
|
|
unitPart int
|
|
|
|
unitPart int
|
|
|
|
unit string
|
|
|
|
unit string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
|
|
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
|
|
|
t := &SingleValueExtractorRegexHandler{
|
|
|
|
t := &SingleValueExtractorRegexHandler{
|
|
|
|
ready: false,
|
|
|
|
ready: false,
|
|
|
|
@@ -88,6 +87,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
|
|
|
localConfig.valuePart = valuePart
|
|
|
|
localConfig.valuePart = valuePart
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if config.Attributes["valueType"] != "float" && config.Attributes["valueType"] != "string" {
|
|
|
|
|
|
|
|
log.Printf("Error: invalid value %s for valueType", config.Attributes["valueType"])
|
|
|
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
localConfig.valueType = config.Attributes["valueType"]
|
|
|
|
|
|
|
|
|
|
|
|
if config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL {
|
|
|
|
if config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL {
|
|
|
|
log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"])
|
|
|
|
log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"])
|
|
|
|
return t
|
|
|
|
return t
|
|
|
|
@@ -161,6 +166,7 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
|
|
|
variable.Label = ""
|
|
|
|
variable.Label = ""
|
|
|
|
variable.Variable = ""
|
|
|
|
variable.Variable = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var value string
|
|
|
|
switch self.config.valueFrom {
|
|
|
|
switch self.config.valueFrom {
|
|
|
|
case PAYLOAD_SEL:
|
|
|
|
case PAYLOAD_SEL:
|
|
|
|
if self.payloadRegex == nil {
|
|
|
|
if self.payloadRegex == nil {
|
|
|
|
@@ -171,9 +177,19 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
|
|
|
self.Lost("valuePart out of range", nil, message)
|
|
|
|
self.Lost("valuePart out of range", nil, message)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
variable.Value = payloadMatches[self.config.valuePart]
|
|
|
|
value = payloadMatches[self.config.valuePart]
|
|
|
|
case PAYLOAD_FULL_SEL:
|
|
|
|
case PAYLOAD_FULL_SEL:
|
|
|
|
variable.Value = message.Payload
|
|
|
|
value = message.Payload
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.config.valueType == "float" {
|
|
|
|
|
|
|
|
fValue, err := strconv.ParseFloat(value, 64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
self.Lost("Unable to convert value to float", err, message)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
variable.Value = fValue
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
variable.Value = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch self.config.unitFrom {
|
|
|
|
switch self.config.unitFrom {
|
|
|
|
@@ -197,4 +213,3 @@ func (self *SingleValueExtractorRegexHandler) Handle(message handler.MessageT) {
|
|
|
|
self.dbh.StoreMeasurement(&measurement)
|
|
|
|
self.dbh.StoreMeasurement(&measurement)
|
|
|
|
self.S()
|
|
|
|
self.S()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|