openc3 7.5.0 → 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 (175) 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 +236 -195
  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 +229 -61
  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/log_writer.rb +9 -8
  33. data/lib/openc3/logs/packet_log_writer.rb +8 -3
  34. data/lib/openc3/microservices/decom_common.rb +4 -1
  35. data/lib/openc3/microservices/decom_microservice.rb +73 -5
  36. data/lib/openc3/microservices/interface_decom_common.rb +16 -1
  37. data/lib/openc3/microservices/interface_microservice.rb +50 -11
  38. data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
  39. data/lib/openc3/microservices/log_microservice.rb +22 -8
  40. data/lib/openc3/microservices/microservice.rb +8 -2
  41. data/lib/openc3/microservices/multi_microservice.rb +76 -22
  42. data/lib/openc3/microservices/queue_microservice.rb +29 -24
  43. data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
  44. data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
  45. data/lib/openc3/models/bridge_model.rb +3 -3
  46. data/lib/openc3/models/cvt_model.rb +10 -3
  47. data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
  48. data/lib/openc3/models/interface_model.rb +27 -7
  49. data/lib/openc3/models/microservice_group.rb +167 -0
  50. data/lib/openc3/models/microservice_model.rb +88 -2
  51. data/lib/openc3/models/panel_model.rb +109 -0
  52. data/lib/openc3/models/plugin_model.rb +1006 -26
  53. data/lib/openc3/models/plugin_store_model.rb +6 -1
  54. data/lib/openc3/models/protected_storage_model.rb +64 -0
  55. data/lib/openc3/models/queue_model.rb +19 -10
  56. data/lib/openc3/models/scope_model.rb +80 -3
  57. data/lib/openc3/models/setting_model.rb +2 -2
  58. data/lib/openc3/models/shared_resource_model.rb +381 -0
  59. data/lib/openc3/models/target_model.rb +333 -74
  60. data/lib/openc3/operators/microservice_operator.rb +76 -9
  61. data/lib/openc3/operators/operator.rb +29 -0
  62. data/lib/openc3/packets/commands.rb +16 -16
  63. data/lib/openc3/packets/limits.rb +2 -0
  64. data/lib/openc3/packets/packet.rb +75 -4
  65. data/lib/openc3/packets/packet_config.rb +152 -13
  66. data/lib/openc3/packets/packet_item.rb +48 -22
  67. data/lib/openc3/packets/packet_item_limits.rb +67 -6
  68. data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
  69. data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
  70. data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
  71. data/lib/openc3/packets/parsers/state_parser.rb +1 -1
  72. data/lib/openc3/script/CLAUDE.md +1 -0
  73. data/lib/openc3/script/api_shared.rb +27 -17
  74. data/lib/openc3/script/calendar.rb +18 -6
  75. data/lib/openc3/script/commands.rb +11 -9
  76. data/lib/openc3/script/critical_cmd.rb +22 -2
  77. data/lib/openc3/script/extract.rb +52 -5
  78. data/lib/openc3/script/metadata.rb +30 -4
  79. data/lib/openc3/script/plugins.rb +8 -0
  80. data/lib/openc3/script/script.rb +9 -25
  81. data/lib/openc3/script/web_socket_api.rb +23 -17
  82. data/lib/openc3/system/system.rb +9 -3
  83. data/lib/openc3/top_level.rb +17 -0
  84. data/lib/openc3/topics/command_topic.rb +7 -1
  85. data/lib/openc3/topics/decom_interface_topic.rb +9 -3
  86. data/lib/openc3/topics/discovery_topic.rb +84 -0
  87. data/lib/openc3/topics/limits_event_topic.rb +317 -11
  88. data/lib/openc3/topics/router_topic.rb +6 -2
  89. data/lib/openc3/topics/system_events_topic.rb +9 -6
  90. data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
  91. data/lib/openc3/topics/topic.rb +9 -1
  92. data/lib/openc3/utilities/authentication.rb +67 -16
  93. data/lib/openc3/utilities/bucket.rb +5 -0
  94. data/lib/openc3/utilities/cli_generator.rb +117 -25
  95. data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
  96. data/lib/openc3/utilities/config_overlay.rb +24 -1
  97. data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
  98. data/lib/openc3/utilities/hardware_discovery.rb +279 -0
  99. data/lib/openc3/utilities/limits_rollup.rb +81 -0
  100. data/lib/openc3/utilities/local_mode.rb +48 -5
  101. data/lib/openc3/utilities/questdb_client.rb +256 -54
  102. data/lib/openc3/utilities/reingest_job.rb +12 -3
  103. data/lib/openc3/utilities/running_script.rb +206 -49
  104. data/lib/openc3/utilities/script.rb +24 -12
  105. data/lib/openc3/utilities/script_env.rb +164 -0
  106. data/lib/openc3/utilities/script_message_signing.rb +133 -0
  107. data/lib/openc3/utilities/secrets.rb +5 -0
  108. data/lib/openc3/utilities/store_autoload.rb +35 -2
  109. data/lib/openc3/utilities/store_queued.rb +5 -1
  110. data/lib/openc3/version.rb +5 -5
  111. data/templates/command_validator/command_validator.py +9 -9
  112. data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
  113. data/templates/panel/Rakefile +24 -0
  114. data/templates/panel/package.json +17 -0
  115. data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
  116. data/templates/panel/src/Panel.js +52 -0
  117. data/templates/panel/src/Panel.vue +60 -0
  118. data/templates/panel/src/panelSdk.js +24 -0
  119. data/templates/panel/vite-Panel.config.js +43 -0
  120. data/templates/tool_vue/package.json +3 -3
  121. data/templates/widget/package.json +2 -2
  122. metadata +24 -56
  123. data/templates/tool_angular/.editorconfig +0 -16
  124. data/templates/tool_angular/.gitignore +0 -44
  125. data/templates/tool_angular/.vscode/extensions.json +0 -4
  126. data/templates/tool_angular/.vscode/launch.json +0 -20
  127. data/templates/tool_angular/.vscode/tasks.json +0 -42
  128. data/templates/tool_angular/angular.json +0 -111
  129. data/templates/tool_angular/extra-webpack.config.js +0 -8
  130. data/templates/tool_angular/package.json +0 -48
  131. data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
  132. data/templates/tool_angular/src/app/app.component.html +0 -22
  133. data/templates/tool_angular/src/app/app.component.scss +0 -18
  134. data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
  135. data/templates/tool_angular/src/app/app.component.ts +0 -52
  136. data/templates/tool_angular/src/app/app.module.ts +0 -30
  137. data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
  138. data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
  139. data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
  140. data/templates/tool_angular/src/assets/.gitkeep +0 -0
  141. data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
  142. data/templates/tool_angular/src/environments/environment.ts +0 -16
  143. data/templates/tool_angular/src/favicon.ico +0 -0
  144. data/templates/tool_angular/src/index.html +0 -13
  145. data/templates/tool_angular/src/main.single-spa.ts +0 -40
  146. data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
  147. data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
  148. data/templates/tool_angular/src/styles.scss +0 -1
  149. data/templates/tool_angular/tsconfig.app.json +0 -13
  150. data/templates/tool_angular/tsconfig.json +0 -33
  151. data/templates/tool_angular/tsconfig.spec.json +0 -14
  152. data/templates/tool_react/.eslintrc +0 -7
  153. data/templates/tool_react/.gitignore +0 -71
  154. data/templates/tool_react/.prettierignore +0 -8
  155. data/templates/tool_react/babel.config.json +0 -29
  156. data/templates/tool_react/jest.config.js +0 -12
  157. data/templates/tool_react/package.json +0 -51
  158. data/templates/tool_react/src/openc3-tool_name.js +0 -24
  159. data/templates/tool_react/src/root.component.js +0 -88
  160. data/templates/tool_react/src/root.component.test.js +0 -9
  161. data/templates/tool_react/webpack.config.js +0 -27
  162. data/templates/tool_svelte/.gitignore +0 -71
  163. data/templates/tool_svelte/.prettierignore +0 -8
  164. data/templates/tool_svelte/.prettierrc.js +0 -5
  165. data/templates/tool_svelte/babel.config.js +0 -12
  166. data/templates/tool_svelte/build/smui.css +0 -1
  167. data/templates/tool_svelte/jest.config.js +0 -9
  168. data/templates/tool_svelte/package.json +0 -49
  169. data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
  170. data/templates/tool_svelte/rollup.config.js +0 -74
  171. data/templates/tool_svelte/src/App.svelte +0 -42
  172. data/templates/tool_svelte/src/App.test.js +0 -9
  173. data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
  174. data/templates/tool_svelte/src/tool_name.js +0 -17
  175. data/templates/widget/LICENSE.md +0 -20
@@ -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
@@ -26,6 +27,7 @@ module OpenC3
26
27
  'get_out_of_limits',
27
28
  'get_overall_limits_state',
28
29
  'limits_enabled?',
30
+ 'limits_enabled', # Python scripts call this alias since Python method names can't end in ?
29
31
  'enable_limits',
30
32
  'disable_limits',
31
33
  'get_limits',
@@ -60,11 +62,10 @@ module OpenC3
60
62
  def get_overall_limits_state(ignored_items = nil, manual: false, scope: $openc3_scope, token: $openc3_token)
61
63
  # We only need to check out of limits items so call get_out_of_limits() which authorizes
62
64
  out_of_limits = get_out_of_limits(scope: scope, token: token)
63
- overall = 'GREEN'
64
65
 
65
- # Build easily matchable ignore list
66
+ # Build easily matchable ignore list without modifying the caller's list
66
67
  if ignored_items
67
- ignored_items.map! do |item|
68
+ ignored_items = ignored_items.map do |item|
68
69
  raise "Invalid ignored item: #{item}. Must be [TGT, PKT, ITEM] where ITEM can be nil." if item.length != 3
69
70
 
70
71
  item.join('__')
@@ -73,27 +74,19 @@ module OpenC3
73
74
  ignored_items = []
