Skip to content

Commit 2a75703

Browse files
committed
Handle LATEST with never received
1 parent 7387f0b commit 2a75703

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

openc3/lib/openc3/models/cvt_model.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ def self.determine_latest_packet_for_item(target_name, item_name, cache_timeout:
411411
latest_packet_name = packet_name
412412
end
413413
end
414-
raise "Item '#{target_name} LATEST #{item_name}' does not exist for scope: #{scope}" if latest == -1
414+
# Return the first packet name if no packets have been received
415+
if latest == -1
416+
latest_packet_name = packet_names[0]
417+
end
415418
return latest_packet_name
416419
end
417420

openc3/python/openc3/models/cvt_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ def determine_latest_packet_for_item(cls, target_name, item_name, cache_timeout=
442442
if pkt_hash["PACKET_TIMESECONDS"] and pkt_hash["PACKET_TIMESECONDS"] > latest:
443443
latest = pkt_hash["PACKET_TIMESECONDS"]
444444
latest_packet_name = packet_name
445+
# Return the first packet name if no packets have been received
445446
if latest == -1:
446-
raise RuntimeError(f"Item '{target_name} LATEST {item_name}' does not exist for scope: {scope}")
447+
latest_packet_name = packet_names[0]
447448
return latest_packet_name
448449

449450
@classmethod

openc3/python/test/models/test_cvt_model.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from openc3.models.target_model import TargetModel
2323
from openc3.packets.packet import Packet
2424
from openc3.conversions.generic_conversion import GenericConversion
25-
25+
from openc3.utilities.store import Store
2626

2727
class TestCvtModel(unittest.TestCase):
2828
def setUp(self):
@@ -619,3 +619,13 @@ def test_returns_all_overrides_the_cvt(self):
619619
CvtModel.normalize("INST", "HEALTH_STATUS", "TEMP2", type="ALL", scope="DEFAULT")
620620
CvtModel.normalize("INST", "ADCS", "POSX", type="ALL", scope="DEFAULT")
621621
CvtModel.normalize("SYSTEM", "META", "OPERATOR_NAME", type="ALL", scope="DEFAULT")
622+
623+
def test_determine_latest_packet_for_item_works_if_not_received(self):
624+
model = TargetModel(folder_name="INST", name="INST", scope="DEFAULT")
625+
model.create()
626+
names = TargetModel.names(scope="DEFAULT")
627+
self.assertIn("INST", names)
628+
Store.set(f"DEFAULT__INST__item_to_packet_map", json.dumps({"PACKET_ID": ["PACKET1"]}))
629+
Store.hset(f"DEFAULT__tlm__INST", "PACKET1", json.dumps({"PACKET_TIMESECONDS": None}))
630+
packet_name = CvtModel.determine_latest_packet_for_item("INST", "PACKET_ID", scope="DEFAULT")
631+
self.assertNotEqual(packet_name, None)

openc3/spec/models/cvt_model_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ def check_temp1
344344
end)
345345
expect(packet_name).not_to eq('something')
346346
end
347+
348+
it "works_if_not_received" do
349+
model = TargetModel.new(folder_name: "INST", name: "INST", scope: "DEFAULT")
350+
model.create()
351+
names = TargetModel.names(scope:"DEFAULT")
352+
expect(names.include?("INST"))
353+
Store.set("DEFAULT__INST__item_to_packet_map", JSON.generate({"PACKET_ID" => ["PACKET1"]}))
354+
Store.hset("DEFAULT__tlm__INST", "PACKET1", JSON.generate({"PACKET_TIMESECONDS" => nil}))
355+
packet_name = CvtModel.determine_latest_packet_for_item("INST", "PACKET_ID", scope:"DEFAULT")
356+
expect(packet_name != nil)
357+
end
347358
end
348359

349360
describe "overrides" do

0 commit comments

Comments
 (0)