/*!
  \example gdRangeTest.cpp

  \brief GD の範囲を変えながら応答を確認する

  \author Satofumi KAMIMURA

  $Id: gdRangeTest.cpp 1434 2009-10-20 16:52:38Z satofumi $
*/

#include "mUrgCtrl.h"
#include "findUrgPorts.h"
#include <SDL.h>

using namespace qrk;
using namespace std;


namespace {
  vector<string> findUrgPort(void)
  {
    vector<string> ports;
    findUrgPorts(ports);

    return ports;
  }
}


int main(int argc, char *argv[])
{
  vector<string> urg_ports = findUrgPort();
  if (urg_ports.empty()) {
    printf("no URG ports.\n");
    exit(1);
  }

  printf("%s\n", urg_ports[0].c_str());
  mUrgCtrl urg(argc, argv);
  if (! urg.connect(urg_ports[0].c_str())) {
    printf("UrgCtrl::connect: %s\n", urg.what());
    exit(1);
  }

  vector<long> data;
  for (int last = 500; last >= 0; --last) {
    //urg.setCaptureRange(0, last);
    urg.setCaptureRange(0, 301);
    int n = urg.capture(data);

    printf("%3d: n = %d\n", last, n);
  }

  return 0;
}
