openc3 7.5.1 → 7.6.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.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -0
  3. data/bin/openc3cli +82 -5
  4. data/data/config/_params.yaml +3 -0
  5. data/data/config/command_modifiers.yaml +5 -3
  6. data/data/config/default_plugins.yaml +1 -0
  7. data/data/config/interface_modifiers.yaml +17 -1
  8. data/data/config/item_modifiers.yaml +24 -1
  9. data/data/config/microservice.yaml +15 -1
  10. data/data/config/parameter_modifiers.yaml +4 -4
  11. data/data/config/plugins.yaml +511 -3
  12. data/data/config/settings.yaml +17 -0
  13. data/data/config/target.yaml +53 -0
  14. data/data/config/telemetry.yaml +58 -2
  15. data/data/config/widgets.yaml +30 -0
  16. data/lib/openc3/accessors/accessor.rb +14 -2
  17. data/lib/openc3/accessors/binary_accessor.rb +25 -5
  18. data/lib/openc3/api/CLAUDE.md +1 -0
  19. data/lib/openc3/api/api.rb +1 -0
  20. data/lib/openc3/api/cmd_api.rb +9 -1
  21. data/lib/openc3/api/interface_api.rb +7 -2
  22. data/lib/openc3/api/limits_api.rb +93 -41
  23. data/lib/openc3/api/router_api.rb +7 -2
  24. data/lib/openc3/api/settings_api.rb +4 -1
  25. data/lib/openc3/api/shared_resource_api.rb +107 -0
  26. data/lib/openc3/api/tlm_api.rb +10 -0
  27. data/lib/openc3/interfaces/http_client_interface.rb +84 -27
  28. data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
  29. data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
  30. data/lib/openc3/io/json_api.rb +2 -10
  31. data/lib/openc3/io/json_api_object.rb +2 -10
  32. data/lib/openc3/logs/packet_log_writer.rb +8 -3
  33. data/lib/openc3/microservices/decom_common.rb +4 -1
  34. data/lib/openc3/microservices/decom_microservice.rb +52 -6
  35. data/lib/openc3/microservices/interface_decom_common.rb +13 -0
  36. data/lib/openc3/microservices/interface_microservice.rb +50 -11
  37. data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
  38. data/lib/openc3/microservices/log_microservice.rb +22 -8
  39. data/lib/openc3/microservices/microservice.rb +8 -2
  40. data/lib/openc3/microservices/multi_microservice.rb +76 -22
  41. data/lib/openc3/microservices/queue_microservice.rb +29 -24
  42. data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
  43. data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
  44. data/lib/openc3/models/bridge_model.rb +3 -3
  45. data/lib/openc3/models/cvt_model.rb +3 -1
  46. data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
  47. data/lib/openc3/models/interface_model.rb +27 -7
  48. data/lib/openc3/models/microservice_group.rb +167 -0
  49. data/lib/openc3/models/microservice_model.rb +88 -2
  50. data/lib/openc3/models/panel_model.rb +109 -0
  51. data/lib/openc3/models/plugin_model.rb +1006 -26
  52. data/lib/openc3/models/plugin_store_model.rb +6 -1
  53. data/lib/openc3/models/protected_storage_model.rb +64 -0
  54. data/lib/openc3/models/queue_model.rb +19 -10
  55. data/lib/openc3/models/scope_model.rb +80 -3
  56. data/lib/openc3/models/setting_model.rb +2 -2
  57. data/lib/openc3/models/shared_resource_model.rb +381 -0
  58. data/lib/openc3/models/target_model.rb +324 -68
  59. data/lib/openc3/operators/microservice_operator.rb +76 -9
  60. data/lib/openc3/operators/operator.rb +29 -0
  61. data/lib/openc3/packets/commands.rb +16 -16
  62. data/lib/openc3/packets/limits.rb +2 -0
  63. data/lib/openc3/packets/packet.rb +75 -4
  64. data/lib/openc3/packets/packet_config.rb +152 -13
  65. data/lib/openc3/packets/packet_item.rb +35 -14
  66. data/lib/openc3/packets/packet_item_limits.rb +67 -6
  67. data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
  68. data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
  69. data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
  70. data/lib/openc3/packets/parsers/state_parser.rb +1 -1
  71. data/lib/openc3/script/CLAUDE.md +1 -0
  72. data/lib/openc3/script/api_shared.rb +17 -9
  73. data/lib/openc3/script/calendar.rb +18 -6
  74. data/lib/openc3/script/commands.rb +11 -9
  75. data/lib/openc3/script/critical_cmd.rb +22 -2
  76. data/lib/openc3/script/metadata.rb +30 -4
  77. data/lib/openc3/script/plugins.rb +8 -0
  78. data/lib/openc3/script/script.rb +8 -24
  79. data/lib/openc3/script/web_socket_api.rb +23 -17
  80. data/lib/openc3/system/system.rb +9 -3
  81. data/lib/openc3/top_level.rb +17 -0
  82. data/lib/openc3/topics/command_topic.rb +7 -1
  83. data/lib/openc3/topics/decom_interface_topic.rb +9 -3
  84. data/lib/openc3/topics/discovery_topic.rb +84 -0
  85. data/lib/openc3/topics/limits_event_topic.rb +236 -17
  86. data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
  87. data/lib/openc3/topics/topic.rb +2 -1
  88. data/lib/openc3/utilities/authentication.rb +67 -16
  89. data/lib/openc3/utilities/cli_generator.rb +117 -25
  90. data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
  91. data/lib/openc3/utilities/config_overlay.rb +24 -1
  92. data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
  93. data/lib/openc3/utilities/hardware_discovery.rb +279 -0
  94. data/lib/openc3/utilities/limits_rollup.rb +81 -0
  95. data/lib/openc3/utilities/local_mode.rb +48 -5
  96. data/lib/openc3/utilities/questdb_client.rb +130 -22
  97. data/lib/openc3/utilities/reingest_job.rb +12 -3
  98. data/lib/openc3/utilities/running_script.rb +206 -49
  99. data/lib/openc3/utilities/script.rb +24 -12
  100. data/lib/openc3/utilities/script_env.rb +164 -0
  101. data/lib/openc3/utilities/script_message_signing.rb +133 -0
  102. data/lib/openc3/utilities/store_autoload.rb +32 -1
  103. data/lib/openc3/utilities/store_queued.rb +5 -1
  104. data/lib/openc3/version.rb +6 -6
  105. data/templates/command_validator/command_validator.py +9 -9
  106. data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
  107. data/templates/panel/Rakefile +24 -0
  108. data/templates/panel/package.json +17 -0
  109. data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
  110. data/templates/panel/src/Panel.js +52 -0
  111. data/templates/panel/src/Panel.vue +60 -0
  112. data/templates/panel/src/panelSdk.js +24 -0
  113. data/templates/panel/vite-Panel.config.js +43 -0
  114. data/templates/tool_vue/package.json +3 -3
  115. data/templates/widget/package.json +2 -2
  116. metadata +24 -56
  117. data/templates/tool_angular/.editorconfig +0 -16
  118. data/templates/tool_angular/.gitignore +0 -44
  119. data/templates/tool_angular/.vscode/extensions.json +0 -4
  120. data/templates/tool_angular/.vscode/launch.json +0 -20
  121. data/templates/tool_angular/.vscode/tasks.json +0 -42
  122. data/templates/tool_angular/angular.json +0 -111
  123. data/templates/tool_angular/extra-webpack.config.js +0 -8
  124. data/templates/tool_angular/package.json +0 -48
  125. data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
  126. data/templates/tool_angular/src/app/app.component.html +0 -22
  127. data/templates/tool_angular/src/app/app.component.scss +0 -18
  128. data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
  129. data/templates/tool_angular/src/app/app.component.ts +0 -52
  130. data/templates/tool_angular/src/app/app.module.ts +0 -30
  131. data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
  132. data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
  133. data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
  134. data/templates/tool_angular/src/assets/.gitkeep +0 -0
  135. data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
  136. data/templates/tool_angular/src/environments/environment.ts +0 -16
  137. data/templates/tool_angular/src/favicon.ico +0 -0
  138. data/templates/tool_angular/src/index.html +0 -13
  139. data/templates/tool_angular/src/main.single-spa.ts +0 -40
  140. data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
  141. data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
  142. data/templates/tool_angular/src/styles.scss +0 -1
  143. data/templates/tool_angular/tsconfig.app.json +0 -13
  144. data/templates/tool_angular/tsconfig.json +0 -33
  145. data/templates/tool_angular/tsconfig.spec.json +0 -14
  146. data/templates/tool_react/.eslintrc +0 -7
  147. data/templates/tool_react/.gitignore +0 -71
  148. data/templates/tool_react/.prettierignore +0 -8
  149. data/templates/tool_react/babel.config.json +0 -29
  150. data/templates/tool_react/jest.config.js +0 -12
  151. data/templates/tool_react/package.json +0 -51
  152. data/templates/tool_react/src/openc3-tool_name.js +0 -24
  153. data/templates/tool_react/src/root.component.js +0 -88
  154. data/templates/tool_react/src/root.component.test.js +0 -9
  155. data/templates/tool_react/webpack.config.js +0 -27
  156. data/templates/tool_svelte/.gitignore +0 -71
  157. data/templates/tool_svelte/.prettierignore +0 -8
  158. data/templates/tool_svelte/.prettierrc.js +0 -5
  159. data/templates/tool_svelte/babel.config.js +0 -12
  160. data/templates/tool_svelte/build/smui.css +0 -1
  161. data/templates/tool_svelte/jest.config.js +0 -9
  162. data/templates/tool_svelte/package.json +0 -49
  163. data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
  164. data/templates/tool_svelte/rollup.config.js +0 -74
  165. data/templates/tool_svelte/src/App.svelte +0 -42
  166. data/templates/tool_svelte/src/App.test.js +0 -9
  167. data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
  168. data/templates/tool_svelte/src/tool_name.js +0 -17
  169. data/templates/widget/LICENSE.md +0 -20
@@ -15,6 +15,7 @@ TELEMETRY:
15
15
  description:
16
16
  Name of this telemetry packet. Also referred to as its mnemonic.
17
17
  Must be unique to telemetry packets in this target. Ideally will be as short and clear as possible.
18
+ LIMITS_GROUP is reserved for the packet COSMOS generates from the target's limits groups.
18
19
  values: \D\S*
19
20
  - name: Endianness
20
21
  required: true
@@ -59,6 +60,30 @@ LIMITS_GROUP:
59
60
  but the last enabled or disabled group "wins". For example, if an item belongs to
60
61
  GROUP1 and GROUP2 and you first enable GROUP1 and then disable GROUP2 the item will
61
62
  be disabled. If you then enable GROUP1 again it will be enabled.
63
+
64
+
65
+ Each limits group is also published as telemetry in the LIMITS_GROUP packet of the
66
+ target which defines the group. For a group named THERMAL defined by the INST target,
67
+ INST LIMITS_GROUP THERMAL is the most severe limits state (GREEN, YELLOW or RED) of the
68
+ group's members which have limits enabled, so it can be displayed on screens, graphed,
69
+ used in scripts with tlm and wait_check, and extracted from history. It's BLUE only
70
+ when every member which counts is BLUE, and DISABLED when limits are disabled on every
71
+ member. INST LIMITS_GROUP THERMAL_ENABLED is TRUE when limits are enabled on every
72
+ member, FALSE when they're disabled on every member, and PARTIAL otherwise, for example
73
+ when a nested group is disabled. A group whose enabled members have no limits state yet
74
+ is GREEN with no limits color. The LIMITS_GROUP packet
75
+ name is reserved, so a target can't define a telemetry packet named LIMITS_GROUP.
76
+
77
+
78
+ Group names become item names so they follow the same rules as ITEM names
79
+ (no spaces, quotes, double underscores or trailing underscore). They also become
80
+ time-series database columns so they can't contain characters the database
81
+ replaces with an underscore, like the period in TEMP.A. They can't end in _ENABLED,
82
+ use a reserved item name like RECEIVED_COUNT or PACKET_TIME, or be longer than 119
83
+ characters. A group whose name breaks these rules is skipped with a warning, along
84
+ with its LIMITS_GROUP_ITEM and NESTED_LIMITS_GROUP lines, and a NESTED_LIMITS_GROUP
85
+ with such a name is skipped the same way. Group names only need to be unique within
86
+ a target, so two targets can each define a THERMAL group.
62
87
  parameters:
