-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremy Hahn
committed
May 1, 2016
1 parent
7124f3e
commit d666d3f
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'ffi' | ||
require 'pp' | ||
|
||
class EcutoolsError < StandardError; end | ||
|
||
module Ecutools; end | ||
|
||
module Ecutools::J2534 | ||
extend FFI::Library | ||
ffi_lib 'c' | ||
#ffi_lib '/usr/local/lib/libj2534.so' | ||
ffi_lib '../../.libs/libj2534.so' | ||
attach_function :PassThruScanForDevices, [ :pointer ], :long | ||
attach_function :PassThruOpen, [ :pointer, :pointer ], :long | ||
end | ||
|
||
module Ecutools | ||
|
||
class Api | ||
|
||
def PassThruScanForDevices | ||
pDeviceCount = FFI::MemoryPointer.new(:ulong, 1) | ||
raise 'PassThruScanForDevices error' if Ecutools::J2534.PassThruScanForDevices(pDeviceCount) != 0 | ||
pDeviceCount.read_ulong | ||
end | ||
|
||
def PassThruOpen(name, deviceId) | ||
pName = FFI::MemoryPointer.from_string(name) | ||
pDeviceId = FFI::MemoryPointer.new(:ulong, 1) | ||
rc = Ecutools::J2534.PassThruOpen(pName, pDeviceId) | ||
raise EcutoolsError, "PassThruOpen: error=#{rc}" unless rc == 0 | ||
rc | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
describe Ecutools::Api do | ||
|
||
let(:ecutools) { Ecutools::Api.new } | ||
let(:deviceName) { "J2534-1:ecutools"} | ||
let(:deviceId) { 420 } | ||
|
||
it 'PassThruScanForDevices returns 1 device' do | ||
expect(ecutools.PassThruScanForDevices).to eq(1) | ||
end | ||
|
||
it 'PassThruOpen returns success when it finds VirtualDataLogger' do | ||
expect(ecutools.PassThruOpen("VirtualDataLogger", deviceId)).to eq(0) | ||
end | ||
|
||
it 'PassThruOpen throws EcutoolsError when it doesnt find the requested device' do | ||
expect { ecutools.PassThruOpen(deviceName, deviceId) }.to raise_error EcutoolsError | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
require 'ecutools' |