Commit 16fae0d0 authored by Gaia Grosso's avatar Gaia Grosso
Browse files

Update main.py

parent 0a86f9e3
......@@ -50,15 +50,15 @@ def ReadProperty(device, location, offset, width, verbose=False):
read_32bits = ctypes.c_uint(0);
isRead = reg.read_bits(device, location, ctypes.byref(read_32bits))
if isRead == -1:
print("An error occured while executing C function read_bitsò")
print("An error occured while executing C function read_bits")
return -1
string_32bits = "{:032b}".format(read_32bits.value)
if verbose:
print("Read: %s"%(string_32bits))
strin_out = string_32bits[-1*(offset+width): -1*offset] # remove masked bits
output = int(string_out, 2) # convert selected string to integer
string_32bits = "{:032b}".format(read_32bits.value>>offset)
string_out = string_32bits[-1*width:] # remove masked bits
output = int(string_out, 2) # convert selected string to integer
if verbose:
print("Unmasked result: %i"%(output))
return output
......@@ -67,7 +67,7 @@ def WriteProperty(device, location, offset, width, write_value, verbose=False):
read_value = ctypes.c_uint(0);
isRead = reg.read_bits(device, location, ctypes.byref(read_value))
if isRead == -1:
print("An error occured while executing C function read_bitsò")
print("An error occured while executing C function read_bits")
return -1
string_read = "{:032b}".format(read_value.value)
string_write = "{:032b}".format(write_value.value<<offset)
......@@ -75,7 +75,7 @@ def WriteProperty(device, location, offset, width, write_value, verbose=False):
print("Read: %s"%(string_read))
print("Write: %s"%(string_write))
string_write = string_read[:-1*(offset+width)] + string_write[-1*(offset+width):-1*offset]] + string_read[-1*offset:]
string_write = string_read[:-1*(offset+width)] + string_write[-1*(offset+width):-1*offset] + string_read[-1*offset:]
output = int(string_write, 2)
isWritten = reg.write_bits(device, location, output)
if isWritten == -1:
......@@ -97,6 +97,7 @@ if __name__ == '__main__':
parser.add_argument('-a','--action', type=str, help="control action", required=True, choices=actions)
parser.add_argument('-p','--property', type=str, help="control property", required=True)
parser.add_argument('-v','--value', type=str, help="new value", required=False)
parser.add_argument('-d','--dump', type=bool,help="dump messages", required=False, default=False)
args = parser.parse_args()
board = args.board
......@@ -106,10 +107,10 @@ if __name__ == '__main__':
offset = config_dict[board]["property"][prop]["offset"]
width = config_dict[board]["property"][prop]["width"]
action = args.action
value = args.value
value = int(args.value)
verbose = args.dump
# exceptions:
if offeset > 30:
if offset > 30:
print("Offset value %i is out of range 0-30. Check the configuration file."%(offset))
exit()
if width == 0:
......@@ -129,8 +130,8 @@ if __name__ == '__main__':
print("Overflow error! value %s doesn't fit in the allowed memory location."%(args.value))
exit()
else:
writevalue = ctypes.c_uint(int(args.value)) #unsigned int (32 bits)
isWritten = WriteProperty(device, location, offset, width, writevalue)
writevalue = ctypes.c_uint(value) #unsigned int (32 bits)
isWritten = WriteProperty(device, location, offset, width, writevalue, verbose=verbose)
if isWritten == -1:
print('The value could not be updated.')
exit()
......@@ -138,7 +139,7 @@ if __name__ == '__main__':
print('Set property %s from location %s on %s: %i'%(prop, location, board, writevalue.value))
elif action == "get":
isRead = ReadProperty(device, location, offset, width)
isRead = ReadProperty(device, location, offset, width, verbose=verbose)
if isRead == -1:
print('The register could not be read.')
exit()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment