lib/openc3/models/cvt_model.rb in openc3-5.0.11 vs lib/openc3/models/cvt_model.rb in openc3-5.1.0
- old
+ new
@@ -14,10 +14,13 @@
# GNU Affero General Public License for more details.
# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
+#
+# This file may also be used under the terms of a commercial license
+# if purchased from OpenC3, Inc.
require 'openc3/utilities/store'
module OpenC3
class CvtModel
@@ -85,12 +88,14 @@
end
# Return all item values and limit state from the CVT
#
# @param items [Array<String>] Items to return. Must be formatted as TGT__PKT__ITEM__TYPE
+ # @param stale_time [Integer] Time in seconds from Time.now that value will be marked stale
# @return [Array] Array of values
- def self.get_tlm_values(items, scope: $openc3_scope)
+ def self.get_tlm_values(items, stale_time: 30, scope: $openc3_scope)
+ now = Time.now.to_f
results = []
lookups = []
packet_lookup = {}
# First generate a lookup hash of all the items represented so we can query the CVT
items.each { |item| _parse_item(lookups, item) }
@@ -107,13 +112,17 @@
item_result[0] = hash[value]
break if item_result[0] # We want the first value
end
# If we were able to find a value, try to get the limits state
if item_result[0]
- # The last key is simply the name (RAW) so we can append __L
- # If there is no limits then it returns nil which is acceptable
- item_result[1] = hash["#{packet_values[-1]}__L"]
- item_result[1] = item_result[1].intern if item_result[1] # Convert to symbol
+ if now - hash['RECEIVED_TIMESECONDS'] > stale_time
+ item_result[1] = :STALE
+ else
+ # The last key is simply the name (RAW) so we can append __L
+ # If there is no limits then it returns nil which is acceptable
+ item_result[1] = hash["#{packet_values[-1]}__L"]
+ item_result[1] = item_result[1].intern if item_result[1] # Convert to symbol
+ end
else
raise "Item '#{target_name} #{packet_name} #{packet_values[-1]}' does not exist" unless hash.key?(packet_values[-1])
item_result[1] = nil
end
results << item_result