--- a/graphics/DebugDataConsumer.py Fri Aug 11 15:18:19 2017 +0300
+++ b/graphics/DebugDataConsumer.py Mon Aug 14 19:13:01 2017 +0300
@@ -46,7 +46,7 @@
return float(value.days * DAY + \
value.seconds * SECOND + \
value.microseconds)
- return
+ return
def generate_time(value):
"""
@@ -56,38 +56,38 @@
@return: IEC 61131 TIME literal
"""
microseconds = get_microseconds(value)
-
+
# Get absolute microseconds value and save if it was negative
negative = microseconds < 0
microseconds = abs(microseconds)
-
+
# TIME literal prefix
data = "T#"
if negative:
data += "-"
-
+
# In TIME literal format, it isn't mandatory to indicate null values
# if no greater non-null values are available. This variable is used to
# inhibit formatting until a non-null value is found
not_null = False
-
+
for val, format in [
(int(microseconds) / DAY, "%dd"), # Days
((int(microseconds) % DAY) / HOUR, "%dh"), # Hours
((int(microseconds) % HOUR) / MINUTE, "%dm"), # Minutes
((int(microseconds) % MINUTE) / SECOND, "%ds")]: # Seconds
-
- # Add value to TIME literal if value is non-null or another non-null
+
+ # Add value to TIME literal if value is non-null or another non-null
# value have already be found
if val > 0 or not_null:
data += format % val
-
+
# Update non-null variable
not_null = True
-
- # In any case microseconds have to be added to TIME literal
+
+ # In any case microseconds have to be added to TIME literal
data += "%gms" % (microseconds % SECOND / 1000.)
-
+
return data
def generate_date(value):
@@ -116,22 +116,22 @@
@return: IEC 61131 TIME_OF_DAY literal
"""
microseconds = get_microseconds(value)
-
+
# TIME_OF_DAY literal prefix
data = "TOD#"
-
+
for val, format in [
(int(microseconds) / HOUR, "%2.2d:"), # Hours
((int(microseconds) % HOUR) / MINUTE, "%2.2d:"), # Minutes
((int(microseconds) % MINUTE) / SECOND, "%2.2d."), # Seconds
(microseconds % SECOND, "%6.6d")]: # Microseconds
-
+
# Add value to TIME_OF_DAY literal
data += format % val
-
+
return data
-# Dictionary of translation functions from value send by debugger to IEC
+# Dictionary of translation functions from value send by debugger to IEC
# literal stored by type
TYPE_TRANSLATOR = {
"TIME": generate_time,
@@ -154,7 +154,7 @@
"""
class DebugDataConsumer:
-
+
def __init__(self):
"""
Constructor
@@ -162,17 +162,17 @@
# Debug value and forced flag
self.Value = None
self.Forced = False
-
+
# Store debug value and forced flag when value update is inhibited
self.LastValue = None
self.LastForced = False
-
+
# Value IEC data type
self.DataType = None
-
+
# Flag that value update is inhibited
self.Inhibited = False
-
+
def Inhibit(self, inhibit):
"""
Set flag to inhibit or activate value update
@@ -180,23 +180,23 @@
"""
# Save inhibit flag
self.Inhibited = inhibit
-
+
# When reactivated update value and forced flag with stored values
if not inhibit and self.LastValue is not None:
self.SetForced(self.LastForced)
self.SetValue(self.LastValue)
-
+
# Reset stored values
self.LastValue = None
self.LastForced = False
-
+
def SetDataType(self, data_type):
"""
Set value IEC data type
@param data_type: Value IEC data type
"""
self.DataType = data_type
-
+
def NewValues(self, tick, values, raw="BOOL"):
"""
Function called by debug thread when a new debug value is available
@@ -206,21 +206,21 @@
@param raw: Data type of values not translated (default: 'BOOL')
"""
value, forced = values
-
+
# Translate value to IEC literal
if self.DataType != raw:
value = TYPE_TRANSLATOR.get(self.DataType, str)(value)
-
+
# Store value and forced flag when value update is inhibited
if self.Inhibited:
self.LastValue = value
self.LastForced = forced
-
+
# Update value and forced flag in any other case
else:
self.SetForced(forced)
self.SetValue(value)
-
+
def SetValue(self, value):
"""
Update value.
@@ -228,14 +228,14 @@
@param value: New value
"""
self.Value = value
-
+
def GetValue(self):
"""
Return current value
@return: Current value
"""
return self.Value
-
+
def SetForced(self, forced):
"""
Update Forced flag.
@@ -243,7 +243,7 @@
@param forced: New forced flag
"""
self.Forced = forced
-
+
def IsForced(self):
"""
Indicate if current value is forced