Module: OpenC3::InterfaceDecomCommon

Included in:
DecomMicroservice, InterfaceCmdHandlerThread
Defined in:
lib/openc3/microservices/interface_decom_common.rb

Instance Method Summary collapse

Instance Method Details

#handle_build_cmd(build_cmd_json, msg_id) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/openc3/microservices/interface_decom_common.rb', line 61

def handle_build_cmd(build_cmd_json, msg_id)
  build_cmd_hash = JSON.parse(build_cmd_json, allow_nan: true, create_additions: true)
  target_name = build_cmd_hash['target_name']
  cmd_name = build_cmd_hash['cmd_name']
  cmd_params = build_cmd_hash['cmd_params']
  range_check = build_cmd_hash['range_check']
  raw = build_cmd_hash['raw']
  db_shard = Store.db_shard_for_target(target_name, scope: @scope)
  ack_topic = "{#{@scope}__ACKCMD}TARGET__#{target_name}"
  begin
    command = System.commands.build_cmd(target_name, cmd_name, cmd_params, range_check, raw)
    msg_hash = {
      id: msg_id,
      result: 'SUCCESS',
      time: command.packet_time.to_nsec_from_epoch,
      received_time: command.received_time.to_nsec_from_epoch,
      target_name: command.target_name,
      packet_name: command.packet_name,
      received_count: command.received_count,
      buffer: command.buffer(false)
    }
  # If there is an error due to parameter out of range, etc, we rescue it so we can
  # write the ACKCMD}TARGET topic and allow the TelemetryDecomTopic.build_cmd to return
  rescue => error
    msg_hash = {
      id: msg_id,
      result: error.message
    }
  end
  Topic.write_topic(ack_topic, msg_hash, db_shard: db_shard)
end

#handle_get_tlm_buffer(get_tlm_buffer_json, msg_id) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/openc3/microservices/interface_decom_common.rb', line 93

def handle_get_tlm_buffer(get_tlm_buffer_json, msg_id)
  get_tlm_buffer_hash = JSON.parse(get_tlm_buffer_json, allow_nan: true, create_additions: true)
  target_name = get_tlm_buffer_hash['target_name']
  packet_name = get_tlm_buffer_hash['packet_name']
  db_shard = Store.db_shard_for_target(target_name, scope: @scope)
  ack_topic = "{#{@scope}__ACKCMD}TARGET__#{target_name}"
  begin
    packet = System.telemetry.packet(target_name, packet_name)
    msg_hash = {
      id: msg_id,
      result: 'SUCCESS',
      time: packet.packet_time.to_nsec_from_epoch,
      received_time: packet.received_time.to_nsec_from_epoch,
      target_name: packet.target_name,
      packet_name: packet.packet_name,
      received_count: packet.received_count,
      stored: packet.stored.to_s,
      buffer: packet.buffer(false)
    }
    msg_hash[:extra] = JSON.generate(packet.extra.as_json, allow_nan: true) if packet.extra

  # If there is an error due to parameter out of range, etc, we rescue it so we can
  # write the ACKCMD}TARGET topic and allow the source to return
  rescue => error
    msg_hash = {
      id: msg_id,
      result: error.message
    }
  end
  Topic.write_topic(ack_topic, msg_hash, db_shard: db_shard)
end

#handle_inject_tlm(inject_tlm_json) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/openc3/microservices/interface_decom_common.rb', line 22

def handle_inject_tlm(inject_tlm_json)
  inject_tlm_hash = JSON.parse(inject_tlm_json, allow_nan: true, create_additions: true)
  target_name = inject_tlm_hash['target_name']
  packet_name = inject_tlm_hash['packet_name']
  item_hash = inject_tlm_hash['item_hash']
  type = inject_tlm_hash['type'].to_s.intern
  packet = System.telemetry.packet(target_name, packet_name)
  if item_hash
    item_hash.each do |name, value|
      packet.write(name.to_s, value, type)
    end
  end
  stored = inject_tlm_hash.fetch('stored', false)
  packet.stored = stored.to_s.downcase == 'true'
  packet.received_time = Time.now.sys
  packet.received_count = TargetModel.increment_telemetry_count(packet.target_name, packet.packet_name, 1, scope: @scope)
  TelemetryTopic.write_packet(packet, scope: @scope)
end

#handle_inject_tlm_with_ack(inject_tlm_json, msg_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/openc3/microservices/interface_decom_common.rb', line 41

def handle_inject_tlm_with_ack(inject_tlm_json, msg_id)
  inject_tlm_hash = JSON.parse(inject_tlm_json, allow_nan: true, create_additions: true)
  target_name = inject_tlm_hash['target_name']
  ack_topic = "{#{@scope}__ACKCMD}TARGET__#{target_name}"
  begin
    handle_inject_tlm(inject_tlm_json)
    msg_hash = {
      id: msg_id,
      result: 'SUCCESS'
    }
  rescue => error
    @logger.error "inject_tlm error due to #{error.message}"
    msg_hash = {
      id: msg_id,
      result: error.message
    }
  end
  Topic.write_topic(ack_topic, msg_hash)
end