ant-wireless 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ant.rb CHANGED
@@ -12,7 +12,7 @@ module Ant
12
12
  extend Loggability
13
13
 
14
14
  # Package version
15
- VERSION = '0.1.0'
15
+ VERSION = '0.4.0'
16
16
 
17
17
  # A Range for matching valid ANT device numbers
18
18
  VALID_DEVICE_NUMBERS = ( 0...65535 ).freeze
@@ -26,6 +26,14 @@ module Ant
26
26
  # The valid offsets for the "RF Frequency" setting; this is an offset from 2400Hz.
27
27
  VALID_RF_FREQUENCIES = ( 0...124 ).freeze
28
28
 
29
+ # Default options for advanced burst when it's enabled.
30
+ DEFAULT_ADVANCED_OPTIONS = {
31
+ max_packet_length: 24,
32
+ frequency_hopping: :optional,
33
+ stall_count: 0,
34
+ retry_count: 0
35
+ }
36
+
29
37
 
30
38
  # Loggability API -- set up a logger for the library
31
39
  log_as :ant
@@ -35,6 +43,23 @@ module Ant
35
43
  autoload :DataUtilities, 'ant/mixins'
36
44
 
37
45
 
46
+ # Capabilities hash -- set asynchronously by calling Ant.request_capabilities
47
+ @capabilities = nil
48
+ singleton_class.attr_reader( :capabilities )
49
+
50
+ # Serial number -- set asynchronously by calling Ant.request_serial_num
51
+ @serial_num = nil
52
+ singleton_class.attr_reader( :serial_num )
53
+
54
+ # Version of ANT supported by the hardware -- set asynchronously by calling
55
+ # Ant.request_version
56
+ @hardware_version = nil
57
+ singleton_class.attr_reader( :hardware_version )
58
+
59
+ # Add some convenience aliases
60
+ singleton_class.alias_method( :is_initialized?, :initialized? )
61
+
62
+
38
63
  ### Set up the given +object+ as the handler for response callbacks. It must
39
64
  ### respond to :handle_response_callback.
40
65
  def self::set_response_handler( object=Ant::ResponseCallbacks )
@@ -126,5 +151,55 @@ module Ant
126
151
  return offset
127
152
  end
128
153
 
154
+
155
+ ### Enable advanced burst mode with the given +options+.
156
+ def self::enable_advanced_burst( **options )
157
+ options = DEFAULT_ADVANCED_OPTIONS.merge( options )
158
+
159
+ max_packet_length = self.convert_max_packet_length( options[:max_packet_length] )
160
+
161
+ required_fields = self.make_required_fields_config( options )
162
+ optional_fields = self.make_optional_fields_config( options )
163
+
164
+ stall_count = options[:stall_count]
165
+ retry_count = options[:retry_count]
166
+
167
+ self.configure_advanced_burst( true, max_packet_length, required_fields, optional_fields,
168
+ stall_count, retry_count )
169
+ end
170
+
171
+
172
+ ### Validate that the specified +length+ (in bytes) is a valid setting as an
173
+ ### advanced burst max packet length configuration value. Returns the equivalent
174
+ ### configuration value.
175
+ def self::convert_max_packet_length( length )
176
+ case length
177
+ when 8 then return 0x01
178
+ when 16 then return 0x02
179
+ when 24 then return 0x03
180
+ else
181
+ raise ArgumentError,
182
+ "invalid max packet length; expected 8, 16, or 24, got %p" % [ length ]
183
+ end
184
+ end
185
+
186
+
187
+ ### Given an options hash, return a configuration value for required fields.
188
+ def self::make_required_fields_config( **options )
189
+ value = 0
190
+ value |= 0x01 if options[:frequency_hopping] == :required
191
+
192
+ return value
193
+ end
194
+
195
+
196
+ ### Given an options hash, return a configuration value for optional fields.
197
+ def self::make_optional_fields_config( **options )
198
+ value = 0
199
+ value |= 0x01 if options[:frequency_hopping] == :optional
200
+
201
+ return value
202
+ end
203
+
129
204
  end # module Ant
130
205
 
data/spec/ant_spec.rb CHANGED
@@ -33,6 +33,15 @@ RSpec.describe( Ant ) do
33
33
  end
34
34
 
35
35
 
36
+ it "knows if it's been initialized or not", :hardware do
37
+ expect( Ant ).to_not be_initialized
38
+ Ant.init
39
+ expect( Ant ).to be_initialized
40
+ Ant.close
41
+ expect( Ant ).to_not be_initialized
42
+ end
43
+
44
+
36
45
  it "can validate a device number" do
37
46
  expect( described_class.validate_device_number(111) ).to eq( 111 )
