/*!
  \file
  \brief データ取得サンプル

  \author Satofumi KAMIMURA

  $Id: gdScanSample.cpp 1883 2010-08-20 04:12:36Z satofumi $
*/

#include "UrgCtrl.h"
#include <cstdlib>
#include <cstdio>

using namespace qrk;
using namespace std;


//! main
int main(int argc, char *argv[]) {

  //const char device[] = "COM3"; /* Windows での例 */
  const char device[] = "/dev/ttyACM0";

  UrgCtrl urg;
  if (! urg.connect(device)) {
    printf("UrgCtrl::connect: %s\n", urg.what());
    exit(1);
  }

  // データ取得
  vector<long> data;
  long timestamp = 0;
  int n = urg.capture(data, &timestamp);
  printf("n = %d\n", n);
  if (n < 0) {
    printf("UrgCtrl::capture: %s\n", urg.what());
    exit(1);
  }

  printf("timestamp: %ld\n", timestamp);
  for (int i = 0; i < n; ++i) {
    printf("%ld, ", data[i]);
  }
  printf("\n");

  return 0;
}
