sappho-heatmiser-proxy 0.0.8 → 0.0.9
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.
@@ -19,15 +19,13 @@ module Sappho
|
|
19
19
|
def initialize
|
20
20
|
@mutex = Mutex.new
|
21
21
|
@clients = {}
|
22
|
-
@max = Integer SystemConfiguration.instance.config['heatmiser.clients.max']
|
23
|
-
@log = TraceLog.instance
|
24
22
|
end
|
25
23
|
|
26
24
|
def register client
|
27
25
|
@mutex.synchronize do
|
28
26
|
ip = client.getpeername
|
29
27
|
@clients[client] = ip = (4 ... 8).map{|pos|ip[pos]}.join('.')
|
30
|
-
|
28
|
+
TraceLog.instance.info "client #{ip} connected"
|
31
29
|
log
|
32
30
|
end
|
33
31
|
end
|
@@ -36,7 +34,7 @@ module Sappho
|
|
36
34
|
@mutex.synchronize do
|
37
35
|
ip = @clients[client]
|
38
36
|
@clients.delete client
|
39
|
-
|
37
|
+
TraceLog.instance.info "client #{ip} disconnected"
|
40
38
|
log
|
41
39
|
end
|
42
40
|
end
|
@@ -46,13 +44,14 @@ module Sappho
|
|
46
44
|
end
|
47
45
|
|
48
46
|
def maxAlreadyConnected?
|
49
|
-
@mutex.synchronize { @clients.size >=
|
47
|
+
@mutex.synchronize { @clients.size >= SystemConfiguration.instance.maxClients }
|
50
48
|
end
|
51
49
|
|
52
50
|
private
|
53
51
|
|
54
52
|
def log
|
55
|
-
|
53
|
+
TraceLog.instance.info "clients: #{@clients.size > 0 ?
|
54
|
+
(@clients.collect{|client, ip| ip}).join(', ') : 'none'}"
|
56
55
|
end
|
57
56
|
|
58
57
|
end
|
@@ -22,69 +22,80 @@ module Sappho
|
|
22
22
|
queue = CommandQueue.instance
|
23
23
|
log = TraceLog.instance
|
24
24
|
config = SystemConfiguration.instance
|
25
|
-
|
25
|
+
desc = "heatmiser at #{config.heatmiserHostname}:#{config.heatmiserPort}"
|
26
26
|
queryCommand = HeatmiserCRC.new([0x93, 0x0B, 0x00, config.pinLo, config.pinHi, 0x00, 0x00, 0xFF, 0xFF]).appendCRC
|
27
27
|
loop do
|
28
|
-
|
28
|
+
log.info "opening connection to #{desc}"
|
29
|
+
socket = nil
|
29
30
|
begin
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
31
|
+
timeout 5 do
|
32
|
+
socket = TCPSocket.open config.heatmiserHostname, config.heatmiserPort
|
33
|
+
end
|
34
|
+
log.info "connected to #{desc}"
|
35
|
+
rescue Timeout::Error
|
36
|
+
log.info "timeout while connecting to #{desc}"
|
37
|
+
rescue => error
|
38
|
+
log.error error
|
39
|
+
end
|
40
|
+
if socket
|
41
|
+
active = true
|
42
|
+
while active do
|
43
|
+
begin
|
44
|
+
sleep 5
|
45
|
+
command = queryCommand
|
46
|
+
if queuedCommand = queue.get
|
47
|
+
command = queuedCommand
|
48
|
+
else
|
49
|
+
if status.get{status.valid ? status.deviceTimeOffset : 0.0}.abs > 5.0
|
50
|
+
timeNow = Time.now
|
51
|
+
dayOfWeek = timeNow.wday
|
52
|
+
dayOfWeek = 7 if dayOfWeek == 0
|
53
|
+
command = HeatmiserCRC.new([0xA3, 0x12, 0x00, config.pinLo, config.pinHi, 0x01, 0x2B, 0x00, 0x07,
|
54
|
+
timeNow.year - 2000,
|
55
|
+
timeNow.month,
|
56
|
+
timeNow.day,
|
57
|
+
dayOfWeek,
|
58
|
+
timeNow.hour,
|
59
|
+
timeNow.min,
|
60
|
+
timeNow.sec]).appendCRC
|
61
|
+
log.info "clock correction: #{TraceLog.hex command}"
|
61
62
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
end
|
64
|
+
log.debug "sending command: #{TraceLog.hex command}" if log.debug?
|
65
|
+
reply = []
|
66
|
+
startTime = Time.now
|
67
|
+
timeout 20 do
|
68
|
+
socket.write command.pack('c*')
|
69
|
+
reply = socket.read(81).unpack('c*')
|
70
|
+
end
|
71
|
+
timestamp = Time.now
|
72
|
+
log.debug "reply: #{TraceLog.hex reply}" if log.debug?
|
73
|
+
crcHi = reply.pop & 0xFF
|
74
|
+
crcLo = reply.pop & 0xFF
|
75
|
+
crc = HeatmiserCRC.new reply
|
76
|
+
if (reply[0] & 0xFF) == 0x94 and reply[1] == 0x51 and reply[2] == 0 and
|
77
|
+
crc.crcHi == crcHi and crc.crcLo == crcLo
|
78
|
+
reply << crcLo << crcHi
|
79
|
+
status.set reply, timestamp, (timestamp - startTime) do
|
80
|
+
queue.completed if queuedCommand
|
73
81
|
end
|
74
|
-
rescue Timeout::Error
|
75
|
-
log.info "heatmiser at #{hostname}:#{config.port} is not responding - assuming connection down"
|
76
|
-
break
|
77
|
-
rescue => error
|
78
|
-
log.error error
|
79
|
-
break
|
80
82
|
end
|
83
|
+
rescue Timeout::Error
|
84
|
+
log.info "#{desc} is not responding - assuming connection down"
|
85
|
+
active = false
|
86
|
+
rescue => error
|
87
|
+
log.error error
|
88
|
+
active = false
|
81
89
|
end
|
82
|
-
|
90
|
+
end
|
91
|
+
status.invalidate
|
92
|
+
begin
|
83
93
|
socket.close
|
94
|
+
rescue
|
84
95
|
end
|
85
|
-
|
86
|
-
log.error error
|
96
|
+
log.info "closed connection to #{desc}"
|
87
97
|
end
|
98
|
+
log.info "waiting 10 seconds before attempting to re-connect to #{desc}"
|
88
99
|
sleep 10
|
89
100
|
end
|
90
101
|
end
|
@@ -14,14 +14,16 @@ module Sappho
|
|
14
14
|
|
15
15
|
include Singleton
|
16
16
|
|
17
|
-
attr_reader :
|
17
|
+
attr_reader :heatmiserHostname, :heatmiserPort, :pinLo, :pinHi, :maxClients
|
18
18
|
|
19
19
|
def initialize
|
20
|
-
|
21
|
-
@
|
22
|
-
|
20
|
+
data = YAML.load_file(File.expand_path(ARGV[0] || 'heatmiser-proxy.yml'))
|
21
|
+
@heatmiserHostname = data['heatmiser.address']
|
22
|
+
@heatmiserPort = Integer data['heatmiser.port']
|
23
|
+
pin = Integer data['heatmiser.pin']
|
23
24
|
@pinLo = pin & 0xFF
|
24
25
|
@pinHi = (pin >> 8) & 0xFF
|
26
|
+
@maxClients = Integer data['clients.max']
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
@@ -6,13 +6,13 @@
|
|
6
6
|
module Sappho
|
7
7
|
module Heatmiser
|
8
8
|
module Proxy
|
9
|
-
NAME =
|
10
|
-
VERSION =
|
11
|
-
AUTHORS = [
|
12
|
-
EMAILS = [
|
13
|
-
HOMEPAGE =
|
14
|
-
SUMMARY =
|
15
|
-
DESCRIPTION =
|
9
|
+
NAME = 'sappho-heatmiser-proxy'
|
10
|
+
VERSION = '0.0.9'
|
11
|
+
AUTHORS = ['Andrew Heald']
|
12
|
+
EMAILS = ['andrew@heald.co.uk']
|
13
|
+
HOMEPAGE = 'https://github.com/sappho/sappho-heatmiser-proxy/wiki'
|
14
|
+
SUMMARY = 'Acts as a proxy for Heatmiser hardware to allow continuous monitoring and control by many controllers'
|
15
|
+
DESCRIPTION = 'See the project home page for more information'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -21,7 +21,7 @@ module Sappho
|
|
21
21
|
TraceLog.instance.info "#{NAME} version #{VERSION} - #{HOMEPAGE}"
|
22
22
|
Thread.new do
|
23
23
|
clients = ClientRegister.instance
|
24
|
-
port = SystemConfiguration.instance.
|
24
|
+
port = SystemConfiguration.instance.heatmiserPort
|
25
25
|
log = TraceLog.instance
|
26
26
|
log.info "opening proxy server port #{port}"
|
27
27
|
TCPServer.open port do | server |
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sappho-heatmiser-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Heald
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02
|
18
|
+
date: 2012-03-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|
@@ -45,7 +45,6 @@ extra_rdoc_files: []
|
|
45
45
|
|
46
46
|
files:
|
47
47
|
- bin/sappho-heatmiser-proxy
|
48
|
-
- lib/sappho-heatmiser-proxy.rb
|
49
48
|
- lib/sappho-heatmiser-proxy/client_register.rb
|
50
49
|
- lib/sappho-heatmiser-proxy/command_queue.rb
|
51
50
|
- lib/sappho-heatmiser-proxy/heatmiser.rb
|
@@ -55,6 +54,7 @@ files:
|
|
55
54
|
- lib/sappho-heatmiser-proxy/system_configuration.rb
|
56
55
|
- lib/sappho-heatmiser-proxy/trace_log.rb
|
57
56
|
- lib/sappho-heatmiser-proxy/version.rb
|
57
|
+
- lib/sappho-heatmiser-proxy.rb
|
58
58
|
homepage: https://github.com/sappho/sappho-heatmiser-proxy/wiki
|
59
59
|
licenses: []
|
60
60
|
|