cassia-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +50 -0
  3. data/.env.sample +3 -0
  4. data/.gitignore +12 -0
  5. data/.ruby-version +1 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +79 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +377 -0
  11. data/Rakefile +2 -0
  12. data/bin/console +17 -0
  13. data/bin/setup +8 -0
  14. data/cassia-ruby.gemspec +38 -0
  15. data/lib/cassia/access_controller.rb +111 -0
  16. data/lib/cassia/api.rb +39 -0
  17. data/lib/cassia/characteristic.rb +14 -0
  18. data/lib/cassia/configuration.rb +9 -0
  19. data/lib/cassia/default_logger.rb +11 -0
  20. data/lib/cassia/device.rb +14 -0
  21. data/lib/cassia/requests/close_ap_state.rb +31 -0
  22. data/lib/cassia/requests/close_connection_state.rb +38 -0
  23. data/lib/cassia/requests/close_notify.rb +38 -0
  24. data/lib/cassia/requests/close_scan.rb +38 -0
  25. data/lib/cassia/requests/combined_sse.rb +27 -0
  26. data/lib/cassia/requests/connect_device.rb +38 -0
  27. data/lib/cassia/requests/connect_local.rb +44 -0
  28. data/lib/cassia/requests/disconnect_device.rb +36 -0
  29. data/lib/cassia/requests/disconnect_local.rb +33 -0
  30. data/lib/cassia/requests/discover_all_char.rb +33 -0
  31. data/lib/cassia/requests/discover_all_services.rb +33 -0
  32. data/lib/cassia/requests/discover_all_services_and_chars.rb +33 -0
  33. data/lib/cassia/requests/discover_char_of_service.rb +34 -0
  34. data/lib/cassia/requests/discover_descriptor_of_char.rb +34 -0
  35. data/lib/cassia/requests/get_all_routers_status.rb +33 -0
  36. data/lib/cassia/requests/get_connected_devices_router.rb +34 -0
  37. data/lib/cassia/requests/get_token.rb +34 -0
  38. data/lib/cassia/requests/open_ap_state.rb +31 -0
  39. data/lib/cassia/requests/open_connection_state.rb +38 -0
  40. data/lib/cassia/requests/open_notify.rb +38 -0
  41. data/lib/cassia/requests/open_scan.rb +50 -0
  42. data/lib/cassia/requests/switch_autoselect.rb +37 -0
  43. data/lib/cassia/requests/write_char_by_handle.rb +35 -0
  44. data/lib/cassia/response_handlers/close_ap_state.rb +31 -0
  45. data/lib/cassia/response_handlers/close_connection_state.rb +32 -0
  46. data/lib/cassia/response_handlers/close_notify.rb +32 -0
  47. data/lib/cassia/response_handlers/close_scan.rb +32 -0
  48. data/lib/cassia/response_handlers/connect_device.rb +29 -0
  49. data/lib/cassia/response_handlers/connect_local.rb +32 -0
  50. data/lib/cassia/response_handlers/disconnect_device.rb +28 -0
  51. data/lib/cassia/response_handlers/disconnect_local.rb +31 -0
  52. data/lib/cassia/response_handlers/discover_all_char.rb +33 -0
  53. data/lib/cassia/response_handlers/discover_all_services.rb +33 -0
  54. data/lib/cassia/response_handlers/discover_all_services_and_chars.rb +41 -0
  55. data/lib/cassia/response_handlers/discover_char_of_service.rb +37 -0
  56. data/lib/cassia/response_handlers/discover_descriptor_of_char.rb +23 -0
  57. data/lib/cassia/response_handlers/get_all_routers_status.rb +32 -0
  58. data/lib/cassia/response_handlers/get_connected_devices_router.rb +33 -0
  59. data/lib/cassia/response_handlers/get_token.rb +29 -0
  60. data/lib/cassia/response_handlers/open_ap_state.rb +31 -0
  61. data/lib/cassia/response_handlers/open_connection_state.rb +32 -0
  62. data/lib/cassia/response_handlers/open_notify.rb +32 -0
  63. data/lib/cassia/response_handlers/open_scan.rb +32 -0
  64. data/lib/cassia/response_handlers/switch_autoselect.rb +29 -0
  65. data/lib/cassia/response_handlers/write_char_by_handle.rb +28 -0
  66. data/lib/cassia/router.rb +75 -0
  67. data/lib/cassia/ruby/version.rb +5 -0
  68. data/lib/cassia/service.rb +13 -0
  69. data/lib/cassia.rb +82 -0
  70. metadata +252 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2d229db9bae35ba77cf6fb4602c2d84fdc24de4f1492f123efffb4f498b97e11
