Commit d096c46e authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Work on autogui

parent c6863cad
......@@ -312,40 +312,35 @@ class asn1Editor(QTreeView):
def parseModel(self, root, nbRows=-1, dest=None):
''' Parse the model to get all field values recursively
root type is QStandardItem
(optional) dest is a ctypes instance of the type to fill
dest is a ctypes instance of the type to fill
'''
if dest is None:
self.log.error('parseModel: destination ASN.1 variable not set')
if root.hasChildren():
seqofValue = 0
seqOf = False
itemState = None
if nbRows == -1:
seqOf = True if nbRows != -1 else False
if not seqOf:
nbRows = root.rowCount()
else:
seqOf = True
destState = dest.GetState()
def parseRow(root, i, dest, choice=False, seqOf=False):
name = root.child(i, 0).text()
name = root.child(i, 0).text().replace('-', '_')
asnType = root.child(i, 1).text()
# Value appears with underscore in the GUI but keys use ASN.1
value = root.child(i, 3).text().replace('_', '-')
if not choice:
dest.Reset(destState)
value = root.child(i, 3).text()
ptr = getattr(dest, name) if not seqOf else dest
if seqOf:
ptr = ptr[i]
if asnType in ('SEQUENCE', 'SET'):
state = ptr.GetState()
if not seqOf:
ptr = getattr(ptr, name.replace('-', '_'))
#state = ptr.GetState()
#if not seqOf:
# ptr = getattr(ptr, name)
self.parseModel(root.child(i), dest=ptr)
ptr.Reset(state)
#ptr.Reset(state)
elif asnType == 'SEQOF':
state = ptr.GetState()
#if not seqOf:
# ptr = getattr(ptr, name.replace('-', '_'))
#state = ptr.GetState()
# XXX missing SetLength
self.parseModel(root.child(i), nbRows=int(value), dest=ptr)
ptr.Reset(state)
#ptr.Reset(state)
elif asnType == 'CHOICE':
state = ptr.GetState()
# We must parse only one row, containing the choice (value)
......@@ -367,7 +362,7 @@ class asn1Editor(QTreeView):
elif asnType == 'REAL':
ptr.Set(float(value))
elif asnType == 'BOOLEAN':
boolValue = True if value == 'True' else False
boolValue = value == 'True'
ptr.Set(boolValue)
elif asnType == 'ENUMERATED':
valNb = getattr(self.backend.DV, value.replace('-', '_'))
......@@ -377,8 +372,9 @@ class asn1Editor(QTreeView):
else: # Strings
ptr.SetFromPyString(value)
for i in xrange(nbRows): # for each child row
stateBefore = dest.GetState()
parseRow(root, i, dest, seqOf=seqOf)
dest.Reset(destState)
dest.Reset(stateBefore)
else: # single elements (all but SeqOf, Choice, Sequence)
row = root.row()
try:
......@@ -389,16 +385,28 @@ class asn1Editor(QTreeView):
value = ''
asnType = None
if asnType == 'INTEGER':
# TESTED OK
dest.Set(int(value))
elif asnType == 'REAL':
# TESTED OK
dest.Set(float(value))
elif asnType == 'BOOLEAN':
# TESTED OK
dest.Set(True if value == 'True' else False)
elif asnType == 'ENUMERATED':
# XXX probably not good, take name from data first
dest.Set(getattr(self.backend.DV, value.replace('-', '_')))
# TESTED OK
intMappings = self.model.item(row, 3).data(INTMAP)
for enumerant, num in intMappings.viewitems():
if enumerant == value:
print 'Value:', num
dest.Set(num)
break
else:
self.log.error('Missing enumerted or bug - please report')
elif asnType == 'STRING':
dest.SetFromPyString(value)
else: # What about octet string ? XXX CHECKME
pass
self.log.error('Unsupported type: please report bug')
def getVariable(self, root=None, dest=None):
''' Read the ASN.1 variable from the tree editor
......@@ -430,14 +438,13 @@ class asn1Editor(QTreeView):
nbRows = root.rowCount()
def fillRow(root, i, dest, choice=False, seqOf=False):
name = root.child(i, 0).text()
name = root.child(i, 0).text().replace('-', '_')
asnType = root.child(i, 1).text()
child = root.child(i, 3)
#if not choice:
# dest.Reset(destState)
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)
......@@ -485,21 +492,21 @@ class asn1Editor(QTreeView):
fillRow(root, i, ptr, seqOf=seqOf)
ptr.Reset(stateBefore)
def updateVariable(self, root=None):
def updateVariable(self, root=None, asn1Var=None):
''' Update the variable value (when loading a TC or receiving a TM) '''
root = root or self.treeItem
asn1Instance = asn1Var or self.asn1Instance
row = root.row()
name = root.text()
#value = var[name] # value replaced now by asn1Instance
asnType = self.model.item(row, 1).text()
if asnType == 'SEQOF':
# Set the number of items in column 3
nbElem = self.asn1Instance.GetLength()
nbElem = asn1Instance.GetLength()
self.model.item(row, 3).setText(str(nbElem))
# And set the values recursively
self.updateModel(root, ptr=self.asn1Instance, nbRows=nbElem)
self.updateModel(root, ptr=asn1Instance, nbRows=nbElem)
elif asnType == 'CHOICE':
kind = self.asn1Instance.kind.Get()
kind = asn1Instance.kind.Get()
# get the mapping to retrieve the choice name from the kind
intMappings = self.model.item(row, 3).data(INTMAP)
for enumerant, num in intMappings.viewitems():
......@@ -507,18 +514,18 @@ class asn1Editor(QTreeView):
break
else:
print("ERROR - CHOICE index not found in DV.py")
# how to translate this kind number into the choice string?
# how to translate this kind number into the choice string? XXX
self.model.item(row, 3).setText(enumerant)
# decode the actual value
ptr = getattr(self.asn1Instance, enumerant)
ptr = getattr(asn1Instance, enumerant.replace('-', '_'))
self.updateModel(root, ptr)
elif asnType in ('INTEGER', 'REAL', 'STRING', 'BOOLEAN'):
value = self.asn1Instance.Get()
value = asn1Instance.Get()
if asnType == 'BOOLEAN':
value = 'True' if value else 'False'
self.model.item(row, 3).setText(str(value))
elif asnType == 'ENUMERATED':
value = self.asn1Instance.Get()
value = asn1Instance.Get()
# get the mapping to retrieve the integer value
intMappings = self.model.item(row, 3).data(INTMAP)
for enumerant, num in intMappings.viewitems():
......@@ -526,9 +533,9 @@ class asn1Editor(QTreeView):
self.model.item(row, 3).setText(enumerant)
break
else:
print("ERROR - ENUMERATED value not found")
self.log.error("ENUMERATED value not found")
else: # SEQUENCE or SET
self.updateModel(root, self.asn1Instance)
self.updateModel(root, asn1Instance)
if asnType in ('INTEGER', 'REAL', 'SEQOF'):
plotters = self.model.item(row, 3).data(PLOTTERS)
if plotters != None:
......
......@@ -596,18 +596,18 @@ class sdlHandler(QObject):
size = get_size()
# ctypes hint: don't use c_char_p except for text strings
get_value = getattr(self.dll, "{}_value".format(var))
get_value.restype = ctypes.c_void_p # ctypes.POINTER(ctypes.c_char) # CHECKME
get_value.restype = ctypes.c_void_p
value = get_value()
#asn1_instance = getattr(ASN1, typename)()
#asn1_instance.SetData(value)
if not self.asn1_editor.asn1Instance:
print 'Creating instance of type ', self.asn1_editor.item['nodeTypename']
self.asn1_editor.asn1Instance = getattr(ASN1, self.asn1_editor.item['nodeTypename'])()
self.asn1_editor.asn1Instance.SetData(value)
asn1_instance = getattr(ASN1, typename)()
asn1_instance.SetData(value)
#typeC = self.asn1_editor.item['nodeTypename'].replace('-', '_')
#asn1_instance = getattr(ASN1, typeC)()
#self.asn1_editor.asn1Instance.SetData(value)
#gser = asn1_instance.GSER()
#as_pyside = vn.fromValueNotationToPySide(var, gser)
self.asn1_editor.updateVariable(root=self.tree_items[var])
complete_state.append(self.asn1_editor.asn1Instance) #asn1_instance)
self.asn1_editor.updateVariable(root=self.tree_items[var],
asn1Var=asn1_instance)
complete_state.append(asn1_instance)
# Add the SDL state to the new global state
complete_state.append(self.current_sdl_state)
# Update the SDL state in the global state panel
......
......@@ -123,6 +123,8 @@ def asn1sccToasn1ValueEditorTypes(dataview, name, asntype):
for child, childtype in t.Children.viewitems():
result['choices'].append(
asn1sccToasn1ValueEditorTypes(dataview, child, childtype.type))
result['choiceIdx'] = {enumerant: "DV.{}".format(chty.EnumID)
for enumerant, chty in t.Children.viewitems()}
elif t.kind.endswith('StringType'):
result['type'] = 'STRING'
result['id'] = name
......
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