File: find_all_pp.cpp

package info (click to toggle)
libftdi 0.20-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, stretch, trixie
  • size: 2,076 kB
  • ctags: 598
  • sloc: sh: 11,006; ansic: 2,417; cpp: 594; makefile: 116
file content (71 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (4)
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
/* final_all_pp.cpp

   Simple libftdi-cpp usage

   This program is distributed under the GPL, version 2
*/

#include "ftdi.hpp"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
using namespace Ftdi;

int main(int argc, char **argv)
{
    // Show help
    if (argc > 1)
    {
        if (strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0)
        {
            std::cout << "Usage: " << argv[0] << " [-v VENDOR_ID] [-p PRODUCT_ID]" << std::endl;
            return EXIT_SUCCESS;
        }
    }

    // Parse args
    int vid = 0x0403, pid = 0x6010, tmp = 0;
    for (int i = 0; i < (argc - 1); i++)
    {
        if (strcmp(argv[i], "-v") == 0)
            if ((tmp = strtol(argv[++i], 0, 16)) >= 0)
                vid = tmp;

        if (strcmp(argv[i], "-p") == 0)
            if ((tmp = strtol(argv[++i], 0, 16)) >= 0)
                pid = tmp;
    }

    // Print header
    std::cout << std::hex << std::showbase
    << "Found devices ( VID: " << vid << ", PID: " << pid << " )"
    << std::endl
    << "------------------------------------------------"
    << std::endl << std::dec;

    // Print whole list
    List* list = List::find_all(vid, pid);
    for (List::iterator it = list->begin(); it != list->end(); it++)
    {
        std::cout << "FTDI (" << &*it << "): "
        << it->vendor() << ", "
        << it->description() << ", "
        << it->serial();

        // Open test
        if(it->open() == 0)
           std::cout << " (Open OK)";
        else
           std::cout << " (Open FAILED)";

        it->close();

        std::cout << std::endl;

    }

    delete list;

    return EXIT_SUCCESS;
}