cosmos 5.0.2 → 5.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/data/config/microservice.yaml +47 -35
  3. data/data/config/plugins.yaml +3 -150
  4. data/data/config/target.yaml +70 -0
  5. data/data/config/tool.yaml +37 -31
  6. data/lib/cosmos/api/cmd_api.rb +11 -0
  7. data/lib/cosmos/api/tlm_api.rb +56 -32
  8. data/lib/cosmos/config/config_parser.rb +17 -20
  9. data/lib/cosmos/conversions/generic_conversion.rb +2 -2
  10. data/lib/cosmos/conversions/polynomial_conversion.rb +5 -8
  11. data/lib/cosmos/conversions/segmented_polynomial_conversion.rb +26 -9
  12. data/lib/cosmos/io/json_drb.rb +5 -1
  13. data/lib/cosmos/microservices/cleanup_microservice.rb +28 -29
  14. data/lib/cosmos/microservices/microservice.rb +1 -1
  15. data/lib/cosmos/models/gem_model.rb +1 -1
  16. data/lib/cosmos/models/scope_model.rb +0 -20
  17. data/lib/cosmos/models/target_model.rb +110 -3
  18. data/lib/cosmos/packets/packet.rb +23 -0
  19. data/lib/cosmos/packets/packet_config.rb +2 -2
  20. data/lib/cosmos/packets/packet_item.rb +57 -0
  21. data/lib/cosmos/packets/packet_item_limits.rb +14 -2
  22. data/lib/cosmos/packets/parsers/packet_item_parser.rb +1 -1
  23. data/lib/cosmos/packets/parsers/packet_parser.rb +1 -1
  24. data/lib/cosmos/packets/parsers/xtce_parser.rb +1 -1
  25. data/lib/cosmos/packets/structure_item.rb +10 -1
  26. data/lib/cosmos/script/api_shared.rb +30 -25
  27. data/lib/cosmos/script/commands.rb +5 -7
  28. data/lib/cosmos/script/script.rb +19 -39
  29. data/lib/cosmos/script/storage.rb +92 -105
  30. data/lib/cosmos/tools/table_manager/table_item.rb +1 -1
  31. data/lib/cosmos/topics/command_decom_topic.rb +4 -0
  32. data/lib/cosmos/topics/telemetry_decom_topic.rb +4 -0
  33. data/lib/cosmos/topics/topic.rb +10 -0
  34. data/lib/cosmos/utilities/logger.rb +1 -0
  35. data/lib/cosmos/utilities/s3.rb +61 -0
  36. data/lib/cosmos/utilities/store_autoload.rb +0 -10
  37. data/lib/cosmos/version.rb +5 -4
  38. data/templates/plugin-template/plugin.gemspec +0 -2
  39. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f94954d88cfda8c83f25e5f9a073360d2cf2f7ca9ec359212d3aa6c1bce5a909
4
- data.tar.gz: ab1f28afba922389b69d3c5527944d9e53d8ceca45ebe25746ef1517a44b54b8
3
+ metadata.gz: 8cc294c0ebdd3984fd89fc3a21d4c269c47c6bc4bd7851f0f3ef5ae5393ad365
4
+ data.tar.gz: 89168bfb640bb201cc62f1060b83285326ca7497feeea878c4ec81b6a0c8b40c
5
5
  SHA512:
6
- metadata.gz: 3b5ed0b4186b705cd0360caabbed8f04daac8eaedf9872b8e22fb147c43a0a748fe98afc1b88a8fc99d15d6bd4b3bb9208c1497bb7732f4ef031b856735c6ea7
7
- data.tar.gz: 9353b73975d3d6c0f84560b388e2d175a70c2cd4d6c03dbe2f92a650368007c6c0b44cb8b114292180284bb1b8cd465e8e680fd4d6da85c125fc6fe853bf7156
6
+ metadata.gz: 4f3524b98078bf0568a703d2622f81865fe1133a34434c203b03d2a29ff7dd55510a762fe06b75584fc35f90ebe06a31b4ee3882cdf2553628368f908912173f
7
+ data.tar.gz: 6caeb0cefd049620051a44ffbe0d398e6e43a466bbd7c6cc5edb499652cb5c242c769afb91e560b310700059764ec4ecf64a1bc109ed7654af4ecc568c379e88
@@ -2,65 +2,77 @@
2
2
  MICROSERVICE:
