~vibhavp/ubuntu/saucy/urg/merge-from-debian

« back to all changes in this revision

Viewing changes to samples/cpp/thread_scan.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albert Huang
  • Date: 2011-05-20 11:33:03 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110520113303-u8niofzwzcea0osk
Tags: 0.8.12-1
* New upstream release (closes: #624987)
* Add debian/watch file
* Bump standards-version to 3.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file
 
3
  \brief Thread sample
 
4
 
 
5
  \author Satofumi KAMIMURA
 
6
 
 
7
  $Id: thread_scan.cpp 1854 2010-07-14 00:55:57Z satofumi $
 
8
*/
 
9
 
 
10
#include "UrgDevice.h"
 
11
#include "Thread.h"
 
12
#include "delay.h"
 
13
#include <iostream>
 
14
#include <cstdlib>
 
15
 
 
16
using namespace qrk;
 
17
using namespace std;
 
18
 
 
19
#define AUTO_CAPTURE_TEST
 
20
 
 
21
 
 
22
static int thread_function(void* args)
 
23
{
 
24
    UrgDevice urg;
 
25
 
 
26
    const char* device = static_cast<const char*>(args);
 
27
    if (! urg.connect(device)) {
 
28
        cout << "UrgDevice::connect: " << urg.what() << endl;
 
29
        exit(1);
 
30
    }
 
31
#if defined(AUTO_CAPTURE_TEST)
 
32
    urg.setCaptureMode(AutoCapture);
 
33
#endif
 
34
 
 
35
    enum { CaptureTimes = 10 };
 
36
    vector<long> data;
 
37
    int scan_times = 0;
 
38
    while (scan_times < CaptureTimes) {
 
39
        data.clear();
 
40
        long timestamp;
 
41
        if (urg.capture(data, &timestamp)) {
 
42
            cout << device << ": n = " << data.size()
 
43
                 << ", (" << timestamp << ')'
 
44
                 << ", " << scan_times << endl;
 
45
            ++scan_times;
 
46
        } else {
 
47
#if defined(AUTO_CAPTURE_TEST)
 
48
            delay(urg.scanMsec());
 
49
#endif
 
50
        }
 
51
        delay(1);
 
52
    }
 
53
 
 
54
    return 0;
 
55
}
 
56
 
 
57
 
 
58
int main(int argc, char *argv[])
 
59
{
 
60
    // Change the port name appropriately
 
61
#ifdef WINDOWS_OS
 
62
    const char *devices[] = {
 
63
        "COM3",
 
64
        "COM4",
 
65
    };
 
66
#else
 
67
    const char *devices[] = {
 
68
        "/dev/ttyACM0",
 
69
        "/dev/ttyACM1",
 
70
    };
 
71
#endif
 
72
 
 
73
    Thread *threads[2];
 
74
    for (int i = 0; i < 2; ++i) {
 
75
        threads[i] = new Thread(thread_function, const_cast<char *>(devices[i]));
 
76
        threads[i]->run();
 
77
    }
 
78
 
 
79
    for (int i = 0; i < 2; ++i) {
 
80
        threads[i]->wait();
 
81
    }
 
82
 
 
83
#ifdef MSC
 
84
    getchar();
 
85
#endif
 
86
 
 
87
    return 0;
 
88
}