sgslib 0.2.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c7ee0414fad3641eb50bf386b9e05b2b4290ac3d
4
- data.tar.gz: aec3efc5d970a7705bc44b90f26e060dd286650a
2
+ SHA256:
3
+ metadata.gz: aaae860efa0ec12d6920ac0c2e7498e52b4c858ebe689f8591416187077c0381
4
+ data.tar.gz: ef31a4d32a397c6c557c389ccf78a2206050a62bd69f10885fd9ff36f9de5014
5
5
  SHA512:
6
- metadata.gz: cf487f698bae00c8c37a2dfd588ab7388bc122afcb312d2a441ba8fc7887cb80a1da80d7d3e2977ed31964fe37c1a6943e40de5931553a62c942b0cbaabc130c
7
- data.tar.gz: db0e9bbfc4fdcd778885dbb30fc2a7f98a8594b5933fcd9e8c681f6853df2f28a0bc99097d41e4b675776d3aff1c04a8f506cc0592bea97e83a28c0cf14fafb6
6
+ metadata.gz: 29df64a13c4e2526137fd7c4c049932f629c5a302285c4d866ee66b239fa7ddd79b816a1e1bb7c120388e71f5d9198c3ebc6bf54f688ef2d48403258f73d5ea2
7
+ data.tar.gz: 90f580001c3cd7377acec7abfd0dcbf66e56601187e42bf10339faa6868bec8ee23e241363828cfe0fb5efa99bfcaebf7bb4d8354269707f0503e89014ac2a15
@@ -97,7 +97,7 @@ module SGS
97
97
  #
98
98
  # Convert an alarm number into a string.
99
99
  def name(alarmno)
100
- MESSAGES[alarmno]
100
+ ALARM_NAMES[alarmno]
101
101
  end
102
102
  end
103
103
  end
@@ -46,7 +46,6 @@ module SGS
46
46
  Otto.setup
47
47
  Timing.setup
48
48
  Waypoint.setup
49
- Mission.setup
50
49
  end
51
50
  end
52
51
  end
@@ -34,7 +34,6 @@ module SGS
34
34
  class RedisBase
35
35
  class << self
36
36
  def redis
37
- puts "Class init"
38
37
  @@redis ||= Redis.new
39
38
  end
40
39
  end
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright (c) 2018, Kalopa Research. All rights reserved. This is free
3
+ # software; you can redistribute it and/or modify it under the terms of the
4
+ # GNU General Public License as published by the Free Software Foundation;
5
+ # either version 2, or (at your option) any later version.
6
+ #
7
+ # It is distributed in the hope that it will be useful, but WITHOUT
8
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10
+ # for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License along
13
+ # with this product; see the file COPYING. If not, write to the Free
14
+ # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH "AS IS" AND ANY EXPRESS OR
17
+ # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
+ # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
+ # IN NO EVENT SHALL KALOPA RESEARCH BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22
+ # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
+ # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ #
27
+
28
+ ##
29
+ # Routines for sending and receiving messages using Redis. Sourced from
30
+ # Anthoni Scotti, https://128bit.io/2014/08/31/rpc-using-redis/
31
+ #
32
+ require 'redis'
33
+ require 'securerandom'
34
+ require 'msgpack'
35
+
36
+ module SGS
37
+ class RPCClient
38
+ def initialize(channel)
39
+ @channel = channel.to_s
40
+ end
41
+
42
+ def method_missing(name, *args)
43
+ uuid = SecureRandom.uuid
44
+ request = {
45
+ 'id' => uuid,
46
+ 'jsonrpc' => '2.0',
47
+ 'method' => name,
48
+ 'params' => args
49
+ }
50
+ SGS::RedisBase.redis.lpush(@channel, request.to_msgpack)
51
+ channel, response = SGS::RedisBase.redis.brpop(uuid, timeout=60)
52
+ MessagePack.unpack(response)['result']
53
+ end
54
+ end
55
+
56
+ class RPCServer
57
+ def initialize(channel, klass)
58
+ @channel = channel.to_s
59
+ @klass = klass
60
+ end
61
+
62
+ def start
63
+ puts "Starting RPC server for #{@channel}"
64
+ loop do
65
+ channel, request = SGS::RedisBase.redis.brpop(@channel)
66
+ request = MessagePack.unpack(request)
67
+
68
+ puts "Working on request: #{request['id']}"
69
+
70
+ args = request['params'].unshift(request['method'])
71
+ result = @klass.send *args
72
+
73
+ reply = {
74
+ 'jsonrpc' => '2.0',
75
+ 'result' => result,
76
+ 'id' => request['id']
77
+ }
78
+
79
+ SGS::RedisBase.redis.rpush(request['id'], MessagePack.pack(reply))
80
+ SGS::RedisBase.redis.expire(request['id'], 30)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,3 +1,3 @@
1
1
  module SGS
2
- VERSION = "0.2.6"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -30,6 +30,7 @@
30
30
  require "sgs/version"
31
31
  require 'sgs/redis_base'
32
32
  require 'sgs/config'
33
+ require 'sgs/rpc'
33
34
  require 'sgs/location'
34
35
  require 'sgs/nmea'
35
36
  require 'sgs/gps'
@@ -33,5 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
 
36
+ spec.add_runtime_dependency "msgpack", "~> 1.3"
37
+
36
38
  spec.add_dependency "redis", "~> 3.3"
37
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sgslib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dermot Tynan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: msgpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: redis
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +109,7 @@ files:
95
109
  - lib/sgs/nmea.rb
96
110
  - lib/sgs/otto.rb
97
111
  - lib/sgs/redis_base.rb
112
+ - lib/sgs/rpc.rb
98
113
  - lib/sgs/timing.rb
99
114
  - lib/sgs/version.rb
100
115
  - lib/sgs/waypoint.rb
@@ -121,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
136
  version: '0'
122
137
  requirements: []
123
138
  rubyforge_project:
124
- rubygems_version: 2.5.2.1
139
+ rubygems_version: 2.7.6
125
140
  signing_key:
126
141
  specification_version: 4
127
142
  summary: Sailboat Guidance System