4
+ data.tar.gz: b7f499a5a965da624cf360374924be9d0f48511677dcaec2d85ccd786fc6b560
5
+ SHA512:
6
+ metadata.gz: 2b9c21b633672555da4a1ea7a1db12d91d6147010e608ea879b962455189e64ecad39b0cd8f5733eed5b7a249b837d3f5455bab6370567810c26bdeee3f9973d
7
+ data.tar.gz: 990cf7d2d97cc891c138f4a94a50a1b4c02b11c78c58777c27fdb8024d66be5dcddf45c5905652373f087243a6f8d2c16d991ff3938a051cf0081a4d71de65f4
@@ -0,0 +1,50 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/cassia-ruby
5
+ docker:
6
+ - image: circleci/ruby:2.5.3
7
+ environment:
8
+ BUNDLE_JOBS: 3
9
+ BUNDLE_RETRY: 3
10
+ BUNDLE_PATH: vendor/bundle
11
+ RAILS_ENV: test
12
+
13
+ steps:
14
+ - checkout
15
+
16
+ - run:
17
+ name: Configure Bundler
18
+ command: |
19
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
20
+ source $BASH_ENV
21
+ gem install bundler
22
+
23
+ # Restore bundle cache
24
+ - restore_cache:
25
+ keys:
26
+ - cassia-ruby-{{ checksum "Gemfile.lock" }}
27
+ - cassia-ruby-
28
+
29
+ - run:
30
+ name: Bundle Install
31
+ command: bundle check || bundle install
32
+
33
+ # Store bundle cache
34
+ - save_cache:
35
+ key: cassia-ruby-{{ checksum "Gemfile.lock" }}
36
+ paths:
37
+ - vendor/bundle
38
+
39
+ # Setup the environment
40
+ - run: cp .env.sample .env
41
+
42
+ # Run rspec in parallel
43
+ - run:
44
+ name: Run rspec in parallel
45
+ command: bundle exec rspec
46
+
47
+ # Save test results for timing analysis
48
+ - store_test_results:
49
+ path: test_results
50
+
data/.env.sample ADDED
@@ -0,0 +1,3 @@
1
+ CASSIA_CLIENT_ID=cassiaClientId
2
+ CASSIA_SECRET=cassiaSecret
3
+ CASSIA_AC_URL=http://demo.cassia.pro
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_Store
10
+ .env
11
+ .rspec_status
12
+ **/.vscode
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at adelinewang679@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cassia-ruby.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cassia-ruby (1.0.0)
5
+ faraday
6
+ faraday_middleware
7
+ ld-eventsource
8
+ virtus
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ axiom-types (0.1.1)
14
+ descendants_tracker (~> 0.0.4)
15
+ ice_nine (~> 0.11.0)
16
+ thread_safe (~> 0.3, >= 0.3.1)
17
+ coderay (1.1.2)
18
+ coercible (1.0.0)
19
+ descendants_tracker (~> 0.0.1)
20
+ concurrent-ruby (1.1.5)
21
+ descendants_tracker (0.0.4)
22
+ thread_safe (~> 0.3, >= 0.3.1)
23
+ diff-lcs (1.3)
24
+ dotenv (2.7.2)
25
+ equalizer (0.0.11)
26
+ faraday (0.15.4)
27
+ multipart-post (>= 1.2, < 3)
28
+ faraday_middleware (0.13.1)
29
+ faraday (>= 0.7.4, < 1.0)
30
+ hitimes (1.3.1)
31
+ http_tools (0.4.5)
32
+ ice_nine (0.11.2)
33
+ ld-eventsource (1.0.0)
34
+ concurrent-ruby (~> 1.0)
35
+ http_tools (~> 0.4.5)
36
+ socketry (~> 0.5.1)
37
+ method_source (0.9.2)
38
+ multipart-post (2.1.1)
39
+ pry (0.12.2)
40
+ coderay (~> 1.1.0)
41
+ method_source (~> 0.9.0)
42
+ rake (10.5.0)
43
+ rspec (3.8.0)
44
+ rspec-core (~> 3.8.0)
45
+ rspec-expectations (~> 3.8.0)
46
+ rspec-mocks (~> 3.8.0)
47
+ rspec-core (3.8.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-expectations (3.8.4)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.8.0)
52
+ rspec-mocks (3.8.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-support (3.8.2)
56
+ socketry (0.5.1)
57
+ hitimes (~> 1.2)
58
+ thread_safe (0.3.6)
59
+ vcr (5.0.0)
60
+ virtus (1.0.5)
61
+ axiom-types (~> 0.1)
62
+ coercible (~> 1.0)
63
+ descendants_tracker (~> 0.0, >= 0.0.3)
64
+ equalizer (~> 0.0, >= 0.0.9)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 2.0)
71
+ cassia-ruby!
72
+ dotenv
73
+ pry
74
+ rake (~> 10.0)
75
+ rspec
76
+ vcr
77
+
78
+ BUNDLED WITH
79
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 adelinewang679
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # Cassia::Ruby
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cassia/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cassia-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cassia-ruby
22
+
23
+ ## Configuration
24
+ Here is a list of the available configuration options and their default values
25
+
26
+ | Option | Description |
27
+ |-----------------|:---------------------------------:|
28
+ | `ac_url` | The URL of your AC server address |
29
+ | `client_id` | Your Cassia API Developer Key |
30
+ | `secret` | Your Cassia API Developer Secret |
31
+
32
+ ### Setting your configuration
33
+
34
+ To set configuration options use the `Cassia.configure` method:
35
+
36
+ ```ruby
37
+ Cassia.configure do |config|
38
+ config.ac_url = ENV['CASSIA_AC_URL']
39
+ config.client_id = ENV['CASSIA_CLIENT_ID']
40
+ config.secret = ENV['CASSIA_SECRET']
41
+ end
42
+ ```
43
+
44
+ ## Resources
45
+
46
+ ### AccessControllers
47
+
48
+ In the following context, `access_controller` is a `Cassia::AccessController` object which contains attributes and structures of a Cassia access controller.
49
+
50
+ #### Retrieve An Access Token From the Cassia API
51
+ ```ruby
52
+ access_controller.get_token
53
+ access_controller.access_token
54
+ ```
55
+
56
+ `get_token` will make a request from `access_controller` to generate an access token encoded from `config.client_id` and `config.secret` using base64.
57
+
58
+ `access_token` will return the access token of `access_controller`.
59
+
60
+ #### Obtain Cassia router's status
61
+ ```ruby
62
+ access_controller.get_all_routers_status
63
+ access_controller.routers
64
+ ```
65
+
66
+ `routers` will return an Array of `Router` objects connected to `access_controller`.
67
+
68
+ #### Switch Router Auto-Selection
69
+ ```ruby
70
+ access_controller.switch_autoselect(flag: 1)
71
+ ```
72
+
73
+ If `flag` is 1, the router auto-selection function will be enabled. If `flag` is 0, the router auto-selection function will be disabled.
74
+
75
+ #### Open Scanning for all the routers in the router list
76
+ ```ruby
77
+ access_controller.open_scan(aps: ["CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8"], chip: 0, active: 0, filter_name: "cassia", filter_mac: "CC:1B:E0:E7:FE:F7", filter_uuid: "00001800-0000-1000-800000805f9b34fb")
78
+ ```
79
+
80
+ `aps` is an array of one or multiple router's MAC address.
81
+ `chip` (optional) means which chip to scan.
82
+ `active` (optional) is either 0 or 1. 0 means enable passive scanning, 1 means enable active scanning.
83
+ `filter_name` (optional) is a filter for device name.
84
+ `filter_mac` (optional) is a filter for device MAC.
85
+ `filter_uuid` (optional) is a filter for device UUID.
86
+
87
+ #### Close Scanning for all the routers in the router list
88
+ ```ruby
89
+ access_controller.close_scan(aps: ["CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8"])
90
+ ```
91
+
92
+ `aps` is an array of one or multiple router's MAC address.
93
+
94
+ #### Connect A Device to An Automatically Selected Router from the router list
95
+ ```ruby
96
+ access_controller.connect_device(aps: '*', device_mac: "CC:1B:E0:E7:FE:F8")
97
+ ```
98
+
99
+ `aps` is an array of one or multiple router's MAC address, or the string '*' which refers to all currently connected routers.
100
+ `device_mac` is the mac address of the device that you are connecting to. You may only pass in one MAC address.
101
+
102
+ #### Disconnect A Device
103
+ ```ruby
104
+ access_controller.disconnect_device(device_mac: "CC:1B:E0:E7:FE:F8")
105
+ ```
106
+
107
+ `device_mac` is the mac address of the device that you are disconnecting.
108
+
109
+ #### Open Notification on SSE Channel
110
+ ```ruby
111
+ access_controller.open_notify(aps: ["CC:1B:E0:E7:FE:F8","CC:1B:E0:E7:FE:F8"])
112
+ ```
113
+
114
+ `aps` is an array of one or multiple router's MAC address.
115
+
116
+ #### Close Notification on SSE Channel
117
+ ```ruby
118
+ access_controller.close_notify(aps: ["CC:1B:E0:E7:FE:F8","CC:1B:E0:E7:FE:F8"])
119
+ ```
120
+
121
+ `aps` is an array of one or multiple router's MAC address.
122
+
123
+ #### Open Connection-state Monitoring on SSE Channel
124
+ ```ruby
125
+ access_controller.open_connection_state(aps: ["CC:1B:E0:E7:FE:F8","CC:1B:E0:E7:FE:F8"])
126
+ ```
127
+
128
+ `aps` is an array of one or multiple router's MAC address.
129
+
130
+ #### Close Connection-state Monitoring on SSE Channel
131
+ ```ruby
132
+ access_controller.close_connection_state(aps: ["CC:1B:E0:E7:FE:F8","CC:1B:E0:E7:FE:F9"])
133
+ ```
134
+
135
+ `aps` is an array of one or multiple router's MAC address.
136
+
137
+ #### Open Ap-state Monitoring on SSE Channel
138
+ ```ruby
139
+ access_controller.open_ap_state
140
+ ```
141
+
142
+ #### Close Ap-state Monitoring on SSE Channel
143
+ ```ruby
144
+ access_controller.close_ap_state
145
+ ```
146
+
147
+ #### Create One Combined SSE Connection
148
+ ```ruby
149
+ access_controller.combined_sse do |client|
150
+ client.on_event do |event|
151
+ puts "I received an event: #{event.type}, #{event.data}"
152
+ # put code here to act on events
153
+ end
154
+ client.on_error { |err| puts "#{err.status}" }
155
+ end
156
+ ```
157
+ You can pass a block to the combined_sse method that allows you to act on the SSE's that you get from the routers.
158
+
159
+ We are using the https://github.com/launchdarkly/ruby-eventsource gem ld-eventsource for our SSE client. Please refer to their documentation for more info.
160
+
161
+ #### Discover All GATT Services
162
+ ```ruby
163
+ access_controller.discover_all_services(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9")
164
+ device.services
165
+ ```
166
+
167
+ `router` is the MAC address of the router that is currently connected to the access controller.
168
+
169
+ `device_mac` is the mac address of the device that you are discovering all GATT services of.
170
+
171
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.services` returns all GATT services provided by `device`.
172
+
173
+ #### Discover All GATT Characteristics
174
+ ```ruby
175
+ access_controller.discover_all_char(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9")
176
+ device.characteristics
177
+ ```
178
+
179
+ `router` is the MAC address of the router that is currently connected to the access controller.
180
+
181
+ `device_mac` is the mac address of the device that you are discovering all GATT characteristics of.
182
+
183
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.characteristics` returns all GATT characteristics of services provided by `device`.
184
+
185
+ #### Discover All Characteristics of One Service
186
+ ```ruby
187
+ access_controller.discover_all_char(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9", service_uuid: "00001800-0000-1000-800000805f9b34fb")
188
+ service.characteristics
189
+ ```
190
+
191
+ `router` is the MAC address of the router that is currently connected to the access controller.
192
+
193
+ `device_mac` is the mac address of the device that you are discovering GATT characteristics of.
194
+
195
+ `servide_uuid` is the uuid of the service that you are discovering GATT characteristics of.
196
+
197
+ `service` is an `Cassia::Service` object with uuid `service_uuid`. `service.characteristics` returns all GATT characteristics of `service`.
198
+
199
+ #### Discover All Characteristics And Services
200
+ ```ruby
201
+ access_controller.discover_all_services_and_chars(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9")
202
+ device.services
203
+ device.characteristics
204
+ ```
205
+
206
+ `router` is the MAC address of the router that is currently connected to the access controller.
207
+
208
+ `device_mac` is the mac address of the device that you are discovering GATT characteristics and services of.
209
+
210
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.services` returns all GATT services provided by `device`.
211
+ `device.characteristics` returns all GATT characteristics of services provided by `device`.
212
+
213
+ #### Write Value Of A Characteristic
214
+ ```ruby
215
+ access_controller.write_char_by_handle(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9", handle: 3, value: "0100")
216
+ ```
217
+
218
+ `router` is the MAC address of the router that is currently connected to the access controller.
219
+
220
+ `device_mac` is the mac address of the device that you are writing GATT characteristic to.
221
+
222
+ `handle` is the handle of the characteristic that you are writing.
223
+
224
+ `value` refers to the function you would like executed. To open the notification, set `value` to "0100". To close the notification, set `value` to "0000".
225
+
226
+ #### Open Notification of A Characteristic
227
+ ```ruby
228
+ access_controller.open_char_notification(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9", handle: 3)
229
+ ```
230
+
231
+ `router` is the MAC address of the router that is currently connected to the access controller.
232
+
233
+ `device_mac` is the mac address of the device whose characteristic is being turned on notification.
234
+
235
+ `handle` is the handle of the characteristic that you are turning notification on.
236
+
237
+ #### Close Notification of A Characteristic
238
+ ```ruby
239
+ access_controller.close_char_notification(router: "CC:1B:E0:E7:FE:F8", device_mac: "CC:1B:E0:E7:FE:F9", handle: 3)
240
+ ```
241
+
242
+ `router` is the MAC address of the router that is currently connected to the access controller.
243
+
244
+ `device_mac` is the mac address of the device whose characteristic is being turned off notification.
245
+
246
+ `handle` is the handle of the characteristic that you are turning notification off.
247
+
248
+ ### Routers
249
+
250
+ In the following context, `router` is a `Cassia::Router` object which contains attributes and structures of a router.
251
+
252
+ #### Connect To A Target Device
253
+ ```ruby
254
+ router.connect_local(access_controller, device_mac: "CC:1B:E0:E7:FE:F9", type: "random")
255
+ ```
256
+
257
+ `device_mac` is the mac address of the device that you are connecting `router` to.
258
+
259
+ `type` is the address type of the device, either "public" or "random".
260
+
261
+ #### Disconnect A Target Device
262
+ ```ruby
263
+ router.disconnect_local(access_controller, device_mac: "CC:1B:E0:E7:FE:F9")
264
+ ```
265
+
266
+ `device_mac` is the mac address of the device that you are disconnecting from `router`.
267
+
268
+ #### Get Device List Connected To A Router
269
+ ```ruby
270
+ router.get_connected_devices(access_controller)
271
+ router.connected_devices
272
+ ```
273
+
274
+ `connected_devices` returns an Array of devices connected to `router`.
275
+
276
+ #### Discover All GATT Services
277
+ ```ruby
278
+ router.discover_all_services(access_controller, device_mac: "CC:1B:E0:E7:FE:F9")
279
+ device.services
280
+ ```
281
+
282
+ `device_mac` is the mac address of the device that you are discovering all GATT services of.
283
+
284
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.services` returns all GATT services provided by `device`.
285
+
286
+ #### Discover All GATT Characteristics
287
+ ```ruby
288
+ router.discover_all_char(access_controller, device_mac: "CC:1B:E0:E7:FE:F9")
289
+ device.characteristics
290
+ ```
291
+
292
+ `device_mac` is the mac address of the device that you are discovering all GATT characteristics of.
293
+
294
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.characteristics` returns all GATT characteristics of services provided by `device`.
295
+
296
+ #### Discover All Characteristics of One Service
297
+ ```ruby
298
+ router.discover_all_char(access_controller, device_mac: "CC:1B:E0:E7:FE:F9", service_uuid: "00001800-0000-1000-800000805f9b34fb")
299
+ service.characteristics
300
+ ```
301
+
302
+ `device_mac` is the mac address of the device that you are discovering GATT characteristics of.
303
+
304
+ `servide_uuid` is the uuid of the service that you are discovering GATT characteristics of.
305
+
306
+ `service` is an `Cassia::Service` object with uuid `service_uuid`. `service.characteristics` returns all GATT characteristics of `service`.
307
+
308
+ #### Discover All Characteristics And Services
309
+ ```ruby
310
+ router.discover_all_services_and_chars(access_controller, device_mac: "CC:1B:E0:E7:FE:F9")
311
+ device.services
312
+ device.characteristics
313
+ ```
314
+
315
+ `device_mac` is the mac address of the device that you are discovering GATT characteristics and services of.
316
+
317
+ `device` is an `Cassia::Device` object with mac address `device_mac`. `device.services` returns all GATT services provided by `device`.
318
+ `device.characteristics` returns all GATT characteristics of services provided by `device`.
319
+
320
+ #### Write Value Of A Characteristic
321
+ ```ruby
322
+ router.write_char_by_handle(access_controller, device_mac: "CC:1B:E0:E7:FE:F9", handle: 3, value: "0100")
323
+ ```
324
+
325
+ `device_mac` is the mac address of the device that you are writing GATT characteristic to.
326
+
327
+ `handle` is the handle of the characteristic that you are writing.
328
+
329
+ `value` refers to the function you would like executed. To open the notification, set `value` to "0100". To close the notification, set `value` to "0000".
330
+
331
+ #### Open Notification of A Characteristic
332
+ ```ruby
333
+ router.open_char_notification(access_controller, device_mac: "CC:1B:E0:E7:FE:F9", handle: 3)
334
+ ```
335
+
336
+ `device_mac` is the mac address of the device whose characteristic is being turned on notification.
337
+
338
+ `handle` is the handle of the characteristic that you are turning notification on.
339
+
340
+ #### Close Notification of A Characteristic
341
+ ```ruby
342
+ router.close_char_notification(access_controller, device_mac: "CC:1B:E0:E7:FE:F9", handle: 3)
343
+ ```
344
+
345
+ `device_mac` is the mac address of the device whose characteristic is being turned off notification.
346
+
347
+ `handle` is the handle of the characteristic that you are turning notification off.
348
+
349
+ ### Characteristics
350
+
351
+ A class whose objects contain attributes of a characteristic of some service provided by a BLE device.
352
+
353
+ ### Devices
354
+
355
+ A class whose objects contain attributes of a BLE device.
356
+
357
+ ### Services
358
+
359
+ A class whose objects contain attributes of a service provided by a BLE device.
360
+
361
+ ## Development
362
+
363
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
364
+
365
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
366
+
367
+ ## Contributing
368
+
369
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cassia-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
370
+
371
+ ## License
372
+
373
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
374
+
375
+ ## Code of Conduct
376
+
377
+ Everyone interacting in the Cassia::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cassia-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cassia"
5
+ require "irb"
6
+ require "pry"
7
+ require "dotenv"
8
+
9
+ Dotenv.load
10
+
11
+ Cassia.configure do |config|
12
+ config.ac_url = ENV['CASSIA_AC_URL']
13
+ config.client_id = ENV['CASSIA_CLIENT_ID']
14
+ config.secret = ENV['CASSIA_SECRET']
15
+ end
16
+
17
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here