lxi_rb 0.2.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/ffi.rb +44 -18
- data/lib/lxi/version.rb +1 -1
- metadata +1 -1
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/ffi.rb
CHANGED
@@ -7,14 +7,15 @@ module Lxi
|
|
7
7
|
ffi_lib '/opt/homebrew/lib/liblxi.dylib'
|
8
8
|
ffi_lib_flags :now, :global
|
9
9
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
# Define liblxi structs
|
11
|
+
class LxiInfo < FFI::Struct
|
12
|
+
layout :broadcast,
|
13
|
+
callback(%i[pointer pointer], :void),
|
14
|
+
:device,
|
15
|
+
callback(%i[pointer pointer], :void),
|
16
|
+
:service,
|
17
|
+
callback(%i[pointer pointer pointer int], :void)
|
18
|
+
end
|
18
19
|
|
19
20
|
# LXI Constants
|
20
21
|
LXI_OK = 0
|
@@ -24,6 +25,15 @@ module Lxi
|
|
24
25
|
enum :lxi_protocol_type, %i[vxi11 raw hyslip]
|
25
26
|
enum :lxi_discover_type, %i[vxi11 mdns]
|
26
27
|
|
28
|
+
# Expose liblxi functions
|
29
|
+
attach_function :lxi_init, [], :int
|
30
|
+
attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
|
31
|
+
attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
|
32
|
+
attach_function :lxi_connect, %i[string int string int lxi_protocol_type], :int
|
33
|
+
attach_function :lxi_send, %i[int string int int], :int
|
34
|
+
attach_function :lxi_receive, %i[int pointer int int], :int
|
35
|
+
attach_function :lxi_disconnect, [:int], :int
|
36
|
+
|
27
37
|
# VXI11 Discovery Callbacks
|
28
38
|
BroadcastCallback =
|
29
39
|
FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
|
@@ -40,19 +50,35 @@ module Lxi
|
|
40
50
|
puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
|
41
51
|
end
|
42
52
|
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
# Initialise the LXI library
|
54
|
+
def init_lxi_session
|
55
|
+
raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK
|
56
|
+
end
|
57
|
+
|
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
|
61
|
+
|
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
|
67
|
+
|
68
|
+
info = LxiInfo.new
|
69
|
+
info[:broadcast] = BroadcastCallback
|
70
|
+
info[:device] = callback
|
71
|
+
|
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
|
51
77
|
end
|
52
78
|
|
53
79
|
# Discover LXI-11 devices on the LAN
|
54
|
-
def self.
|
55
|
-
|
80
|
+
def self.discover_local(timeout: 1000, type: :vxi11)
|
81
|
+
init_lxi_session
|
56
82
|
|
57
83
|
info = LxiInfo.new
|
58
84
|
info[:broadcast] = BroadcastCallback
|
data/lib/lxi/version.rb
CHANGED