Я должен разделить список шестнадцатеричных адресов на 4 части, взвесив разницу между двумя последовательными адресами.
Пример списка:
[0x10004158, 0x10004166, 0x100041a0, 0x100041e8, 0x100041f4, 0xb00ac668,0xb00ac672, 0xb00ac676, 0xb00ac67e, 0xb00ac682, 0xb00ac686, 0xb00c077f]
Вес рассчитывается по разнице между двумя последовательными адресами 0xb00c077f- 0x10004158 = 0xA00BC627
.
Цель состоит в том, чтобы создать как можно меньше минилистов вблизи 0x80000
, но не превышать это число.
В конце мы создадим минилисты. (Цель состоит в том, чтобы разница между первым и последним адресом списка не превышала 0x80000, но была бы ближе к этому значению.)
- Список 1
Start Adresse
, End Adresse
- Список 2
Start Adresse
, End Adresse
- Список 2
Start Adresse
, End Adresse
- Список 4
Start Adresse
, End Adresse
код:
import sys
import os
import time
import re
import glob
import numpy as np
class VXINI:
def __init__(self, pfad):
self.pfad = pfad
print self.findA2l()
print self.findMap()
print ("**** VX.ini Generator V1.0****** \n " + pfad)
def generator(self, parts):
myList = []
myListPoint = []
patern= re.compile("VALUE (0x[a-f0-9]{5,8})|ECU_ADDRESS (0x[a-f0-9]{5,8})")
for i , line in enumerate(open(self.findA2l())):
for match in re.finditer(patern, line):
filterString = match.group()
filterS = filterString.replace('ECU_ADDRESS ','')
filterFinal = filterS.replace('VALUE ','')
#print '%s: %s' % (i+i, filterFinal)
myList.append(filterFinal)
myList.sort()
print 'Number of Adresses %s:' % len(myList)
test = np.array_split(myList,parts)
print 'Number of Parts %s:' % len(test)
print '================================'
diffArr0 = hex(self.sToH(test[0][len(test[0])-1])-self.sToH(test[0][0]))
print diffArr0
diffArr1 = hex(self.sToH(test[1][len(test[1])-1])-self.sToH(test[1][0]))
diffArr2 = hex(self.sToH(test[2][len(test[2])-1])-self.sToH(test[2][0]))
diffArr3 = hex(self.sToH(test[3][len(test[3])-1])-self.sToH(test[3][0]))
diffArr4 = hex(self.sToH(test[4][len(test[4])-1])-self.sToH(test[4][0]))
diffArr5 = hex(self.sToH(test[5][len(test[5])-1])-self.sToH(test[5][0]))
diffArr6 = hex(self.sToH(test[6][len(test[6])-1])-self.sToH(test[6][0]))
diffArr7 = hex(self.sToH(test[7][len(test[7])-1])-self.sToH(test[7][0]))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[0][0],diffArr0,self.checkSize(diffArr0))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[1][0],diffArr1,self.checkSize(diffArr1))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[2][0],diffArr2, self.checkSize(diffArr2))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[3][0],diffArr3, self.checkSize(diffArr3))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[4][0],diffArr4, self.checkSize(diffArr4))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[5][0],diffArr5, self.checkSize(diffArr5))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[6][0],diffArr6, self.checkSize(diffArr6))
print 'Start Adresse %s: Size:%s Size compare to 0x80000 Size: %s' % (test[7][0],diffArr7, self.checkSize(diffArr7))
print '================================'
for i in range(0,parts):
myListPoint.append(test[0][i])
self.writeFile(self.pfad,myList)
self.compareMap(self.findMap(),myListPoint,"0x80000",parts)
print self.findMap()
def checkSize(self, difference):
sizeA = hex(self.sToH("0x80000"))
#print sizeA
#print difference
if(difference<sizeA):
result = "OK"
else:
result = "not OK"
return result
def compareMap(self,mapA,myList,sizeA,parts):
result = ""
for i in range(0,parts):
difference = self.sToH(mapA) - self.sToH(myList[i].tostring())
if(difference<sizeA):
result = "OK"
else:
result = "not OK"
print "mapA in Bereich. " + result
return result
def sToH(self,hex_str):
return int(hex_str, 16)
def findA2l(self):
concateFolderPathT1 =os.path.join(self.pfad,'*.a2l')
folderT1=glob.glob(concateFolderPathT1)
return folderT1[0]
def findMap(self):
concateFolderPathT1 =os.path.join(self.pfad,'*.map')
folderT1=glob.glob(concateFolderPathT1)
patern= re.compile("gVX1000 (b[a-f0-9]{5,8})")
finded = "jhgj"
for i , line in enumerate(open(folderT1[0])):
for match in re.finditer(patern, line):
filterString = match.group()
finded = filterString.replace('gVX1000 ','')
return "0x"+finded
objektvx = VXINI("C:\Users\user\Desktop\VX")
objektvx.generator(8)
Как я могу запрограммировать это в python?