gt06_server 0.0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6badba6dc484656af3c748b440f056939d3c805
4
- data.tar.gz: db9fc1cc01be0b01f459f79dcd1e454ae12f8ba3
3
+ metadata.gz: e529d1799f33d8ba12e1236e6811dd265f12196f
4
+ data.tar.gz: 4c78509f1ef0311d99d69c8b52f0592538c269cd
5
5
  SHA512:
6
- metadata.gz: 7d0448a5b3a64627a81d6944afef86858be10818b935513d6754749f7d99b0fd347ac64ede06af5264fbfd140146305f0a3cf3cee1ab173aec841a4ad0a8ca60
7
- data.tar.gz: 9a4dd20d39938f850ac5876d424b583f88a773a5997608cfc7d003d5c2d533bab69dd65fb98644b3fe4d171f42ac3f20621e456b84ff4b9a9dffd7e4ff6b809a
6
+ metadata.gz: bccdc6654fb193367a58f5ae6608355034168dc316cf3f743c7370dcedec8a01e292654d7ed4716d3abd2503a74d72a2026744d82e5c0013581a13f40663b0bc
7
+ data.tar.gz: 8c501ab625004291b3998a301863ec329a03c3d730132abc9db31e90e8fb50a8efe58edd3d8023e71aee810490eb98f29f4d3deeb94aac62dcc83dc2db08872e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gt06_server (0.0.1)
4
+ gt06_server (0.0.2)
5
5
  bindata (~> 2.3)
6
6
  celluloid-io (~> 0.17.3)
7
7
  concurrent-ruby (~> 1.0)
@@ -16,7 +16,7 @@ GEM
16
16
  descendants_tracker (~> 0.0.4)
17
17
  ice_nine (~> 0.11.0)
18
18
  thread_safe (~> 0.3, >= 0.3.1)
19
- bindata (2.3.1)
19
+ bindata (2.3.4)
20
20
  byebug (9.0.5)
21
21
  capistrano (3.5.0)
22
22
  airbrussh (>= 1.0.0)
@@ -148,4 +148,4 @@ DEPENDENCIES
148
148
  rubocop
149
149
 
150
150
  BUNDLED WITH
151
- 1.13.1
151
+ 1.13.6
@@ -13,18 +13,20 @@ require_relative 'messages/gps_query_address'
13
13
  module Gt06Server
14
14
  class TerminalPacket < BinData::Record
15
15
  class << self
16
- attr_accessor :types
17
- end
16
+ attr_reader :types
18
17
 
19
- TerminalPacket.types = {
20
- login_message: 0x01,
21
- location_data: 0x12,
22
- status_information: 0x13,
23
- string_information: 0x15,
24
- alarm_packet: 0x16,
25
- gps_query_address_information: 0x1A,
26
- command_information: 0x80
27
- }
18
+ def types
19
+ {
20
+ login_message: 0x01,
21
+ location_data: 0x12,
22
+ status_information: 0x13,
23
+ string_information: 0x15,
24
+ alarm_packet: 0x16,
25
+ gps_query_address_information: 0x1A,
26
+ command_information: 0x80
27
+ }
28
+ end
29
+ end
28
30
 
29
31
  # Data Packet Format
30
32
  # The communication is transferred asynchronously in bytes.
@@ -32,18 +32,20 @@ module Gt06Server
32
32
  end
33
33
 
34
34
  def initialize(host, port, handler, options: {} )
35
-
36
35
  @logger = options.fetch(:logger, Logger.new(STDOUT))
37
36
  @host = host
38
37
  @port = port
39
38
 
40
39
  @sessions = Concurrent::Map.new
41
40
 
42
- sweeper = SessionSweeper.new(@sessions, options.fetch(:session_timeout, nil), interval: options.fetch(:sweep_interval, nil))
41
+ sweeper = SessionSweeper.new(
42
+ @sessions,
43
+ options.fetch(:session_timeout, nil),
44
+ interval: options.fetch(:sweep_interval, nil),
45
+ logger: @logger
46
+ )
43
47
  sweeper.run
44
48
 
45
- @info = { sweeper_info: sweeper.info }
46
-
47
49
  async.run handler
48
50
  end
49
51
 
@@ -3,10 +3,11 @@ module Gt06Server
3
3
  class Session
4
4
  class SessionError < RuntimeError; end
5
5
 
6
- attr_reader :terminal_id, :io, :info, :logger
6
+ attr_reader :terminal_id, :io, :info, :logger, :addr
7
7
 
8
8
  def initialize(io, logger: Logger.new(STDOUT))
9
9
  @io = io
10
+ @addr = io.peeraddr
10
11
  @terminal_id = ''
11
12
  @info = { received_count: 0, sent_count: 0, last_received_at: Time.now}
12
13
  @logger = logger
@@ -24,6 +25,10 @@ module Gt06Server
24
25
  end
25
26
  end
26
27
 
28
+ def inspect
29
+ "#{object_id} Terminal id:#{@terminal_id}, ip: #{@addr}, #{@info}"
30
+ end
31
+
27
32
  private
28
33
 
29
34
  def handle_head_pack(pack)
@@ -1,13 +1,14 @@
1
1
  require 'concurrent'
2
2
 
3
3
  class SessionSweeper
4
- attr_reader :sessions , :info, :timeout, :interval
4
+ attr_reader :sessions , :info, :timeout, :interval, :logger
5
5
 
6
- def initialize(sessions, timeout = 60, interval: 30)
6
+ def initialize(sessions, timeout = 60, interval: 30, logger: Logger.new(STDOUT))
7
7
  @sessions = sessions
8
8
  @timeout = timeout
9
9
  @interval = interval
10
10
  @info = {killed: 0, live:0, count:0}
11
+ @logger = logger
11
12
  end
12
13
 
13
14
  def run
@@ -17,7 +18,9 @@ class SessionSweeper
17
18
  if (session.info[:last_received_at] + @timeout) < time_now
18
19
  session.io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, [1,0].pack('ii'))
19
20
  session.io.close
20
- puts "Session #{session} has been closed"
21
+
22
+ @logger.debug "Session #{session.inspect} has been closed"
23
+
21
24
  @info[:killed] += 1
22
25
  @sessions.delete(key)
23
26
  end
@@ -25,9 +28,27 @@ class SessionSweeper
25
28
 
26
29
  @info[:live] = @sessions.size
27
30
  @info[:count] += 1
31
+
32
+ @info
28
33
  end
29
34
 
35
+ timer.add_observer(SessionSweeperObserver.new(@logger))
30
36
  timer.execute
31
37
  end
32
38
 
39
+ class SessionSweeperObserver
40
+ def initialize(logger)
41
+ @logger = logger
42
+ end
43
+
44
+ def update(time, result, exception)
45
+ if result
46
+ @logger.info "(#{time}) Execution successfully returned #{result}"
47
+ else
48
+ @logger.error "(#{time}) Execution failed with error #{exception}"
49
+ # Airbrake.notify(exception)
50
+ end
51
+ end
52
+ end
53
+
33
54
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Gt06Server
3
- VERSION = '0.0.2'
3
+ VERSION = '0.1.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gt06_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CoolElvis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-13 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata