Class: OpenC3::RouterTlmHandlerThread

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/microservices/interface_microservice.rb

Instance Method Summary collapse

Constructor Details

#initialize(router, tlm, scope:) ⇒ RouterTlmHandlerThread

Returns a new instance of RouterTlmHandlerThread.



164
165
166
167
168
# File 'lib/openc3/microservices/interface_microservice.rb', line 164

def initialize(router, tlm, scope:)
  @router = router
  @tlm = tlm
  @scope = scope
end

Instance Method Details

#graceful_killObject



183
184
185
# File 'lib/openc3/microservices/interface_microservice.rb', line 183

def graceful_kill
  RouterTopic.shutdown(@router, scope: @scope)
end

#runObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/openc3/microservices/interface_microservice.rb', line 187

def run
  RouterTopic.receive_telemetry(@router, scope: @scope) do |topic, msg_hash|
    # Check for commands to the router itself
    if /CMD}ROUTER/.match?(topic)
      if msg_hash['shutdown']
        Logger.info "#{@router.name}: Shutdown requested"
        return
      end
      if msg_hash['connect']
        Logger.info "#{@router.name}: Connect requested"
        @tlm.attempting()
      end
      if msg_hash['disconnect']
        Logger.info "#{@router.name}: Disconnect requested"
        @tlm.disconnect(false)
      end
      if msg_hash.key?('log_raw')
        if msg_hash['log_raw'] == 'true'
          Logger.info "#{@router.name}: Enable raw logging"
          @router.start_raw_logging
        else
          Logger.info "#{@router.name}: Disable raw logging"
          @router.stop_raw_logging
        end
      end
      next 'SUCCESS'
    end

    if @router.connected?
      target_name = msg_hash["target_name"]
      packet_name = msg_hash["packet_name"]

      packet = System.telemetry.packet(target_name, packet_name)
      packet.stored = ConfigParser.handle_true_false(msg_hash["stored"])
      packet.received_time = Time.from_nsec_from_epoch(msg_hash["time"].to_i)
      packet.received_count = msg_hash["received_count"].to_i
      packet.buffer = msg_hash["buffer"]

      begin
        @router.write(packet)
        RouterStatusModel.set(@router.as_json(:allow_nan => true), scope: @scope)
        next 'SUCCESS'
      rescue => e
        Logger.error "#{@router.name}: #{e.formatted}"
        next e.message
      end
    end
  end
end

#startObject



170
171
172
173
174
175
176
177
# File 'lib/openc3/microservices/interface_microservice.rb', line 170

def start
  @thread = Thread.new do
    run()
  rescue Exception => err
    Logger.error "#{@router.name}: Telemetry handler thread died: #{err.formatted}"
    raise err
  end
end

#stopObject



179
180
181
# File 'lib/openc3/microservices/interface_microservice.rb', line 179

def stop
  OpenC3.kill_thread(self, @thread)
end