This commit is contained in:
@ -9,6 +9,7 @@ type MessageT struct {
|
||||
}
|
||||
|
||||
type Handler interface {
|
||||
GetId() string
|
||||
Handle(MessageT)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package iot
|
||||
|
||||
import "log"
|
||||
import "fmt"
|
||||
import "udi/handlers/handler"
|
||||
|
||||
var idSeq int = 0
|
||||
@ -9,7 +10,7 @@ type IoTHandler struct {
|
||||
id int
|
||||
}
|
||||
|
||||
func NewIoTHandler() *IoTHandler {
|
||||
func NewIoTHandler() handler.Handler {
|
||||
t := &IoTHandler {
|
||||
id: idSeq,
|
||||
}
|
||||
@ -17,6 +18,10 @@ func NewIoTHandler() *IoTHandler {
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *IoTHandler) GetId() string {
|
||||
return fmt.Sprintf("IoT%d", self.id)
|
||||
}
|
||||
|
||||
func (self *IoTHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler IoT %d processing %s -> %s", self.id, message.Topic, message.Payload)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
//"reflect"
|
||||
"time"
|
||||
"strconv"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
@ -30,7 +31,7 @@ type Observation struct {
|
||||
}
|
||||
|
||||
|
||||
func NewMbgw3Handler(config config.HandlerConfigT) *Mbgw3Handler {
|
||||
func NewMbgw3Handler(config config.HandlerConfigT) handler.Handler {
|
||||
t := &Mbgw3Handler {
|
||||
id: idSeq,
|
||||
}
|
||||
@ -39,6 +40,10 @@ func NewMbgw3Handler(config config.HandlerConfigT) *Mbgw3Handler {
|
||||
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)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
"reflect"
|
||||
"time"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
@ -39,7 +40,7 @@ type PvValue struct {
|
||||
}
|
||||
|
||||
|
||||
func NewPvHandler(config config.HandlerConfigT) *PvHandler {
|
||||
func NewPvHandler(config config.HandlerConfigT) handler.Handler {
|
||||
t := &PvHandler {
|
||||
id: idSeq,
|
||||
}
|
||||
@ -48,6 +49,10 @@ func NewPvHandler(config config.HandlerConfigT) *PvHandler {
|
||||
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)
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"regexp"
|
||||
"fmt"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
@ -38,13 +39,13 @@ type localConfig struct {
|
||||
}
|
||||
|
||||
|
||||
func NewSveHandler(config config.HandlerConfigT) *SingleValueExtractorHandler {
|
||||
func NewSveHandler(config config.HandlerConfigT) handler.Handler {
|
||||
t := &SingleValueExtractorHandler {
|
||||
id: idSeq,
|
||||
ready: false,
|
||||
}
|
||||
idSeq += 1
|
||||
|
||||
|
||||
var localConfig localConfig
|
||||
if config.Attributes["application"] == "" {
|
||||
log.Println("Error: application not configured")
|
||||
@ -111,6 +112,10 @@ func NewSveHandler(config config.HandlerConfigT) *SingleValueExtractorHandler {
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *SingleValueExtractorHandler) GetId() string {
|
||||
return fmt.Sprintf("SVE%d", self.id)
|
||||
}
|
||||
|
||||
func lost(msg string, message handler.MessageT) {
|
||||
log.Printf("Error: %s, message %s is lost", msg, message)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ttn
|
||||
|
||||
import "log"
|
||||
import "fmt"
|
||||
import "udi/handlers/handler"
|
||||
|
||||
var idSeq int = 0
|
||||
@ -9,7 +10,7 @@ type TTNHandler struct {
|
||||
id int
|
||||
}
|
||||
|
||||
func NewTTNHandler() *TTNHandler {
|
||||
func NewTTNHandler() handler.Handler {
|
||||
t := &TTNHandler {
|
||||
id: idSeq,
|
||||
}
|
||||
@ -17,6 +18,10 @@ func NewTTNHandler() *TTNHandler {
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *TTNHandler) GetId() string {
|
||||
return fmt.Sprintf("TTN%d", self.id)
|
||||
}
|
||||
|
||||
func (self *TTNHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler TTN %d processing %s -> %s", self.id, message.Topic, message.Payload)
|
||||
}
|
||||
|
Reference in New Issue
Block a user