scsi2sd-test.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // For compilers that support precompilation, includes "wx/wx.h".
  18. #include "SCSI2SD_HID.hh"
  19. #include "Dfu.hh"
  20. #include <algorithm>
  21. #include <iomanip>
  22. #include <iostream>
  23. #include <vector>
  24. #include <set>
  25. #include <sstream>
  26. #if __cplusplus >= 201103L
  27. #include <cstdint>
  28. #include <memory>
  29. using std::shared_ptr;
  30. #else
  31. #include <stdint.h>
  32. #include <tr1/memory>
  33. using std::tr1::shared_ptr;
  34. #endif
  35. using namespace SCSI2SD;
  36. int main()
  37. {
  38. shared_ptr<HID> hid;
  39. try
  40. {
  41. hid.reset(HID::Open());
  42. if (hid)
  43. {
  44. std::cout << "SCSI2SD Ready, firmware version " <<
  45. hid->getFirmwareVersionStr() << "\n";
  46. std::vector<uint8_t> csd(hid->getSD_CSD());
  47. std::vector<uint8_t> cid(hid->getSD_CID());
  48. std::cout << "SD Capacity (512-byte sectors): " <<
  49. hid->getSDCapacity() << std::endl;
  50. int errcode;
  51. std::cout << "SCSI Self-Test: ";
  52. if (hid->scsiSelfTest(errcode))
  53. {
  54. std::cout << "Passed\n";
  55. }
  56. else
  57. {
  58. std::cout << "FAIL (" << errcode << ")\n";
  59. }
  60. }
  61. else
  62. {
  63. std::cerr << "Device not found" << std::endl;
  64. }
  65. }
  66. catch (std::runtime_error& e)
  67. {
  68. std::cerr << e.what() << std::endl;
  69. }
  70. }