3
3
  summary: Defines a new microservice
4
4
  example: MICROSERVICE EXAMPLE example-microservice
5
+ description: Defines a microservice that the plugin adds to the COSMOS system. Microservices are background software processes that perform persistent processing.
5
6
  parameters:
6
- - name: Folder Name
7
+ - name: Microservice Folder Name
8
+ description: The exact name of the microservice folder in the plugin. ie. microservices/<Microservice Folder Name>
7
9
  required: true
8
- description: The target folder where the microservice is located
9
- values: .*
10
- - name: Name
10
+ values: .+
11
+ - name: Microservice Name
12
+ description: The specific name of this instance of the microservice in the COSMOS system
11
13
  required: true
12
- description: The microservice name
13
- values: .*
14
+ values: .+
14
15
  modifiers:
15
16
  ENV:
16
- summary: Environment variable
17
+ summary: Sets an environment variable in the microservice.
17
18
  parameters:
18
- - name: Name
19
+ - name: Key
19
20
  required: true
20
21
  description: Environment variable name
21
- values: .*
22
+ values: .+
22
23
  - name: Value
23
24
  required: true
24
25
  description: Environment variable value
25
- values: .*
26
+ values: .+
26
27
  WORK_DIR:
27
- summary: Directory to start the microservice in (CWD)
28
+ summary: Set the working directory
29
+ description: Working directory to run the microservice CMD in. Can be a path relative to the microservice folder in the plugin, or an absolute path in the container the microservice runs in.
28
30
  parameters:
29
- - name: Path
31
+ - name: Directory
30
32
  required: true
31
- description: Relative path from the target directory
32
- values: .*
33
+ description: Working directory to run the microservice CMD in. Can be a path relative to the microservice folder in the plugin, or an absolute path in the container the microservice runs in.
34
+ values: .+
33
35
  TOPIC:
34
- summary: Topic the microservice should process data from
36
+ summary: Associate a Redis topic
37
+ description: Redis topic to associate with this microservice. Standard COSMOS microservices such as decom_microservice use this information to know what packet streams to subscribe to. The TOPIC keyword can be used as many times as necessary to associate all needed topics.
35
38
  parameters:
36
- - name: Name
39
+ - name: Topic Name
37
40
  required: true
38
- description: Topic name
39
- values: .*
41
+ description: Redis Topic to associate with the microservice
42
+ values: .+
40
43
  TARGET_NAME:
41
- summary: Target which this microservice processes
44
+ summary: Associate a COSMOS target
45
+ description: COSMOS target to associate with the microservice. For standard COSMOS microservices such as decom_microservice this causes the target configuration to get loaded into the container for the microservice.
42
46
  parameters:
43
- - name: Name
47
+ - name: Target Name
44
48
  required: true
45
- description: Target name
46
- values: .*
49
+ description: COSMOS target to associate with the microservice
50
+ values: .+
47
51
  CMD:
48
- summary: Command to run which starts the microservice
52
+ summary: Command line to execute to run the microservice.
53
+ description: Command line to execute to run the microservice.
49
54
  parameters:
50
- - name: Executable
55
+ - name: Args
51
56
  required: true
52
- description: Executable to call
53
- values: .*
54
- - name: Command parameters
55
- required: false
56
- description: Additional parameters used by the command
57
+ description: One or more arguments to exec to run the microservice.
58
+ values: .+
57
59
  OPTION:
58
- summary: Options to pass to the underlying microservice (used by InterfaceMicroservice, etc.)
60
+ summary: Pass an option to the microservice
61
+ description: Generic key/value(s) options to pass to the microservice. These take the form of KEYWORD/PARAMS like a line in a COSMOS configuration file. Multiple OPTION keywords can be used to pass multiple options to the microservice.
59
62
  parameters:
