8000 Discussion: Have an enum for Device Identifiers by NobodysNightmare · Pull Request #37 · Tinkerforge/generators · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Discussion: Have an enum for Device Identifiers #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions csharp/IPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -602,7 +602,7 @@ private void CallbackLoop(BlockingQueue<CallbackQueueObject> 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);
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions csharp/generate_csharp_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import csharp_common

device = None
enum_devices = []

def format_doc(packet):
text = common.select_lang(packet.get_doc()[1])
Expand Down Expand Up @@ -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'):
Expand All @@ -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'

Expand All @@ -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())
3 changes: 3 additions & 0 deletions generate_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
0