Sha256: 7dac68f327059ec60d6f5ebd3f7e776b292e7b9e4139233120efa7e224c9ef66

Contents?: true

Size: 1.45 KB

Versions: 24

Compression:

Stored size: 1.45 KB

Contents

# encoding: ascii-8bit

# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos'

module Cosmos

  class TemplatedInterface < TcpipClientInterface
    def initialize(*args)
      super(*args)
      @polling_thread = nil
      @sleeper = Sleeper.new
    end

    def connect
      super()

      # Start a thread to poll telemetry
      Thread.new do |thread|
        Cosmos.kill_thread(self, @polling_thread)
        @sleeper = Sleeper.new
        @polling_thread = Thread.current
        begin
          while connected?
            cmd("#{@target_names[0]} GET_SETPT_VOLTAGE")
            break if @sleeper.sleep(1)
          end
        rescue Errno::ECONNRESET
          # This typically means the target disconnected
        rescue Exception => err
          Logger.error "Polling Thread Unexpectedly Died.\n#{err.formatted}"
        end
      end
    end

    def disconnect
      super()
      # Note: This must be after super or the disconnect process will be interrupted by killing
      # the thread
      Cosmos.kill_thread(self, @polling_thread) if Thread.current != @polling_thread
      @polling_thread = nil
    end

    def graceful_kill
      @sleeper.cancel
    end
  end

end # module Cosmos

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cosmos-3.9.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.9.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.8.3 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.8.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.8.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.8.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.7.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.7.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.6.3 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.6.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.6.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.6.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.5.3 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.5.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.5.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.4.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.4.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.4.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.3.3 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-3.3.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb