ruby_can 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34917f037360fc7facd58f677a301b0e9200247e
4
+ data.tar.gz: e6efea3519074cf3446274797ace18d943ece679
5
+ SHA512:
6
+ metadata.gz: 14ddcbefc3a915a5032277c0f6052eddfce91334bcf10f288a08a73b0456ce7231d663550468d38c0ef7476bc76c86b2de26ef29642c25732dc0056faac6ce04
7
+ data.tar.gz: 7643f41d962e799dcc28d49deaafa80bc0c7aea77148452019fb889c006d7a240779718c4ae0331062375295aa09fc6138ce531be10245dcece946489a9e2e78
@@ -0,0 +1,17 @@
1
+ .vagrant/
2
+ Gemfile.lock
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_can.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ As an example, to start listening on vcan0 do the following
2
+
3
+ 1. git clone https://github.com/tomekr/ruby-can.git
4
+ 1. cd ruby-can/
5
+ 1. bundle install
6
+ 1. ruby lib/ruby_can.rb
7
+
8
+ Gem Setup
9
+ ---
10
+ `gem build ruby_can.gemspec`
11
+ `gem install ruby_can-0.0.1.gem`
12
+
13
+
14
+ Cucumber Tests
15
+ ---
16
+ bundle exec cucumber
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new(:features) do |t|
6
+ t.cucumber_opts = "--format pretty" # Any valid command line option can go here.
7
+ end
@@ -0,0 +1,13 @@
1
+ Vagrant.configure(2) do |config|
2
+ config.vm.box = "puphpet/ubuntu1404-x64"
3
+
4
+ config.ssh.forward_agent = true
5
+
6
+ config.vm.provider "virtualbox" do |vb|
7
+ # # Customize the amount of memory on the VM:
8
+ vb.memory = "1024"
9
+ end
10
+
11
+ config.vm.provision :shell, :path => "vagrant_scripts/bootstrap.sh"
12
+ config.vm.provision :shell, :path => "vagrant_scripts/install-rvm.sh"
13
+ end
@@ -0,0 +1,10 @@
1
+ Feature: Raw CAN Access for reading and writing CAN Packets
2
+ I want to be able to read raw CAN packets as well as write
3
+ to CAN devices. I want to be able to setup listeners and
4
+ handle ISO-TP style packets.
5
+
6
+ Scenario: See CAN traffic
7
+ Given A steady stream of CAN traffic is on "vcan0" with ID of "312" and data of "010203" is on the network
8
+ When I create a listening socket on "vcan0"
9
+ Then I should see a packet with ID of "312" with a size of 3 and data of "010203"
10
+ And the stream stops
@@ -0,0 +1,22 @@
1
+ Given(/^A steady stream of CAN traffic is on "([^"]*)" with ID of "([^"]*)" and data of "([^"]*)" is on the network$/) do |dev, id, data|
2
+ ifup = false
3
+ playing_data = false
4
+ ifup = true if File.exists? "/sys/class/net/#{dev}"
5
+ playing_data = system "cangen #{dev} -I #{id} -L #{data.size / 2} -D #{data} &"
6
+ ifup and playing_data
7
+ end
8
+
9
+ When(/^I create a listening socket on "([^"]*)"$/) do |dev|
10
+ @socket = RubyCan::CanSocket.new( dev )
11
+ not @socket == nil
12
+ end
13
+
14
+ Then(/^I should see a packet with ID of "([^"]*)" with a size of (\d+) and data of "([^"]*)"$/) do |id, dlc, data|
15
+ can_packet = RubyCan::CanPacket.read(@socket.read(16))
16
+ can_packet.can_id == id and can_packet.can_dlc == dlc and can_packet.data.to_s == data
17
+ end
18
+
19
+ Then(/^the stream stops$/) do
20
+ system "killall cangen"
21
+ end
22
+
@@ -0,0 +1,15 @@
1
+ require "ruby_can"
2
+
3
+ #ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ #LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ # @original_rubylib = ENV['RUBYLIB']
10
+ # ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ # ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'socket'
2
+ require 'ruby_can/version'
3
+ require 'ruby_can/can_socket'
4
+ require 'ruby_can/can_packet'
5
+
6
+ module RubyCan
7
+
8
+ end
@@ -0,0 +1,16 @@
1
+ require 'bindata'
2
+
3
+ module RubyCan
4
+ class CanPacket < BinData::Record
5
+ endian :little
6
+
7
+ uint32 :can_id
8
+ uint8 :can_dlc
9
+
10
+ # The data section is byte aligned so we have 3 bytes here that are not
11
+ # used.
12
+ uint8 :unused, :length => 3
13
+
14
+ array :data, :type => :uint8, :initial_length => :can_dlc
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ # CREDIT: Bart Duchesne
2
+ # https://github.com/bduc/raspcan/blob/master/raspcan_test.rb
3
+ module RubyCan
4
+ class CanSocket < Socket
5
+
6
+ PF_CAN=29
7
+ AF_CAN=PF_CAN
8
+ CAN_RAW=1
9
+ SIOCGIFINDEX=0x8933
10
+
11
+ def initialize( can_interface_name )
12
+
13
+ super(PF_CAN, Socket::SOCK_RAW, CAN_RAW)
14
+
15
+ # struct ifreq in net/if.h
16
+ if_idx_req = can_interface_name.ljust(16,"\0")+[0].pack("L")
17
+ ioctl(SIOCGIFINDEX, if_idx_req )
18
+
19
+ if_name,if_index = if_idx_req.unpack("A16L")
20
+
21
+ # sockaddr_can from linux/can.h
22
+ #struct sockaddr_can {
23
+ # __kernel_sa_family_t can_family; S
24
+ # int can_ifindex; l
25
+ # union {
26
+ # /* transport protocol class address information (e.g. ISOTP) */
27
+ # struct { canid_t rx_id, tx_id; } tp; LL
28
+ #
29
+ # /* reserved for future CAN protocols address information */
30
+ # } can_addr;
31
+ #};
32
+ # align on 16 byte -> pad with 2 bytes exta S
33
+
34
+ sockaddr_can = [AF_CAN,if_index,0,0,0].pack("SlLLS")
35
+
36
+ bind(sockaddr_can)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module RubyCan
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_can/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_can"
8
+ spec.version = RubyCan::VERSION
9
+ spec.authors = ["Tomek Rabczak","Craig Smith"]
10
+ spec.email = ["craig@theailabs.com"]
11
+ spec.summary = %q{ruby_can - Raw CAN Bus Module}
12
+ spec.description = %q{ruby_can - Raw library for listening and sending CAN bus packets over SocketCAN}
13
+ spec.homepage = ""
14
+ spec.license = "GPLv3"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "cucumber", "~> 2.0"
24
+
25
+ # Not just for dev, but used by cucumber
26
+ spec.add_development_dependency('bindata', '~> 2.1')
27
+
28
+ end
@@ -0,0 +1,9 @@
1
+ sudo apt-get update
2
+
3
+ sudo apt-get install -y can-utils git 2> /dev/null
4
+
5
+ # Setup the vcan0 interface
6
+ sudo modprobe can
7
+ sudo modprobe vcan
8
+ sudo ip link add dev vcan0 type vcan
9
+ sudo ip link set up vcan0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ su - vagrant -c 'gem install bundler'
4
+ su - vagrant -c 'gem install pry'
5
+ su - vagrant -c '(cd /vagrant && bundle install)'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_can
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tomek Rabczak
8
+ - Craig Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: cucumber
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bindata
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.1'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.1'
70
+ description: ruby_can - Raw library for listening and sending CAN bus packets over
71
+ SocketCAN
72
+ email:
73
+ - craig@theailabs.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - Vagrantfile
83
+ - features/ruby_can.feature
84
+ - features/step_definitions/ruby_can_steps.rb
85
+ - features/support/env.rb
86
+ - lib/ruby_can.rb
87
+ - lib/ruby_can/can_packet.rb
88
+ - lib/ruby_can/can_socket.rb
89
+ - lib/ruby_can/version.rb
90
+ - ruby_can.gemspec
91
+ - vagrant_scripts/bootstrap.sh
92
+ - vagrant_scripts/install-rvm.sh
93
+ homepage: ''
94
+ licenses:
95
+ - GPLv3
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: ruby_can - Raw CAN Bus Module
117
+ test_files:
118
+ - features/ruby_can.feature
119
+ - features/step_definitions/ruby_can_steps.rb
120
+ - features/support/env.rb