#!/usr/bin/env ruby $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'optparse' require 'subduino' require 'subduino/os' require 'faye' Debug = false OptionParser.new { |op| op.on('-d', '--debug') { |d| Debug = true } op.on('-e env') { |val| set :environment, val.to_sym } op.on('-s server') { |val| set :server, val } op.on('-p port') { |val| set :port, val.to_i } }.parse!(ARGV) # set :run, true if Debug puts "Starting on #{OS}" end if ARGV.empty? || ARGV.join =~ /yml/ LastRun = {:all => 0} if File.exists?(f = ARGV.join) puts "Using config file #{f}" AppConfig = YAML.load(File.read(f))["opts"] else AppConfig = { "log_interval" => 30, "bauds" => 115200 } end client = Faye::Client.new('http://localhost:8000/faye') EM.run do Subduino.start do |read| # Subduino::ArdIO.write("hi") if Debug # puts "--------------------- #{Time.now}" p read end if LastRun[:all] < (Time.now.to_i - AppConfig["log_interval"]) LastRun[:all] = Time.now.to_i client.publish('/stats', 'data' => read) Subduino::Store.add_csv_to_store(read, true) else Subduino::Store.add_csv_to_store(read) end end end elsif ARGV.join =~ /send/ txt = ARGV[1..-1].join puts "Writing #{txt}" Subduino::ArdPS.write(txt) else require "subduino/scaffold/generator" dir = ARGV[0] puts "Subduing dir #{dir}" `mkdir #{dir}` unless File.exists?(dir) Subduino::Generator.copy_files(dir) end