lxi_rb 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46b92e004dc07e1fe7bd3badd3ad1163c4555abe9ec2992b619ff9f49ffc657c
4
- data.tar.gz: b0c02b7b8ef14803b3179b5360c9b5c515049dfe69e6137736d3d989cac0027a
3
+ metadata.gz: 3e72bc52c850f4d1904dd30130293eda4a68c004f201026f7b90f967980820db
4
+ data.tar.gz: bf7cf567edc90d38f1a295ffee34b7ac1eef04a564b5ebca1003995c9381fbea
5
5
  SHA512:
6
- metadata.gz: 6ba992bf1a91502ba42c5ff7e5f408d38d627a56eb20019491ee3fd596a059881cb516ade0132d0be9551767c30e52ce471cffbd6a7b581ac985770456be1012
7
- data.tar.gz: d85a26e8551eeee60d5aa87594d81027b6bd42a997b2234aa49d530f9431939346bd802ff3175e63a40ddff3b9e802e4e1d94f998f42aee8c0d57c0d2cf30980
6
+ metadata.gz: 56dd416d6c473a111929c8b69dcf12f8c4c0a71b65f3c3b1f8d37333022ceb902f6228d691fb8dbfb4884dcf284a6f9c07c9da8892e9eb8fcd038b15e75d959c
7
+ data.tar.gz: 44fea582e9a62f9f3c1c3eadc89838d471e1d9649c3627ad837d49a5e4ef5c5caf48036626f82782da307451635c0452de32f1d9eaf49820f44ea0b371baa896
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
- ## [Unreleased]
1
+ ## v0.2.3 (2023-05-07)
2
+ ## v0.2.2 (2023-05-07)
3
+ ## v0.2.1 (2023-05-07)
2
4
 
3
- ## [0.1.0] - 2023-05-02
5
+ ### New feature:
4
6
 
5
- - Initial release
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lxi_rb (0.2.0)
4
+ lxi_rb (0.2.3)
5
5
  ffi (~> 1.15)
6
6
 
7
7
  GEM
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
- # 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
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
- # 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)
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.search(timeout: 1000, type: :vxi11)
55
- lxi_init
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
@@ -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.3'
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Carruthers