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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user