Skip to content

Commit

Permalink
Start work on PassThruStartMsgFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Hahn committed Oct 25, 2016
1 parent 10fdf55 commit 0d171ea
Show file tree
Hide file tree
Showing 20 changed files with 499 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SRC_FILES += $(ECUTOOLS_SRC_FILES)
#LOG_FLAGS += -DIOT_WARN
#LOG_FLAGS += -DIOT_ERROR

COMPILER_FLAGS = -g3
COMPILER_FLAGS = -g3 -w
COMPILER_FLAGS += $(LOG_FLAGS)

# ecutools
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Dynamic libraries (not included):

To install,

./autogen.sh
./configure
./autogen.sh
./configure
make mbedtls
make
sudo make install
make
sudo make install

## Development

Expand Down
63 changes: 58 additions & 5 deletions bindings/ruby/lib/ecutools/j2534.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def PassThruOpen(name, deviceId)
pDeviceId = FFI::MemoryPointer.new(:ulong, 8).put_ulong(0, deviceId)
response = Libj2534.PassThruOpen(pName, pDeviceId)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
true
response
end

def PassThruClose(deviceId)
response = Libj2534.PassThruClose(deviceId)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
true
response
end

def PassThruConnect(deviceId, protocolId, flags, baudRate, resource, channelId)
Expand All @@ -68,13 +68,13 @@ def PassThruConnect(deviceId, protocolId, flags, baudRate, resource, channelId)
pChannelID = FFI::MemoryPointer.new(:ulong, 8).put_ulong(0, channelId)
response = Libj2534.PassThruConnect(deviceId, protocolId, flags, baudRate, resourceStruct, pChannelID)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
true
response
end

def PassThruDisconnect(channelId)
response = Libj2534.PassThruDisconnect(channelId)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
true
response
end

def PassThruLogicalConnect(physicalChannelId, protocolId, flags, channelDescriptor, channelId)
Expand All @@ -92,7 +92,47 @@ def PassThruSelect(channelSet, selectType, timeout)
).put_array_of_ulong(0, channelSet.ChannelList)
response = Libj2534.PassThruSelect(channelset, selectType, timeout)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
true
response
end

def PassThruReadMsgs(channelId, message, numMsgs, timeout)
end

def PassThruQueueMsgs(channelId, message, numMsgs)
end

def PassThruStartPeriodicMsg(channelId, message, messageId, timeInterval)
end

def PassThruStopPeriodicMsg(channelId, messageId)
end

# long PassThruStartMsgFilter(unsigned long ChannelID, unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg, unsigned long *pFilterID);

# attach_function :PassThruStartMsgFilter, [ :ulong, :ulong, Ecutools::J2534::Structs::PASSTHRU_MSG.by_ref, Ecutools::J2534::Structs::PASSTHRU_MSG.by_ref, :pointer ], :long

def PassThruStartMsgFilter(channelId, filterType, maskMsg, patternMsg, filterId)
pMaskMsg = map_model_to_passthru_msg(maskMsg, Ecutools::J2534::Structs::PASSTHRU_MSG.new)
pPatternMsg = map_model_to_passthru_msg(patternMsg, Ecutools::J2534::Structs::PASSTHRU_MSG.new)
pFilterID = FFI::MemoryPointer.new(:ulong, 8).put_ulong(0, filterId)
response = Libj2534.PassThruStartMsgFilter(channelId, filterType, pMaskMsg, pPatternMsg, pFilterID)
raise Ecutools::J2534Error, Error[response] unless response === STATUS_NOERROR
response
end

def PassThruStopMsgFilter(channelId, filterId)
end

def PassThruSetProgrammingVoltage(deviceId, resourceStruct, voltage)
end

def PassThruReadVersion(deviceId)
end

def PassThruGetLastError
end

def PassThruIoctl(controlTarget, ioctlId)
end

private
Expand All @@ -108,5 +148,18 @@ def map_sdevice_to_model(sdevice, device)
device
end

def map_model_to_passthru_msg(model, passthru_msg)
passthru_msg[:ProtocolID] = model.ProtocolID || 0
passthru_msg[:MsgHandle] = model.MsgHandle
passthru_msg[:RxStatus] = model.RxStatus || 0
passthru_msg[:TxFlags] = model.TxFlags || 0
passthru_msg[:Timestamp] = model.Timestamp || 0
passthru_msg[:DataLength] = model.DataLength
passthru_msg[:ExtraDataIndex] = model.ExtraDataIndex || 0
passthru_msg[:DataBuffer] = model.DataBuffer
passthru_msg[:DataBufferSize] = model.DataBufferSize || 0
passthru_msg
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@

it 'returns STATUS_NOERROR when connected' do
things.test_with_ecutuned {
expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)
expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(Ecutools::J2534::Error::STATUS_NOERROR)
resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)
expect(j2534.PassThruConnect(
1,
Ecutools::J2534::CAN,
Ecutools::J2534::CAN_ID_BOTH,
500000,
resource,
1
)).to eq(Ecutools::J2534::Error::STATUS_NOERROR)
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
it 'returns STATUS_NOERROR when disconnected' do
things.test_with_ecutuned {

expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)
expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(Ecutools::J2534::Error::STATUS_NOERROR)

resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)

