TargetPanel.cc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. // Copyright (C) 2014 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 <wx/wxprec.h>
  19. #ifndef WX_PRECOMP
  20. #include <wx/wx.h>
  21. #endif
  22. #include <wx/wrapsizer.h>
  23. #include "ConfigUtil.hh"
  24. #include "TargetPanel.hh"
  25. #include <limits>
  26. #include <sstream>
  27. #include <math.h>
  28. #include <string.h>
  29. using namespace SCSI2SD;
  30. wxDEFINE_EVENT(SCSI2SD::ConfigChangedEvent, wxCommandEvent);
  31. namespace
  32. {
  33. template<typename IntType, class WXCTRL> std::pair<IntType, bool>
  34. CtrlGetValue(WXCTRL* ctrl)
  35. {
  36. IntType value;
  37. std::stringstream conv;
  38. conv << ctrl->GetValue();
  39. conv >> value;
  40. return std::make_pair(value, static_cast<bool>(conv));
  41. }
  42. void CtrlGetFixedString(wxTextEntry* ctrl, char* dest, size_t len)
  43. {
  44. memset(dest, ' ', len);
  45. strncpy(dest, ctrl->GetValue().ToAscii(), len);
  46. }
  47. bool CtrlIsAscii(wxTextEntry* ctrl)
  48. {
  49. return ctrl->GetValue().IsAscii();
  50. }
  51. }
  52. TargetPanel::TargetPanel(wxWindow* parent, const TargetConfig& initialConfig) :
  53. wxPanel(parent),
  54. myParent(parent),
  55. myStartSDSectorValidator(new wxIntegerValidator<uint32_t>),
  56. mySectorSizeValidator(new wxIntegerValidator<uint16_t>),
  57. myNumSectorValidator(new wxIntegerValidator<uint32_t>),
  58. mySizeValidator(new wxFloatingPointValidator<float>(2))
  59. {
  60. wxFlexGridSizer *fgs = new wxFlexGridSizer(13, 3, 9, 25);
  61. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  62. myEnableCtrl =
  63. new wxCheckBox(
  64. this,
  65. ID_enableCtrl,
  66. wxT("Enable SCSI Target"));
  67. fgs->Add(myEnableCtrl);
  68. // Set a non-visible string to leave room in the column for future messages
  69. fgs->Add(new wxStaticText(this, wxID_ANY, wxT(" ")));
  70. Bind(wxEVT_CHECKBOX, &TargetPanel::onInput<wxCommandEvent>, this, ID_enableCtrl);
  71. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("SCSI ID")));
  72. myScsiIdCtrl =
  73. new wxSpinCtrl
  74. (this,
  75. ID_scsiIdCtrl,
  76. wxEmptyString,
  77. wxDefaultPosition,
  78. wxDefaultSize,
  79. wxSP_WRAP | wxSP_ARROW_KEYS,
  80. 0,
  81. 7,
  82. 0);
  83. fgs->Add(myScsiIdCtrl);
  84. myScsiIdMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  85. fgs->Add(myScsiIdMsg);
  86. Bind(wxEVT_SPINCTRL, &TargetPanel::onInput<wxSpinEvent>, this, ID_scsiIdCtrl);
  87. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Device Type")));
  88. wxString deviceTypes[] = {wxT("Hard Drive"), wxT("Removable"), wxT("CDROM")};
  89. myDeviceTypeCtrl =
  90. new wxChoice(
  91. this,
  92. ID_deviceTypeCtrl,
  93. wxDefaultPosition,
  94. wxDefaultSize,
  95. sizeof(deviceTypes) / sizeof(wxString),
  96. deviceTypes
  97. );
  98. myDeviceTypeCtrl->SetSelection(0);
  99. fgs->Add(myDeviceTypeCtrl);
  100. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  101. Bind(wxEVT_CHOICE, &TargetPanel::onInput<wxCommandEvent>, this, ID_deviceTypeCtrl);
  102. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  103. myParityCtrl =
  104. new wxCheckBox(
  105. this,
  106. ID_parityCtrl,
  107. wxT("Enable Parity"));
  108. fgs->Add(myParityCtrl);
  109. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  110. Bind(wxEVT_CHECKBOX, &TargetPanel::onInput<wxCommandEvent>, this, ID_parityCtrl);
  111. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  112. myUnitAttCtrl =
  113. new wxCheckBox(
  114. this,
  115. ID_unitAttCtrl,
  116. wxT("Enable Unit Attention"));
  117. fgs->Add(myUnitAttCtrl);
  118. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  119. Bind(wxEVT_CHECKBOX, &TargetPanel::onInput<wxCommandEvent>, this, ID_unitAttCtrl);
  120. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("SD card start sector")));
  121. myStartSDSectorCtrl =
  122. new wxTextCtrl(
  123. this,
  124. ID_startSDSectorCtrl,
  125. "0",
  126. wxDefaultPosition,
  127. wxDefaultSize,
  128. 0,
  129. *myStartSDSectorValidator);
  130. myStartSDSectorCtrl->SetToolTip(wxT("Supports multiple SCSI targets "
  131. "on a single memory card. In units of 512-byte sectors."));
  132. fgs->Add(myStartSDSectorCtrl);
  133. myStartSDSectorMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  134. fgs->Add(myStartSDSectorMsg);
  135. Bind(wxEVT_TEXT, &TargetPanel::onInput<wxCommandEvent>, this, ID_startSDSectorCtrl);
  136. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Sector size (bytes)")));
  137. mySectorSizeCtrl =
  138. new wxTextCtrl(
  139. this,
  140. ID_sectorSizeCtrl,
  141. "512",
  142. wxDefaultPosition,
  143. wxDefaultSize,
  144. 0,
  145. *mySectorSizeValidator);
  146. mySectorSizeCtrl->SetToolTip(wxT("Between 64 and 8192. Default of 512 is suitable in most cases."));
  147. fgs->Add(mySectorSizeCtrl);
  148. mySectorSizeMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  149. fgs->Add(mySectorSizeMsg);
  150. Bind(wxEVT_TEXT, &TargetPanel::onSizeInput, this, ID_sectorSizeCtrl);
  151. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Sector count")));
  152. myNumSectorCtrl =
  153. new wxTextCtrl(
  154. this,
  155. ID_numSectorCtrl,
  156. "",
  157. wxDefaultPosition,
  158. wxDefaultSize,
  159. 0,
  160. *myNumSectorValidator);
  161. myNumSectorCtrl->SetToolTip(wxT("Number of sectors (device size)"));
  162. fgs->Add(myNumSectorCtrl);
  163. myNumSectorMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  164. fgs->Add(myNumSectorMsg);
  165. Bind(wxEVT_TEXT, &TargetPanel::onSizeInput, this, ID_numSectorCtrl);
  166. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Device size")));
  167. wxWrapSizer* sizeContainer = new wxWrapSizer();
  168. mySizeCtrl =
  169. new wxTextCtrl(
  170. this,
  171. ID_sizeCtrl,
  172. "",
  173. wxDefaultPosition,
  174. wxDefaultSize,
  175. 0,
  176. *mySizeValidator);
  177. mySizeCtrl->SetToolTip(wxT("Device size"));
  178. sizeContainer->Add(mySizeCtrl);
  179. wxString units[] = {wxT("KB"), wxT("MB"), wxT("GB")};
  180. mySizeUnitCtrl =
  181. new wxChoice(
  182. this,
  183. ID_sizeUnitCtrl,
  184. wxDefaultPosition,
  185. wxDefaultSize,
  186. sizeof(units) / sizeof(wxString),
  187. units
  188. );
  189. sizeContainer->Add(mySizeUnitCtrl);
  190. fgs->Add(sizeContainer);
  191. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  192. Bind(wxEVT_TEXT, &TargetPanel::onSizeInput, this, ID_sizeCtrl);
  193. Bind(wxEVT_CHOICE, &TargetPanel::onSizeInput, this, ID_sizeUnitCtrl);
  194. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Vendor")));
  195. myVendorCtrl =
  196. new wxTextCtrl(
  197. this,
  198. ID_vendorCtrl);
  199. myVendorCtrl->SetMaxLength(8);
  200. myVendorCtrl->SetToolTip(wxT("SCSI Vendor string. eg. ' codesrc'"));
  201. fgs->Add(myVendorCtrl);
  202. myVendorMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  203. fgs->Add(myVendorMsg);
  204. Bind(wxEVT_TEXT, &TargetPanel::onInput<wxCommandEvent>, this, ID_vendorCtrl);
  205. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Product ID")));
  206. myProductCtrl =
  207. new wxTextCtrl(
  208. this,
  209. ID_productCtrl);
  210. myProductCtrl->SetMaxLength(16);
  211. myProductCtrl->SetToolTip(wxT("SCSI Product ID string. eg. 'SCSI2SD'"));
  212. fgs->Add(myProductCtrl);
  213. myProductMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  214. fgs->Add(myProductMsg);
  215. Bind(wxEVT_TEXT, &TargetPanel::onInput<wxCommandEvent>, this, ID_productCtrl);
  216. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Revision")));
  217. myRevisionCtrl =
  218. new wxTextCtrl(
  219. this,
  220. ID_revisionCtrl);
  221. myRevisionCtrl->SetMaxLength(4);
  222. myRevisionCtrl->SetToolTip(wxT("SCSI device revision string. eg. '3.5a'"));
  223. fgs->Add(myRevisionCtrl);
  224. myRevisionMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  225. fgs->Add(myRevisionMsg);
  226. Bind(wxEVT_TEXT, &TargetPanel::onInput<wxCommandEvent>, this, ID_revisionCtrl);
  227. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("Serial number")));
  228. mySerialCtrl =
  229. new wxTextCtrl(
  230. this,
  231. ID_serialCtrl);
  232. mySerialCtrl->SetMaxLength(16);
  233. mySerialCtrl->SetToolTip(wxT("SCSI serial number. eg. '13eab5632a'"));
  234. fgs->Add(mySerialCtrl);
  235. mySerialMsg = new wxStaticText(this, wxID_ANY, wxT(""));
  236. fgs->Add(mySerialMsg);
  237. Bind(wxEVT_TEXT, &TargetPanel::onInput<wxCommandEvent>, this, ID_serialCtrl);
  238. wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
  239. hbox->Add(fgs, 1, wxALL | wxEXPAND, 15);
  240. this->SetSizer(hbox);
  241. Centre();
  242. setConfig(initialConfig);
  243. evaluate();
  244. }
  245. bool
  246. TargetPanel::evaluate()
  247. {
  248. bool valid = true;
  249. std::stringstream conv;
  250. uint32_t startSDsector;
  251. {
  252. conv << myStartSDSectorCtrl->GetValue();
  253. conv >> startSDsector;
  254. }
  255. if (!conv)
  256. // TODO check if it is beyond the current SD card.
  257. {
  258. myStartSDSectorMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Number &gt;= 0</span>"));
  259. valid = false;
  260. }
  261. else
  262. {
  263. myStartSDSectorMsg->SetLabelMarkup("");
  264. }
  265. conv.str(std::string()); conv.clear();
  266. uint16_t sectorSize(CtrlGetValue<uint16_t>(mySectorSizeCtrl).first);
  267. if (sectorSize < 64 || sectorSize > 8192)
  268. {
  269. mySectorSizeMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Must be between 64 and 8192</span>"));
  270. valid = false;
  271. }
  272. else
  273. {
  274. mySectorSizeMsg->SetLabelMarkup("");
  275. }
  276. conv.str(std::string()); conv.clear();
  277. std::pair<uint32_t, bool> numSectors(CtrlGetValue<uint32_t>(myNumSectorCtrl));
  278. if (!numSectors.second ||
  279. numSectors.first == 0 ||
  280. !convertUnitsToSectors().second)
  281. {
  282. myNumSectorMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Invalid size</span>"));
  283. valid = false;
  284. }
  285. else
  286. {
  287. myNumSectorMsg->SetLabelMarkup("");
  288. }
  289. if (!CtrlIsAscii(myVendorCtrl))
  290. {
  291. myVendorMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Invalid characters</span>"));
  292. valid = false;
  293. }
  294. else
  295. {
  296. myVendorMsg->SetLabelMarkup("");
  297. }
  298. if (!CtrlIsAscii(myProductCtrl))
  299. {
  300. myProductMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Invalid characters</span>"));
  301. valid = false;
  302. }
  303. else
  304. {
  305. myProductMsg->SetLabelMarkup("");
  306. }
  307. if (!CtrlIsAscii(myRevisionCtrl))
  308. {
  309. myRevisionMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Invalid characters</span>"));
  310. valid = false;
  311. }
  312. else
  313. {
  314. myRevisionMsg->SetLabelMarkup("");
  315. }
  316. if (!CtrlIsAscii(mySerialCtrl))
  317. {
  318. mySerialMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Invalid characters</span>"));
  319. valid = false;
  320. }
  321. else
  322. {
  323. mySerialMsg->SetLabelMarkup("");
  324. }
  325. bool enabled = myEnableCtrl->IsChecked();
  326. {
  327. myScsiIdCtrl->Enable(enabled);
  328. myDeviceTypeCtrl->Enable(enabled);
  329. myParityCtrl->Enable(enabled);
  330. myUnitAttCtrl->Enable(enabled);
  331. myStartSDSectorCtrl->Enable(enabled);
  332. mySectorSizeCtrl->Enable(enabled);
  333. myNumSectorCtrl->Enable(enabled);
  334. mySizeCtrl->Enable(enabled);
  335. mySizeUnitCtrl->Enable(enabled);
  336. myVendorCtrl->Enable(enabled);
  337. myProductCtrl->Enable(enabled);
  338. myRevisionCtrl->Enable(enabled);
  339. mySerialCtrl->Enable(enabled);
  340. }
  341. return valid || !enabled;
  342. }
  343. template<typename EvtType> void
  344. TargetPanel::onInput(EvtType& event)
  345. {
  346. wxCommandEvent changeEvent(ConfigChangedEvent);
  347. wxPostEvent(myParent, changeEvent);
  348. }
  349. void
  350. TargetPanel::onSizeInput(wxCommandEvent& event)
  351. {
  352. if (event.GetId() == ID_numSectorCtrl)
  353. {
  354. uint32_t numSectors;
  355. std::stringstream conv;
  356. conv << myNumSectorCtrl->GetValue();
  357. conv >> numSectors;
  358. conv.str(""); conv.clear();
  359. if (conv)
  360. {
  361. uint64_t bytes =
  362. uint64_t(numSectors) *
  363. CtrlGetValue<uint16_t>(mySectorSizeCtrl).first;
  364. if (bytes >= 1024 * 1024 * 1024)
  365. {
  366. conv << (bytes / (1024.0 * 1024 * 1024));
  367. mySizeUnitCtrl->SetSelection(UNIT_GB);
  368. }
  369. else if (bytes >= 1024 * 1024)
  370. {
  371. conv << (bytes / (1024.0 * 1024));
  372. mySizeUnitCtrl->SetSelection(UNIT_MB);
  373. }
  374. else
  375. {
  376. conv << (bytes / 1024.0);
  377. mySizeUnitCtrl->SetSelection(UNIT_KB);
  378. }
  379. mySizeCtrl->ChangeValue(conv.str());
  380. }
  381. }
  382. else
  383. {
  384. std::stringstream ss;
  385. ss << convertUnitsToSectors().first;
  386. myNumSectorCtrl->ChangeValue(ss.str());
  387. }
  388. onInput(event); // propagate
  389. }
  390. std::pair<uint32_t, bool>
  391. TargetPanel::convertUnitsToSectors() const
  392. {
  393. bool valid = true;
  394. uint64_t multiplier(0);
  395. switch (mySizeUnitCtrl->GetSelection())
  396. {
  397. case UNIT_KB: multiplier = 1024; break;
  398. case UNIT_MB: multiplier = 1024 * 1024; break;
  399. case UNIT_GB: multiplier = 1024 * 1024 * 1024; break;
  400. default: valid = false;
  401. }
  402. double size;
  403. std::stringstream conv;
  404. conv << mySizeCtrl->GetValue();
  405. conv >> size;
  406. valid = valid && conv;
  407. uint16_t sectorSize = CtrlGetValue<uint16_t>(mySectorSizeCtrl).first;
  408. uint64_t sectors = ceil(multiplier * size / sectorSize);
  409. if (sectors > std::numeric_limits<uint32_t>::max())
  410. {
  411. sectors = std::numeric_limits<uint32_t>::max();
  412. valid = false;
  413. }
  414. return std::make_pair(static_cast<uint32_t>(sectors), valid);
  415. }
  416. TargetConfig
  417. TargetPanel::getConfig() const
  418. {
  419. TargetConfig config;
  420. // Try and keep unknown/unused fields as-is to support newer firmware
  421. // versions.
  422. memcpy(&config, &myConfig, sizeof(config));
  423. bool valid = true;
  424. auto scsiId = CtrlGetValue<uint8_t>(myScsiIdCtrl);
  425. config.scsiId = scsiId.first & CONFIG_TARGET_ID_BITS;
  426. valid = valid && scsiId.second;
  427. if (myEnableCtrl->IsChecked())
  428. {
  429. config.scsiId = config.scsiId | CONFIG_TARGET_ENABLED;
  430. }
  431. config.deviceType = myDeviceTypeCtrl->GetSelection();
  432. config.flags =
  433. (myParityCtrl->IsChecked() ? CONFIG_ENABLE_PARITY : 0) |
  434. (myUnitAttCtrl->IsChecked() ? CONFIG_ENABLE_UNIT_ATTENTION : 0);
  435. auto startSDSector = CtrlGetValue<uint32_t>(myStartSDSectorCtrl);
  436. config.sdSectorStart = startSDSector.first;
  437. valid = valid && startSDSector.second;
  438. auto numSectors = CtrlGetValue<uint32_t>(myNumSectorCtrl);
  439. config.scsiSectors = numSectors.first;
  440. valid = valid && numSectors.second;
  441. auto sectorSize = CtrlGetValue<uint16_t>(mySectorSizeCtrl);
  442. config.bytesPerSector = sectorSize.first;
  443. valid = valid && sectorSize.second;
  444. CtrlGetFixedString(myVendorCtrl, config.vendor, sizeof(config.vendor));
  445. CtrlGetFixedString(myProductCtrl, config.prodId, sizeof(config.prodId));
  446. CtrlGetFixedString(myRevisionCtrl, config.revision, sizeof(config.revision));
  447. CtrlGetFixedString(mySerialCtrl, config.serial, sizeof(config.serial));
  448. return config;
  449. }
  450. void
  451. TargetPanel::setConfig(const TargetConfig& config)
  452. {
  453. memcpy(&myConfig, &config, sizeof(config));
  454. myScsiIdCtrl->SetValue(config.scsiId & CONFIG_TARGET_ID_BITS);
  455. myEnableCtrl->SetValue(config.scsiId & CONFIG_TARGET_ENABLED);
  456. myDeviceTypeCtrl->SetSelection(config.deviceType);
  457. myParityCtrl->SetValue(config.flags & CONFIG_ENABLE_PARITY);
  458. myUnitAttCtrl->SetValue(config.flags & CONFIG_ENABLE_UNIT_ATTENTION);
  459. {
  460. std::stringstream ss; ss << config.sdSectorStart;
  461. myStartSDSectorCtrl->ChangeValue(ss.str());
  462. }
  463. {
  464. std::stringstream ss; ss << config.scsiSectors;
  465. myNumSectorCtrl->ChangeValue(ss.str());
  466. }
  467. {
  468. std::stringstream ss; ss << config.bytesPerSector;
  469. mySectorSizeCtrl->ChangeValue(ss.str());
  470. }
  471. myVendorCtrl->ChangeValue(std::string(config.vendor, sizeof(config.vendor)));
  472. myProductCtrl->ChangeValue(std::string(config.prodId, sizeof(config.prodId)));
  473. myRevisionCtrl->ChangeValue(std::string(config.revision, sizeof(config.revision)));
  474. mySerialCtrl->ChangeValue(std::string(config.serial, sizeof(config.serial)));
  475. // Set the size fields based on sector size, and evaluate inputs.
  476. wxCommandEvent fakeEvent(wxEVT_NULL, ID_numSectorCtrl);
  477. onSizeInput(fakeEvent);
  478. }
  479. bool
  480. TargetPanel::isEnabled() const
  481. {
  482. return myEnableCtrl->IsChecked();
  483. }
  484. uint8_t
  485. TargetPanel::getSCSIId() const
  486. {
  487. return CtrlGetValue<uint8_t>(myScsiIdCtrl).first & CONFIG_TARGET_ID_BITS;
  488. }
  489. std::pair<uint32_t, uint64_t>
  490. TargetPanel::getSDSectorRange() const
  491. {
  492. std::pair<uint32_t, uint64_t> result;
  493. result.first = CtrlGetValue<uint32_t>(myStartSDSectorCtrl).first;
  494. uint32_t numSCSISectors = CtrlGetValue<uint32_t>(myNumSectorCtrl).first;
  495. uint16_t scsiSectorSize = CtrlGetValue<uint16_t>(mySectorSizeCtrl).first;
  496. const int sdSector = 512; // Always 512 for SDHC/SDXC
  497. result.second = result.first +
  498. (
  499. ((uint64_t(numSCSISectors) * scsiSectorSize) + (sdSector - 1))
  500. / sdSector
  501. );
  502. return result;
  503. }
  504. void
  505. TargetPanel::setDuplicateID(bool duplicate)
  506. {
  507. if (duplicate)
  508. {
  509. myScsiIdMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Duplicate ID</span>"));
  510. }
  511. else
  512. {
  513. myScsiIdMsg->SetLabelMarkup("");
  514. }
  515. }
  516. void
  517. TargetPanel::setSDSectorOverlap(bool overlap)
  518. {
  519. if (overlap)
  520. {
  521. myStartSDSectorMsg->SetLabelMarkup(wxT("<span foreground='red' weight='bold'>Overlapping data</span>"));
  522. }
  523. else
  524. {
  525. myStartSDSectorMsg->SetLabelMarkup("");
  526. }
  527. }