60
- - name: Name
63
+ - name: Option Name
64
+ required: true
65
+ description: Name of the option
66
+ values: .+
67
+ - name: Option Value(s)
61
68
  required: true
62
- description: Option name
63
- values: .*
64
- - name: Values
69
+ description: One or more values to associate with the option
70
+ values: .+
71
+ CONTAINER:
72
+ summary: Docker Container.
73
+ description: Container to execute and run the microservice in.
74
+ parameters:
75
+ - name: Args
65
76
  required: false
66
- description: Option values
77
+ description: Name of the container
78
+ values: .+
@@ -65,153 +65,6 @@ ROUTER:
65
65
  <%= MetaConfigParser.load('_interfaces.yaml').to_meta_config_yaml(8) %>
66
66
  documentation: Additional parameters are required. Please see the [Interfaces](/docs/v5/interfaces)
67
67
  documentation for more details.
68
- TARGET:
69
- summary: Define a target
70
- description: Defines a target that the plugin adds to the COSMOS system. Targets are entities that COSMOS can send commands to and receive telemetry from.
71
- parameters:
72
- - name: Target Folder Name
73
- description: The exact name of the target folder in the plugin. ie. targets/<Target Folder Name>
74
- required: true
75
- values: .+
76
- - name: Target Name
77
- description: The specific name of this instance of the target in the COSMOS system
78
- required: true
79
- values: .+
80
- MICROSERVICE:
81
- summary: Define a microservice
82
- description: Defines a microservice that the plugin adds to the COSMOS system. Microservices are background software processes that perform persistent processing.
83
- parameters:
84
- - name: Microservice Folder Name
85
- description: The exact name of the microservice folder in the plugin. ie. microservices/<Microservice Folder Name>
86
- required: true
87
- values: .+
88
- - name: Microservice Name
89
- description: The specific name of this instance of the microservice in the COSMOS system
90
- required: true
91
- values: .+
92
- modifiers:
93
- ENV:
94
- summary: Sets an environment variable in the microservice.
95
- description: Sets an environment variable in the microservice.
96
- parameters:
97
- - name: Key
98
- required: true
99
- description: Name of the environment variable
100
- values: .+
101
- - name: Value
102
- required: true
103
- description: Value of the environment variable
104
- values: .+
105
- WORK_DIR:
106
- summary: Set the working directory
107
- description: Working directory to run the microservice CMD in. Can be a path relative to the microservice folder in the plugin, or an absolute path in the container the microservice runs in.
108
- parameters:
109
- - name: Directory
110
- required: true
111
- description: Working directory to run the microservice CMD in. Can be a path relative to the microservice folder in the plugin, or an absolute path in the container the microservice runs in.
112
- values: .+
113
- TOPIC:
114
- summary: Associate a Redis topic
115
- description: Redis topic to associate with this microservice. Standard COSMOS microservices such as decom_microservice use this information to know what packet streams to subscribe to. The TOPIC keyword can be used as many times as necessary to associate all needed topics.
116
- parameters:
117
- - name: Topic Name
118
- required: true
119
- description: Redis Topic to associate with the microservice
120
- values: .+
121
- TARGET_NAME:
122
- summary: Associate a COSMOS target
123
- description: COSMOS target to associate with the microservice. For standard COSMOS microservices such as decom_microservice this causes the target configuration to get loaded into the container for the microservice.
124
- parameters:
125
- - name: Target Name
126
- required: true
127
- description: COSMOS target to associate with the microservice
128
- values: .+
129
- CMD:
130
- summary: Command line to execute to run the microservice.
131
- description: Command line to execute to run the microservice.
132
- parameters:
133
- - name: Args
134
- required: true
135
- description: One or more arguments to exec to run the microservice.
136
- values: .+
137
- CONTAINER:
138
- summary: Docker Container.
139
- description: Container to execute and run the microservice in.
140
- parameters:
141
- - name: Args
142
- required: false
143
- description: Name of the container
144
- values: .+
145
- OPTION:
146
- summary: Pass an option to the microservice
147
- description: Generic key/value(s) options to pass to the microservice. These take the form of KEYWORD/PARAMS like a line in a COSMOS configuration file. Multiple OPTION keywords can be used to pass multiple options to the microservice.
148
- parameters:
149
- - name: Option Name
150
- required: true
151
- description: Name of the option
152
- values: .+
153
- - name: Option Value(s)
154
- required: true
155
- description: One or more values to associate with the option
156
- values: .+
157
- TOOL:
158
- summary: Define a tool
159
- description: Defines a tool that the plugin adds to the COSMOS system. Tools are web based applications that make use of the Single-SPA javascript library that allows them to by dynamically added to the running system as independent frontend microservices.
160
- parameters:
161
- - name: Tool Folder Name
162
- description: The exact name of the tool folder in the plugin. ie. tools/<Tool Folder Name>
163
- required: true
164
- values: .+
165
- - name: Tool Name
166
- description: Name of the tool that is displayed in the COSMOS Navigation menu
167
- required: true
168
- values: .+
169
- modifiers:
170
- URL:
171
- summary: Url used to access the tool
172
- description: The relative url used to access the tool. Defaults to "/tools/<Tool Folder Name>".
173
- parameters:
174
- - name: Url
175
- required: true
176
- description: The url. If not given defaults to tools/<Tool Folder Name>. Generally should not be given unless linking to external tools.
177
- values: .+
178
- INLINE_URL:
179
- summary: Internal url to load a tool
180
- description: The url of the javascript file used to load the tool into single-SPA. Defaults to "js/app.js".
181
- parameters:
182
- - name: Url
183
- required: true
184
- description: The inline url. If not given defaults to js/app.js. Generally should not be given unless using a non-standard filename.
185
- values: .+
186
- WINDOW:
187
- summary: How to display the tool when navigated to
188
- description: The window mode used to display the tool. Currently supported modes are INLINE which opens the tool internally without refreshing the page using the Single-SPA framework, and NEW which opens the tool in a new TAB. A future release will support IFRAME to open external tools in an Iframe within COSMOS.
189
- parameters:
190
- - name: Window Mode
191
- required: true
192
- description: INLINE, NEW, or IFRAME
193
- values: .+
194
- ICON:
195
- summary: Set tool icon
196
- description: Icon shown next to the tool name in the COSMOS navigation menu.
197
- parameters:
198
- - name: Icon Name
199
- required: true
200
- description: Icon to display next to the tool name. Icons come from Font Awesome, Material Design, and Astro. See https://vuetifyjs.com/en/components/icons/
201
- values: .+
202
- CATEGORY:
203
- summary: Category for the tool
204
- description: Associates the tool with a category. In a future release this will be able to organize tools into submenus in the Navigation menu.
205
- parameters:
206
- - name: Category Name
207
- required: true
208
- description: Category to associate the tool with
209
- values: .+
210
- SHOWN:
211
- summary: Show the tool or not
212
- description: Whether or not the tool is shown in the Navigation menu. Should generally be true, except for the cosmos base tool.
213
- parameters:
214
- - name: Shown
215
- required: true
216
- description: Whether or not the tool is shown. TRUE or FALSE
217
- values: .+
68
+ <%= MetaConfigParser.load('target.yaml').to_meta_config_yaml() %>
69
+ <%= MetaConfigParser.load('microservice.yaml').to_meta_config_yaml() %>
70
+ <%= MetaConfigParser.load('tool.yaml').to_meta_config_yaml() %>
@@ -28,6 +28,13 @@ TARGET:
28
28
  required: true