63
88
  - name: Group Name
64
89
  required: true
@@ -68,7 +93,10 @@ LIMITS_GROUP_ITEM:
68
93
  summary: Adds the specified telemetry item to the last defined LIMITS_GROUP
69
94
  description:
70
95
  Limits group information is typically kept in a separate configuration
71
- file in the config/TARGET/cmd_tlm folder named limits_groups.txt.
96
+ file in the config/TARGET/cmd_tlm folder named limits_groups.txt. Use
97
+ NESTED_LIMITS_GROUP to add another limits group. A LIMITS_GROUP_ITEM in a
98
+ packet named LIMITS_GROUP is skipped with a warning since that packet holds
99
+ the rolled up state of limits groups.
72
100
  parameters:
73
101
  - name: Target Name
74
102
  required: true
@@ -83,7 +111,35 @@ LIMITS_GROUP_ITEM:
83
111
  description: Name of the telemetry item to add to the group
84
112
  values: .+
85
113
  example: |
86
- LIMITS_GROUP SUBSYSTEM
114
+ LIMITS_GROUP THERMAL
87
115
  LIMITS_GROUP_ITEM INST HEALTH_STATUS TEMP1
88
116
  LIMITS_GROUP_ITEM INST HEALTH_STATUS TEMP2
89
117
  LIMITS_GROUP_ITEM INST HEALTH_STATUS TEMP3
118
+ NESTED_LIMITS_GROUP:
119
+ summary: Nests the specified limits group in the last defined LIMITS_GROUP
120
+ description:
121
+ The parent group rolls up the nested group's state. Enabling or disabling the
122
+ parent enables or disables every group and item below it unless the API is
123
+ called with cascade false, which only changes the parent itself and the items
124
+ directly in it. A group disabled this way is DISABLED and its parents ignore it
125
+ while its nested groups keep checking limits and rolling up their own state. Pass just
126
+ the group name to nest a group defined by the same target, or the target name
127
+ and group name to nest a group defined by another target. A nested group can be
128
+ installed after its parent and is ignored until it is.
129
+ Nested groups can't form a loop, so a group can't contain itself directly or
130
+ through other groups. Installing a target skips the NESTED_LIMITS_GROUP which
131
+ would close a loop and logs a warning.
132
+ parameters:
133
+ - name: Target Name or Group Name
134
+ required: true
135
+ description: Name of the target which defines the group, or the name of a limits group of this target when it's the only parameter
136
+ values: .+
137
+ - name: Group Name
138
+ required: false
139
+ description: Name of the limits group. Required when the first parameter is a target name.
140
+ values: .+
141
+ example: |
142
+ LIMITS_GROUP SPACECRAFT
143
+ NESTED_LIMITS_GROUP THERMAL
144
+ NESTED_LIMITS_GROUP INST2 POWER
145
+ LIMITS_GROUP_ITEM INST HEALTH_STATUS VOLTS
@@ -119,6 +119,36 @@ Layout Widgets:
119
119
  END
120
120
  TABBOOK:
121
121
  summary: Creates a tabbed area in which to place TABITEM widgets
122
+ example: |
123
+ TABBOOK
124
+ SETTING LIMITS_STATE TRUE
125
+ TABITEM "Temperatures"
126
+ LABELVALUE INST HEALTH_STATUS TEMP1
127
+ LABELVALUE INST HEALTH_STATUS TEMP2
128
+ END
129
+ TABITEM "Ground"
130
+ LABELVALUE INST HEALTH_STATUS GROUND1STATUS
131
+ END
132
+ END
133
+ settings:
134
+ LIMITS_STATE:
135
+ summary: Outline each tab in the worst limits color of the items on it
136
+ description:
137
+ When set to TRUE, each tab is outlined in the worst limits color of the items on
138
+ that tab (RED, then YELLOW, then GREEN, with BLUE counted as GREEN) and shows the
139
+ matching Astro status icon before its name, so you can see a problem on a tab that
140
+ isn't showing. Tabs without items in a limits state have
141
+ no outline. Items in TABBOOKs nested inside a tab count toward that tab.
142
+ To do this every tab, including the tabs of nested TABBOOKs, is built when the
143
+ screen opens instead of when it is first shown, so all of their items are polled
144
+ and their graphs and other widgets run from the start. Put this SETTING directly
145
+ after TABBOOK, before the first TABITEM.
146
+ since: 7.6.0
147
+ parameters:
148
+ - name: Enabled
149
+ required: true
150
+ description: Whether to outline the tabs
151
+ values: ["TRUE", "FALSE"]
122
152
  TABITEM:
123
153
  summary: Creates a VERTICAL layout tab into which to place widgets
124
154
  parameters:
@@ -139,9 +139,9 @@ module OpenC3
139
139
  when :UINT, :INT
140
140
  if item.array_size
141
141
  value = JSON.parse(value) if value.is_a? String
142
- value = value.map { |v| Integer(v) }
142
+ value = value.map { |v| convert_to_int(v) }
143
143
  else
144
- value = Integer(value)
144
+ value = convert_to_int(value)
145
145
  end
146
146
  when :FLOAT
147
147
  if item.array_size
@@ -155,5 +155,17 @@ module OpenC3
155
155
  end
156
156
  return value
157
157
  end
158
+
159
+ # Leading zeros on a decimal string, which Integer() would read as octal
160
+ LEADING_ZEROS = /\A(\s*[+-]?)(?:0_?)+(?=\d[\d_]*\s*\z)/
161
+
162
+ # Integer() with leading zeros treated as decimal, so "010" is 10 rather
163
+ # than octal 8. Prefixed strings like "0x10" are left to Integer().
164
+ # Python's accessor.py _convert_to_int matches this, keep the two in sync.
165
+ def self.convert_to_int(value)
166
+ value = value.sub(LEADING_ZEROS, '\1') if value.is_a?(String)
167
+ return Integer(value)
168
+ end
169
+ private_class_method :convert_to_int
158
170
  end
159
171
  end
@@ -179,7 +179,15 @@ module OpenC3
179
179
  structure = parent_item.structure
180
180
  structure.read(item.key, :RAW, structure_buffer)
181
181
  else
182
- handle_read_variable_bit_size(item, buffer) if item.variable_bit_size
182
+ if item.variable_bit_size
183
+ handle_read_variable_bit_size(item, buffer)
184
+ # A size of 0 normally means fill the rest of the buffer but here it means empty
185
+ if item.array_size
186
+ return [] if item.array_size == 0
187
+ elsif item.bit_size == 0
188
+ return ''.b
189
+ end
190
+ end
183
191
  if @packet.short_buffer_allowed && (native_value_out_of_range?(item) || derived_size_negative?(item, buffer))
184
192
  return nil
185
193
  end
@@ -274,26 +282,38 @@ module OpenC3
274
282
  end
275
283
  # Probably not possible to get this condition because we don't allow 0 sized floats
276
284
  # but check for it just to cover all the possible data_types
277
- elsif item.data_type == :FLOAT
285
+ # (variable sized FLOAT arrays are handled below)
286
+ elsif item.data_type == :FLOAT and not item.original_array_size
278
287
  raise "Variable bit size not currently supported for FLOAT data type"
279
288
  else
280
289
  # STRING, BLOCK, or array types
290
+ length_bits_per_count = item.variable_bit_size['length_bits_per_count']
291
+ length_value_bit_offset = item.variable_bit_size['length_value_bit_offset']
281
292
 
282
293
  # Calculate current bit size so we can preserve bytes after the item
283
294
  length_item_value = @packet.read(item.variable_bit_size['length_item_name'], :CONVERTED)
284
- current_bit_size = (length_item_value * item.variable_bit_size['length_bits_per_count']) + item.variable_bit_size['length_value_bit_offset']
295
+ current_bit_size = (length_item_value * length_bits_per_count) + length_value_bit_offset
285
296
 
286
297
  # Calculate bits after this item
287
298
  bits_with_item = item.bit_offset + current_bit_size
288
299
  bits_after_item = (buffer.length * 8) - bits_with_item
300
+
301
+ # Arrays are sized in elements, STRING and BLOCK in bytes
302
+ value_unit_bit_size = item.original_array_size ? item.bit_size : 8
303
+ new_bit_size = value.length * value_unit_bit_size
304
+ # Reject sizes the length item can't represent exactly or the reader would decode the wrong size
305
+ length_bits = new_bit_size - length_value_bit_offset
306
+ if length_bits % length_bits_per_count != 0
307
+ raise ArgumentError, "Variable bit size #{new_bit_size} for item #{item.name} is not representable with length_bits_per_count #{length_bits_per_count} and length_value_bit_offset #{length_value_bit_offset}"
308
+ end
309
+
289
310
  if item.original_array_size
290
311
  item.array_size = -bits_after_item
291
312
  else
292
313
  item.bit_size = -bits_after_item
293
314
  end
294
315
 
295
- new_bit_size = value.length * 8
296
- length_value = (new_bit_size - item.variable_bit_size['length_value_bit_offset']) / item.variable_bit_size['length_bits_per_count']
316
+ length_value = length_bits / length_bits_per_count
297
317
  @packet.write(item.variable_bit_size['length_item_name'], length_value)
298
318
 
299
319
  # Later items need their bit_offset adjusted by the change in this item
@@ -0,0 +1 @@
1
+ When any files in this directory are modified, update the appropriate documentation in docs.openc3.com/docs/guides/scripting-api.md and the docs.openc3.com/docs/guides/script-writing.md
@@ -26,6 +26,7 @@ require 'openc3/api/metrics_api'
26
26
  require 'openc3/api/offline_access_api'
27
27
  require 'openc3/api/router_api'
28
28
  require 'openc3/api/settings_api'
29
+ require 'openc3/api/shared_resource_api'
29
30
  require 'openc3/api/stash_api'
30
31
  require 'openc3/api/target_api'
31
32
  require 'openc3/api/tlm_api'
@@ -20,6 +20,7 @@
20
20
 
21
21
  require 'openc3/api/interface_api'
22
22
  require 'openc3/models/queue_model'
23
+ require 'openc3/models/shared_resource_model'
23
24
  require 'openc3/models/target_model'
24
25
  require 'openc3/topics/command_topic'
25
26
  require 'openc3/topics/command_decom_topic'
@@ -170,6 +171,7 @@ module OpenC3
170
171
  interface['cmd_target_names'].each do |target_name|
171
172
  authorize(permission: 'cmd_raw', interface_name: interface_name, target_name: target_name, manual: manual, scope: scope, token: token)
172
173
  end
174
+ SharedResourceModel.check_interface_active('INTERFACE', interface_name, scope: scope)
173
175
  InterfaceTopic.write_raw(interface_name, data, scope: scope)
174
176
  end
175
177
 
@@ -447,7 +449,7 @@ module OpenC3
447
449
 
448
450
  # NOTE: When adding new keywords to this method, make sure to update script/commands.rb
449
451
  def _cmd_implementation(method_name, *args, range_check:, hazardous_check:, raw:, timeout: nil, log_message: nil, manual: false, validate: true, queue: nil,
450
- queue_username: nil, scope: $openc3_scope, token: $openc3_token, **kwargs)
452
+ queue_username: nil, extra: nil, scope: $openc3_scope, token: $openc3_token, **kwargs)
451
453
  extract_string_kwargs_to_args(args, kwargs)
452
454
  unless [nil, true, false].include?(log_message)
453
455
  raise "Invalid log_message parameter: #{log_message}. Must be true or false."
@@ -459,6 +461,9 @@ module OpenC3
459
461
  raise "Invalid timeout parameter: #{timeout}. Must be numeric."
460
462
  end
461
463
  end
464
+ unless extra.nil? || extra.is_a?(Hash)
465
+ raise "Invalid extra parameter: #{extra}. Must be a Hash."
466
+ end
462
467
 
463
468
  case args.length
464
469
  when 1
@@ -479,6 +484,7 @@ module OpenC3
479
484
  cmd_name = cmd_name.upcase
480
485
  cmd_params = cmd_params.transform_keys(&:upcase)
481
486
  user = authorize(permission: 'cmd', target_name: target_name, packet_name: cmd_name, manual: manual, scope: scope, token: token)
487
+ SharedResourceModel.check_target_active(target_name, scope: scope)
482
488
  if user.nil?
483
489
  user = {}
484
490
  user['username'] = ENV.fetch('OPENC3_MICROSERVICE_NAME', nil)
@@ -532,6 +538,7 @@ module OpenC3
532
538
  'log_message' => log_message.to_s,
533
539
  'obfuscated_items' => packet['obfuscated_items'].to_s
534
540
  }
541
+ command['extra'] = extra unless extra.nil?
535
542
  # Record the original queuing user (author) separately from 'username' (the
536
543
  # user or process that actually executed the command). Command History shows
537
544
  # 'username' as "Executed By" and queue_username as "Queued By".
@@ -547,6 +554,7 @@ module OpenC3
547
554
  target_name: target_name,
548
555
  cmd_name: cmd_name,
549
556
  cmd_params: cmd_params,
557
+ extra: extra,
550
558
  validate: validate,
551
559
  timeout: timeout,
552
560
  username: username,
@@ -17,6 +17,7 @@
17
17
 
18
18
  require 'openc3/models/interface_model'
19
19
  require 'openc3/models/interface_status_model'
20
+ require 'openc3/models/shared_resource_model'
20
21
  require 'openc3/topics/interface_topic'
21
22
 
22
23
  module OpenC3
@@ -64,6 +65,7 @@ module OpenC3
64
65
  def connect_interface(interface_name, *interface_params, manual: false, scope: $openc3_scope, token: $openc3_token)
65
66
  # TODO: Check if they have command authority for the targets mapped to this interface
66
67
  authorize(permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token)
68
+ SharedResourceModel.check_interface_active('INTERFACE', interface_name, scope: scope)
67
69
  InterfaceTopic.connect_interface(interface_name, *interface_params, scope: scope)
68
70
  end
69
71
 
@@ -83,7 +85,7 @@ module OpenC3
83
85
  # TODO: Check if they have command authority for the targets mapped to this interface
84
86
  authorize(permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token)
85
87
  if interface_name == 'ALL'
86
- get_interface_names().each do |interface_name|
88
+ get_interface_names(manual: manual, scope: scope, token: token).each do |interface_name|
87
89
  InterfaceTopic.start_raw_logging(interface_name, scope: scope)
88
90
  end
89
91
  else
@@ -98,7 +100,7 @@ module OpenC3
98
100
  # TODO: Check if they have command authority for the targets mapped to this interface
99
101
  authorize(permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token)
100
102
  if interface_name == 'ALL'
101
- get_interface_names().each do |interface_name|
103
+ get_interface_names(manual: manual, scope: scope, token: token).each do |interface_name|
102
104
  InterfaceTopic.stop_raw_logging(interface_name, scope: scope)
103
105
  end
104
106
  else
@@ -176,12 +178,14 @@ module OpenC3
176
178
  def interface_cmd(interface_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token)
177
179
  # TODO: Check if they have command authority for the targets mapped to this interface
178
180
  authorize(permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token)
181
+ SharedResourceModel.check_interface_active('INTERFACE', interface_name, scope: scope)
179
182
  InterfaceTopic.interface_cmd(interface_name, cmd_name, *cmd_params, scope: scope)