expect(j2534.PassThruDisconnect(1)).to eq(true)
expect(j2534.PassThruConnect(
1,
Ecutools::J2534::CAN,
Ecutools::J2534::CAN_ID_BOTH, 500000,
resource,
1
)).to eq(Ecutools::J2534::Error::STATUS_NOERROR)

expect(j2534.PassThruDisconnect(1)).to eq(Ecutools::J2534::Error::STATUS_NOERROR)
}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
##
# ecutools: IoT Automotive Tuning, Diagnostics & Analytics
# Copyright (C) 2014 Jeremy Hahn
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'spec_helper'

describe Ecutools::J2534 do
include_context 'J2534' do
context 'PassThruSelect' do

it 'returns ERR_EXCEEDED_LIMIT when more than 10 filters are specified' do
things.test_with_ecutuned {

expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)

resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)

maskMsg = Ecutools::J2534::Models::Message.new
maskMsg.ProtocolID = Ecutools::J2534::CAN
maskMsg.MsgHandle = 1
maskMsg.DataBuffer = 0x7FF
maskMsg.DataLength = 11

patternMsg = Ecutools::J2534::Models::Message.new
patternMsg.ProtocolID = Ecutools::J2534::CAN
patternMsg.MsgHandle = 2
patternMsg.DataBuffer = 0x7DF
patternMsg.DataLength = 11

i = 0
10.times do
i = i + 1
expect(j2534.PassThruStartMsgFilter(i, Ecutools::J2534::PASS_FILTER, maskMsg, patternMsg, 1)).to eq(true)
end
expect{j2534.PassThruStartMsgFilter(11, Ecutools::J2534::PASS_FILTER, maskMsg, patternMsg, 1)}.to raise_error /ERR_EXCEEDED_LIMIT/
}
end

end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##
# ecutools: IoT Automotive Tuning, Diagnostics & Analytics
# Copyright (C) 2014 Jeremy Hahn
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'spec_helper'

describe Ecutools::J2534 do
include_context 'J2534' do
context 'PassThruSelect' do

it 'returns ERR_FILTER_TYPE_NOT_SUPPORTED when an invalid filter is specified' do
things.test_with_ecutuned {

expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)

resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)

maskMsg = Ecutools::J2534::Models::Message.new
maskMsg.ProtocolID = Ecutools::J2534::CAN
maskMsg.MsgHandle = 1
maskMsg.DataBuffer = 0x7FF
maskMsg.DataLength = 11

patternMsg = Ecutools::J2534::Models::Message.new
patternMsg.ProtocolID = Ecutools::J2534::CAN
patternMsg.MsgHandle = 2
patternMsg.DataBuffer = 0x7DF
patternMsg.DataLength = 11

expect{j2534.PassThruStartMsgFilter(1, 1, maskMsg, patternMsg, 1)}.to raise_error /ERR_FILTER_TYPE_NOT_SUPPORTED/
}
end

end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##
# ecutools: IoT Automotive Tuning, Diagnostics & Analytics
# Copyright (C) 2014 Jeremy Hahn
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'spec_helper'

describe Ecutools::J2534 do
include_context 'J2534' do
context 'PassThruSelect' do

it 'returns ERR_INVALID_MSG when an invalid data length is specified' do
things.test_with_ecutuned {

expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)

resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)

maskMsg = Ecutools::J2534::Models::Message.new
maskMsg.ProtocolID = Ecutools::J2534::CAN
maskMsg.MsgHandle = 1
maskMsg.DataBuffer = 0x7FF
maskMsg.DataLength = 13

patternMsg = Ecutools::J2534::Models::Message.new
patternMsg.ProtocolID = Ecutools::J2534::CAN
patternMsg.MsgHandle = 2
patternMsg.DataBuffer = 0x7DF
patternMsg.DataLength = 13

expect{j2534.PassThruStartMsgFilter(1, Ecutools::J2534::PASS_FILTER, maskMsg, patternMsg, 1)}.to raise_error /ERR_INVALID_MSG/
}
end

end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##
# ecutools: IoT Automotive Tuning, Diagnostics & Analytics
# Copyright (C) 2014 Jeremy Hahn
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'spec_helper'

describe Ecutools::J2534 do
include_context 'J2534' do
context 'PassThruSelect' do

it 'returns ERR_MSG_PROTOCOL_ID when an invalid protocol id is specified' do
things.test_with_ecutuned {

expect(j2534.PassThruOpen(things[0][:name], 1)).to eq(true)

resource = Ecutools::J2534::Models::Resource.new
resource.Connector = Ecutools::J2534::J1962_CONNECTOR
expect(j2534.PassThruConnect(1, Ecutools::J2534::CAN, Ecutools::J2534::CAN_ID_BOTH, 500000, resource, 1)).to eq(true)

maskMsg = Ecutools::J2534::Models::Message.new
maskMsg.ProtocolID = 0
maskMsg.MsgHandle = 1
maskMsg.DataBuffer = 0x7FF
maskMsg.DataLength = 11

patternMsg = Ecutools::J2534::Models::Message.new
patternMsg.ProtocolID = 0
patternMsg.MsgHandle = 2
patternMsg.DataBuffer = 0x7DF
patternMsg.DataLength = 11

expect{j2534.PassThruStartMsgFilter(1, Ecutools::J2534::PASS_FILTER, maskMsg, patternMsg, 1)}.to raise_error /ERR_MSG_PROTOCOL_ID/
}
end

end

end

end
Loading

0 comments on commit 0d171ea

Please sign in to comment.