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
08698895
Commit
08698895
authored
Mar 22, 2015
by
Maxime Perrotin
Browse files
Compute combinations of ASN.1 field values
parent
6bd655a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/resources.py
View file @
08698895
...
...
@@ -2,7 +2,7 @@
# Resource object code
#
# Created: S
at
Mar 2
1 16:33:04
2015
# Created: S
un
Mar 2
2 21:50:51
2015
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
...
...
asn1_value_editor/sdlHandler.py
View file @
08698895
...
...
@@ -21,6 +21,7 @@
import
os
import
ctypes
import
itertools
from
functools
import
partial
from
PySide.QtGui
import
(
QDockWidget
,
QPushButton
,
QGridLayout
,
QListWidget
,
...
...
@@ -52,6 +53,88 @@ CleanName = lambda name: name.replace(UNICODE_SEP, '->')
UnicodeName
=
lambda
name
:
name
.
replace
(
'->'
,
UNICODE_SEP
)
# Set of functions used by the simulator to compute the combination input
# parameters for each ASN.1 data type. Yield ASN.1 Value Notation strings
# ASN.1 types must be in the format generated by ASN1SCC Python backend
def
compute_combinations
(
asn1_ty
,
pool
):
''' Top-level, type-dispatching function
"pool" is the set of types, found in the process.dataview attribute '''
basic
=
opengeode
.
ogParser
.
find_basic_type
(
asn1_ty
.
type
,
pool
)
# Python2 has no "yield from"...
if
basic
.
kind
.
startswith
(
'Integer'
):
for
each
in
compute_integer_combinations
(
basic
):
yield
each
if
basic
.
kind
==
'BooleanType'
:
for
each
in
compute_boolean_combinations
(
basic
):
yield
each
elif
basic
.
kind
.
startswith
(
'Real'
):
for
each
in
compute_real_combinations
(
basic
):
yield
each
elif
basic
.
kind
==
'EnumeratedType'
:
for
each
in
compute_enumerated_combinations
(
basic
):
yield
each
elif
basic
.
kind
==
'ChoiceType'
:
for
each
in
compute_choice_combinations
(
basic
,
pool
):
yield
each
elif
basic
.
kind
in
(
'SequenceType'
,
'SetType'
):
for
each
in
compute_sequence_combinations
(
basic
,
pool
):
yield
each
elif
basic
.
kind
in
(
'SequenceOfType'
,
'SetOfType'
):
for
each
in
compute_sequenceof_combinations
(
basic
,
pool
):
yield
each
def
compute_integer_combinations
(
asn1_ty
):
''' Generator returning all combinations of integer '''
for
each
in
xrange
(
int
(
asn1_ty
.
Min
),
int
(
asn1_ty
.
Max
)):
yield
str
(
each
)
def
compute_real_combinations
(
asn1_ty
):
''' Generator returning three real values only (set is infinite) '''
yield
asn1_ty
.
Min
yield
str
((
float
(
asn1_ty
.
Max
)
+
float
(
asn1_ty
.
Min
))
/
2.0
)
yield
asn1_ty
.
Max
def
compute_boolean_combinations
(
asn1_ty
):
''' Generator returning all combinations of boolean '''
yield
'TRUE'
yield
'FALSE'
def
compute_enumerated_combinations
(
asn1_ty
):
''' Generator returning all combinations of enumerated '''
for
each
in
asn1_ty
.
EnumValues
.
viewkeys
():
yield
each
def
compute_choice_combinations
(
asn1_ty
,
pool
):
''' Generator returning all combinations of choice components '''
for
discr
,
value_ty
in
asn1_ty
.
Children
.
viewitems
():
for
each
in
compute_combinations
(
value_ty
,
pool
):
yield
'{}: {}'
.
format
(
discr
,
each
)
def
compute_sequence_combinations
(
asn1_ty
,
pool
):
''' Generator returning all combinations of SEQUENCE types '''
elems
=
[]
for
name
,
value_ty
in
asn1_ty
.
Children
.
viewitems
():
# Create a list of iterables
elems
.
append
(
compute_combinations
(
value_ty
,
pool
))
# Generator with all combinations
for
each
in
itertools
.
product
(
*
elems
):
# each is a tuple with values for the sequence, join with fieldnames
pairs
=
itertools
.
izip
(
asn1_ty
.
Children
.
viewkeys
(),
each
)
res
=
(
'{} {}'
.
format
(
name
,
value
)
for
name
,
value
in
pairs
)
yield
'{{ {} }}'
.
format
(
', '
.
join
(
res
))
def
compute_sequenceof_combinations
(
asn1_ty
,
pool
):
''' Generator returning all combinations of arrays '''
pass
class
SendTC
(
QUndoCommand
):
''' Undo command to send a message to the running system '''
def
__init__
(
self
,
handler
,
old_state
):
...
...
@@ -246,7 +329,8 @@ class sdlHandler(QObject):
if
idx
!=
len
(
props
):
self
.
log_area
.
addItem
(
'Wrong number of properties found!'
)
return
self
.
properties
=
{
ppty
.
inputString
:
ptr
for
ppty
,
ptr
in
zip
(
props
,
properties
)}
self
.
properties
=
{
ppty
.
inputString
:
ptr
for
ppty
,
ptr
in
zip
(
props
,
properties
)}
def
check_properties
(
self
,
statehash
):
''' Check the properties at runtime
...
...
@@ -399,6 +483,12 @@ class sdlHandler(QObject):
self
.
log_area
.
addItem
(
'Sent {}({})'
.
format
(
tc_name
,
param
or
''
))
self
.
check_properties
(
new_hash
)
# TEMP TO TEST
# for name, typedef in self.proc.dataview.viewitems():
# print 'All combinations of ', name
# for combi in compute_combinations(typedef, self.proc.dataview):
# print combi
# END TEMP
return
new_hash
def
update_button_state
(
self
,
tc_name
=
None
):
...
...
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