From 02652148fc9648e258f091298d7fae6159069823 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 3 Apr 2015 19:44:23 +0300 Subject: Generate #defines for plain message ids --- generator/nanopb_generator.py | 10 +++++++--- tests/options/options.expected | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 4673ac67..fc32e2c5 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -1005,9 +1005,8 @@ def generate_header(dependencies, headername, enums, messages, extensions, optio yield '#define %-40s %s\n' % (identifier, msize) yield '\n' - yield '/* helper macros for message type ids if set with */\n' - yield '/* option (nanopb_msgopt).msgid = ; */\n\n' - + yield '/* Message IDs (where set with "msgid" option) */\n' + yield '#ifdef PB_MSGID\n' for msg in messages: if hasattr(msg,'msgid'): @@ -1026,6 +1025,11 @@ def generate_header(dependencies, headername, enums, messages, extensions, optio yield '\tPB_MSG(%d,%s,%s) \\\n' % (msg.msgid, m, msg.name) yield '\n' + for msg in messages: + if hasattr(msg,'msgid'): + yield '#define %s_msgid %d\n' % (msg.name, msg.msgid) + yield '\n' + yield '#endif\n\n' diff --git a/tests/options/options.expected b/tests/options/options.expected index ad74a525..63ba0fd8 100644 --- a/tests/options/options.expected +++ b/tests/options/options.expected @@ -14,4 +14,5 @@ Message5_EnumValue1 \s+PB_MSG\(103,[0-9]*,Message3\) \\ \s+PB_MSG\(104,-1,Message4\) \\ \s+PB_MSG\(105,[0-9]*,Message5\) \\ +#define Message5_msgid 105 -- cgit 1.2.3-korg