-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss_scanner.bgs
63 lines (45 loc) · 1.79 KB
/
rss_scanner.bgs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# USB CDC RX
dim rx_return_code
dim rx_return_data_size
dim rx_return_data(8)
# characteristic value (2-byte array)
dim measure_buf(3)
# Boot event listener
event system_boot(major, minor, patch, build, ll_version, protocol_version, hw)
measure_buf(0:2) = 0 # beacon ID
measure_buf(1:2) = 0 # location ID
measure_buf(2:2) = 0 # RSS measurement
call system_endpoint_set_watermarks(3, 1, 0)
call gap_set_adv_parameters(32, 48, 7)
call gap_set_mode(gap_general_discoverable, gap_undirected_connectable)
call gap_set_scan_parameters($c8, $c8, 0)
end
event connection_status(connection, flags, address, address_type, conn_interval, timeout, latency, bonding)
if flags & $05 then
call gap_discover(gap_discover_generic)
end if
end
event gap_scan_response(rssi, packet_type, sender, address_type, bond, data_len, data_data)
if packet_type = 2 then
if data_data(10:1) = $44 && data_data(9:1) = $44 && data_data(24:1) = $44 then
# update characteristic
measure_buf(0:2) = data_data(26:1) # beacon ID
measure_buf(1:2) = 0 # location ID
measure_buf(2:2) = $100 - rssi # RSS measurement
# write charachteristc
call attributes_write(c_beacons_rss, 0, 3, measure_buf(0:3))
end if
end if
end
event connection_disconnected(handle, result)
call gap_set_adv_parameters(32, 48, 7)
call gap_set_mode(gap_general_discoverable, gap_undirected_connectable)
call gap_discover(gap_discover_generic)
end
# listen to USB CDC and reboot into DFU when ASCII '0' is received
event system_endpoint_watermark_rx(endpoint, size)
call system_endpoint_rx(endpoint, size)(rx_return_code, rx_return_data_size, rx_return_data(0:rx_return_data_size))
if rx_return_data(0:1) = $30 then
call system_reset(1)
end if
end