This commit is contained in:
@@ -2,15 +2,13 @@ package dt1t
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"udi/handlers/handler"
|
"time"
|
||||||
"udi/database"
|
|
||||||
"udi/config"
|
"udi/config"
|
||||||
|
"udi/database"
|
||||||
|
"udi/handlers/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Dt1tHandler struct {
|
type Dt1tHandler struct {
|
||||||
handler.CommonHandler
|
handler.CommonHandler
|
||||||
ready bool
|
ready bool
|
||||||
@@ -18,12 +16,10 @@ type Dt1tHandler struct {
|
|||||||
dbh *database.DatabaseHandle
|
dbh *database.DatabaseHandle
|
||||||
application string
|
application string
|
||||||
device string
|
device string
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||||
t := &Dt1tHandler {
|
t := &Dt1tHandler{}
|
||||||
}
|
|
||||||
|
|
||||||
if config.Attributes["Application"] == "" {
|
if config.Attributes["Application"] == "" {
|
||||||
log.Println("Error: application not configured")
|
log.Println("Error: application not configured")
|
||||||
@@ -44,7 +40,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
||||||
if ! self.ready {
|
if !self.ready {
|
||||||
self.Lost("Handler is not marked as ready", nil, message)
|
self.Lost("Handler is not marked as ready", nil, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -55,7 +51,7 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
|||||||
self.Lost("Invalid raw value", err, message)
|
self.Lost("Invalid raw value", err, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if temperature & 0x8000 != 0{
|
if temperature&0x8000 != 0 {
|
||||||
temperature = ((temperature - 1) ^ 0xffff) * -1
|
temperature = ((temperature - 1) ^ 0xffff) * -1
|
||||||
}
|
}
|
||||||
temperatureF := float32(temperature) / 10.0
|
temperatureF := float32(temperature) / 10.0
|
||||||
@@ -69,7 +65,7 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
|||||||
variable.Label = "Temperature"
|
variable.Label = "Temperature"
|
||||||
variable.Variable = ""
|
variable.Variable = ""
|
||||||
variable.Unit = "°C"
|
variable.Unit = "°C"
|
||||||
variable.Value = fmt.Sprintf("%f", temperatureF)
|
variable.Value = temperatureF
|
||||||
measurement.Values = make(map[string]database.VariableType)
|
measurement.Values = make(map[string]database.VariableType)
|
||||||
measurement.Values["Value"] = variable
|
measurement.Values["Value"] = variable
|
||||||
|
|
||||||
@@ -77,5 +73,3 @@ func (self *Dt1tHandler) Handle(message handler.MessageT) {
|
|||||||
self.dbh.StoreMeasurement(&measurement)
|
self.dbh.StoreMeasurement(&measurement)
|
||||||
self.S()
|
self.S()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user