diff --git a/csharp/IPConnection.cs b/csharp/IPConnection.cs index 0cea6f61c..ddddc9df2 100644 --- a/csharp/IPConnection.cs +++ b/csharp/IPConnection.cs @@ -79,7 +79,7 @@ public class IPConnection public event EnumerateEventHandler EnumerateCallback; public delegate void EnumerateEventHandler(IPConnection sender, string uid, string connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, - int deviceIdentifier, short enumerationType); + DeviceIdentifier deviceIdentifier, short enumerationType); public event ConnectedEventHandler Connected; public delegate void ConnectedEventHandler(IPConnection sender, short connectReason); public event DisconnectedEventHandler Disconnected; @@ -602,7 +602,7 @@ private void CallbackLoop(BlockingQueue localCallbackQueue) firmwareVersion[0] = LEConverter.ByteFrom(28, cqo.data); firmwareVersion[1] = LEConverter.ByteFrom(29, cqo.data); firmwareVersion[2] = LEConverter.ByteFrom(30, cqo.data); - int deviceIdentifier = LEConverter.ShortFrom(31, cqo.data); + DeviceIdentifier deviceIdentifier = (DeviceIdentifier)LEConverter.ShortFrom(31, cqo.data); short enumerationType = LEConverter.ByteFrom(33, cqo.data); enumHandler(this, uid_str, connectedUid_str, position, hardwareVersion, firmwareVersion, deviceIdentifier, enumerationType); @@ -941,6 +941,7 @@ public void SetResponseExpectedAll(bool responseExpected) } } + //FIXME: can't use DeviceIdentifier enum here because of generators public abstract void GetIdentity(out string uid, out string connectedUid, out char position, out byte[] hardwareVersion, out byte[] firmwareVersion, out int deviceIdentifier); diff --git a/csharp/generate_csharp_bindings.py b/csharp/generate_csharp_bindings.py index 89442b57a..f0aa14b2b 100644 --- a/csharp/generate_csharp_bindings.py +++ b/csharp/generate_csharp_bindings.py @@ -34,6 +34,7 @@ import csharp_common device = None +enum_devices = [] def format_doc(packet): text = common.select_lang(packet.get_doc()[1]) @@ -397,6 +398,22 @@ def make_methods(): return methods +def make_enum_content(): + enum_content = """ +public enum DeviceIdentifier +{{ +{0} +}} +""" + enum_string = '' + for device in enum_devices: + enum_string += '\t{0} = {1},\n'.format(device[0], device[1]) + + """quick and dirty: strip away last comma and line-breaks""" + enum_string = enum_string[:-2] + + return enum_content.format(enum_string) + def get_data_size(packet): size = 0 for element in packet.get_elements('in'): @@ -405,8 +422,10 @@ def get_data_size(packet): def make_files(com_new, directory): global device + global enum_devices device = common.Device(com_new) file_name = '{0}{1}'.format(device.get_category(), device.get_camel_case_name()) + enum_devices += [(file_name, device.get_device_identifier())] version = common.get_changelog_version(directory) directory += '/bindings' @@ -421,5 +440,16 @@ def make_files(com_new, directory): csharp.write(make_methods()) csharp.write(make_callbacks()) +def generate_additional_files(directory): + directory += '/bindings' + generate_enum_file(directory) + +def generate_enum_file(directory): + print(" * DeviceIdentifier.cs") + enum_file = file('{0}/DeviceIdentifier.cs'.format(directory), "w") + enum_file.write(make_enum_content()) + enum_file.flush() + if __name__ == "__main__": common.generate(os.getcwd(), 'en', make_files, common.prepare_bindings, False) + generate_additional_files(os.getcwd()) diff --git a/generate_all.py b/generate_all.py index 8e0afc4de..e668f33c9 100644 --- a/generate_all.py +++ b/generate_all.py @@ -23,6 +23,9 @@ module = __import__('generate_{0}_bindings'.format(binding)) print("\nGenerating bindings for {0}:".format(binding)) common.generate(path_binding, 'en', module.make_files, common.prepare_bindings, False) + if("generate_additional_files" in dir(module)): + print(" * Additional Files:") + module.generate_additional_files(path_binding) # doc for binding in bindings: