Skip to content

Commit

Permalink
V1.19.01
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyates committed Jan 29, 2024
1 parent 796b903 commit e2e6f1f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions genmonlib/custom_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import threading
import time
import copy
import struct

from genmonlib.controller import GeneratorController
from genmonlib.modbus_file import ModbusFile
Expand Down Expand Up @@ -1616,14 +1617,28 @@ def GetDisplayEntry(self, entry, JSONNum=False, no_units=False, inheritreg = Non
value = self.ProcessMaskModifier(entry, value)
if value == int(entry["value"], 16):
ReturnValue = entry["text"]

elif entry["type"] == "bool":
value = self.GetParameter(Register, ReturnInt=True, IsCoil=IsCoil, IsInput=IsInput)
if "value" in entry.keys():
if isinstance(entry["value"], str):
logical_value = (entry["value"].lower() == "true")
elif isinstance(entry["value"], bool):
logical_value = entry["value"]
else:
self.LogError("Error: for type bool 'value' must be a string or bool: " + str(entry))
logical_value = True
else:
logical_value = True
value = self.ProcessMaskModifier(entry, value)
value = self.ProcessBitModifiers(entry, value)
if (not (value == 0)) == logical_value:
ReturnValue = entry["text"]
elif entry["type"] == "float":
value = self.GetParameter(Register, ReturnInt=True, IsCoil=IsCoil, IsInput=IsInput)
value = self.ProcessMaskModifier(entry, value)
value = self.ProcessBitModifiers(entry, value, ReturnFloat=True)
value = self.ProcessTemperatureModifier( entry, value)
if "round" in entry.keys():
value = round(float(value), int(entry["round"]))
value = self.ProcessRoundModifiers(entry, value)
if "bounds_regex" in entry.keys():
if re.match(entry["bounds_regex"], str(float(value))):
ReturnValue = self.ProcessExecModifier(entry, float(value))
Expand Down Expand Up @@ -1723,13 +1738,33 @@ def GetDisplayEntry(self, entry, JSONNum=False, no_units=False, inheritreg = Non
self.LogDebug(str(entry))

return ReturnTitle, ReturnValue

# ------------ GeneratorController:ProcessRoundModifiers ----------------------
def ProcessRoundModifiers(self, entry, value):
try:
if "round" in entry.keys():
return round(float(value), int(entry["round"]))
else:
return value
except Exception as e1:
self.LogErrorLine("Error in ProcessRoundModifiers: " + str(e1) + ": " + str(entry["title"]))
return value
# ------------ GeneratorController:ProcessBitModifiers ----------------------
def ProcessBitModifiers(self, entry, value, ReturnFloat = False):
try:
if "shiftright" in entry.keys():
value = value >> int(entry["shiftright"])
if "shiftleft" in entry.keys():
value = value << int(entry["shiftleft"])
if "ieee754" in entry.keys() and ReturnFloat:
if entry["ieee754"].lower() == "half":
value = float(struct.unpack('f', struct.pack('H', int(value)))[0])
elif entry["ieee754"].lower() == "single":
value = float(struct.unpack('f', struct.pack('I', int(value)))[0])
elif entry["ieee754"].lower() == "double":
value = float(struct.unpack('f', struct.pack('Q', int(value)))[0])
else:
self.LogError("Error converting ieee754 floating point: invalid ieee754 type: " + str(entry))
if "multiplier" in entry.keys():
if ReturnFloat:
value = float(value * float(entry["multiplier"]))
Expand Down

0 comments on commit e2e6f1f

Please sign in to comment.