genfile.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import sys,getopt,string
  2. filenames = None
  3. fileOut = None
  4. filePath = None
  5. blocksize = 1024
  6. i = 0
  7. license ='/*\n'\
  8. ' ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio\n'\
  9. '\n'\
  10. ' Licensed under the Apache License, Version 2.0 (the "License");\n'\
  11. ' you may not use this file except in compliance with the License.\n'\
  12. ' You may obtain a copy of the License at\n'\
  13. '\n'\
  14. ' http://www.apache.org/licenses/LICENSE-2.0\n'\
  15. '\n'\
  16. ' Unless required by applicable law or agreed to in writing, software\n'\
  17. ' distributed under the License is distributed on an "AS IS" BASIS,\n'\
  18. ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'\
  19. ' See the License for the specific language governing permissions and\n'\
  20. ' limitations under the License.\n'\
  21. '*/\n'
  22. opts,args = getopt.getopt(sys.argv[1:],'f:o:p:')
  23. for o,a in opts:
  24. if o == '-f':
  25. filenames = a
  26. if o == '-o':
  27. fileOut = a
  28. if o == '-p':
  29. filePath = a
  30. filenames = filenames.split(",")
  31. fc = open (filePath+"/"+fileOut+".c","w")
  32. fh = open (filePath+"/"+fileOut+".h","w")
  33. fc.write(license)
  34. fc.write("\n#include \"hal.h\"\n\n")
  35. fh.write(license)
  36. fh.write("#ifndef TEST_"+fileOut.upper()+"_H_\n")
  37. fh.write("#define TEST_"+fileOut.upper()+"_H_\n\n")
  38. for fn in filenames:
  39. print "opening ",fn
  40. i = 0
  41. f = open(fn+".enc","rb")
  42. block = f.read(blocksize)
  43. d = fn.split("_")
  44. fc.write("const uint8_t ref"+d[0].upper()+"_"+d[1].upper()+"_"+d[2].upper()+"[]={\n")
  45. fh.write("extern const uint8_t ref"+d[0].upper()+"_"+d[1].upper()+"_"+d[2].upper()+"[];\n")
  46. str = ""
  47. for ch in block:
  48. i += 1
  49. str += "0x"+format(ord(ch), '02X')+","
  50. if i == 10:
  51. str += "\n"
  52. i = 0
  53. fc.write(str)
  54. fc.write("\n};\n")
  55. fh.write("#endif //TEST_"+fileOut.upper()+"_H_\n")