1
0

GeocacheDisplay.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2012
  6. All rights reserved.
  7. */
  8. #pragma once
  9. #include "stdafx.h"
  10. #include "GeocacheDisplay.h"
  11. #include "antmessage.h"
  12. using namespace System::Runtime::InteropServices;
  13. static ULONG ulMessageCount = 0;
  14. static BOOL bFoundGeocache; // GPS 'Found' the Geocache
  15. static BOOL bAllPagesRecvd; // GPS 'Received' all Geocache Pages
  16. static BOOL bProgramming; // GPS 'Programming' Geocache
  17. static BOOL bSendAuthReq;
  18. static BOOL bUpdateLoggedVisit;
  19. static UCHAR ucNumPagesRecvd; // GPS Number of Pages Received
  20. static time_t tmtEpoch;
  21. static struct tm tmEpoch;
  22. /**************************************************************************
  23. * GeocacheDisplay::InitializeSim
  24. *
  25. * Initialize the simulator variables
  26. *
  27. * returns: N/A
  28. *
  29. **************************************************************************/
  30. void GeocacheDisplay::InitializeSim()
  31. {
  32. ulTimerInterval = 250; // in ms - simulates the sensor sending the most relevant information every message period
  33. dbDispAcumTime = 0;
  34. dbDispAcumDist = 0;
  35. usLastEventTime = 0;
  36. ulTotalTime = 0;
  37. bFoundGeocache = FALSE;
  38. bAllPagesRecvd = FALSE;
  39. GeocacheData->InitDisplay();
  40. this->buttonProgram->Enabled = FALSE;
  41. this->buttonErase->Enabled = FALSE;
  42. ulMessageCount = 0;
  43. ucNumPagesRecvd = 0;
  44. GeocacheData->ucTotalPages = 0;
  45. GeocacheData->ucCurrProgPage = 0;
  46. GeocacheData->ucProgTotalPages = 0;
  47. GeocacheData->InitDisplay();
  48. UpdateDisplay();
  49. commonData->eTimeResolution = CommonData::TimeResolution::TWO;
  50. commonData->ulOpTime = ulTotalTime;
  51. tmEpoch.tm_year = 1989 - 1900;
  52. tmEpoch.tm_mon = 12 - 1;
  53. tmEpoch.tm_mday = 31;
  54. tmEpoch.tm_hour = 00;
  55. tmEpoch.tm_min = 00;
  56. tmEpoch.tm_sec = 00;
  57. tmtEpoch = mktime(&tmEpoch);
  58. }
  59. /**************************************************************************
  60. * GeocacheDisplay::ANT_eventNotification
  61. *
  62. * Process ANT channel event
  63. *
  64. * ucEventCode_: code of ANT channel event
  65. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  66. * or a pointer to the transmit buffer in the case of an EVENT_TX
  67. *
  68. * returns: N/A
  69. *
  70. **************************************************************************/
  71. void GeocacheDisplay::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
  72. {
  73. switch(ucEventCode_)
  74. {
  75. case EVENT_TX:
  76. // HandleTransmit((UCHAR*) pucEventBuffer_);
  77. break;
  78. case EVENT_RX_BROADCAST:
  79. case EVENT_RX_ACKNOWLEDGED:
  80. case EVENT_RX_BURST_PACKET: // intentional fall thru
  81. HandleReceive((UCHAR*) pucEventBuffer_);
  82. break;
  83. case EVENT_TRANSFER_TX_COMPLETED:
  84. UpdateAckStatus((UCHAR*) pucEventBuffer_);
  85. break;
  86. case EVENT_ACK_TIMEOUT:
  87. case EVENT_TRANSFER_TX_FAILED: // intentional fall through
  88. UpdateDisplayAckStatus(GeocacheData->ACK_FAIL);
  89. break;
  90. case MESG_CLOSE_CHANNEL_ID:
  91. InitializeSim();
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. /**************************************************************************
  98. * GeocacheDisplay::HandleReceive
  99. *
  100. * Handle incoming (Geocache) Broadcast Packets
  101. *
  102. * pucRxBuffer_: pointer to the receive buffer
  103. *
  104. * returns: N/A
  105. *
  106. **************************************************************************/
  107. void GeocacheDisplay::HandleReceive(UCHAR* pucRxBuffer_)
  108. {
  109. ulMessageCount++;
  110. // Check to see if we are Programming the Geocache ?
  111. // ... ignore incoming requests if we are !!!
  112. if (!bProgramming)
  113. {
  114. UCHAR ucPage = pucRxBuffer_[0];
  115. // Mark Page Read ...
  116. if (ucPage <= commonData->PAGE82)
  117. GeocacheData->bPageRead[ucPage] = TRUE;
  118. // Check if this is Common Pages or Geocache Pages
  119. if (ucPage < commonData->START_COMMON_PAGE)
  120. GeocacheData->Decode(pucRxBuffer_);
  121. else
  122. commonData->Decode(pucRxBuffer_);
  123. UpdateDisplay();
  124. // If 'just' discovered the Geocache - Send PAGE_1 (PIN) Request
  125. if (!bFoundGeocache)
  126. {
  127. pucRxBuffer_[0] = 0x46; // Page Request
  128. pucRxBuffer_[1] = 0xFF;
  129. pucRxBuffer_[2] = 0xFF;
  130. pucRxBuffer_[3] = 0xFF;
  131. pucRxBuffer_[4] = 0xFF;
  132. pucRxBuffer_[5] = 0x01; // (Un)Acknowledged Response / 1 Time
  133. pucRxBuffer_[6] = 0x01; // PAGE 1
  134. pucRxBuffer_[7] = 0x01; // Data Page Request
  135. requestBcastMsg(pucRxBuffer_);
  136. bFoundGeocache = TRUE;
  137. }
  138. // Wait for Page Rotation Data before explicitly Requesting ...
  139. else if (!bAllPagesRecvd && (ulMessageCount > GeocacheData->MESG_WAIT_REQ))
  140. {
  141. pucRxBuffer_[0] = 0x46; // Page Request
  142. pucRxBuffer_[1] = 0xFF;
  143. pucRxBuffer_[2] = 0xFF;
  144. pucRxBuffer_[3] = 0xFF;
  145. pucRxBuffer_[4] = 0xFF;
  146. pucRxBuffer_[5] = 0x01; // (Un)Acknowledged Response / 1 Time
  147. pucRxBuffer_[6] = NextUnReadPage();
  148. pucRxBuffer_[7] = 0x01; // Data Page Request
  149. requestBcastMsg(pucRxBuffer_);
  150. }
  151. else if (bSendAuthReq)
  152. {
  153. GeocacheData->GenerateAuthRequestPage(pucRxBuffer_);
  154. requestAckMsg(pucRxBuffer_);
  155. bSendAuthReq = FALSE;
  156. if (GeocacheData->bLoggedVisitsEnabled) bUpdateLoggedVisit = TRUE;
  157. }
  158. else if (bUpdateLoggedVisit)
  159. {
  160. UpdateLoggedVisit();
  161. GeocacheData->UpdateLoggedVisitPage();
  162. GeocacheData->GetPageData(GeocacheData->ucLoggedVisitPage, pucRxBuffer_);
  163. requestAckMsg(pucRxBuffer_);
  164. bUpdateLoggedVisit = FALSE;
  165. }
  166. }
  167. else
  168. {
  169. // Programming Pages !!!
  170. GeocacheData->GetPageData(GeocacheData->ucCurrProgPage, pucRxBuffer_);
  171. requestAckMsg(pucRxBuffer_);
  172. UpdateDisplay();
  173. }
  174. }
  175. /**************************************************************************
  176. * GeocacheDisplay::UpdateAckStatus
  177. *
  178. * Updates Page Programming based on ACK status of the tx message
  179. *
  180. * UCHAR status_: gives the success or fail status of the tx message
  181. *
  182. * returns: N/A
  183. *
  184. **************************************************************************/
  185. void GeocacheDisplay::UpdateAckStatus(UCHAR* pucRxBuffer_)
  186. {
  187. if (bProgramming)
  188. {
  189. // Mark Page Read ...
  190. if (pucRxBuffer_[0] < GeocacheData->PAGE_32)
  191. GeocacheData->bPageProg[pucRxBuffer_[0]] = TRUE;
  192. if (GeocacheData->ucCurrProgPage >= GeocacheData->ucProgTotalPages)
  193. {
  194. bProgramming = FALSE;
  195. this->labelProgStatus->Text = "Done Programming ...";
  196. this->labelProgStatus->ForeColor = System::Drawing::Color::Black;
  197. }
  198. else
  199. {
  200. GeocacheData->ucCurrProgPage++;
  201. }
  202. }
  203. }
  204. /**************************************************************************
  205. * GeocacheSensor::UpdateDisplayAckStatus
  206. *
  207. * Adjusts the GUI depending on the ACK status of the tx message
  208. *
  209. * UCHAR status_: gives the success or fail status of the tx message
  210. *
  211. * returns: N/A
  212. *
  213. **************************************************************************/
  214. void GeocacheDisplay::UpdateDisplayAckStatus(UCHAR status_)
  215. {
  216. // Nothing to do ...
  217. }
  218. /**************************************************************************
  219. * Geocache::Authentication
  220. *
  221. * Generate Authentication Token from GPS Serial # and Nonce
  222. *
  223. *
  224. * pucRxBuffer_: pointer to the buffer containing the received data
  225. *
  226. * returns: N/A
  227. *
  228. **************************************************************************/
  229. using namespace System::Security::Cryptography;
  230. void GeocacheDisplay::Authentication(UCHAR* pucRxBuffer_)
  231. {
  232. GeocacheData->GenerateAuthRequestPage(pucRxBuffer_);
  233. requestBcastMsg(pucRxBuffer_);
  234. }
  235. /**************************************************************************
  236. * GeocacheDisplay::HandleTransmit
  237. *
  238. * Encode data generated by simulator for transmission
  239. *
  240. * ucPageNum_: The page number to be transmitted
  241. * pucTxBuffer_: pointer to the transmit buffer
  242. *
  243. * returns: N/A
  244. *
  245. **************************************************************************/
  246. void GeocacheDisplay::HandleTransmit(UCHAR* pucTxBuffer_)
  247. {
  248. }
  249. /**************************************************************************
  250. * Geocache::NextUnReadPage
  251. *
  252. * Returns the Page # of the next unread Page
  253. *
  254. * Exceptions are thrown when dealing with invalid data
  255. *
  256. * returns: N/A
  257. *
  258. **************************************************************************/
  259. UCHAR GeocacheDisplay::NextUnReadPage(void)
  260. {
  261. ucNumPagesRecvd = 0;
  262. // Check Geocache Pages
  263. for (UCHAR ucPage=0; ucPage<GeocacheData->ucTotalPages; ucPage++)
  264. {
  265. if (!GeocacheData->bPageRead[ucPage])
  266. return (ucPage);
  267. else
  268. ucNumPagesRecvd++;
  269. }
  270. // Common Data Pages
  271. if (!GeocacheData->bPageRead[commonData->PAGE80]) return (commonData->PAGE80);
  272. if (!GeocacheData->bPageRead[commonData->PAGE81]) return (commonData->PAGE81);
  273. if (!GeocacheData->bPageRead[commonData->PAGE82]) return (commonData->PAGE82);
  274. bAllPagesRecvd = TRUE;
  275. bSendAuthReq = TRUE;
  276. this->buttonProgram->Enabled = TRUE;
  277. this->buttonErase->Enabled = TRUE;
  278. return (0);
  279. }
  280. /**************************************************************************
  281. * GeocacheDisplay::UpdateLoggedVisit
  282. *
  283. * Update the Logged Visits Page (current Time)
  284. *
  285. * returns: N/A
  286. *
  287. **************************************************************************/
  288. void GeocacheDisplay::UpdateLoggedVisit(void)
  289. {
  290. time_t tmtNow;
  291. //struct tm * ptmNow;
  292. time(&tmtNow);
  293. // ptmNow = localtime(&tmtNow);
  294. GeocacheData->ulLastVisitTimestamp = (ULONG) difftime(tmtNow, tmtEpoch);
  295. GeocacheData->usNumVisits++;
  296. }
  297. /**************************************************************************
  298. * GeocacheDisplay::buttonForget_Click
  299. *
  300. * Forget *this* Geocache
  301. *
  302. * returns: N/A
  303. *
  304. **************************************************************************/
  305. void GeocacheDisplay::buttonForget_Click(System::Object^ sender, System::EventArgs^ e)
  306. {
  307. bFoundGeocache = FALSE;
  308. bAllPagesRecvd = FALSE;
  309. this->buttonProgram->Enabled = FALSE;
  310. this->buttonErase->Enabled = FALSE;
  311. ulMessageCount = 0;
  312. ucNumPagesRecvd = 0;
  313. GeocacheData->ucTotalPages = 0;
  314. GeocacheData->ucCurrProgPage = 0;
  315. GeocacheData->ucProgTotalPages = 0;
  316. GeocacheData->InitDisplay();
  317. UpdateDisplay();
  318. }
  319. /**************************************************************************
  320. * GeocacheDisplay::buttonErase_Click
  321. *
  322. * Erase the Geocache
  323. *
  324. * returns: N/A
  325. *
  326. **************************************************************************/
  327. void GeocacheDisplay::buttonErase_Click(System::Object^ sender, System::EventArgs^ e)
  328. {
  329. ucNumPagesRecvd = 0;
  330. GeocacheData->InitDisplay();
  331. GeocacheData->GenerateProgPages();
  332. GeocacheData->ucProgTotalPages = 32; // Initialize ALL Pages to DEFAULTs !!!
  333. GeocacheData->ucCurrProgPage = GeocacheData->PAGE_0; // Start Programming with Page 0
  334. bProgramming = TRUE;
  335. UpdateDisplay();
  336. }
  337. /**************************************************************************
  338. * GeocacheDisplay::buttonProgram_Click
  339. *
  340. * Update the Programmable Pages (per UI Values)
  341. *
  342. * returns: N/A
  343. *
  344. **************************************************************************/
  345. void GeocacheDisplay::buttonProgram_Click(System::Object^ sender, System::EventArgs^ e)
  346. {
  347. // Check PIN
  348. if (GeocacheData->ulPIN == GeocacheData->DEFAULT_PIN) // Default/Unprogrammed
  349. {
  350. bProgramming = TRUE;
  351. this->labelProgStatus->Text = "Programming...";
  352. this->labelProgStatus->ForeColor = System::Drawing::Color::Green;
  353. }
  354. else if ((this->textBoxPIN->Text->Length > 0) && (System::Convert::ToInt32(this->textBoxPIN->Text) == GeocacheData->ulPIN))
  355. {
  356. bProgramming = TRUE;
  357. this->labelProgStatus->Text = "Programming ...";
  358. this->labelProgStatus->ForeColor = System::Drawing::Color::Green;
  359. }
  360. else
  361. {
  362. bProgramming = FALSE;
  363. this->labelProgStatus->Text = "Incorrect PIN";
  364. this->labelProgStatus->ForeColor = System::Drawing::Color::Red;
  365. return;
  366. }
  367. GeocacheData->bLatitudeEnabled = FALSE;
  368. GeocacheData->bLongitudeEnabled = FALSE;
  369. GeocacheData->bHintEnabled = FALSE;
  370. GeocacheData->bLoggedVisitsEnabled = FALSE;
  371. // ID
  372. if (this->checkBoxID->Checked)
  373. {
  374. char* stringPointer = (char*) Marshal::StringToHGlobalAnsi(this->textBoxID->Text->ToUpper()).ToPointer();
  375. for (int i=0; i<this->textBoxID->Text->Length; i++)
  376. GeocacheData->cID[i] = stringPointer[i] - 0x20;
  377. for (int i=this->textBoxID->Text->Length; i<9; i++)
  378. GeocacheData->cID[i] = 0x00;
  379. // Always free the unmanaged string.
  380. Marshal::FreeHGlobal(IntPtr(stringPointer));
  381. }
  382. // PIN
  383. if (this->checkBoxPIN->Checked)
  384. {
  385. GeocacheData->ulPIN = System::Convert::ToUInt32(this->textBoxPIN->Text);
  386. }
  387. if (this->checkBoxLatitude->Checked)
  388. {
  389. GeocacheData->bLatitudeEnabled = TRUE;
  390. GeocacheData->slLatitude_SC = System::Convert::ToInt32(double (this->numericUpDownLatitude->Value) * GeocacheData->SEMI_CIRCLE_CONVERSION);
  391. }
  392. if (this->checkBoxLongitude->Checked)
  393. {
  394. GeocacheData->bLongitudeEnabled = TRUE;
  395. GeocacheData->slLongitude_SC = System::Convert::ToInt32(double (this->numericUpDownLongitude->Value) * GeocacheData->SEMI_CIRCLE_CONVERSION);
  396. }
  397. if (this->checkBoxLoggedVisits->Checked)
  398. {
  399. time_t tmtLastVisit;
  400. struct tm tmLastVisit;
  401. tmLastVisit.tm_year = System::Convert::ToUInt16(this->numericUpDownYear->Value) - 1900;
  402. tmLastVisit.tm_mon = System::Convert::ToUInt16(this->numericUpDownMonth->Value) - 1;
  403. tmLastVisit.tm_mday = System::Convert::ToUInt16(this->numericUpDownDay->Value);
  404. tmLastVisit.tm_hour = System::Convert::ToUInt16(this->numericUpDownHours->Value);
  405. tmLastVisit.tm_min = System::Convert::ToUInt16(this->numericUpDownMinutes->Value);
  406. tmLastVisit.tm_sec = System::Convert::ToUInt16(this->numericUpDownSeconds->Value);
  407. tmtLastVisit = mktime(&tmLastVisit);
  408. if (tmLastVisit.tm_isdst > 0) // Daylight Savings ?
  409. GeocacheData->ulLastVisitTimestamp = (ULONG) difftime(tmtLastVisit, tmtEpoch) - 3600;
  410. else
  411. GeocacheData->ulLastVisitTimestamp = (ULONG) difftime(tmtLastVisit, tmtEpoch);
  412. GeocacheData->bLoggedVisitsEnabled = TRUE;
  413. GeocacheData->usNumVisits = System::Convert::ToUInt16(this->numericUpDownNumVisits->Value);
  414. }
  415. if (this->checkBoxHint->Checked)
  416. {
  417. char* stringPointer = (char*) Marshal::StringToHGlobalAnsi(this->textBoxHint->Text).ToPointer();
  418. for (int i=0; i<this->textBoxHint->Text->Length; i++)
  419. GeocacheData->cHint[i] = stringPointer[i];
  420. GeocacheData->ucNumHintPages = (this->textBoxHint->Text->Length/GeocacheData->HINT_CHARS_PER_PAGE) + 1;
  421. GeocacheData->bHintEnabled = TRUE;
  422. }
  423. UCHAR ucPriorTotalPages = GeocacheData->ucTotalPages;
  424. GeocacheData->GenerateProgPages();
  425. GeocacheData->ucProgTotalPages = (ucPriorTotalPages > GeocacheData->ucTotalPages) ? ucPriorTotalPages : GeocacheData->ucTotalPages;
  426. GeocacheData->ucCurrProgPage = GeocacheData->PAGE_0; // Start Programming with Page 0
  427. }
  428. /**************************************************************************
  429. * GeocacheDisplay::Update Display
  430. *
  431. * Update the GUI with all the changes
  432. *
  433. * returns: N/A
  434. *
  435. **************************************************************************/
  436. void GeocacheDisplay::UpdateDisplay()
  437. {
  438. // ID
  439. System::Text::StringBuilder^ builder = gcnew System::Text::StringBuilder();
  440. for(int i=0; i<GeocacheData->cID->Length; i++) builder->Append((Char)(GeocacheData->cID[i]+0x20));
  441. this->labelGCdID->Text = builder->ToString();
  442. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  443. {
  444. this->textBoxID->Text = builder->ToString();
  445. this->labelID->Text = builder->ToString();
  446. }
  447. // PIN
  448. this->labelPIN->Text = GeocacheData->ulPIN.ToString();
  449. this->labelGCdPIN->Text = GeocacheData->ulPIN.ToString();
  450. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  451. this->textBoxPIN->Text = GeocacheData->ulPIN.ToString();
  452. // Total Pages
  453. this->labelGCdTotNumPages->Text = GeocacheData->ucTotalPages.ToString();
  454. this->labelGCdPagesRecvd->Text = ucNumPagesRecvd.ToString();
  455. // Total Prog Pages
  456. this->labelProgTotalPages->Text = GeocacheData->ucProgTotalPages.ToString();
  457. this->labelCurrProgPage->Text = GeocacheData->ucCurrProgPage.ToString();
  458. // Lat/Lon Pages
  459. if (GeocacheData->bLatitudeEnabled)
  460. {
  461. this->labelLat->Text = ((double)GeocacheData->slLatitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString("N2");
  462. this->labelGCdLat->Text = ((double)GeocacheData->slLatitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString("N2");
  463. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  464. this->numericUpDownLatitude->Text = ((double)GeocacheData->slLatitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString();
  465. }
  466. else
  467. {
  468. this->labelLat->Text = "---";
  469. this->labelGCdLat->Text = "---";
  470. }
  471. if (GeocacheData->bLongitudeEnabled)
  472. {
  473. this->labelLon->Text = ((double)GeocacheData->slLongitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString("N2");
  474. this->labelGCdLon->Text = ((double)GeocacheData->slLongitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString("N2");
  475. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  476. this->numericUpDownLongitude->Text = ((double)GeocacheData->slLongitude_SC / GeocacheData->SEMI_CIRCLE_CONVERSION).ToString();
  477. }
  478. else
  479. {
  480. this->labelLon->Text = "---";
  481. this->labelGCdLon->Text = "---";
  482. }
  483. // Hint Page(s)
  484. if (GeocacheData->bHintEnabled)
  485. {
  486. System::Text::StringBuilder^ builder = gcnew System::Text::StringBuilder();
  487. for(int i=0; i<GeocacheData->cHint->Length; i++) builder->Append((Char)GeocacheData->cHint[i]);
  488. this->labelHint->Text = builder->ToString();
  489. this->labelGCdHint->Text = builder->ToString();
  490. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  491. this->textBoxHint->Text = builder->ToString();
  492. }
  493. else
  494. {
  495. this->labelHint->Text = "---";
  496. this->labelGCdHint->Text = "---";
  497. }
  498. // Logged Visits Page
  499. if (GeocacheData->bLoggedVisitsEnabled && (GeocacheData->ulLastVisitTimestamp > 0))
  500. {
  501. this->labelNumVisits->Text = GeocacheData->usNumVisits.ToString();
  502. this->labelGCdNumVisits->Text = GeocacheData->usNumVisits.ToString();
  503. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  504. this->numericUpDownNumVisits->Value = GeocacheData->usNumVisits;
  505. time_t tmtLastVisit;
  506. struct tm * tmLastVisit;
  507. tmtLastVisit = ((time_t)GeocacheData->ulLastVisitTimestamp + tmtEpoch);
  508. #pragma warning (disable : 4996) //This is used to quiet the compiler from an invalid warning
  509. tmLastVisit = localtime(&tmtLastVisit);
  510. if (this->tabControl1->SelectedIndex != 3) // Don't update if Programming Tab Selected
  511. {
  512. this->numericUpDownYear->Value = tmLastVisit->tm_year + 1900;
  513. this->numericUpDownMonth->Value = tmLastVisit->tm_mon + 1;
  514. this->numericUpDownDay->Value = tmLastVisit->tm_mday;
  515. this->numericUpDownHours->Value = tmLastVisit->tm_hour;
  516. this->numericUpDownMinutes->Value = tmLastVisit->tm_min;
  517. this->numericUpDownSeconds->Value = tmLastVisit->tm_sec;
  518. }
  519. System::Text::StringBuilder^ builder = gcnew System::Text::StringBuilder();
  520. for(int i=0; i<26; i++) builder->Append((Char)((asctime(&tmLastVisit[0]))[i]));
  521. this->labelTimestamp->Text = builder->ToString();
  522. this->labelGCdTimestamp->Text = builder->ToString();
  523. }
  524. else
  525. {
  526. this->labelNumVisits->Text = "---";
  527. this->labelTimestamp->Text = "---";
  528. this->labelGCdNumVisits->Text = "---";
  529. this->labelGCdTimestamp->Text = "---";
  530. }
  531. // Authentication Token
  532. UInt64 ui64AuthToken = ((UInt64)GeocacheData->ucAuthToken[0]) +
  533. ((UInt64)GeocacheData->ucAuthToken[1] << 8) +
  534. ((UInt64)GeocacheData->ucAuthToken[2] << 16) +
  535. ((UInt64)GeocacheData->ucAuthToken[3] << 24) +
  536. ((UInt64)GeocacheData->ucAuthToken[4] << 32) +
  537. ((UInt64)GeocacheData->ucAuthToken[5] << 40) +
  538. ((UInt64)GeocacheData->ucAuthToken[6] << 48);
  539. this->labelAuthToken->Text = ui64AuthToken.ToString("X2");
  540. this->labelAuthSerialNum->Text = GeocacheData->ulSerialNum.ToString();
  541. this->labelAuthNonce->Text = GeocacheData->usNonce.ToString();
  542. // update the values for the HW common data page
  543. if (commonData->usMfgID != 0)
  544. {
  545. this->label_Glb_ManfIDDisplay->Text = commonData->usMfgID.ToString();
  546. this->label_Glb_HardwareVerDisplay->Text = commonData->ucHwVersion.ToString();
  547. this->label_Glb_ModelNumDisplay->Text = commonData->usModelNum.ToString();
  548. }
  549. // update the values for the SW common data page
  550. if (commonData->ulSerialNum != 0)
  551. {
  552. if(commonData->ulSerialNum == 0xFFFFFFFF)
  553. this->label_Glb_SerialNumDisplay->Text = "N/A";
  554. else
  555. this->label_Glb_SerialNumDisplay->Text = commonData->ulSerialNum.ToString();
  556. this->label_Glb_SoftwareVerDisplay->Text = commonData->ucSwVersion.ToString();
  557. }
  558. // update the values for the battery common data page
  559. if (commonData->ulOpTime != 0)
  560. {
  561. if(commonData->IsBatteryVoltageInvalid(commonData->usBatVoltage256)) // Battery voltage
  562. this->labelBattVolt->Text = "Invalid";
  563. else
  564. this->labelBattVolt->Text = System::Math::Round((double)commonData->usBatVoltage256/256,4).ToString("N2");
  565. if (commonData->eTimeResolution == CommonData::TimeResolution::SIXTEEN)
  566. this->labelTimeRes->Text = "16";
  567. else
  568. this->labelTimeRes->Text = "2";
  569. // now that we know the time resolution we can display the run time
  570. this->labelOpTime->Text = (commonData->ulOpTime * (UCHAR) commonData->eTimeResolution).ToString();
  571. switch (commonData->eBatStatus)
  572. {
  573. case CommonData::BatStatus::CRITICAL:
  574. this->labelBattStatus->Text = "Critical";
  575. break;
  576. case CommonData::BatStatus::GOOD:
  577. this->labelBattStatus->Text = "Good";
  578. break;
  579. case CommonData::BatStatus::INVALID:
  580. this->labelBattStatus->Text = "Invalid";
  581. break;
  582. case CommonData::BatStatus::LOW:
  583. this->labelBattStatus->Text = "Low";
  584. break;
  585. case CommonData::BatStatus::NEW:
  586. this->labelBattStatus->Text = "New";
  587. break;
  588. case CommonData::BatStatus::OK:
  589. this->labelBattStatus->Text = "Ok";
  590. break;
  591. default:
  592. break;
  593. }
  594. }
  595. }
  596. /**************************************************************************
  597. * GeocacheDisplay::onTimerTock
  598. *
  599. * Simulates a sensor event, updating simulator data based on this event
  600. * Modifications to the timer interval are applied immediately after this
  601. * at ANTChannel
  602. *
  603. * usEventTime_: current time (ms)
  604. *
  605. * returns: N/A
  606. *
  607. **************************************************************************/
  608. void GeocacheDisplay::onTimerTock(USHORT eventTime)
  609. {
  610. UpdateDisplay();
  611. }
  612. /**************************************************************************
  613. * GeocacheDisplay::numericUpDownLongitude_ValueChanged
  614. *
  615. * Adjusts the current longitude via the GUI
  616. *
  617. * returns: N/A
  618. *
  619. **************************************************************************/
  620. void GeocacheDisplay::numericUpDownLongitude_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  621. {
  622. // GeocacheData->slLongitude_SC = System::Convert::ToInt32(double (this->numericUpDownLongitude->Value) * GeocacheData->SEMI_CIRCLE_CONVERSION);
  623. }
  624. /**************************************************************************
  625. * GeocacheDisplay::numericUpDownLatitude_ValueChanged
  626. *
  627. * Adjusts the current latitude via the GUI
  628. *
  629. * returns: N/A
  630. *
  631. **************************************************************************/
  632. void GeocacheDisplay::numericUpDownLatitude_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  633. {
  634. // GeocacheData->slLatitude_SC = System::Convert::ToInt32(double (this->numericUpDownLatitude->Value) * GeocacheData->SEMI_CIRCLE_CONVERSION);
  635. }
  636. /**************************************************************************
  637. * GeocacheDisplay::checkBoxID_CheckedChanged
  638. *
  639. * Enables and disables the ID Text Box
  640. *
  641. * returns: N/A
  642. *
  643. **************************************************************************/
  644. void GeocacheDisplay::checkBoxID_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  645. {
  646. if (this->checkBoxID->Checked == TRUE)
  647. {
  648. this->textBoxID->Enabled = TRUE;
  649. }
  650. else
  651. {
  652. this->textBoxID->Enabled = FALSE;
  653. }
  654. }
  655. // Boolean flag used to determine when a character other than a number is entered.
  656. bool nonNumberEntered;
  657. /**************************************************************************
  658. * GeocacheDisplay:textBoxID_KeyDown
  659. *
  660. * Handle the KeyDown event to determine the type of character entered into the control.
  661. *
  662. * returns: N/A
  663. *
  664. **************************************************************************/
  665. void GeocacheDisplay::textBoxID_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
  666. {
  667. // Initialize the flag to false.
  668. nonNumberEntered = false;
  669. // Determine whether the keystroke is a number from the top of the keyboard.
  670. // ... or a valid KEY ...
  671. if ( e->KeyCode < Keys::D0 || e->KeyCode > Keys::Z )
  672. {
  673. // Determine whether the keystroke is a number from the keypad.
  674. if ( e->KeyCode < Keys::NumPad0 || e->KeyCode > Keys::NumPad9 )
  675. {
  676. // Determine whether the keystroke is a backspace.
  677. if ( e->KeyCode != Keys::Back )
  678. {
  679. // A non-numerical keystroke was pressed.
  680. // Set the flag to true and evaluate in KeyPress event.
  681. nonNumberEntered = true;
  682. }
  683. }
  684. }
  685. // If shift key was pressed, it's not a number.
  686. if (Control::ModifierKeys == Keys::Shift) {
  687. // Only allow Shifted A-Z
  688. if ( e->KeyCode < Keys::A || e->KeyCode > Keys::Z )
  689. nonNumberEntered = true;
  690. }
  691. }
  692. /**************************************************************************
  693. * GeocacheDisplay:textBoxID_KeyPress
  694. *
  695. * This event occurs after the KeyDown event and can be used to prevent
  696. * characters from entering the control.
  697. *
  698. * returns: N/A
  699. *
  700. **************************************************************************/
  701. void GeocacheDisplay::textBoxID_KeyPress( Object^ /*sender*/, System::Windows::Forms::KeyPressEventArgs^ e )
  702. {
  703. // Check for the flag being set in the KeyDown event.
  704. if ( nonNumberEntered == true )
  705. { // Stop the character from being entered into the control since it is non-numerical.
  706. e->Handled = true;
  707. }
  708. }
  709. /**************************************************************************
  710. * GeocacheDisplay::checkBoxPIN_CheckedChanged
  711. *
  712. * Enables and disables the PIN Text Box
  713. *
  714. * returns: N/A
  715. *
  716. **************************************************************************/
  717. void GeocacheDisplay::checkBoxPIN_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  718. {
  719. if (this->checkBoxPIN->Checked == TRUE)
  720. {
  721. this->textBoxPIN->Enabled = TRUE;
  722. }
  723. else
  724. {
  725. this->textBoxPIN->Enabled = FALSE;
  726. }
  727. }
  728. /**************************************************************************
  729. * GeocacheDisplay:textBoxPIN_KeyDown
  730. *
  731. * Handle the KeyDown event to determine the type of character entered into the control.
  732. *
  733. * returns: N/A
  734. *
  735. **************************************************************************/
  736. void GeocacheDisplay::textBoxPIN_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
  737. {
  738. // Initialize the flag to false.
  739. nonNumberEntered = false;
  740. // Determine whether the keystroke is a number from the top of the keyboard.
  741. // ... or a valid KEY ...
  742. if ( e->KeyCode < Keys::D0 || e->KeyCode > Keys::D9 )
  743. {
  744. // Determine whether the keystroke is a number from the keypad.
  745. if ( e->KeyCode < Keys::NumPad0 || e->KeyCode > Keys::NumPad9 )
  746. {
  747. // Determine whether the keystroke is a backspace.
  748. if ( e->KeyCode != Keys::Back )
  749. {
  750. // A non-numerical keystroke was pressed.
  751. // Set the flag to true and evaluate in KeyPress event.
  752. nonNumberEntered = true;
  753. }
  754. }
  755. }
  756. // If shift key was pressed, it's not a number.
  757. if (Control::ModifierKeys == Keys::Shift) {
  758. nonNumberEntered = true;
  759. }
  760. }
  761. /**************************************************************************
  762. * GeocacheDisplay:textBoxPIN_KeyPress
  763. *
  764. * This event occurs after the KeyDown event and can be used to prevent
  765. * characters from entering the control.
  766. *
  767. * returns: N/A
  768. *
  769. **************************************************************************/
  770. void GeocacheDisplay::textBoxPIN_KeyPress( Object^ /*sender*/, System::Windows::Forms::KeyPressEventArgs^ e )
  771. {
  772. // Check for the flag being set in the KeyDown event.
  773. if ( nonNumberEntered == true )
  774. { // Stop the character from being entered into the control since it is non-numerical.
  775. e->Handled = true;
  776. }
  777. }
  778. /**************************************************************************
  779. * GeocacheDisplay::checkBoxLatitude_CheckedChanged
  780. *
  781. * Enables and disables the Latitude numeric upDown
  782. *
  783. * returns: N/A
  784. *
  785. **************************************************************************/
  786. void GeocacheDisplay::checkBoxLatitude_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  787. {
  788. if (this->checkBoxLatitude->Checked == TRUE)
  789. {
  790. this->numericUpDownLatitude->Enabled = TRUE;
  791. }
  792. else
  793. {
  794. this->numericUpDownLatitude->Enabled = FALSE;
  795. }
  796. }
  797. /**************************************************************************
  798. * GeocacheDisplay::checkBoxLongitude_CheckedChanged
  799. *
  800. * Enables and disables the Longitude numeric upDown
  801. *
  802. * returns: N/A
  803. *
  804. **************************************************************************/
  805. void GeocacheDisplay::checkBoxLongitude_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  806. {
  807. if (this->checkBoxLongitude->Checked == TRUE)
  808. {
  809. this->numericUpDownLongitude->Enabled = TRUE;
  810. }
  811. else
  812. {
  813. this->numericUpDownLongitude->Enabled = FALSE;
  814. }
  815. }
  816. /**************************************************************************
  817. * GeocacheDisplay::checkBoxHint_CheckedChanged
  818. *
  819. * Enables and disables the Hint Test Box
  820. *
  821. * returns: N/A
  822. *
  823. **************************************************************************/
  824. void GeocacheDisplay::checkBoxHint_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  825. {
  826. if (this->checkBoxHint->Checked == TRUE)
  827. {
  828. this->textBoxHint->Enabled = TRUE;
  829. }
  830. else
  831. {
  832. this->textBoxHint->Enabled = FALSE;
  833. }
  834. }
  835. /**************************************************************************
  836. * GeocacheDisplay::checkBoxLoggedVisits_CheckedChanged
  837. *
  838. * Enables and disables the Various Logged Visit Parameters ...
  839. *
  840. * returns: N/A
  841. *
  842. **************************************************************************/
  843. void GeocacheDisplay::checkBoxLoggedVisits_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  844. {
  845. if (this->checkBoxLoggedVisits->Checked == TRUE)
  846. {
  847. this->numericUpDownNumVisits->Enabled = TRUE;
  848. this->numericUpDownYear->Enabled = TRUE;
  849. this->numericUpDownMonth->Enabled = TRUE;
  850. this->numericUpDownDay->Enabled = TRUE;
  851. this->numericUpDownHours->Enabled = TRUE;
  852. this->numericUpDownMinutes->Enabled = TRUE;
  853. this->numericUpDownSeconds->Enabled = TRUE;
  854. }
  855. else
  856. {
  857. this->numericUpDownNumVisits->Enabled = FALSE;
  858. this->numericUpDownYear->Enabled = FALSE;
  859. this->numericUpDownMonth->Enabled = FALSE;
  860. this->numericUpDownDay->Enabled = FALSE;
  861. this->numericUpDownHours->Enabled = FALSE;
  862. this->numericUpDownMinutes->Enabled = FALSE;
  863. this->numericUpDownSeconds->Enabled = FALSE;
  864. }
  865. }
  866. /**************************************************************************
  867. * GeocacheDisplay::numericUpDownNumVisits_ValueChanged
  868. *
  869. * Adjusts the current Number of Visits via the GUI
  870. *
  871. * returns: N/A
  872. *
  873. **************************************************************************/
  874. void GeocacheDisplay::numericUpDownNumVisits_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  875. {
  876. // Nothing to do ...
  877. }
  878. /**************************************************************************
  879. * GeocacheDisplay::numericUpDownDay_ValueChanged
  880. *
  881. * Sets value of the day
  882. *
  883. * returns: N/A
  884. *
  885. **************************************************************************/
  886. void GeocacheDisplay::numericUpDownDay_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  887. {
  888. commonData->ucDays = System::Convert::ToByte(this->numericUpDownDay->Value);
  889. }
  890. /**************************************************************************
  891. * GeocacheDisplay::numericUpDownMonth_ValueChanged
  892. *
  893. * Sets value of the month
  894. *
  895. * returns: N/A
  896. *
  897. **************************************************************************/
  898. void GeocacheDisplay::numericUpDownMonth_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  899. {
  900. commonData->ucMonth = System::Convert::ToByte(this->numericUpDownMonth->Value);
  901. }
  902. /**************************************************************************
  903. * GeocacheDisplay::numericUpDownYear_ValueChanged
  904. *
  905. * Sets value of the year
  906. *
  907. * returns: N/A
  908. *
  909. **************************************************************************/
  910. void GeocacheDisplay::numericUpDownYear_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  911. {
  912. commonData->ucYears = System::Convert::ToByte(this->numericUpDownYear->Value);
  913. }
  914. /**************************************************************************
  915. * GeocacheDisplay::numericUpDownHours_ValueChanged
  916. *
  917. * Sets value of the hours
  918. *
  919. * returns: N/A
  920. *
  921. **************************************************************************/
  922. void GeocacheDisplay::numericUpDownHours_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  923. {
  924. commonData->ucHours = System::Convert::ToByte(this->numericUpDownHours->Value);
  925. }
  926. /**************************************************************************
  927. * GeocacheDisplay::numericUpDownMinutes_ValueChanged
  928. *
  929. * Sets value of the minutes
  930. *
  931. * returns: N/A
  932. *
  933. **************************************************************************/
  934. void GeocacheDisplay::numericUpDownMinutes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  935. {
  936. commonData->ucMinutes = System::Convert::ToByte(this->numericUpDownMinutes->Value);
  937. }
  938. /**************************************************************************
  939. * GeocacheDisplay::numericUpDownSeconds_ValueChanged
  940. *
  941. * Sets value of the minutes
  942. *
  943. * returns: N/A
  944. *
  945. **************************************************************************/
  946. void GeocacheDisplay::numericUpDownSeconds_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  947. {
  948. commonData->ucSeconds = System::Convert::ToByte(this->numericUpDownSeconds->Value);
  949. }