obd 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31a5d5e23dc326c83edf645288eb71aed3ae0c6d
4
+ data.tar.gz: 1ace47b48604381ef3f4e44e8a417983f6f44ca4
5
+ SHA512:
6
+ metadata.gz: 4bef32db33dae5d3f96679a7ed4ed079a37d4fde5a5155fbef759e1c9bd642898e4646010ad76d5aefde841a16a7a0ae6f0d604e5c4ea8362e42d827678c2e87
7
+ data.tar.gz: 38d643c4d181a091f2074d50761e557c134f2736e39f377b8c687ab2806ab057b13e7dd614d826f3d49af5f95e819197924e91d3ceeb2e4428828c65623e2189
@@ -0,0 +1,24 @@
1
+ Installation
2
+ ============
3
+ ~~~ text
4
+ gem install obd
5
+ ~~~
6
+
7
+ Usage
8
+ =====
9
+
10
+ Connect your OBD-II adapter and pass its device file to `OBD.connect`:
11
+
12
+ ~~~ ruby
13
+ require 'obd'
14
+
15
+ obd = OBD.connect '/dev/tty.obd'
16
+
17
+ obd[:engine_rpm]
18
+ => "4367.25rpm"
19
+
20
+ # Retrieve error codes
21
+ obd.send("03")
22
+ => "43000545"
23
+ ~~~
24
+
@@ -2,12 +2,12 @@ module OBD
2
2
  class Command
3
3
 
4
4
  def initialize
5
-
5
+
6
6
  end
7
7
 
8
8
  def self.format_result command, result
9
9
  if is_command?(command) && result != "NO DATA"
10
- pids[command.to_sym].call h(result)
10
+ pids[command.to_sym].call h(result), h(result).to_i(16)
11
11
  else
12
12
  result
13
13
  end
@@ -25,26 +25,33 @@ module OBD
25
25
  pids.keys.include? command.to_sym
26
26
  end
27
27
 
28
+ def self.pid
29
+ {
30
+ "atrv" => [:battery_voltage, lambda {|x| x.to_s}],
31
+ "0100" => [:pids_supported_1]
32
+ }
33
+ end
34
+
28
35
  def self.pids
