sappho-heatmiser-proxy 0.1.9 → 0.1.10

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.
@@ -16,27 +16,11 @@ module Sappho
16
16
  include Singleton, Sappho::LogUtilities
17
17
 
18
18
  def initialize
19
- @refreshRequested = false
20
19
  @queue = []
21
20
  @mutex = Mutex.new
22
21
  @log = Sappho::ApplicationAutoFlushLog.instance
23
22
  end
24
23
 
25
- def refreshStatus clientIP
26
- @log.info "client #{clientIP} requests status refresh"
27
- @mutex.synchronize do
28
- @refreshRequested = true
29
- end
30
- end
31
-
32
- def refreshRequested?
33
- @mutex.synchronize do
34
- requested = @refreshRequested
35
- @refreshRequested = false
36
- requested
37
- end
38
- end
39
-
40
24
  def push clientIP, command
41
25
  @log.info "client #{clientIP} requests command: #{hexString command}"
42
26
  @mutex.synchronize do
@@ -26,6 +26,7 @@ module Sappho
26
26
  desc = "heatmiser at #{config.heatmiserHostname}:#{config.heatmiserPort}"
27
27
  queryCommand = HeatmiserCRC.new([0x93, 0x0B, 0x00, config.pinLo, config.pinHi, 0x00, 0x00, 0xFF, 0xFF]).appendCRC
28
28
  socket = Sappho::Socket::SafeSocket.new 5
29
+ openPort = true
29
30
  timestamp = Time.now - config.sampleDelay
30
31
  loop do
31
32
  begin
@@ -48,22 +49,21 @@ module Sappho
48
49
  log.info "clock correction: #{hexString command}"
49
50
  end
50
51
  end
51
- refreshRequested = queue.refreshRequested?
52
- clientsActive = yield
53
52
  unless command
54
- command = queryCommand if refreshRequested or clientsActive or (Time.now - timestamp) >= config.sampleDelay
53
+ command = queryCommand if yield or (Time.now - timestamp) >= config.sampleDelay
55
54
  end
56
55
  if command
57
56
  log.debug "sending command: #{hexString command}" if log.debug?
58
- socket.close # just in case it wasn't last time around
59
- socket.open config.heatmiserHostname, config.heatmiserPort
60
- socket.settle 0.01
57
+ if openPort
58
+ openPort = false
59
+ socket.close
60
+ socket.open config.heatmiserHostname, config.heatmiserPort
61
+ socket.settle 1
62
+ end
61
63
  startTime = Time.now
62
64
  socket.write command.pack('c*')
63
65
  reply = socket.read(81).unpack('c*')
64
66
  timestamp = Time.now
65
- socket.settle 0.01
66
- socket.close
67
67
  log.debug "reply: #{hexString reply}" if log.debug?
68
68
  crcHi = reply.pop & 0xFF
69
69
  crcLo = reply.pop & 0xFF
@@ -77,9 +77,11 @@ module Sappho
77
77
  end
78
78
  end
79
79
  rescue Timeout::Error
80
+ openPort = true
80
81
  status.invalidate
81
82
  log.info "#{desc} is not responding - assuming connection down"
82
83
  rescue => error
84
+ openPort = true
83
85
  status.invalidate
84
86
  log.error error
85
87
  end
@@ -23,7 +23,6 @@ module Sappho
23
23
 
24
24
  def communicate
25
25
  queue = CommandQueue.instance
26
- queue.refreshStatus @ip
27
26
  status = HeatmiserStatus.instance
28
27
  config = SystemConfiguration.instance
29
28
  log = Sappho::ApplicationAutoFlushLog.instance
@@ -7,7 +7,7 @@ module Sappho
7
7
  module Heatmiser
8
8
  module Proxy
9
9
  NAME = 'sappho-heatmiser-proxy'
10
- VERSION = '0.1.9'
10
+ VERSION = '0.1.10'
11
11
  AUTHORS = ['Andrew Heald']
12
12
  EMAILS = ['andrew@heald.co.uk']
13
13
  HOMEPAGE = 'https://github.com/sappho/sappho-heatmiser-proxy/wiki'
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: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
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-04-21 00:00:00 Z
18
+ date: 2012-04-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake