File: thread_scan.cpp

package info (click to toggle)
urg 0.8.12-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,236 kB
  • sloc: sh: 10,014; cpp: 6,715; ansic: 2,388; makefile: 188
file content (88 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*!
  \file
  \brief Thread sample

  \author Satofumi KAMIMURA

  $Id: thread_scan.cpp 1854 2010-07-14 00:55:57Z satofumi $
*/

#include "UrgDevice.h"
#include "Thread.h"
#include "delay.h"
#include <iostream>
#include <cstdlib>

using namespace qrk;
using namespace std;

#define AUTO_CAPTURE_TEST


static int thread_function(void* args)
{
    UrgDevice urg;

    const char* device = static_cast<const char*>(args);
    if (! urg.connect(device)) {
        cout << "UrgDevice::connect: " << urg.what() << endl;
        exit(1);
    }
#if defined(AUTO_CAPTURE_TEST)
    urg.setCaptureMode(AutoCapture);
#endif

    enum { CaptureTimes = 10 };
    vector<long> data;
    int scan_times = 0;
    while (scan_times < CaptureTimes) {
        data.clear();
        long timestamp;
        if (urg.capture(data, &timestamp)) {
            cout << device << ": n = " << data.size()
                 << ", (" << timestamp << ')'
                 << ", " << scan_times << endl;
            ++scan_times;
        } else {
#if defined(AUTO_CAPTURE_TEST)
            delay(urg.scanMsec());
#endif
        }
        delay(1);
    }

    return 0;
}


int main(int argc, char *argv[])
{
    // Change the port name appropriately
#ifdef WINDOWS_OS
    const char *devices[] = {
        "COM3",
        "COM4",
    };
#else
    const char *devices[] = {
        "/dev/ttyACM0",
        "/dev/ttyACM1",
    };
#endif

    Thread *threads[2];
    for (int i = 0; i < 2; ++i) {
        threads[i] = new Thread(thread_function, const_cast<char *>(devices[i]));
        threads[i]->run();
    }

    for (int i = 0; i < 2; ++i) {
        threads[i]->wait();
    }

#ifdef MSC
    getchar();
#endif

    return 0;
}