zfm20.cxx revision 765adb95dc941c32690d6c43bc08b9d07d197fcb
1/*
2 * Author: Jon Trulson <jtrulson@ics.com>
3 * Copyright (c) 2015 Intel Corporation.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <unistd.h>
26#include <iostream>
27#include <signal.h>
28#include "zfm20.h"
29
30using namespace std;
31using namespace upm;
32
33int main (int argc, char **argv)
34{
35//! [Interesting]
36  // Instantiate a ZFM20 Fingerprint reader on UART 0
37
38  upm::ZFM20* fp = new upm::ZFM20(0);
39
40  // make sure port is initialized properly.  57600 baud is the default.
41  if (!fp->setupTty(B57600))
42    {
43      cerr << "Failed to setup tty port parameters" << endl;
44      return 1;
45    }
46
47  // first, set the default password and address
48  fp->setPassword(ZFM20_DEFAULT_PASSWORD);
49  fp->setAddress(ZFM20_DEFAULT_ADDRESS);
50
51  // now verify the password.  If this fails, any other commands
52  // will be ignored, so we just bail.
53  if (fp->verifyPassword())
54    {
55      cout << "Password verified." << endl;
56    }
57  else
58    {
59      cerr << "Password verification failed." << endl;
60      return 1;
61    }
62
63  // how many valid stored templates (fingerprints) do we have?
64  cout << "Total stored templates: " << fp->getNumTemplates() << endl;
65  cout << endl;
66
67  // now spin waiting for a fingerprint to successfully image
68  cout << "Waiting for finger print..." << endl;
69
70  while (fp->generateImage() == ZFM20::ERR_NO_FINGER)
71    ;
72
73  // in theory, we have an image
74  cout << "Image captured, converting..." << endl;
75
76  uint8_t rv;
77  if ((rv = fp->image2Tz(1)) != ZFM20::ERR_OK)
78    {
79      cerr << "Image conversion failed with error code " << int(rv) <<endl;
80      return 1;
81    }
82
83  cout << "Image conversion succeeded." << endl;
84  cout << "Searching database..." << endl;
85
86  uint16_t id = 0;
87  uint16_t score = 0;
88
89  // we search for a print matching slot 1, where we shored our last
90  // converted fingerprint
91  if ((rv = fp->search(1, &id, &score)) != ZFM20::ERR_OK)
92    {
93      if (rv == ZFM20::ERR_FP_NOTFOUND)
94        {
95          cout << "Finger Print not found" << endl;
96          return 0;
97        }
98      else
99        {
100          cerr << "Search failed with error code " << int(rv) <<endl;
101          return 1;
102        }
103    }
104
105  cout << "Fingerprint found!" << endl;
106  cout << "ID: " << int(id) << ", Score: " << int(score) << endl;
107
108//! [Interesting]
109
110  delete fp;
111  return 0;
112}
113