29
29
  description: Maximum file size in bytes (default = 50_000_000)
30
30
  values: \d+
31
+ CMD_LOG_RETAIN_TIME:
32
+ summary: How long to keep raw command logs in seconds.
33
+ parameters:
34
+ - name: Time
35
+ required: true
36
+ description: Number of seconds to keep raw command logs (default = nil = Forever)
37
+ values: \d+
31
38
  CMD_DECOM_LOG_CYCLE_TIME:
32
39
  summary: Command decommutation logs can be cycled on a time interval.
33
40
  parameters:
@@ -42,6 +49,13 @@ TARGET:
42
49
  required: true
43
50
  description: Maximum file size in bytes (default = 50_000_000)
44
51
  values: \d+
52
+ CMD_DECOM_LOG_RETAIN_TIME:
53
+ summary: How long to keep decom command logs in seconds.
54
+ parameters:
55
+ - name: Time
56
+ required: true
57
+ description: Number of seconds to keep decom command logs (default = nil = Forever)
58
+ values: \d+
45
59
  TLM_LOG_CYCLE_TIME:
46
60
  summary: Telemetry binary logs can be cycled on a time interval.
47
61
  parameters:
@@ -56,6 +70,13 @@ TARGET:
56
70
  required: true
57
71
  description: Maximum file size in bytes (default = 50_000_000)
