scan_beacon 0.7.1 → 0.7.2

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
  SHA1:
3
- metadata.gz: 5f8844b16259f721c6d4f61beebf3864c6414b83
4
- data.tar.gz: a39128a6ae36cefc7d6a08fa3acdd544cabaecb6
3
+ metadata.gz: ea62479acf5f65e19dddfb63fd45bbe502d0df36
4
+ data.tar.gz: d338df688e255c8361688191ed63129a2f5aefdf
5
5
  SHA512:
6
- metadata.gz: a18157a020028352344d31b431097a4f9b322c5a382a382098dd6e5ecc62eb406038c052754360d047d170ab1175a4024a07109be862923823c12b5d0f98ed24
7
- data.tar.gz: 76db397e4a1c005cbe7f61c393e585cbe3678a6d79070e6d22e064fc8836c4b7376c32f2a07bca8071771a091757479c2541450a1dd2395f9a5d6078999e53b2
6
+ metadata.gz: 51a2a247e35d654722086b2c70e4ada9249edba07da87b6def8e8f03f7d7af92d7725fa0a400fb6e2208d902689612fe4251371c4a60b181ef1f99e1eb9044d2
7
+ data.tar.gz: 6b2724b5e74aeb2207017099b130ccd6a21b79a62a0437018e2ee958da438574cf9582418ec62fe0001ad5d02a12190f0e61da7d500f77ab24c52f2ce3c51656
@@ -15,6 +15,8 @@ VALUE method_scan();
15
15
  VALUE method_new_adverts();
16
16
  VALUE new_scan_hash(NSString* device, NSData *data, NSNumber *rssi, NSData *service_uuid);
17
17
 
18
+ VALUE method_get_addr();
19
+ VALUE method_set_random_addr();
18
20
  VALUE method_set_advertisement_data(VALUE klass, VALUE data);
19
21
  VALUE method_start_advertising();
20
22
  VALUE method_stop_advertising();
@@ -26,6 +28,8 @@ VALUE method_stop_advertising();
26
28
  - (int)BluetoothHCILESetAdvertisingParameters:(unsigned short)arg1 advertisingIntervalMax:(unsigned short)arg2 advertisingType:(unsigned char)arg3 ownAddressType:(unsigned char)arg4 directAddressType:(unsigned char)arg5 directAddress:(struct BluetoothDeviceAddress { unsigned char x1[6]; }*)arg6 advertisingChannelMap:(unsigned char)arg7 advertisingFilterPolicy:(unsigned char)arg8;
27
29
  - (int)BluetoothHCILESetScanParameters:(unsigned char)arg1 LEScanInterval:(unsigned short)arg2 LEScanWindow:(unsigned short)arg3 ownAddressType:(unsigned char)arg4 scanningFilterPolicy:(unsigned char)arg5;
28
30
  - (int)BluetoothHCILESetScanEnable:(unsigned char)arg1 filterDuplicates:(unsigned char)arg2;
31
+ - (int)getAddress:(struct BluetoothDeviceAddress { unsigned char x1[6]; }*)arg1;
32
+ - (int)BluetoothHCILESetRandomAddress:(const char*)arg1;
29
33
  @end
30
34
 
