Add command-line test utility
[SCSI2SD-V6.git] / src / scsi2sd-util6 / scsi2sd-test.cc
1 // Copyright (C) 2018 Michael McMaster <michael@codesrc.com>
2 //
3 // This file is part of SCSI2SD.
4 //
5 // SCSI2SD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // SCSI2SD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
17
18
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "SCSI2SD_HID.hh"
21 #include "Dfu.hh"
22
23 #include <algorithm>
24 #include <iomanip>
25 #include <iostream>
26 #include <vector>
27 #include <set>
28 #include <sstream>
29
30 #if __cplusplus >= 201103L
31 #include <cstdint>
32 #include <memory>
33 using std::shared_ptr;
34 #else
35 #include <stdint.h>
36 #include <tr1/memory>
37 using std::tr1::shared_ptr;
38 #endif
39
40 using namespace SCSI2SD;
41
42 int main()
43 {
44 shared_ptr<HID> hid;
45 try
46 {
47 hid.reset(HID::Open());
48 if (hid)
49 {
50 std::cout << "SCSI2SD Ready, firmware version " <<
51 hid->getFirmwareVersionStr() << "\n";
52
53 std::vector<uint8_t> csd(hid->getSD_CSD());
54 std::vector<uint8_t> cid(hid->getSD_CID());
55 std::cout << "SD Capacity (512-byte sectors): " <<
56 hid->getSDCapacity() << std::endl;
57
58 int errcode;
59 std::cout << "SCSI Self-Test: ";
60 if (hid->scsiSelfTest(errcode))
61 {
62 std::cout << "Passed\n";
63 }
64 else
65 {
66 std::cout << "FAIL (" << errcode << ")\n";
67 }
68 }
69 else
70 {
71 std::cerr << "Device not found" << std::endl;
72 }
73 }
74 catch (std::runtime_error& e)
75 {
76 std::cerr << e.what() << std::endl;
77 }
78 }
79