Commit 2b7fe29d authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Parse ASN.1 Editor widget and return swig variable

parent c55b82c6
......@@ -505,39 +505,52 @@ class asn1Editor(QTreeView):
raw = vn.toASN1ValueNotation(data).strip()
return raw if not use_dash else raw.replace('_', '-')
def to_asn1scc_swig(self, root, dest, ASN1Swig, ASN1_type):
def to_asn1scc_swig(self, root, dest, ASN1Swig, sort, ASN1_AST):
''' Helper API function: read variable and set ASN.1 SWIG variable
Inputs: root: select which variable to parse
dest: Swig variable (will be modified)
ASN1Swig: python module containing SWIG DV access
ASN1_type: AST generated by ASN1SCC for the root type
sort: root ASN.1 typename (with dash, no underscores)
ASN1_AST: full AST generated by ASN1SCC
'''
var = self.getVariable(root).popitem()[1]
print ASN1_type
def rec(inp, outp, sort):
''' Recursively parse the value '''
''' Recursively fill up the value '''
if sort.kind == 'ReferenceType':
sort = ASN1_AST[sort.ReferencedTypeName]
if isinstance(inp, list):
# SEQUENCE OF
for i in range(len(inp)):
# Follow the ASN.1 type in the AST from ASN1SCC
rec(inp[i], outp[i], sort.type.type)
if sort.type.Min != sort.type.Max:
# The ASN1SCC AST only knows if the list has a fixed length
dest.SetLength(len(inp))
elif isinstance(inp, (int, float, bool)):
outp.Set(inp)
elif isinstance(inp, dict):
if 'Enum' in inp:
val = getattr(ASN1Swig.DV, inp['Enum'])
# Get proper enum id from the ASN1SCC AST
enum_id = sort.type.EnumValues[
inp['Enum'].replace('_', '-')].EnumID
val = getattr(ASN1Swig.DV, enum_id)
outp.Set(val)
elif 'Choice' in inp:
# We need the _PRESENT string TOOD
pass
child_name = inp['Choice']
ch_ty = sort.type.Children[child_name.replace('_', '-')]
enum_val = getattr(ASN1Swig.DV, ch_ty.EnumID)
outp.kind.Set(enum_val)
rec(inp[child_name],
getattr(outp, child_name),
ch_ty.type)
else:
for each in inp:
rec(inp, getattr(outp, each))
# SEQUENCE
for field, data in inp.viewitems():
field_ty = sort.type.Children[field.replace('_', '-')]
rec(data, getattr(outp, field), field_ty.type)
else:
self.log.error('Unsupported type in to_asn1scc_swig')
rec(var, dest, ASN1_type)
return
rec(var, dest, sort)
def sendTC(self):
......
......@@ -2,7 +2,7 @@
# Resource object code
#
# Created: Wed Feb 18 16:54:13 2015
# Created: Wed Feb 18 20:57:05 2015
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
......
......@@ -255,11 +255,13 @@ class sdlHandler(QObject):
for var, (sort, _) in self.proc.variables.viewitems():
#as_pyside = self.asn1_editor.getVariable(root=self.tree_items[var])
typename = sort.ReferencedTypeName.replace('-', '_')
asn1_type = self.proc.dataview[sort.ReferencedTypeName]
asn1_instance = getattr(ASN1, typename)()
# Fill up the SWIG ASN.1 instance
self.asn1_editor.to_asn1scc_swig(root=self.tree_items[var],
dest=asn1_instance, ASN1Swig=ASN1,
ASN1_type=sort)
sort=sort,
ASN1_AST=self.proc.dataview)
def on_event(self, tc_name=None, param=None):
''' Update the list of global states and GUI after a TC has been sent
......
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