Sha256: 78c45f106b9c317b29573cda0624ac853314d00b738696f2cce9255dfd5e5e17

Contents?: true

Size: 1.55 KB

Versions: 37

Compression:

Stored size: 1.55 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
          # Wait for the connection to actually occur
          while !connected?
            @sleeper.sleep(1)
          end
          loop do
            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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
cosmos-4.5.2-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.5.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.5.1-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.5.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.5.0-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.5.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.2-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.1-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.1 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.0-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.4.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.3.0-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.3.0 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.4-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.4 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.3-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.3 demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.2-java demo/config/targets/TEMPLATED/lib/templated_interface.rb
cosmos-4.2.2 demo/config/targets/TEMPLATED/lib/templated_interface.rb