pj_link 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aec09d81bcdea4646f9990366f1888025d995798
4
+ data.tar.gz: 097dfeaa7039e099bb58e604aaaee09e5208ab02
5
+ SHA512:
6
+ metadata.gz: 78e73f0b3b90a10252254a0a6a0ed52488c047a8259603dff64d19d8cca67f8904527d5bf35ea8aa12950c907ad6f7c7447f97040a41863296da5b9fe5906e81
7
+ data.tar.gz: a898627e00ba60a726bc33ed90cd5f5b758af72621623e93073a309b5c15d24859c5b1971f0c07096972a61483b3c932c833067375eb0b626bc35ecf5dca0260
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pjlink.gemspec
4
+ gemspec
5
+
6
+
7
+ group [:development, :test] do
8
+ gem 'rspec'
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brian Goff
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.
@@ -0,0 +1,57 @@
1
+ # PjLink
2
+
3
+ A simple library for communicating over the PJLink protocol
4
+
5
+ Based off of initial work by @macprince:
6
+ https://github.com/macprince/ruby-pjlink
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'pj_link'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install pj_link
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ projector = PjLink::Client.new '1.1.1.1', 'super_secret_password'
26
+ projector.power_status
27
+ ```
28
+
29
+ You can also use this without a password if your projector allows you too.
30
+
31
+ Available commands are:
32
+ - power_on
33
+ - power_off
34
+ - power_status
35
+ - video_mute_on
36
+ - video_mute_off
37
+ - mute_on
38
+ - mute_off
39
+ - av_mute_on
40
+ - av_mute_off
41
+ - inputs
42
+ - set_input
43
+ - mute_status
44
+ - lamp_hours
45
+ - device_name
46
+ - manufacturer
47
+ - product
48
+ - pjlink_class
49
+ - other_info
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require "pj_link/version"
2
+ require 'pj_link/client'
3
+
4
+
5
+ module PjLink
6
+ end
@@ -0,0 +1,160 @@
1
+ require 'net/telnet'
2
+ require 'digest/md5'
3
+
4
+ module PjLink
5
+ class Client
6
+ attr_accessor :gateway, :password
7
+
8
+ def initialize(address, password=nil)
9
+ @gateway = Gateway.new(*address.split(':'))
10
+ @password = password
11
+ end
12
+
13
+ def command(cmd)
14
+ gateway.send_message(cmd, @password)
15
+ end
16
+
17
+ def power_on
18
+ command 'POWR 1'
19
+ end
20
+
21
+ def power_off
22
+ command 'POWR 0'
23
+ end
24
+
25
+ def power_status
26
+ command('POWR ?').to_i
27
+ end
28
+
29
+ def video_mute_on
30
+ command 'AVMT 11'
31
+ end
32
+
33
+ def video_mute_off
34
+ command 'AVMT 10'
35
+ end
36
+
37
+ def mute_on
38
+ command 'AVMT 21'
39
+ end
40
+
41
+ def mute_off
42
+ command 'AVMT 20'
43
+ end
44
+
45
+ def av_mute_on
46
+ command 'AVMT 31'
47
+ end
48
+
49
+ def av_mute_off
50
+ command 'AVMT 30'
51
+ end
52
+
53
+ def inputs
54
+ command('INST ?').split.sort
55
+ end
56
+
57
+ def set_input(input)
58
+ command "INPT #{input}"
59
+ end
60
+
61
+ def mute_status
62
+ command('AVMT ?').to_i
63
+ end
64
+
65
+ def lamp_hours
66
+ command('LAMP ?').split.map(&:to_i)
67
+ end
68
+
69
+ def device_name
70
+ command 'NAME ?'
71
+ end
72
+
73
+ def manufacturer
74
+ command 'INF1 ?'
75
+ end
76
+
77
+ def product
78
+ command 'INF2 ?'
79
+ end
80
+
81
+ def pjlink_class
82
+ command 'CLSS ?'
83
+ end
84
+
85
+ def other_info
86
+ command 'INFO ?'
87
+ end
88
+
89
+ class Gateway
90
+ class ::PjLink::Client::PasswordRequiredError < StandardError; end
91
+ DEFAULT_PORT = 4352
92
+
93
+ attr_reader :connection, :connection_key, :port, :address
94
+
95
+ def initialize(address, port=DEFAULT_PORT)
96
+ @address, @port = address, port.to_i
97
+ end
98
+
99
+ def send_message(message, password)
100
+ retry_count = 0
101
+ begin
102
+ connect(password)
103
+ @connection.write("#{@password_hash}%1#{message}\r")
104
+ response = @connection.waitfor("Prompt" => /%1/).
105
+ gsub(/^.*=/, "")
106
+
107
+ response
108
+ rescue Errno::EPIPE
109
+ if retry_count < 4
110
+ disconnect
111
+ retry_count += 1
112
+ retry
113
+ else
114
+ raise
115
+ end
116
+ rescue Net::ReadTimeout
117
+ raise PasswordRequiredError,
118
+ "You must provide a password to access this device"
119
+ ensure
120
+ disconnect
121
+ end
122
+ end
123
+ private
124
+ def connect(password)
125
+ retry_count = 0
126
+ begin
127
+ @connection = Net::Telnet.new(
128
+ 'Host' => @address,
129
+ 'Port' => @port,
130
+ 'Telnetmode' => false,
131
+ 'Promp' => /%1/)
132
+ _, auth_required, key = *@connection.sock.recvmsg[0].split
133
+ rescue Errno::ECONNRESET
134
+ if retry_count < 4
135
+ retry_count += 1
136
+ sleep 1
137
+ retry
138
+ else
139
+ raise
140
+ end
141
+ end
142
+
143
+ @password_hash = Digest::MD5.hexdigest("#{key}#{password}") if auth_required
144
+ self
145
+ end
146
+
147
+ def disconnect
148
+ begin
149
+ @connection.close if @connection
150
+ rescue IOError; nil
151
+ ensure
152
+ @connection = nil
153
+ end
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+ end
160
+
@@ -0,0 +1,3 @@
1
+ module PjLink
2
+ VERSION = "1.0.0"
3
+ end
@@ -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 'pj_link/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pj_link"
8
+ spec.version = PjLink::VERSION
9
+ spec.authors = ["Brian Goff"]
10
+ spec.email = ["cpuguy83@gmail.com"]
11
+ spec.description = %q{A simple library for communicating over the PjLink protocol}
12
+ spec.summary = %q{A simple library for communicating over the PjLink protocol}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module PjLink
4
+ describe Client do
5
+ context 'a port is provided' do
6
+ it 'accepts ADDRESS:PORT notation' do
7
+ client = Client.new('0.0.0.0:1000')
8
+
9
+ expect(client.gateway.port).to eq 1000
10
+ end
11
+ end
12
+
13
+ context 'no port is provided' do
14
+ describe Client::Gateway do
15
+ it 'assigns a default port when no port is given' do
16
+ gateway = Client::Gateway.new '0.0.0.0'
17
+
18
+ expect(gateway.port).
19
+ to eq Client::Gateway::DEFAULT_PORT
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ require 'pj_link'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pj_link
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Goff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-25 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ description: A simple library for communicating over the PjLink protocol
42
+ email:
43
+ - cpuguy83@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/pj_link.rb
54
+ - lib/pj_link/client.rb
55
+ - lib/pj_link/version.rb
56
+ - pj_link.gemspec
57
+ - spec/client.rb
58
+ - spec/spec_helper.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A simple library for communicating over the PjLink protocol
83
+ test_files:
84
+ - spec/client.rb
85
+ - spec/spec_helper.rb