cosmos 5.0.2 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cosmos +183 -42
- data/data/config/microservice.yaml +47 -35
- data/data/config/plugins.yaml +10 -147
- data/data/config/target.yaml +70 -0
- data/data/config/tool.yaml +37 -31
- data/ext/cosmos/ext/cosmos_io/cosmos_io.c +14 -14
- data/ext/cosmos/ext/packet/packet.c +3 -3
- data/ext/cosmos/ext/structure/structure.c +31 -31
- data/lib/cosmos/api/api.rb +1 -25
- data/lib/cosmos/api/cmd_api.rb +17 -6
- data/lib/cosmos/api/config_api.rb +10 -4
- data/lib/cosmos/api/limits_api.rb +1 -1
- data/lib/cosmos/api/settings_api.rb +19 -7
- data/lib/cosmos/api/target_api.rb +2 -2
- data/lib/cosmos/api/tlm_api.rb +65 -41
- data/lib/cosmos/config/config_parser.rb +19 -22
- data/lib/cosmos/config/meta_config_parser.rb +1 -1
- data/lib/cosmos/conversions/generic_conversion.rb +2 -2
- data/lib/cosmos/conversions/polynomial_conversion.rb +5 -8
- data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +26 -9
- data/lib/cosmos/io/json_drb.rb +5 -1
- data/lib/cosmos/logs/log_writer.rb +78 -29
- data/lib/cosmos/microservices/cleanup_microservice.rb +28 -29
- data/lib/cosmos/microservices/decom_microservice.rb +1 -1
- data/lib/cosmos/microservices/interface_microservice.rb +0 -16
- data/lib/cosmos/microservices/microservice.rb +3 -3
- data/lib/cosmos/microservices/reducer_microservice.rb +12 -10
- data/lib/cosmos/models/cvt_model.rb +6 -6
- data/lib/cosmos/models/gem_model.rb +9 -3
- data/lib/cosmos/models/info_model.rb +1 -1
- data/lib/cosmos/models/interface_model.rb +16 -7
- data/lib/cosmos/models/interface_status_model.rb +1 -1
- data/lib/cosmos/models/metadata_model.rb +69 -219
- data/lib/cosmos/models/metric_model.rb +2 -2
- data/lib/cosmos/models/microservice_model.rb +7 -4
- data/lib/cosmos/models/microservice_status_model.rb +1 -1
- data/lib/cosmos/models/model.rb +23 -16
- data/lib/cosmos/models/note_model.rb +122 -0
- data/lib/cosmos/models/ping_model.rb +2 -1
- data/lib/cosmos/models/plugin_model.rb +108 -48
- data/lib/cosmos/models/process_status_model.rb +1 -1
- data/lib/cosmos/models/scope_model.rb +10 -25
- data/lib/cosmos/models/settings_model.rb +55 -0
- data/lib/cosmos/models/sorted_model.rb +167 -0
- data/lib/cosmos/models/target_model.rb +143 -27
- data/lib/cosmos/models/tool_config_model.rb +38 -0
- data/lib/cosmos/models/tool_model.rb +9 -9
- data/lib/cosmos/models/widget_model.rb +11 -11
- data/lib/cosmos/operators/microservice_operator.rb +2 -1
- data/lib/cosmos/packets/packet.rb +24 -1
- data/lib/cosmos/packets/packet_config.rb +2 -2
- data/lib/cosmos/packets/packet_item.rb +57 -0
- data/lib/cosmos/packets/packet_item_limits.rb +14 -2
- data/lib/cosmos/packets/parsers/packet_item_parser.rb +1 -1
- data/lib/cosmos/packets/parsers/packet_parser.rb +1 -1
- data/lib/cosmos/packets/parsers/xtce_parser.rb +1 -1
- data/lib/cosmos/packets/structure.rb +30 -33
- data/lib/cosmos/packets/structure_item.rb +10 -1
- data/lib/cosmos/script/api_shared.rb +30 -25
- data/lib/cosmos/script/calendar.rb +37 -15
- data/lib/cosmos/script/commands.rb +5 -7
- data/lib/cosmos/script/script.rb +19 -39
- data/lib/cosmos/script/storage.rb +92 -105
- data/lib/cosmos/system/system.rb +2 -1
- data/lib/cosmos/tools/table_manager/table_config.rb +16 -1
- data/lib/cosmos/tools/table_manager/table_item.rb +1 -1
- data/lib/cosmos/tools/table_manager/table_manager_core.rb +213 -309
- data/lib/cosmos/top_level.rb +5 -1
- data/lib/cosmos/topics/autonomic_topic.rb +2 -2
- data/lib/cosmos/topics/calendar_topic.rb +1 -1
- data/lib/cosmos/topics/command_decom_topic.rb +35 -1
- data/lib/cosmos/topics/command_topic.rb +6 -4
- data/lib/cosmos/topics/config_topic.rb +68 -0
- data/lib/cosmos/topics/interface_topic.rb +8 -8
- data/lib/cosmos/topics/limits_event_topic.rb +5 -3
- data/lib/cosmos/topics/notifications_topic.rb +1 -1
- data/lib/cosmos/topics/router_topic.rb +9 -9
- data/lib/cosmos/topics/telemetry_decom_topic.rb +5 -1
- data/lib/cosmos/topics/telemetry_topic.rb +1 -1
- data/lib/cosmos/topics/timeline_topic.rb +1 -1
- data/lib/cosmos/topics/topic.rb +23 -8
- data/lib/cosmos/utilities/logger.rb +4 -3
- data/lib/cosmos/utilities/metric.rb +32 -26
- data/lib/cosmos/utilities/s3.rb +61 -0
- data/lib/cosmos/utilities/s3_file_cache.rb +12 -6
- data/lib/cosmos/utilities/store.rb +1 -0
- data/lib/cosmos/utilities/store_autoload.rb +25 -134
- data/lib/cosmos/version.rb +5 -4
- data/templates/plugin-template/plugin.gemspec +0 -2
- metadata +12 -10
- data/bin/xtce_converter +0 -92
- data/lib/cosmos/models/narrative_model.rb +0 -280
@@ -31,7 +31,7 @@ end
|
|
31
31
|
module Cosmos
|
32
32
|
class Store
|
33
33
|
# Variable that holds the singleton instance
|
34
|
-
|
34
|
+
@instance = nil
|
35
35
|
|
36
36
|
# Mutex used to ensure that only one instance is created
|
37
37
|
@@instance_mutex = Mutex.new
|
@@ -42,11 +42,11 @@ module Cosmos
|
|
42
42
|
# Get the singleton instance
|
43
43
|
def self.instance(pool_size = 100)
|
44
44
|
# Logger.level = Logger::DEBUG
|
45
|
-
return
|
45
|
+
return @instance if @instance
|
46
46
|
|
47
47
|
@@instance_mutex.synchronize do
|
48
|
-
|
49
|
-
return
|
48
|
+
@instance ||= self.new(pool_size)
|
49
|
+
return @instance
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -87,44 +87,10 @@ module Cosmos
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
def get_cmd_item(target_name, packet_name, param_name, type: :WITH_UNITS, scope: $cosmos_scope)
|
91
|
-
msg_id, msg_hash = read_topic_last("#{scope}__DECOMCMD__{#{target_name}}__#{packet_name}")
|
92
|
-
if msg_id
|
93
|
-
# TODO: We now have these reserved items directly on command packets
|
94
|
-
# Do we still calculate from msg_hash['time'] or use the times directly?
|
95
|
-
#
|
96
|
-
# if param_name == 'RECEIVED_TIMESECONDS' || param_name == 'PACKET_TIMESECONDS'
|
97
|
-
# Time.from_nsec_from_epoch(msg_hash['time'].to_i).to_f
|
98
|
-
# elsif param_name == 'RECEIVED_TIMEFORMATTED' || param_name == 'PACKET_TIMEFORMATTED'
|
99
|
-
# Time.from_nsec_from_epoch(msg_hash['time'].to_i).formatted
|
100
|
-
if param_name == 'RECEIVED_COUNT'
|
101
|
-
msg_hash['received_count'].to_i
|
102
|
-
else
|
103
|
-
json = msg_hash['json_data']
|
104
|
-
hash = JSON.parse(json)
|
105
|
-
# Start from the most complex down to the basic raw value
|
106
|
-
value = hash["#{param_name}__U"]
|
107
|
-
return value if value && type == :WITH_UNITS
|
108
|
-
|
109
|
-
value = hash["#{param_name}__F"]
|
110
|
-
return value if value && (type == :WITH_UNITS || type == :FORMATTED)
|
111
|
-
|
112
|
-
value = hash["#{param_name}__C"]
|
113
|
-
return value if value && (type == :WITH_UNITS || type == :FORMATTED || type == :CONVERTED)
|
114
|
-
|
115
|
-
return hash[param_name]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
90
|
###########################################################################
|
121
91
|
# Stream APIs
|
122
92
|
###########################################################################
|
123
93
|
|
124
|
-
def self.initialize_streams(topics)
|
125
|
-
self.instance.initialize_streams(topics)
|
126
|
-
end
|
127
|
-
|
128
94
|
def initialize_streams(topics)
|
129
95
|
@redis_pool.with do |redis|
|
130
96
|
topics.each do |topic|
|
@@ -134,48 +100,18 @@ module Cosmos
|
|
134
100
|
end
|
135
101
|
end
|
136
102
|
|
137
|
-
def self.get_oldest_message(topic)
|
138
|
-
self.instance.get_oldest_message(topic)
|
139
|
-
end
|
140
|
-
|
141
103
|
def get_oldest_message(topic)
|
142
104
|
@redis_pool.with do |redis|
|
143
105
|
result = redis.xrange(topic, count: 1)
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
def self.get_newest_message(topic)
|
149
|
-
self.instance.get_newest_message(topic)
|
150
|
-
end
|
151
|
-
|
152
|
-
def get_newest_message(topic)
|
153
|
-
@redis_pool.with do |redis|
|
154
|
-
result = redis.xrevrange(topic, count: 1)
|
155
|
-
return result[0]
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def self.get_last_offset(topic)
|
160
|
-
self.instance.get_last_offset(topic)
|
161
|
-
end
|
162
|
-
|
163
|
-
def get_last_offset(topic)
|
164
|
-
@redis_pool.with do |redis|
|
165
|
-
result = redis.xrevrange(topic, count: 1)
|
166
|
-
if result and result[0] and result[0][0]
|
167
|
-
result[0][0]
|
106
|
+
if result and result.length > 0
|
107
|
+
return result[0]
|
168
108
|
else
|
169
|
-
|
109
|
+
return nil
|
170
110
|
end
|
171
111
|
end
|
172
112
|
end
|
173
113
|
|
174
|
-
def
|
175
|
-
self.instance.read_topic_last(topic)
|
176
|
-
end
|
177
|
-
|
178
|
-
def read_topic_last(topic)
|
114
|
+
def get_newest_message(topic)
|
179
115
|
@redis_pool.with do |redis|
|
180
116
|
# Default in xrevrange is range end '+', start '-' which means get all
|
181
117
|
# elements from higher ID to lower ID and since we're limiting to 1
|
@@ -189,18 +125,15 @@ module Cosmos
|
|
189
125
|
end
|
190
126
|
end
|
191
127
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
def self.update_topic_offsets(topics)
|
203
|
-
self.instance.update_topic_offsets(topics)
|
128
|
+
def get_last_offset(topic)
|
129
|
+
@redis_pool.with do |redis|
|
130
|
+
result = redis.xrevrange(topic, count: 1)
|
131
|
+
if result and result[0] and result[0][0]
|
132
|
+
result[0][0]
|
133
|
+
else
|
134
|
+
"0-0"
|
135
|
+
end
|
136
|
+
end
|
204
137
|
end
|
205
138
|
|
206
139
|
def update_topic_offsets(topics)
|
@@ -221,15 +154,12 @@ module Cosmos
|
|
221
154
|
return offsets
|
222
155
|
end
|
223
156
|
|
224
|
-
def self.read_topics(topics, offsets = nil, timeout_ms = 1000, &block)
|
225
|
-
self.instance.read_topics(topics, offsets, timeout_ms, &block)
|
226
|
-
end
|
227
157
|
unless $enterprise_cosmos
|
228
|
-
def read_topics(topics, offsets = nil, timeout_ms = 1000)
|
158
|
+
def read_topics(topics, offsets = nil, timeout_ms = 1000, count = nil)
|
229
159
|
# Logger.debug "read_topics: #{topics}, #{offsets} pool:#{@redis_pool}"
|
230
160
|
@redis_pool.with do |redis|
|
231
161
|
offsets = update_topic_offsets(topics) unless offsets
|
232
|
-
result = redis.xread(topics, offsets, block: timeout_ms)
|
162
|
+
result = redis.xread(topics, offsets, block: timeout_ms, count: count)
|
233
163
|
if result and result.length > 0
|
234
164
|
result.each do |topic, messages|
|
235
165
|
messages.each do |msg_id, msg_hash|
|
@@ -244,26 +174,6 @@ module Cosmos
|
|
244
174
|
end
|
245
175
|
end
|
246
176
|
|
247
|
-
# Add new entry to the redis stream.
|
248
|
-
# > https://www.rubydoc.info/github/redis/redis-rb/Redis:xadd
|
249
|
-
#
|
250
|
-
# @example Without options
|
251
|
-
# COSMOS::Store().write_topic('MANGO__TOPIC', {'message' => 'something'})
|
252
|
-
# @example With options
|
253
|
-
# COSMOS::Store().write_topic('MANGO__TOPIC', {'message' => 'something'}, id: '0-0', maxlen: 1000, approximate: false)
|
254
|
-
#
|
255
|
-
# @param topic [String] the stream / topic
|
256
|
-
# @param msg_hash [Hash] one or multiple field-value pairs
|
257
|
-
#
|
258
|
-
# @option opts [String] :id the entry id, default value is `*`, it means auto generation
|
259
|
-
# @option opts [Integer] :maxlen max length of entries
|
260
|
-
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen or not
|
261
|
-
#
|
262
|
-
# @return [String] the entry id
|
263
|
-
def self.write_topic(topic, msg_hash, id = '*', maxlen = nil, approximate = true)
|
264
|
-
self.instance.write_topic(topic, msg_hash, id, maxlen, approximate)
|
265
|
-
end
|
266
|
-
|
267
177
|
# Add new entry to the redis stream.
|
268
178
|
# > https://www.rubydoc.info/github/redis/redis-rb/Redis:xadd
|
269
179
|
#
|
@@ -289,23 +199,6 @@ module Cosmos
|
|
289
199
|
end
|
290
200
|
end
|
291
201
|
|
292
|
-
# Trims older entries of the redis stream if needed.
|
293
|
-
# > https://www.rubydoc.info/github/redis/redis-rb/Redis:xtrim
|
294
|
-
#
|
295
|
-
# @example Without options
|
296
|
-
# COSMOS::Store.trim_topic('MANGO__TOPIC', 1000)
|
297
|
-
# @example With options
|
298
|
-
# COSMOS::Store.trim_topic('MANGO__TOPIC', 1000, approximate: true, limit: 0)
|
299
|
-
#
|
300
|
-
# @param topic [String] the stream key
|
301
|
-
# @param minid [Integer] max length of entries to trim
|
302
|
-
# @param limit [Boolean] whether to add `~` modifier of maxlen or not
|
303
|
-
#
|
304
|
-
# @return [Integer] the number of entries actually deleted
|
305
|
-
def self.trim_topic(topic, minid, approximate = true, limit: 0)
|
306
|
-
self.instance.trim_topic(topic, minid, approximate, limit: limit)
|
307
|
-
end
|
308
|
-
|
309
202
|
# Trims older entries of the redis stream if needed.
|
310
203
|
# > https://www.rubydoc.info/github/redis/redis-rb/Redis:xtrim
|
311
204
|
#
|
@@ -324,15 +217,13 @@ module Cosmos
|
|
324
217
|
return redis.xtrim_minid(topic, minid, approximate: approximate, limit: limit)
|
325
218
|
end
|
326
219
|
end
|
220
|
+
end
|
327
221
|
|
328
|
-
|
329
|
-
def
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
# Execute any Redis command. Args must be an array (e.g. ["KEYS", "*"])
|
334
|
-
def execute_raw(args)
|
335
|
-
synchronize { |client| client.call(args) }
|
222
|
+
class EphemeralStore < Store
|
223
|
+
def initialize(pool_size = 10)
|
224
|
+
super(pool_size)
|
225
|
+
@redis_url = "redis://#{ENV['COSMOS_REDIS_EPHEMERAL_HOSTNAME']}:#{ENV['COSMOS_REDIS_EPHEMERAL_PORT']}"
|
226
|
+
@redis_pool = ConnectionPool.new(size: pool_size) { build_redis() }
|
336
227
|
end
|
337
228
|
end
|
338
229
|
end
|
data/lib/cosmos/version.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# encoding: ascii-8bit
|
2
2
|
|
3
|
-
COSMOS_VERSION = '5.0.
|
3
|
+
COSMOS_VERSION = '5.0.5'
|
4
4
|
module Cosmos
|
5
5
|
module Version
|
6
6
|
MAJOR = '5'
|
7
7
|
MINOR = '0'
|
8
|
-
PATCH = '
|
8
|
+
PATCH = '5'
|
9
9
|
OTHER = ''
|
10
|
-
BUILD = '
|
10
|
+
BUILD = 'e31c5f3ab7a18f52db7c00430c36efe651048fd7'
|
11
11
|
end
|
12
|
-
VERSION = '5.0.
|
12
|
+
VERSION = '5.0.5'
|
13
|
+
GEM_VERSION = '5.0.5'
|
13
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cosmos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Melton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -129,14 +129,14 @@ dependencies:
|
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '1.
|
132
|
+
version: '1.13'
|
133
133
|
type: :runtime
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: '1.
|
139
|
+
version: '1.13'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: puma
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,14 +157,14 @@ dependencies:
|
|
157
157
|
requirements:
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
160
|
+
version: 2.2.3.1
|
161
161
|
type: :runtime
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
167
|
+
version: 2.2.3.1
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: redis
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
@@ -500,7 +500,6 @@ executables:
|
|
500
500
|
- cosmos
|
501
501
|
- rubysloc
|
502
502
|
- cstol_converter
|
503
|
-
- xtce_converter
|
504
503
|
extensions:
|
505
504
|
- ext/cosmos/ext/array/extconf.rb
|
506
505
|
- ext/cosmos/ext/buffered_file/extconf.rb
|
@@ -524,7 +523,6 @@ files:
|
|
524
523
|
- bin/cosmos
|
525
524
|
- bin/cstol_converter
|
526
525
|
- bin/rubysloc
|
527
|
-
- bin/xtce_converter
|
528
526
|
- data/config/_array_params.yaml
|
529
527
|
- data/config/_id_items.yaml
|
530
528
|
- data/config/_id_params.yaml
|
@@ -693,7 +691,7 @@ files:
|
|
693
691
|
- lib/cosmos/models/microservice_model.rb
|
694
692
|
- lib/cosmos/models/microservice_status_model.rb
|
695
693
|
- lib/cosmos/models/model.rb
|
696
|
-
- lib/cosmos/models/
|
694
|
+
- lib/cosmos/models/note_model.rb
|
697
695
|
- lib/cosmos/models/notification_model.rb
|
698
696
|
- lib/cosmos/models/ping_model.rb
|
699
697
|
- lib/cosmos/models/plugin_model.rb
|
@@ -703,8 +701,11 @@ files:
|
|
703
701
|
- lib/cosmos/models/router_model.rb
|
704
702
|
- lib/cosmos/models/router_status_model.rb
|
705
703
|
- lib/cosmos/models/scope_model.rb
|
704
|
+
- lib/cosmos/models/settings_model.rb
|
705
|
+
- lib/cosmos/models/sorted_model.rb
|
706
706
|
- lib/cosmos/models/target_model.rb
|
707
707
|
- lib/cosmos/models/timeline_model.rb
|
708
|
+
- lib/cosmos/models/tool_config_model.rb
|
708
709
|
- lib/cosmos/models/tool_model.rb
|
709
710
|
- lib/cosmos/models/trigger_group_model.rb
|
710
711
|
- lib/cosmos/models/trigger_model.rb
|
@@ -771,6 +772,7 @@ files:
|
|
771
772
|
- lib/cosmos/topics/calendar_topic.rb
|
772
773
|
- lib/cosmos/topics/command_decom_topic.rb
|
773
774
|
- lib/cosmos/topics/command_topic.rb
|
775
|
+
- lib/cosmos/topics/config_topic.rb
|
774
776
|
- lib/cosmos/topics/interface_topic.rb
|
775
777
|
- lib/cosmos/topics/limits_event_topic.rb
|
776
778
|
- lib/cosmos/topics/notifications_topic.rb
|
@@ -837,7 +839,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
837
839
|
- !ruby/object:Gem::Version
|
838
840
|
version: '0'
|
839
841
|
requirements: []
|
840
|
-
rubygems_version: 3.3.
|
842
|
+
rubygems_version: 3.3.14
|
841
843
|
signing_key:
|
842
844
|
specification_version: 4
|
843
845
|
summary: Ball Aerospace COSMOS
|
data/bin/xtce_converter
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: ascii-8bit
|
3
|
-
|
4
|
-
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
5
|
-
# All Rights Reserved.
|
6
|
-
#
|
7
|
-
# This program is free software; you can modify and/or redistribute it
|
8
|
-
# under the terms of the GNU Affero General Public License
|
9
|
-
# as published by the Free Software Foundation; version 3 with
|
10
|
-
# attribution addendums as found in the LICENSE.txt
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU Affero General Public License for more details.
|
16
|
-
#
|
17
|
-
# This program may also be used under the terms of a commercial or
|
18
|
-
# enterprise edition license of COSMOS if purchased from the
|
19
|
-
# copyright holder
|
20
|
-
|
21
|
-
# This file converts to and from the .xtce file format
|
22
|
-
|
23
|
-
require 'ostruct'
|
24
|
-
require 'optparse'
|
25
|
-
require 'cosmos'
|
26
|
-
|
27
|
-
input_filename = nil
|
28
|
-
|
29
|
-
option_parser = OptionParser.new do |option_parser|
|
30
|
-
option_parser.banner = "Usage: xtce_converter [options] --import input_xtce_filename output_dir\n xtce_converter [options] --export output_dir"
|
31
|
-
option_parser.separator("")
|
32
|
-
|
33
|
-
# Create the help option
|
34
|
-
option_parser.on("-h", "--help", "Show this message") do
|
35
|
-
puts option_parser
|
36
|
-
exit
|
37
|
-
end
|
38
|
-
|
39
|
-
# Create the version option
|
40
|
-
option_parser.on("-v", "--version", "Show version") do
|
41
|
-
puts "COSMOS Version: #{COSMOS_VERSION}"
|
42
|
-
puts "User Version: #{USER_VERSION}" if defined? USER_VERSION
|
43
|
-
exit
|
44
|
-
end
|
45
|
-
|
46
|
-
# Create the system option
|
47
|
-
option_parser.on("--system VALUE", "Use an alternative system.txt file") do |arg|
|
48
|
-
Cosmos::System.instance(File.join(USERPATH, 'config', 'system', arg))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Handle --import mode
|
52
|
-
option_parser.on("-i VALUE", "--import VALUE", "Import the specified .xtce file") do |arg|
|
53
|
-
input_filename = arg
|
54
|
-
end
|
55
|
-
|
56
|
-
# Handle --export mode
|
57
|
-
option_parser.on("-e", "--export", "Create .xtce file(s) from the COSMOS Configuration") do |arg|
|
58
|
-
# This is optional and the default
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
begin
|
63
|
-
option_parser.parse!(ARGV)
|
64
|
-
rescue => err
|
65
|
-
puts err
|
66
|
-
puts option_parser
|
67
|
-
exit
|
68
|
-
end
|
69
|
-
|
70
|
-
if ARGV[0]
|
71
|
-
output_dir = ARGV[0]
|
72
|
-
else
|
73
|
-
puts option_parser
|
74
|
-
exit
|
75
|
-
end
|
76
|
-
|
77
|
-
if input_filename
|
78
|
-
packet_config = Cosmos::PacketConfig.new
|
79
|
-
puts "Processing #{input_filename}..."
|
80
|
-
packet_config.process_file(input_filename, nil)
|
81
|
-
puts "Converting to COSMOS config files in #{output_dir}"
|
82
|
-
packet_config.to_config(output_dir)
|
83
|
-
puts "Success"
|
84
|
-
exit 0
|
85
|
-
else
|
86
|
-
puts "Loading COSMOS Configuration..."
|
87
|
-
Cosmos::System.commands
|
88
|
-
puts "Converting configuration to .xtce files in #{output_dir}"
|
89
|
-
Cosmos::System.instance.instance_variable_get(:@config).to_xtce(output_dir)
|
90
|
-
puts "Success"
|
91
|
-
exit 0
|
92
|
-
end
|