#!/usr/bin/ruby
#
# This was supposed to feed a circle of fixes to the emulator, but it
# doesn't seem to work...

require 'net/telnet'

LATITUDE = 45.52
LONGITUDE = -122.68
SCALE = 0.1

begin
  (0..10).each do |angle|
    radians = (2.0 * Math::PI) * (angle / 10.0)
    longitude = LONGITUDE - (Math.cos(radians) * SCALE)
    latitude = LATITUDE + (Math.sin(radians) * SCALE)
    android = Net::Telnet::new("Host" => "localhost",
                               "Port" => 5554,
                               "Timeout" => 10,
                               "Prompt" => "OK",
                               "Output_log" => "telnet.log")

    cmd = "geo fix %3.4f %2.4f\n\r" % [longitude, latitude]
    puts "Sending #{cmd}"
    android.write(cmd)
    puts "Waiting for prompt"
    android.waitfor "String" => "OK"
    puts "closing"
    android.close
    puts "Sleeping"
    sleep 5
  end
end while true