180
183
  end
181
184
 
182
185
  def interface_protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1, manual: false, scope: $openc3_scope, token: $openc3_token)
183
186
  # TODO: Check if they have command authority for the targets mapped to this interface
184
187
  authorize(permission: 'system_set', interface_name: interface_name, manual: manual, scope: scope, token: token)
188
+ SharedResourceModel.check_interface_active('INTERFACE', interface_name, scope: scope)
185
189
  InterfaceTopic.protocol_cmd(interface_name, cmd_name, *cmd_params, read_write: read_write, index: index, scope: scope)
186
190
  end
187
191
 
@@ -221,6 +225,7 @@ module OpenC3
221
225
 
222
226
  def interface_details(interface_name, manual: false, scope: $openc3_scope, token: $openc3_token)
223
227
  authorize(permission: 'system', interface_name: interface_name, manual: manual, scope: scope, token: token)
228
+ SharedResourceModel.check_interface_active('INTERFACE', interface_name, scope: scope)
224
229
  InterfaceTopic.interface_details(interface_name, scope: scope)
225
230
  end
226
231
  end
@@ -18,6 +18,7 @@
18
18
  require 'openc3/api/target_api'
19
19
  require 'openc3/models/cvt_model'
20
20
  require 'openc3/packets/packet_item'
21
+ require 'openc3/utilities/limits_rollup'
21
22
 
22
23
  module OpenC3
23
24
  module Api
@@ -61,11 +62,10 @@ module OpenC3
61
62
  def get_overall_limits_state(ignored_items = nil, manual: false, scope: $openc3_scope, token: $openc3_token)
62
63
  # We only need to check out of limits items so call get_out_of_limits() which authorizes
63
64
  out_of_limits = get_out_of_limits(scope: scope, token: token)
64
- overall = 'GREEN'
65
65
 
66
- # Build easily matchable ignore list
66
+ # Build easily matchable ignore list without modifying the caller's list
67
67
  if ignored_items
68
- ignored_items.map! do |item|
68
+ ignored_items = ignored_items.map do |item|
69
69
  raise "Invalid ignored item: #{item}. Must be [TGT, PKT, ITEM] where ITEM can be nil." if item.length != 3
70
70
 
71
71
  item.join('__')
@@ -74,27 +74,19 @@ module OpenC3
74
74
  ignored_items = []
75
75
  end
76
76
 
77
+ states = []
77
78
  out_of_limits.each do |target_name, packet_name, item_name, limits_state|
78
- # Ignore this item if we match one of the ignored items. Checking against /^#{item}/
79
- # allows us to detect matches against a TGT__PKT__ with no item defined.
80
- next if ignored_items.detect { |item| "#{target_name}__#{packet_name}__#{item_name}" =~ /^#{item}/ }
79
+ # Ignore this item if we match one of the ignored items. A key ending in __
80
+ # has no item so it matches every item in the packet, otherwise the item must
81
+ # match exactly so ignoring TEMP1 does not also ignore TEMP10.
82
+ full_name = "#{target_name}__#{packet_name}__#{item_name}"
83
+ next if ignored_items.detect { |item| item.end_with?('__') ? full_name.start_with?(item) : full_name == item }
81
84
 
82
- if limits_state == 'RED' || limits_state == 'RED_HIGH' || limits_state == 'RED_LOW'
83
- overall = limits_state
84
- break # Red is as high as we go so no need to look for more
85
- end
86
-
87
- case overall
88
- # If our overall state is currently blue or green we can go to any state
89
- when 'BLUE', 'GREEN', 'GREEN_HIGH', 'GREEN_LOW'
90
- overall = limits_state
91
- # else YELLOW - Stay at YELLOW until we find a red
92
- end
85
+ states << limits_state
93
86
  end
94
- overall = 'GREEN' if overall == 'GREEN_HIGH' || overall == 'GREEN_LOW' || overall == 'BLUE'
95
- overall = 'YELLOW' if overall == 'YELLOW_HIGH' || overall == 'YELLOW_LOW'
96
- overall = 'RED' if overall == 'RED_HIGH' || overall == 'RED_LOW'
97
- return overall
87
+ overall = LimitsRollup.worst(states)
88
+ # The overall state has never been BLUE
89
+ return (overall.nil? or overall == 'BLUE') ? 'GREEN' : overall
98
90
  end
99
91
 
100
92
  # Whether the limits are enabled for the given item
@@ -175,7 +167,8 @@ module OpenC3
175
167
  limits = {}
176
168
  item = TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
177
169
  item['limits'].each do |key, vals|
178
- next unless vals.is_a?(Hash)
170
+ # Skip non-numeric limits such as SEQUENCE, CHANGE, or STATIC change limits
171
+ next unless vals.is_a?(Hash) && vals.key?('red_low')
179
172
 
180
173
  limits[key] = [vals['red_low'], vals['yellow_low'], vals['yellow_high'], vals['red_high']]
181
174
  limits[key].concat([vals['green_low'], vals['green_high']]) if vals['green_low']
@@ -209,6 +202,12 @@ module OpenC3
209
202
  item = packet['items'].find { |packet_item| packet_item['name'] == item_name }
210
203
  raise "Item '#{target_name} #{name} #{item_name}' does not exist while setting limits" unless item
211
204
  raise "Cannot set_limits on item without any limits" unless item['limits']
205
+
206
+ default = item['limits']['DEFAULT']
207
+ if default.is_a?(Hash) && default['change_type']
208
+ raise "Cannot set_limits on item '#{target_name} #{name} #{item_name}' with #{default['change_type']} limits"
209
+ end
210
+
212
211
  [name, packet, item]
213
212
  end
214
213
  items.each do |name, packet, item|
@@ -305,26 +304,58 @@ module OpenC3
305
304
  end
306
305
  end
307
306
 
308
- # Returns all limits_groups and their members
307
+ # Returns limits groups and their members. A nested group is the member
308
+ # <TARGET> LIMITS_GROUP <GROUP>.
309
+ #
310
+ # With no target name the groups of every target are keyed by group name. A
311
+ # group name defined by more than one target is keyed TARGET__GROUP instead
312
+ # since the name alone doesn't identify the group.
313
+ #
309
314
  # @since 5.0.0 Returns hash with values
315
+ # @param target_name [String, nil] Only return the groups defined by this target
310
316
  # @return [Hash{String => Array<Array<String, String, String>>]
311
- def get_limits_groups(manual: false, scope: $openc3_scope, token: $openc3_token)
312
- authorize(permission: 'tlm', manual: manual, scope: scope, token: token)
313
- TargetModel.limits_groups(scope: scope)
317
+ def get_limits_groups(target_name = nil, manual: false, scope: $openc3_scope, token: $openc3_token)
318
+ target_name = target_name.to_s.upcase if target_name
319
+ authorize(permission: 'tlm', target_name: target_name, manual: manual, scope: scope, token: token)
320
+ groups = TargetModel.limits_groups(scope: scope).map do |key, items|
321
+ group_target_name, group_name = LimitsEventTopic.split_limits_group_key(key)
322
+ [key, group_target_name, group_name, items]
323
+ end
324
+ if target_name
325
+ groups.select { |_key, group_target_name, _group_name, _items| group_target_name == target_name }
326
+ .to_h { |_key, _group_target_name, group_name, items| [group_name, items] }
327
+ else
328
+ counts = groups.map { |group| group[2] }.tally
329
+ groups.to_h { |key, _group_target_name, group_name, items| [counts[group_name] > 1 ? key : group_name, items] }
330
+ end
314
331
  end
315
332
 
316
333
  # Enables limits for all the items in the group
317
334
  #
318
- # @param group_name [String] Name of the group to enable
319
- def enable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token)
320
- _limits_group(group_name, action: :enable, manual: manual, scope: scope, token: token)
335
+ # Usage:
336
+ # enable_limits_group(group_name)
337
+ # enable_limits_group(target_name, group_name)
338
+ #
339
+ # A group name alone must only be defined by one target
340
+ #
341
+ # @param cascade [Boolean] Whether to also enable the nested groups and their items.
342
+ # When false only the group itself and the items directly in it are enabled.
343
+ def enable_limits_group(*args, cascade: true, manual: false, scope: $openc3_scope, token: $openc3_token)
344
+ _limits_group(args, 'enable_limits_group', action: :enable, cascade: cascade, manual: manual, scope: scope, token: token)
321
345
  end