29
- {
30
- pids_supported_1: lambda {|x| x.to_s(2).split('').each_with_index.map{|b,i| pids.keys[i] if b == '1'}},
31
- monitor_status_since_clear: lambda {|x| x.to_s},
32
- freeze_dtc: lambda {|x| x.to_s},
33
- fuel_system_status: lambda {|x| x.to_s},
34
- calculated_engine_load: lambda {|x| "%0.2f" % (x * 100.0 / 255.0) + '%'},
35
- engine_coolent_temperature: lambda {|x| "%0.2f" % (x * 1.8 - 104) + '*F'},
36
- short_term_fuel_trim_bank_1: lambda {|x| "%0.2f" % (x * 0.78125 - 100) + '%'},
37
- long_term_fuel_trim_bank_1: lambda {|x| "%0.2f" % (x * 0.78125 - 100) + '%'},
38
- short_term_fuel_trim_bank_2: lambda {|x| "%0.2f" % (x * 0.78125 - 100) + '%'},
39
- long_term_fuel_trim_bank_2: lambda {|x| "%0.2f" % (x * 0.78125 - 100) + '%'},
40
- fuel_pressure: lambda {|x| "%0.2f" % (x * 3 * 0.145) + 'psi'},
41
- intake_manifold_absolute_pressure: lambda {|x| "%0.2f" % (x * 0.145) + 'psi'},
42
- engine_rpm: lambda {|x| "%0.2f" % (x / 4.0) + 'rpm'},
43
- vehicle_speed: lambda {|x| "%0.2f" % (x * 0.621371192) + 'mph'},
44
- timing_advance: lambda {|x| "%0.2f" % (x / 2.0 - 64) + '*'},
45
- intake_air_temperature: lambda {|x| "%0.2f" % (x * 1.8 - 104) + '*F'},
46
- maf_air_flow_rate: lambda {|x| "%0.2f" % (x / 100.0) + 'grams/sec'},
47
- throttle_position: lambda {|x| "%0.2f" % (x * 100 / 255.0) + '%'},
36
+ {
37
+ pids_supported_1: lambda {|x,d| d.to_s(2).split('').each_with_index.map{|b,i| pids.keys[i] if b == '1'}},
38
+ monitor_status_since_clear: lambda {|x| x},
39
+ freeze_dtc: lambda {|x| x},
40
+ fuel_system_status: lambda {|x| x},
41
+ calculated_engine_load: lambda {|x,d| "%0.2f" % (d * 100.0 / 255.0) + '%'},
42
+ engine_coolent_temperature: lambda {|x,d| "%0.2f" % (d * 1.8 - 104) + '*F'},
43
+ short_term_fuel_trim_bank_1: lambda {|x,d| "%0.2f" % (d * 0.78125 - 100) + '%'},
44
+ long_term_fuel_trim_bank_1: lambda {|x,d| "%0.2f" % (d * 0.78125 - 100) + '%'},
45
+ short_term_fuel_trim_bank_2: lambda {|x,d| "%0.2f" % (d * 0.78125 - 100) + '%'},
46
+ long_term_fuel_trim_bank_2: lambda {|x,d| "%0.2f" % (d * 0.78125 - 100) + '%'},
47
+ fuel_pressure: lambda {|x,d| "%0.2f" % (d * 3 * 0.145) + 'psi'},
48
+ intake_manifold_absolute_pressure: lambda {|x,d| "%0.2f" % (d * 0.145) + 'psi'},
49
+ engine_rpm: lambda {|x,d| "%0.2f" % (d / 4.0) + 'rpm'},
50
+ vehicle_speed: lambda {|x,d| "%0.2f" % (d * 0.621371192) + 'mph'},
51
+ timing_advance: lambda {|x,d| "%0.2f" % (d / 2.0 - 64) + '*'},
52
+ intake_air_temperature: lambda {|x,d| "%0.2f" % (d * 1.8 - 104) + '*F'},
53
+ maf_air_flow_rate: lambda {|x,d| "%0.2f" % (d / 100.0) + 'grams/sec'},
54
+ throttle_position: lambda {|x,d| "%0.2f" % (d * 100 / 255.0) + '%'},
48
55
  commanded_secondary_air_status: lambda {|x| x}, # bit encoded
49
56
  oxygen_sensors_present: lambda {|x| x}, # [A0..A3] == Bank 1,Sensors 1-4.[A4..A7]
50
57
  bank_1_sensor_1_oxygen_sensor_voltage: lambda {|x| x},
@@ -58,14 +65,14 @@ module OBD
58
65
  obd_standards_vehicle_conforms_to: lambda {|x| x}, # bit encoded
59
66
  oxygen_sensors_present_2: lambda {|x| x}, # complicated...
60
67
  aux_input_status: lambda {|x| (x == 1).inspect}, # Power Take Off (PTO) status is active?
61
- run_time_since_engine_start: lambda {|x| x}, # seconds
62
- pids_supported_2: lambda {|x| x.to_s(2).split('').each_with_index.map{|b,i| pids.keys[i+33] if b == '1'}}, # bit encoded
63
- distance_traveled_with_mil_on: lambda {|x| x.to_s + 'km'}
68
+ run_time_since_engine_start: lambda {|x,d| d}, # seconds
69
+ pids_supported_2: lambda {|x,d| d.to_s(2).split('').each_with_index.map{|b,i| pids.keys[i+33] if b == '1'}}, # bit encoded
70
+ distance_traveled_with_mil_on: lambda {|x,d| d.to_s + 'km'}
64
71
  }
65
72
  end
66
73
 
67
74
  def self.h response
68
- response[4..-1].to_i(16)
75
+ response[4..-1]
69
76
  end
70
77
 
71
78
 
@@ -13,7 +13,7 @@ module OBD
13
13
 
14
14
  def connect
15
15
  @serial_port = SerialPort.new @port, @baud # , data_bits: 8, stop_bits: 1, parity: SerialPort::NONE
16
- @serial_port.read_timeout = 5000
16
+ @serial_port.read_timeout = 2000
17
17
  read
18
18
  send("AT E0") # turn echo off
19
19
  send("AT L0") # turn linefeeds off
@@ -24,6 +24,7 @@ module OBD
24
24
 
25
25
  def [] command
26
26
  OBD::Command.format_result(command, send(OBD::Command.to_hex(command)))
27
+ com = OBD::Command.new command
27
28
  end
28
29
 
29
30
  def send data
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeff Peterson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-16 00:00:00.000000000Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: serialport
16
- requirement: &70153807947280 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 1.0.0
19
+ version: '1.3'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70153807947280
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
25
27
  description: A Ruby API that interfaces with ELM327 compatible devices over serial.
26
28
  email: jeff@petersonj.com
27
29
  executables: []
@@ -35,26 +37,25 @@ files:
35
37
  - lib/obd/response.rb
36
38
  homepage: http://petersonj.com/obd
37
39
  licenses: []
40
+ metadata: {}
38
41
  post_install_message:
39
42
  rdoc_options: []
40
43
  require_paths:
41
44
  - lib
42
45
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
46
  requirements:
45
- - - ! '>='
47
+ - - '>='
46
48
  - !ruby/object:Gem::Version
47
49
  version: '0'
48
50
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
51
  requirements:
51
- - - ! '>='
52
+ - - '>='
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  requirements: []
55
56
  rubyforge_project:
56
- rubygems_version: 1.8.13
57
+ rubygems_version: 2.0.14
57
58
  signing_key:
58
- specification_version: 3
59
+ specification_version: 4
59
60
  summary: A Ruby OBD-II API
60
61
  test_files: []