2
0

RacquetDisplay.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. #include "StdAfx.h"
  9. #include "RacquetDisplay.h"
  10. void RacquetDisplay::InitializeSim()
  11. {
  12. }
  13. void RacquetDisplay::ANT_eventNotification(UCHAR ucEventCode_, UCHAR *pucEventBuffer_)
  14. {
  15. UCHAR ucPageNum = pucEventBuffer_[0];
  16. switch(ucEventCode_)
  17. {
  18. case EVENT_RX_ACKNOWLEDGED:
  19. case EVENT_RX_BURST_PACKET:
  20. case EVENT_RX_BROADCAST:
  21. // Check if incoming page is a common page or a racquet page
  22. if(ucPageNum < Common->START_COMMON_PAGE)
  23. RacquetData->Decode(pucEventBuffer_);
  24. else
  25. Common->Decode(pucEventBuffer_);
  26. // Update the UI
  27. UpdateDisplay(ucPageNum);
  28. break;
  29. case EVENT_TRANSFER_TX_COMPLETED:
  30. ucAckRetryCount = 0; // Reset retransmission counter
  31. ucMsgExpectingAck = 0; // Clear pending msg code
  32. UpdateDisplayAckStatus(RacquetData->ACK_SUCCESS); // Tx successful
  33. break;
  34. case EVENT_TRANSFER_TX_FAILED:
  35. case EVENT_ACK_TIMEOUT: // Intentional fall thru
  36. if(ucMsgExpectingAck)
  37. {
  38. if(HandleRetransmit())
  39. UpdateDisplayAckStatus(RacquetData->ACK_RETRY); // Data was retransmitted
  40. else
  41. UpdateDisplayAckStatus(RacquetData->ACK_FAIL); // Maximum number of retries exceeded, Tx failed
  42. }
  43. break;
  44. case EVENT_RX_FAIL:
  45. break;
  46. default:
  47. break;
  48. }
  49. }
  50. void RacquetDisplay::UpdateDisplay(UCHAR ucPageNum_)
  51. {
  52. switch(ucPageNum_)
  53. {
  54. case (UCHAR)AntPlusRacquet::PAGE_STROKE_EVENT:
  55. lbEventCount->Text = RacquetData->ucEventCount.ToString();
  56. lbEventTime->Text = RacquetData->usEventTime.ToString();
  57. lbStrokeType->Text = GetStrokeText(RacquetData->ucEventType, ucPageNum_);
  58. lbRacquetZone->Text = GetZoneText(RacquetData->ucRacquetZone, ucPageNum_);
  59. lbANTFS->Text = GetANTFSText (RacquetData->ucANTFS, ucPageNum_);
  60. lbBallSpeed->Text = (RacquetData->usSpeed == AntPlusRacquet::UNKNOWN ?
  61. "Invalid" :
  62. rbMPS->Checked ?
  63. ((double)RacquetData->usSpeed / 100).ToString("F2") :
  64. Math::Round((((double)RacquetData->usSpeed / 100) * ((double)36 / (double)10)), 3, System::MidpointRounding::AwayFromZero).ToString("F2"));
  65. lbDisplayZone->Text = GetZoneText(RacquetData->ucRacquetZone, ucPageNum_);
  66. // lbDisplayANTFS->Text = GetANTFSText (RacquetData->ucANTFS, ucPageNum_);
  67. lbDisplayEvent->Text = RacquetData->ucEventCount.ToString();
  68. lbDisplayStroke->Text = GetStrokeText(RacquetData->ucEventType, ucPageNum_);
  69. lbDisplayTime->Text = RacquetData->usEventTime.ToString();
  70. lbDisplaySpeed->Text = (RacquetData->usSpeed == AntPlusRacquet::UNKNOWN ?
  71. "Invalid" :
  72. rbMPS->Checked ?
  73. ((double)RacquetData->usSpeed / 100).ToString("F2") :
  74. Math::Round((((double)RacquetData->usSpeed / 100) * ((double)36 / (double)10)), 3, System::MidpointRounding::AwayFromZero).ToString("F2"));
  75. break;
  76. case (UCHAR)AntPlusRacquet::PAGE_STROKE_COUNT:
  77. lbStrokeType1->Text = GetStrokeText(RacquetData->ucStrokeType1, ucPageNum_);
  78. lbStrokeType2->Text = GetStrokeText(RacquetData->ucStrokeType2, ucPageNum_);
  79. lbStrokeCount1->Text = (RacquetData->usStrokeCount1 == AntPlusRacquet::UNKNOWN ?
  80. "Unknown" :
  81. RacquetData->usStrokeCount1.ToString());
  82. lbStrokeCount2->Text = (RacquetData->usStrokeCount2 == AntPlusRacquet::UNKNOWN ?
  83. "Unknown" :
  84. RacquetData->usStrokeCount2.ToString());
  85. break;
  86. case (UCHAR)AntPlusRacquet::PAGE_PREVIOUS_STROKE_EVENT:
  87. lbPreviousCount->Text = RacquetData->ucPreviousEventCount.ToString();
  88. lbPreviousType->Text = GetStrokeText(RacquetData->ucPreviousEventType, ucPageNum_);
  89. lbPreviousTime->Text = RacquetData->usPreviousEventTime.ToString();
  90. lbPreviousZone->Text = GetZoneText(RacquetData->ucPreviousRacquetZone, ucPageNum_);
  91. lbPreviousSpeed->Text = (RacquetData->usPreviousSpeed == AntPlusRacquet::UNKNOWN ?
  92. "Invalid" :
  93. ((double)RacquetData->usPreviousSpeed / 100).ToString());
  94. break;
  95. case (UCHAR)AntPlusRacquet::PAGE_ZONE_COUNT:
  96. lbZoneStroke->Text = GetStrokeText(RacquetData->ucType, ucPageNum_);
  97. lbZone1->Text = GetZoneText(RacquetData->ucZone, ucPageNum_);
  98. if ((UCHAR)(RacquetData->ucZone + 1) == 0)
  99. {
  100. lbZone2->Text = "N/A";
  101. }
  102. else if(RacquetData->ucZone + 1 == (UCHAR) AntPlusRacquet::RacquetZones::UNKNOWN)
  103. {
  104. lbZone2->Text = "Unknown";
  105. }
  106. else
  107. {
  108. lbZone2->Text = GetZoneText (RacquetData->ucZone++ , ucPageNum_);
  109. }
  110. lbZoneCount1->Text = (RacquetData->usCount == AntPlusRacquet::UNKNOWN ?
  111. "Unknown" :
  112. RacquetData->usCount.ToString());
  113. lbZoneCount2->Text = (RacquetData->usCountPlus1 == AntPlusRacquet::UNKNOWN ?
  114. "Unknown" :
  115. RacquetData->usCountPlus1.ToString());
  116. break;
  117. case (UCHAR)CommonData::PAGE80:
  118. lbHardwareVer->Text = Common->ucHwVersion.ToString();
  119. lbManfId->Text = Common->usMfgID.ToString();
  120. lbModelNumber->Text = Common->usModelNum.ToString();
  121. break;
  122. case (UCHAR)CommonData::PAGE81:
  123. lbSoftwareVer->Text = Common->ucSwVersion.ToString();
  124. lbSerialNumber->Text = (Common->ulSerialNum == 0xFFFFFFFF ?
  125. "Invalid" :
  126. Common->ulSerialNum.ToString());
  127. break;
  128. case (UCHAR)CommonData::PAGE82:
  129. if(Common->usBatVoltage256 == CommonData::BATTERY_VOLTAGE_INVALID)
  130. labelBattVolt->Text = "Invalid";
  131. else
  132. labelBattVolt->Text = System::Math::Round((double)Common->usBatVoltage256/256, 4).ToString("N2");
  133. if(Common->eTimeResolution == CommonData::TimeResolution::SIXTEEN)
  134. labelTimeRes->Text = "16 s";
  135. else
  136. labelTimeRes->Text = "2 s";
  137. labelOpTime->Text = (Common->ulOpTime * (UCHAR)Common->eTimeResolution).ToString();
  138. switch(Common->eBatStatus)
  139. {
  140. case CommonData::BatStatus::CRITICAL:
  141. labelBattStatus->Text = "Critical";
  142. break;
  143. case CommonData::BatStatus::GOOD:
  144. labelBattStatus->Text = "Good";
  145. break;
  146. case CommonData::BatStatus::INVALID:
  147. labelBattStatus->Text = "Invalid";
  148. break;
  149. case CommonData::BatStatus::LOW:
  150. labelBattStatus->Text = "Low";
  151. break;
  152. case CommonData::BatStatus::NEW:
  153. labelBattStatus->Text = "New";
  154. break;
  155. case CommonData::BatStatus::OK:
  156. labelBattStatus->Text = "Ok";
  157. break;
  158. default:
  159. labelBattStatus->Text = "---";
  160. break;
  161. }
  162. break;
  163. default:
  164. break;
  165. }
  166. }
  167. System::String^ RacquetDisplay::GetStrokeText(UCHAR ucRacquetData_, UCHAR ucPageNum_)
  168. {
  169. System::String^ strokeText;
  170. switch(ucRacquetData_)
  171. {
  172. case (UCHAR)AntPlusRacquet::StrokeTypes::NO_EVENT:
  173. switch(ucPageNum_)
  174. {
  175. case (UCHAR)AntPlusRacquet::PAGE_PREVIOUS_STROKE_EVENT:
  176. case (UCHAR)AntPlusRacquet::PAGE_STROKE_EVENT:
  177. strokeText = "No Event";
  178. break;
  179. default:
  180. strokeText = "All Events";
  181. break;
  182. }
  183. break;
  184. case (UCHAR)AntPlusRacquet::StrokeTypes::OTHER:
  185. strokeText = "Other";
  186. break;
  187. case (UCHAR)AntPlusRacquet::StrokeTypes::SERVE:
  188. strokeText = "Serve";
  189. break;
  190. case (UCHAR)AntPlusRacquet::StrokeTypes::FOREHAND:
  191. strokeText = "Forehand";
  192. break;
  193. case (UCHAR)AntPlusRacquet::StrokeTypes::BACKHAND:
  194. strokeText = "Backhand";
  195. break;
  196. case (UCHAR)AntPlusRacquet::StrokeTypes::SMASH:
  197. strokeText = "Smash";
  198. break;
  199. case (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN:
  200. strokeText = "Unknown";
  201. break;
  202. default:
  203. strokeText = "----";
  204. break;
  205. }
  206. return strokeText;
  207. }
  208. System::String^ RacquetDisplay::GetZoneText(UCHAR ucRacquetData_, UCHAR ucPageNum_)
  209. {
  210. System::String^ zoneText;
  211. switch(ucRacquetData_)
  212. {
  213. case(UCHAR)AntPlusRacquet::RacquetZones::MISS:
  214. zoneText = "Miss";
  215. break;
  216. case(UCHAR)AntPlusRacquet::RacquetZones::TOP_RIGHT:
  217. zoneText = "Top Right";
  218. break;
  219. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_RIGHT:
  220. zoneText = "Middle Right";
  221. break;
  222. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_RIGHT:
  223. zoneText = "Bottom Right";
  224. break;
  225. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_CENTRE:
  226. zoneText = "Bottom Centre";
  227. break;
  228. case (UCHAR)AntPlusRacquet::RacquetZones::BOTTOM_LEFT:
  229. zoneText = "Bottom Left";
  230. break;
  231. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_CENTRE:
  232. zoneText = "Middle Centre";
  233. break;
  234. case (UCHAR)AntPlusRacquet::RacquetZones::MIDDLE_LEFT:
  235. zoneText = "Middle Left";
  236. break;
  237. case (UCHAR)AntPlusRacquet::RacquetZones::TOP_LEFT:
  238. zoneText = "Top Left";
  239. break;
  240. case (UCHAR)AntPlusRacquet::RacquetZones::TOP_CENTRE:
  241. zoneText = "Top Centre";
  242. break;
  243. case (UCHAR)AntPlusRacquet::RacquetZones::RIM_OTHER:
  244. zoneText = "Rim/Other";
  245. break;
  246. case (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN:
  247. zoneText = "Unknown";
  248. break;
  249. default:
  250. zoneText = "----";
  251. break;
  252. }
  253. return zoneText;
  254. }
  255. System::String^ RacquetDisplay::GetANTFSText(UCHAR ucRacquetData_, UCHAR ucPageNum_)
  256. {
  257. System::String^ aNTFSText;
  258. switch(ucRacquetData_)
  259. {
  260. case(UCHAR)AntPlusRacquet::ANTFS::SUPPORTED:
  261. aNTFSText = "Supported";
  262. break;
  263. case(UCHAR)AntPlusRacquet::ANTFS::NOT_SUPPORTED:
  264. aNTFSText = "Not Supported";
  265. break;
  266. default:
  267. aNTFSText = "---";
  268. break;
  269. }
  270. return aNTFSText;
  271. }
  272. void RacquetDisplay::onTimerTock(USHORT eventTime)
  273. {
  274. }
  275. void RacquetDisplay::btRequestEvent_Click(System::Object ^sender, System::EventArgs ^e)
  276. {
  277. UCHAR aucAckBuffer[8] = {0,0,0,0,0,0,0,0};
  278. Common->ucDescriptorByte1 = (UCHAR)nmPreviousEvent->Value;
  279. Common->ucDescriptorByte2 = (UCHAR)AntPlusRacquet::UNKNOWN;
  280. Common->ucReqTransResp = (UCHAR)nmTxResponsePrevious->Value;
  281. Common->ucReqPageNum = AntPlusRacquet::PAGE_PREVIOUS_STROKE_EVENT;
  282. Common->ucCommandType = CommonData::COMMAND_TYPE_DATA;
  283. SendAckMessage(Common->PAGE70);
  284. }
  285. void RacquetDisplay::btRequestStrokeCount_Click(System::Object ^sender, System::EventArgs ^e)
  286. {
  287. UCHAR aucAckBuffer[8] = {0,0,0,0,0,0,0,0};
  288. Common->ucDescriptorByte1 = (cbStrokeType1->SelectedIndex == AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1 ? // Unknown
  289. (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN :
  290. cbStrokeType1->SelectedIndex);
  291. Common->ucDescriptorByte2 = (cbStrokeType2->SelectedIndex == AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1 ? // Unknown
  292. (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN :
  293. cbStrokeType2->SelectedIndex);
  294. Common->ucReqTransResp = (UCHAR)nmTxResponseStrokes->Value;
  295. Common->ucReqPageNum = AntPlusRacquet::PAGE_STROKE_COUNT;
  296. Common->ucCommandType = CommonData::COMMAND_TYPE_DATA;
  297. Common->Encode(CommonData::PAGE70, aucAckBuffer);
  298. SendAckMessage(Common->PAGE70);
  299. }
  300. void RacquetDisplay::btRequestZoneCount_Click(System::Object ^sender, System::EventArgs ^e)
  301. {
  302. UCHAR aucAckBuffer[8] = {0,0,0,0,0,0,0,0};
  303. Common->ucDescriptorByte1 = (cbStrokeType->SelectedIndex == AntPlusRacquet::NUMBER_OF_STROKE_TYPES - 1 ? // Unknown
  304. (UCHAR)AntPlusRacquet::StrokeTypes::UNKNOWN :
  305. cbStrokeType->SelectedIndex);
  306. Common->ucDescriptorByte2 = (cbZoneType->SelectedIndex == AntPlusRacquet::NUMBER_OF_ZONES - 1 ? // Unknown
  307. (UCHAR)AntPlusRacquet::RacquetZones::UNKNOWN :
  308. cbZoneType->SelectedIndex);
  309. Common->ucReqTransResp = (UCHAR)nmTxResponseZones->Value;
  310. Common->ucReqPageNum = AntPlusRacquet::PAGE_ZONE_COUNT;
  311. Common->ucCommandType = CommonData::COMMAND_TYPE_DATA;
  312. Common->Encode(CommonData::PAGE70, aucAckBuffer);
  313. SendAckMessage(Common->PAGE70);
  314. }
  315. void RacquetDisplay::UpdateDisplayAckStatus(UCHAR ucStatus_)
  316. {
  317. switch(ucStatus_)
  318. {
  319. case RacquetData->ACK_SUCCESS:
  320. lbAckStatus->ForeColor = System::Drawing::Color::Green;
  321. lbAckStatus->Text = "SENT";
  322. break;
  323. case RacquetData->ACK_RETRY:
  324. lbAckStatus->ForeColor = System::Drawing::Color::Blue;
  325. lbAckStatus->Text = "RTRY";
  326. break;
  327. case RacquetData->ACK_FAIL:
  328. lbAckStatus->ForeColor = System::Drawing::Color::Red;
  329. lbAckStatus->Text = "FAIL";
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. BOOL RacquetDisplay::HandleRetransmit()
  336. {
  337. BOOL bSuccess = TRUE;
  338. if(ucMsgExpectingAck) // Message still expecting an ack
  339. {
  340. if(ucAckRetryCount++ < RacquetData->MAX_RETRIES)
  341. SendAckMessage(ucMsgExpectingAck);
  342. else
  343. bSuccess = FALSE;
  344. }
  345. return bSuccess;
  346. }
  347. void RacquetDisplay::btSessionStart_Click(System::Object ^sender, System::EventArgs ^e)
  348. {
  349. RacquetData->eEvent = AntPlusRacquet::FITEvents::SESSION;
  350. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::START;
  351. RacquetData->ulEventData = AntPlusRacquet::UNKNOWN_ULONG;
  352. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  353. }
  354. void RacquetDisplay::btSessionStop_Click(System::Object ^sender, System::EventArgs ^e)
  355. {
  356. RacquetData->eEvent = AntPlusRacquet::FITEvents::SESSION;
  357. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::STOP;
  358. RacquetData->ulEventData = AntPlusRacquet::UNKNOWN_ULONG;
  359. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  360. }
  361. void RacquetDisplay::btTimerStart_Click(System::Object ^sender, System::EventArgs ^e)
  362. {
  363. RacquetData->eEvent = AntPlusRacquet::FITEvents::TIMER;
  364. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::START;
  365. RacquetData->ulEventData = AntPlusRacquet::UNKNOWN_ULONG;
  366. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  367. }
  368. void RacquetDisplay::btTimerStop_Click(System::Object ^sender, System::EventArgs ^e)
  369. {
  370. RacquetData->eEvent = AntPlusRacquet::FITEvents::TIMER;
  371. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::STOP;
  372. RacquetData->ulEventData = AntPlusRacquet::UNKNOWN_ULONG;
  373. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  374. }
  375. void RacquetDisplay::btMarkStroke_Click(System::Object ^sender, System::EventArgs ^e)
  376. {
  377. RacquetData->eEvent = AntPlusRacquet::FITEvents::USER_MARKER;
  378. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::MARKER;
  379. RacquetData->ulEventData = AntPlusRacquet::UNKNOWN_ULONG;
  380. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  381. }
  382. void RacquetDisplay::btSendGameScore_Click(System::Object ^sender, System::EventArgs ^e)
  383. {
  384. RacquetData->eEvent = AntPlusRacquet::FITEvents::SPORT_POINT;
  385. RacquetData->eEventType = AntPlusRacquet::FITEventTypes::MARKER;
  386. // Clear the data so we can populate it
  387. RacquetData->ulEventData = 0x00;
  388. if(cbInvalidMyGameScore->Checked)
  389. RacquetData->ulEventData |= (ULONG)AntPlusRacquet::UNKNOWN;
  390. else
  391. RacquetData->ulEventData |= System::Convert::ToInt16(nmMyGameScore->Value);
  392. if(cbInvalidOpponentGameScore->Checked)
  393. RacquetData->ulEventData |= (ULONG)((ULONG)AntPlusRacquet::UNKNOWN << 16);
  394. else
  395. RacquetData->ulEventData |= (ULONG)(System::Convert::ToInt16(nmOpponentGameScore->Value) << 16);
  396. SendAckMessage(AntPlusRacquet::PAGE_EVENT_DATA);
  397. }
  398. void RacquetDisplay::btSendSessionData_Click(System::Object ^sender, System::EventArgs ^e)
  399. {
  400. switch(cbGameMode->SelectedIndex)
  401. {
  402. case 0: // Warm Up
  403. RacquetData->eGameMode = AntPlusRacquet::FITSubSports::WARM_UP;
  404. break;
  405. case 1: // Match
  406. RacquetData->eGameMode = AntPlusRacquet::FITSubSports::MATCH;
  407. break;
  408. case 2: // Exercise
  409. RacquetData->eGameMode = AntPlusRacquet::FITSubSports::EXERCISE;
  410. break;
  411. case 3: // Challenge
  412. RacquetData->eGameMode = AntPlusRacquet::FITSubSports::CHALLENGE;
  413. break;
  414. default:
  415. break;
  416. }
  417. if(cbInvalidMySetsWon->Checked)
  418. RacquetData->usMySessionsWon = AntPlusRacquet::UNKNOWN;
  419. else
  420. RacquetData->usMySessionsWon = System::Convert::ToUInt16(nmMySetsWon->Value);
  421. if(cbInvalidOpponentSetsWon->Checked)
  422. RacquetData->usOpponentSessionsWon = AntPlusRacquet::UNKNOWN;
  423. else
  424. RacquetData->usOpponentSessionsWon = System::Convert::ToUInt16(nmOpponentSetsWon->Value);
  425. SendAckMessage(RacquetData->PAGE_SESSION_DATA);
  426. }
  427. void RacquetDisplay::btSendSetCount_Click(System::Object ^sender, System::EventArgs ^e)
  428. {
  429. if(cbInvalidMySetCount->Checked)
  430. RacquetData->usMySetCount = AntPlusRacquet::UNKNOWN;
  431. else
  432. RacquetData->usMySetCount = System::Convert::ToUInt16(nmMySetCount->Value);
  433. if(cbInvalidOpponentSetCount->Checked)
  434. RacquetData->usOpponentSetCount = AntPlusRacquet::UNKNOWN;
  435. else
  436. RacquetData->usOpponentSetCount = System::Convert::ToUInt16(nmOpponentSetCount->Value);
  437. SendAckMessage(RacquetData->PAGE_LAP_DATA);
  438. }
  439. void RacquetDisplay::btSendGameCount_Click(System::Object ^sender, System::EventArgs ^e)
  440. {
  441. if(cbInvalidMyGameCount->Checked)
  442. RacquetData->usMyGameCount = AntPlusRacquet::UNKNOWN;
  443. else
  444. RacquetData->usMyGameCount = System::Convert::ToUInt16(nmMyGameCount->Value);
  445. if(cbInvalidOpponentGameCount->Checked)
  446. RacquetData->usOpponentGameCount = AntPlusRacquet::UNKNOWN;
  447. else
  448. RacquetData->usOpponentGameCount = System::Convert::ToUInt16(nmOpponentGameCount->Value);
  449. SendAckMessage(RacquetData->PAGE_LENGTH_DATA);
  450. }
  451. void RacquetDisplay::cbInvalidMyGameCount_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  452. {
  453. if(cbInvalidMyGameCount->Checked)
  454. nmMyGameCount->Enabled = false;
  455. else
  456. nmMyGameCount->Enabled = true;
  457. }
  458. void RacquetDisplay::cbInvalidOpponentGameCount_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  459. {
  460. if(cbInvalidOpponentGameCount->Checked)
  461. nmOpponentGameCount->Enabled = false;
  462. else
  463. nmOpponentGameCount->Enabled = true;
  464. }
  465. void RacquetDisplay::cbInvalidMySetCount_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  466. {
  467. if(cbInvalidMySetCount->Checked)
  468. nmMySetCount->Enabled = false;
  469. else
  470. nmMySetCount->Enabled = true;
  471. }
  472. void RacquetDisplay::cbInvalidMySetsWon_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  473. {
  474. if(cbInvalidMySetsWon->Checked)
  475. nmMySetsWon->Enabled = false;
  476. else
  477. nmMySetsWon->Enabled = true;
  478. }
  479. void RacquetDisplay::cbInvalidOpponentSetCount_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  480. {
  481. if(cbInvalidOpponentSetCount->Checked)
  482. nmOpponentSetCount->Enabled = false;
  483. else
  484. nmOpponentSetCount->Enabled = true;
  485. }
  486. void RacquetDisplay::cbInvalidOpponentSetsWon_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  487. {
  488. if(cbInvalidOpponentSetsWon->Checked)
  489. nmOpponentSetsWon->Enabled = false;
  490. else
  491. nmOpponentSetsWon->Enabled = true;
  492. }
  493. void RacquetDisplay::cbInvalidMyGameScore_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  494. {
  495. if(cbInvalidMyGameScore->Checked)
  496. nmMyGameScore->Enabled = false;
  497. else
  498. nmMyGameScore->Enabled = true;
  499. }
  500. void RacquetDisplay::cbInvalidOpponentGameScore_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  501. {
  502. if(cbInvalidOpponentGameScore->Checked)
  503. nmOpponentGameScore->Enabled = false;
  504. else
  505. nmOpponentGameScore->Enabled = true;
  506. }
  507. void RacquetDisplay::SendAckMessage(UCHAR ucMsgCode_)
  508. {
  509. UCHAR aucAckBuffer[8] = {0,0,0,0,0,0,0,0};
  510. switch(ucMsgCode_)
  511. {
  512. case AntPlusRacquet::PAGE_EVENT_DATA:
  513. RacquetData->Encode(AntPlusRacquet::PAGE_EVENT_DATA, aucAckBuffer);
  514. break;
  515. case AntPlusRacquet::PAGE_SESSION_DATA:
  516. RacquetData->Encode(AntPlusRacquet::PAGE_SESSION_DATA, aucAckBuffer);
  517. break;
  518. case AntPlusRacquet::PAGE_LAP_DATA:
  519. RacquetData->Encode(AntPlusRacquet::PAGE_LAP_DATA, aucAckBuffer);
  520. break;
  521. case AntPlusRacquet::PAGE_LENGTH_DATA:
  522. RacquetData->Encode(AntPlusRacquet::PAGE_LENGTH_DATA, aucAckBuffer);
  523. break;
  524. case AntPlusRacquet::PAGE_METABOLIC_DATA:
  525. RacquetData->Encode(AntPlusRacquet::PAGE_METABOLIC_DATA, aucAckBuffer);
  526. break;
  527. case AntPlusRacquet::PAGE_SPEED_DATA:
  528. RacquetData->Encode(AntPlusRacquet::PAGE_SPEED_DATA, aucAckBuffer);
  529. break;
  530. case AntPlusRacquet::PAGE_DISTANCE_DATA:
  531. RacquetData->Encode(AntPlusRacquet::PAGE_DISTANCE_DATA, aucAckBuffer);
  532. break;
  533. case CommonData::PAGE70:
  534. Common->Encode(CommonData::PAGE70, aucAckBuffer);
  535. break;
  536. default:
  537. return; // Do not transmit if unsupported message code
  538. }
  539. // Send acknowledged message
  540. if(!ucMsgExpectingAck) // If this message is not a retransmission
  541. {
  542. ucAckRetryCount = 0; // Reset retransmission counter
  543. ucMsgExpectingAck = ucMsgCode_; // Set code to message for which an ACK wil be expected
  544. }
  545. requestAckMsg(aucAckBuffer); // Send message
  546. }
  547. void RacquetDisplay::rbMPS_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
  548. {
  549. if(lbBallSpeed->Text == "----")
  550. return;
  551. if(RacquetData->usSpeed == AntPlusRacquet::UNKNOWN)
  552. lbBallSpeed->Text = "Invalid";
  553. else
  554. {
  555. if(rbMPS->Checked)
  556. lbBallSpeed->Text = ((double)((double)RacquetData->usSpeed / (double)100)).ToString("F2");
  557. else
  558. {
  559. lbBallSpeed->Text = Math::Round(((RacquetData->usSpeed / 100) * ((double)36 / (double)10)), 2, System::MidpointRounding::AwayFromZero).ToString("F2");
  560. }
  561. }
  562. }
  563. void RacquetDisplay::btSendMetabolicData_Click(System::Object^ sender, System::EventArgs^ e)
  564. {
  565. RacquetData->ucMaxHeartRate = System::Convert::ToByte(nmMaxHR->Value);
  566. RacquetData->ucAvgHeartRate = System::Convert::ToByte(nmAvgHR->Value);
  567. RacquetData->usTotalCalories = System::Convert::ToUInt16(nmTotalCalories->Value);
  568. SendAckMessage(RacquetData->PAGE_METABOLIC_DATA);
  569. }
  570. void RacquetDisplay::btSendSpeedData_Click(System::Object^ sender, System::EventArgs^ e)
  571. {
  572. RacquetData->usMaxRunningSpeed = System::Convert::ToUInt16(nmMaxRunSpeed->Value );
  573. RacquetData->usAvgRunningSpeed = System::Convert::ToUInt16(nmAvgRunSpeed->Value);
  574. SendAckMessage(RacquetData->PAGE_SPEED_DATA);
  575. }
  576. void RacquetDisplay::btSendDistanceData_Click(System::Object^ sender, System::EventArgs^ e)
  577. {
  578. RacquetData->uiTotalDistance = System::Convert::ToUInt32(nmTotalDistance->Value);
  579. SendAckMessage(RacquetData->PAGE_DISTANCE_DATA);
  580. }