# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
import sys
import os, os.path
if len(sys.argv) != 2:
print("Syntax = " + sys.argv[0] + " nom_du_fichier_log_sans_point_log")
exit(1)
logdir = os.path.dirname(sys.argv[1])
logname = os.path.basename(sys.argv[1])
if logdir == '':
dirlog = logname
else:
dirlog = logdir + '/' + logname
#logfile = "../../logs/2011-06-24_1.log"
#logfile = "../../logs/2011-06-24_2.log"
print('hello1')
codes={\
'002':(4,'?'),
'020':(3,'?'),
'022':(8,'Lateral acceleration'),
'023':(7,'Forward acceleration'),
'025':(8,'Steering position'),
'030':(8,'Brake pedal pressure'),
'038':(7,'? ICE RPM'),
'039':(4,'? Temp'),
'03A':(7,'? Gas torque'),
'03B':(5,'Electric motor current/voltage'),
'03E':(3,'Gear rotation ?'),
'060':(7,''),
'087':(8,''),
'0B0':(3,''),
'0B1':(6,'Front wheel rotation'),
'0B3':(6,'Rear wheel rotation'),
'0B4':(8,'Speed'),
'0C9':(5,'? ABS'),
'120':(8,'Drive mode'),
'230':(7,'counter ?'),
'244':(8,'Gas Pedal/Speed'),
'262':(4,'?'),
'348':(6,'ICE'),
'34F':(5,''),
'3C8':(6,'RPM'),
'3C9':(8,'? date'),
'3CA':(5,'Speed'),
'3CB':(7,'Battery Max discharge/charge,state,temperature'),
'3CD':(5,'Battery Fault code'),
'3CF':(5,'? ICE'),
'423':(1,'? const'),
'484':(5,'????'),
'4C1':(8,'? const'),
'4C3':(8,'? const'),
'4C6':(8,'? const'),
'4C7':(8,'? const'),
'4C8':(8,'? const'),
'4CE':(8,'? const'),
'4D0':(8,'? HECU -> Batt [16, 0, 2, 3, 0, 0, 0, 0])'),
'4D1':(8,'? Batt -> HECU [17, 0, 1, 2, 0, 0, 0, 0])'),
'520':(3,'Fuel injector'),
'521':(2,'? const'),
'526':(3,'Timing'),
'527':(3,'? const'),
'528':(4,'? const'),
'529':(7,'EV Mode'),
'52C':(2,'Engine temperature [35, 49] ... [35, 168]'),
'53F':(5,'-???'),
'540':(4,'Shift lever'),
'553':(7,'? const'),
'554':(7,'? const'),
'56D':(4,'? EV'),
'57F':(7,'Lights'),
'591':(4,'???'),
'5A4':(2,'Gas gauge [99, 38] ... [99, 36]'),
'5B2':(4,'? const [37, 0, 4, 0]'),
'5B6':(3,'Open doors [100, 193, 0] [228, 193, 128] [100, 193, 128] [228, 193, 0]) [100, 193, 0]'),
'5C8':(3,'Cruise [36, 0, 0] [164, 0, 16] [36, 0, 16] [164, 0, 0] [36, 0, 0]'),
'5CC':(3,'? const [36, 1, 176]'),
'5D4':(2,'? const [35, 0]'),
'5EC':(7,'? const [40, 0, 0, 0, 0, 36, 58]'),
'5ED':(6,'? const [103, 8, 0, 255, 0, 0]'),
'5F8':(2,'? const [35, 0]'),
'602':(2,'? const [35, 0]')}
not_good = {}
def with_checksum(ts, k, c, il, data):
cdata = map(lambda x: int(x,16), data[0:-1])
adata = np.array(cdata, np.uint8)
if adata.size != codes[k][0] - 1:
print("Mauvaise taille ligne " + str(il) + ": \"" + l[0:-2] + "\"")
return
c = reduce(lambda x,y:x+y,cdata,c)
if c % 256 != 0:
print("Erreur de checksum ligne " + str(il) + ": \"" + l[0:-2] + "\"")
return
iframe = fts.tell() // 8
np.array(ts).tofile(fts)
fk = df[k]
np.array(iframe, np.int32).tofile(fk)
adata.tofile(fk)
def without_checksum(ts, k, il, data):
cdata = map(lambda x: int(x,16), data)
adata = np.array(cdata, np.uint8)
if adata.size != codes[k][0]:
print("Mauvaise taille ligne " + str(il) + ": \"" + l[0:-2] + "\"")
return
iframe = fts.tell() // 8
np.array(ts).tofile(fts)
fk = df[k]
np.array(iframe, np.int32).tofile(fk)
adata.tofile(fk)
def work_on_line(il, l):
if l.find('\x00') >= 0: # Erreurs rares à signaler et corriger
print("\\x00 dans la ligne " + str(il) + ": \"" + l[0:-1] + "\"")
l = l.replace('\x00','')
[l0,l1] = l.split(":")[-2:]
if (l1[-2:] != ' \n'): # Erreur
print("mauvaise terminaison de la ligne " + str(il) + ": \"" + l[0:-1] + "\"")
return
try:
h0 = int(l1[0],16)
h1 = int(l1[1:3],16)
data = l1[4:-2].split(' ')
ts = float(l0)
if (h0 > 3) or (h0 == 0 and h1 == 32):
without_checksum(ts, l1[0:3], il, data)
else:
with_checksum(ts, l1[0:3], h0 + h1 + len(data) - int(data[-1],16), il, data)
except Exception,e:
print("Exception " + str(e) + " for \"" + l[0:-2] + "\"")
f = open(dirlog + '.log',"r")
if not os.path.exists(dirlog):
os.mkdir(dirlog)
df = {}
for k in codes:
df[k] = open(dirlog + '/' + k, 'w')
fts = open(dirlog + '/timestamps', 'w')
il = 0
while True:
l = f.readline()
il+=1
if il % 100000 == 0:
print(il)
if len(l) == 0: # EOF
break
try:
work_on_line(il, l)
except Exception:
not_good[il] = "Exception: \"" + l + "\""
print str(il) + " is not good: \"" + l + "\""
#
f.close()
fts.close()
for k in df.keys():
df[k].close()
print('done')