74
75
  end
75
76
 
77
+ states = []
76
78
  out_of_limits.each do |target_name, packet_name, item_name, limits_state|
77
- # Ignore this item if we match one of the ignored items. Checking against /^#{item}/
78
- # allows us to detect matches against a TGT__PKT__ with no item defined.
79
- 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 }
80
84
 
81
- if limits_state == 'RED' || limits_state == 'RED_HIGH' || limits_state == 'RED_LOW'
82
- overall = limits_state
83
- break # Red is as high as we go so no need to look for more
84
- end
85
-
86
- case overall
87
- # If our overall state is currently blue or green we can go to any state
88
- when 'BLUE', 'GREEN', 'GREEN_HIGH', 'GREEN_LOW'
89
- overall = limits_state
90
- # else YELLOW - Stay at YELLOW until we find a red
91
- end
85
+ states << limits_state
92
86
  end
93
- overall = 'GREEN' if overall == 'GREEN_HIGH' || overall == 'GREEN_LOW' || overall == 'BLUE'
94
- overall = 'YELLOW' if overall == 'YELLOW_HIGH' || overall == 'YELLOW_LOW'
95
- overall = 'RED' if overall == 'RED_HIGH' || overall == 'RED_LOW'
96
- return overall
87
+ overall = LimitsRollup.worst(states)
88
+ # The overall state has never been BLUE
89
+ return (overall.nil? or overall == 'BLUE') ? 'GREEN' : overall
97
90
  end
98
91
 
99
92
  # Whether the limits are enabled for the given item
@@ -121,29 +114,16 @@ module OpenC3
121
114
  #
122
115
  # Favor the first syntax where possible as it is more succinct.
123
116
  #
124
- # @param args [String|Array<String>] See the description for calling style
117
+ # @param args [String|Array<String>] See the description for calling style.
118
+ # A packet name of LATEST applies to every packet which contains the item.
125
119
  def enable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token)
126
- target_name, packet_name, item_name = _tlm_process_args(args, 'enable_limits', scope: scope)
127
- authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
128
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
129
- found_item = nil
130
- packet['items'].each do |item|
131
- if item['name'] == item_name
132
- item['limits']['enabled'] = true
133
- found_item = item
134
- break
135
- end
120
+ target_name, packet_names, item_name = _tlm_process_args_all_packets(args, 'enable_limits', scope: scope)
121
+ packet_names.each do |packet_name|
122
+ authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
123
+ end
124
+ packet_names.each do |packet_name|
125
+ _set_limits_enabled(target_name, packet_name, item_name, true, scope: scope)
136
126
  end
137
- raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist while enabling limits" unless found_item
138
-
139
- TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
140
-
141
- message = "Enabling Limits For '#{target_name} #{packet_name} #{item_name}'"
142
- Logger.info(message, scope: scope)
143
-
144
- event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name,
145
- item_name: item_name, enabled: true, time_nsec: Time.now.to_nsec_from_epoch, message: message }
146
- LimitsEventTopic.write(event, scope: scope)
147
127
  end
148
128
 
149
129
  # Disable limit checking for a telemetry item
@@ -154,29 +134,16 @@ module OpenC3
154
134
  #
155
135
  # Favor the first syntax where possible as it is more succinct.
156
136
  #
157
- # @param args [String|Array<String>] See the description for calling style
137
+ # @param args [String|Array<String>] See the description for calling style.
138
+ # A packet name of LATEST applies to every packet which contains the item.
158
139
  def disable_limits(*args, manual: false, scope: $openc3_scope, token: $openc3_token)
159
- target_name, packet_name, item_name = _tlm_process_args(args, 'disable_limits', scope: scope)
160
- authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
161
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
162
- found_item = nil
163
- packet['items'].each do |item|
164
- if item['name'] == item_name
165
- item['limits']['enabled'] = false
166
- found_item = item
167
- break
168
- end
140
+ target_name, packet_names, item_name = _tlm_process_args_all_packets(args, 'disable_limits', scope: scope)
141
+ packet_names.each do |packet_name|
142
+ authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
143
+ end
144
+ packet_names.each do |packet_name|
145
+ _set_limits_enabled(target_name, packet_name, item_name, false, scope: scope)
169
146
  end
170
- raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist while disabling limits" unless found_item
171
-
172
- TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
173
-
174
- message = "Disabling Limits for '#{target_name} #{packet_name} #{item_name}'"
175
- Logger.info(message, scope: scope)
176
-
177
- event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name,
178
- item_name: item_name, enabled: false, time_nsec: Time.now.to_nsec_from_epoch, message: message }
179
- LimitsEventTopic.write(event, scope: scope)
180
147
  end
181
148
 
182
149
  # Get a Hash of all the limits sets defined for an item. Hash keys are the limit
@@ -189,11 +156,19 @@ module OpenC3
189
156
  #
190
157
  # @return [Hash{String => Array<Number, Number, Number, Number, Number, Number>}]
191
158
  def get_limits(target_name, packet_name, item_name, cache_timeout: nil, manual: false, scope: $openc3_scope, token: $openc3_token)
159
+ target_name = target_name.upcase
160
+ packet_name = packet_name.upcase
161
+ item_name = item_name.upcase
162
+ # Resolve LATEST before authorizing so the real packet is authorized
163
+ if packet_name == 'LATEST'
164
+ packet_name = CvtModel.determine_latest_packet_for_item(target_name, item_name, cache_timeout: cache_timeout, scope: scope)
165
+ end
192
166
  authorize(permission: 'tlm', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
193
167
  limits = {}
194
- item = _get_item(target_name, packet_name, item_name, cache_timeout: cache_timeout, scope: scope)
168
+ item = TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
195
169
  item['limits'].each do |key, vals|
196
- 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')
197
172
 
198
173
  limits[key] = [vals['red_low'], vals['yellow_low'], vals['yellow_high'], vals['red_high']]
199
174
  limits[key].concat([vals['green_low'], vals['green_high']]) if vals['green_low']
@@ -202,56 +177,64 @@ module OpenC3
202
177
  end
203
178
 
204
179
  # Change the limits settings for a given item. By default, a new limits set called 'CUSTOM'
205
- # is created to avoid overriding existing limits.
180
+ # is created to avoid overriding existing limits. A packet name of LATEST
181
+ # applies to every packet which contains the item.
206
182
  def set_limits(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high,
207
183
  green_low = nil, green_high = nil, limits_set = 'CUSTOM', persistence = nil, enabled = true,
208
184
  manual: false, scope: $openc3_scope, token: $openc3_token)
209
- authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
185
+ target_name = target_name.upcase
186
+ packet_name = packet_name.upcase
187
+ item_name = item_name.upcase
188
+ packet_names = (packet_name == 'LATEST') ? _tlm_packet_names(target_name, packet_name, item_name, scope: scope) : [packet_name]
189
+ packet_names.each do |name|
190
+ authorize(permission: 'tlm_set', target_name: target_name, packet_name: name, manual: manual, scope: scope, token: token)
191
+ end
210
192
  if (red_low > yellow_low) || (yellow_low >= yellow_high) || (yellow_high > red_high)
211
193
  raise "Invalid limits specified. Ensure yellow limits are within red limits."
212
194
  end
213
195
  if (green_low && green_high) && ((yellow_low > green_low) || (green_low >= green_high) || (green_high > yellow_high))
214
196
  raise "Invalid limits specified. Ensure green limits are within yellow limits."
215
197
  end
216
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
217
- found_item = nil
218
- packet['items'].each do |item|
219
- if item['name'] == item_name
220
- if item['limits']
221
- item['limits']['persistence_setting'] = persistence if persistence
222
- if enabled
223
- item['limits']['enabled'] = true
224
- else
225
- item['limits']['enabled'] = false
226
- end
227
- limits = {}
228
- limits['red_low'] = red_low
229
- limits['yellow_low'] = yellow_low
230
- limits['yellow_high'] = yellow_high
231
- limits['red_high'] = red_high
232
- limits['green_low'] = green_low if green_low && green_high
233
- limits['green_high'] = green_high if green_low && green_high
234
- item['limits'][limits_set] = limits
235
- found_item = item
236
- break
237
- else
238
- raise "Cannot set_limits on item without any limits"
239
- end
198
+ # Validate every packet before changing any so an error doesn't leave a partial update.
199
+ # TargetModel.packet returns a cached hash so it must not be modified until validated.
200
+ items = packet_names.map do |name|
201
+ packet = TargetModel.packet(target_name, name, scope: scope)
202
+ item = packet['items'].find { |packet_item| packet_item['name'] == item_name }
203
+ raise "Item '#{target_name} #{name} #{item_name}' does not exist while setting limits" unless item
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"
240
209
  end
241
- end
242
- raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist while setting limits" unless found_item
243
- message = "Setting '#{target_name} #{packet_name} #{item_name}' limits to #{red_low} #{yellow_low} #{yellow_high} #{red_high}"
244
- message << " #{green_low} #{green_high}" if green_low && green_high
245
- message << " in set #{limits_set} with persistence #{persistence} as enabled #{enabled}"
246
- Logger.info(message, scope: scope)
247
210
 
248
- TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
249
-
250
- event = { type: :LIMITS_SETTINGS, target_name: target_name, packet_name: packet_name,
251
- item_name: item_name, red_low: red_low, yellow_low: yellow_low, yellow_high: yellow_high, red_high: red_high,
252
- green_low: green_low, green_high: green_high, limits_set: limits_set, persistence: persistence, enabled: enabled,
253
- time_nsec: Time.now.to_nsec_from_epoch, message: message }
254
- LimitsEventTopic.write(event, scope: scope)
211
+ [name, packet, item]
212
+ end
213
+ items.each do |name, packet, item|
214
+ item['limits']['persistence_setting'] = persistence if persistence
215
+ item['limits']['enabled'] = enabled ? true : false
216
+ limits = {}
217
+ limits['red_low'] = red_low
218
+ limits['yellow_low'] = yellow_low
219
+ limits['yellow_high'] = yellow_high
220
+ limits['red_high'] = red_high
221
+ limits['green_low'] = green_low if green_low && green_high
222
+ limits['green_high'] = green_high if green_low && green_high
223
+ item['limits'][limits_set] = limits
224
+
225
+ message = "Setting '#{target_name} #{name} #{item_name}' limits to #{red_low} #{yellow_low} #{yellow_high} #{red_high}"
226
+ message << " #{green_low} #{green_high}" if green_low && green_high
227
+ message << " in set #{limits_set} with persistence #{persistence} as enabled #{enabled}"
228
+ Logger.info(message, scope: scope)
229
+
230
+ TargetModel.set_packet(target_name, name, packet, scope: scope)
231
+
232
+ event = { type: :LIMITS_SETTINGS, target_name: target_name, packet_name: name,
233
+ item_name: item_name, red_low: red_low, yellow_low: yellow_low, yellow_high: yellow_high, red_high: red_high,
234
+ green_low: green_low, green_high: green_high, limits_set: limits_set, persistence: persistence, enabled: enabled,
235
+ time_nsec: Time.now.to_nsec_from_epoch, message: message }
236
+ LimitsEventTopic.write(event, scope: scope)
237
+ end
255
238
  end
256
239
 
257
240
  # Change the color associated with a telemetry item state in realtime.
@@ -266,9 +249,16 @@ module OpenC3
266
249
  # or RED. Pass nil to clear (remove) the state color. Setting a color also
267
250
  # enables limits for the item, but clearing the color (nil) does not change
268
251
  # whether limits are enabled.
252
+ # A packet name of LATEST applies to every packet which contains the item.
269
253
  def set_state_color(target_name, packet_name, item_name, state_name, color,
270
254
  manual: false, scope: $openc3_scope, token: $openc3_token)
271
- authorize(permission: 'tlm_set', target_name: target_name, packet_name: packet_name, manual: manual, scope: scope, token: token)
255
+ target_name = target_name.upcase
256
+ packet_name = packet_name.upcase
257
+ item_name = item_name.upcase
258
+ packet_names = (packet_name == 'LATEST') ? _tlm_packet_names(target_name, packet_name, item_name, scope: scope) : [packet_name]
259
+ packet_names.each do |name|
260
+ authorize(permission: 'tlm_set', target_name: target_name, packet_name: name, manual: manual, scope: scope, token: token)
261
+ end
272
262
  state_name = state_name.to_s.upcase
273
263
  unless color.nil?
274
264
  color = color.to_s.upcase
@@ -276,62 +266,96 @@ module OpenC3
276
266
  raise "Invalid state color '#{color}'. Must be one of #{PacketItem::STATE_COLORS.join(', ')}."
277
267
  end
278
268
  end
279
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
280
- found_item = nil
281
- packet['items'].each do |item|
282
- if item['name'] == item_name
283
- unless item['states'] && item['states'][state_name]
284
- raise "State '#{state_name}' does not exist for item '#{target_name} #{packet_name} #{item_name}'"
285
- end
286
- if color.nil?
287
- # Clear the state color
288
- item['states'][state_name].delete('color')
289
- else
290
- item['states'][state_name]['color'] = color
291
- # Defining a state color implies limits are enabled for the item
292
- item['limits'] ||= {}
293
- item['limits']['enabled'] = true
294
- end
295
- found_item = item
296
- break
269
+ # Validate every packet before changing any so an error doesn't leave a partial update.
270
+ # TargetModel.packet returns a cached hash so it must not be modified until validated.
271
+ items = packet_names.map do |name|
272
+ packet = TargetModel.packet(target_name, name, scope: scope)
273
+ item = packet['items'].find { |packet_item| packet_item['name'] == item_name }
274
+ raise "Item '#{target_name} #{name} #{item_name}' does not exist while setting state color" unless item
275
+ unless item['states'] && item['states'][state_name]
276
+ raise "State '#{state_name}' does not exist for item '#{target_name} #{name} #{item_name}'"
297
277
  end
278
+ [name, packet, item]
298
279
  end
299
- raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist while setting state color" unless found_item
300
- if color.nil?
301
- message = "Clearing '#{target_name} #{packet_name} #{item_name}' state #{state_name} color"
302
- else
303
- message = "Setting '#{target_name} #{packet_name} #{item_name}' state #{state_name} color to #{color}"
304
- end
305
- Logger.info(message, scope: scope)
280
+ items.each do |name, packet, item|
281
+ if color.nil?
282
+ # Clear the state color
283
+ item['states'][state_name].delete('color')
284
+ else
285
+ item['states'][state_name]['color'] = color
286
+ # Defining a state color implies limits are enabled for the item
287
+ item['limits'] ||= {}
288
+ item['limits']['enabled'] = true
289
+ end
306
290
 
307
- TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
291
+ if color.nil?
292
+ message = "Clearing '#{target_name} #{name} #{item_name}' state #{state_name} color"
293
+ else
294
+ message = "Setting '#{target_name} #{name} #{item_name}' state #{state_name} color to #{color}"
295
+ end
296
+ Logger.info(message, scope: scope)
308
297
 
309
- event = { type: :LIMITS_STATE_COLOR, target_name: target_name, packet_name: packet_name,
310
- item_name: item_name, state_name: state_name, color: color,
311
- time_nsec: Time.now.to_nsec_from_epoch, message: message }
312
- LimitsEventTopic.write(event, scope: scope)
298
+ TargetModel.set_packet(target_name, name, packet, scope: scope)
299
+
300
+ event = { type: :LIMITS_STATE_COLOR, target_name: target_name, packet_name: name,
301
+ item_name: item_name, state_name: state_name, color: color,
302
+ time_nsec: Time.now.to_nsec_from_epoch, message: message }
303
+ LimitsEventTopic.write(event, scope: scope)
304
+ end
313
305
  end
314
306
 
315
- # 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
+ #
316
314
  # @since 5.0.0 Returns hash with values
315
+ # @param target_name [String, nil] Only return the groups defined by this target
317
316
  # @return [Hash{String => Array<Array<String, String, String>>]
318
- def get_limits_groups(manual: false, scope: $openc3_scope, token: $openc3_token)
319
- authorize(permission: 'tlm', manual: manual, scope: scope, token: token)
320
- 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
321
331
  end
322
332
 
323
333
  # Enables limits for all the items in the group
324
334
  #
325
- # @param group_name [String] Name of the group to enable
326
- def enable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token)
327
- _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)
328
345
  end
329
346
 
330
347
  # Disables limits for all the items in the group
331
348
  #
332
- # @param group_name [String] Name of the group to disable
333
- def disable_limits_group(group_name, manual: false, scope: $openc3_scope, token: $openc3_token)
334
- _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)
335
359
  end
336
360
 
337
361
  # Returns all defined limits sets
@@ -404,61 +428,78 @@ module OpenC3
404
428
  ###########################################################################
405
429
 
406
430
  # Enables or disables a limits group
407
- def _limits_group(group_name, action:, manual:, scope:, token:)
408
- authorize(permission: 'tlm_set', manual: manual, scope: scope, token: token)
409
- group_name.upcase!
410
- group = get_limits_groups(scope: scope, token: token)[group_name]
411
- raise "LIMITS_GROUP #{group_name} undefined. Ensure your telemetry definition contains the line: LIMITS_GROUP #{group_name}" unless group
412
-
413
- Logger.info("#{action.to_s.capitalize} Limits Group: #{group_name}", scope: scope)
414
- last_target_name = nil
415
- last_packet_name = nil
416
- packet = nil
417
- group.sort.each do |target_name, packet_name, item_name|
418
- if last_target_name != target_name || last_packet_name != packet_name
419
- if last_target_name && last_packet_name
420
- TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope)
421
- end
422
- packet = TargetModel.packet(target_name, packet_name, scope: scope)
423
- end
424
- packet['items'].each do |item|
425
- if item['name'] == item_name
426
- if action == :enable
427
- enabled = true
428
- item['limits']['enabled'] = true
429
- message = "Enabling Limits for '#{target_name} #{packet_name} #{item_name}'"
430
- elsif action == :disable
431
- enabled = false
432
- item['limits']['enabled'] = false
433
- message = "Disabling Limits for '#{target_name} #{packet_name} #{item_name}'"
434
- end
435
- Logger.info(message, scope: scope)
436
-
437
- event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name,
438
- item_name: item_name, enabled: enabled, time_nsec: Time.now.to_nsec_from_epoch, message: message }
439
- LimitsEventTopic.write(event, scope: scope)
440
- break
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)
445
+ # Items grouped by target and packet so each packet is read and written once
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
453
+
454
+ enabled = (action == :enable)
455
+ message = "#{enabled ? 'Enabling' : 'Disabling'} Limits Group: #{[target_name, group_name].compact.join(' ')}"
456
+ message += " (not nested groups)" unless cascade
457
+ Logger.info(message, scope: scope)
458
+
459
+ items.each do |item_target_name, packets|
460
+ packets.each do |packet_name, item_names|
461
+ packet = TargetModel.packet(item_target_name, packet_name, scope: scope)
462
+ item_names_hash = item_names.to_h { |name| [name, true] }
463
+ packet['items'].each do |item|
464
+ item['limits']['enabled'] = enabled if item_names_hash[item['name']]
441
465
  end
