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,11 +1,8 @@
package mbgw3
import (
"log"
//"reflect"
"time"
"strconv"
"fmt"
"encoding/json"
"udi/config"
"udi/handlers/handler"
@ -13,10 +10,8 @@ import (
)
var idSeq int = 0
type Mbgw3Handler struct {
id int
handler.CommonHandler
dbh *database.DatabaseHandle
}
@ -31,26 +26,21 @@ type Observation struct {
}
func NewMbgw3Handler(config config.HandlerConfigT) handler.Handler {
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &Mbgw3Handler {
id: idSeq,
}
idSeq += 1
t.Id = id
t.dbh = database.NewDatabaseHandle()
return t
}
func (self *Mbgw3Handler) GetId() string {
return fmt.Sprintf("MBGW3%d", self.id)
}
func (self *Mbgw3Handler) Handle(message handler.MessageT) {
// log.Printf("Handler MBGW3 %d processing %s -> %s", self.id, message.Topic, message.Payload)
//log.Printf("Handler MBGW3 %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var observation Observation
err := json.Unmarshal([]byte(message.Payload), &observation)
if err != nil {
log.Printf("Unable to parse payload into Observation struct, message %s -> %s is lost, error ", message.Topic, message.Payload, err)
self.Lost("Unable to parse payload into Observation struct", err, message)
return
}
@ -95,9 +85,10 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
}
}
// log.Printf("Prepared measurement item: %s", measurement)
//log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement)
self.S()
}