sx1231_params_convert.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # coding=utf-8
  2. import sys,os
  3. import codecs
  4. import re
  5. def cmt2300_import_hex(strFile, getValue):
  6. input = codecs.open(strFile, 'r', 'utf-8')
  7. arr8 = [0] * 0x72
  8. addrArr8 = [0] * 0x72
  9. count = 0
  10. for i in range(0x71):
  11. addrArr8[i] = 0xff
  12. for line in input:
  13. line = line.replace('\r', '').replace('\n', '').replace('\t', ' ').replace('\v', ' ').strip()
  14. if(line.find('PKT')>=0) or (line.find('#Type')>=0):
  15. continue
  16. arr = re.findall('0[xX][0-9A-Fa-f]+', line)
  17. print('addr',arr[0])
  18. print('value',arr[1])
  19. if len(arr) >= 2:
  20. addr = int(arr[0], 16)
  21. arr8[addr] = int(arr[1], 16)
  22. addrArr8[addr] = addr
  23. input.close()
  24. if getValue == 1:
  25. return arr8
  26. else:
  27. return addrArr8
  28. def cmt2300_convert_hex(strSrcFile, strDstFile, strSubfix):
  29. output = codecs.open(strDstFile, 'w', 'utf-8')
  30. arr8 = cmt2300_import_hex(strSrcFile, 1)
  31. addrArr8 = cmt2300_import_hex(strSrcFile, 0)
  32. output.write('#ifndef __SX1231_PARAMS' +strSubfix.upper()+ '_H\r\n')
  33. output.write('#define __SX1231_PARAMS' +strSubfix.upper()+ '_H\r\n')
  34. output.write('#include <stdint.h>\r\n')
  35. output.write('\r\n')
  36. output.write('const uint8_t sx1231ParamsList' +strSubfix+ '[] = {\r\n')
  37. output.write('/* addr value*/\r\n')
  38. for i in range(0x00, 0x72):
  39. str = " 0x%02X," %(addrArr8[i])
  40. output.write(str)
  41. str = " 0x%02X," %(arr8[i])
  42. output.write(str +'\r\n')
  43. output.write('};\r\n\r\n')
  44. output.write('#endif\r\n')
  45. output.close()
  46. cmt2300_convert_hex('sx1231skb.exp', 'sx1231_params.h', '')