From 04f780ae54261a331eaf10cccebdbd8d8baa0ba0 Mon Sep 17 00:00:00 2001 From: shrlnm Date: Thu, 9 May 2019 13:13:35 +0300 Subject: [PATCH] 9p add convert_db --- pyren/convert_db.py | 80 +++++++++++++++++++++++++++++++++++++++++++++ pyren/mod_elm.py | 35 +++++++++++--------- 2 files changed, 100 insertions(+), 15 deletions(-) create mode 100755 pyren/convert_db.py diff --git a/pyren/convert_db.py b/pyren/convert_db.py new file mode 100755 index 0000000..432878a --- /dev/null +++ b/pyren/convert_db.py @@ -0,0 +1,80 @@ +#!/usr/bin/python + +import glob +import os +import pickle +import sys +import zipfile +from StringIO import StringIO + +from mod_optfile import * + +if __name__ == "__main__": + zipoutput = StringIO () + + if len (sys.argv) < 2: + print "Usage : convert_db.py [path/to/GenAppli]" + exit () + + inputpath = sys.argv[1] + ecudir = os.path.join (inputpath, "EcuRenault") + vehicledir = os.path.join (inputpath, "Vehicles") + locationdir = os.path.join (inputpath, "Location") + + ecufiles = glob.glob (os.path.join (ecudir, "*.xml")) + fbsessionfiles = glob.glob (os.path.join (ecudir, "Sessions", "FB*.xml")) + fbsessionfiles += glob.glob (os.path.join (ecudir, "Sessions", "FG*.xml")) + fgsessionfiles = glob.glob (os.path.join (ecudir, "Sessions", "SG*.xml")) + vehiclesfiles = glob.glob (os.path.join (vehicledir, "*.xml")) + locationsfiles = glob.glob (os.path.join (locationdir, "*.bqm")) + scnerariosfiles = glob.glob (os.path.join (ecudir, "Scenarios", "*.xml")) + + with zipfile.ZipFile (zipoutput, mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=True) as zf: + for vf in scnerariosfiles: + print "Processing file ", vf + f = open (vf, "r") + data = f.read () + zf.writestr (os.path.join ("EcuRenault", "Scenarios", os.path.basename (vf)), str (data)) + + for vf in vehiclesfiles: + print "Processing file ", vf + f = open (vf, "r") + data = f.read () + zf.writestr (os.path.join ("Vehicles", os.path.basename (vf)), str (data)) + + for vf in ecufiles: + print "Processing file ", vf + f = open (vf, "r") + data = f.read () + zf.writestr (os.path.join ("EcuRenault", os.path.basename (vf)), str (data)) + + for vf in fbsessionfiles: + print "Processing file ", vf + f = open (vf, "r") + data = f.read () + zf.writestr (os.path.join ("EcuRenault", "Sessions", os.path.basename (vf)), str (data)) + + for vf in locationsfiles: + print "Processing file ", vf + try: + optf = optfile (vf) + except: + print "Skipping file ", vf + continue + data = pickle.dumps (optf.dict) + zf.writestr (os.path.join ("Location", + os.path.basename (vf).replace (".bqm", ".p")), str (data)) + + for vf in fgsessionfiles: + print "Processing file ", vf + try: + optf = optfile (vf) + except: + print "Skipping file ", vf + continue + data = pickle.dumps (optf.dict) + zf.writestr (os.path.join ("EcuRenault", "Sessions", + os.path.basename (vf).replace ("FG", "UG").replace (".xml", ".p")), str (data)) + + with open ("pyrendata.zip", "wb") as zf: + zf.write (zipoutput.getvalue ()) diff --git a/pyren/mod_elm.py b/pyren/mod_elm.py index f4a4d73..0599609 100755 --- a/pyren/mod_elm.py +++ b/pyren/mod_elm.py @@ -142,7 +142,7 @@ class Port: kaLock = False rwLock = False lastReadTime = 0 - ka_timer = None + #ka_timer = None atKeepAlive = 2 # period of sending AT during inactivity @@ -153,14 +153,18 @@ class Port: portName = portName.strip () if re.match (r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}$", portName): - self.ipaddr, self.tcpprt = portName.split (':') - self.tcpprt = int (self.tcpprt) - self.portType = 1 - self.hdr = socket.socket (socket.AF_INET, socket.SOCK_STREAM) - self.hdr.setsockopt (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - self.hdr.settimeout(3) - self.hdr.connect ((self.ipaddr, self.tcpprt)) - self.hdr.setblocking (True) + try: + self.ipaddr, self.tcpprt = portName.split (':') + self.tcpprt = int (self.tcpprt) + self.portType = 1 + self.hdr = socket.socket (socket.AF_INET, socket.SOCK_STREAM) + self.hdr.setsockopt (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + self.hdr.settimeout(3) + self.hdr.connect ((self.ipaddr, self.tcpprt)) + self.hdr.setblocking (True) + except: + print " \n\nERROR: Can not connect to WiFi ELM\n\n" + pass elif mod_globals.os == 'android' and portName == 'bt': self.portType = 2 self.droid = android.Android () @@ -195,8 +199,9 @@ class Port: #self.elm_at_KeepAlive () def __del__(self): - if self.ka_timer: - self.ka_timer.cancel () + pass + #if self.ka_timer: + # self.ka_timer.cancel () def reinit(self): ''' @@ -376,8 +381,8 @@ class Port: # stop any read/write self.rwLock = False self.kaLock = False - if self.ka_timer: - self.ka_timer.cancel () + #if self.ka_timer: + # self.ka_timer.cancel () print "Changing baud rate to:", boudrate, @@ -567,8 +572,8 @@ class ELM: if not mod_globals.opt_demo: print '*' * 40 print '* RESETTING ELM' - if self.port.ka_timer: - self.port.ka_timer.cancel () + #if self.port.ka_timer: + # self.port.ka_timer.cancel () self.port.write ("atz\r") self.port.atKeepAlive = 0 if self.run_allow_event: