diff --git a/.travis.yml b/.travis.yml index 4f87c6c..fa1319a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ branches: before_install: - sudo apt-get -qq update + - sudo apt-get install golang install: - pip install -r requirements.txt diff --git a/Makefile b/Makefile index 0ecfafb..0cd7ba4 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ gen: protos @echo "Generating from templates..." @python codegen/build.py @find out -type f \( -iname '*.[ch]' -o -iname '*.ts' \) | xargs -r clang-format -i -fallback-style=Google + @find out -type f \( -iname '*.go' \) | xargs -r gofmt -w lint: @echo "Linting..." diff --git a/helpers/helpers.mako b/helpers/helpers.mako index 0a47390..bef2c32 100644 --- a/helpers/helpers.mako +++ b/helpers/helpers.mako @@ -19,3 +19,24 @@ Args: % endfor NUM_${prefix}S = ${len(data)} \ + +<%doc> +Helps generating enum body content in the format: + + prefix_val0 type = 0, + prefix_val1 type = 2, + prefix_val2 type = 5, + ... + +Args: + data: a dictionary of data in the range (empty values should have a value of None) + prefix: the prefix to use + go_type: the type in go + +<%def name="generate_enum_go(data, prefix, go_type)"> \ + % for key, value in data.items(): + % if value != None: + ${prefix}${''.join(x.title() for x in value.split('_'))} ${go_type} = ${key} + % endif + % endfor + diff --git a/templates/can_msg_defs.mako.go b/templates/can_msg_defs.mako.go new file mode 100644 index 0000000..dae1038 --- /dev/null +++ b/templates/can_msg_defs.mako.go @@ -0,0 +1,18 @@ +<%namespace name="helpers" file="/helpers/helpers.mako" /> \ +<% from data import NUM_CAN_MESSAGES, NUM_CAN_DEVICES, parse_can_device_enum, parse_can_message_enum, parse_can_frames %> \ +package CanMsgDefs + +type CanDeviceId uint16 +type CanMsgId uint32 + +// For setting the CAN device +const ( + <% can_devices = parse_can_device_enum() %> \ +${helpers.generate_enum_go(can_devices, 'SystemCanDevice', 'CanDeviceId')} +) + +// For setting the CAN message ID +const ( + <% can_messages = parse_can_message_enum(options.filename) %> \ +${helpers.generate_enum_go(can_messages, 'SystemCanMessage', 'CanMsgId')} +)