lxi_rb 0.2.0 → 0.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -3
- data/Gemfile.lock +1 -1
- data/lib/lxi/ffi.rb +44 -19
- 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: 3e72bc52c850f4d1904dd30130293eda4a68c004f201026f7b90f967980820db
|
4
|
+
data.tar.gz: bf7cf567edc90d38f1a295ffee34b7ac1eef04a564b5ebca1003995c9381fbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56dd416d6c473a111929c8b69dcf12f8c4c0a71b65f3c3b1f8d37333022ceb902f6228d691fb8dbfb4884dcf284a6f9c07c9da8892e9eb8fcd038b15e75d959c
|
7
|
+
data.tar.gz: 44fea582e9a62f9f3c1c3eadc89838d471e1d9649c3627ad837d49a5e4ef5c5caf48036626f82782da307451635c0452de32f1d9eaf49820f44ea0b371baa896
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
##
|
1
|
+
## v0.2.3 (2023-05-07)
|
2
|
+
## v0.2.2 (2023-05-07)
|
3
|
+
## v0.2.1 (2023-05-07)
|
2
4
|
|
3
|
-
|
5
|
+
### New feature:
|
4
6
|
|
5
|
-
-
|
7
|
+
- **ffi**: Add search class method([`8f7351f`](https://github.com/robcarruthers/lxi_rb/commit/8f7351f9b541614a717a83d291d169b1fd8db356)) (by Rob Carruthers)
|
8
|
+
|
9
|
+
## v0.2.0 (2023-05-07)
|
10
|
+
|
11
|
+
## v0.1.0 (2023-05-07)
|
data/Gemfile.lock
CHANGED
data/lib/lxi/ffi.rb
CHANGED
@@ -3,18 +3,18 @@ require 'ffi'
|
|
3
3
|
module Lxi
|
4
4
|
extend FFI::Library
|
5
5
|
|
6
|
-
# Set the path to the library
|
7
6
|
ffi_lib '/opt/homebrew/lib/liblxi.dylib'
|
8
7
|
ffi_lib_flags :now, :global
|
9
8
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
# Define liblxi structs
|
10
|
+
class LxiInfo < FFI::Struct
|
11
|
+
layout :broadcast,
|
12
|
+
callback(%i[pointer pointer], :void),
|
13
|
+
:device,
|
14
|
+
callback(%i[pointer pointer], :void),
|
15
|
+
:service,
|
16
|
+
callback(%i[pointer pointer pointer int], :void)
|
17
|
+
end
|
18
18
|
|
19
19
|
# LXI Constants
|
20
20
|
LXI_OK = 0
|
@@ -24,6 +24,15 @@ module Lxi
|
|
24
24
|
enum :lxi_protocol_type, %i[vxi11 raw hyslip]
|
25
25
|
enum :lxi_discover_type, %i[vxi11 mdns]
|
26
26
|
|
27
|
+
# Expose liblxi functions
|
28
|
+
attach_function :lxi_init, [], :int
|
29
|
+
attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
|
30
|
+
attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
|
31
|
+
attach_function :lxi_connect, %i[string int string int lxi_protocol_type], :int
|
32
|
+
attach_function :lxi_send, %i[int string int int], :int
|
33
|
+
attach_function :lxi_receive, %i[int pointer int int], :int
|
34
|
+
attach_function :lxi_disconnect, [:int], :int
|
35
|
+
|
27
36
|
# VXI11 Discovery Callbacks
|
28
37
|
BroadcastCallback =
|
29
38
|
FFI::Function.new(:void, %i[pointer pointer]) do |address, interface|
|
@@ -40,19 +49,35 @@ module Lxi
|
|
40
49
|
puts "Service: #{address.read_string}, #{id.read_string}, #{service.read_string}, #{port}"
|
41
50
|
end
|
42
51
|
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
# Initialise the LXI library
|
53
|
+
def init_lxi_session
|
54
|
+
raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK
|
55
|
+
end
|
56
|
+
|
57
|
+
# Search for LXI-11 devices on the specified interface and return hash of devices
|
58
|
+
def self.devices(interface: 'en0', timeout: 1000, type: :vxi11)
|
59
|
+
raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK
|
60
|
+
|
61
|
+
devices = []
|
62
|
+
callback =
|
63
|
+
FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
|
64
|
+
devices << { address: address.read_string, id: id.read_string }
|
65
|
+
end
|
66
|
+
|
67
|
+
info = LxiInfo.new
|
68
|
+
info[:broadcast] = BroadcastCallback
|
69
|
+
info[:device] = callback
|
70
|
+
|
71
|
+
result = lxi_discover_internal(info, timeout, type)
|
72
|
+
sleep 0.1
|
73
|
+
puts "result: #{result}"
|
74
|
+
puts "info: #{info[:device].read_string}"
|
75
|
+
devices
|
51
76
|
end
|
52
77
|
|
53
78
|
# Discover LXI-11 devices on the LAN
|
54
|
-
def self.
|
55
|
-
|
79
|
+
def self.discover_local(timeout: 1000, type: :vxi11)
|
80
|
+
init_lxi_session
|
56
81
|
|
57
82
|
info = LxiInfo.new
|
58
83
|
info[:broadcast] = BroadcastCallback
|
data/lib/lxi/version.rb
CHANGED