aus der Not heraus habe ich auf die Schnelle einen Converter für ASCII-Logdateien geschrieben. Es sind Cancorder CAN-Trace Logs, die in was für Canape Lesbares gewandelt werden.
Eine zu konvertierende Datei sieht so aus:
Eine konvertierte Datei sieht so aus:// Tracefile imported from CANCorder device on
// Mon Aug 27 14:15:15 2007
// Tracerecord from blue PiraT data logger
// Number of records : 245626
// Trace duration : 0:04:00
// Started trace at : Tue Aug 21 12:03:43 2007
// Stopped trace at : Tue Aug 21 12:07:43 2007
00:00:00.029.0 CAN2 Rx ---- Pre ce 51 04 54 04 4e 04 4e 04
00:00:00.029.3 CAN2 Rx ---- Pre 128 6e 35 e0 e0 00 c7 7e ff
00:00:00.029.5 CAN2 Rx ---- Pre c9 de ff 10 00 90 1c 4b 12
00:00:00.031.3 CAN2 Rx ---- Pre 118 00 80 17 00 80 fa ff 0e
00:00:00.031.6 CAN2 Rx ---- Pre 11f 08 01 00 00 d7 ff 44 69
00:00:00.032.5 CAN2 Rx ---- Pre 80 00 00 c4 ed 00
Also nichts Wildes an sich. Die einzelnen Reihen sind vertauscht, der Zeitstempel ist anders aufgebaut.date Tue Aug 21 12:03:43 2007
base hex timestamps absolute
0.0000 2 ce Rx d 8 51 04 54 04 4e 04 4e 04
0.0003 2 128 Rx d 8 6e 35 e0 e0 00 c7 7e ff
0.0005 2 c9 Rx d 8 de ff 10 00 90 1c 4b 12
0.0023 2 118 Rx d 8 00 80 17 00 80 fa ff 0e
0.0026 2 11f Rx d 8 08 01 00 00 d7 ff 44 69
0.0035 2 80 Rx d 5 00 00 c4 ed 00
Mein Programm funktioniert auch, nur beim Ausführen lastet es einen CPU-Lern voll aus (C2D, 2GB Ram, WinXP). Ich kann nicht ganz nachvollziehen, was daran soviel Rechenzeit frisst.
Ich habe Windows in Verdacht, bin mir aber nicht sicher, ob es evtl. an meinem Programm liegt. Könnt ihr mal bitte mal drüber schauen?
Code: Alles auswählen
import csv
import sys
from os import path
if len(sys.argv) == 2:
infile_name = sys.argv[1]
tmp = path.splitext(infile_name)
outfile_name = ''.join([tmp[0],'_conv',tmp[1]])
else:
print "Aufruf: converter [Trace-Datei]"
sys.exit()
flag_1 = True
out_str = str()
output = open(outfile_name,'w')
lines = csv.reader(open(infile_name, "r"),delimiter=' ', skipinitialspace = True)
for line in lines:
if '//' in line[0]:
if 'Started' in line[1]:
date = '%s %s %s %s %s %s' % ('date',line[5],line[6],line[7],line[8],line[9])
elif line[0]:
try:
tmp = line[0].split(':')
tmp1 = tmp[2].split('.')
hour = int(tmp[0]) * 3600
min = int(tmp[1]) * 60
sec = int(tmp1[0])
msec = float(''.join(['0.',tmp1[1],tmp1[2]]))
if flag_1:
flag_1 = False
output.write(date+'\n')
output.write('base hex timestamps absolute\n')
offset = hour + min + sec + msec
timestamp = '%.4f' % (hour+min+sec+msec-offset)
can_num = line[1][-1:]
can_id = line[5].rjust(3)
direction = line[2]
unknown1 = 'd'
data_len = len(line[6:])
data = ' '.join(line[6:])
output.write('%s %s %s %s %s %s %s\n' % (timestamp, can_num, can_id, direction, unknown1, data_len, data))
except:
output.write(''.join(line))
output.close()