466
+ TargetModel.set_packet(item_target_name, packet_name, packet, scope: scope)
442
467
  end
443
- last_target_name = target_name
444
- last_packet_name = packet_name
445
- end
446
- if last_target_name && last_packet_name
447
- TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope)
448
468
  end
469
+
470
+ # Write a single event for the entire group. Writing one event per item
471
+ # floods the limits event stream, which is trimmed to ~1000 entries, so
472
+ # decom microservices could miss events and leave limits enabled.
473
+ # The event only names the group (readers look up the items) so it stays
474
+ # small no matter how many items the group contains.
475
+ event = { type: :LIMITS_GROUP_ENABLE_STATE, group_name: group_name,
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
481
+ LimitsEventTopic.write(event, scope: scope)
449
482
  end
450
483
 
451
- # Gets an item. The code below is mostly duplicated from tlm_process_args in tlm_api.rb.
452
- #
453
- # @param target_name [String] target name
454
- # @param packet_name [String] packet name
455
- # @param item_name [String] item name
456
- # @param scope [String] scope
457
- # @return Hash The requested item based on the packet name
458
- def _get_item(target_name, packet_name, item_name, cache_timeout: nil, scope:)
459
- # Determine if this item exists, it will raise appropriate errors if not
460
- packet_name = CvtModel.determine_latest_packet_for_item(target_name, item_name, cache_timeout: cache_timeout, scope: scope) if packet_name == 'LATEST'
461
- return TargetModel.packet_item(target_name, packet_name, item_name, scope: scope)
484
+ def _set_limits_enabled(target_name, packet_name, item_name, enabled, scope:)
485
+ packet = TargetModel.packet(target_name, packet_name, scope: scope)
486
+ item = packet['items'].find { |packet_item| packet_item['name'] == item_name }
487
+ action = enabled ? 'enabling' : 'disabling'
488
+ raise "Item '#{target_name} #{packet_name} #{item_name}' does not exist while #{action} limits" unless item
489
+
490
+ item['limits']['enabled'] = enabled
491
+ TargetModel.set_packet(target_name, packet_name, packet, scope: scope)
492
+
493
+ if enabled
494
+ message = "Enabling Limits For '#{target_name} #{packet_name} #{item_name}'"
495
+ else
496
+ message = "Disabling Limits for '#{target_name} #{packet_name} #{item_name}'"
497
+ end
498
+ Logger.info(message, scope: scope)
499
+
500
+ event = { type: :LIMITS_ENABLE_STATE, target_name: target_name, packet_name: packet_name,
501
+ item_name: item_name, enabled: enabled, time_nsec: Time.now.to_nsec_from_epoch, message: message }
502
+ LimitsEventTopic.write(event, scope: scope)
462
503
  end
463
504
  end
464
505
  end
@@ -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)