Class: OpenC3::CommandDecomTopic
- Inherits:
-
Topic
show all
- Defined in:
- lib/openc3/topics/command_decom_topic.rb
Class Method Summary
collapse
Methods inherited from Topic
clear_topics, get_cnt, method_missing
Class Method Details
.get_cmd_item(target_name, packet_name, param_name, type: :WITH_UNITS, scope: $openc3_scope) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/openc3/topics/command_decom_topic.rb', line 47
def self.get_cmd_item(target_name, packet_name, param_name, type: :WITH_UNITS, scope: $openc3_scope)
msg_id, msg_hash = Topic.get_newest_message("#{scope}__DECOMCMD__{#{target_name}}__#{packet_name}")
if msg_id
if param_name == 'RECEIVED_COUNT'
msg_hash['received_count'].to_i
else
json = msg_hash['json_data']
hash = JSON.parse(json, :allow_nan => true, :create_additions => true)
value = hash["#{param_name}__U"]
return value if value && type == :WITH_UNITS
value = hash["#{param_name}__F"]
return value if value && (type == :WITH_UNITS || type == :FORMATTED)
value = hash["#{param_name}__C"]
return value if value && (type == :WITH_UNITS || type == :FORMATTED || type == :CONVERTED)
return hash[param_name]
end
end
end
|
.write_packet(packet, scope:) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/openc3/topics/command_decom_topic.rb', line 28
def self.write_packet(packet, scope:)
topic = "#{scope}__DECOMCMD__{#{packet.target_name}}__#{packet.packet_name}"
msg_hash = { time: packet.packet_time.to_nsec_from_epoch,
target_name: packet.target_name,
packet_name: packet.packet_name,
stored: packet.stored.to_s,
received_count: packet.received_count }
json_hash = {}
packet.sorted_items.each do |item|
json_hash[item.name] = packet.read_item(item, :RAW)
json_hash[item.name + "__C"] = packet.read_item(item, :CONVERTED) if item.write_conversion or item.states
json_hash[item.name + "__F"] = packet.read_item(item, :FORMATTED) if item.format_string
json_hash[item.name + "__U"] = packet.read_item(item, :WITH_UNITS) if item.units
end
json_hash['extra'] = JSON.generate(packet..as_json(:allow_nan => true))
msg_hash['json_data'] = JSON.generate(json_hash.as_json(:allow_nan => true))
EphemeralStoreQueued.write_topic(topic, msg_hash)
end
|