iremocon_control 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 565b087e857108a61b08f0a3cdaef677bac979da
4
+ data.tar.gz: 077de46e117014eb7800135279591739c26f5c44
5
+ SHA512:
6
+ metadata.gz: 2a171a8b08a261274d37d74beae572743a4e891b330e0085b278c3984f3124a0da11c7e70ca71c517788baf10e8e3a8882220785e45caedfd84bce81bf464426
7
+ data.tar.gz: 66150d122b6a7069020977f146aace599fa51ceaccc78c276140c4c981e10c10ba8dc622106a4833cceed72628e1f1ecaf8a0298a1d044d2a31ab3cb44b267b0
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iremocon_control.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 YutaTanaka
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,29 @@
1
+ # IremoconControl
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'iremocon_control'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install iremocon_control
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/iremocon_control/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/iremocon ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ require 'iremocon_control'
5
+ require 'optparse'
6
+ require 'yaml'
7
+
8
+ Version = IRemoconControl::VERSION
9
+
10
+ def main
11
+ #ポートはデフォルトで51013
12
+ host, port, method = nil, 51013, :is
13
+
14
+ #デフォルトで ~/.iremoconrc を読み込む
15
+ conf = YAML.load_file(File.expand_path("~/.iremoconrc")) rescue nil
16
+ if conf
17
+ host = conf["host"] if conf["host"]
18
+ port = conf["port"] if conf["port"]
19
+ end
20
+
21
+ # オプションの解析
22
+ opt = OptionParser.new
23
+
24
+ # 設定ファイルの指定
25
+ opt.on('-f FILE', '--file=FILE', '読み込む設定ファイルの指定') do |f|
26
+ begin
27
+ conf = YAML.load_file(File.expand_path(f))
28
+ rescue
29
+ STDERR.puts "file [#{f}] doesn't exist or isn't YAML file."
30
+ exit
31
+ end
32
+ host = conf["host"] if conf["host"]
33
+ port = conf["port"] if conf["port"]
34
+ end
35
+
36
+ # ホスト名指定
37
+ opt.on('-h HOST', '--host=HOST', 'iremoconのホスト名') do |h|
38
+ host = h
39
+ end
40
+
41
+ # ポート番号指定
42
+ opt.on('-p PORT', '--port=PORT', 'iremoconのポート番号(デフォルト:51013)') do |p|
43
+ port = p.to_i
44
+ end
45
+
46
+ # コマンドの指定
47
+ opt.on('--au', 'iremoconとの接続の確認') { method = :au } # 接続の確認
48
+ opt.on('--ts', 'iremoconの現在時刻設定') { method = :ts } # 現在時刻設定
49
+ opt.on('--tg', 'iremoconの現在時刻取得') { method = :tg } # 現在時刻取得
50
+ opt.on('--vr', 'iremoconのバージョン取得') { method = :vr } # バージョン取得
51
+ opt.on('--is', 'iremoconから赤外線送信(デフォルト)') { method = :is } # 赤外線送信(デフォルト)
52
+
53
+ opt.parse!(ARGV)
54
+
55
+ ir = IRemoconControl::IRemocon.new(host, port, logger:STDERR)
56
+
57
+ # 引数の数チェック
58
+ method_args = ir.method(method).parameters
59
+ if ARGV.size != method_args.size
60
+ puts "Command [#{method}] needs #{method_args.size} params"
61
+ exit
62
+ end
63
+
64
+ # コマンド送信
65
+ puts ir.send(method, *ARGV) rescue nil
66
+ end
67
+
68
+ main if __FILE__ == $0
69
+
70
+ # vim: sw=2 ts=2 sts=2 et
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iremocon_control/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iremocon_control"
8
+ spec.version = IRemoconControl::VERSION
9
+ spec.authors = ["YutaTanaka"]
10
+ spec.email = ["yuta84q.ihcarok@gmail.com"]
11
+ spec.summary = "send commands to iremocon"
12
+ spec.description = "send commands to iremocon"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = nil
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,29 @@
1
+ #encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ module IRemoconControl
6
+ class IRemoconError < StandardError
7
+ FILE = File.expand_path(File.dirname(__FILE__)) + "/iremocon_error.yml"
8
+ DEF = YAML.load_file(FILE)
9
+
10
+ attr_reader :command, :code, :description
11
+
12
+ def initialize(command, code)
13
+ raise if DEF[@command]
14
+ @command, @code = command, code
15
+ @desctiption = DEF[@command][@code]
16
+ @desctiption ||= DEF["common"][@code]
17
+ end
18
+
19
+ def to_s
20
+ @desctiption
21
+ end
22
+
23
+ def inspect
24
+ "[#{@command}-#{@code}] #{@desctiption}"
25
+ end
26
+ end
27
+ end
28
+
29
+ # vim: sw=2 ts=2 sts=2 et
@@ -0,0 +1,32 @@
1
+ common:
2
+ "010": "フォーマットエラー"
3
+ "020": "タイムアウトエラー"
4
+ au:
5
+ is:
6
+ "001": "リモコン番号範囲外"
7
+ "002": "リモコンデータ未登録"
8
+ "003": "送信エラー"
9
+ ic:
10
+ "001": "リモコン番号範囲外"
11
+ "002": "キャンセル"
12
+ "003": "受信エラー"
13
+ cc:
14
+ "001": "実行エラー"
15
+ tm:
16
+ "001": "リモコン番号範囲外"
17
+ "002": "実行時間範囲外エラー"
18
+ "003": "繰り返し時間範囲外エラー"
19
+ "004": "2重登録エラー(同一時間あり)"
20
+ "005": "登録数オーバーエラー"
21
+ "006": "リモコンデータエラー"
22
+ tl:
23
+ "001": "タイマー登録なし"
24
+ td:
25
+ "001": "タイマー番号範囲外エラー"
26
+ "002": "タイマー登録なし"
27
+ ts:
28
+ "001": "設定時間範囲外エラー"
29
+ tg:
30
+ vr:
31
+
32
+ # vim": set ts=2 sts=2 sw=2 :
@@ -0,0 +1,3 @@
1
+ module IRemoconControl
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,155 @@
1
+ #encoding: utf-8
2
+
3
+ require 'net/telnet'
4
+ require 'logger'
5
+ require_relative 'iremocon_control/iremocon_error.rb'
6
+ require_relative 'iremocon_control/version.rb'
7
+
8
+ module IRemoconControl
9
+
10
+ #
11
+ # iRemoconを操作するクラス
12
+ #
13
+ class IRemocon
14
+ attr_reader :host, :port, :logger
15
+
16
+ #
17
+ # コンストラクタ
18
+ #
19
+ def initialize(host, port=51013, logger:nil)
20
+ @host = host
21
+ @port = port.to_i
22
+ @logger = (logger.is_a?(Logger) ? logger : Logger.new(logger))
23
+ @logger.level = Logger::WARN
24
+ end
25
+
26
+ #
27
+ # 接続の確認用コマンド
28
+ #
29
+ def au
30
+ reply = send_cmd("*au")
31
+ true
32
+ end
33
+
34
+ #
35
+ # 赤外線発光用コマンド
36
+ #
37
+ def is(remocon_id)
38
+ reply = send_cmd("*is", remocon_id)
39
+ true
40
+ end
41
+
42
+ #
43
+ # リモコン学習開始用コマンド
44
+ #
45
+ def ic(remocon_id)
46
+ reply = send_cmd("*ic", remocon_id)
47
+ true
48
+ end
49
+
50
+ #
51
+ # リモコン学習中止用コマンド
52
+ #
53
+ def cc
54
+ reply = send_cmd("*cc")
55
+ true
56
+ end
57
+
58
+ #
59
+ # タイマーセット用コマンド
60
+ #
61
+ def tm(remocon_id, time, repeat_interval = 0)
62
+ reply = send_cmd("*tm", remocon_id, time.to_i, repeat_interval)
63
+ true
64
+ end
65
+
66
+ #
67
+ # タイマー一覧取得用コマンド
68
+ #
69
+ def tl
70
+ reply = send_cmd("*tl")
71
+ reply[3..-1].map(&:to_i).each_slice(4).to_a
72
+ end
73
+
74
+ #
75
+ # タイマー解除用コマンド
76
+ #
77
+ def td(timer_id)
78
+ reply = send_cmd("*td", timer_id)
79
+ true
80
+ end
81
+
82
+ #
83
+ # 現在時刻設定用コマンド
84
+ #
85
+ def ts(time)
86
+ reply = send_cmd("*ts", time.to_i)
87
+ true
88
+ end
89
+
90
+ #
91
+ # 現在時刻取得用コマンド
92
+ #
93
+ def tg
94
+ reply = send_cmd("*tg")
95
+ reply[2].to_i
96
+ end
97
+
98
+ #
99
+ # ファームバージョン番号の取得用コマンド
100
+ #
101
+ def vr
102
+ reply = send_cmd("*vr")
103
+ reply[0]
104
+ end
105
+
106
+ private
107
+
108
+ def send_cmd(*cmds)
109
+ begin
110
+ reply = _send_cmd(*cmds)
111
+ rescue => e
112
+ @logger.warn "#{cmds} -> #{e}"
113
+ raise e
114
+ end
115
+
116
+ if error? reply
117
+ error = get_error reply
118
+ @logger.warn "#{cmds} -> #{error}"
119
+ raise error
120
+ else
121
+ @logger.info "#{cmds} -> #{reply}"
122
+ end
123
+ reply
124
+ end
125
+
126
+ def _send_cmd(*cmds)
127
+ begin
128
+ telnet = Net::Telnet.new('Host' => @host, 'Port' => @port)
129
+ rescue
130
+ raise StandardError.new("IRemocon Connection Error - #{@host}:#{port}")
131
+ end
132
+
133
+ code = ""
134
+ telnet.cmd(cmds.join(";")) do |res|
135
+ code << res;
136
+ break if res =~ /\n$/
137
+ end
138
+
139
+ telnet.close
140
+ return code.chomp.split(";")
141
+ end
142
+
143
+ def error?(reply)
144
+ reply[1] == "err"
145
+ end
146
+
147
+ def get_error(reply)
148
+ cmd = reply[0]
149
+ err_no = reply[2]
150
+ return IRemoconError.new cmd, err_no
151
+ end
152
+ end
153
+ end
154
+
155
+ # vim: sw=2 ts=2 sts=2 et
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe IremoconControl do
4
+ it 'has a version number' do
5
+ expect(IremoconControl::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'iremocon_control'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iremocon_control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - YutaTanaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: send commands to iremocon
56
+ email:
57
+ - yuta84q.ihcarok@gmail.com
58
+ executables:
59
+ - iremocon
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/iremocon
71
+ - iremocon_control.gemspec
72
+ - lib/iremocon_control.rb
73
+ - lib/iremocon_control/iremocon_error.rb
74
+ - lib/iremocon_control/iremocon_error.yml
75
+ - lib/iremocon_control/version.rb
76
+ - spec/iremocon_control_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: ''
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: send commands to iremocon
102
+ test_files: []