322
346
 
323
347
  # Disables limits for all the items in the group
324
348
  #
325
- # @param group_name [String] Name of the group to disable
326
- def disable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token)
327
- _limits_group(group_name, action: :disable, manual: manual, scope: scope, token: token)
349
+ # Usage:
350
+ # disable_limits_group(group_name)
351
+ # disable_limits_group(target_name, group_name)
352
+ #
353
+ # A group name alone must only be defined by one target
354
+ #
355
+ # @param cascade [Boolean] Whether to also disable the nested groups and their items.
356
+ # When false only the group itself and the items directly in it are disabled.
357
+ def disable_limits_group(*args, cascade: true, manual: false, scope: $openc3_scope, token: $openc3_token)
358
+ _limits_group(args, 'disable_limits_group', action: :disable, cascade: cascade, manual: manual, scope: scope, token: token)
328
359
  end
329
360
 
330
361
  # Returns all defined limits sets
@@ -397,25 +428,42 @@ module OpenC3
397
428
  ###########################################################################
398
429
 
399
430
  # Enables or disables a limits group
400
- def _limits_group(group_name, action:, manual:, scope:, token:)
401
- authorize(permission: 'tlm_set', manual: manual, scope: scope, token: token)
402
- group_name.upcase!
431
+ def _limits_group(args, method_name, action:, cascade:, manual:, scope:, token:)
432
+ case args.length
433
+ when 1
434
+ target_name = nil
435
+ group_name = args[0]
436
+ when 2
437
+ target_name, group_name = args
438
+ else
439
+ # Invalid number of arguments
440
+ raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{method_name}()"
441
+ end
442
+ authorize(permission: 'tlm_set', target_name: target_name&.to_s&.upcase, manual: manual, scope: scope, token: token)
443
+ key = LimitsEventTopic.find_limits_group(target_name, group_name, scope: scope)
444
+ target_name, group_name = LimitsEventTopic.split_limits_group_key(key)
403
445
  # Items grouped by target and packet so each packet is read and written once
404
- items = LimitsEventTopic.limits_group_items(group_name, scope: scope)
405
- raise "LIMITS_GROUP #{group_name} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_name}" unless items
446
+ cascade = cascade ? true : false
447
+ items = LimitsEventTopic.limits_group_items(key, cascade: cascade, scope: scope)
448
+ # Members can be items of other targets, directly or through nested groups,
449
+ # so check every target before changing any of them
450
+ items.each_key do |item_target_name|
451
+ authorize(permission: 'tlm_set', target_name: item_target_name, manual: manual, scope: scope, token: token)
452
+ end
406
453
 
407
454
  enabled = (action == :enable)
