Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
scouting-demonstrator
SCONE
Commits
b134e681
Commit
b134e681
authored
Nov 30, 2020
by
Gaia Grosso
Browse files
Update main.py for the merge request
parent
d47c2a26
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.py
View file @
b134e681
import
sys
import
argparse
import
math
import
ctypes
so_file
=
"./functions.so"
reg
=
ctypes
.
CDLL
(
so_file
)
...
...
@@ -40,10 +41,11 @@ config_dict = {
actions
=
[
"get"
,
"set"
]
def
ReadProperty
(
device
,
location
,
mask_32bits
):
read_32bits
=
ctypes
.
c_uint
(
reg
.
read_bits
(
device
,
location
,
width
=
"w"
))
def
ReadProperty
(
device
,
location
,
mask_32bits
,
verbose
=
False
):
read_32bits
=
ctypes
.
c_uint
(
reg
.
read_bits
(
device
,
location
))
string_32bits
=
"{:032b}"
.
format
(
read_32bits
.
value
)
print
(
"Read: %s"
%
(
string_32bits
))
if
verbose
:
print
(
"Read: %s"
%
(
string_32bits
))
list_32bits
=
[
int
(
bit
)
for
bit
in
string_32bits
]
list_32mask
=
[
int
(
bit
)
for
bit
in
mask_32bits
]
selected_bits
=
[]
...
...
@@ -56,7 +58,7 @@ def ReadProperty(device, location, mask_32bits):
return
output
def
WriteProperty
(
device
,
location
,
string_mask
,
write_value
):
read_value
=
ctypes
.
c_uint
(
reg
.
read_bits
(
device
,
location
,
width
=
"w"
))
read_value
=
ctypes
.
c_uint
(
reg
.
read_bits
(
device
,
location
))
string_read
=
"{:032b}"
.
format
(
read_value
.
value
)
string_write
=
"{:032b}"
.
format
(
write_value
.
value
)
print
(
"Read: %s"
%
(
string_read
))
...
...
@@ -77,8 +79,12 @@ def WriteProperty(device, location, string_mask, write_value):
for
bit
in
list_32out
:
output
=
(
output
<<
1
)
|
bit
output
=
ctypes
.
c_uint
(
output
)
reg
.
write_bits
(
device
,
location
,
"w"
,
output
);
return
reg
.
write_bits
(
device
,
location
,
output
)
# Readback as checkout
read_value_new
=
ctypes
.
c_uint
(
reg
.
read_bits
(
device
,
location
))
if
read_value_new
==
read_value
:
return
True
else
:
return
False
def
NBitsAllowed
(
mask
):
#string of bits
...
...
@@ -90,16 +96,7 @@ def NBitsAllowed(mask): #string of bits
return
output
def
NBitsNeeded
(
value
):
#string of bits
output
=
32
i
=
0
while
(
int
(
value
[
i
])
<
1
):
output
-=
1
i
+=
1
print
(
"Number of required bits: %i"
%
(
output
))
if
output
==
0
:
# 1 bit needed to store 0
output
+=
1
return
output
return
math
.
ceil
(
math
.
log2
(
int
(
value
,
2
)
+
1
))
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
#Python tool that makes it easy to create an user-friendly command-line interface
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment