def get_tvpl_return_desc(self): nothing = { 'en': 'no output', 'de': 'keine Ausgabe' } has_symbols = { 'en': 'has symbols', 'de': 'hat Symbole' } elements = self.get_elements(direction='out') if len(elements) == 0: return '\n :noreturn: {0}\n'.format(common.select_lang(nothing)) ret = '\n' for element in elements: t = element.get_tvpl_doc_type() ret += ' :returns {0}: {1}'.format(element.get_name().space.replace(' ', '$nbsp;'), t) if element.get_constant_group() is not None or \ self.get_function_id() == 255 and element.get_name().space == 'Device Identifier': ret += ' ({0})'.format(common.select_lang(has_symbols)) ret += '\n' return ret
def get_tvpl_api(self): api = { 'en': """ .. _{0}_tvpl_api: API --- {1} {2} """, 'de': """ .. _{0}_tvpl_api: API --- {1} {2} """ } bf = self.get_tvpl_methods('bf') af = self.get_tvpl_methods('af') api_str = '' if bf: api_str += common.select_lang(common.bf_str).format('', bf) if af: api_str += common.select_lang(common.af_str).format(af) return common.select_lang(api).format(self.get_doc_rst_ref_name(), self.replace_tvpl_function_links(common.select_lang(self.get_doc())), api_str)
def constant_format(prefix, constant_group, constant, value): c = '* {0} = {1}, '.format(constant.get_name().space, value) for_ = { 'en': 'for', 'de': 'für' } c += common.select_lang(for_) + ' ' e = [] for element in constant_group.get_elements(): e.append(element.get_name().space) if len(e) > 1: and_ = { 'en': 'and', 'de': 'und' } c += ', '.join(e[:-1]) + ' ' + common.select_lang(and_) + ' ' + e[-1] else: c += e[0] return c + '\n'
def get_matlab_object_desc(self, high_level=False): if len(self.get_elements(direction='out', high_level=high_level)) < 2: return '' desc = { 'en': """ The returned object has the public member variables {0}. """, 'de': """ Das zurückgegebene Objekt enthält die Public-Member-Variablen {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements(direction='out', high_level=high_level): var.append('``{0} {1}``'.format(element.get_matlab_type(), element.get_name().headless)) if len(var) == 1: return common.select_lang(desc).format(var[0]) elif len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) else: return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def get_python_object_desc(self): if len(self.get_elements("out")) < 2: return "" desc = { "en": """ The returned namedtuple has the variables {0}. """, "de": """ Das zurückgegebene namedtuple enthält die Variablen {0}. """, } and_ = {"en": " and ", "de": " und "} var = [] for element in self.get_elements("out"): var.append("``{0}``".format(element.get_underscore_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(", ".join(var[:-1]) + common.select_lang(and_) + var[-1])
def get_java_object_desc(self): if len(self.get_elements("out")) < 2: return "" desc = { "en": """ The returned object has the public member variables {0}. """, "de": """ Das zurückgegebene Objekt enthält die Public-Member-Variablen {0}. """, } and_ = {"en": " and ", "de": " und "} var = [] for element in self.get_elements("out"): typ = element.get_java_type() if element.get_cardinality() > 1 and element.get_type() != "string": typ += "[]" var.append("``{0} {1}``".format(typ, element.get_headless_camel_case_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(", ".join(var[:-1]) + common.select_lang(and_) + var[-1])
def format_doc(packet, shift_right): text = common.select_lang(packet.get_doc()[1]) cb_link = ":java:func:`{2}Listener <{0}{1}.{2}Listener>`" fu_link = ":java:func:`{2}() <{0}{1}::{2}>`" parameter = {"en": "parameter", "de": "Parameter"} parameters = {"en": "parameters", "de": "Parameter"} cls = device.get_camel_case_name() for other_packet in device.get_packets(): name_false = ":func:`{0}`".format(other_packet.get_camel_case_name()) if other_packet.get_type() == "callback": name = other_packet.get_camel_case_name() name_right = cb_link.format(device.get_category(), cls, name) else: name = other_packet.get_headless_camel_case_name() name_right = fu_link.format(device.get_category(), cls, name) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = text.replace("Callback ", "Listener ") text = text.replace(" Callback", " Listener") text = text.replace("callback ", "listener ") text = text.replace(" callback", " listener") text = common.handle_rst_if(text, device) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, shift_right)
def make_obj_desc(packet): if len(packet.get_elements("out")) < 2: return "" desc = { "en": """ The returned object has the public member variables {0}. """, "de": """ Das zurückgegebene Objekt enthält die Public Member Variablen {0}. """, } var = [] for element in packet.get_elements("out"): var.append( "``{0} {1}``".format(get_java_type(element[1]), common.underscore_to_headless_camel_case(element[0])) ) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + " and " + var[1]) return common.select_lang(desc).format(", ".join(var[:-1]) + " and " + var[-1])
def get_java_object_desc(self): if len(self.get_elements('out')) < 2: return '' desc = { 'en': """ The returned object has the public member variables {0}. """, 'de': """ Das zurückgegebene Objekt enthält die Public-Member-Variablen {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements('out'): typ = element.get_java_type() if element.get_cardinality() > 1 and element.get_type() != 'string': typ += '[]' var.append('``{0} {1}``'.format(typ, element.get_headless_camel_case_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def format_doc(packet): text = common.select_lang(packet.get_doc()[1]) parameter = { 'en': 'response value', 'de': 'Rückgabewert' } parameters = { 'en': 'response values', 'de': 'Rückgabewerte' } cls = device.get_camel_case_name() for other_packet in device.get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) if other_packet.get_type() == 'callback': name_upper = other_packet.get_upper_case_name() name_right = ':tcpip:func:`CALLBACK_{1} <{0}.CALLBACK_{1}>`'.format(cls, name_upper) else: name_right = ':tcpip:func:`{1} <{0}.{1}>`'.format(cls, other_packet.get_underscore_name()) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = common.handle_rst_if(text, device) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, 1)
def constant_format(prefix, constant_group, constant, value): c = '* {0}: {1}, '.format(value, constant.get_name().lower()) for_ = { 'en': 'for', 'de': 'für' } c += common.select_lang(for_) + ' ' e = [] for element in constant_group.get_elements(): name = element.get_underscore_name() e.append(name) if len(e) > 1: and_ = { 'en': 'and', 'de': 'und' } c += ', '.join(e[:-1]) + ' ' + common.select_lang(and_) + ' ' + e[-1] else: c += e[0] return c + '\n'
def format_doc(packet, shift_right): text = common.select_lang(packet.get_doc()[1]) parameter = { 'en': 'parameter', 'de': 'Parameter' } parameters = { 'en': 'parameters', 'de': 'Parameter' } link = ':csharp:func:`{2}() <{0}{1}::{2}>`' cls = device.get_camel_case_name() for other_packet in device.get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) name = other_packet.get_camel_case_name() name_right = link.format(device.get_category(), cls, name) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = common.handle_rst_if(text, device) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, shift_right)
def get_go_imports(self): tf_doc_link = {'en': '// See also the documentation here: https://www.tinkerforge.com/en/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Go.html.', 'de': '// Siehe auch die Dokumentation hier: https://www.tinkerforge.com/de/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Go.html.' } desc = common.select_lang(self.get_description()) plenk = "REPLACE_WITH_ZWJ" if len(desc) > 0 and desc[-1].isupper() else "" description = desc + plenk + "." description += '\n// \n// \n' description += common.select_lang(tf_doc_link).format(device_category_camel = self.get_category().camel, device_name_camel = self.get_name().camel) return """{header} //{description} package {device} import ( "encoding/binary" "bytes" . "github.com/Tinkerforge/go-api-bindings/internal" "github.com/Tinkerforge/go-api-bindings/ipconnection" ) """.format(header=self.get_generator().get_header_comment(kind='asterisk'), description=description, device=self.get_go_package())
def get_shell_return_desc(self): nothing = { 'en': 'no output', 'de': 'keine Ausgabe' } has_symbols = { 'en': 'has symbols', 'de': 'hat Symbole' } elements = self.get_elements('out') if len(elements) == 0: return '\n :noreturn: {0}\n'.format(common.select_lang(nothing)) ret = '\n' for element in elements: t = element.get_shell_type() ret += ' :returns {0}: {1}'.format(element.get_dash_name(), t) if element.get_constant_group() is not None or \ self.get_function_id() == 255 and element.get_underscore_name() == 'device_identifier': ret += ' ({0})'.format(common.select_lang(has_symbols)) ret += '\n' return ret
def get_python_object_desc(self, high_level=False): if len(self.get_elements(direction='out', high_level=high_level)) < 2: return '' desc = { 'en': """ The returned namedtuple has the variables {0}. """, 'de': """ Das zurückgegebene namedtuple enthält die Variablen {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements(direction='out', high_level=high_level): var.append('``{0}``'.format(element.get_name().under)) if len(var) == 1: return common.select_lang(desc).format(var[0]) elif len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) else: return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def constant_format(prefix, constant_group, constant_item, value): c = '* ``{0}`` = {1}, '.format(constant_item.get_dash_name(), value) for_ = { 'en': 'for', 'de': 'für' } c += common.select_lang(for_) + ' ' e = [] for element in constant_group.get_elements(): name = element.get_dash_name() if element.get_direction() == 'in': e.append('<{0}>'.format(name)) else: e.append(name) if len(e) > 1: and_ = { 'en': 'and', 'de': 'und' } c += ', '.join(e[:-1]) + ' ' + common.select_lang(and_) + ' ' + e[-1] else: c += e[0] return c + '\n'
def format_doc(packet): text = common.select_lang(packet.get_doc()[1]) parameter = { 'en': 'parameter', 'de': 'Parameter' } parameters = { 'en': 'parameters', 'de': 'Parameter' } for other_packet in device.get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) if other_packet.get_type() == 'callback': name_upper = other_packet.get_upper_case_name() pre_upper = device.get_upper_case_name() name_right = ':c:data:`{0}_CALLBACK_{1}`'.format(pre_upper, name_upper) else: name_right = ':c:func:`{0}_{1}`'.format(device.get_underscore_name(), other_packet.get_underscore_name()) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = common.handle_rst_if(text, device) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, 1)
def get_php_object_desc(self): if len(self.get_elements('out')) < 2: return '' desc = { 'en': """ The returned array has the keys {0}. """, 'de': """ Das zurückgegebene Array enthält die Keys {0}. """ } and_ = {'en': ' and ', 'de': ' und '} var = [] for element in self.get_elements('out'): var.append('``{0}``'.format(element.get_underscore_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def format_doc(packet): text = common.select_lang(packet.get_doc()[1]) parameter = { 'en': 'parameter', 'de': 'Parameter' } parameters = { 'en': 'parameters', 'de': 'Parameter' } cls = device.get_category() + device.get_camel_case_name() for other_packet in device.get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) name = other_packet.get_camel_case_name() if other_packet.get_type() == 'callback': name_right = ':delphi:func:`On{1} <T{0}.On{1}>`'.format(cls, name) else: name_right = ':delphi:func:`{1} <T{0}.{1}>`'.format(cls, name) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = common.handle_rst_if(text, device) prefix = '{0}_{1}_'.format(device.get_category().upper(), device.get_upper_case_name()) text = common.handle_constants(text, prefix, packet) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, 1)
def get_perl_object_desc(self, high_level=False): if len(self.get_elements(direction='out', high_level=high_level)) < 2: return '' desc = { 'en': """ The returned array contains the elements {0}. """, 'de': """ Das zurückgegebene Array enthält die Elemente {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements(direction='out', high_level=high_level): var.append('``{0}``'.format(element.get_name().under)) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def constant_format(prefix, constant_group, constant, value): c = '* {0}: {1}, '.format(value, constant.get_underscore_name().replace('_', ' ')) for_ = { 'en': 'for', 'de': 'für' } c += common.select_lang(for_) + ' ' e = [] for element in constant_group.get_elements(): name = element.get_underscore_name() e.append(name) if len(e) > 1: and_ = { 'en': 'and', 'de': 'und' } c += ', '.join(e[:-1]) + ' ' + common.select_lang(and_) + ' ' + e[-1] else: c += e[0] return c + '\n'
def get_perl_object_desc(self): if len(self.get_elements("out")) < 2: return "" desc = { "en": """ The returned array contains the elements {0}. """, "de": """ Das zurückgegebene Array enthält die Elemente {0}. """, } and_ = {"en": " and ", "de": " und "} var = [] for element in self.get_elements("out"): var.append("``{0}``".format(element.get_underscore_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(", ".join(var[:-1]) + common.select_lang(and_) + var[-1])
def get_php_object_desc(self): if len(self.get_elements('out')) < 2: return '' desc = { 'en': """ The returned array has the keys {0}. """, 'de': """ Das zurückgegebene Array enthält die Keys {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements('out'): var.append('``{0}``'.format(element.get_underscore_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def get_java_object_desc(self, high_level=False): if len(self.get_elements(direction='out', high_level=high_level)) < 2: return '' desc = { 'en': """ The returned object has the public member variables {0}. """, 'de': """ Das zurückgegebene Objekt enthält die Public-Member-Variablen {0}. """ } and_ = {'en': ' and ', 'de': ' und '} var = [] for element in self.get_elements(direction='out', high_level=high_level): var.append('``{0} {1}``'.format(element.get_java_type(), element.get_name().headless)) if len(var) == 1: return common.select_lang(desc).format(var[0]) elif len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) else: return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def get_matlab_object_desc(self): if len(self.get_elements('out')) < 2: return '' desc = { 'en': """ The returned object has the public member variables {0}. """, 'de': """ Das zurückgegebene Objekt enthält die Public Member Variablen {0}. """ } and_ = { 'en': ' and ', 'de': ' und ' } var = [] for element in self.get_elements('out'): typ = element.get_matlab_type() if element.get_cardinality() > 1 and element.get_type() != 'string': typ += '[]' var.append('``{0} {1}``'.format(typ, element.get_headless_camel_case_name())) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + common.select_lang(and_) + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + common.select_lang(and_) + var[-1])
def format_doc(packet): text = common.select_lang(packet.get_doc()[1]) parameter = { 'en': 'parameter', 'de': 'Parameter' } parameters = { 'en': 'parameters', 'de': 'Parameter' } cls = device.get_camel_case_name() for other_packet in device.get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) if other_packet.get_type() == 'callback': name_upper = other_packet.get_upper_case_name() name_right = ':py:attr:`CALLBACK_{1} <{0}.CALLBACK_{1}>`'.format(cls, name_upper) else: name_right = ':py:func:`{1}() <{0}.{1}>`'.format(cls, other_packet.get_underscore_name()) text = text.replace(name_false, name_right) text = text.replace(":word:`parameter`", common.select_lang(parameter)) text = text.replace(":word:`parameters`", common.select_lang(parameters)) text = common.handle_rst_if(text, device) text = common.handle_constants(text, device.get_category() + device.get_camel_case_name() + '.', packet) text = common.handle_since_firmware(text, device, packet) return common.shift_right(text, 1)
def get_go_imports(self): tf_doc_link = { 'en': '// See also the documentation here: https://www.tinkerforge.com/en/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Go.html.', 'de': '// Siehe auch die Dokumentation hier: https://www.tinkerforge.com/de/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Go.html.' } desc = common.select_lang(self.get_description()) plenk = "REPLACE_WITH_ZWJ" if len(desc) > 0 and desc[-1].isupper( ) else "" description = desc + plenk + "." description += '\n// \n// \n' description += common.select_lang(tf_doc_link).format( device_category_camel=self.get_category().camel, device_name_camel=self.get_name().camel) return """{header} //{description} package {device} import ( "encoding/binary" "bytes" . "github.com/Tinkerforge/go-api-bindings/internal" "github.com/Tinkerforge/go-api-bindings/ipconnection" ) """.format(header=self.get_generator().get_header_comment(kind='asterisk'), description=description, device=self.get_go_package())
def make_object_desc(packet): if len(packet.get_elements('out')) < 2: return '' desc = { 'en': """ The returned object has the public member variables {0}. """, 'de': """ Das zurückgegebene Objekt enthält die Public Member Variablen {0}. """ } var = [] for element in packet.get_elements('out'): var.append('``{0} {1}``'.format(java_common.get_java_type(element[1]), common.underscore_to_headless_camel_case(element[0]))) if len(var) == 1: return common.select_lang(desc).format(var[0]) if len(var) == 2: return common.select_lang(desc).format(var[0] + ' and ' + var[1]) return common.select_lang(desc).format(', '.join(var[:-1]) + ' and ' + var[-1])
def get_tvpl_doc_type(self): t = common.select_lang(self.tvpl_doc_types)[self.get_type()] c = self.get_cardinality() list_of = {"en": "List of ", "de": "Liste von "} if c == 1 or self.get_type() == "string": return t[0] return "{0}{1} {2}".format(common.select_lang(list_of), c, t[0 if c == 1 else 1])
def get_tvpl_doc_type(self): t = common.select_lang(self.tvpl_doc_types)[self.get_type()] c = self.get_cardinality() list_of = {'en': 'List of ', 'de': 'Liste von '} if c == 1 or self.get_type() == 'string': return t[0] return '{0}{1} {2}'.format(common.select_lang(list_of), c, t[0 if c == 1 else 1])
def get_tvpl_doc_type(self): t = common.select_lang(self.tvpl_doc_types)[self.get_type()] c = self.get_cardinality() list_of = { 'en': 'List of ', 'de': 'Liste von ' } if c == 1 or self.get_type() == 'string': return t[0] return '{0}{1} {2}'.format(common.select_lang(list_of), c, t[0 if c == 1 else 1])
def get_mqtt_formatted_doc(self): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_mqtt_doc_function_links(text) constants = {'en': 'symbols', 'de': 'Symbole'} callback_parameter = {'en': 'callback payload', 'de': 'Payload des Callbacks'} callback_parameters = {'en': 'callback payload members', 'de': 'Payload-Member des Callbacks'} def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) if self.get_type() == 'callback': text = common.handle_rst_word(text, parameter=callback_parameter, parameters=callback_parameters, constants=constants) else: text = common.handle_rst_word(text, constants=constants) text = common.handle_rst_substitutions(text, self) prefix = '' const_fmt_func = lambda prefix, constant_group, constant, value: '* "{0}" = {1}\n'.format( constant.get_name().camel, value) const_func_id_fmt_func = lambda prefix, func_name, value: '* {0}Function{1} = {2}\n'.format( prefix, func_name.camel, value) def constant_group_func(group): splt = group.get_name().under.split('_') found = None for elem in group.get_elements(): if elem.get_packet().get_name().under == self.get_name().under: return elem.get_name().under #to_search = [] #for word in reversed(splt): # to_search.append(word) # if elem.get_name().under == '_'.join(to_search): # return elem.get_name().under return group.get_name().under if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants(prefix, self.get_device(), constants, constant_format_func=const_func_id_fmt_func) else: _for = common.select_lang({'en': 'for', 'de': 'für'}) text += common.format_constants(prefix, self, constants, constant_format_func=const_fmt_func, show_constant_group=True, group_format_func=lambda g: "\n" + _for + " " + constant_group_func(g) + ":\n\n") text += common.format_since_firmware(self.get_device(), self) text = text.replace('|device_identifier_constant|\n', '') return common.shift_right(text, 1)
def get_rust_imports(self): conv_receiver_imports = ["ConvertingReceiver"] # High level functions return a Result<(PayloadT, ResultT), BrickletRecvTimeoutError> directly, because they block. if any(packet.has_high_level() for packet in self.get_packets()): conv_receiver_imports.append("BrickletRecvTimeoutError") # Conversion from String to bytes can raise an error, which is sent directly into the created result channel. # Rust can't deduce the channel's type parameters, so we need to specify them. BrickletError is the Result's error type. if any("String" in elem.get_rust_type() for packet in self.get_packets() for elem in packet.get_elements(direction='in')): conv_receiver_imports.append("BrickletError") conv_receiver = conv_receiver_imports[0] if len( conv_receiver_imports) == 1 else ( "{" + ", ".join(conv_receiver_imports) + "}") tf_doc_link = { 'en': '//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Rust.html).', 'de': '//! Siehe auch die Dokumentation [hier](https://www.tinkerforge.com/de/doc/Software/{device_category_camel}s/{device_name_camel}_{device_category_camel}_Rust.html).' } description = common.select_lang(self.get_description()) + "." description += '\n//! \n' description += common.select_lang(tf_doc_link).format( device_category_camel=self.get_category().camel, device_name_camel=self.get_name().camel) return """{header} //! {description} use crate::{{ byte_converter::*, converting_receiver::{conv_receiver},{callback_recv}{high_level_callback_recv} device::*, ip_connection::IpConnection,{low_level} }};""".format( header=self.get_generator().get_header_comment(kind='asterisk'), description=description, callback_recv="" if len(self.get_packets("callback")) == 0 else "\n\tconverting_callback_receiver::ConvertingCallbackReceiver,", high_level_callback_recv="" if all( not packet.has_high_level() for packet in self.get_packets("callback")) else "\n\tconverting_high_level_callback_receiver::ConvertingHighLevelCallbackReceiver,", low_level="" if all(not packet.has_high_level() for packet in self.get_packets()) else "\n\tlow_level_traits::*", conv_receiver=conv_receiver)
def get_mathematica_formatted_doc(self): text = common.select_lang(self.get_doc()[1]) cls = self.get_device().get_mathematica_class_name() for other_packet in self.get_device().get_packets(): name_false = ':func:`{0}`'.format(other_packet.get_camel_case_name()) name = other_packet.get_camel_case_name() if other_packet.get_type() == 'callback': name_right = ':mathematica:func:`{1} <{0}@{1}>`'.format(cls, name) else: name_right = ':mathematica:func:`{1}[] <{0}@{1}>`'.format(cls, name) text = text.replace(name_false, name_right) def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = cls + '`' if self.get_underscore_name() == 'set_response_expected': text += common.format_function_id_constants(prefix, self.get_device()).replace('_', 'U') else: def constant_format(prefix, constant_group, constant_item, value): return '* {0}{1}U{2} = {3}\n'.format(prefix, constant_group.get_upper_case_name().replace('_', 'U'), constant_item.get_upper_case_name().replace('_', 'U'), value) text += common.format_constants(prefix, self, char_format='``ToCharacterCode["{0}"][[0]]``', constant_format_func=constant_format) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def make_callbacks(): cb = { 'en': """ .. csharp:function:: public event {0}::{1}({2}) {3} """, 'de': """ .. csharp:function:: public event {0}::{1}({2}) {3} """ } cbs = '' cls = device.get_camel_case_name() for packet in device.get_packets('callback'): desc = format_doc(packet, 2) params = csharp_common.make_parameter_list(packet) cbs += common.select_lang(cb).format(device.get_category() + device.get_camel_case_name(), packet.get_camel_case_name(), params, desc) return cbs
def get_vbnet_callbacks(self): cb = { 'en': """ .. vbnet:function:: Event {0}.{1}(ByVal sender As {0}{2}) {3} """, 'de': """ .. vbnet:function:: Event {0}.{1}(ByVal sender As {0}{2}) {3} """ } cbs = '' for packet in self.get_packets('callback'): desc = packet.get_vbnet_formatted_doc() params = packet.get_vbnet_parameter_list() if len(params) > 0: params = ', ' + params cbs += common.select_lang(cb).format(self.get_vbnet_class_name(), packet.get_camel_case_name(), params, desc) return cbs
def get_csharp_callbacks(self): cb = { 'en': """ .. csharp:function:: public event {0}::{1}({0} sender{2}) {3} """, 'de': """ .. csharp:function:: public event {0}::{1}({0} sender{2}) {3} """ } cbs = '' cls = self.get_csharp_class_name() for packet in self.get_packets('callback'): desc = packet.get_csharp_formatted_doc(2) params = packet.get_csharp_parameter_list() if len(params) > 0: params = ', ' + params cbs += common.select_lang(cb).format(cls, packet.get_camel_case_name(), params, desc) return cbs
def get_java_formatted_doc(self, shift_right): text = common.select_lang(self.get_doc()[1]) text = self.get_device().replace_java_function_links(text) text = text.replace('Callback ', 'Listener ') text = text.replace(' Callback', ' Listener') text = text.replace('callback ', 'listener ') text = text.replace(' callback', ' listener') def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_java_class_name() + '.' if self.get_underscore_name() == 'set_response_expected': text += common.format_function_id_constants( prefix, self.get_device()) else: text += common.format_constants(prefix, self) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, shift_right)
def get_vbnet_formatted_doc(self): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_vbnet_doc_function_links(text) # FIXME: add something similar for :char:`c` def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_vbnet_class_name() + '.' if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants( prefix, self.get_device()) else: text += common.format_constants(prefix, self, char_format_func='"{0}"C'.format) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_java_formatted_doc(self, shift_right): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_java_doc_function_links(text) text = text.replace('Callback ', 'Listener ') text = text.replace(' Callback', ' Listener') text = text.replace('callback ', 'listener ') text = text.replace(' callback', ' listener') def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_java_class_name() + '.' if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants( prefix, self.get_device()) else: text += common.format_constants( prefix, self, bool_format_func=lambda value: str(value).lower()) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, shift_right)
def get_mqtt_elements(self, high_level, direction): # if direction == 'in': # param_str = ':register' if self.get_type() == 'callback' else ':request' # elif direction == 'out': # param_str = ':callback' if self.get_type() == 'callback' else ':response' if direction == 'in': param_str = ':request' elif direction == 'out': param_str = ':response' params = [] has_symbols = {'en': ' `(has symbols)`', 'de': ' `(hat Symbole)`'} # The bindings are patched to translate device_identifier constants. Document this behaviour show_symbols = lambda elem: elem.get_constant_group() != None \ or (self.get_name().under == 'get_identity' and elem.get_name().under == 'device_identifier') for element in self.get_elements(direction=direction, high_level=high_level): params.append('{param_str} {name}: {type}{symbols}'.format( param_str=param_str, name=element.get_name().under, type=element.get_mqtt_type(for_doc=True), symbols=common.select_lang(has_symbols) if show_symbols(element) else '')) if self.get_name().under == 'get_identity' and direction == 'out': params.append(':response _display_name: string') return '\n '.join(params)
def get_php_callbacks(self): signature_str = { 'en': """ .. code-block:: php <?php void callback({0}) ?> """, 'de': """ .. code-block:: php <?php void callback({0}) ?> """ } cbs = '' func_start = '.. php:member:: int ' cls = self.get_php_class_name() for packet in self.get_packets('callback'): skip = -2 if packet.has_high_level() else 0 params = packet.get_php_parameters(context='doc', high_level=True) if len(params) > 0: params += " [, mixed $user_data]" else: params += "[mixed $user_data]" desc = packet.get_php_formatted_doc() signature = common.select_lang(signature_str).format(params) func = '{0}{1}::CALLBACK_{2}\n{3}{4}'.format( func_start, cls, packet.get_name(skip=skip).upper, signature, desc) cbs += func + '\n' return cbs
def get_delphi_formatted_doc(self): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_delphi_doc_function_links(text) def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = '{0}_{1}_'.format(self.get_device().get_category().upper, self.get_device().get_name().upper) if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants( prefix, self.get_device()) else: text += common.format_constants( prefix, self, bool_format_func=lambda value: str(value).lower()) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_go_callbacks(self): param_format = { 'en': """ .. code-block:: c void callback({0}) """, 'de': """ .. code-block:: c void callback({0}) """ } cbs = '' func_start = '.. c:var:: ' for packet in self.get_packets('callback'): plist = packet.get_c_parameter_list()[2:].replace('*ret_', '').replace('ret_', '') if not plist: plist = 'void *user_data' else: plist += ', void *user_data' params = common.select_lang(param_format).format(plist) desc = packet.get_c_formatted_doc() name = '{0}_{1}'.format(self.get_upper_case_name(), packet.get_upper_case_name()) func = '{0}{1}_CALLBACK_{2}\n{3}\n{4}'.format(func_start, self.get_upper_case_name(), packet.get_upper_case_name(), params, desc) cbs += func + '\n' return cbs
def get_delphi_callbacks(self): cbs = '' cb = { 'en': """.. delphi:function:: property {0}.On{1} .. code-block:: delphi procedure(sender: {0}{4}{2}) of object; {3} """, 'de': """.. delphi:function:: property {0}.On{1} .. code-block:: delphi procedure(sender: {0}{4}{2}) of object; {3} """ } cls = self.get_delphi_class_name() for packet in self.get_packets('callback'): name = packet.get_name().camel params = '; '.join(packet.get_delphi_parameters(True)) desc = packet.get_delphi_formatted_doc() semi = '' if len(params) > 0: semi = '; ' cbs += common.select_lang(cb).format(cls, name, params, desc, semi) return cbs
def get_c_callbacks(self): param_format = { 'en': """ .. code-block:: c void callback({0}) """, 'de': """ .. code-block:: c void callback({0}) """ } cbs = '' func_start = '.. c:var:: ' for packet in self.get_packets('callback'): plist = packet.get_c_parameter_list()[2:].replace('*ret_', '').replace( 'ret_', '') if not plist: plist = 'void *user_data' else: plist += ', void *user_data' params = common.select_lang(param_format).format(plist) desc = packet.get_c_formatted_doc() name = '{0}_{1}'.format(self.get_upper_case_name(), packet.get_upper_case_name()) func = '{0}{1}_CALLBACK_{2}\n{3}\n{4}'.format( func_start, self.get_upper_case_name(), packet.get_upper_case_name(), params, desc) cbs += func + '\n' return cbs
def get_mathematica_formatted_doc(self): text = common.select_lang(self.get_doc()[1]) text = self.get_device().replace_mathematica_function_links(text) def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_mathematica_class_name() + '`' if self.get_underscore_name() == 'set_response_expected': text += common.format_function_id_constants(prefix, self.get_device()).replace('_', 'U') else: def constant_format(prefix, constant_group, constant_item, value): return '* {0}{1}U{2} = {3}\n'.format(prefix, constant_group.get_upper_case_name().replace('_', 'U'), constant_item.get_upper_case_name().replace('_', 'U'), value) text += common.format_constants(prefix, self, char_format='``ToCharacterCode["{0}"][[0]]``', constant_format_func=constant_format) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_tcpip_formatted_doc(self): text = common.select_lang(self.get_doc_text()) constants = {'en': 'meanings', 'de': 'Bedeutungen'} constants_intro = { 'en': """ The following {0} are defined for the parameters of this function: """, 'de': """ Die folgenden {0} sind für die Parameter dieser Funktion definiert: """ } parameter = {'en': 'response value', 'de': 'Rückgabewert'} parameters = {'en': 'response values', 'de': 'Rückgabewerte'} text = self.get_device().specialize_tcpip_doc_function_links(text) def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text, parameter, parameters) text = common.handle_rst_substitutions(text, self) def constant_format(prefix, constant_group, constant, value): c = '* {0}: {1}, '.format(value, constant.get_name().lower) for_ = {'en': 'for', 'de': 'für'} c += common.select_lang(for_) + ' ' e = [] for element in constant_group.get_elements(): name = element.get_name().under e.append(name) if len(e) > 1: and_ = {'en': 'and', 'de': 'und'} c += ', '.join( e[:-1]) + ' ' + common.select_lang(and_) + ' ' + e[-1] else: c += e[0] return c + '\n' text += common.format_constants('', self, constants_name=constants, char_format='{0}', constant_format_func=constant_format, constants_intro=constants_intro) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_rust_formatted_doc(self): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_rust_doc_function_links(text) constants = {'en': 'constants', 'de': 'Konstanten'} callback_parameter = {'en': 'received variable', 'de': 'empfangene Variable'} callback_parameters = {'en': 'members of the received struct', 'de': 'Felder der empfangenen Struktur'} def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) if self.get_type() == 'callback': text = common.handle_rst_word(text, parameter=callback_parameter, parameters=callback_parameters, constants=constants) else: text = common.handle_rst_word(text, constants=constants) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_rust_module_name().upper() + '_' if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants(prefix, self.get_device(), constants) else: text += common.format_constants(prefix, self, constants, bool_format_func=lambda value: str(value).lower()) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_c_callbacks(self): param_format = { 'en': """ .. code-block:: c void callback({0}) """, 'de': """ .. code-block:: c void callback({0}) """ } cbs = '' func_start = '.. c:var:: ' for packet in self.get_packets('callback'): plist = packet.get_c_parameters(high_level=True) if len(plist) == 0: plist = 'void *user_data' else: plist += ', void *user_data' params = common.select_lang(param_format).format(plist) desc = packet.get_c_formatted_doc() skip = -2 if packet.has_high_level() else 0 func = '{0}{1}_CALLBACK_{2}\n{3}\n{4}'.format( func_start, self.get_name().upper, packet.get_name(skip=skip).upper, params, desc) cbs += func + '\n' return cbs
def get_mathematica_formatted_doc(self): text = common.select_lang(self.get_doc_text()) text = self.get_device().specialize_mathematica_doc_function_links(text) def format_parameter(name): return '``{0}``'.format(name) # FIXME text = common.handle_rst_param(text, format_parameter) text = common.handle_rst_word(text) text = common.handle_rst_substitutions(text, self) prefix = self.get_device().get_mathematica_class_name() + '`' if self.get_name().space == 'Set Response Expected': text += common.format_function_id_constants(prefix, self.get_device()).replace('_', 'U') else: def constant_format(prefix, constant_group, constant, value): return '* {0}{1}U{2} = {3}\n'.format(prefix, constant_group.get_name().upper.replace('_', 'U'), constant.get_name().upper.replace('_', 'U'), value) text += common.format_constants(prefix, self, char_format_func='``ToCharacterCode["{0}"][[0]]``'.format, constant_format_func=constant_format) text += common.format_since_firmware(self.get_device(), self) return common.shift_right(text, 1)
def get_tvpl_return_list(self): ret = ' R{0}' ret_list = [] and_ = {'en': '_and_', 'de': '_und_'} list_of = {'en': 'List_of_', 'de': 'Liste_mit_'} for element in self.get_elements(direction='out'): ret_list.append(element.get_name().space.replace(' ', '_')) if len(ret_list) == 0: return '' elif len(ret_list) == 1: return ret.format(ret_list[0]) return ret.format( common.select_lang(list_of) + ',_'.join(ret_list[:-1]) + common.select_lang(and_) + ret_list[-1])
def get_matlab_callbacks(self): cb = { 'en': """ .. matlab:member:: public callback {0}.{1}Callback {2} {3} In MATLAB the ``set()`` function can be used to register a callback function to this callback. In Octave a callback function can be added to this callback using the ``add{1}Callback()`` function. An added callback function can be removed with the ``remove{1}Callback()`` function. """, 'de': """ .. matlab:member:: public callback {0}.{1}Callback {2} {3} In MATLAB kann die ``set()`` Function verwendet werden um diesem Callback eine Callback-Function zuzuweisen. In Octave kann diesem Callback mit ``add{1}Callback()`` eine Callback-Function hinzugefügt werde. Eine hinzugefügter Callback-Function kann mit ``remove{1}Callback()`` wieder entfernt werden. """ } cbs = '' cls = self.get_matlab_class_name() for packet in self.get_packets('callback'): desc = packet.get_matlab_formatted_doc(1) params = [] for element in packet.get_elements('out'): matlab_type = element.get_matlab_type() name = element.get_headless_camel_case_name() if element.get_cardinality() > 1 and element.get_type( ) != 'string': matlab_type += '[]' params.append(' :param {0}: {1}'.format(name, matlab_type)) cbs += common.select_lang(cb).format(cls, packet.get_camel_case_name(), '\n'.join(params), desc) return cbs