# coding=utf-8 import sys,os import codecs import re def cmt2300_import_hex(strFile, getValue): input = codecs.open(strFile, 'r', 'utf-8') arr8 = [0] * 0x72 addrArr8 = [0] * 0x72 count = 0 for i in range(0x71): addrArr8[i] = 0xff for line in input: line = line.replace('\r', '').replace('\n', '').replace('\t', ' ').replace('\v', ' ').strip() if(line.find('PKT')>=0) or (line.find('#Type')>=0): continue arr = re.findall('0[xX][0-9A-Fa-f]+', line) print('addr',arr[0]) print('value',arr[1]) if len(arr) >= 2: addr = int(arr[0], 16) arr8[addr] = int(arr[1], 16) addrArr8[addr] = addr input.close() if getValue == 1: return arr8 else: return addrArr8 def cmt2300_convert_hex(strSrcFile, strDstFile, strSubfix): output = codecs.open(strDstFile, 'w', 'utf-8') arr8 = cmt2300_import_hex(strSrcFile, 1) addrArr8 = cmt2300_import_hex(strSrcFile, 0) output.write('#ifndef __SX1231_PARAMS' +strSubfix.upper()+ '_H\r\n') output.write('#define __SX1231_PARAMS' +strSubfix.upper()+ '_H\r\n') output.write('#include \r\n') output.write('\r\n') output.write('const uint8_t sx1231ParamsList' +strSubfix+ '[] = {\r\n') output.write('/* addr value*/\r\n') for i in range(0x00, 0x72): str = " 0x%02X," %(addrArr8[i]) output.write(str) str = " 0x%02X," %(arr8[i]) output.write(str +'\r\n') output.write('};\r\n\r\n') output.write('#endif\r\n') output.close() cmt2300_convert_hex('sx1231skb.exp', 'sx1231_params.h', '')