/*!
  \example gdRangeTest.cpp

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

  \author Satofumi KAMIMURA

  $Id: gdRangeTest.cpp 1739 2010-03-06 07:43:32Z satofumi $
*/

#include "mUrgDevice.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());
  mUrgDevice urg(argc, argv);
  if (! urg.connect(urg_ports[0].c_str())) {
    printf("UrgDevice::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;
}