58
72
  values: \d+
73
+ TLM_LOG_RETAIN_TIME:
74
+ summary: How long to keep raw telemetry logs in seconds.
75
+ parameters:
76
+ - name: Time
77
+ required: true
78
+ description: Number of seconds to keep raw telemetry logs (default = nil = Forever)
79
+ values: \d+
59
80
  TLM_DECOM_LOG_CYCLE_TIME:
60
81
  summary: Telemetry decommutation logs can be cycled on a time interval.
61
82
  parameters:
@@ -70,3 +91,52 @@ TARGET:
70
91
  required: true
71
92
  description: Maximum file size in bytes (default = 50_000_000)
72
93
  values: \d+
94
+ TLM_DECOM_LOG_RETAIN_TIME:
95
+ summary: How long to keep decom telemetry logs in seconds.
96
+ parameters:
97
+ - name: Time
98
+ required: true
99
+ description: Number of seconds to keep decom telemetry logs (default = nil = Forever)
100
+ values: \d+
101
+ REDUCED_MINUTE_LOG_RETAIN_TIME:
102
+ summary: How long to keep reduced minute telemetry logs in seconds.
103
+ parameters:
104
+ - name: Time
105
+ required: true
106
+ description: Number of seconds to keep reduced minute telemetry logs (default = nil = Forever)
107
+ values: \d+
108
+ REDUCED_HOUR_LOG_RETAIN_TIME:
109
+ summary: How long to keep reduced hour telemetry logs in seconds.
110
+ parameters:
111
+ - name: Time
112
+ required: true
113
+ description: Number of seconds to keep reduced hour telemetry logs (default = nil = Forever)
114
+ values: \d+
115
+ REDUCED_DAY_LOG_RETAIN_TIME:
116
+ summary: How long to keep reduced day telemetry logs in seconds.
117
+ parameters:
118
+ - name: Time
119
+ required: true
120
+ description: Number of seconds to keep reduced day telemetry logs (default = nil = Forever)
121
+ values: \d+
122
+ LOG_RETAIN_TIME:
123
+ summary: How long to keep all regular telemetry logs in seconds.
124
+ parameters:
125
+ - name: Time
126
+ required: true
127
+ description: Number of seconds to keep all regular telemetry logs (default = nil = Forever)
128
+ values: \d+
129
+ REDUCED_LOG_RETAIN_TIME:
130
+ summary: How long to keep all reduced telemetry logs in seconds.
131
+ parameters:
132
+ - name: Time
133
+ required: true
134
+ description: Number of seconds to keep all reduced telemetry logs (default = nil = Forever)
135
+ values: \d+
136
+ CLEANUP_POLL_TIME:
137
+ summary: Period at which to run the cleanup process.
138
+ parameters:
139
+ - name: Time
140
+ required: true
141
+ description: Number of seconds between runs of the cleanup process (default = 900 = 15 minutes)
142
+ values: \d+
@@ -1,57 +1,63 @@
1
1
  ---
2
2
  TOOL:
3
- summary: Defines a new tool
3
+ summary: Define a tool
4
4
  example: TOOL DEMO Demo
5
+ description: Defines a tool that the plugin adds to the COSMOS system. Tools are web based applications that make use of the Single-SPA javascript library that allows them to by dynamically added to the running system as independent frontend microservices.
5
6
  parameters:
6
- - name: Folder Name
7
+ - name: Tool Folder Name
8
+ description: The exact name of the tool folder in the plugin. ie. tools/<Tool Folder Name>
7
9
  required: true
