This commit is contained in:
@ -2,6 +2,7 @@ package draginoLdds75
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
@ -25,7 +26,7 @@ type message struct {
|
||||
TempC_DS18B20 string `json:"TempC_DS18B20"`
|
||||
}
|
||||
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType) error {
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, device *database.Device) error {
|
||||
if fPort != 2 {
|
||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||
}
|
||||
@ -54,6 +55,24 @@ func Parse(fPort int, decodedPayload []byte, variables *map[string]database.Vari
|
||||
Unit: "mm",
|
||||
Value: distance,
|
||||
}
|
||||
groundLevelI, exists := device.Attributes["GroundLevel"]
|
||||
groundLevelS, ok := groundLevelI.(string)
|
||||
groundLevel, err3 := strconv.Atoi(groundLevelS)
|
||||
if exists && err3 == nil && ok {
|
||||
log.Println("add corrected distance")
|
||||
correctedDistance := groundLevel - distance
|
||||
(*variables)["CorrectedDistance"] = database.VariableType {
|
||||
Label: "CorrectedDistance",
|
||||
Variable: "Level",
|
||||
Unit: "mm",
|
||||
Value: correctedDistance,
|
||||
}
|
||||
} else {
|
||||
log.Printf("no ground level: %s %s %s", exists, err3, ok)
|
||||
log.Printf("Device: %s", device)
|
||||
log.Printf("Attributes: %s", device.Attributes)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package draginoLmds200
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
"udi/database"
|
||||
)
|
||||
@ -25,7 +26,7 @@ type message struct {
|
||||
Dis2 int `json:"dis2"`
|
||||
}
|
||||
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType) error {
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, device *database.Device) error {
|
||||
if fPort != 2 {
|
||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||
}
|
||||
@ -40,17 +41,38 @@ func Parse(fPort int, decodedPayload []byte, variables *map[string]database.Vari
|
||||
Unit: "V",
|
||||
Value: message.Bat,
|
||||
}
|
||||
distance1 := message.Dis1 * 10
|
||||
(*variables)["Distance1"] = database.VariableType {
|
||||
Label: "Distance1",
|
||||
Variable: "Level",
|
||||
Unit: "mm",
|
||||
Value: (message.Dis1 * 10),
|
||||
Value: distance1,
|
||||
}
|
||||
distance2 := message.Dis2 * 10
|
||||
(*variables)["Distance2"] = database.VariableType {
|
||||
Label: "Distance2",
|
||||
Variable: "Level",
|
||||
Unit: "mm",
|
||||
Value: (message.Dis2 * 10),
|
||||
Value: distance2,
|
||||
}
|
||||
groundLevelI, exists := device.Attributes["GroundLevel"]
|
||||
groundLevelS, ok := groundLevelI.(string)
|
||||
groundLevel, err3 := strconv.Atoi(groundLevelS)
|
||||
if exists && err3 == nil && ok {
|
||||
correctedDistance1 := groundLevel - distance1
|
||||
(*variables)["CorrectedDistance1"] = database.VariableType {
|
||||
Label: "CorrectedDistance1",
|
||||
Variable: "Level",
|
||||
Unit: "mm",
|
||||
Value: correctedDistance1,
|
||||
}
|
||||
correctedDistance2 := groundLevel - distance2
|
||||
(*variables)["CorrectedDistance2"] = database.VariableType {
|
||||
Label: "CorrectedDistance2",
|
||||
Variable: "Level",
|
||||
Unit: "mm",
|
||||
Value: correctedDistance2,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ type emuMessage1 struct {
|
||||
|
||||
|
||||
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType) error {
|
||||
func Parse(fPort int, decodedPayload []byte, variables *map[string]database.VariableType, _ *database.Device) error {
|
||||
//log.Printf("Parse input: %d, %s", fPort, decodedPayload)
|
||||
switch fPort {
|
||||
case 1:
|
||||
|
@ -142,7 +142,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
|
||||
|
||||
//log.Printf("DeviceLabel: %s, DeviceType: %s", device.Label, device.DeviceType.ModelIdentifier)
|
||||
|
||||
var parser func(int, []byte, *map[string]database.VariableType) error
|
||||
var parser func(int, []byte, *map[string]database.VariableType, *database.Device) error
|
||||
switch device.DeviceType.ModelIdentifier {
|
||||
case "emu-prof-ii-lora-cfg1":
|
||||
parser = emuProfIILoRaCfg1.Parse
|
||||
@ -156,7 +156,7 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
|
||||
}
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
err3 := parser(uplinkMessage.UplinkMessage.FPort, uplinkMessage.UplinkMessage.DecodedPayload.Payload, &(measurement.Values))
|
||||
err3 := parser(uplinkMessage.UplinkMessage.FPort, uplinkMessage.UplinkMessage.DecodedPayload.Payload, &(measurement.Values), device)
|
||||
if err3 != nil {
|
||||
lost(fmt.Sprintf("Model parser failed: %s", err3), message)
|
||||
return
|
||||
|
Reference in New Issue
Block a user