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
|
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 = {
|
Converters = {
|
||||||
"dht20TOFloat": {
|
"dht20TOFloat": {
|
||||||
"in": lambda x : float(x[0]) / 10.0,
|
"in": lambda x : float(x[0]) / 10.0,
|
||||||
@ -14,5 +22,10 @@ Converters = {
|
|||||||
"uint32": {
|
"uint32": {
|
||||||
"in": lambda x : unpack('L', pack('HH', *x))[0],
|
"in": lambda x : unpack('L', pack('HH', *x))[0],
|
||||||
"out": lambda x : unpack('HH', pack('L', int(x)))
|
"out": lambda x : unpack('HH', pack('L', int(x)))
|
||||||
|
},
|
||||||
|
"fix1twos": {
|
||||||
|
"in": lambda x: fix1twos(x),
|
||||||
|
"out": None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
{
|
{
|
||||||
"args": {
|
"args": {
|
||||||
"address": 1,
|
"address": 1,
|
||||||
"converter": "dht20TOFloat",
|
"converter": "fix1twos",
|
||||||
"count": 1,
|
"count": 1,
|
||||||
"label": "wago1",
|
"label": "wago1",
|
||||||
"publishTopic": "IoT/Measurement/Modbus2/Wago1",
|
"publishTopic": "IoT/Measurement/Modbus2/Wago1",
|
||||||
@ -103,14 +103,14 @@
|
|||||||
{
|
{
|
||||||
"args": {
|
"args": {
|
||||||
"address": 0,
|
"address": 0,
|
||||||
"converter": "dht20TOFloat",
|
"converter": "fix1twos",
|
||||||
"count": 1,
|
"count": 1,
|
||||||
"label": "wago0",
|
"label": "Freezer",
|
||||||
"publishTopic": "IoT/Measurement/Modbus2/Wago0",
|
"publishTopic": "IoT/Measurement/Modbus2/Freezer",
|
||||||
"scanRate": 1.0,
|
"scanRate": 1.0,
|
||||||
"unit": 11,
|
"unit": 11,
|
||||||
"updateOnly": false
|
"updateOnly": false
|
||||||
},
|
},
|
||||||
"type": "InputRegisterDatapoint"
|
"type": "InputRegisterDatapoint"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user