def generate(path): # Make temporary generator directory if os.path.exists('/tmp/generator'): shutil.rmtree('/tmp/generator/') os.makedirs('/tmp/generator/bindings') os.chdir('/tmp/generator/bindings') # Copy examples common.generate(path, 'en', make_files, None, False) shutil.copy(common.path_binding.replace('/generators/delphi', '/doc/en/source/Software/Example.pas'), '/tmp/generator/examples/ExampleEnumerate.pas') # Copy bindings and readme for filename in glob.glob(path + '/bindings/*.pas'): shutil.copy(filename, '/tmp/generator/bindings') shutil.copy(path + '/Base58.pas', '/tmp/generator/bindings') shutil.copy(path + '/BlockingQueue.pas', '/tmp/generator/bindings') shutil.copy(path + '/Device.pas', '/tmp/generator/bindings') shutil.copy(path + '/IPConnection.pas', '/tmp/generator/bindings') shutil.copy(path + '/LEConverter.pas', '/tmp/generator/bindings') shutil.copy(path + '/TimedSemaphore.pas', '/tmp/generator/bindings') shutil.copy(path + '/changelog.txt', '/tmp/generator/') shutil.copy(path + '/readme.txt', '/tmp/generator/') # Make zip version = common.get_changelog_version(path) common.make_zip('delphi', '/tmp/generator', path, version)
def generate(path): # Make temporary generator directory if os.path.exists('/tmp/generator'): shutil.rmtree('/tmp/generator/') os.makedirs('/tmp/generator/egg/source/tinkerforge') os.chdir('/tmp/generator') # Copy examples common.generate(path, 'en', make_files, None, False) shutil.copy(common.path_binding.replace('/generators/python', '/doc/en/source/Software/example.py'), '/tmp/generator/egg/examples/example_enumerate.py') # Copy bindings and readme for filename in glob.glob(path + '/bindings/*.py'): shutil.copy(filename, '/tmp/generator/egg/source/tinkerforge') shutil.copy(path + '/ip_connection.py', '/tmp/generator/egg/source/tinkerforge') shutil.copy(path + '/changelog.txt', '/tmp/generator/egg') shutil.copy(path + '/readme.txt', '/tmp/generator/egg') # Write setup.py version = common.get_changelog_version(path) file('/tmp/generator/egg/source/setup.py', 'wb').write(""" #!/usr/bin/env python from setuptools import setup setup(name='tinkerforge', version='{0}.{1}.{2}', description='TCP/IP based library for Bricks and Bricklets', author='Tinkerforge GmbH', author_email='*****@*****.**', url='http://www.tinkerforge.com', packages=['tinkerforge']) """.format(*version)) # Make egg os.chdir('/tmp/generator/egg/source') args = ['/usr/bin/python', 'setup.py', 'bdist_egg'] if subprocess.call(args) != 0: raise Exception("Command '{0}' failed".format(' '.join(args))) # Remove build stuff shutil.rmtree('/tmp/generator/egg/source/build') shutil.rmtree('/tmp/generator/egg/source/tinkerforge.egg-info') shutil.copy('/tmp/generator/egg/source/dist/' + os.listdir('/tmp/generator/egg/source/dist')[0], '/tmp/generator/egg/tinkerforge.egg') shutil.rmtree('/tmp/generator/egg/source/dist') # Make __init__.py f = open('/tmp/generator/egg/source/tinkerforge/__init__.py', 'w') f.write(' ') f.close() # Make zip common.make_zip('python', '/tmp/generator/egg', path, version)
def generate(path): # Make temporary generator directory if os.path.exists('/tmp/generator'): shutil.rmtree('/tmp/generator/') os.makedirs('/tmp/generator/jar/source/com/tinkerforge') os.chdir('/tmp/generator') # Copy examples common.generate(path, 'en', make_files, None, False) lines = [] for line in file(common.path_binding.replace('/generators/java', '/doc/en/source/Software/Example.java'), 'rb'): lines.append(line.replace('public class Example {', 'public class ExampleEnumerate {')) file('/tmp/generator/jar/examples/ExampleEnumerate.java', 'wb').writelines(lines) # Copy bindings and readme for filename in glob.glob(path + '/bindings/*.java'): shutil.copy(filename, '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/Device.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/IPConnection.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/TinkerforgeException.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/TimeoutException.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/AlreadyConnectedException.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/NotConnectedException.java', '/tmp/generator/jar/source/com/tinkerforge') shutil.copy(path + '/changelog.txt', '/tmp/generator/jar') shutil.copy(path + '/Readme.txt', '/tmp/generator/jar') # Make Manifest version = common.get_changelog_version(path) file('/tmp/generator/manifest.txt', 'wb').write('Bindings-Version: {0}.{1}.{2}\n'.format(*version)) # Make jar args = ['/usr/bin/javac ' + '-Xlint ' + '/tmp/generator/jar/source/com/tinkerforge/*.java'] if subprocess.call(args, shell=True) != 0: raise Exception("Command '{0}' failed".format(' '.join(args))) os.chdir('/tmp/generator/jar/source') args = ['/usr/bin/jar ' + 'cfm ' + '/tmp/generator/jar/Tinkerforge.jar ' + '/tmp/generator/manifest.txt ' + 'com'] if subprocess.call(args, shell=True) != 0: raise Exception("Command '{0}' failed".format(' '.join(args))) # Remove class for f in os.listdir('/tmp/generator/jar/source/com/tinkerforge/'): if f.endswith('.class'): os.remove('/tmp/generator/jar/source/com/tinkerforge/' + f) # Make zip common.make_zip('java', '/tmp/generator/jar', path, version)
def generate(path): # Make temporary generator directory if os.path.exists('/tmp/generator'): shutil.rmtree('/tmp/generator/') os.makedirs('/tmp/generator/dll/source/Tinkerforge') os.chdir('/tmp/generator') # Copy examples common.generate(path, 'en', make_files, None, False) shutil.copy(common.path_binding.replace('/generators/vbnet', '/doc/en/source/Software/Example.vb'), '/tmp/generator/dll/examples/ExampleEnumerate.vb') lines = [] for line in file(common.path_binding.replace('/generators/vbnet', '/doc/en/source/Software/Example.vb'), 'rb'): lines.append(line.replace('Module Example', 'Module ExampleEnumerate')) file('/tmp/generator/dll/examples/ExampleEnumerate.vb', 'wb').writelines(lines) # Copy bindings and readme for filename in glob.glob(path + '/bindings/*.cs'): shutil.copy(filename, '/tmp/generator/dll/source/Tinkerforge') shutil.copy(path + '/../csharp/IPConnection.cs', '/tmp/generator/dll/source/Tinkerforge') shutil.copy(path + '/changelog.txt', '/tmp/generator/dll') shutil.copy(path + '/readme.txt', '/tmp/generator/dll') # Write AssemblyInfo version = common.get_changelog_version(path) file('/tmp/generator/dll/source/Tinkerforge/AssemblyInfo.cs', 'wb').write(""" using System.Reflection; using System.Runtime.CompilerServices; [assembly: AssemblyTitle("Visual Basic .NET API Bindings")] [assembly: AssemblyDescription("Visual Basic .NET API Bindings for Tinkerforge Bricks and Bricklets")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Tinkerforge GmbH")] [assembly: AssemblyProduct("Visual Basic .NET API Bindings")] [assembly: AssemblyCopyright("Tinkerforge GmbH 2011-2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("{0}.{1}.{2}.0")] """.format(*version)) # Make dll args = ['/usr/bin/gmcs', '/optimize', '/target:library', '/out:/tmp/generator/dll/Tinkerforge.dll', '/doc:/tmp/generator/dll/Tinkerforge.xml', '/tmp/generator/dll/source/Tinkerforge/*.cs'] if subprocess.call(args) != 0: raise Exception("Command '{0}' failed".format(' '.join(args))) # Make zip common.make_zip('vbnet', '/tmp/generator/dll', path, version)
def generate(path): # Make temporary generator directory if os.path.exists('/tmp/generator'): shutil.rmtree('/tmp/generator/') os.makedirs('/tmp/generator/bindings') os.chdir('/tmp/generator/bindings') # Copy examples common.generate(path, 'en', make_files, None, False) shutil.copy(common.path_binding.replace('/generators/c', '/doc/en/source/Software/example.c'), '/tmp/generator/examples/example_enumerate.c') # Copy bindings and readme for filename in glob.glob(path + '/bindings/*.[ch]'): shutil.copy(filename, '/tmp/generator/bindings') shutil.copy(path + '/ip_connection.c', '/tmp/generator/bindings') shutil.copy(path + '/ip_connection.h', '/tmp/generator/bindings') shutil.copy(path + '/changelog.txt', '/tmp/generator/') shutil.copy(path + '/readme.txt', '/tmp/generator/') # Make zip version = common.get_changelog_version(path) common.make_zip('c', '/tmp/generator', path, version)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', PythonZipGenerator)
def generate(root_dir, language): common.generate(root_dir, language, PerlDocGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', DelphiZipGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', DelphiExamplesGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', JavaScriptZipGenerator)
def generate(root_dir, language): common.generate(root_dir, language, DelphiDocGenerator)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, LabVIEWDocGenerator)
def generate(root_dir): common.generate(root_dir, 'en', DelphiZipGenerator)
def generate(root_dir): common.generate(root_dir, 'en', MathematicaExamplesGenerator)
def generate(root_dir): common.generate(root_dir, 'en', MQTTZipGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', MATLABZipGenerator)
def generate(root_dir): print('=== Generating MATLAB ===') common.generate(root_dir, 'en', MATLABBindingsGenerator) print('=== Generating Octave ===') common.generate(root_dir, 'en', OcatveBindingsGenerator)
def generate(root_dir): common.generate(root_dir, 'en', GoBindingsGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', MathematicaZipGenerator)
if len(unpack_format) > 0: final_unpack = ' $payload = unpack(\'{0}\', $data);'.format('/'.join(unpack_format)) wrappers += wrapper.format(name, final_unpack, '\n'.join(collect), packet.get_upper_case_name()) return wrappers def make_files(com_new, directory): global device device = common.Device(com_new) file_name = '{0}{1}'.format(device.get_category(), device.get_camel_case_name()) directory += '/bindings' php = file('{0}/{1}.php'.format(directory, file_name), "w") php.write("<?php\n\n") php.write(make_import()) php.write(make_class()) php.write(make_callback_id_definitions()) php.write(make_function_id_definitions()) php.write(make_device_identifier()) php.write(make_constructor()) php.write(make_callback_wrapper_definitions()) php.write(make_methods()) php.write(make_callback_wrappers()) php.write("}\n\n?>\n") if __name__ == "__main__": common.generate(os.getcwd(), 'en', make_files, common.prepare_bindings, False)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, JavaScriptDocGenerator)
power 3[3] 0x00 on,off """ ######################################################################## # Template for methods in the body of the struct ######################################################################## BODY_TMPL="""\ boost::uint8_t get_reg(boost::uint8_t addr){ boost::uint8_t reg = 0; switch(addr){ % for addr in sorted(set(map(lambda r: r.get_addr(), regs))): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (boost::uint8_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return boost::uint8_t(reg); } """ if __name__ == '__main__': import common; common.generate( name='tuner_4937di5_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
def generate(root_dir, language): common.generate(root_dir, language, MathematicaDocGenerator)
def generate(root_dir, language): common.generate(root_dir, language, JavaDocGenerator)
def generate(root_dir): common.generate(root_dir, 'en', ShellExamplesGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', ShellZipGenerator)
mod 0[12] 0 chn 0[13] 0 """ ######################################################################## # Template for methods in the body of the struct ######################################################################## BODY_TMPL="""\ boost::uint16_t get_reg(void){ boost::uint16_t reg = 0; #for $reg in filter(lambda r: r.get_addr() == 0, $regs) reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for return reg; } void set_reg(boost::uint16_t reg){ #for $reg in filter(lambda r: r.get_addr() == 0, $regs) $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); #end for } """ if __name__ == '__main__': import common; common.generate( name='ad7922_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
void set_reg(boost::uint8_t addr, boost::uint8_t reg){ switch(addr){ #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) case $addr: #for $reg in filter(lambda r: r.get_addr() == addr, $regs) $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); #end for break; #end for } } """ if __name__ == '__main__': import common common.generate( name='max2118_write_regs', regs_tmpl=WRITE_REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, ) import common common.generate( name='max2118_read_regs', regs_tmpl=READ_REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, append=True, )
def generate(root_dir): common.generate(root_dir, 'en', DocStubGenerator)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, MATLABDocGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', PHPBindingsGenerator)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, CSharpDocGenerator)
void set_reg(boost::uint8_t addr, boost::uint8_t reg){ switch(addr){ #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) case $addr: #for $reg in filter(lambda r: r.get_addr() == addr, $regs) $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); #end for break; #end for } } """ SPLIT_REGS_HELPER_TMPL = """\ #for $divname in ['n','f'] void set_$(divname)_divider(boost::uint32_t $divname){ #for $regname in sorted(map(lambda r: r.get_name(), filter(lambda r: r.get_name().find(divname + '_divider') == 0, $regs))) #end for } #end for """ if __name__ == '__main__': import common common.generate( name='tda18272hnm_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', CSharpBindingsGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', JavaScriptBindingsGenerator)
power 3[3] 0x00 on,off """ ######################################################################## # Template for methods in the body of the struct ######################################################################## BODY_TMPL="""\ uint8_t get_reg(uint8_t addr){ uint8_t reg = 0; switch(addr){ % for addr in sorted(set(map(lambda r: r.get_addr(), regs))): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint8_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return uint8_t(reg); } """ if __name__ == '__main__': import common; common.generate( name='tuner_4937di5_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', LabVIEWZipGenerator)
def generate(root_dir): common.generate(root_dir, 'en', JSONZipGenerator)
######################################################################## BODY_TMPL = """\ uint32_t get_reg(int addr){ uint32_t reg = 0; switch(addr){ % for addr in sorted(set(map(lambda r: r.get_addr(), regs))): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint32_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return reg; } """ if __name__ == '__main__': import common common.generate( name='lmk04828_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
ADDR_R1 = 1, ADDR_R2 = 2, ADDR_R3 = 3, ADDR_R4 = 4, ADDR_R5 = 5 }; boost::uint32_t get_reg(boost::uint8_t addr){ boost::uint32_t reg = addr & 0x7; switch(addr){ #for $addr in range(5+1) case $addr: #for $reg in filter(lambda r: r.get_addr() == addr, $regs) reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for break; #end for } return reg; } """ if __name__ == '__main__': import common; common.generate( name='max2870_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
article, device.get_device_identifier()) ref = '.. _{0}_{1}_tcpip_api:\n'.format(device.get_underscore_name(), device.get_category().lower()) api_desc = '' if 'api' in device.com: api_desc = common.select_lang(device.com['api']) return common.select_lang(api).format(ref, api_desc, api_str) def make_files(com_new, directory): global device device = common.Device(com_new) file_name = '{0}_{1}_TCPIP'.format(device.get_camel_case_name(), device.get_category()) title = { 'en': 'TCP/IP protocol', 'de': 'TCP/IP Protokoll' } directory = os.path.join(directory, 'doc', common.lang) f = file('{0}/{1}.rst'.format(directory, file_name), "w") f.write(common.make_rst_header(device, 'tcpip', 'TCP/IP')) f.write(common.make_rst_summary(device, common.select_lang(title))) f.write(make_api()) if __name__ == "__main__": for lang in ['en', 'de']: print("=== Generating %s ===" % lang) common.generate(os.getcwd(), lang, make_files, common.prepare_doc, True)
tx_vga_gain 12[0:5] 0 """ ######################################################################## # Template for methods in the body of the struct ######################################################################## BODY_TMPL = """\ uint32_t get_reg(uint8_t addr){ uint16_t reg = 0; switch(addr){ % for addr in sorted(set(map(lambda r: r.get_addr(), regs))): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint16_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return (uint32_t(reg) << 4) | (addr & 0xf); } """ if __name__ == '__main__': import common common.generate( name='max2829_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
######################################################################## BODY_TMPL = """\ enum addr_t{ ADDR_R0 = 0, ADDR_R1 = 1, ADDR_R2 = 2, ADDR_R3 = 3, ADDR_R4 = 4, ADDR_R5 = 5 }; uint32_t get_reg(uint8_t addr){ uint32_t reg = addr & 0x7; switch(addr){ % for addr in range(5+1): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint32_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return reg; } """ if __name__ == "__main__": import common common.generate(name="adf4351_regs", regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__)
case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint8_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return uint8_t(reg); } void set_reg(uint8_t addr, uint8_t reg){ switch(addr){ % for addr in sorted(set(map(lambda r: r.get_addr(), regs))): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): ${reg.get_name()} = ${reg.get_type()}((reg >> ${reg.get_shift()}) & ${reg.get_mask()}); % endfor break; % endfor } } """ if __name__ == '__main__': import common; common.generate( name='tda18272hnm_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
def generate(root_dir): common.generate(root_dir, 'en', JavaZipGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', VBNETBindingsGenerator)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, MathematicaDocGenerator)
def generate(root_dir): common.generate(root_dir, 'en', MATLABZipGenerator)
def generate(root_dir, language): common.generate(root_dir, language, CSharpDocGenerator)
def generate(bindings_root_directory): common.generate(bindings_root_directory, "en", JavaBindingsGenerator)
def generate(root_dir): common.generate(root_dir, 'en', CSharpBindingsGenerator)
def generate(bindings_root_directory, language): common.generate(bindings_root_directory, language, TCPIPDocGenerator)
ADDR_R8 = 8, ADDR_R9 = 9, ADDR_R10 = 10, ADDR_R11 = 11, ADDR_R12 = 12 }; uint32_t get_reg(uint8_t addr){ uint32_t reg = addr & 0xF; switch(addr){ % for addr in range(12+1): case ${addr}: % for reg in filter(lambda r: r.get_addr() == addr, regs): reg |= (uint32_t(${reg.get_name()}) & ${reg.get_mask()}) << ${reg.get_shift()}; % endfor break; % endfor } return reg; } """ if __name__ == '__main__': import common common.generate( name='adf5355_regs', regs_tmpl=REGS_TMPL, body_tmpl=BODY_TMPL, file=__file__, )
def generate(bindings_root_directory): common.generate(bindings_root_directory, 'en', EmulatorConfigGenerator)