lxi_rb 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b92e004dc07e1fe7bd3badd3ad1163c4555abe9ec2992b619ff9f49ffc657c
4
- data.tar.gz: b0c02b7b8ef14803b3179b5360c9b5c515049dfe69e6137736d3d989cac0027a
3
+ metadata.gz: 5e2583bda1cd48c51967b68e5b16f139c77f915cab04b8abbfd88165dba8b245
4
+ data.tar.gz: b4e21c0a5430cb59bcddfb8db0d4740da4a9368b0e695ed777083fb06b9d3bf4
5
5
  SHA512:
6
- metadata.gz: 6ba992bf1a91502ba42c5ff7e5f408d38d627a56eb20019491ee3fd596a059881cb516ade0132d0be9551767c30e52ce471cffbd6a7b581ac985770456be1012
7
- data.tar.gz: d85a26e8551eeee60d5aa87594d81027b6bd42a997b2234aa49d530f9431939346bd802ff3175e63a40ddff3b9e802e4e1d94f998f42aee8c0d57c0d2cf30980
6
+ metadata.gz: 035f02d9942e7a270f0b3a4b3d4a1220e1ca0c01bd7a366e9a6ce39f635fdfc796a9df572856284fc6fcf12120142d8a87960cfa3d7abc55b2bcb682a007b8ec
7
+ data.tar.gz: ba12b510bc5f56cbd7ee5530c2d8c7119b2e6340c580ba84c0d863c175d74cbc596785ba63abc8aae958c9733f65c4731a17d6bfff1be81ad6968a72bcf11b6d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lxi_rb (0.2.0)
4
+ lxi_rb (0.2.1)
5
5
  ffi (~> 1.15)
6
6
 
7
7
  GEM
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
- # Expose liblxi functions
11
- attach_function :lxi_init, [], :int
12
- attach_function :lxi_discover_internal, :lxi_discover, [LxiInfo.ptr, :int, :lxi_discover_type], :int
13
- attach_function :lxi_discover_if, [LxiInfo.ptr, :string, :int, :lxi_discover_type], :int
14
- attach_function :lxi_connect, %i[string int string int lxi_protocol_type], :int
15
- attach_function :lxi_send, %i[int string int int], :int
16
- attach_function :lxi_receive, %i[int pointer int int], :int
17
- attach_function :lxi_disconnect, [:int], :int
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
- # Define liblxi structs
44
- class LxiInfo < FFI::Struct
45
- layout :broadcast,
46
- callback(%i[pointer pointer], :void),
47
- :device,
48
- callback(%i[pointer pointer], :void),
49
- :service,
50
- callback(%i[pointer pointer pointer int], :void)
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.search(timeout: 1000, type: :vxi11)
55
- lxi_init
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lxi
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxi_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers