Fixing bugs
authorPaul Robinson <darkraver@gmail.com>
Sun, 16 Dec 2012 16:20:05 +0000 (16:20 +0000)
committerPaul Robinson <darkraver@gmail.com>
Sun, 16 Dec 2012 16:20:05 +0000 (16:20 +0000)
obd_io.py
obd_recorder.py
obd_sensors.py

index ed2fa1f..79413af 100644 (file)
--- a/obd_io.py
+++ b/obd_io.py
@@ -26,6 +26,7 @@ import serial
 import string
 import time
 from math import ceil
+from datetime import datetime
 
 import obd_sensors
 
@@ -171,7 +172,7 @@ class OBDPort:
     
      def get_result(self):
          """Internal use only: not a public interface"""
-         time.sleep(0.01)
+         #time.sleep(0.01)
          repeat_count = 0
          if self.port is not None:
              buffer = ""
@@ -180,6 +181,7 @@ class OBDPort:
                  if len(c) == 0:
                     if(repeat_count == 5):
                         break
+                    print "Got nothing\n"
                     repeat_count = repeat_count + 1
                     continue
                     
@@ -213,6 +215,7 @@ class OBDPort:
                  data = sensor.value(data)
          else:
              return "NORESPONSE"
+             
          return data
 
      # return string of sensor name and value from sensor index
index 863150c..9f0691c 100755 (executable)
@@ -4,7 +4,7 @@ import obd_io
 import serial
 import platform
 import obd_sensors
-import datetime
+from datetime import datetime
 import time
 
 from obd_utils import scanSerial
@@ -16,7 +16,7 @@ class OBD_Recorder():
         localtime = time.localtime(time.time())
         filename = path+"bike-"+str(localtime[0])+"-"+str(localtime[1])+"-"+str(localtime[2])+"-"+str(localtime[3])+"-"+str(localtime[4])+"-"+str(localtime[5])+".log"
         self.log_file = open(filename, "w", 128)
-        self.log_file.write("Time,RPM,MPH,Throttle,Gear");
+        self.log_file.write("Time,RPM,MPH,Throttle,Load,Gear\n");
 
         for item in log_items:
             self.add_log_item(item)
@@ -60,7 +60,7 @@ class OBD_Recorder():
             localtime = datetime.now()
             current_time = str(localtime.hour)+":"+str(localtime.minute)+":"+str(localtime.second)+"."+str(localtime.microsecond)
             log_string = current_time
-
+            results = {}
             for index in self.sensorlist:
                 (name, value, unit) = self.port.sensor(index)
                 log_string = log_string + ","+str(value)
@@ -68,7 +68,7 @@ class OBD_Recorder():
 
             gear = self.calculate_gear(results["rpm"], results["speed"])
             log_string = log_string + "," + str(gear)
-            self.log_file.write(log_string)
+            self.log_file.write(log_string+"\n")
             
     def calculate_gear(self, rpm, speed):
         if speed == "" or speed == 0:
@@ -85,6 +85,8 @@ class OBD_Recorder():
         tyre_circumference = 1.978 #meters
 
         current_gear_ratio = (rps*tyre_circumference)/(mps*primary_gear*final_drive)
+        
+        print current_gear_ratio
         gear = min((abs(current_gear_ratio - i), i) for i in self.gear_ratios)[1] 
         return gear
             
index ebf323b..59b5832 100644 (file)
@@ -138,7 +138,7 @@ SENSORS = [
     Sensor("dtc_status"            , "Status Since DTC Cleared", "0101", dtc_decrypt      ,""       ),    
     Sensor("dtc_ff"                , "DTC Causing Freeze Frame", "0102", cpass            ,""       ),    
     Sensor("fuel_status"           , "      Fuel System Status", "0103", cpass            ,""       ),
-    Sensor("load"                  , "   Calculated Load Value", "0104", percent_scale    ,""       ),    
+    Sensor("load"                  , "   Calculated Load Value", "01041", percent_scale    ,""       ),    
     Sensor("temp"                  , "     Coolant Temperature", "0105", temp             ,"C"      ),
     Sensor("short_term_fuel_trim_1", "    Short Term Fuel Trim", "0106", fuel_trim_percent,"%"      ),
     Sensor("long_term_fuel_trim_1" , "     Long Term Fuel Trim", "0107", fuel_trim_percent,"%"      ),