X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=generator%2Fnanopb_generator.py;h=4f8ed94cbe755e699471f6327ad702a3ce055bfe;hb=a2f8112166d73aaf7e8fc877f0310202319d4639;hp=7b3c9f80622b6bbad929625f916b02ce1cb8415c;hpb=45c1a32e5046fe9323d4fd0213b474a554b2bbed;p=apps%2Fagl-service-can-low-level.git diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 7b3c9f80..4f8ed94c 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -1,30 +1,39 @@ #!/usr/bin/python '''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.''' -nanopb_version = "nanopb-0.2.5-dev" +nanopb_version = "nanopb-0.2.6-dev" + +import sys try: + # Add some dummy imports to keep packaging tools happy. import google, distutils.util # bbfreeze seems to need these + import pkg_resources # pyinstaller / protobuf 2.5 seem to need these +except: + # Don't care, we will error out later if it is actually important. + pass + +try: import google.protobuf.text_format as text_format except: - print - print "*************************************************************" - print "*** Could not import the Google protobuf Python libraries ***" - print "*** Try installing package 'python-protobuf' or similar. ***" - print "*************************************************************" - print + sys.stderr.write(''' + ************************************************************* + *** Could not import the Google protobuf Python libraries *** + *** Try installing package 'python-protobuf' or similar. *** + ************************************************************* + ''' + '\n') raise try: import proto.nanopb_pb2 as nanopb_pb2 import proto.descriptor_pb2 as descriptor except: - print - print "********************************************************************" - print "*** Failed to import the protocol definitions for generator. ***" - print "*** You have to run 'make' in the nanopb/generator/proto folder. ***" - print "********************************************************************" - print + sys.stderr.write(''' + ******************************************************************** + *** Failed to import the protocol definitions for generator. *** + *** You have to run 'make' in the nanopb/generator/proto folder. *** + ******************************************************************** + ''' + '\n') raise @@ -160,6 +169,7 @@ class Field: self.max_count = None self.array_decl = "" self.enc_size = None + self.ctype = None # Parse field options if field_options.HasField("max_size"): @@ -305,6 +315,12 @@ class Field: data = self.default.decode('string_escape') data = ['0x%02x' % ord(c) for c in data] default = '{%d, {%s}}' % (len(data), ','.join(data)) + elif self.pbtype in ['FIXED32', 'UINT32']: + default += 'u' + elif self.pbtype in ['FIXED64', 'UINT64']: + default += 'ull' + elif self.pbtype in ['SFIXED64', 'INT64']: + default += 'll' if declaration_only: return 'extern const %s %s_default%s;' % (ctype, self.struct_name + self.name, array_decl)