#! /usr/bin/env ruby
#
require 'orocos'
require 'optparse'
Orocos.initialize

gui = false
optparse = OptionParser.new do |opt|
    opt.banner = "run [--gui] DEVICE"
    opt.on '--gui', "starts the Rock task inspection widget on the running task" do
        gui = true
    end
end

dev_id = *optparse.parse(ARGV)
if !dev_id
    puts optparse
    exit 1
end

if gui
    require 'vizkit'
end

Orocos.run 'mbeam_imagenex::Task' => 'mbeam' do
    Orocos.logger.level = Logger::DEBUG
    Orocos.log_all
    puts "deployed the mbeam_imagenex::Task task"
    mbeam = Orocos::TaskContext.get 'mbeam'
    mbeam.io_read_timeout = Time.at(2);
    Orocos.apply_conf_file(mbeam, 'mbeam.yml', [dev_id])
    mbeam.configure
    mbeam.start

    if gui
        task_inspector = Vizkit.default_loader.task_inspector
        task_inspector.config(mbeam)
        task_inspector.show
        Vizkit.exec
    else
	#reader = mbeam.mbeam_samples.reader
        #Orocos.watch(alt) do
        #    if sample = reader.read
        #        pp sample
        #    end
        #end
    end
end