38
47
  expect {
@@ -0,0 +1,141 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'spec_helper'
5
+
6
+ require 'ant/bitvector'
7
+
8
+
9
+ RSpec.describe( Ant::BitVector ) do
10
+
11
+ context 'when first instantiated' do
12
+
13
+ it "is empty when created without arguments" do
14
+ v = described_class.new
15
+ expect( v.to_i ).to eq( 0 )
16
+ expect( v.size ).to eq( 1 )
17
+ end
18
+
19
+
20
+ it "accepts a decimal argument" do
21
+ v = described_class.new( 242 )
22
+ expect( v.to_hex ).to eq( '0x00f2' )
23
+ end
24
+
25
+
26
+ it "accepts a hexadecimal argument" do
27
+ v = described_class.new( 0x00f2 )
28
+ expect( v.to_i ).to eq( 242 )
29
+ end
30
+
31
+
32
+ it "accepts a bit string argument" do
33
+ v = described_class.new( 0b11110010 )
34
+ expect( v.to_i ).to eq( 242 )
35
+ end
36
+
37
+
38
+ it "accepts a different BitVector argument" do
39
+ v = described_class.new( described_class.new( 242 ) )
40
+ expect( v.to_i ).to eq( 242 )
41
+ end
42
+
43
+
44
+ it "accepts a string argument" do
45
+ v = described_class.new( "242" )
46
+ expect( v.to_i ).to eq( 242 )
47
+ end
48
+
49
+
50
+ it "rejects objects that don't have a 'to_i' method" do
51
+ expect {
52
+ described_class.new( Class )
53
+ }.to raise_error( ArgumentError, /don't know what to do/i )
54
+ end
55
+
56
+ end
57
+
58
+
59
+ context 'after modified with a value' do
60
+
61
+ let( :bv ) { described_class.new( 242 ) }
62
+
63
+
64
+ it "can be converted into various formats" do
65
+ expect( bv.to_int ).to eq( 242 )
66
+ expect( bv.to_hex ).to eq( '0x00f2' )
67
+ expect( bv.to_bin ).to eq( '0b11110010' )
68
+ end
69
+
70
+
71
+ it "knows the size of its own bit string" do
72
+ expect( bv.size ).to eq( 8 )
73
+ bv.toggle( 9 )
74
+ expect( bv.size ).to eq( 10 )
75
+ end
76
+
77
+
78
+ it "can switch specific bits on and off" do
79
+ expect( bv.on?( 12 ) ).to be_falsey
80
+
81
+ bv.on( 12 )
82
+ expect( bv[12] ).to be_truthy
83
+
84
+ bv.off( 12 )
85
+ expect( bv.off?( 12 ) ).to be_truthy
86
+
87
+ bv[12] = true
88
+ expect( bv.on?( 12 ) ).to be_truthy
89
+ end
90
+
91
+
92
+ it "can set bits in a range" do
93
+ expect( bv[ 8] ).to be_falsey
94
+ expect( bv[ 9] ).to be_falsey
95
+ expect( bv[10] ).to be_falsey
96
+ expect( bv[11] ).to be_falsey
97
+ expect( bv[12] ).to be_falsey
98
+
99
+ bv[8..12] = true
100
+
101
+ expect( bv[ 8] ).to be_truthy
102
+ expect( bv[ 9] ).to be_truthy
103
+ expect( bv[10] ).to be_truthy
104
+ expect( bv[11] ).to be_truthy
105
+ expect( bv[12] ).to be_truthy
106
+ end
107
+
108
+
109
+ it "delegates math operations to the underlying integer" do
110
+ bv2 = described_class.new( 4112 )
111
+
112
+ bv3 = bv + bv2
113
+ expect( bv3.to_int ).to eq( 4354 )
114
+
115
+ bv3 = bv | bv2
116
+ expect( bv3.to_int ).to eq( 4338 )
117
+
118
+ bv3 = bv & bv2
119
+ expect( bv3.to_int ).to eq( 16 )
120
+
121
+ expect( bv3 ).to be_a( described_class )
122
+ end
123
+
124
+
125
+ it "can compare different bitvector objects" do
126
+ bv1 = described_class.new( bv )
127
+ bv2 = described_class.new( 4112 )
128
+ expect( bv ).to eq( bv1 )
129
+ expect( bv ).to be < bv2
130
+ end
131
+
132
+
133
+ it "is enumerable" do
134
+ bits = bv.to_a
135
+ expect( bits ).to eq( [0, 1, 0, 0, 1, 1, 1, 1] )
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,8 @@ RSpec.configure do |config|
20
20
  Ant.init
21
21
  Ant.close
22
22
  rescue => err
23
+ $stderr.puts "%p while initializing hardware: %s; disabling hardware specs" %
24
+ [ err.class, err.message ]
23
25
  config.filter_run_excluding( :hardware )
24
26
  end
25
27
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ant-wireless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -34,7 +34,7 @@ cert_chain:
34
34
  MCh97sQ/Z/MOusb5+QddBmB+k8EicXyGNl4b5L4XpL7fIQu+Y96TB3JEJlShxFD9
35
35
  k9FjI4d9EP54gS/4
36
36
  -----END CERTIFICATE-----
37
- date: 2021-08-26 00:00:00.000000000 Z
37
+ date: 2021-11-05 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rake-compiler
@@ -106,6 +106,7 @@ files:
106
106
  - ext/ant_ext/version.h
107
107
  - lib/ant-wireless.rb
108
108
  - lib/ant.rb
109
+ - lib/ant/bitvector.rb
109
110
  - lib/ant/channel.rb
110
111
  - lib/ant/channel/event_callbacks.rb
111
112
  - lib/ant/message.rb
@@ -113,6 +114,7 @@ files:
113
114
  - lib/ant/response_callbacks.rb
114
115
  - lib/ant/wireless.rb
115
116
  - spec/ant_spec.rb
117
+ - spec/bitvector_spec.rb
116
118
  - spec/spec_helper.rb
117
119
  homepage: https://sr.ht/~ged/ruby-ant-wireless/
118
120
  licenses:
metadata.gz.sig CHANGED
Binary file