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



45
46
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/microservices/interface_decom_common.rb', line 45

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']
  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: error.message
    }
  end
  Topic.write_topic(ack_topic, msg_hash)
end

#handle_inject_tlm(inject_tlm_json) ⇒ Object



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

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
  packet.received_count += 1
  packet.received_time = Time.now.sys
  TelemetryTopic.write_packet(packet, scope: @scope)
# If the inject_tlm parameters are bad we rescue so
# interface_microservice and decom_microservice can continue
rescue => e
  @logger.error "inject_tlm error due to #{e.message}"
end