Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
f07ad281
Commit
f07ad281
authored
Jul 12, 2016
by
Maxime Perrotin
Browse files
Set default log function
parent
cc73ff15
Changes
1
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/asn1_value_editor.py
View file @
f07ad281
...
...
@@ -20,6 +20,7 @@ __version__ = "1.4.0"
__url__
=
"http://taste.tuxfamily.org"
import
sys
import
logging
try
:
from
PySide
import
*
...
...
@@ -231,7 +232,7 @@ class asn1Editor(QTreeView):
self
.
plotterBackend
=
None
self
.
backend
=
None
self
.
plottedIdxs
=
[]
self
.
log
=
None
self
.
log
=
logging
self
.
pendingTM
=
None
# item is the ASN.1 node in Pyside format from datamodel.py
self
.
item
=
None
...
...
@@ -425,6 +426,7 @@ class asn1Editor(QTreeView):
self
.
parseModel
(
root
,
nbRows
=
nbRows
,
dest
=
dest
)
elif
asnType
==
'CHOICE'
:
value
=
self
.
model
.
item
(
row
,
3
).
text
()
print
value
,
'THIS IS THE CHOICE VALUE, MAN'
self
.
parseModel
(
root
,
dest
=
dest
)
# XXX missing a kind.Set here !
else
:
...
...
@@ -432,61 +434,61 @@ class asn1Editor(QTreeView):
def
updateModel
(
self
,
root
,
ptr
,
nbRows
=-
1
):
''' Recursive update of the values in the GUI from ASN.1 instance '''
def
fillRow
(
root
,
i
,
dest
,
choice
=
False
,
seqOf
=
False
):
name
=
root
.
child
(
i
,
0
).
text
().
replace
(
'-'
,
'_'
)
asnType
=
root
.
child
(
i
,
1
).
text
()
child
=
root
.
child
(
i
,
3
)
ptr
=
getattr
(
dest
,
name
)
if
not
seqOf
else
dest
if
seqOf
:
ptr
=
ptr
[
i
]
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'SEQOF'
):
# XXX plotter: TODO
plotters
=
child
.
data
(
PLOTTERS
)
if
plotters
is
not
None
:
self
.
log
.
debug
(
"updateModel - updatePlot call"
)
for
plotter
in
plotters
:
self
.
plotterBackend
.
updatePlot
(
plotter
,
value
)
self
.
log
.
debug
(
"updateModel - updatePlot end"
)
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'BOOLEAN'
):
child
.
setText
(
str
(
ptr
.
Get
()))
elif
asnType
==
'STRING'
:
child
.
setText
(
ptr
.
GetPyString
())
elif
asnType
==
'ENUMERATED'
:
value
=
ptr
.
Get
()
intMappings
=
child
.
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
num
==
value
:
child
.
setText
(
enumerant
)
break
else
:
print
(
"ERROR = ENUMERATED value not found"
)
elif
asnType
in
(
'SEQUENCE'
,
'SET'
):
self
.
updateModel
(
root
.
child
(
i
),
ptr
)
elif
asnType
==
'CHOICE'
:
state
=
ptr
.
GetState
()
value
=
ptr
.
kind
.
Get
()
ptr
.
Reset
(
state
)
intMappings
=
child
.
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
num
==
value
:
child
.
setText
(
str
(
enumerant
))
# is num really the row of this choice ? XXX
fillRow
(
root
.
child
(
i
),
num
,
dest
=
ptr
,
choice
=
True
)
break
#ptr.Reset(state)
elif
asnType
==
'SEQOF'
:
state
=
ptr
.
GetState
()
size
=
ptr
.
GetLength
()
ptr
.
Reset
(
state
)
child
.
setText
(
str
(
size
))
self
.
updateModel
(
root
.
child
(
i
),
ptr
,
nbRows
=
size
)
if
root
.
hasChildren
():
seqOf
=
True
if
nbRows
!=
-
1
else
False
if
not
seqOf
:
nbRows
=
root
.
rowCount
()
def
fillRow
(
root
,
i
,
dest
,
choice
=
False
,
seqOf
=
False
):
name
=
root
.
child
(
i
,
0
).
text
().
replace
(
'-'
,
'_'
)
asnType
=
root
.
child
(
i
,
1
).
text
()
child
=
root
.
child
(
i
,
3
)
ptr
=
getattr
(
dest
,
name
)
if
not
seqOf
else
dest
if
seqOf
:
ptr
=
ptr
[
i
]
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'SEQOF'
):
# XXX plotter: TODO
plotters
=
child
.
data
(
PLOTTERS
)
if
plotters
is
not
None
:
self
.
log
.
debug
(
"updateModel - updatePlot call"
)
for
plotter
in
plotters
:
self
.
plotterBackend
.
updatePlot
(
plotter
,
value
)
self
.
log
.
debug
(
"updateModel - updatePlot end"
)
if
asnType
in
(
'INTEGER'
,
'REAL'
,
'BOOLEAN'
):
child
.
setText
(
str
(
ptr
.
Get
()))
elif
asnType
==
'STRING'
:
child
.
setText
(
ptr
.
GetPyString
())
elif
asnType
==
'ENUMERATED'
:
value
=
ptr
.
Get
()
intMappings
=
child
.
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
num
==
value
:
child
.
setText
(
enumerant
)
break
else
:
print
(
"ERROR = ENUMERATED value not found"
)
elif
asnType
in
(
'SEQUENCE'
,
'SET'
):
self
.
updateModel
(
root
.
child
(
i
),
ptr
)
elif
asnType
==
'CHOICE'
:
state
=
ptr
.
GetState
()
value
=
ptr
.
kind
.
Get
()
ptr
.
Reset
(
state
)
intMappings
=
child
.
data
(
INTMAP
)
for
enumerant
,
num
in
intMappings
.
viewitems
():
if
num
==
value
:
child
.
setText
(
str
(
enumerant
))
# is num really the row of this choice ? XXX
fillRow
(
root
.
child
(
i
),
num
,
dest
=
ptr
,
choice
=
True
)
break
#ptr.Reset(state)
elif
asnType
==
'SEQOF'
:
state
=
ptr
.
GetState
()
size
=
ptr
.
GetLength
()
ptr
.
Reset
(
state
)
child
.
setText
(
str
(
size
))
self
.
updateModel
(
root
.
child
(
i
),
ptr
,
nbRows
=
size
)
for
i
in
xrange
(
nbRows
):
stateBefore
=
ptr
.
GetState
()
fillRow
(
root
,
i
,
ptr
,
seqOf
=
seqOf
)
...
...
@@ -497,8 +499,8 @@ class asn1Editor(QTreeView):
root
=
root
or
self
.
treeItem
asn1Instance
=
asn1Var
or
self
.
asn1Instance
row
=
root
.
row
()
#name = root.text()
asnType
=
self
.
model
.
item
(
row
,
1
).
text
()
asn1Instance
.
Reset
()
if
asnType
==
'SEQOF'
:
# Set the number of items in column 3
...
...
@@ -518,8 +520,9 @@ class asn1Editor(QTreeView):
# how to translate this kind number into the choice string? XXX
self
.
model
.
item
(
row
,
3
).
setText
(
enumerant
)
# decode the actual value
ptr
=
getattr
(
asn1Instance
,
enumerant
.
replace
(
'-'
,
'_'
))
self
.
updateModel
(
root
,
ptr
)
print
'choice, enumerant='
,
enumerant
#ptr = getattr(asn1Instance, enumerant.replace('-', '_'))
self
.
updateModel
(
root
,
asn1Instance
)
elif
asnType
in
(
'INTEGER'
,
'REAL'
):
self
.
model
.
item
(
row
,
3
).
setText
(
str
(
asn1Instance
.
Get
()))
elif
asnType
==
'BOOLEAN'
:
...
...
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