sgslib 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgs/alarm.rb +1 -1
- data/lib/sgs/otto.rb +70 -94
- data/lib/sgs/redis_base.rb +15 -14
- data/lib/sgs/version.rb +1 -1
- data/lib/sgslib.rb +0 -1
- metadata +2 -3
- data/lib/sgs/command.rb +0 -167
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7ee0414fad3641eb50bf386b9e05b2b4290ac3d
|
4
|
+
data.tar.gz: aec3efc5d970a7705bc44b90f26e060dd286650a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf487f698bae00c8c37a2dfd588ab7388bc122afcb312d2a441ba8fc7887cb80a1da80d7d3e2977ed31964fe37c1a6943e40de5931553a62c942b0cbaabc130c
|
7
|
+
data.tar.gz: db0e9bbfc4fdcd778885dbb30fc2a7f98a8594b5933fcd9e8c681f6853df2f28a0bc99097d41e4b675776d3aff1c04a8f506cc0592bea97e83a28c0cf14fafb6
|
data/lib/sgs/alarm.rb
CHANGED
data/lib/sgs/otto.rb
CHANGED
@@ -30,134 +30,110 @@
|
|
30
30
|
#
|
31
31
|
module SGS
|
32
32
|
class Otto < RedisBase
|
33
|
-
|
34
|
-
attr_accessor :
|
33
|
+
attr_accessor :raw_rudder, :raw_sail, :raw_compass, :raw_awa, :raw_tc, :raw_ta
|
34
|
+
attr_accessor :mode, :rudder_m, :rudder_c, :sail_m, :sail_c
|
35
|
+
attr_accessor :bv_m, :bv_c, :bi_m, :bi_c, :bt_m, :bt_c, :sv_m, :sv_c
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@rudder = read_rudder
|
42
|
-
@sail = read_sail
|
43
|
-
@compass = read_compass
|
44
|
-
@twa = read_twa
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Set the required rudder angle. Input values range from +/- 40 degrees
|
50
|
-
def rudder=(val)
|
51
|
-
val = -39.9 if val < -39.9
|
52
|
-
val = 39.9 if val > 39.9
|
53
|
-
return if @rudder == val
|
54
|
-
@rudder = val
|
55
|
-
intval = (@rudder * 120.0 / 40.0).to_int + 128
|
56
|
-
puts "New rudder value: #{intval} (#{@rudder} degrees)"
|
57
|
-
send_command(SET_RUDDER, intval)
|
58
|
-
end
|
37
|
+
MODE_INERT = 0
|
38
|
+
MODE_DIAGNOSTICS = 1
|
39
|
+
MODE_MANUAL = 2
|
40
|
+
MODE_TRACK_COMPASS = 3
|
41
|
+
MODE_TRACK_AWA = 4
|
59
42
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
val = 90.0 if val > 90.0
|
65
|
-
return if @sail == val
|
66
|
-
@sail = val
|
67
|
-
intval = (@sail * 256.0 / 90.0).to_int
|
68
|
-
puts "New sail angle: #{intval} (#{@sail} degrees)"
|
69
|
-
send_command(SET_SAIL, intval)
|
70
|
-
end
|
43
|
+
MODE_NAMES = [
|
44
|
+
"Inert Mode", "Diagnostics Mode", "Manual Control Mode",
|
45
|
+
"Compass-Tracking Mode", "AWA-Tracking Mode"
|
46
|
+
].freeze
|
71
47
|
|
72
48
|
#
|
73
|
-
# Set
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
@
|
81
|
-
|
82
|
-
|
83
|
-
|
49
|
+
# Set up some useful defaults. We assume rudder goes from 0 to 200 as does
|
50
|
+
# the sail angle.
|
51
|
+
def initialize
|
52
|
+
#
|
53
|
+
# Configure the Mx + C values for sail and rudder
|
54
|
+
@rudder_m = 2.5
|
55
|
+
@rudder_c = 100.0
|
56
|
+
@sail_m = 2.0
|
57
|
+
@sail_c = 0.0
|
58
|
+
#
|
59
|
+
# Now set the rudder and sail to default positions (rudder is centered)
|
60
|
+
rudder = 0.0
|
61
|
+
sail = 0.0
|
62
|
+
#
|
63
|
+
# Set up some basic parameters for battery/solar readings
|
64
|
+
@bv_m = @bi_m = @bt_m = @sv_m = 1.0
|
65
|
+
@bv_c = @bi_c = @bt_c = @sv_c = 0.0
|
66
|
+
super
|
84
67
|
end
|
85
68
|
|
86
69
|
#
|
87
|
-
# Set the required
|
88
|
-
def
|
89
|
-
val = -
|
90
|
-
val =
|
91
|
-
|
92
|
-
@twa = val
|
93
|
-
val = 360.0 + val if val < 0.0
|
94
|
-
intval = (val * 256.0 / 360.0).to_int
|
95
|
-
puts "New TWA: #{intval} (#{@twa} degrees)"
|
96
|
-
send_command(SET_TWA, intval)
|
70
|
+
# Set the required rudder angle. Input values range from +/- 40.0 degrees
|
71
|
+
def rudder=(val)
|
72
|
+
val = -40.0 if val < -40.0
|
73
|
+
val = 40.0 if val > 40.0
|
74
|
+
@raw_rudder = (@rudder_m * val.to_f + @rudder_c).to_i
|
97
75
|
end
|
98
76
|
|
99
77
|
#
|
100
|
-
#
|
101
|
-
def
|
102
|
-
|
78
|
+
# Return the rudder angle in degrees
|
79
|
+
def rudder
|
80
|
+
(@raw_rudder.to_f - @rudder_c) / @rudder_m
|
103
81
|
end
|
104
82
|
|
105
83
|
#
|
106
|
-
#
|
107
|
-
def
|
108
|
-
|
109
|
-
|
84
|
+
# Set the required sail angle. Input values range from 0 -> 90 degrees.
|
85
|
+
def sail=(val)
|
86
|
+
val = 0.0 if val < 0.0
|
87
|
+
val = 100.0 if val > 100.0
|
88
|
+
@raw_sail = (@sail_m * val.to_f + @sail_c).to_i
|
110
89
|
end
|
111
90
|
|
112
91
|
#
|
113
|
-
#
|
114
|
-
def
|
115
|
-
|
116
|
-
intval.to_f * @bical / 1024.0
|
92
|
+
# Return the sail setting (0.0 -> 100.0)
|
93
|
+
def sail
|
94
|
+
(@raw_sail.to_f - @sail_c) / @sail_m
|
117
95
|
end
|
118
96
|
|
119
97
|
#
|
120
|
-
#
|
121
|
-
def
|
122
|
-
|
123
|
-
intval.to_f * @btcal / 1024.0
|
98
|
+
# Return the compass angle (in radians)
|
99
|
+
def compass
|
100
|
+
@raw_compass.to_f * Math::PI / 128.0
|
124
101
|
end
|
125
102
|
|
126
103
|
#
|
127
|
-
#
|
128
|
-
def
|
129
|
-
|
130
|
-
intval.to_f * @svcal / 1024.0
|
104
|
+
# Return the apparent wind angle (in radians)
|
105
|
+
def awa
|
106
|
+
@raw_awa.to_f * Math::PI / 128.0
|
131
107
|
end
|
132
108
|
|
133
109
|
#
|
134
|
-
#
|
135
|
-
def
|
136
|
-
|
137
|
-
|
110
|
+
# Set the required compass reading. Input values range from 0 -> 359 degrees
|
111
|
+
def track_compass=(val)
|
112
|
+
while val < 0.0
|
113
|
+
val += 360.0
|
114
|
+
end
|
115
|
+
val %= 360.0
|
116
|
+
@raw_tc = (val.to_f * 128.0 / Math::PI).to_i
|
138
117
|
end
|
139
118
|
|
140
119
|
#
|
141
|
-
#
|
142
|
-
def
|
143
|
-
|
144
|
-
val = intval.to_f * 180.0 / 128.0
|
145
|
-
val = val - 360.0 if val > 180.0
|
146
|
-
val
|
120
|
+
# Return the compass value for tracking.
|
121
|
+
def track_compass
|
122
|
+
@raw_tc.to_f * Math::PI / 128.0
|
147
123
|
end
|
148
124
|
|
149
125
|
#
|
150
|
-
#
|
151
|
-
def
|
152
|
-
|
153
|
-
|
126
|
+
# Set the required AWA for tracking.
|
127
|
+
def track_awa=(val)
|
128
|
+
val = -180.0 if val < -180.0
|
129
|
+
val = 180.0 if val > 180.0
|
130
|
+
@raw_ta = (val.to_f * 128.0 / Math::PI).to_i
|
154
131
|
end
|
155
132
|
|
156
133
|
#
|
157
|
-
#
|
158
|
-
def
|
159
|
-
|
160
|
-
intval.to_f
|
134
|
+
# Return the current tracking AWA.
|
135
|
+
def track_awa
|
136
|
+
@raw_ta.to_f * Math::PI / 128.0
|
161
137
|
end
|
162
138
|
end
|
163
139
|
end
|
data/lib/sgs/redis_base.rb
CHANGED
@@ -32,17 +32,18 @@ require 'redis'
|
|
32
32
|
|
33
33
|
module SGS
|
34
34
|
class RedisBase
|
35
|
-
|
35
|
+
class << self
|
36
|
+
def redis
|
37
|
+
puts "Class init"
|
38
|
+
@@redis ||= Redis.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
36
43
|
# The base (inherited) class for dealing with Redis data for
|
37
44
|
# the navigation system. Each model class inherits this parent,
|
38
45
|
# and gets an update count for free.
|
39
46
|
|
40
|
-
#
|
41
|
-
# Initialize the base class.
|
42
|
-
def initialize
|
43
|
-
$redis = Redis.new unless $redis
|
44
|
-
end
|
45
|
-
|
46
47
|
#
|
47
48
|
# Initialize the (sub-)class variables in Redis.
|
48
49
|
def self.setup
|
@@ -67,7 +68,7 @@ module SGS
|
|
67
68
|
# Initialize a Redis variable.
|
68
69
|
def self.var_init(var, val, idx = nil)
|
69
70
|
cls = new
|
70
|
-
|
71
|
+
SGS::RedisBase.redis.setnx cls.make_redis_name(var, :idx => idx), self.to_redis(var, val, idx)
|
71
72
|
end
|
72
73
|
|
73
74
|
#
|
@@ -133,11 +134,11 @@ module SGS
|
|
133
134
|
#
|
134
135
|
# Inside a multi-block, set all the variables and increment
|
135
136
|
# the count.
|
136
|
-
|
137
|
+
SGS::RedisBase.redis.multi do
|
137
138
|
var_list.each do |key, value|
|
138
|
-
|
139
|
+
SGS::RedisBase.redis.set key, value
|
139
140
|
end
|
140
|
-
|
141
|
+
SGS::RedisBase.redis.incr count_name
|
141
142
|
end
|
142
143
|
true
|
143
144
|
end
|
@@ -149,7 +150,7 @@ module SGS
|
|
149
150
|
# class name), you can remember the last received count and decide if
|
150
151
|
# there is fresh data. Or, you can just act anyway.
|
151
152
|
def publish
|
152
|
-
|
153
|
+
SGS::RedisBase.redis.publish self.class.redis_handle, count.to_s
|
153
154
|
end
|
154
155
|
|
155
156
|
#
|
@@ -174,7 +175,7 @@ module SGS
|
|
174
175
|
#
|
175
176
|
# Retrieve the count
|
176
177
|
def count
|
177
|
-
|
178
|
+
SGS::RedisBase.redis.get count_name
|
178
179
|
end
|
179
180
|
|
180
181
|
#
|
@@ -187,7 +188,7 @@ module SGS
|
|
187
188
|
# Get an instance variable value from a Redis value.
|
188
189
|
def redis_read_var(var, klass, opts = {})
|
189
190
|
redis_name = make_redis_name var, opts
|
190
|
-
redis_val =
|
191
|
+
redis_val = SGS::RedisBase.redis.get redis_name
|
191
192
|
redis_val = nil if redis_val == ""
|
192
193
|
if redis_val
|
193
194
|
if not klass or klass == NilClass
|
data/lib/sgs/version.rb
CHANGED
data/lib/sgslib.rb
CHANGED
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.
|
4
|
+
version: 0.2.6
|
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-
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- bin/console
|
86
86
|
- bin/setup
|
87
87
|
- lib/sgs/alarm.rb
|
88
|
-
- lib/sgs/command.rb
|
89
88
|
- lib/sgs/config.rb
|
90
89
|
- lib/sgs/course.rb
|
91
90
|
- lib/sgs/gps.rb
|
data/lib/sgs/command.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2013, 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 handling sailboat alarms. Note that this is the definitive
|
30
|
-
# list of alarms on the system. To add or modify an alarm, do so here.
|
31
|
-
#
|
32
|
-
module SGS
|
33
|
-
##
|
34
|
-
# Deal with command subsystem.
|
35
|
-
#
|
36
|
-
# This code handles the Fonz packet commands.
|
37
|
-
#
|
38
|
-
class Command < RedisBase
|
39
|
-
attr_accessor :last_received, :time
|
40
|
-
|
41
|
-
FONZ_PING = 0
|
42
|
-
FONZ_MAGIC = 1
|
43
|
-
FONZ_ACK = 2
|
44
|
-
|
45
|
-
FONZ_GET_TIMEL = 4
|
46
|
-
FONZ_TIME_DATAL = 5
|
47
|
-
FONZ_GET_TIMEH = 6
|
48
|
-
FONZ_TIME_DATAH = 7
|
49
|
-
|
50
|
-
FONZ_GET_VOLTS1 = 8
|
51
|
-
FONZ_VOLTS1_DATA = 9
|
52
|
-
FONZ_GET_VOLTS2 = 10
|
53
|
-
FONZ_VOLTS2_DATA = 11
|
54
|
-
FONZ_GET_VOLTS3 = 12
|
55
|
-
FONZ_VOLTS3_DATA = 13
|
56
|
-
FONZ_GET_VOLTS4 = 14
|
57
|
-
FONZ_VOLTS4_DATA = 15
|
58
|
-
FONZ_GET_VOLTS5 = 16
|
59
|
-
FONZ_VOLTS5_DATA = 17
|
60
|
-
FONZ_GET_VOLTS6 = 18
|
61
|
-
FONZ_VOLTS6_DATA = 19
|
62
|
-
FONZ_GET_VOLTS7 = 20
|
63
|
-
FONZ_VOLTS7_DATA = 21
|
64
|
-
FONZ_GET_VOLTS8 = 22
|
65
|
-
FONZ_VOLTS8_DATA = 23
|
66
|
-
|
67
|
-
FONZ_GET_CURR1 = 24
|
68
|
-
FONZ_CURR1_DATA = 25
|
69
|
-
FONZ_GET_CURR2 = 26
|
70
|
-
FONZ_CURR2_DATA = 27
|
71
|
-
FONZ_GET_CURR3 = 28
|
72
|
-
FONZ_CURR3_DATA = 29
|
73
|
-
FONZ_GET_CURR4 = 30
|
74
|
-
FONZ_CURR4_DATA = 31
|
75
|
-
FONZ_GET_CURR5 = 32
|
76
|
-
FONZ_CURR5_DATA = 33
|
77
|
-
FONZ_GET_CURR6 = 34
|
78
|
-
FONZ_CURR6_DATA = 35
|
79
|
-
FONZ_GET_CURR7 = 36
|
80
|
-
FONZ_CURR7_DATA = 37
|
81
|
-
FONZ_GET_CURR8 = 38
|
82
|
-
FONZ_CURR8_DATA = 39
|
83
|
-
|
84
|
-
FONZ_GET_ALARMS = 40
|
85
|
-
FONZ_ALARM_RAISE = 41
|
86
|
-
|
87
|
-
FONZ_GET_OTTORST = 42
|
88
|
-
FONZ_OTTORST_DATA = 43
|
89
|
-
FONZ_GET_MISSION = 44
|
90
|
-
FONZ_MISSION_DATA = 45
|
91
|
-
FONZ_GET_COMPASS = 46
|
92
|
-
FONZ_COMPASS_DATA = 47
|
93
|
-
FONZ_GET_TWA = 48
|
94
|
-
FONZ_TWA_DATA = 49
|
95
|
-
FONZ_GET_RUDDER = 50
|
96
|
-
FONZ_RUDDER_DATA = 51
|
97
|
-
FONZ_GET_SAIL = 52
|
98
|
-
FONZ_SAIL_DATA = 53
|
99
|
-
FONZ_GET_PDOWN = 54
|
100
|
-
FONZ_PDOWN_DATA = 55
|
101
|
-
FONZ_GET_NAVLIGHT = 56
|
102
|
-
FONZ_NAVLIGHT_DATA = 57
|
103
|
-
FONZ_GET_BUZZER = 58
|
104
|
-
FONZ_BUZZER_DATA = 59
|
105
|
-
|
106
|
-
FONZ_GET_EEADDR = 60
|
107
|
-
FONZ_SET_EEADDR = 61
|
108
|
-
FONZ_GET_EEDATA = 62
|
109
|
-
FONZ_SET_EEDATA = 63
|
110
|
-
|
111
|
-
MESSAGES = [
|
112
|
-
"Ping", "Magic Word",
|
113
|
-
"ACK", "??",
|
114
|
-
"Get Time (Lo)", "Time Data (Lo)",
|
115
|
-
"Get Time (Hi)", "Time Data (Hi)",
|
116
|
-
"Get Voltage1", "Voltage1 Data",
|
117
|
-
"Get Voltage2", "Voltage2 Data",
|
118
|
-
"Get Voltage3", "Voltage3 Data",
|
119
|
-
"Get Voltage4", "Voltage4 Data",
|
120
|
-
"Get Voltage5", "Voltage5 Data",
|
121
|
-
"Get Voltage6", "Voltage6 Data",
|
122
|
-
"Get Voltage7", "Voltage7 Data",
|
123
|
-
"Get Voltage8", "Voltage8 Data",
|
124
|
-
"Get Current1", "Current1 Data",
|
125
|
-
"Get Current2", "Current2 Data",
|
126
|
-
"Get Current3", "Current3 Data",
|
127
|
-
"Get Current4", "Current4 Data",
|
128
|
-
"Get Current5", "Current5 Data",
|
129
|
-
"Get Current6", "Current6 Data",
|
130
|
-
"Get Current7", "Current7 Data",
|
131
|
-
"Get Current8", "Current8 Data",
|
132
|
-
"Get Alarms", "Alarm Raised!",
|
133
|
-
"Get Otto Reset", "Otto Reset Status",
|
134
|
-
"Get Mission", "Mission Data",
|
135
|
-
"Get Compass", "Compass Data",
|
136
|
-
"Get TWA", "TWA Data",
|
137
|
-
"Get Rudder Position", "Rudder Position Data",
|
138
|
-
"Get Sail Trim", "Sail Trim Data",
|
139
|
-
"Get Power Down", "Time to Power Down",
|
140
|
-
"Get Nav Light", "Nav Light Status",
|
141
|
-
"Get Buzzer", "Buzzer Status",
|
142
|
-
"Get EEPROM Address", "Set EEPROM Address",
|
143
|
-
"Get EEPROM Data", "Set EEPROM Data"
|
144
|
-
].freeze
|
145
|
-
|
146
|
-
def initialize
|
147
|
-
@count = 0
|
148
|
-
@last_report = nil
|
149
|
-
@time = Array.new(32, Time.at(0))
|
150
|
-
super
|
151
|
-
end
|
152
|
-
|
153
|
-
#
|
154
|
-
# Convert a command code into a string.
|
155
|
-
def name(code)
|
156
|
-
(code < MESSAGES.count) ? MESSAGES[code] : nil
|
157
|
-
end
|
158
|
-
|
159
|
-
#
|
160
|
-
# Send a command to the microcontroller
|
161
|
-
def send_command(cmd, arg = nil)
|
162
|
-
puts "Send command #{cmd} (#{name(cmd)})"
|
163
|
-
puts "Arg is #{arg}" if arg
|
164
|
-
return 0
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|