Sha256: 2a95d38175b22d24a47226a94b26c8decbcd752298a11e2fb1ad7934ed4df668

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

# encoding: ascii-8bit

# Copyright 2017 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

# This file implements an example background task

require 'cosmos/tools/cmd_tlm_server/background_task'

module Cosmos
  # Starts by sleeping 5 seconds then sends up to three collect commands
  class ExampleBackgroundTask < BackgroundTask
    def initialize
      super()
      @name = 'Example Background Task'
    end

    def call
      sent_count = 0
      @sleeper = Sleeper.new
      @status = "Sleeping for 5 seconds"
      return if @sleeper.sleep(5) # allow interfaces time to start
      initial_count = tlm('INST', 'HEALTH_STATUS', 'COLLECTS')
      loop do
        # Start up with at least 3 collects
        count = tlm('INST', 'HEALTH_STATUS', 'COLLECTS')
        if (count < (initial_count + 3))
          begin
            cmd('INST', 'COLLECT', 'TYPE' => 'NORMAL', 'DURATION' => 1)
            sent_count += 1
            @status = "Sent COLLECT ##{sent_count} at #{Time.now.sys.formatted}"
            wait("INST HEALTH_STATUS COLLECTS > #{count}", 5)
            @status = "Tlm Updated at #{Time.now.sys.formatted}"
          rescue
            # Oh well - probably disconnected
          end
        else
          break
        end
        return if @sleeper.sleep(1)
      end
      @status = "Finished at #{Time.now.sys.formatted}"
    end

    def stop
      @sleeper.cancel
      @status = "Stopped at #{Time.now.sys.formatted}"
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cosmos-4.0.3-java demo/lib/example_background_task.rb
cosmos-4.0.3-universal-java-1.8 demo/lib/example_background_task.rb
cosmos-4.0.3 demo/lib/example_background_task.rb
cosmos-4.0.2-universal-java-1.8 demo/lib/example_background_task.rb
cosmos-4.0.2 demo/lib/example_background_task.rb
cosmos-4.0.1-universal-java-1.8 demo/lib/example_background_task.rb
cosmos-4.0.1 demo/lib/example_background_task.rb
cosmos-4.0.0-universal-java-1.8 demo/lib/example_background_task.rb
cosmos-4.0.0 demo/lib/example_background_task.rb