Commit 5b1386c8 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Complete clean decoding of input and output args

parent 84f8efa4
......@@ -16,7 +16,7 @@
__author__ = "Maxime Perrotin"
__license__ = "LGPLv3"
__version__ = "1.0.1"
__version__ = "1.0.2"
__url__ = "http://taste.tuxfamily.org"
import sys
......
......@@ -602,39 +602,42 @@ class sdlHandler(QObject):
self.log_area.addItem('Received event "{}"'.format(tm_name))
def external_proc_handler(self, name, *args):
''' Callback function when an external procedure is called
''' Callback function when an external procedure is invoked
Parameters: name is the name of the external procedure, and
args is the list of arguments: (void*, size) for each in/out fpar
'''
self.log_area.addItem('Call to external procedure {}'.format(name))
assert len(args) % 2 is 0, "Invalid number of arguments"
interface = {'in' : [], 'out': []}
# Cut the params into tuples of (void *, size)
params = ((args[i], args[i+1]) for i in xrange(0, len(args), 2))
# Retrieve the AST of the procedure to get the list of FPARs
procedure = self.proc_handlers[name.lower()][1]
# Decode all input and output parameters and create native ASN.1 values
for spec, (val, size) in zip(procedure.fpar, params):
# Decode input parameters
if spec['direction'] != 'in':
continue
# Cast the void* to an array of unsigned bytes, knowing the size:
as_bytes = ctypes.cast(val,
ctypes.POINTER((ctypes.c_ubyte * (size / 8) )))
# Create a SWIG buffer of the same size:
swig_ptr = ASN1.DV.new_byte_SWIG_PTR(size / 8)
# Copy the content of the input buffer to the SWIG buffer:
for idx in xrange(size / 8):
ASN1.DV.byte_SWIG_PTR_setitem(swig_ptr,
idx,
as_bytes.contents[idx])
# Create native ASN.1 type and put the swig buffer data into it
ctypes.POINTER((ctypes.c_ubyte * (size / 8))))
# Create native ASN.1 type
typename = spec['type'].ReferencedTypeName.replace('-', '_')
asn1_type = self.proc.dataview[spec['type'].ReferencedTypeName]
asn1_instance = getattr(ASN1, typename)()
setter = getattr(ASN1.DV, "SetDataFor_{}".format(typename))
setter(asn1_instance._ptr, swig_ptr)
gser = asn1_instance.GSER()
#as_pyside = vn.fromValueNotationToPySide(var, gser)
print 'Input param:', gser
# Input parameters: copy the content in the ASN.1 Swig type
if spec['direction'] == 'in':
# Create a SWIG buffer of the same size:
swig_ptr = ASN1.DV.new_byte_SWIG_PTR(size / 8)
# Copy the content of the input buffer to the SWIG buffer:
for idx in xrange(size / 8):
ASN1.DV.byte_SWIG_PTR_setitem(swig_ptr,
idx,
as_bytes.contents[idx])
setter = getattr(ASN1.DV, "SetDataFor_{}".format(typename))
setter(asn1_instance._ptr, swig_ptr)
gser = asn1_instance.GSER()
print 'Input param:', gser
interface['in'].append((spec, asn1_instance))
else:
interface['out'].append((spec, as_bytes, asn1_instance))
def set_timer(self, name, duration):
''' Callback function when the SDL model sets a timer '''
......
Markdown is supported
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