Skip to content
Snippets Groups Projects
Commit 21ebec3a authored by kpetersn's avatar kpetersn
Browse files

Initial commit of script. Shows MSTA changes. Assumes only one motor in the log file.

parents
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#
# Interpret motor changes in camonitor log
#
import sys
#!print sys.argv
msta_dict = {1 << 0 : ("Direction", ("Negative", "Positive")),
1 << 1 : ("Done", ("Moving", "Done")),
1 << 2 : ("Plus limit", ("Off", "On")),
1 << 3 : ("Home limit", ("Off", "On")),
1 << 4 : ("Unused", ("0", "1")),
1 << 5 : ("Closed-loop", ("Enabled", "Disabled")),
1 << 6 : ("Slip/stall", ("OK", "Stalled")),
1 << 7 : ("Home", ("Not Home", "Home")),
1 << 8 : ("Encoder present", ("No", "Yes")),
1 << 9 : ("Problem", ("No", "Yes")),
1 << 10 : ("Moving", ("Done", "Moving")),
1 << 11 : ("Gain support", ("No", "Yes")),
1 << 12 : ("Comm error", ("OK", "Error")),
1 << 13 : ("Minus limit", ("Off", "On")),
1 << 14 : ("Homed", ("Not homed", "Homed")),
}
#!print msta_dict
def msta_diff(last_msta, current_msta):
if last_msta == -1:
print "\t1st MSTA, No comparison possible"
return current_msta
else:
# XOR shows changed bits
changed_bits = last_msta ^ current_msta
# Display changes
for index in range(15):
bit = 1 << index
if (bit & changed_bits):
if (current_msta & bit):
bit_state = 1
else:
bit_state = 0
print "\t%s (0x%X) bit changed to \"%s\"" % (msta_dict[bit][0], bit, msta_dict[bit][1][bit_state])
def main(log_file):
# Try to open the log file
try:
fh = open(log_file, 'r')
except IOError:
print "%s doesn't exist." % log_file
sys.exit(1)
last_msta = -1
last_mip = -1
for line in fh:
#!print line[:-1]
# Break line into list of values: PV name, date, time, value
line_list = line[:-1].split()
if len(line_list) != 4:
# Line is not valid, continue to the next
continue
else:
# split line into PV name and field
name, field = line_list[0].split('.')
date = line_list[1]
time = line_list[2]
value = line_list[3]
# Check for MSTA change
if field == "MSTA":
# Maybe catch error here
current_msta = int(value)
print "[%s %s] %s's %s field changed from %i (0x%X) to %i (0x%X)" % (date, time, name, field, last_msta, last_msta, current_msta, current_msta)
msta_diff(last_msta, current_msta)
last_msta = current_msta
print
# Check for MIP change
if field == "MIP":
current_mip = int(value)
fh.close()
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage: motorHist.py <log_file>"
else:
main(sys.argv[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment