mirror of https://github.com/pvnis/srsRAN_4G.git
Removed high-level modules and scripts
parent
3f357ad6f2
commit
68c4f3a6e1
@ -1,60 +0,0 @@
|
||||
#
|
||||
# Copyright 2012-2013 The libLTE Developers. See the
|
||||
# COPYRIGHT file at the top-level directory of this distribution.
|
||||
#
|
||||
# This file is part of the libLTE library.
|
||||
#
|
||||
# libLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# libLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Lesser General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
from module import Module
|
||||
from xml2aloe import MakeModule
|
||||
import sys, os, getopt
|
||||
|
||||
argv = sys.argv
|
||||
input_file = None
|
||||
output_dir = None
|
||||
try:
|
||||
opts, args = getopt.getopt(argv,"hi:o:",["input_file=","output_dir="])
|
||||
except getopt.GetoptError:
|
||||
print argv[0] + ' -i <input_file> -o <output_dir>'
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
if opt == '-h':
|
||||
print argv[0] + ' -i <input_file> -o <output_dir>'
|
||||
sys.exit()
|
||||
elif opt in ("-i", "--input_file"):
|
||||
input_file = arg
|
||||
elif opt in ("-o", "--output_dir"):
|
||||
output_dir = arg
|
||||
|
||||
if input_file == None or output_dir == None:
|
||||
print argv[0] + ' -i <input_file> -o <output_dir>'
|
||||
sys.exit(2)
|
||||
|
||||
filename=os.path.basename(input_file).split('.')[0]
|
||||
|
||||
print filename + '\n'
|
||||
print input_file + '\n'
|
||||
print output_dir + '\n'
|
||||
#m = Module("binsource")
|
||||
|
||||
#m.readHeader(input_file)
|
||||
#MakeModule(m,output_dir)
|
||||
#print m.toString()
|
||||
|
@ -1,31 +0,0 @@
|
||||
#
|
||||
# Copyright 2012-2013 The libLTE Developers. See the
|
||||
# COPYRIGHT file at the top-level directory of this distribution.
|
||||
#
|
||||
# This file is part of the libLTE library.
|
||||
#
|
||||
# libLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# libLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Lesser General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
from module import Module
|
||||
from xml2aloe import MakeModule
|
||||
|
||||
m = Module("binsource")
|
||||
m.readHeader('/home/ismael/work/osld-lib/scripts/binsource.h')
|
||||
MakeModule(m)
|
||||
print m.toString()
|
@ -1,311 +0,0 @@
|
||||
#
|
||||
# Copyright 2012-2013 The libLTE Developers. See the
|
||||
# COPYRIGHT file at the top-level directory of this distribution.
|
||||
#
|
||||
# This file is part of the libLTE library.
|
||||
#
|
||||
# libLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# libLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Lesser General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
|
||||
|
||||
from xml.dom.minidom import Document,parseString
|
||||
from pyclibrary import CParser
|
||||
|
||||
class Module:
|
||||
# name
|
||||
nof_inputs=0
|
||||
nof_outputs=0
|
||||
init_params = []
|
||||
input_params = []
|
||||
output_params = []
|
||||
|
||||
def __init__(self,name):
|
||||
self.name=name
|
||||
self.init_func=name+'_initialize'
|
||||
self.work_func=name+'_work'
|
||||
self.handler=name+'_hl'
|
||||
self.handler_instance=name
|
||||
self.init_pm_struct=name+'_init'
|
||||
self.input_pm_struct=name+'_ctrl_in'
|
||||
self.output_pm_struct=name+'_ctrl_out'
|
||||
self.directory_name = 'lib_' + name
|
||||
|
||||
def set_input(self,nof_inputs, input_type, input_size):
|
||||
self.nof_inputs = nof_inputs
|
||||
self.input_type = input_type
|
||||
self.input_size = input_size
|
||||
|
||||
def set_output(self,nof_outputs, output_type, output_size):
|
||||
self.nof_outputs = nof_outputs
|
||||
self.output_type = output_type
|
||||
self.output_size = output_size
|
||||
|
||||
def add_init_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.init.'+name,'type':type,'default':default}
|
||||
self.init_params.append(p)
|
||||
|
||||
def add_input_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.ctrl_in.'+name,'type':type,'default':default}
|
||||
self.input_params.append(p)
|
||||
|
||||
def add_output_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.ctrl_in.'+name,'type':type,'default':default}
|
||||
self.output_params.append(p)
|
||||
|
||||
def toString(self):
|
||||
s = 'name: ' + self.name + '\n'
|
||||
s = s + 'handler: ' + self.handler + '\n'
|
||||
if self.nof_inputs > 0:
|
||||
s = s + str(self.nof_inputs) + ' ' + self.input_type + ' inputs of size ' + str(self.output.size) + '\n'
|
||||
else:
|
||||
s = s + 'no inputs\n'
|
||||
if self.nof_outputs > 0:
|
||||
s = s + str(self.nof_outputs) + ' ' + self.output_type + ' outputs of size ' + str(self.output_size) + '\n'
|
||||
else:
|
||||
s = s + 'no outputs\n'
|
||||
|
||||
if self.init_params:
|
||||
s = s + 'Initialization parameters:\n'
|
||||
for p in self.init_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name'] + ' = ' + p['default'] + '\n'
|
||||
|
||||
if self.input_params:
|
||||
s = s + 'Input parameters:\n'
|
||||
for p in self.input_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name']
|
||||
if p['default'] == None:
|
||||
s = s + ' (Mandatory)\n'
|
||||
else:
|
||||
s = s + ' = ' + p['default'] + '\n'
|
||||
|
||||
if self.output_params:
|
||||
s = s + 'Output parameters:\n'
|
||||
for p in self.output_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name'] + '\n'
|
||||
return s
|
||||
|
||||
def toXML(self):
|
||||
root = Document()
|
||||
|
||||
module = root.createElement('module')
|
||||
root.appendChild(module)
|
||||
|
||||
module.setAttribute("name",self.name)
|
||||
module.setAttribute("handler",self.handler)
|
||||
module.setAttribute("handler_instance",self.handler_instance)
|
||||
|
||||
# Functions
|
||||
functions = root.createElement("functions")
|
||||
module.appendChild(functions)
|
||||
functions.setAttribute("initialize",self.init_func)
|
||||
functions.setAttribute("work",self.work_func)
|
||||
|
||||
# Interfaces
|
||||
inputs = root.createElement("inputs")
|
||||
module.appendChild(inputs)
|
||||
inputs.setAttribute("num",str(self.nof_inputs))
|
||||
inputs.setAttribute("type",self.input_type)
|
||||
inputs.setAttribute("size",self.input_size)
|
||||
|
||||
outputs = root.createElement("outputs")
|
||||
module.appendChild(outputs)
|
||||
outputs.setAttribute("num",str(self.nof_outputs))
|
||||
outputs.setAttribute("type",self.output_type)
|
||||
outputs.setAttribute("size",self.output_size)
|
||||
|
||||
# Init Parameters
|
||||
pinit = root.createElement("init_parameters")
|
||||
module.appendChild(pinit)
|
||||
for p in self.init_params:
|
||||
pi = root.createElement("param")
|
||||
pinit.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
pi.setAttribute("default",p['default'])
|
||||
|
||||
pinput = root.createElement("input_parameters")
|
||||
module.appendChild(pinput)
|
||||
for p in self.input_params:
|
||||
pi = root.createElement("param")
|
||||
pinput.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
pi.setAttribute("default",p['default'])
|
||||
|
||||
poutput = root.createElement("output_parameters")
|
||||
module.appendChild(poutput)
|
||||
for p in self.input_params:
|
||||
pi = root.createElement("param")
|
||||
pinput.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
|
||||
|
||||
return root.toprettyxml()
|
||||
|
||||
def readXML(self, string):
|
||||
root = parseString(string)
|
||||
module = root.getElementsByTagName("module").item(0)
|
||||
|
||||
self.name = module.getAttribute("name")
|
||||
self.handler = module.getAttribute("handler")
|
||||
self.handler_instance = module.getAttribute("handler_instance")
|
||||
|
||||
functions = root.getElementsByTagName("functions").item(0)
|
||||
self.init_func = functions.getAttribute("initialize")
|
||||
self.work_func = functions.getAttribute("work")
|
||||
|
||||
# Interfaces
|
||||
inputs = root.getElementsByTagName("inputs").item(0)
|
||||
self.nof_inputs = int(inputs.getAttribute("num"))
|
||||
self.input_type = inputs.getAttribute("type")
|
||||
self.input_size = inputs.getAttribute("size")
|
||||
|
||||
outputs = root.getElementsByTagName("outputs").item(0)
|
||||
self.nof_outputs = int(outputs.getAttribute("num"))
|
||||
self.output_type = outputs.getAttribute("type")
|
||||
self.output_size = outputs.getAttribute("size")
|
||||
|
||||
pinit = root.getElementsByTagName("init_parameters").item(0)
|
||||
for p in pinit.getElementsByTagName("params"):
|
||||
self.init_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"), \
|
||||
'type':p.getAttribute("type"),\
|
||||
'default':p.getAttribute("default")})
|
||||
|
||||
pinput = root.getElementsByTagName("input_parameters").item(0)
|
||||
for p in pinput.getElementsByTagName("params"):
|
||||
self.input_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"),\
|
||||
'type':p.getAttribute("type"),\
|
||||
'default':p.getAttribute("default")})
|
||||
|
||||
poutput = root.getElementsByTagName("output_parameters").item(0)
|
||||
for p in poutput.getElementsByTagName("params"):
|
||||
self.output_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"),\
|
||||
'type':p.getAttribute("type")})
|
||||
def findMember(self,members, name):
|
||||
for m in members:
|
||||
if m[0] == name:
|
||||
return m
|
||||
return None
|
||||
|
||||
def findDefault(self, lines, variable):
|
||||
for line in lines:
|
||||
if variable in line:
|
||||
if 'default' in line.lower():
|
||||
return str(int(line.split('=')[1].split('*/')[0]))
|
||||
else:
|
||||
return None
|
||||
|
||||
def findSize(self, lines, variable):
|
||||
for line in lines:
|
||||
if variable in line:
|
||||
if 'size' in line.lower():
|
||||
return line.split('=')[1].split('*/')[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def findLinesStruct(self, lines, struct_name):
|
||||
slines = []
|
||||
state = "nf"
|
||||
for line in lines:
|
||||
if state == 'nf':
|
||||
if 'struct ' + struct_name in line:
|
||||
state = "f1"
|
||||
elif state == 'f1':
|
||||
if '}' in line:
|
||||
state = 'f2'
|
||||
return slines
|
||||
else:
|
||||
slines.append(line)
|
||||
|
||||
def findLinesHandler(self,file_name):
|
||||
with open(file_name,'r') as f:
|
||||
slines = []
|
||||
state = "nf"
|
||||
for line in reversed(f.readlines()):
|
||||
if state == 'nf':
|
||||
if self.handler in line and '}' in line:
|
||||
state = "f1"
|
||||
elif state == 'f1':
|
||||
if 'typedef' in line and 'struct' in line:
|
||||
state = 'f2'
|
||||
return reversed(slines)
|
||||
else:
|
||||
slines.append(line)
|
||||
|
||||
def readHeader(self, file_name):
|
||||
|
||||
p = CParser([file_name])
|
||||
h = p.defs['structs'][p.defs['types'][p.defs['types'][self.handler][0]][1]]['members']
|
||||
|
||||
input = self.findMember(h,'input')
|
||||
if input == None:
|
||||
self.nof_inputs = 0
|
||||
self.input_type = None
|
||||
self.input_size = 0
|
||||
else:
|
||||
self.nof_inputs = input[1][2][0]
|
||||
self.input_type = input[1][0]
|
||||
size = self.findSize(self.findLinesHandler(file_name), 'input')
|
||||
if size == None:
|
||||
size = '2048*20'
|
||||
self.input_size = size
|
||||
|
||||
output = self.findMember(h,'output')
|
||||
if output == None:
|
||||
self.nof_outputs = 0
|
||||
self.output_type = None
|
||||
self.output_size = 0
|
||||
else:
|
||||
self.nof_outputs = output[1][2][0]
|
||||
self.output_type = output[1][0]
|
||||
size = self.findSize(self.findLinesHandler(file_name), 'output')
|
||||
if size == None:
|
||||
size = '2048*20'
|
||||
self.output_size = size
|
||||
|
||||
initpm = p.defs['structs'].get(self.init_pm_struct)
|
||||
if (initpm != None):
|
||||
for m in initpm['members']:
|
||||
default = self.findDefault(self.findLinesStruct(\
|
||||
self.findLinesHandler(file_name),\
|
||||
self.init_pm_struct), m[0])
|
||||
if default == None:
|
||||
default = '0'
|
||||
self.init_params.append({'name':m[0],'variable':self.name+'.init.'+m[0],\
|
||||
'type':m[1][0],'default':default})
|
||||
|
||||
|
||||
inputpm = p.defs['structs'].get(self.input_pm_struct)
|
||||
if (inputpm != None):
|
||||
for m in inputpm['members']:
|
||||
default = self.findDefault(self.findLinesStruct(\
|
||||
self.findLinesHandler(file_name),\
|
||||
self.input_pm_struct), m[0])
|
||||
self.input_params.append({'name':m[0],'variable':self.name+'.ctrl_in.'+m[0],\
|
||||
'type':m[1][0],'default':default})
|
||||
|
||||
outputpm = p.defs['structs'].get(self.output_pm_struct)
|
||||
if (outputpm != None):
|
||||
for m in outputpm['members']:
|
||||
self.output_params.append({'name':m[0],'variable':self.name+'.ctrl_out.'+m[0],\
|
||||
'type':m[1][0]})
|
||||
|
Binary file not shown.
@ -1,319 +0,0 @@
|
||||
#
|
||||
# Copyright 2012-2013 The libLTE Developers. See the
|
||||
# COPYRIGHT file at the top-level directory of this distribution.
|
||||
#
|
||||
# This file is part of the libLTE library.
|
||||
#
|
||||
# libLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# libLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Lesser General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
|
||||
|
||||
from xml.dom.minidom import Document,parseString
|
||||
from pyclibrary import CParser
|
||||
|
||||
class Module:
|
||||
# name
|
||||
nof_inputs=0
|
||||
nof_outputs=0
|
||||
init_params = []
|
||||
input_params = []
|
||||
output_params = []
|
||||
|
||||
def __init__(self,name):
|
||||
self.name=name
|
||||
self.init_func=name+'_initialize'
|
||||
self.work_func=name+'_work'
|
||||
self.handler=name+'_hl'
|
||||
self.handler_instance=name
|
||||
self.init_pm_struct=name+'_init'
|
||||
self.input_pm_struct=name+'_ctrl_in'
|
||||
self.output_pm_struct=name+'_ctrl_out'
|
||||
self.directory_name = 'lib_' + name
|
||||
self.library_name = 'osld'
|
||||
|
||||
def set_input(self,nof_inputs, input_type, input_size):
|
||||
self.nof_inputs = nof_inputs
|
||||
self.input_type = input_type
|
||||
self.input_size = input_size
|
||||
|
||||
def set_output(self,nof_outputs, output_type, output_size):
|
||||
self.nof_outputs = nof_outputs
|
||||
self.output_type = output_type
|
||||
self.output_size = output_size
|
||||
|
||||
def add_init_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.init.'+name,'type':type,'default':default}
|
||||
self.init_params.append(p)
|
||||
|
||||
def add_input_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.ctrl_in.'+name,'type':type,'default':default}
|
||||
self.input_params.append(p)
|
||||
|
||||
def add_output_param(self,name,type,default):
|
||||
p={'name':name,'variable':self.name+'.ctrl_in.'+name,'type':type,'default':default}
|
||||
self.output_params.append(p)
|
||||
|
||||
def toString(self):
|
||||
s = 'name: ' + self.name + '\n'
|
||||
s = s + 'handler: ' + self.handler + '\n'
|
||||
s = s + 'directory: ' + self.directory_name + '\n'
|
||||
s = s + 'library name: ' + self.library_name + '\n'
|
||||
|
||||
if self.nof_inputs > 0:
|
||||
s = s + str(self.nof_inputs) + ' ' + self.input_type + ' inputs of size ' + str(self.output.size) + '\n'
|
||||
else:
|
||||
s = s + 'no inputs\n'
|
||||
if self.nof_outputs > 0:
|
||||
s = s + str(self.nof_outputs) + ' ' + self.output_type + ' outputs of size ' + str(self.output_size) + '\n'
|
||||
else:
|
||||
s = s + 'no outputs\n'
|
||||
|
||||
if self.init_params:
|
||||
s = s + 'Initialization parameters:\n'
|
||||
for p in self.init_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name'] + ' = ' + p['default'] + '\n'
|
||||
|
||||
if self.input_params:
|
||||
s = s + 'Input parameters:\n'
|
||||
for p in self.input_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name']
|
||||
if p['default'] == None:
|
||||
s = s + ' (Mandatory)\n'
|
||||
else:
|
||||
s = s + ' = ' + p['default'] + '\n'
|
||||
|
||||
if self.output_params:
|
||||
s = s + 'Output parameters:\n'
|
||||
for p in self.output_params:
|
||||
s = s + ' - ' + p['type'] + ' ' + p['name'] + '\n'
|
||||
return s
|
||||
|
||||
def toXML(self):
|
||||
root = Document()
|
||||
|
||||
module = root.createElement('module')
|
||||
root.appendChild(module)
|
||||
|
||||
module.setAttribute("name",self.name)
|
||||
module.setAttribute("handler",self.handler)
|
||||
module.setAttribute("handler_instance",self.handler_instance)
|
||||
module.setAttribute("library",self.library_name)
|
||||
module.setAttribute("directory_name",self.directory_name)
|
||||
|
||||
# Functions
|
||||
functions = root.createElement("functions")
|
||||
module.appendChild(functions)
|
||||
functions.setAttribute("initialize",self.init_func)
|
||||
functions.setAttribute("work",self.work_func)
|
||||
|
||||
# Interfaces
|
||||
inputs = root.createElement("inputs")
|
||||
module.appendChild(inputs)
|
||||
inputs.setAttribute("num",str(self.nof_inputs))
|
||||
inputs.setAttribute("type",self.input_type)
|
||||
inputs.setAttribute("size",self.input_size)
|
||||
|
||||
outputs = root.createElement("outputs")
|
||||
module.appendChild(outputs)
|
||||
outputs.setAttribute("num",str(self.nof_outputs))
|
||||
outputs.setAttribute("type",self.output_type)
|
||||
outputs.setAttribute("size",self.output_size)
|
||||
|
||||
# Init Parameters
|
||||
pinit = root.createElement("init_parameters")
|
||||
module.appendChild(pinit)
|
||||
for p in self.init_params:
|
||||
pi = root.createElement("param")
|
||||
pinit.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
pi.setAttribute("default",p['default'])
|
||||
|
||||
pinput = root.createElement("input_parameters")
|
||||
module.appendChild(pinput)
|
||||
for p in self.input_params:
|
||||
pi = root.createElement("param")
|
||||
pinput.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
pi.setAttribute("default",p['default'])
|
||||
|
||||
poutput = root.createElement("output_parameters")
|
||||
module.appendChild(poutput)
|
||||
for p in self.input_params:
|
||||
pi = root.createElement("param")
|
||||
pinput.appendChild(pi)
|
||||
pi.setAttribute("name",p['name'])
|
||||
pi.setAttribute("var",p['variable'])
|
||||
pi.setAttribute("type",p['type'])
|
||||
|
||||
|
||||
return root.toprettyxml()
|
||||
|
||||
def readXML(self, string):
|
||||
root = parseString(string)
|
||||
module = root.getElementsByTagName("module").item(0)
|
||||
|
||||
self.name = module.getAttribute("name")
|
||||
self.handler = module.getAttribute("handler")
|
||||
self.handler_instance = module.getAttribute("handler_instance")
|
||||
self.directory_name = module.getAttribute("directory_name")
|
||||
self.library_name = module.getAttribute("library")
|
||||
|
||||
functions = root.getElementsByTagName("functions").item(0)
|
||||
self.init_func = functions.getAttribute("initialize")
|
||||
self.work_func = functions.getAttribute("work")
|
||||
|
||||
# Interfaces
|
||||
inputs = root.getElementsByTagName("inputs").item(0)
|
||||
self.nof_inputs = int(inputs.getAttribute("num"))
|
||||
self.input_type = inputs.getAttribute("type")
|
||||
self.input_size = inputs.getAttribute("size")
|
||||
|
||||
outputs = root.getElementsByTagName("outputs").item(0)
|
||||
self.nof_outputs = int(outputs.getAttribute("num"))
|
||||
self.output_type = outputs.getAttribute("type")
|
||||
self.output_size = outputs.getAttribute("size")
|
||||
|
||||
pinit = root.getElementsByTagName("init_parameters").item(0)
|
||||
for p in pinit.getElementsByTagName("params"):
|
||||
self.init_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"), \
|
||||
'type':p.getAttribute("type"),\
|
||||
'default':p.getAttribute("default")})
|
||||
|
||||
pinput = root.getElementsByTagName("input_parameters").item(0)
|
||||
for p in pinput.getElementsByTagName("params"):
|
||||
self.input_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"),\
|
||||
'type':p.getAttribute("type"),\
|
||||
'default':p.getAttribute("default")})
|
||||
|
||||
poutput = root.getElementsByTagName("output_parameters").item(0)
|
||||
for p in poutput.getElementsByTagName("params"):
|
||||
self.output_params.appendChild({'name':p.getAttribute("name"),\
|
||||
'variable':p.getAttribute("variable"),\
|
||||
'type':p.getAttribute("type")})
|
||||
def findMember(self,members, name):
|
||||
for m in members:
|
||||
if m[0] == name:
|
||||
return m
|
||||
return None
|
||||
|
||||
def findDefault(self, lines, variable):
|
||||
for line in lines:
|
||||
if variable in line:
|
||||
if 'default' in line.lower():
|
||||
return str(int(line.split('=')[1].split('*/')[0]))
|
||||
else:
|
||||
return None
|
||||
|
||||
def findSize(self, lines, variable):
|
||||
for line in lines:
|
||||
if variable in line:
|
||||
if 'size' in line.lower():
|
||||
return line.split('=')[1].split('*/')[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def findLinesStruct(self, lines, struct_name):
|
||||
slines = []
|
||||
state = "nf"
|
||||
for line in lines:
|
||||
if state == 'nf':
|
||||
if 'struct ' + struct_name in line:
|
||||
state = "f1"
|
||||
elif state == 'f1':
|
||||
if '}' in line:
|
||||
state = 'f2'
|
||||
return slines
|
||||
else:
|
||||
slines.append(line)
|
||||
|
||||
def findLinesHandler(self,file_name):
|
||||
with open(file_name,'r') as f:
|
||||
slines = []
|
||||
state = "nf"
|
||||
for line in reversed(f.readlines()):
|
||||
if state == 'nf':
|
||||
if self.handler in line and '}' in line:
|
||||
state = "f1"
|
||||
elif state == 'f1':
|
||||
if 'typedef' in line and 'struct' in line:
|
||||
state = 'f2'
|
||||
return reversed(slines)
|
||||
else:
|
||||
slines.append(line)
|
||||
|
||||
def readHeader(self, file_name):
|
||||
|
||||
p = CParser([file_name])
|
||||
h = p.defs['structs'][p.defs['types'][p.defs['types'][self.handler][0]][1]]['members']
|
||||
|
||||
input = self.findMember(h,'input')
|
||||
if input == None:
|
||||
self.nof_inputs = 0
|
||||
self.input_type = None
|
||||
self.input_size = 0
|
||||
else:
|
||||
self.nof_inputs = input[1][2][0]
|
||||
self.input_type = input[1][0]
|
||||
size = self.findSize(self.findLinesHandler(file_name), 'input')
|
||||
if size == None:
|
||||
size = '2048*20'
|
||||
self.input_size = size
|
||||
|
||||
output = self.findMember(h,'output')
|
||||
if output == None:
|
||||
self.nof_outputs = 0
|
||||
self.output_type = None
|
||||
self.output_size = 0
|
||||
else:
|
||||
self.nof_outputs = output[1][2][0]
|
||||
self.output_type = output[1][0]
|
||||
size = self.findSize(self.findLinesHandler(file_name), 'output')
|
||||
if size == None:
|
||||
size = '2048*20'
|
||||
self.output_size = size
|
||||
|
||||
initpm = p.defs['structs'].get(self.init_pm_struct)
|
||||
if (initpm != None):
|
||||
for m in initpm['members']:
|
||||
default = self.findDefault(self.findLinesStruct(\
|
||||
self.findLinesHandler(file_name),\
|
||||
self.init_pm_struct), m[0])
|
||||
if default == None:
|
||||
default = '0'
|
||||
self.init_params.append({'name':m[0],'variable':self.name+'.init.'+m[0],\
|
||||
'type':m[1][0],'default':default})
|
||||
|
||||
|
||||
inputpm = p.defs['structs'].get(self.input_pm_struct)
|
||||
if (inputpm != None):
|
||||
for m in inputpm['members']:
|
||||
default = self.findDefault(self.findLinesStruct(\
|
||||
self.findLinesHandler(file_name),\
|
||||
self.input_pm_struct), m[0])
|
||||
self.input_params.append({'name':m[0],'variable':self.name+'.ctrl_in.'+m[0],\
|
||||
'type':m[1][0],'default':default})
|
||||
|
||||
outputpm = p.defs['structs'].get(self.output_pm_struct)
|
||||
if (outputpm != None):
|
||||
for m in outputpm['members']:
|
||||
self.output_params.append({'name':m[0],'variable':self.name+'.ctrl_out.'+m[0],\
|
||||
'type':m[1][0]})
|
||||
|
Binary file not shown.
@ -1,501 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
CLibrary.py - Provides CLibrary class
|
||||
Copyright 2010 Luke Campagnola
|
||||
Distributed under MIT/X11 license. See license.txt for more infomation.
|
||||
|
||||
Proxy to both CHeader and ctypes, allowing automatic type conversion and
|
||||
function calling based on C header definitions.
|
||||
"""
|
||||
|
||||
|
||||
from ctypes import *
|
||||
import sys
|
||||
|
||||
|
||||
class CLibrary:
|
||||
"""The CLibrary class is intended to automate much of the work in using ctypes by integrating
|
||||
header file definitions from CParser. Ths class serves as a proxy to a ctypes, adding
|
||||
a few features:
|
||||
- allows easy access to values defined via CParser
|
||||
- automatic type conversions for function calls using CParser function signatures
|
||||
- creates ctype classes based on type definitions from CParser
|
||||
|
||||
Initialize using a ctypes shared object and a CParser:
|
||||
headers = CParser.winDefs()
|
||||
lib = CLibrary(windll.User32, headers)
|
||||
|
||||
There are 3 ways to access library elements:
|
||||
lib(type, name) - type can be one of 'values', 'functions', 'types', 'structs', 'unions', or 'enums'.
|
||||
Returns an object matching name. For values, the value from the headers is
|
||||
returned. For functions, a callable object is returned that handles automatic
|
||||
type conversion for arguments and return values. for structs, types, and enums,
|
||||
a ctypes class is returned matching the type specified.
|
||||
lib.name - searches in order through values, functions, types, structs, unions, and enums from
|
||||
header definitions and returns an object for the first match found. The object
|
||||
returned is the same as returned by lib(type, name). This is the preferred way to access
|
||||
elements from CLibrary, but may not work in some situations (for example, if
|
||||
a struct and variable share the same name).
|
||||
lib[type] - Accesses the header definitions directly, returns definition dictionaries
|
||||
based on the type requested. This is equivalent to headers.defs[type].
|
||||
"""
|
||||
Null = object()
|
||||
|
||||
cTypes = {
|
||||
'char': c_char,
|
||||
'wchar': c_wchar,
|
||||
'unsigned char': c_ubyte,
|
||||
'short': c_short,
|
||||
'short int': c_short,
|
||||
'unsigned short': c_ushort,
|
||||
'unsigned short int': c_ushort,
|
||||
'int': c_int,
|
||||
'unsigned': c_uint,
|
||||
'unsigned int': c_uint,
|
||||
'long': c_long,
|
||||
'long int': c_long,
|
||||
'unsigned long': c_ulong,
|
||||
'unsigned long int': c_ulong,
|
||||
'__int64': c_longlong,
|
||||
'long long': c_longlong,
|
||||
'long long int': c_longlong,
|
||||
'unsigned __int64': c_ulonglong,
|
||||
'unsigned long long': c_ulonglong,
|
||||
'unsigned long long int': c_ulonglong,
|
||||
'float': c_float,
|
||||
'double': c_double,
|
||||
'long double': c_longdouble
|
||||
}
|
||||
cPtrTypes = {
|
||||
'char': c_char_p,
|
||||
'wchar': c_wchar_p,
|
||||
'void': c_void_p
|
||||
}
|
||||
|
||||
|
||||
|
||||
def __init__(self, lib, headers, prefix=None):
|
||||
## name everything using underscores to avoid name collisions with library
|
||||
|
||||
self._lib_ = lib
|
||||
self._headers_ = headers
|
||||
self._defs_ = headers.defs
|
||||
if prefix is None:
|
||||
self._prefix_ = []
|
||||
elif type(prefix) is list:
|
||||
self._prefix_ = prefix
|
||||
else:
|
||||
self._prefix_ = [prefix]
|
||||
self._objs_ = {}
|
||||
for k in ['values', 'functions', 'types', 'structs', 'unions', 'enums']:
|
||||
self._objs_[k] = {}
|
||||
self._allObjs_ = {}
|
||||
self._structs_ = {}
|
||||
self._unions_ = {}
|
||||
|
||||
def __call__(self, typ, name):
|
||||
if typ not in self._objs_:
|
||||
typs = self._objs_.keys()
|
||||
raise Exception("Type must be one of %s" % str(typs))
|
||||
|
||||
if name not in self._objs_[typ]:
|
||||
self._objs_[typ][name] = self._mkObj_(typ, name)
|
||||
|
||||
return self._objs_[typ][name]
|
||||
|
||||
def _allNames_(self, name):
|
||||
return [name] + [p + name for p in self._prefix_]
|
||||
|
||||
def _mkObj_(self, typ, name):
|
||||
names = self._allNames_(name)
|
||||
|
||||
for n in names:
|
||||
if n in self._objs_:
|
||||
return self._objs_[n]
|
||||
|
||||
for n in names: ## try with and without prefix
|
||||
if n not in self._defs_[typ] and not (typ in ['structs', 'unions', 'enums'] and n in self._defs_['types']):
|
||||
continue
|
||||
|
||||
if typ == 'values':
|
||||
return self._defs_[typ][n]
|
||||
elif typ == 'functions':
|
||||
return self._getFunction(n)
|
||||
elif typ == 'types':
|
||||
obj = self._defs_[typ][n]
|
||||
return self._ctype(obj)
|
||||
elif typ == 'structs':
|
||||
return self._cstruct('structs', n)
|
||||
elif typ == 'unions':
|
||||
return self._cstruct('unions', n)
|
||||
elif typ == 'enums':
|
||||
## Allow automatic resolving of typedefs that alias enums
|
||||
if n not in self._defs_['enums']:
|
||||
if n not in self._defs_['types']:
|
||||
raise Exception('No enums named "%s"' % n)
|
||||
typ = self._headers_.evalType([n])[0]
|
||||
if typ[:5] != 'enum ':
|
||||
raise Exception('No enums named "%s"' % n)
|
||||
n = self._defs_['types'][typ][1] ## look up internal name of enum
|
||||
obj = self._defs_['enums'][n]
|
||||
|
||||
return obj
|
||||
else:
|
||||
raise Exception("Unknown type %s" % typ)
|
||||
raise NameError(name)
|
||||
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""Used to retrieve any type of definition from the headers. Searches for the name in this order:
|
||||
values, functions, types, structs, unions, enums."""
|
||||
if name not in self._allObjs_:
|
||||
names = self._allNames_(name)
|
||||
for k in ['values', 'functions', 'types', 'structs', 'unions', 'enums', None]:
|
||||
if k is None:
|
||||
raise NameError(name)
|
||||
obj = None
|
||||
for n in names:
|
||||
if n in self._defs_[k]:
|
||||
obj = self(k, n)
|
||||
break
|
||||
if obj is not None:
|
||||
break
|
||||
self._allObjs_[name] = obj
|
||||
return self._allObjs_[name]
|
||||
|
||||
def __getitem__(self, name):
|
||||
"""Used to retrieve a specific dictionary from the headers."""
|
||||
return self._defs_[name]
|
||||
|
||||
def __repr__(self):
|
||||
return "<CLibrary instance: %s>" % str(self._lib_)
|
||||
|
||||
def _getFunction(self, funcName):
|
||||
try:
|
||||
func = getattr(self._lib_, funcName)
|
||||
except:
|
||||
raise Exception("Function name '%s' appears in headers but not in library!" % func)
|
||||
|
||||
#print "create function %s," % (funcName), self._defs_['functions'][funcName]
|
||||
return CFunction(self, func, self._defs_['functions'][funcName], funcName)
|
||||
|
||||
def _ctype(self, typ, pointers=True):
|
||||
"""return a ctype object representing the named type.
|
||||
If pointers is True, the class returned includes all pointer/array specs provided.
|
||||
Otherwise, the class returned is just the base type with no pointers."""
|
||||
try:
|
||||
typ = self._headers_.evalType(typ)
|
||||
mods = typ[1:][:]
|
||||
|
||||
## Create the initial type
|
||||
## Some types like ['char', '*'] have a specific ctype (c_char_p)
|
||||
## (but only do this if pointers == True)
|
||||
if pointers and len(typ) > 1 and typ[1] == '*' and typ[0] in CLibrary.cPtrTypes:
|
||||
cls = CLibrary.cPtrTypes[typ[0]]
|
||||
mods = typ[2:]
|
||||
|
||||
## If the base type is in the list of existing ctypes:
|
||||
elif typ[0] in CLibrary.cTypes:
|
||||
cls = CLibrary.cTypes[typ[0]]
|
||||
|
||||
## structs, unions, enums:
|
||||
elif typ[0][:7] == 'struct ':
|
||||
cls = self._cstruct('structs', self._defs_['types'][typ[0]][1])
|
||||
elif typ[0][:6] == 'union ':
|
||||
cls = self._cstruct('unions', self._defs_['types'][typ[0]][1])
|
||||
elif typ[0][:5] == 'enum ':
|
||||
cls = c_int
|
||||
|
||||
## void
|
||||
elif typ[0] == 'void':
|
||||
cls = None
|
||||
else:
|
||||
#print typ
|
||||
raise Exception("Can't find base type for %s" % str(typ))
|
||||
|
||||
if not pointers:
|
||||
return cls
|
||||
|
||||
## apply pointers and arrays
|
||||
while len(mods) > 0:
|
||||
m = mods.pop(0)
|
||||
if isinstance(m, basestring): ## pointer or reference
|
||||
if m[0] == '*' or m[0] == '&':
|
||||
for i in m:
|
||||
cls = POINTER(cls)
|
||||
elif type(m) is list: ## array
|
||||
for i in m:
|
||||
if i == -1: ## -1 indicates an 'incomplete type' like "int variable[]"
|
||||
cls = POINTER(cls) ## which we should interpret like "int *variable"
|
||||
else:
|
||||
cls = cls * i
|
||||
elif type(m) is tuple: ## Probably a function pointer
|
||||
## Find pointer and calling convention
|
||||
isPtr = False
|
||||
conv = '__cdecl'
|
||||
if len(mods) == 0:
|
||||
raise Exception("Function signature with no pointer:", m, mods)
|
||||
for i in [0,1]:
|
||||
if len(mods) < 1:
|
||||
break
|
||||
if mods[0] == '*':
|
||||
mods.pop(0)
|
||||
isPtr = True
|
||||
elif mods[0] in ['__stdcall', '__cdecl']:
|
||||
conv = mods.pop(0)
|
||||
else:
|
||||
break
|
||||
if not isPtr:
|
||||
raise Exception("Not sure how to handle type (function without single pointer): %s" % str(typ))
|
||||
|
||||
if conv == '__stdcall':
|
||||
mkfn = WINFUNCTYPE
|
||||
else:
|
||||
mkfn = CFUNCTYPE
|
||||
#print "Create function pointer (%s)" % conv
|
||||
|
||||
args = [self._ctype(arg[1]) for arg in m]
|
||||
cls = mkfn(cls, *args)
|
||||
|
||||
else:
|
||||
raise Exception("Not sure what to do with this type modifier: '%s'" % str(p))
|
||||
return cls
|
||||
except:
|
||||
print "Error while processing type", typ
|
||||
raise
|
||||
|
||||
def _cstruct(self, strType, strName):
|
||||
if strName not in self._structs_:
|
||||
|
||||
## Resolve struct name--typedef aliases allowed.
|
||||
if strName not in self._defs_[strType]:
|
||||
if strName not in self._defs_['types']:
|
||||
raise Exception('No struct/union named "%s"' % strName)
|
||||
typ = self._headers_.evalType([strName])[0]
|
||||
if typ[:7] != 'struct ' and typ[:6] != 'union ':
|
||||
raise Exception('No struct/union named "%s"' % strName)
|
||||
strName = self._defs_['types'][typ][1]
|
||||
|
||||
## Pull struct definition
|
||||
defn = self._defs_[strType][strName]
|
||||
|
||||
|
||||
## create ctypes class
|
||||
defs = defn['members'][:]
|
||||
if strType == 'structs':
|
||||
class s(Structure):
|
||||
def __repr__(self):
|
||||
return "<ctypes struct '%s'>" % strName
|
||||
elif strType == 'unions':
|
||||
class s(Union):
|
||||
def __repr__(self):
|
||||
return "<ctypes union '%s'>" % strName
|
||||
|
||||
|
||||
## must register struct here to allow recursive definitions.
|
||||
self._structs_[strName] = s
|
||||
|
||||
if defn['pack'] is not None:
|
||||
s._pack_ = defn['pack']
|
||||
|
||||
## assign names to anonymous members
|
||||
members = []
|
||||
anon = []
|
||||
for i in range(len(defs)):
|
||||
if defs[i][0] is None:
|
||||
c = 0
|
||||
while True:
|
||||
name = 'anon_member%d' % c
|
||||
if name not in members:
|
||||
defs[i][0] = name
|
||||
anon.append(name)
|
||||
break
|
||||
members.append(defs[i][0])
|
||||
|
||||
s._anonymous_ = anon
|
||||
s._fields_ = [(m[0], self._ctype(m[1])) for m in defs]
|
||||
s._defaults_ = [m[2] for m in defs]
|
||||
return self._structs_[strName]
|
||||
|
||||
|
||||
|
||||
class CFunction:
|
||||
def __init__(self, lib, func, sig, name):
|
||||
self.lib = lib
|
||||
self.func = func
|
||||
#print sig
|
||||
self.sig = list(sig) # looks like [return_type, [(argName, type, default), (argName, type, default), ...]]
|
||||
self.sig[1] = [s for s in sig[1] if s[1] != ['void']] ## remove void args from list
|
||||
for conv in ['__stdcall', '__cdecl']:
|
||||
if conv in self.sig[0]:
|
||||
self.sig[0].remove(conv)
|
||||
self.name = name
|
||||
self.restype = lib._ctype(self.sig[0])
|
||||
#func.restype = self.restype
|
||||
self.argTypes = [lib._ctype(s[1]) for s in self.sig[1]]
|
||||
func.argtypes = self.argTypes
|
||||
self.reqArgs = [x[0] for x in self.sig[1] if x[2] is None]
|
||||
self.argInds = dict([(self.sig[1][i][0], i) for i in range(len(self.sig[1]))]) ## mapping from argument names to indices
|
||||
#print "created func", self, sig, self.argTypes
|
||||
|
||||
def argCType(self, arg):
|
||||
"""Return the ctype required for the specified argument.
|
||||
arg can be either an integer or the name of the argument.
|
||||
"""
|
||||
if isinstance(arg, basestring):
|
||||
arg = self.argInds[arg]
|
||||
return self.lib._ctype(self.sig[1][arg][1])
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
"""Invoke the SO or dll function referenced, converting all arguments to the correct type.
|
||||
Keyword arguments are allowed as long as the header specifies the argument names.
|
||||
Arguments which are passed byref may be omitted entirely, and will be automaticaly generated.
|
||||
To pass a NULL pointer, give None as the argument.
|
||||
Returns the return value of the function call as well as all of the arguments (so that objects passed by reference can be retrieved)"""
|
||||
#print "CALL: %s(%s)" % (self.name, ", ".join(map(str, args) + ["%s=%s" % (k, str(kwargs[k])) for k in kwargs]))
|
||||
#print " sig:", self.sig
|
||||
argList = [None] * max(len(self.reqArgs), len(args)) ## We'll need at least this many arguments.
|
||||
|
||||
## First fill in args
|
||||
for i in range(len(args)):
|
||||
#argList[i] = self.argTypes[i](args[i])
|
||||
if args[i] is None:
|
||||
argList[i] = self.lib.Null
|
||||
else:
|
||||
argList[i] = args[i]
|
||||
|
||||
## Next fill in kwargs
|
||||
for k in kwargs:
|
||||
#print " kw:", k
|
||||
if k not in self.argInds:
|
||||
print "Function signature:", self.prettySignature()
|
||||
raise Exception("Function signature has no argument named '%s'" % k)
|
||||
ind = self.argInds[k]
|
||||
if ind >= len(argList): ## stretch argument list if needed
|
||||
argList += [None] * (ind - len(argList) + 1)
|
||||
#argList[ind] = self.coerce(kwargs[k], self.argTypes[ind])
|
||||
if kwargs[k] is None:
|
||||
argList[ind] = self.lib.Null
|
||||
else:
|
||||
argList[ind] = kwargs[k]
|
||||
|
||||
guessedArgs = []
|
||||
## Finally, fill in remaining arguments if they are pointers to int/float/void*/struct values
|
||||
## (we assume these are to be modified by the function and their initial value is not important)
|
||||
for i in range(len(argList)):
|
||||
if argList[i] is None or argList[i] is self.lib.Null:
|
||||
try:
|
||||
sig = self.sig[1][i][1]
|
||||
argType = self.lib._headers_.evalType(sig)
|
||||
if argList[i] is self.lib.Null: ## request to build a null pointer
|
||||
if len(argType) < 2:
|
||||
raise Exception("Can not create NULL for non-pointer argument type: %s" % str(argType))
|
||||
argList[i] = self.lib._ctype(sig)()
|
||||
#elif argType == ['char', '*']: ## pass null pointer if none was specified. This is a little dangerous, but some functions will expect it.
|
||||
#argList[i] = c_char_p() ## On second thought: let's just require the user to explicitly ask for a NULL pointer.
|
||||
else:
|
||||
if argType == ['void', '**'] or argType == ['void', '*', '*']:
|
||||
cls = c_void_p
|
||||
else:
|
||||
assert len(argType) == 2 and argType[1] == '*' ## Must be 2-part type, second part must be '*'
|
||||
cls = self.lib._ctype(sig, pointers=False)
|
||||
argList[i] = pointer(cls(0))
|
||||
guessedArgs.append(i)
|
||||
except:
|
||||
if sys.exc_info()[0] is not AssertionError:
|
||||
raise
|
||||
#sys.excepthook(*sys.exc_info())
|
||||
print "Function signature:", self.prettySignature()
|
||||
raise Exception("Function call '%s' missing required argument %d '%s'. (See above for signature)" % (self.name, i, self.sig[1][i][0]))
|
||||
#print " args:", argList
|
||||
try:
|
||||
res = self.func(*argList)
|
||||
except:
|
||||
print "Function call failed. Signature is:", self.prettySignature()
|
||||
print "Arguments:", argList
|
||||
print "Argtypes:", self.func.argtypes
|
||||
raise
|
||||
#print " result:", res
|
||||
|
||||
cr = CallResult(res, argList, self.sig, guessed=guessedArgs)
|
||||
return cr
|
||||
|
||||
def prettySignature(self):
|
||||
return "%s %s(%s)" % (''.join(self.sig[0]), self.name, ', '.join(["%s %s" % ("".join(map(str, s[1])), s[0]) for s in self.sig[1]]))
|
||||
|
||||
class CallResult:
|
||||
"""Class for bundling results from C function calls. Allows access to the function
|
||||
return value as well as all of the arguments, since the function call will often return
|
||||
extra values via these arguments.
|
||||
- Original ctype objects can be accessed via result.rval or result.args
|
||||
- Python values carried by these objects can be accessed using ()
|
||||
To access values:
|
||||
- The return value: ()
|
||||
- The nth argument passed: [n]
|
||||
- The argument by name: ['name']
|
||||
- All values that were auto-generated: .auto()
|
||||
|
||||
The class can also be used as an iterator, so that tuple unpacking is possible:
|
||||
ret, arg1, arg2 = lib.runSomeFunction(...)
|
||||
"""
|
||||
def __init__(self, rval, args, sig, guessed):
|
||||
self.rval = rval ## return value of function call
|
||||
self.args = args ## list of arguments to function call
|
||||
self.sig = sig ## function signature
|
||||
self.guessed = guessed ## list of arguments that were generated automatically (usually byrefs)
|
||||
|
||||
def __call__(self):
|
||||
#print "Clibrary:", type(self.rval), self.mkVal(self.rval)
|
||||
if self.sig[0] == ['void']:
|
||||
return None
|
||||
return self.mkVal(self.rval)
|
||||
|
||||
def __getitem__(self, n):
|
||||
if type(n) is int:
|
||||
return self.mkVal(self.args[n])
|
||||
elif type(n) is str:
|
||||
ind = self.findArg(n)
|
||||
return self.mkVal(self.args[ind])
|
||||
else:
|
||||
raise Exception("Index must be int or str.")
|
||||
|
||||
def __setitem__(self, n, val):
|
||||
if type(n) is int:
|
||||
self.args[n] = val
|
||||
elif type(n) is str:
|
||||
ind = self.findArg(n)
|
||||
self.args[ind] = val
|
||||
else:
|
||||
raise Exception("Index must be int or str.")
|
||||
|
||||
|
||||
def mkVal(self, obj):
|
||||
while not hasattr(obj, 'value'):
|
||||
if not hasattr(obj, 'contents'):
|
||||
return obj
|
||||
try:
|
||||
obj = obj.contents
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
return obj.value
|
||||
|
||||
|
||||
def findArg(self, arg):
|
||||
for i in range(len(self.sig[1])):
|
||||
if self.sig[1][i][0] == arg:
|
||||
return i
|
||||
raise Exception("Can't find argument '%s' in function signature. Arguments are: %s" % (arg, str([a[0] for a in self.sig[1]])))
|
||||
|
||||
def __iter__(self):
|
||||
yield self()
|
||||
for i in range(len(self.args)):
|
||||
yield(self[i])
|
||||
|
||||
def auto(self):
|
||||
return [self[n] for n in self.guessed]
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +0,0 @@
|
||||
pyclibrary
|
||||
==========
|
||||
|
||||
C parser and ctypes automation for Python.
|
||||
|
||||
Fork of <https://launchpad.net/pyclibrary>. (`bzr branch lp:pyclibrary pyclibrary-bzr && mkdir pyclibrary && cd pyclibrary && bar fast-export --plain ../pyclibrary-bzr | git fast-import`)
|
||||
|
||||
Pyclibrary includes 1) a pure-python C parser and 2) a ctypes automation library that uses C header file definitions to simplify the use of ctypes. The C parser currently processes all macros, typedefs, structs, unions, enums, function prototypes, and global variable declarations, and can evaluate typedefs down to their fundamental C types + pointers/arrays/function signatures. Pyclibrary can automatically build ctypes structs/unions and perform type conversions when calling functions via cdll/windll.
|
@ -1,3 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from CParser import *
|
||||
from CLibrary import *
|
@ -1,7 +0,0 @@
|
||||
Copyright (c) 2010 Luke Campagnola ('luke.campagnola@%s.com' % 'gmail')
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
File diff suppressed because it is too large
Load Diff
@ -1,117 +0,0 @@
|
||||
#
|
||||
# Copyright 2012-2013 The libLTE Developers. See the
|
||||
# COPYRIGHT file at the top-level directory of this distribution.
|
||||
#
|
||||
# This file is part of the libLTE library.
|
||||
#
|
||||
# libLTE is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# libLTE is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# A copy of the GNU Lesser General Public License can be found in
|
||||
# the LICENSE file in the top-level directory of this distribution
|
||||
# and at http://www.gnu.org/licenses/.
|
||||
#
|
||||
|
||||
|
||||
|
||||
import shutil
|
||||
import os
|
||||
|
||||
def MakeModule(m):
|
||||
dir = os.path.dirname(__file__)
|
||||
|
||||
tdir = os.path.join(dir, 'template')
|
||||
ddir = tdir + m.directory_name
|
||||
print 'Creating new directory ' + ddir
|
||||
|
||||
shutil.copytree(tdir,ddir)
|
||||
|
||||
WriteAloeC(m,tdir + '/src/template.c',\
|
||||
ddir + '/src/' + m.name + '.c')
|
||||
WriteAloeH(m,tdir + '/src/template.h',\
|
||||
ddir + '/src/' + m.name + '.h')
|
||||
|
||||
|
||||
def WriteInitParamsGet(m, f):
|
||||
for p in m.init_params:
|
||||
f.write('\tif (param_get_' + p['type'] + '_name("' + p['name'] + '", &' + p['variable']+ ')) {\n'
|
||||
'\t\t' + p['variable'] + ' = ' + str(p['default']) + ';\n'\
|
||||
'\t}\n')
|
||||
|
||||
def WriteInputParamsHandlers(m, f):
|
||||
for p in m.input_params:
|
||||
f.write('pmid_t ' + p['name'] + '_id;\n')
|
||||
|
||||
def WriteInputParamsId(m, f):
|
||||
for p in m.input_params:
|
||||
f.write('\t' + p['name'] + '_id = param_id("' + p['name'] + '");\n')
|
||||
|
||||
def WriteInputParamsGet(m, f):
|
||||
for p in m.input_params:
|
||||
f.write('\tif (param_get_' + p['type'] + '(' + p['name'] + '_id, &' + p['variable'] + ') != 1) {\n')
|
||||
if p['default'] == None:
|
||||
f.write('\t\t' + r'moderror("Error getting parameter ' + p['name'] + '\\n");' + '\n')
|
||||
f.write('\t\treturn -1;\n\t}\n')
|
||||
else:
|
||||
f.write('\t\t' + r'modinfo("Parameter ' + p['name'] + ' not found. Setting to default (' + p['default'] + ')\\n");' + '\n')
|
||||
f.write('\t\t' + p['variable'] + ' = ' + p['default'] + ';\n\t}\n')
|
||||
|
||||
|
||||
def WriteAloeC(m, input, output):
|
||||
with open(input,'r') as f:
|
||||
newlines = []
|
||||
for line in f.readlines():
|
||||
newlines.append(line.replace('-name-', m.name))
|
||||
with open(output, 'w') as f:
|
||||
for line in newlines:
|
||||
|
||||
if '--input_parameters_handlers--' in line:
|
||||
WriteInputParamsHandlers(m, f)
|
||||
elif '--input_parameters_getid--' in line:
|
||||
WriteInputParamsId(m, f)
|
||||
elif '--init_parameters--' in line:
|
||||
WriteInitParamsGet(m, f)
|
||||
elif '--input_parameters--' in line:
|
||||
WriteInputParamsGet(m, f)
|
||||
else:
|
||||
f.write(line)
|
||||
|
||||
def WriteAloeH(m, input, output):
|
||||
with open(input,'r') as f:
|
||||
newlines = []
|
||||
for line in f.readlines():
|
||||
if '-typeinput-' in line:
|
||||
if m.nof_inputs > 0:
|
||||
newlines.append(line.replace('-typeinput-', m.input_type))
|
||||
elif '-numinputs-' in line:
|
||||
newlines.append(line.replace('-numinputs-', str(m.nof_inputs)))
|
||||
elif '-sizeinput-' in line:
|
||||
if m.nof_inputs > 0:
|
||||
newlines.append(line.replace('-sizeinput-', m.input_size))
|
||||
else:
|
||||
newlines.append(line.replace('-sizeinput-', '0'))
|
||||
elif '-typeoutput-' in line:
|
||||
if m.nof_outputs > 0:
|
||||
newlines.append(line.replace('-typeoutput-', m.output_type))
|
||||
elif '-numoutputs-' in line:
|
||||
newlines.append(line.replace('-numoutputs-', str(m.nof_outputs)))
|
||||
elif '-sizeoutput-' in line:
|
||||
if m.nof_outputs > 0:
|
||||
newlines.append(line.replace('-sizeoutput-', m.output_size))
|
||||
else:
|
||||
newlines.append(line.replace('-sizeoutput-', '0'))
|
||||
else:
|
||||
newlines.append(line)
|
||||
|
||||
with open(output, 'w') as f:
|
||||
for line in newlines:
|
||||
f.write(line)
|
||||
|
||||
|
Binary file not shown.
@ -1,94 +0,0 @@
|
||||
# This configuration is for the aloe++ skeleton
|
||||
|
||||
# set-up the program libraries here
|
||||
set(LIBRARIES m rt)
|
||||
|
||||
# set-up program includes here
|
||||
include_directories(/usr/local/include/)
|
||||
|
||||
############## DO NOT NEED TO MODIFY BEYOND HERE
|
||||
|
||||
get_filename_component(module ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (${module})
|
||||
|
||||
# The version number.
|
||||
set (OECORE_VERSION_MAJOR 1)
|
||||
set (OECORE_VERSION_MINOR 0)
|
||||
set(MODULE_REPOS_NAME "default")
|
||||
|
||||
else()
|
||||
include_directories(${OESR_INCLUDE})
|
||||
endif()
|
||||
|
||||
|
||||
file(GLOB_RECURSE SOURCES "src/*.c")
|
||||
file(GLOB_RECURSE TEST_SOURCES "test/*.c")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
# aloe module
|
||||
add_library(${module}-aloe SHARED ${SOURCES})
|
||||
set_target_properties(${module}-aloe PROPERTIES OUTPUT_NAME ${module})
|
||||
set_target_properties(${module}-aloe PROPERTIES COMPILE_FLAGS "-D_COMPILE_ALOE")
|
||||
target_link_libraries(${module}-aloe oesrapi skeleton ${LIBRARIES})
|
||||
install(TARGETS ${module}-aloe DESTINATION lib/${MODULE_REPOS_NAME}/)
|
||||
|
||||
|
||||
if (NOT ${TEST_SOURCES} STREQUAL "")
|
||||
# standalone program for testing
|
||||
add_executable(${module}-bin ${SOURCES} ${TEST_SOURCES})
|
||||
set_target_properties(${module}-bin PROPERTIES OUTPUT_NAME ${module})
|
||||
set_target_properties(${module}-bin PROPERTIES COMPILE_FLAGS "-D_COMPILE_STANDALONE")
|
||||
target_link_libraries(${module}-bin standalone ${LIBRARIES})
|
||||
install(TARGETS ${module}-bin DESTINATION bin)
|
||||
endif()
|
||||
|
||||
# octave mex file
|
||||
set(install_mex "")
|
||||
if(NOT $ENV{OCTAVE_INCLUDE} STREQUAL "")
|
||||
if(NOT $ENV{OCTAVE_LIBS} STREQUAL "")
|
||||
|
||||
add_library(${module}-oct SHARED ${SOURCES})
|
||||
set_target_properties(${module}-oct PROPERTIES OUTPUT_NAME ${module})
|
||||
set_target_properties(${module}-oct PROPERTIES PREFIX "am_")
|
||||
set_target_properties(${module}-oct PROPERTIES SUFFIX .mex)
|
||||
|
||||
set_target_properties(${module}-oct PROPERTIES COMPILE_FLAGS "-I$ENV{OCTAVE_INCLUDE} -D_COMPILE_MEX -Wl,-Bsymbolic -L$ENV{OCTAVE_LIBS} -loctinterp -loctave -lcruft -Wl,-Bsymbolic-functions -Wl,-z,relro")
|
||||
target_link_libraries(${module}-oct aloe_octave ${LIBRARIES})
|
||||
install(TARGETS ${module}-oct DESTINATION mex)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#matlab mex
|
||||
if(NOT $ENV{MATLAB_ROOT} STREQUAL "")
|
||||
add_library(${module}-mat SHARED ${SOURCES})
|
||||
set_target_properties(${module}-mat PROPERTIES OUTPUT_NAME ${module})
|
||||
set_target_properties(${module}-mat PROPERTIES PREFIX "am_")
|
||||
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set_target_properties(${module}-mat PROPERTIES SUFFIX .mexa64)
|
||||
set_target_properties(${module}-mat PROPERTIES COMPILE_FLAGS "-I$ENV{MATLAB_ROOT} -O -pthread -shared -Wl,--version-script,$ENV{MATLAB_ROOT}/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -Wl,-rpath-link,$ENV{MATLAB_ROOT}/bin/glnxa64 -L$ENV{MATLAB_ROOT}/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++")
|
||||
else()
|
||||
set_target_properties(${module}-mat PROPERTIES SUFFIX .mexglx)
|
||||
set_target_properties(${module}-mat PROPERTIES COMPILE_FLAGS "-I$ENV{MATLAB_ROOT} -O -pthread -shared -m32 -Wl,--version-script,$ENV{MATLAB_ROOT}/extern/lib/glnx86/mexFunction.map -Wl,--no-undefined -Wl,-rpath-link,$ENV{MATLAB_ROOT}/bin/glnx86 -L$ENV{MATLAB_ROOT}/bin/glnx86 -lmx -lmex -lmat -lm -lstdc++")
|
||||
endif()
|
||||
|
||||
target_link_libraries(${module}-mat aloe_matlab ${LIBRARIES})
|
||||
install(TARGETS ${module}-mat DESTINATION mex)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 The srsLTE Developers. See the
|
||||
* COPYRIGHT file at the top-level directory of this distribution.
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsLTE library.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file has been automatically generated from -name-
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <oesr.h>
|
||||
#include <params.h>
|
||||
#include <skeleton.h>
|
||||
|
||||
#include "-name-.h"
|
||||
|
||||
-name-_hl -name-;
|
||||
|
||||
--input_parameters_handlers--
|
||||
|
||||
int out_len[NOF_OUTPUT_ITF];
|
||||
|
||||
int initialize() {
|
||||
|
||||
/* Initialization Parameters */
|
||||
--init_parameters--
|
||||
|
||||
/* Input Control Parameters */
|
||||
--input_parameters_getid--
|
||||
|
||||
/* Initialization function */
|
||||
return -name-_initialize(&-name-);
|
||||
}
|
||||
|
||||
|
||||
int work(void **inp, void **out) {
|
||||
int i,n;
|
||||
#if NOF_INPUTS>1
|
||||
for (i=0;i<NOF_INPUT_ITF;i++) {
|
||||
-name-.input[i] = inp[i];
|
||||
-name-.in_len[i] = get_input_samples(i)
|
||||
}
|
||||
#elif NOF_INPUTS == 1
|
||||
-name-.input = inp[0];
|
||||
-name-.in_len = get_input_samples(0);
|
||||
#endif
|
||||
|
||||
#if NOF_OUTPUTS>1
|
||||
for (i=0;i<NOF_OUTPUT_ITF;i++) {
|
||||
-name-.output[i] = out[i];
|
||||
-name-.out_len = &out_len[i];
|
||||
}
|
||||
#elif NOF_OUTPUTS == 1
|
||||
-name-output = out[0];
|
||||
-name-.out_len = &out_len[0];
|
||||
#endif
|
||||
|
||||
/* Get input parameters */
|
||||
--input_parameters--
|
||||
|
||||
/* call work */
|
||||
n = -name-_work(&-name-);
|
||||
|
||||
/* Set output nof_samples */
|
||||
for (i=0;i<NOF_OUTPUT_ITF;i++) {
|
||||
set_output_samples(i,out_len[i]);
|
||||
-name-.out_len = &out_len[i];
|
||||
}
|
||||
|
||||
/* Set output parameters */
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int stop() {
|
||||
-name-_destroy(&-name-);
|
||||
return 0;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 The srsLTE Developers. See the
|
||||
* COPYRIGHT file at the top-level directory of this distribution.
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsLTE library.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DEFINE_H
|
||||
#define DEFINE_H
|
||||
#include <stdint.h>
|
||||
|
||||
typedef -typeinput- input_t;
|
||||
typedef -typeoutput- output_t;
|
||||
|
||||
#define INPUT_MAX_SAMPLES -sizeinput-
|
||||
#define OUTPUT_MAX_SAMPLES -sizeoutput-
|
||||
|
||||
#define NOF_INPUT_ITF -numinputs-
|
||||
#define NOF_OUTPUT_ITF -numoutputs-
|
||||
|
||||
#endif
|
||||
/**@} */
|
||||
|
||||
#ifndef INCLUDE_DEFS_ONLY
|
||||
|
||||
/* Input and output buffer sizes (in number of samples) */
|
||||
const int input_max_samples = INPUT_MAX_SAMPLES;
|
||||
const int output_max_samples = OUTPUT_MAX_SAMPLES;
|
||||
|
||||
/* leave these two lines unmodified */
|
||||
const int input_sample_sz = sizeof(input_t);
|
||||
int output_sample_sz = sizeof(output_t);
|
||||
|
||||
/* Number of I/O interfaces. All have the same maximum size */
|
||||
const int nof_input_itf = NOF_INPUT_ITF;
|
||||
const int nof_output_itf = NOF_OUTPUT_ITF;
|
||||
|
||||
#endif
|
@ -1,83 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 The srsLTE Developers. See the
|
||||
* COPYRIGHT file at the top-level directory of this distribution.
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsLTE library.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Functions that generate the test data fed into the DSP modules being developed */
|
||||
#include <complex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <skeleton.h>
|
||||
#include <params.h>
|
||||
|
||||
#define INCLUDE_DEFS_ONLY
|
||||
#include "template.h"
|
||||
|
||||
int offset=0;
|
||||
|
||||
/**
|
||||
* Generates input signal. VERY IMPORTANT to fill length vector with the number of
|
||||
* samples that have been generated.
|
||||
* @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
|
||||
* Use in(ptr,idx) to access the address.
|
||||
*
|
||||
* @param lengths Save on n-th position the number of samples generated for the n-th interface
|
||||
*/
|
||||
int generate_input_signal(void *in, int *lengths)
|
||||
{
|
||||
int i;
|
||||
input_t *input = in;
|
||||
int block_length;
|
||||
pmid_t blen_id;
|
||||
|
||||
blen_id = param_id("block_length");
|
||||
if (!blen_id) {
|
||||
moderror("Parameter block_length not found\n");
|
||||
return -1;
|
||||
}
|
||||
if (!param_get_int(blen_id,&block_length)) {
|
||||
moderror("Getting integer parameter block_length\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
modinfo_msg("Parameter block_length is %d\n",block_length);
|
||||
|
||||
|
||||
/** HERE INDICATE THE LENGTH OF THE SIGNAL */
|
||||
lengths[0] = block_length;
|
||||
|
||||
for (i=0;i<block_length;i++) {
|
||||
#ifdef GENESRSLTE_TCOD_RATE_COMPLEX
|
||||
__real__ input[i] = (float) ((i+offset)%(block_length));
|
||||
__imag__ input[i] = (float) ((block_length-i-1+offset)%(block_length));
|
||||
#else
|
||||
input[i] = (i+offset)%(block_length);
|
||||
#endif
|
||||
}
|
||||
offset++;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue