dt1t and counter and refactoring using embedded interfaces
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user