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 <string>
28 #include <signal.h>
29 #include <stdio.h>
30 #include "sm130.h"
31
32 using namespace std;
33 using namespace upm;
34
main(int argc,char ** argv)35 int main (int argc, char **argv)
36 {
37 //! [Interesting]
38
39 // Instantiate a UART based SM130 RFID Module using defaults
40 upm::SM130* sensor = new upm::SM130();
41
42 // set the baud rate. 19200 baud is the default.
43 if (sensor->setBaudRate(19200))
44 {
45 cerr << "Failed to set baud rate" << endl;
46 return 1;
47 }
48
49 cout << "Resetting..." << endl;
50 sensor->reset();
51
52 cout << "Firmware revision: " << sensor->getFirmwareVersion() << endl;
53
54 cout << "Waiting up to 5 seconds for a tag..." << endl;
55
56 if (sensor->waitForTag(5000))
57 {
58 cout << "Found tag, UID: "
59 << sensor->string2HexString(sensor->getUID()) << endl;
60 cout << "Tag Type: " << sensor->tag2String(sensor->getTagType())
61 << endl;
62 }
63 else
64 {
65 // error
66 cout << "waitForTag failed: " << sensor->getLastErrorString() << endl;
67 }
68
69 //! [Interesting]
70
71 cout << "Exiting" << endl;
72 delete sensor;
73 return 0;
74 }
75