8
- description: The folder where the tool is located relative to the tools folder in the plugin
9
- values: .*
10
- - name: Name
10
+ values: .+
11
+ - name: Tool Name
12
+ description: Name of the tool that is displayed in the COSMOS Navigation menu
11
13
  required: true
12
- description: The tool name displayed in the Nav bar
13
- values: .*
14
+ values: .+
14
15
  modifiers:
15
16
  URL:
16
- summary: Url to reach the tool relative to the tools Folder Name, or absolute
17
+ summary: Url used to access the tool
18
+ description: The relative url used to access the tool. Defaults to "/tools/<Tool Folder Name>".
17
19
  parameters:
18
- - name: URL
20
+ - name: Url
19
21
  required: true
20
- description: URL
21
- values: .*
22
+ description: The url. If not given defaults to tools/<Tool Folder Name>. Generally should not be given unless linking to external tools.
23
+ values: .+
22
24
  INLINE_URL:
23
- summary: Single SPA url to reach the tool
24
- example: js/app.js
25
+ summary: Internal url to load a tool
26
+ description: The url of the javascript file used to load the tool into single-SPA. Defaults to "js/app.js".
25
27
  parameters:
26
- - name: URL
28
+ - name: Url
27
29
  required: true
28
- description: URL
29
- values: .*
30
- ICON:
31
- summary: Icon used to display the tool link
32
- parameters:
33
- - name: Name
34
- required: true
35
- description: Material design icon name (https://materialdesignicons.com/)
36
- values: .*
30
+ description: The inline url. If not given defaults to js/app.js. Generally should not be given unless using a non-standard filename.
31
+ values: .+
37
32
  WINDOW:
38
- summary: How the tool should be displayed
33
+ summary: How to display the tool when navigated to
34
+ description: The window mode used to display the tool. INLINE opens the tool internally without refreshing the page using the Single-SPA framework. IFRAME opens external tools in an Iframe within COSMOS. NEW opens the tool in a new TAB.
39
35
  parameters:
40
- - name: Mode
36
+ - name: Window Mode
41
37
  required: true
42
38
  description: Tool display mode
43
39
  values: ["INLINE", "IFRAME", "NEW"]
40
+ ICON:
41
+ summary: Set tool icon
42
+ description: Icon shown next to the tool name in the COSMOS navigation menu.
43
+ parameters:
44
+ - name: Icon Name
45
+ required: true
46
+ description: Icon to display next to the tool name. Icons come from Font Awesome, Material Design (https://materialdesignicons.com/), and Astro.
47
+ values: .+
44
48
  CATEGORY:
45
- summary: Category to place the tool into
49
+ summary: Category for the tool
50
+ description: Associates the tool with a category. In a future release this will be able to organize tools into submenus in the Navigation menu.
46
51
  parameters:
47
- - name: Category
52
+ - name: Category Name
48
53
  required: true
49
- description: Name of a category to organize a tool into
50
- values: .*
54
+ description: Category to associate the tool with
55
+ values: .+
51
56
  SHOWN:
52
- summary: Is the Tool Shown in the Nav Bar
57
+ summary: Show the tool or not
58
+ description: Whether or not the tool is shown in the Navigation menu. Should generally be true, except for the cosmos base tool.
53
59
  parameters:
54
60
  - name: Shown
55
61
  required: true
56
- description: Is Shown?
62
+ description: Whether or not the tool is shown. TRUE or FALSE
57
63
  values: ["true", "false"]
@@ -35,6 +35,7 @@ module Cosmos
35
35
  'cmd_raw_no_checks',
36
36
  'send_raw',
37
37
  'get_all_commands',
38
+ 'get_all_commands_list',
38
39
  'get_command',
39
40
  'get_parameter',
40
41
  'get_cmd_buffer',
@@ -212,6 +213,16 @@ module Cosmos
212
213
  TargetModel.packets(target_name, type: :CMD, scope: scope)
213
214
  end
214
215
 
216
+ # Returns an array of all the command names and their descriptions
217
+ #
218
+ # @since 5.0.3
219
+ # @param target_name [String] Name of the target
220
+ # @return [Array<Hash>] Array of all commands as a hash
221
+ def get_all_commands_list(target_name, scope: $cosmos_scope, token: $cosmos_token)
222
+ authorize(permission: 'cmd_info', target_name: target_name, scope: scope, token: token)
223
+ TargetModel.all_packet_name_descriptions(target_name, type: :CMD, scope: scope)
224
+ end
225
+
215
226
  # Returns a hash of the given command
216
227
  #
217
228
  # @since 5.0.0
@@ -19,6 +19,8 @@
19
19
 
20
20
  require 'cosmos/models/target_model'
21
21
  require 'cosmos/models/cvt_model'
22
+ require 'cosmos/packets/packet'
23
+ require 'cosmos/topics/telemetry_topic'
22
24
  require 'cosmos/utilities/s3'
23
25
 
24
26
  module Cosmos
@@ -38,10 +40,11 @@ module Cosmos
38
40
  'get_tlm_packet',
39
41
  'get_tlm_values',
40
42
  'get_all_telemetry',
43
+ 'get_all_telemetry_list',
41
44
  'get_telemetry',
42
45
  'get_item',
43
46
  'subscribe_packets',
44
- 'get_packet',
47
+ 'get_packets',
45
48
  'get_all_tlm_info',
46
49
  'get_tlm_cnt',
47
50
  'get_packet_derived_items',
@@ -125,19 +128,18 @@ module Cosmos
125
128
  # Check that the packet exists ... exceptions are raised if not
126
129
  TargetModel.packet(target_name, packet_name, scope: scope)
127
130
  end
128
- inject = {}
129
- inject['inject_tlm'] = true
130
- inject['log'] = log
131
- inject['target_name'] = target_name
132
- inject['packet_name'] = packet_name
133
- inject['item_hash'] = JSON.generate(item_hash) if item_hash
134
- inject['type'] = type
135
-
136
- InterfaceModel.all(scope: scope).each do |name, interface|
137
- if interface['target_names'].include? target_name
138
- Store.write_topic("{#{scope}__CMD}INTERFACE__#{interface['name']}", inject, '*', 100)
131
+
132
+ packet_hash = get_telemetry(target_name, packet_name, scope: scope, token: token)
133
+ packet = Packet.from_json(packet_hash)
134
+ if item_hash
135
+ item_hash.each do |name, value|
136
+ packet.write(name.to_s, value, type)
139
137
  end
140
138
  end
139
+ packet.received_time = Time.now.sys
140
+ # TODO: New packet so received_count is not correct
141
+ packet.received_count += 1
142
+ TelemetryTopic.write_packet(packet, scope: scope)
141
143
  end
142
144
 
143
145
  # Override the current value table such that a particular item always
@@ -245,7 +247,17 @@ module Cosmos
245
247
  # @return [Array<Hash>] Array of all telemetry packet hashes
246
248
  def get_all_telemetry(target_name, scope: $cosmos_scope, token: $cosmos_token)
247
249
  authorize(permission: 'tlm', target_name: target_name, scope: scope, token: token)
248
- TargetModel.packets(target_name, scope: scope)
250
+ TargetModel.packets(target_name, type: :TLM, scope: scope)
251
+ end
252
+
253
+ # Returns an array of all telemetry packet's name and descriptions
254
+ #
255
+ # @since 5.0.3
256
+ # @param target_name [String] Name of the target
257
+ # @return [Array<Hash>] Array of all telemetry packet name and descriptions
258
+ def get_all_telemetry_list(target_name, scope: $cosmos_scope, token: $cosmos_token)
259
+ authorize(permission: 'tlm', target_name: target_name, scope: scope, token: token)
260
+ TargetModel.all_packet_name_descriptions(target_name, type: :TLM, scope: scope)
249
261
  end
250
262
 
251
263
  # Returns a telemetry packet hash
@@ -271,41 +283,53 @@ module Cosmos
271
283
  TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
272
284
  end
273
285
 
286
+ # 2x double underscore since __ is reserved
287
+ SUBSCRIPTION_DELIMITER = '____'
288
+
274
289
  # Subscribe to a list of packets. An ID is returned which is passed to
275
- # get_packet(id) to yield packets back to a block.
290
+ # get_packets(id) to return packets.
276
291
  #
277
292
  # @param packets [Array<Array<String, String>>] Array of arrays consisting of target name, packet name
278
- # @return [String] ID which should be passed to get_packet
293
+ # @return [String] ID which should be passed to get_packets
279
294
  def subscribe_packets(packets, scope: $cosmos_scope, token: $cosmos_token)
280
295
  if !packets.is_a?(Array) || !packets[0].is_a?(Array)
281
296
  raise ArgumentError, "packets must be nested array: [['TGT','PKT'],...]"
282
297
  end
283
298
 
284
- result = [Time.now.to_nsec_from_epoch]
299
+ result = {}
285
300
  packets.each do |target_name, packet_name|
286
301
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, scope: scope, token: token)
287
- result << "#{scope}__DECOM__{#{target_name}}__#{packet_name}"
302
+ topic = "#{scope}__DECOM__{#{target_name}}__#{packet_name}"
303
+ id, _ = Store.read_topic_last(topic)
304
+ result[topic] = id ? id : '0-0'
288
305
  end
289
- result.join("\n")
306
+ result.to_a.join(SUBSCRIPTION_DELIMITER)
290
307
  end
291
308
  # Alias the singular as well since that matches COSMOS 4
292
309
  alias subscribe_packet subscribe_packets
293
310
 
294
- # Get a packet which was previously subscribed to by subscribe_packet.
295
- # This method takes a block and yields back packet hashes.
296
- def get_packet(id, scope: $cosmos_scope, token: $cosmos_token)
311
+ # Get packets based on ID returned from subscribe_packet.
312
+ # @param id [String] ID returned from subscribe_packets or last call to get_packets
313
+ # @param block [Integer] Number of milliseconds to block when requesting packets
314
+ # @param count [Integer] Maximum number of packets to return from EACH packet stream
315
+ # @return [Array<String, Array<Hash>] Array of the ID and array of all packets found
316
+ def get_packets(id, block: nil, count: 1000, scope: $cosmos_scope, token: $cosmos_token)
297
317
  authorize(permission: 'tlm', scope: scope, token: token)
298
- offset, *topics = id.split("\n")
299
- offsets = []
300
- # Create a common array of offsets for each of the topics
301
- topics.length.times do
302
- offsets << (offset.to_i / 1_000_000).to_s + '-0'
303
- end
304
- Topic.read_topics(topics, offsets) do |topic, msg_id, msg_hash, redis|
305
- json_hash = JSON.parse(msg_hash['json_data'])
306
- msg_hash.delete('json_data')
307
- yield msg_hash.merge(json_hash)
318
+ # Split the list of topic, ID values and turn it into a hash for easy updates
319
+ lookup = Hash[*id.split(SUBSCRIPTION_DELIMITER)]
320
+ xread = Store.xread(lookup.keys, lookup.values, block: block, count: count)
321
+ # Return the original ID and nil if we didn't get anything
322
+ return [id, nil] if xread.empty?
323
+ packets = []
324
+ xread.each do |topic, data|
325
+ data.each do |id, msg_hash|
326
+ lookup[topic] = id # Store the new ID
327
+ json_hash = JSON.parse(msg_hash['json_data'])
328
+ msg_hash.delete('json_data')
329
+ packets << msg_hash.merge(json_hash)
330
+ end
308
331
  end
332
+ return [lookup.to_a.join(SUBSCRIPTION_DELIMITER), packets]
309
333
  end
310
334
 
311
335
  # Get the receive count for a telemetry packet
@@ -336,7 +360,7 @@ module Cosmos
336
360
  key = "#{scope}__TELEMETRY__{#{x}}__#{x}"
337
361
  result << [x, x, _get_cnt(key)]
338
362
  end
339
- # Return the results sorted by target, packet
363
+ # Return the result sorted by target, packet
340
364
  result.sort_by { |a| [a[0], a[1]] }
341
365
  end
342
366