scan_beacon 0.5.3 → 0.5.4
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/ext/bluez/addr_rotation.c +1 -1
- data/ext/bluez/advertising.c +4 -3
- data/ext/bluez/bluez.c +1 -1
- data/ext/bluez/devices.c +5 -3
- data/ext/bluez/scanning.c +10 -7
- data/ext/bluez/utils.c +1 -1
- data/ext/core_bluetooth/extconf.rb +6 -4
- data/lib/scan_beacon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6b201d622b5ea2c016eef5c4ce64e007908cfe7
|
4
|
+
data.tar.gz: 291a61d545e72091f8a5ea1dea06767dc25f49fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac1658d5da26b236bce3d41ecca2e42b81be196d417013fbd42d52129902c1e22a02e166a54f9037cff7627d99994235a12722658697f284647667db3f6f8e05
|
7
|
+
data.tar.gz: 129517c9ab08a69f95fec722450f85be1cd9c64f3fa245ca02fd32afc2b420836a7fe2cd8257da0b0256e9299fd015bc5713cc4eb18b18df9d32a524ec9c3ce9
|
data/ext/bluez/addr_rotation.c
CHANGED
@@ -23,7 +23,6 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
#ifdef linux
|
26
|
-
#include "ruby.h"
|
27
26
|
#include <stdio.h>
|
28
27
|
#include <errno.h>
|
29
28
|
#include <unistd.h>
|
@@ -32,6 +31,7 @@
|
|
32
31
|
#include <bluetooth/bluetooth.h>
|
33
32
|
#include <bluetooth/hci.h>
|
34
33
|
#include <bluetooth/hci_lib.h>
|
34
|
+
#include "ruby.h"
|
35
35
|
|
36
36
|
#include "utils.h"
|
37
37
|
|
data/ext/bluez/advertising.c
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#ifdef linux
|
2
|
-
#include "ruby.h"
|
3
2
|
#include <stdio.h>
|
4
3
|
#include <errno.h>
|
5
4
|
#include <unistd.h>
|
@@ -8,6 +7,7 @@
|
|
8
7
|
#include <bluetooth/bluetooth.h>
|
9
8
|
#include <bluetooth/hci.h>
|
10
9
|
#include <bluetooth/hci_lib.h>
|
10
|
+
#include "ruby.h"
|
11
11
|
#pragma pack(1)
|
12
12
|
|
13
13
|
|
@@ -75,13 +75,15 @@ VALUE method_start_advertising(VALUE klass, VALUE rb_device_id, VALUE random_add
|
|
75
75
|
struct hci_request rq;
|
76
76
|
le_set_advertising_parameters_cp adv_params_cp;
|
77
77
|
uint8_t status;
|
78
|
+
int device_handle;
|
79
|
+
uint16_t interval_100ms = htobs(0x00A0); // 0xA0 * 0.625ms = 100ms
|
78
80
|
|
79
81
|
// open connection to the device
|
80
82
|
int device_id = FIX2INT(rb_device_id);
|
81
83
|
if (device_id < 0) {
|
82
84
|
rb_raise(rb_eException, "Could not find device");
|
83
85
|
}
|
84
|
-
|
86
|
+
device_handle = hci_open_dev(device_id);
|
85
87
|
if (device_handle < 0) {
|
86
88
|
rb_raise(rb_eException, "Could not open device");
|
87
89
|
}
|
@@ -97,7 +99,6 @@ VALUE method_start_advertising(VALUE klass, VALUE rb_device_id, VALUE random_add
|
|
97
99
|
|
98
100
|
// set advertising params
|
99
101
|
memset(&adv_params_cp, 0, sizeof(adv_params_cp));
|
100
|
-
uint16_t interval_100ms = htobs(0x00A0); // 0xA0 * 0.625ms = 100ms
|
101
102
|
adv_params_cp.min_interval = interval_100ms;
|
102
103
|
adv_params_cp.max_interval = interval_100ms;
|
103
104
|
adv_params_cp.advtype = 0x03; // non-connectable undirected advertising
|
data/ext/bluez/bluez.c
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#ifdef linux
|
2
|
-
#include "ruby.h"
|
3
2
|
#include <stdio.h>
|
4
3
|
#include <errno.h>
|
5
4
|
#include <unistd.h>
|
@@ -8,6 +7,7 @@
|
|
8
7
|
#include <bluetooth/bluetooth.h>
|
9
8
|
#include <bluetooth/hci.h>
|
10
9
|
#include <bluetooth/hci_lib.h>
|
10
|
+
#include "ruby.h"
|
11
11
|
|
12
12
|
VALUE bluez_module = Qnil;
|
13
13
|
|
data/ext/bluez/devices.c
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#ifdef linux
|
2
|
-
#include "ruby.h"
|
3
2
|
#include <stdio.h>
|
4
3
|
#include <errno.h>
|
5
4
|
#include <unistd.h>
|
@@ -8,6 +7,7 @@
|
|
8
7
|
#include <bluetooth/bluetooth.h>
|
9
8
|
#include <bluetooth/hci.h>
|
10
9
|
#include <bluetooth/hci_lib.h>
|
10
|
+
#include "ruby.h"
|
11
11
|
|
12
12
|
#include "utils.h"
|
13
13
|
|
@@ -67,6 +67,8 @@ VALUE method_devices()
|
|
67
67
|
struct hci_dev_req *dr;
|
68
68
|
struct hci_dev_info di;
|
69
69
|
int i;
|
70
|
+
int ctl;
|
71
|
+
VALUE devices;
|
70
72
|
|
71
73
|
if (!(dl = malloc(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t)))) {
|
72
74
|
rb_raise(rb_eException, "Can't allocate memory");
|
@@ -75,13 +77,13 @@ VALUE method_devices()
|
|
75
77
|
dl->dev_num = HCI_MAX_DEV;
|
76
78
|
dr = dl->dev_req;
|
77
79
|
|
78
|
-
|
80
|
+
ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
79
81
|
if (ioctl(ctl, HCIGETDEVLIST, (void *) dl) < 0) {
|
80
82
|
rb_raise(rb_eException, "Can't get device list");
|
81
83
|
return Qnil;
|
82
84
|
}
|
83
85
|
|
84
|
-
|
86
|
+
devices = rb_ary_new();
|
85
87
|
|
86
88
|
for (i = 0; i< dl->dev_num; i++) {
|
87
89
|
di.dev_id = (dr+i)->dev_id;
|
data/ext/bluez/scanning.c
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#ifdef linux
|
2
|
-
#include "ruby.h"
|
3
2
|
#include <stdio.h>
|
4
3
|
#include <errno.h>
|
5
4
|
#include <unistd.h>
|
@@ -9,6 +8,7 @@
|
|
9
8
|
#include <bluetooth/bluetooth.h>
|
10
9
|
#include <bluetooth/hci.h>
|
11
10
|
#include <bluetooth/hci_lib.h>
|
11
|
+
#include "ruby.h"
|
12
12
|
|
13
13
|
#include "utils.h"
|
14
14
|
|
@@ -34,6 +34,7 @@ VALUE method_scan(int argc, VALUE *argv, VALUE klass)
|
|
34
34
|
uint16_t window = htobs(0x0005);
|
35
35
|
|
36
36
|
struct hci_filter new_filter;
|
37
|
+
socklen_t filter_size;
|
37
38
|
|
38
39
|
// which device was specified?
|
39
40
|
rb_scan_args(argc, argv, "01", &rb_device_id);
|
@@ -49,7 +50,7 @@ VALUE method_scan(int argc, VALUE *argv, VALUE klass)
|
|
49
50
|
device_handles[device_id] = device_handle;
|
50
51
|
|
51
52
|
// save the old filter so we can restore it later
|
52
|
-
|
53
|
+
filter_size = sizeof(stored_filters[0]);
|
53
54
|
if (getsockopt(device_handle, SOL_HCI, HCI_FILTER, &stored_filters[device_id], &filter_size) < 0) {
|
54
55
|
rb_raise(rb_eException, "Could not get socket options");
|
55
56
|
}
|
@@ -82,15 +83,16 @@ VALUE perform_scan(VALUE device_id_in)
|
|
82
83
|
while (keep_scanning) {
|
83
84
|
evt_le_meta_event *meta;
|
84
85
|
le_advertising_info *info;
|
86
|
+
int ret;
|
85
87
|
|
86
88
|
// wait for data with a timeout
|
87
89
|
fd_set set;
|
90
|
+
struct timeval timeout;
|
88
91
|
FD_ZERO(&set);
|
89
92
|
FD_SET(device_handle, &set);
|
90
|
-
struct timeval timeout;
|
91
93
|
timeout.tv_sec = 0;
|
92
94
|
timeout.tv_usec = 200000; // 200ms
|
93
|
-
|
95
|
+
ret = select(device_handle + 1, &set, NULL, NULL, &timeout);
|
94
96
|
if (ret < 0) {
|
95
97
|
rb_raise(rb_eException, "Error waiting for data");
|
96
98
|
} else if (ret == 0) {
|
@@ -109,6 +111,7 @@ VALUE perform_scan(VALUE device_id_in)
|
|
109
111
|
}
|
110
112
|
|
111
113
|
if (len > 0) {
|
114
|
+
VALUE rssi, ad_data, addr;
|
112
115
|
ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
|
113
116
|
len -= (1 + HCI_EVENT_HDR_SIZE);
|
114
117
|
meta = (void *) ptr;
|
@@ -118,9 +121,9 @@ VALUE perform_scan(VALUE device_id_in)
|
|
118
121
|
}
|
119
122
|
// parse out the ad data, the mac, and the rssi
|
120
123
|
info = (le_advertising_info *) (meta->data + 1);
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
+
rssi = INT2FIX( (int8_t)info->data[info->length] );
|
125
|
+
ad_data = rb_str_new((void *)info->data, info->length);
|
126
|
+
addr = ba2value(&info->bdaddr);
|
124
127
|
keep_scanning = rb_yield_values(3, addr, ad_data, rssi) != Qfalse;
|
125
128
|
}
|
126
129
|
}
|
data/ext/bluez/utils.c
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#ifdef linux
|
2
|
-
#include "ruby.h"
|
3
2
|
#include <stdio.h>
|
4
3
|
#include <errno.h>
|
5
4
|
#include <unistd.h>
|
@@ -8,6 +7,7 @@
|
|
8
7
|
#include <bluetooth/bluetooth.h>
|
9
8
|
#include <bluetooth/hci.h>
|
10
9
|
#include <bluetooth/hci_lib.h>
|
10
|
+
#include "ruby.h"
|
11
11
|
|
12
12
|
#include "utils.h"
|
13
13
|
|
@@ -7,17 +7,19 @@ extension_name = 'scan_beacon/core_bluetooth'
|
|
7
7
|
# The destination
|
8
8
|
dir_config(extension_name)
|
9
9
|
|
10
|
-
|
11
|
-
$DLDFLAGS << " -framework
|
12
|
-
|
13
|
-
|
10
|
+
if RUBY_PLATFORM =~ /darwin/
|
11
|
+
$DLDFLAGS << " -framework Foundation"
|
12
|
+
$DLDFLAGS << " -framework CoreBluetooth"
|
13
|
+
else
|
14
14
|
# don't compile the code on non-mac platforms because
|
15
15
|
# CoreBluetooth wont be there, and we may not even have
|
16
16
|
# the ability to compile ObjC code.
|
17
17
|
COMPILE_C = "echo"
|
18
|
+
CONFIG['CC'] = "echo" # this is for Ruby 2.x mkmf
|
18
19
|
# create a dummy .so file so RubyGems thinks everything
|
19
20
|
# was successful. We wont try to load it anyway.
|
20
21
|
LINK_SO = "touch $@"
|
22
|
+
CONFIG['LDSHARED'] = "touch $@; echo" # for Ruby 2.x mkmf
|
21
23
|
end
|
22
24
|
|
23
25
|
create_makefile(extension_name)
|
data/lib/scan_beacon/version.rb
CHANGED