Method: OpenC3::PreidentifiedProtocol#write_packet

Defined in:
lib/openc3/interfaces/protocols/preidentified_protocol.rb

#write_packet(packet) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/openc3/interfaces/protocols/preidentified_protocol.rb', line 59

def write_packet(packet)
  received_time = packet.received_time
  received_time = Time.now unless received_time
  @write_time_seconds = [received_time.tv_sec].pack('N') # UINT32
  @write_time_microseconds = [received_time.tv_usec].pack('N') # UINT32
  @write_target_name = packet.target_name
  @write_target_name = 'UNKNOWN' unless @write_target_name
  @write_packet_name = packet.packet_name
  @write_packet_name = 'UNKNOWN' unless @write_packet_name
  @write_flags = 0
  @write_flags |= COSMOS4_STORED_FLAG_MASK if packet.stored
  @write_extra = nil
  if packet.extra
    @write_flags |= COSMOS4_EXTRA_FLAG_MASK
    @write_extra = packet.extra.as_json(:allow_nan => true).to_json(:allow_nan => true)
  end
  return packet
end