iot 1.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/iot +81 -0
- data/iot.gemspec +23 -0
- data/lib/iot.rb +34 -0
- data/lib/iot/bleyamlparser.rb +43 -0
- data/lib/iot/characteristic.rb +27 -0
- data/lib/iot/destroy.rb +69 -0
- data/lib/iot/devicename.rb +46 -0
- data/lib/iot/generate.rb +137 -0
- data/lib/iot/help.rb +26 -0
- data/lib/iot/install.rb +93 -0
- data/lib/iot/mkhex.rb +14 -0
- data/lib/iot/new.rb +62 -0
- data/lib/iot/new/bleyaml.rb +11 -0
- data/lib/iot/new/main.rb +54 -0
- data/lib/iot/new/makefile.rb +159 -0
- data/lib/iot/new/stbledevice.rb +83 -0
- data/lib/iot/new/stdeviceinfo.rb +6 -0
- data/lib/iot/new/stservice.rb +118 -0
- data/lib/iot/run.rb +158 -0
- data/lib/iot/service.rb +20 -0
- data/lib/iot/stats.rb +10 -0
- data/lib/iot/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1d6bfe3069d51299c0180844cda1b900f0924a8
|
4
|
+
data.tar.gz: c0e3fb5def22d1df681cf8a672416094d19780b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae0ca356bc213fb5d82fcb335b1a6ecedb1b93e47b0e8bb1645e5415dfb4573107760b202fa69f08a669bf33af1d3652dad58d5c6fed5d11be8460f1d3908d60
|
7
|
+
data.tar.gz: 81a014e7ca741f6d3ef776c153424e3734bbadbba015ec88065701bc83ff03704bdd32520920c00896e3c6140c8b8e5e1ad9371f3c75850d540ee21cd482c573
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Akito Gyoten
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Iot Generator
|
2
|
+
|
3
|
+
Iot Generator make it easy to set development environment up for mbed HRM1017.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'iot'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install iot
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This section is under construction.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/gyoten/iot/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/iot
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
|
4
|
+
require "iot"
|
5
|
+
include Iot
|
6
|
+
|
7
|
+
Command = ARGV[0]
|
8
|
+
|
9
|
+
if Command == "--help" || Command == "-h"
|
10
|
+
Iot.help
|
11
|
+
elsif Command == "--version" || Command == "-v"
|
12
|
+
puts "Iot generator #{Iot::VERSION}"
|
13
|
+
elsif Command == "install"
|
14
|
+
Iot.installComponents
|
15
|
+
elsif Command == "uninstall"
|
16
|
+
Iot.uninstall
|
17
|
+
elsif Command == "new"
|
18
|
+
project_path = "#{ARGV[1]}"
|
19
|
+
|
20
|
+
Iot.new project_path
|
21
|
+
elsif Command == "run"
|
22
|
+
Iot.run
|
23
|
+
elsif Command == "generate" || Command == "g"
|
24
|
+
generate_type = "#{ARGV[1]}"
|
25
|
+
name = "#{ARGV[2]}"
|
26
|
+
|
27
|
+
Iot.generate(generate_type, name)
|
28
|
+
elsif Command == "destroy" || Command == "d"
|
29
|
+
destroy_type = "#{ARGV[1]}"
|
30
|
+
service_name = "#{ARGV[2]}"
|
31
|
+
|
32
|
+
Iot.destroy(destroy_type, service_name)
|
33
|
+
elsif Command == "stats"
|
34
|
+
Iot.stats
|
35
|
+
elsif Command == "service"
|
36
|
+
option = "#{ARGV[1]}"
|
37
|
+
service_name = "#{ARGV[2]}"
|
38
|
+
|
39
|
+
if option == "--delete" || option == "-d"
|
40
|
+
if service_name.empty?
|
41
|
+
puts "Service name is required."
|
42
|
+
else
|
43
|
+
Iot.destroy("service", service_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
else
|
47
|
+
Iot.service
|
48
|
+
end
|
49
|
+
elsif Command == "char"
|
50
|
+
option = "#{ARGV[1]}"
|
51
|
+
char_name = "#{ARGV[2]}"
|
52
|
+
|
53
|
+
if option == "--delete" || option == "-d"
|
54
|
+
if char_name.empty?
|
55
|
+
puts "Characteristic name is required."
|
56
|
+
else
|
57
|
+
Iot.destroy("characteristic", char_name)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
Iot.char
|
61
|
+
end
|
62
|
+
elsif Command == "compname"
|
63
|
+
device_name = "#{ARGV[1]}"
|
64
|
+
|
65
|
+
Iot.change_complete_name device_name
|
66
|
+
elsif Command == "shortname"
|
67
|
+
device_name = "#{ARGV[1]}"
|
68
|
+
|
69
|
+
Iot.change_short_name device_name
|
70
|
+
elsif Command == "devicename"
|
71
|
+
Iot.toggle_local_name
|
72
|
+
elsif Command == "mkhex"
|
73
|
+
softdevice_path = "#{ARGV[1]}"
|
74
|
+
projectfile_path = "#{ARGV[2]}"
|
75
|
+
|
76
|
+
Iot.mkhex(softdevice_path, projectfile_path)
|
77
|
+
else
|
78
|
+
puts "Unknown command"
|
79
|
+
puts ""
|
80
|
+
Iot.help
|
81
|
+
end
|
data/iot.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iot"
|
8
|
+
spec.version = Iot::VERSION
|
9
|
+
spec.authors = ["Akito Gyoten"]
|
10
|
+
spec.email = ["akitogyoten@gmail.com"]
|
11
|
+
spec.summary = %q{Development environment for IoT devices generator}
|
12
|
+
spec.description = %q{IoT gem generate development environment for IoT devices and genarate skelton code for embedded software for IoT devices.}
|
13
|
+
spec.homepage = "http://corp.strobo.me"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = 'iot'
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/iot.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "iot/version"
|
2
|
+
require "iot/help"
|
3
|
+
require "iot/install"
|
4
|
+
require "iot/new"
|
5
|
+
require "iot/run"
|
6
|
+
require "iot/generate"
|
7
|
+
require "iot/destroy"
|
8
|
+
require "iot/stats"
|
9
|
+
require "iot/service"
|
10
|
+
require "iot/characteristic"
|
11
|
+
require "iot/devicename"
|
12
|
+
require "iot/mkhex"
|
13
|
+
|
14
|
+
module Iot
|
15
|
+
extend Iot::Help
|
16
|
+
extend Iot::Install
|
17
|
+
extend Iot::New
|
18
|
+
extend Iot::Run
|
19
|
+
extend Iot::Generate
|
20
|
+
extend Iot::Destroy
|
21
|
+
extend Iot::Stats
|
22
|
+
extend Iot::Service
|
23
|
+
extend Iot::Characteristic
|
24
|
+
extend Iot::DeviceName
|
25
|
+
extend Iot::Mkhex
|
26
|
+
|
27
|
+
def showUsage commands
|
28
|
+
puts "usage:"
|
29
|
+
commands.each do |cmd|
|
30
|
+
puts " #{cmd[0]}\t#{cmd[1]}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
Yaml_path = "ble.yml"
|
4
|
+
|
5
|
+
module Iot
|
6
|
+
module BleYamlParser
|
7
|
+
|
8
|
+
def load_deviceinfo
|
9
|
+
# TODO
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_yaml_body
|
13
|
+
yaml_path = File.expand_path Yaml_path
|
14
|
+
|
15
|
+
if File.exist? yaml_path
|
16
|
+
yaml_body = File.read yaml_path
|
17
|
+
return YAML.load yaml_body
|
18
|
+
else
|
19
|
+
return ""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def refresh_yaml_body yaml
|
24
|
+
yaml_path = File.expand_path Yaml_path
|
25
|
+
File.open(yaml_path, "w") do |file|
|
26
|
+
file = nil
|
27
|
+
end
|
28
|
+
new_yaml= YAML.dump yaml
|
29
|
+
File.write(yaml_path, new_yaml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def service_exist?(services, service_name)
|
33
|
+
services.each do |service|
|
34
|
+
if service["name"] == service_name
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "iot/bleyamlparser"
|
3
|
+
|
4
|
+
module Iot
|
5
|
+
module Characteristic
|
6
|
+
|
7
|
+
def char
|
8
|
+
yaml = load_yaml_body
|
9
|
+
|
10
|
+
deviceinfo = yaml["deviceinfo"]
|
11
|
+
services = deviceinfo["services"]
|
12
|
+
|
13
|
+
char_count = 0
|
14
|
+
services.each do |service|
|
15
|
+
puts "#{service["name"]}"
|
16
|
+
|
17
|
+
chars = service["chars"]
|
18
|
+
chars.each do |char|
|
19
|
+
puts "#{char_count += 1}\t#{char["uuid"]}\t#{char["name"]}"
|
20
|
+
end
|
21
|
+
|
22
|
+
puts ""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/iot/destroy.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "pp"
|
3
|
+
|
4
|
+
module Iot
|
5
|
+
module Destroy
|
6
|
+
|
7
|
+
def destroy(destroy_type, name)
|
8
|
+
if destroy_type == "service"
|
9
|
+
destroy_service name
|
10
|
+
elsif destroy_type == "characteristic"
|
11
|
+
destroy_characteristic name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy_characteristic char_name
|
16
|
+
yaml = load_yaml_body
|
17
|
+
if yaml.empty?
|
18
|
+
puts "No Yaml file"
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
deviceinfo = yaml["deviceinfo"]
|
23
|
+
services = deviceinfo["services"]
|
24
|
+
|
25
|
+
services.each do |service|
|
26
|
+
chars = service["chars"]
|
27
|
+
|
28
|
+
chars.each do |characteristic|
|
29
|
+
if characteristic["name"] == char_name
|
30
|
+
chars.delete characteristic
|
31
|
+
puts "Destroy characteristic: #{char_name}"
|
32
|
+
|
33
|
+
refresh_yaml_body yaml
|
34
|
+
puts yaml
|
35
|
+
return
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "No such service: #{char_name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy_service service_name
|
44
|
+
yaml = load_yaml_body
|
45
|
+
if yaml.empty?
|
46
|
+
puts "No Yaml file"
|
47
|
+
return
|
48
|
+
end
|
49
|
+
|
50
|
+
deviceinfo = yaml["deviceinfo"]
|
51
|
+
services = deviceinfo["services"]
|
52
|
+
|
53
|
+
services.each do |service|
|
54
|
+
if service["name"] == service_name
|
55
|
+
services.delete service
|
56
|
+
puts "Destory service: #{service_name}"
|
57
|
+
|
58
|
+
# YAMLファイルの内容をサービスを追加したものに変更
|
59
|
+
refresh_yaml_body yaml
|
60
|
+
puts yaml
|
61
|
+
return
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "No such service: #{service_name}"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module Iot
|
3
|
+
module DeviceName
|
4
|
+
|
5
|
+
def toggle_local_name
|
6
|
+
yaml = load_yaml_body
|
7
|
+
if yaml.empty?
|
8
|
+
puts "No Yaml file"
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
deviceinfo = yaml["deviceinfo"]
|
13
|
+
deviceinfo["adpacket"]["localname"] = 1 - deviceinfo["adpacket"]["localname"].to_i
|
14
|
+
|
15
|
+
if deviceinfo["adpacket"]["localname"] > 0
|
16
|
+
puts "Short name is selected for advertising packet"
|
17
|
+
else
|
18
|
+
puts "Complete name is selected for advertising packet"
|
19
|
+
end
|
20
|
+
|
21
|
+
refresh_yaml_body yaml
|
22
|
+
end
|
23
|
+
|
24
|
+
def change_complete_name device_name
|
25
|
+
change_name("name", device_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def change_short_name device_name
|
29
|
+
change_name("shortname", device_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def change_name(key, device_name)
|
33
|
+
yaml = load_yaml_body
|
34
|
+
if yaml.empty?
|
35
|
+
puts "No Yaml file"
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
deviceinfo = yaml["deviceinfo"]
|
40
|
+
deviceinfo[key] = device_name
|
41
|
+
|
42
|
+
refresh_yaml_body yaml
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/iot/generate.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "yaml"
|
3
|
+
require "securerandom"
|
4
|
+
require "iot/bleyamlparser"
|
5
|
+
require "pp"
|
6
|
+
|
7
|
+
module Iot
|
8
|
+
extend BleYamlParser
|
9
|
+
module Generate
|
10
|
+
def generate(generate_type, name)
|
11
|
+
if generate_type.empty?
|
12
|
+
puts "Select type \"service\" or \"char\""
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
if name.empty?
|
17
|
+
puts "Select service / char name"
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
if generate_type == "service"
|
22
|
+
generate_service name
|
23
|
+
elsif generate_type == "char"
|
24
|
+
generate_char name
|
25
|
+
else
|
26
|
+
puts "Select type \"service\" or \"char\""
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_char char_name
|
31
|
+
yaml = load_yaml_body
|
32
|
+
if yaml.empty?
|
33
|
+
puts "No Yaml file"
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
deviceinfo = yaml["deviceinfo"]
|
38
|
+
services = deviceinfo["services"]
|
39
|
+
|
40
|
+
puts "#{deviceinfo["name"]} has bellow services."
|
41
|
+
service_num = 0
|
42
|
+
services.each do |service|
|
43
|
+
puts "[#{service_num += 1}]\t#{service["uuid"]}\t#{service["name"]}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Choose target service
|
47
|
+
while true do
|
48
|
+
puts ""
|
49
|
+
puts "Choose an index of target service"
|
50
|
+
print "> "
|
51
|
+
service_index = STDIN.gets
|
52
|
+
service_index = service_index.chomp.to_i
|
53
|
+
|
54
|
+
if service_index > 0 && service_index <= service_num
|
55
|
+
break
|
56
|
+
end
|
57
|
+
|
58
|
+
puts "#{service_index} is invalid index number"
|
59
|
+
end
|
60
|
+
|
61
|
+
# select property of gatt characteristic
|
62
|
+
properties = []
|
63
|
+
["read", "write", "notify"].each do |property|
|
64
|
+
while true do
|
65
|
+
puts ""
|
66
|
+
puts "Add \"#{property}\" property?(Type y / n)"
|
67
|
+
print "> "
|
68
|
+
|
69
|
+
selection = STDIN.gets.chomp
|
70
|
+
if selection == "y"
|
71
|
+
properties << property
|
72
|
+
break
|
73
|
+
elsif selection == "n"
|
74
|
+
break
|
75
|
+
else
|
76
|
+
puts "Type \"y\" or \"n\""
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Add new characteristic
|
82
|
+
target_service = services[service_index - 1]
|
83
|
+
new_char = {
|
84
|
+
"name" => char_name,
|
85
|
+
"uuid" => SecureRandom.uuid,
|
86
|
+
"payload" => 0,
|
87
|
+
"properties" => properties
|
88
|
+
}
|
89
|
+
chars = target_service["chars"]
|
90
|
+
if chars == nil
|
91
|
+
chars = []
|
92
|
+
end
|
93
|
+
chars << new_char
|
94
|
+
|
95
|
+
# Rewrite the yaml file
|
96
|
+
target_service["chars"] = chars
|
97
|
+
refresh_yaml_body yaml
|
98
|
+
pp yaml
|
99
|
+
end
|
100
|
+
|
101
|
+
def generate_service service_name
|
102
|
+
yaml = load_yaml_body
|
103
|
+
if yaml.empty?
|
104
|
+
puts "No Yaml file"
|
105
|
+
return
|
106
|
+
end
|
107
|
+
|
108
|
+
deviceinfo = yaml["deviceinfo"]
|
109
|
+
services = deviceinfo["services"]
|
110
|
+
|
111
|
+
# サービスの名前が重複していないかを確認
|
112
|
+
unless services == nil
|
113
|
+
if service_exist?(services, service_name)
|
114
|
+
puts "#{service_name} already exist"
|
115
|
+
return
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# サービスを追加
|
120
|
+
new_service = {
|
121
|
+
"name" => service_name,
|
122
|
+
"uuid" => SecureRandom.uuid,
|
123
|
+
"chars" => nil
|
124
|
+
}
|
125
|
+
if services == nil
|
126
|
+
deviceinfo["services"] = []
|
127
|
+
services = deviceinfo["services"]
|
128
|
+
end
|
129
|
+
services << new_service
|
130
|
+
|
131
|
+
# YAMLファイルの内容をサービスを追加したものに変更
|
132
|
+
refresh_yaml_body yaml
|
133
|
+
pp yaml
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|