446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
# File 'lib/openc3/microservices/interface_microservice.rb', line 446
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 => connect_error
handle_connection_failed(connect_error)
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 => err
handle_connection_lost(err)
break if @cancel_thread
end
else
@interface_thread_sleeper.sleep(1)
handle_connection_lost() if !@interface.connected?
end
end
end
rescue Exception => error
unless SystemExit === error or SignalException === error
@logger.error "#{@interface.name}: Packet reading thread died: #{error.formatted}"
OpenC3.handle_fatal_exception(error)
end
disconnect(false)
end
if @interface_or_router == 'INTERFACE'
InterfaceStatusModel.set(@interface.as_json(:allow_nan => true), scope: @scope)
else
RouterStatusModel.set(@interface.as_json(:allow_nan => true), scope: @scope)
end
@logger.info "#{@interface.name}: Stopped packet reading"
end
|