teletask 0.0.2
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/lib/constants.rb +37 -0
- data/lib/request.rb +37 -0
- data/lib/response.rb +33 -0
- data/lib/teletask.rb +84 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8350efc1b6d4c835ab2cc2320539fc1ba33d2a10
|
4
|
+
data.tar.gz: 514ce5aaa2c07422c8b9277e11b9e8120d50c161
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 194cd77565b42009579133d36038c74abb3737999c36985800eaf0fb5b4854f2bb7a1265e36d5a668c677d16287167cbc58d7384c16817452da6d6673b9b63e9
|
7
|
+
data.tar.gz: e2f009831ea9c6b9c0298abe94be035de9be905bde7d97df471879e0b6d0cb1aac2b66973273e28b80dbfccdcda4e3455cdd14f35cd3e693705e4ce65bffe34b
|
data/lib/constants.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Teletask
|
2
|
+
module Command
|
3
|
+
SET = 7
|
4
|
+
GET = 6
|
5
|
+
GROUPSET = 9
|
6
|
+
LOG = 3
|
7
|
+
EVENTREPORT = 0x10
|
8
|
+
WRITEDISPLAY = 4
|
9
|
+
KEEPALIVE = 0x11
|
10
|
+
end
|
11
|
+
|
12
|
+
module Function
|
13
|
+
RELAY = 1
|
14
|
+
DIMMER = 2
|
15
|
+
MOTOR = 6
|
16
|
+
LOCALMOOD = 9
|
17
|
+
GENERALMOOD = 10
|
18
|
+
FLAG = 15
|
19
|
+
SENSOR = 20
|
20
|
+
AUDIO = 31
|
21
|
+
PROCESS = 3
|
22
|
+
REGIME = 14
|
23
|
+
SERVICE = 53
|
24
|
+
MESSAGE = 54
|
25
|
+
CONDITION = 60
|
26
|
+
end
|
27
|
+
|
28
|
+
module Setting
|
29
|
+
ON = 255
|
30
|
+
TOGGLE = 103
|
31
|
+
OFF = 0
|
32
|
+
|
33
|
+
MOTORUP = 1
|
34
|
+
MOTORDOWN = 2
|
35
|
+
MOTORSTOP = 3
|
36
|
+
end
|
37
|
+
end
|
data/lib/request.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Request
|
2
|
+
START = 2
|
3
|
+
def initialize command, function = 0, number = 0, setting = nil
|
4
|
+
@command = command
|
5
|
+
@parameters = Array.new
|
6
|
+
|
7
|
+
case command
|
8
|
+
when Teletask::Command::KEEPALIVE
|
9
|
+
when Teletask::Command::LOG
|
10
|
+
@parameters = Array.new
|
11
|
+
@parameters[0] = function
|
12
|
+
@parameters[1] = number
|
13
|
+
else
|
14
|
+
@parameters[0] = 1 #central number
|
15
|
+
@parameters[1] = function
|
16
|
+
@parameters[2] = 0 #byte1
|
17
|
+
@parameters[3] = number #byte2
|
18
|
+
@parameters[4] = setting if setting != nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
#"s,8,7,1,1,0,21,103,143,"
|
24
|
+
request = [START, length, @command] + @parameters + [checksum]
|
25
|
+
request.pack("C*")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def checksum
|
30
|
+
parametersum = @parameters.empty? ? 0 : @parameters.inject{|sum,x| sum + x }
|
31
|
+
return (START + length + @command + parametersum) % 256
|
32
|
+
end
|
33
|
+
|
34
|
+
def length
|
35
|
+
return @parameters.length + 3
|
36
|
+
end
|
37
|
+
end
|
data/lib/response.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Response
|
2
|
+
|
3
|
+
attr_reader :central, :function, :number, :parameters
|
4
|
+
|
5
|
+
def initialize central, function, number, parameters
|
6
|
+
@central, @function, @number, @parameters = central, function, number, parameters
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse data
|
10
|
+
begin
|
11
|
+
data = data.unpack("C*")
|
12
|
+
unless data.first == 10
|
13
|
+
startindex = data.index(2)
|
14
|
+
raise "Start byte not found in Response: #{data.inspect}" unless startindex
|
15
|
+
length = data[startindex+1]
|
16
|
+
calculatedChecksum = data[startindex..startindex+length-1].inject{|sum,x| sum + x } % 256
|
17
|
+
checksum = data[startindex+length]
|
18
|
+
raise "Checksum mismatch. Expecting #{checksum}, but calculated #{calculatedChecksum}" unless checksum == calculatedChecksum
|
19
|
+
raise "Not an response." unless data[startindex+2] == Teletask::Command::EVENTREPORT
|
20
|
+
central = data[startindex+3]
|
21
|
+
function = data[startindex+4]
|
22
|
+
number = data[startindex+5..startindex+6].pack("c*").unpack("n").first
|
23
|
+
parameters =data[startindex+8]
|
24
|
+
return Response.new central, function, number, parameters
|
25
|
+
else
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
rescue Exception => ex
|
29
|
+
puts ex
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/teletask.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'observer'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
require_relative './constants'
|
6
|
+
require_relative './request'
|
7
|
+
require_relative './response'
|
8
|
+
|
9
|
+
class Teletask
|
10
|
+
include Observable
|
11
|
+
|
12
|
+
@host
|
13
|
+
@port
|
14
|
+
@socket
|
15
|
+
@server
|
16
|
+
|
17
|
+
def initialize(host, port = 55957)
|
18
|
+
@host = host
|
19
|
+
@port = port
|
20
|
+
#add_observer(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def finalize
|
24
|
+
close
|
25
|
+
end
|
26
|
+
|
27
|
+
def connect
|
28
|
+
puts "connecting..."
|
29
|
+
@socket = TCPSocket.open @host, @port
|
30
|
+
|
31
|
+
@t = Thread.new{
|
32
|
+
while (data = @socket.recv(1024))
|
33
|
+
response = Response.parse data
|
34
|
+
if response
|
35
|
+
changed
|
36
|
+
notify_observers(self, response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def close()
|
43
|
+
puts "closing connection"
|
44
|
+
@socket.close
|
45
|
+
end
|
46
|
+
|
47
|
+
def keep_alive
|
48
|
+
f = Request.new Command::KEEPALIVE
|
49
|
+
@socket.write f.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def set function, number, setting
|
53
|
+
f = Request.new Command::SET, function, number, setting
|
54
|
+
@socket.write f.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def get function, number
|
58
|
+
f = Request.new Command::GET, function, number
|
59
|
+
@socket.write f.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def group_get
|
63
|
+
raise NotImplementedError.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def log function, setting
|
67
|
+
r = Request.new Command::LOG, function, setting
|
68
|
+
@socket.write r.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def report_event
|
72
|
+
raise NotImplementedError.new
|
73
|
+
end
|
74
|
+
|
75
|
+
def message
|
76
|
+
raise NotImplementedError.new
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class TeleTaskEvent
|
81
|
+
def update object, response
|
82
|
+
puts "Update: #{response.inspect}"
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teletask
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sille Van Landschoot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Teletask gem enables the communication with a Teletask Domitics central
|
14
|
+
using the DoIP protocol
|
15
|
+
email: info@sillevl.be
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/constants.rb
|
21
|
+
- lib/request.rb
|
22
|
+
- lib/response.rb
|
23
|
+
- lib/teletask.rb
|
24
|
+
homepage: http://rubygems.org/gems/teletask
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Teletask DoIP
|
48
|
+
test_files: []
|