408
- message = "#{enabled ? 'Enabling' : 'Disabling'} Limits Group: #{group_name}"
455
+ message = "#{enabled ? 'Enabling' : 'Disabling'} Limits Group: #{[target_name, group_name].compact.join(' ')}"
456
+ message += " (not nested groups)" unless cascade
409
457
  Logger.info(message, scope: scope)
410
458
 
411
- items.each do |target_name, packets|
459
+ items.each do |item_target_name, packets|
412
460
  packets.each do |packet_name, item_names|
413
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
461
+ packet = TargetModel.packet(item_target_name, packet_name, scope: scope)
414
462
  item_names_hash = item_names.to_h { |name| [name, true] }
415
463
  packet['items'].each do |item|
416
464
  item['limits']['enabled'] = enabled if item_names_hash[item['name']]
417
465
  end
418
- TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
466
+ TargetModel.set_packet(item_target_name, packet_name, packet, scope: scope)
419
467
  end
420
468
  end
421
469
 
@@ -426,6 +474,10 @@ module OpenC3
426
474
  # small no matter how many items the group contains.
427
475
  event = { type: :LIMITS_GROUP_ENABLE_STATE, group_name: group_name,
428
476
  enabled: enabled, time_nsec: Time.now.to_nsec_from_epoch, message: message }
477
+ # Groups stored before they were owned by a target have no target name
478
+ event[:target_name] = target_name if target_name
479
+ # Readers expand nested groups unless the event says not to
480
+ event[:cascade] = false unless cascade
429
481
  LimitsEventTopic.write(event, scope: scope)
430
482
  end
431
483
 
@@ -17,6 +17,7 @@
17
17
 
18
18
  require 'openc3/models/router_model'
19
19
  require 'openc3/models/router_status_model'
20
+ require 'openc3/models/shared_resource_model'
20
21
  require 'openc3/topics/router_topic'
21
22
 
22
23
  module OpenC3
@@ -63,6 +64,7 @@ module OpenC3
63
64
  def connect_router(router_name, *router_params, manual: false, scope: $openc3_scope, token: $openc3_token)
64
65
  # TODO: Check if they have command authority for the targets mapped to this router
65
66
  authorize(permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token)
67
+ SharedResourceModel.check_interface_active('ROUTER', router_name, scope: scope)
66
68
  RouterTopic.connect_router(router_name, *router_params, scope: scope)
67
69
  end
68
70
 
@@ -82,7 +84,7 @@ module OpenC3
82
84
  # TODO: Check if they have command authority for the targets mapped to this router
83
85
  authorize(permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token)
84
86
  if router_name == 'ALL'
85
- get_router_names().each do |router_name|
87
+ get_router_names(manual: manual, scope: scope, token: token).each do |router_name|
86
88
  RouterTopic.start_raw_logging(router_name, scope: scope)
87
89
  end
88
90
  else
@@ -97,7 +99,7 @@ module OpenC3
97
99
  # TODO: Check if they have command authority for the targets mapped to this router
98
100
  authorize(permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token)
99
101
  if router_name == 'ALL'
100
- get_router_names().each do |router_name|
102
+ get_router_names(manual: manual, scope: scope, token: token).each do |router_name|
101
103
  RouterTopic.stop_raw_logging(router_name, scope: scope)
102
104
  end
103
105
  else
@@ -125,12 +127,14 @@ module OpenC3
125
127
  def router_cmd(router_name, cmd_name, *cmd_params, manual: false, scope: $openc3_scope, token: $openc3_token)
126
128
  # TODO: Check if they have command authority for the targets mapped to this router
127
129
  authorize(permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token)
130
+ SharedResourceModel.check_interface_active('ROUTER', router_name, scope: scope)
128
131
  RouterTopic.router_cmd(router_name, cmd_name, *cmd_params, scope: scope)
129
132
  end
130
133
 
131
134
  def router_protocol_cmd(router_name, cmd_name, *cmd_params, read_write: :READ_WRITE, index: -1, manual: false, scope: $openc3_scope, token: $openc3_token)
132
135
  # TODO: Check if they have command authority for the targets mapped to this router
133
136
  authorize(permission: 'system_set', router_name: router_name, manual: manual, scope: scope, token: token)
137
+ SharedResourceModel.check_interface_active('ROUTER', router_name, scope: scope)
134
138
  RouterTopic.protocol_cmd(router_name, cmd_name, *cmd_params, read_write: read_write, index: index, scope: scope)
135
139
  end
136
140
 
@@ -216,6 +220,7 @@ module OpenC3
216
220
 
217
221
  def router_details(router_name, manual: false, scope: $openc3_scope, token: $openc3_token)
218
222
  authorize(permission: 'system', router_name: router_name, manual: manual, scope: scope, token: token)
223
+ SharedResourceModel.check_interface_active('ROUTER', router_name, scope: scope)
219
224
  RouterTopic.router_details(router_name, scope: scope)
220
225
  end
221
226
  end
@@ -77,7 +77,10 @@ module OpenC3
77
77
  Logger.info("User #{username} saved setting '#{name}': #{data}", scope: scope, user: username)
78
78
  end
79
79
  # save_setting is DEPRECATED
80
- alias save_setting set_setting
80
+ def save_setting(name, data, manual: false, scope: $openc3_scope, token: $openc3_token)
81
+ OpenC3.deprecation_warning("`save_setting` is deprecated. Please use `set_setting` instead.", uplevel: 1)
82
+ set_setting(name, data, manual: manual, scope: scope, token: token)
83
+ end
81
84
 
82
85
  # Update the news feed on demand to respond to frontend setting changes
83
86
  def update_news(manual: false, scope: $openc3_scope, token: $openc3_token)