573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
|
# File 'lib/openc3/microservices/interface_microservice.rb', line 573
def run
begin
if @interface.read_allowed?
@logger.info "#{@interface.name}: Starting packet reading"
else
@logger.info "#{@interface.name}: Starting connection maintenance"
end
while true
break if @cancel_thread
case @interface.state
when 'DISCONNECTED'
@interface_thread_sleeper.sleep(1)
when 'ATTEMPTING'
begin
@mutex.synchronize do
connect() unless @cancel_thread
end
rescue Exception => e
handle_connection_failed(@interface.connection_string, e)
break if @cancel_thread
end
when 'CONNECTED'
if @interface.read_allowed?
begin
packet = @interface.read
if packet
handle_packet(packet)
@count += 1
if @interface_or_router == 'INTERFACE'
@metric.set(name: 'interface_tlm_total', value: @count, type: 'counter')
else
@metric.set(name: 'router_cmd_total', value: @count, type: 'counter')
end
else
@logger.info "#{@interface.name}: Internal disconnect requested (returned nil)"
handle_connection_lost()
break if @cancel_thread
end
rescue Exception => e
handle_connection_lost(e)
break if @cancel_thread
end
else
@interface_thread_sleeper.sleep(1)
handle_connection_lost() if !@interface.connected?
end
end
end
rescue Exception => e
unless SystemExit === e or SignalException === e
@logger.error "#{@interface.name}: Packet reading thread died: #{e.formatted}"
OpenC3.handle_fatal_exception(e)
end
disconnect(false)
end
if @interface_or_router == 'INTERFACE'
InterfaceStatusModel.set(@interface.as_json(:allow_nan => true), queued: true, scope: @scope)
else
RouterStatusModel.set(@interface.as_json(:allow_nan => true), queued: true, scope: @scope)
end
@logger.info "#{@interface.name}: Stopped packet reading"
end
|