converter for twos-complement fixed decimal numbers
This commit is contained in:
parent
64c26103df
commit
880794f966
@ -6,6 +6,14 @@
|
||||
from struct import pack, unpack
|
||||
|
||||
|
||||
def fix1twos(x):
|
||||
x = x[0]
|
||||
r = x
|
||||
if x & 0x8000:
|
||||
r = ((x - 1) ^ 0xffff) * -1
|
||||
return r / 10
|
||||
|
||||
|
||||
Converters = {
|
||||
"dht20TOFloat": {
|
||||
"in": lambda x : float(x[0]) / 10.0,
|
||||
@ -14,5 +22,10 @@ Converters = {
|
||||
"uint32": {
|
||||
"in": lambda x : unpack('L', pack('HH', *x))[0],
|
||||
"out": lambda x : unpack('HH', pack('L', int(x)))
|
||||
},
|
||||
"fix1twos": {
|
||||
"in": lambda x: fix1twos(x),
|
||||
"out": None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
||||
{
|
||||
"args": {
|
||||
"address": 1,
|
||||
"converter": "dht20TOFloat",
|
||||
"converter": "fix1twos",
|
||||
"count": 1,
|
||||
"label": "wago1",
|
||||
"publishTopic": "IoT/Measurement/Modbus2/Wago1",
|
||||
@ -103,14 +103,14 @@
|
||||
{
|
||||
"args": {
|
||||
"address": 0,
|
||||
"converter": "dht20TOFloat",
|
||||
"converter": "fix1twos",
|
||||
"count": 1,
|
||||
"label": "wago0",
|
||||
"publishTopic": "IoT/Measurement/Modbus2/Wago0",
|
||||
"label": "Freezer",
|
||||
"publishTopic": "IoT/Measurement/Modbus2/Freezer",
|
||||
"scanRate": 1.0,
|
||||
"unit": 11,
|
||||
"updateOnly": false
|
||||
},
|
||||
"type": "InputRegisterDatapoint"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user