OpenC3 / cosmos

OpenC3 COSMOS
https://openc3.com
Other
94 stars 26 forks source link

Telemetry PROCESSOR seems to be called twice per packet #95

Closed jhayes-apl closed 1 year ago

jhayes-apl commented 1 year ago

I have a PROCESSOR attached to a telemetry packet. On receipt of the packet, the PROCESSOR sends a command back to the instrument. However, instead of a single command sent, the PROCESSOR sends two, a few milliseconds apart. Here are two commands from the log (CmdTlmServer):

2022-08-23 13:58:55.198     
INFO    DEFAULT__DECOM__LVX cmd("LVX TIME_RESPONSE with RCV_TIME 16622667336477032704, XMT_TIME 16622667336477032704")
2022-08-23 13:58:55.174     
INFO    DEFAULT__INTERFACE__LVX_INT cmd("LVX TIME_RESPONSE with RCV_TIME 16622667336363126422, XMT_TIME 16622667336363126422")

It's as if the PROCESSOR is called twice. Is this a COSMOS bug, or am I doing something silly?

Here is the telemetry packet and PROCESSOR:

TELEMETRY LVX TIME_REQUEST BIG_ENDIAN "Time request"
  <%= render "_ccsds_tlm.txt", locals: {id: 0x00} %>
  <%= render "_timetag_tlm.txt" %>
  # Keyword      Name           BitSize Type   ID      Description
  APPEND_ITEM    CRC            16      UINT           "CRC"
    FORMAT_STRING "0x%04x"
  PROCESSOR TIMEREQRESP time_service.rb

Here is time_service.rb (some comments deleted):

require 'cosmos/processors/processor'
require 'cosmos/api/api'

module Cosmos
  class TimeService < Processor
    include Api

    # NTP uses 1900 as the epoch
    NTP_DELTA = Time.utc(1970) - Time.utc(1900)

    def initialize
      super()
    end

    # Perform processing on the packet.
    def call(packet, buffer)
      ntp = Time.now + NTP_DELTA    # seconds since the epoch
      ntp_i = ntp.to_i          # broken into integer
      ntp_f = ntp.nsec*(2**32)/(10**9)  #   and fraction
      ntp_time = (2**32)*ntp_i + ntp_f  # combined into 64-bit value
      cmd("LVX TIME_RESPONSE with RCV_TIME #{ntp_time}, XMT_TIME #{ntp_time}")
    end

  end

I am using COSMOS 5.0.3 Linux.

jmthomas commented 1 year ago

It looks like the command is getting processed once by the Interface and then once by our Decommutation logic. This is actually by design because processors are typically used to process and generate telemetry, not to have side effects like sending commands. I'd recommend implementing this in a Custom Protocol.