lxi_rb 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/lxi/device.rb +5 -3
- data/lib/lxi/ffi.rb +46 -43
- data/lib/lxi/version.rb +1 -1
- metadata +2 -3
- data/lxi_rb.gemspec +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2583bda1cd48c51967b68e5b16f139c77f915cab04b8abbfd88165dba8b245
|
4
|
+
data.tar.gz: b4e21c0a5430cb59bcddfb8db0d4740da4a9368b0e695ed777083fb06b9d3bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035f02d9942e7a270f0b3a4b3d4a1220e1ca0c01bd7a366e9a6ce39f635fdfc796a9df572856284fc6fcf12120142d8a87960cfa3d7abc55b2bcb682a007b8ec
|
7
|
+
data.tar.gz: ba12b510bc5f56cbd7ee5530c2d8c7119b2e6340c580ba84c0d863c175d74cbc596785ba63abc8aae958c9733f65c4731a17d6bfff1be81ad6968a72bcf11b6d
|
data/Gemfile.lock
CHANGED
data/lib/lxi/device.rb
CHANGED
@@ -17,10 +17,10 @@ module Lxi
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def connect
|
20
|
-
raise Error, 'LXI Library Initialisation Error' unless Lxi.lxi_init ==
|
20
|
+
raise Error, 'LXI Library Initialisation Error' unless Lxi.lxi_init == LXI_OK
|
21
21
|
|
22
22
|
@id = Lxi.lxi_connect(@address, @port, @name, @timeout, @protocol)
|
23
|
-
raise Error, 'LXI Connection Error' if @id ==
|
23
|
+
raise Error, 'LXI Connection Error' if @id == LXI_ERROR
|
24
24
|
|
25
25
|
true
|
26
26
|
end
|
@@ -42,7 +42,9 @@ module Lxi
|
|
42
42
|
|
43
43
|
def read(length)
|
44
44
|
message = FFI::MemoryPointer.new(:char, length)
|
45
|
-
|
45
|
+
bytes_received = Lxi.lxi_receive(@id, message, length, @timeout)
|
46
|
+
raise Error, 'LXI communications error' unless bytes_received.positive?
|
47
|
+
|
46
48
|
message.read_string
|
47
49
|
end
|
48
50
|
alias gets read
|
data/lib/lxi/ffi.rb
CHANGED
@@ -7,27 +7,7 @@ module Lxi
|
|
7
7
|
ffi_lib '/opt/homebrew/lib/liblxi.dylib'
|
8
8
|
ffi_lib_flags :now, :global
|
9
9
|
|
10
|
-
# Define
|
11
|
-
enum :lxi_protocol_type, %i[vxi11 raw hyslip]
|
12
|
-
enum :lxi_discover_type, %i[vxi11 mdns]
|
13
|
-
|
14
|
-
# Callbacks
|
15
|
-
BroadcastCallback =
|
16
|
-
FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
|
17
|
-
puts "Broadcast: #{address.read_string}, #{interface.read_string}"
|
18
|
-
end
|
19
|
-
|
20
|
-
DeviceCallback =
|
21
|
-
FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
|
22
|
-
puts "Device: #{address.read_string}, #{id.read_string}"
|
23
|
-
end
|
24
|
-
|
25
|
-
ServiceCallback =
|
26
|
-
FFI::Function.new(:void, %i[pointer pointer pointer int]) do |address, id, service, port|
|
27
|
-
puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
|
28
|
-
end
|
29
|
-
|
30
|
-
# Define the structs
|
10
|
+
# Define liblxi structs
|
31
11
|
class LxiInfo < FFI::Struct
|
32
12
|
layout :broadcast,
|
33
13
|
callback(%i[pointer pointer], :void),
|
@@ -37,7 +17,15 @@ module Lxi
|
|
37
17
|
callback(%i[pointer pointer pointer int], :void)
|
38
18
|
end
|
39
19
|
|
40
|
-
#
|
20
|
+
# LXI Constants
|
21
|
+
LXI_OK = 0
|
22
|
+
LXI_ERROR = -1
|
23
|
+
|
24
|
+
# Define liblxi enums
|
25
|
+
enum :lxi_protocol_type, %i[vxi11 raw hyslip]
|
26
|
+
enum :lxi_discover_type, %i[vxi11 mdns]
|
27
|
+
|
28
|
+
# Expose liblxi functions
|
41
29
|
attach_function :lxi_init, [], :int
|
42
30
|
attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
|
43
31
|
attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
|
@@ -46,36 +34,51 @@ module Lxi
|
|
46
34
|
attach_function :lxi_receive, %i[int pointer int int], :int
|
47
35
|
attach_function :lxi_disconnect, [:int], :int
|
48
36
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
37
|
+
# VXI11 Discovery Callbacks
|
38
|
+
BroadcastCallback =
|
39
|
+
FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
|
40
|
+
puts "Broadcast: #{address.read_string}, #{interface.read_string}"
|
41
|
+
end
|
52
42
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
43
|
+
DeviceCallback =
|
44
|
+
FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
|
45
|
+
puts "Device: #{address.read_string}, #{id.read_string}"
|
46
|
+
end
|
57
47
|
|
58
|
-
|
59
|
-
|
48
|
+
ServiceCallback =
|
49
|
+
FFI::Function.new(:void, %i[pointer pointer pointer int]) do |address, id, service, port|
|
50
|
+
puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
|
51
|
+
end
|
60
52
|
|
61
|
-
|
62
|
-
|
53
|
+
# Initialise the LXI library
|
54
|
+
def init_lxi_session
|
55
|
+
raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK
|
56
|
+
end
|
63
57
|
|
64
|
-
|
65
|
-
|
58
|
+
# Search for LXI-11 devices on the specified interface and return hash of devices
|
59
|
+
def self.devices(interface: 'en0', timeout: 1000, type: :vxi11)
|
60
|
+
raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
devices = []
|
63
|
+
callback =
|
64
|
+
FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
|
65
|
+
devices << { address: address.read_string, id: id.read_string }
|
66
|
+
end
|
69
67
|
|
70
|
-
|
68
|
+
info = LxiInfo.new
|
69
|
+
info[:broadcast] = BroadcastCallback
|
70
|
+
info[:device] = callback
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
result = lxi_discover_internal(info, timeout, type)
|
73
|
+
sleep 0.1
|
74
|
+
puts "result: #{result}"
|
75
|
+
puts "info: #{info[:device].read_string}"
|
76
|
+
devices
|
74
77
|
end
|
75
78
|
|
76
|
-
# Discover LXI devices on the LAN
|
77
|
-
def self.
|
78
|
-
|
79
|
+
# Discover LXI-11 devices on the LAN
|
80
|
+
def self.discover_local(timeout: 1000, type: :vxi11)
|
81
|
+
init_lxi_session
|
79
82
|
|
80
83
|
info = LxiInfo.new
|
81
84
|
info[:broadcast] = BroadcastCallback
|
data/lib/lxi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lxi_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Carruthers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -44,7 +44,6 @@ files:
|
|
44
44
|
- lib/lxi/ffi.rb
|
45
45
|
- lib/lxi/version.rb
|
46
46
|
- lib/lxi_rb.rb
|
47
|
-
- lxi_rb.gemspec
|
48
47
|
- sig/lxi_rb.rbs
|
49
48
|
homepage: https://github.com/robcarruthers/lxi_rb
|
50
49
|
licenses:
|
data/lxi_rb.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/lxi/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'lxi_rb'
|
7
|
-
spec.version = Lxi::VERSION
|
8
|
-
spec.authors = ['Rob Carruthers']
|
9
|
-
spec.email = ['robcarruthers@mac.com']
|
10
|
-
|
11
|
-
spec.summary = 'Ruby wrapper for the liblxi library.'
|
12
|
-
spec.description = 'The gem includes methods required for discovering and communicating with LXI compliant devices'
|
13
|
-
spec.homepage = 'https://github.com/robcarruthers/lxi_rb'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 3.1.0'
|
16
|
-
|
17
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
-
spec.metadata['source_code_uri'] = 'https://github.com/robcarruthers/lxi_rb'
|
19
|
-
spec.metadata['changelog_uri'] = 'https://github.com/robcarruthers/lxi_rb/-/blob/master/CHANGELOG.md'
|
20
|
-
|
21
|
-
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files =
|
24
|
-
Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0")
|
26
|
-
.reject do |f|
|
27
|
-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
spec.bindir = 'exe'
|
31
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ['lib']
|
33
|
-
|
34
|
-
# Uncomment to register a new dependency of your gem
|
35
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
-
spec.add_dependency 'ffi', '~> 1.15'
|
37
|
-
|
38
|
-
# For more information and examples about making a new gem, check out our
|
39
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
-
end
|