dt1t and counter and refactoring using embedded interfaces
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
2023-12-21 13:05:00 +01:00
parent 99d678b4b1
commit 8e6bea3f19
15 changed files with 276 additions and 174 deletions

View File

@ -1,10 +1,8 @@
package pv
import (
"log"
"reflect"
"time"
"fmt"
"encoding/json"
"udi/config"
"udi/handlers/handler"
@ -12,10 +10,8 @@ import (
)
var idSeq int = 0
type PvHandler struct {
id int
handler.CommonHandler
dbh *database.DatabaseHandle
}
@ -40,18 +36,14 @@ type PvValue struct {
}
func NewPvHandler(config config.HandlerConfigT) handler.Handler {
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &PvHandler {
id: idSeq,
}
idSeq += 1
t.Id = id
t.dbh = database.NewDatabaseHandle()
return t
}
func (self *PvHandler) GetId() string {
return fmt.Sprintf("PV%d", self.id)
}
func (self *PvHandler) Handle(message handler.MessageT) {
//log.Printf("Handler PV %d processing %s -> %s", self.id, message.Topic, message.Payload)
@ -59,7 +51,7 @@ func (self *PvHandler) Handle(message handler.MessageT) {
var pvValue PvValue
err := json.Unmarshal([]byte(message.Payload), &pvValue)
if err != nil {
log.Printf("Unable to parse payload into pvValue struct, message %s -> %s is lost, error: %s", message.Topic, message.Payload, err)
self.Lost("Unable to parse payload into pvValue struct", err, message)
return
}
@ -85,6 +77,7 @@ func (self *PvHandler) Handle(message handler.MessageT) {
}
self.dbh.StoreMeasurement(&measurement)
self.S()
}