Commit 84f8efa4 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Decode all input params of external procedure call

parent de8aedd0
......@@ -602,9 +602,39 @@ 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 called
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"
# 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]
for spec, (val, size) in zip(procedure.fpar, params):
# Decode input parameters
if spec['direction'] != 'in':
# 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):
# Create native ASN.1 type and put the swig buffer data into it
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
def set_timer(self, name, duration):
''' Callback function when the SDL model sets a timer '''
......@@ -660,14 +690,19 @@ class sdlHandler(QObject):
specified in the SDL model and connect them to handling function '''
# External procedures have a non-fixed number of parameters
# but the first one is always a char string (name of procedure)
func = ctypes.CFUNCTYPE(None, ctypes.c_char_p)
self.proc_handler = func(self.external_proc_handler)
self.proc_handlers = {}
for each in self.proc.procedures:
if not each.external:
# Variable number of parameters of type (void *, size)
params = (ctypes.c_char_p,) + \
(ctypes.c_void_p, ctypes.c_long) * len(each.fpar)
func = ctypes.CFUNCTYPE(None, *params)
self.proc_handlers[each.inputString.lower()] = \
(func(self.external_proc_handler), each)
register_func = getattr(self.dll, "register_{}"
def init_timers(self):
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