31
35
  @interface BLEDelegate : NSObject <CBCentralManagerDelegate> {
@@ -113,8 +117,10 @@ void Init_core_bluetooth()
113
117
  rb_define_singleton_method(cb_module, "scan", method_scan, 0);
114
118
  rb_define_singleton_method(cb_module, "new_adverts", method_new_adverts, 0);
115
119
 
120
+ rb_define_singleton_method(cb_module, "get_addr", method_get_addr, 0);
121
+ rb_define_singleton_method(cb_module, "set_random_addr", method_set_random_addr, 0);
116
122
  rb_define_singleton_method(cb_module, "set_advertisement_data", method_set_advertisement_data, 1);
117
- rb_define_singleton_method(cb_module, "start_advertising", method_start_advertising, 0);
123
+ rb_define_singleton_method(cb_module, "start_advertising", method_start_advertising, 1);
118
124
  rb_define_singleton_method(cb_module, "stop_advertising", method_stop_advertising, 0);
119
125
 
120
126
  sym_device = ID2SYM(rb_intern("device"));
@@ -155,8 +161,6 @@ VALUE method_new_adverts()
155
161
 
156
162
  VALUE method_scan()
157
163
  {
158
- VALUE scans = rb_ary_new();
159
-
160
164
  @autoreleasepool {
161
165
  @try {
162
166
  bleDelegate = [[BLEDelegate alloc] init];
@@ -176,6 +180,32 @@ VALUE method_scan()
176
180
  return Qnil;
177
181
  }
178
182
 
183
+ VALUE addr_to_rbstr(uint8_t* addr)
184
+ {
185
+ char c_str[20];
186
+ sprintf(c_str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
187
+ addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
188
+ return rb_str_new2(c_str);
189
+ }
190
+
191
+ VALUE method_get_addr()
192
+ {
193
+ IOBluetoothHostController *device = [IOBluetoothHostController defaultController];
194
+ uint8_t addr[6];
195
+ [device getAddress: (void*)addr];
196
+ return addr_to_rbstr(addr);
197
+ }
198
+
199
+ VALUE method_set_random_addr()
200
+ {
201
+ uint8_t addr[6];
202
+ SecRandomCopyBytes(kSecRandomDefault, 6, addr);
203
+ addr[0] = addr[0] & 0x7F;
204
+ IOBluetoothHostController *device = [IOBluetoothHostController defaultController];
205
+ [device BluetoothHCILESetRandomAddress: (void*)addr];
206
+ return addr_to_rbstr(addr);
207
+ }
208
+
179
209
  VALUE method_set_advertisement_data(VALUE klass, VALUE data)
180
210
  {
181
211
  IOBluetoothHostController *device = [IOBluetoothHostController defaultController];
@@ -187,17 +217,24 @@ VALUE method_set_advertisement_data(VALUE klass, VALUE data)
187
217
  return Qnil;
188
218
  }
189
219
 
190
- VALUE method_start_advertising()
220
+ VALUE method_start_advertising(VALUE klass, VALUE random)
191
221
  {
222
+ unsigned char ownAddrType = 0x00;
223
+ if (random == Qtrue) {
224
+ ownAddrType = 0x01;
225
+ }
192
226
  IOBluetoothHostController *device = [IOBluetoothHostController defaultController];
193
227
  [device BluetoothHCILESetAdvertisingParameters: 0x00A0
194
228
  advertisingIntervalMax: 0x00A0 // 100ms
195
229
  advertisingType: 0x03
196
- ownAddressType: 0x00
230
+ ownAddressType: ownAddrType
197
231
  directAddressType: 0x00
198
232
  directAddress: (void*)"\x00\x00\x00\x00\x00\x00"
199
233
  advertisingChannelMap: 0x07 // all 3 channels
200
234
  advertisingFilterPolicy: 0x00];
235
+ if (random == Qtrue) {
236
+ method_set_random_addr();
237
+ }
201
238
  [device BluetoothHCILESetAdvertiseEnable: 1];
202
239
  return Qnil;
203
240
  }
@@ -22,7 +22,6 @@ module ScanBeacon
22
22
  # have to pass nil for addr if we don't want to override it and use the internal
23
23
  BlueZ.start_advertising @device_id, nil
24
24
  end
25
-
26
25
  @advertising=true
27
26
  end
28
27
 
@@ -38,7 +37,7 @@ module ScanBeacon
38
37
  def rotate_addr_and_update_ad
39
38
  self.update_ad
40
39
  self.stop
41
- self.start_with_random_addr
40
+ self.start(true)
42
41
  end
43
42
 
44
43
  def random_addr
@@ -10,14 +10,20 @@ module ScanBeacon
10
10
  CoreBluetooth.set_advertisement_data @ad
11
11
  end
12
12
 
13
- def start
14
- CoreBluetooth.start_advertising
13
+ def start(with_rotation = false)
14
+ CoreBluetooth.start_advertising(with_rotation)
15
15
  end
16
16
 
17
17
  def stop
18
18
  CoreBluetooth.stop_advertising
19
19
  end
20
20
 
21
+ def rotate_addr_and_update_ad
22
+ self.update_ad
23
+ self.stop
24
+ self.start(true)
25
+ end
26
+
21
27
  def inspect
22
28
  "<CoreBluetoothAdvertiser ad=#{@ad.inspect}>"
23
29
  end
@@ -15,13 +15,13 @@ module ScanBeacon
15
15
  update_ad
16
16
  end
17
17
 
18
- def update_ad
18
+ def update_ad
19
19
  self.ad = @parser.generate_ad(@beacon) if @parser && @beacon
20
20
  end
21
-
21
+
22
22
  def ad=(value)
23
23
  @ad = value
24
24
  self.start if advertising
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module ScanBeacon
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scan_beacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radius Networks
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.2.2
130
+ rubygems_version: 2.4.6
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Provides Beacon scanning functionality