TemperatureSensor.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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 "TemperatureSensor.h"
  10. #include "antmessage.h"
  11. using namespace System::Runtime::InteropServices;
  12. static ULONG ulMessageCount = 0;
  13. static BOOL bCloseEvent = TRUE;
  14. /**************************************************************************
  15. * TemperatureSensor::InitializeSim
  16. *
  17. * Initializes simulator variables
  18. *
  19. * returns: N/A
  20. *
  21. **************************************************************************/
  22. void TemperatureSensor::InitializeSim()
  23. {
  24. // Set timer period (in ms)
  25. ulTimerInterval = 250;
  26. // Take the initial values from the simulator fields
  27. sMinTemp = System::Convert::ToInt16((this->numericUpDown_Prm_MinTemp->Value)*100); // Default min temperature value is set on UI
  28. sCurTemp = System::Convert::ToInt16((this->numericUpDown_Prm_CurTemp->Value)*100); // Default current temperature value is set on UI
  29. sMaxTemp = System::Convert::ToInt16((this->numericUpDown_Prm_MaxTemp->Value)*100); // Default max temperature value is set on UI
  30. // initialize Temperature
  31. TemperatureData->sCurrentTemp = sCurTemp; // Set initial temperature value (fixed simulation type)
  32. TemperatureData->s24HrHigh = System::Convert::ToInt16((this->numericUpDown_Prm_24HrHigh->Value)*10);
  33. TemperatureData->s24HrLow = System::Convert::ToInt16((this->numericUpDown_Prm_24HrLow->Value)*10);
  34. TemperatureData->ucTxInfo = TemperatureData->TXINFO_P5HZ; // Set initial transmission info (5Hz, 1 page)
  35. TemperatureData->usMessagePeriod = TemperatureData->MESG_P5HZ_PERIOD; // Defaults to Beacon Rate of 0.5Hz
  36. TemperatureData->b4HzRotation = FALSE;
  37. b4HzDefault = FALSE;
  38. // required common pages
  39. commonData->usMfgID = System::Convert::ToUInt16(this->textBox_ManfIDChange->Text); // Default values set on UI
  40. commonData->ucHwVersion = System::Convert::ToByte(this->textBox_HardwareVerChange->Text);
  41. commonData->ucSwVersion = System::Convert::ToByte(this->textBox_SoftwareVerChange->Text);
  42. commonData->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNumChange->Text);
  43. commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNumChange->Text);
  44. //battery common page
  45. commonData->bBattPageEnabled = TRUE;
  46. // update the variables
  47. UpdateBatStatus();
  48. commonData->eTimeResolution = CommonData::TimeResolution::TWO;
  49. commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
  50. commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
  51. commonData->usBatVoltage256 |= System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
  52. commonData->eTimeResolution = CommonData::TimeResolution::TWO;
  53. commonData->ulOpTime = ulTotalTime;
  54. ucReserved = TemperatureData->RESERVED;
  55. //ulRunTime = 0;
  56. ucEventCount = 0;
  57. ucSimDataType = SIM_FIXED; // Generate single fixed temperature value by default
  58. bSweepAscending = TRUE; // sweep values will by default
  59. }
  60. /*************************************************************************
  61. * TemperatureSensor::onTimerTock
  62. *
  63. * Simulates a sensor event, updating simulator data based on this event
  64. * Modifications to the timer interval are applied immediately after this
  65. * at ANTChannel
  66. *
  67. * usEventTime_: current time (ms)
  68. *
  69. * returns: N/A
  70. *
  71. **************************************************************************/
  72. void TemperatureSensor::onTimerTock(USHORT eventTime)
  73. {
  74. UCHAR tempOffset = 0; // Temporary variable to calculate sweeping intervals
  75. // Update temperature value
  76. switch(ucSimDataType)
  77. {
  78. case SIM_FIXED:
  79. // Transmits the current temperature value
  80. TemperatureData->sCurrentTemp = sCurTemp;
  81. break;
  82. /*case SIM_STEP:
  83. // Step: Jumps between min and max every 16 beats
  84. if(ucEventCount & 0x10)
  85. TemperatureData->sCurrentTemp = sMinTemp;
  86. else
  87. TemperatureData->sCurrentTemp = sMaxTemp;
  88. break;
  89. */
  90. case SIM_SWEEP:
  91. // temperature sweeps between min and max
  92. // The jump offset is calculated versus position against the max so it won't get stuck on low values for a long time and won't speed through high values too fast
  93. tempOffset = sMaxTemp - sCurTemp;
  94. tempOffset = (((tempOffset & 0xC0) >> 6) + ((tempOffset & 0x20) >>5) + ((tempOffset & 0x10) >>4)+1)*100;
  95. if(bSweepAscending)
  96. sCurTemp += tempOffset;
  97. else
  98. sCurTemp -= tempOffset;
  99. // Ensure value is not less than min or more than max
  100. if(sCurTemp >= sMaxTemp)
  101. {
  102. sCurTemp = sMaxTemp;
  103. bSweepAscending = FALSE;
  104. }
  105. if(sCurTemp <= sMinTemp)
  106. {
  107. sCurTemp = sMinTemp;
  108. bSweepAscending = TRUE;
  109. }
  110. TemperatureData->sCurrentTemp = sCurTemp;
  111. break;
  112. default:
  113. break;
  114. }
  115. // Update
  116. UpdateDisplay();
  117. }
  118. /**************************************************************************
  119. * TemperatureSensor::ANT_eventNotification
  120. *
  121. * Process ANT channel event
  122. *
  123. * ucEventCode_: code of ANT channel event
  124. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  125. * or a pointer to the transmit buffer in the case of an EVENT_TX
  126. *
  127. * returns: N/A
  128. *
  129. **************************************************************************/
  130. void TemperatureSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
  131. {
  132. switch(ucEventCode_)
  133. {
  134. case EVENT_TX:
  135. HandleTransmit((UCHAR*) pucEventBuffer_);
  136. break;
  137. case EVENT_RX_BROADCAST:
  138. case EVENT_RX_ACKNOWLEDGED:
  139. HandleReceive((UCHAR*) pucEventBuffer_);
  140. break;
  141. case MESG_CLOSE_CHANNEL_ID:
  142. bCloseEvent = TRUE;
  143. this->groupBox_defaultPeriod->Enabled = false;
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149. /**************************************************************************
  150. * TemperatureSensor::HandleTransmit
  151. *
  152. * Encode data generated by simulator for transmission
  153. *
  154. * pucTxBuffer_: pointer to the transmit buffer
  155. *
  156. * returns: N/As
  157. *
  158. **************************************************************************/
  159. void TemperatureSensor::HandleTransmit(UCHAR* pucTxBuffer_)
  160. {
  161. // Kill Page Requests and Switch to 0.5Hz Beacon Mode
  162. if (bCloseEvent)
  163. {
  164. bCloseEvent = FALSE;
  165. this->groupBox_defaultPeriod->Enabled = true;
  166. TemperatureData->bPageRequest = FALSE;
  167. if(!b4HzDefault)
  168. {
  169. TemperatureData->b4HzRotation = FALSE;
  170. TemperatureData->usMessagePeriod = TemperatureData->MESG_P5HZ_PERIOD;
  171. requestUpdateMesgPeriod(TemperatureData->MESG_P5HZ_PERIOD);
  172. }
  173. else
  174. {
  175. TemperatureData->b4HzRotation = TRUE;
  176. TemperatureData->usMessagePeriod = TemperatureData->MESG_4HZ_PERIOD;
  177. requestUpdateMesgPeriod(TemperatureData->MESG_4HZ_PERIOD);
  178. }
  179. }
  180. // Update event count
  181. TemperatureData->ucEventCount = ++ucEventCount;
  182. static UCHAR ucMessageNum = 0; // Message count
  183. static bool bBackgroundToggle = false; // Page toggle tracker
  184. static bool bMainPageToggle = false;
  185. // If a page has been requested
  186. if(TemperatureData->bPageRequest && ucRequestCount != 0)
  187. {
  188. // If all the requested pages have been sent already, uset the flag and continue normally
  189. /* if(ucRequestCount == 0)
  190. {
  191. TemperatureData->bPageRequest = false;
  192. goto send_normal;
  193. }*/
  194. // find out which page needs to be sent and encode it
  195. switch (TemperatureData->ucRequestedPageNum) // Get Requested Page #
  196. {
  197. case TemperatureData->PAGE_0 :
  198. TemperatureData->Encode(TemperatureData->PAGE_0, pucTxBuffer_);
  199. break;
  200. case TemperatureData->PAGE_1 :
  201. TemperatureData->Encode(TemperatureData->PAGE_1, pucTxBuffer_);
  202. break;
  203. case commonData->PAGE80 :
  204. commonData->Encode(commonData->PAGE80, pucTxBuffer_);
  205. break;
  206. case commonData->PAGE81 :
  207. commonData->Encode(commonData->PAGE81, pucTxBuffer_);
  208. break;
  209. case commonData->PAGE82:
  210. if(commonData->bBattPageEnabled)
  211. commonData->Encode(commonData->PAGE82, pucTxBuffer_);
  212. break;
  213. default:
  214. break;
  215. }
  216. ucRequestCount--;
  217. // return;
  218. }
  219. //send_normal:
  220. else if(ucMessageNum++ == TemperatureData->BACKGROUND_INTERVAL - 1)// Send background pages at defined interval
  221. {
  222. TemperatureData->bPageRequest = false;
  223. ucMessageNum = 0;
  224. switch(bBackgroundToggle)
  225. {
  226. case false:
  227. // send Page 80
  228. commonData->Encode(commonData->PAGE80, pucTxBuffer_);
  229. bBackgroundToggle = true;
  230. break;
  231. case true:
  232. // send Page 81
  233. commonData->Encode(commonData->PAGE81, pucTxBuffer_);
  234. bBackgroundToggle = false;
  235. break;
  236. }
  237. }
  238. else
  239. {
  240. // Interleave Page 0 and Page 1
  241. switch( bMainPageToggle)
  242. {
  243. case false : // send page 0
  244. TemperatureData->Encode(TemperatureData->PAGE_0, pucTxBuffer_);
  245. bMainPageToggle = true;
  246. break;
  247. case true : // send page 1
  248. TemperatureData->Encode(TemperatureData->PAGE_1, pucTxBuffer_);
  249. bMainPageToggle = false;
  250. }
  251. }
  252. this->label_TempTx->Text = (System::Convert::ToDecimal(sCurTemp)/100).ToString(); // Display temp being transmitted
  253. ulMessageCount++;
  254. // Return to 0.5Hz Beacon ONLY after 30 secs of no requests and if on 0.5Hz Default
  255. if (TemperatureData->b4HzRotation && (ulMessageCount > TemperatureData->MESG_4HZ_TIMEOUT) && !b4HzDefault)
  256. {
  257. TemperatureData->b4HzRotation = FALSE;
  258. TemperatureData->usMessagePeriod = TemperatureData->MESG_P5HZ_PERIOD;
  259. requestUpdateMesgPeriod(TemperatureData->MESG_P5HZ_PERIOD);
  260. }
  261. static UCHAR ucTimeCount = 0;
  262. // update the batt op time every second
  263. if (ucTimeCount == 3)
  264. {
  265. ulTotalTime++;
  266. commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
  267. ucTimeCount = 0;
  268. }
  269. else
  270. ucTimeCount++;
  271. }
  272. /**************************************************************************
  273. * TemperatureSensor::HandleReceive
  274. *
  275. * Handle incoming page requests
  276. *
  277. * pucTxBuffer_: pointer to the transmit buffer
  278. *
  279. * returns: N/As
  280. *
  281. **************************************************************************/
  282. void TemperatureSensor::HandleReceive(UCHAR *pucRxBuffer_)
  283. {
  284. ulMessageCount = 0; // Reset Message Counter on Any Reset
  285. if (pucRxBuffer_[0] == commonData->PAGE70) // Data Page Request
  286. {
  287. // Change to 4Hz and begin Page Rotation on *ANY* RX
  288. if (!TemperatureData->b4HzRotation || b4HzDefault) // ADD CHECK FOR IF PAGE 70
  289. {
  290. TemperatureData->b4HzRotation = TRUE;
  291. TemperatureData->usMessagePeriod = TemperatureData->MESG_4HZ_PERIOD;
  292. requestUpdateMesgPeriod(TemperatureData->MESG_4HZ_PERIOD);
  293. }
  294. TemperatureData->bPageRequest = TRUE;
  295. TemperatureData->ucRequestedPageNum = pucRxBuffer_[6];
  296. ucRequestCount = (pucRxBuffer_[5] & 0x7F);
  297. }
  298. }
  299. /**************************************************************************
  300. * TemperatureSensor::UpdateDisplay
  301. *
  302. * Update the GUI with all the changes
  303. *
  304. * returns: N/A
  305. *
  306. **************************************************************************/
  307. void TemperatureSensor::UpdateDisplay()
  308. {
  309. this->label_EventCount->Text = ucEventCount.ToString(); // Event count
  310. this->numericUpDown_Prm_CurTemp->Value = System::Convert::ToDecimal(sCurTemp)/100; // Current temperature generated by simulator
  311. // update the operating time for the battery common page
  312. this->label_Bat_ElpTimeDisplay->Text = ulTotalTime.ToString();
  313. }
  314. /**************************************************************************
  315. * TemperatureSensor::ForceUpdate
  316. *
  317. * Causes a timer event, to force the simulator to update all calculations
  318. *
  319. * returns: N/A
  320. *
  321. **************************************************************************/
  322. void TemperatureSensor::ForceUpdate()
  323. {
  324. timerHandle->Interval = 250;
  325. }
  326. /**************************************************************************
  327. * TemperatureSensor::radioButton_SimTypeChanged
  328. *
  329. * Select method to generate simulator data, from user input (GUI)
  330. *
  331. * returns: N/A
  332. *
  333. **************************************************************************/
  334. void TemperatureSensor::radioButton_SimTypeChanged (System::Object^ sender, System::EventArgs^ e)
  335. {
  336. if(this->radioButton_SimTypeFixed->Checked)
  337. {
  338. this->numericUpDown_Prm_CurTemp->Enabled = true;
  339. this->numericUpDown_Prm_MinTemp->Enabled = false;
  340. this->numericUpDown_Prm_MaxTemp->Enabled = false;
  341. ucSimDataType = SIM_FIXED;
  342. }
  343. else if(this->radioButton_SimTypeSweep->Checked)
  344. {
  345. this->numericUpDown_Prm_CurTemp->Enabled = false;
  346. this->numericUpDown_Prm_MinTemp->Enabled = true;
  347. this->numericUpDown_Prm_MaxTemp->Enabled = true;
  348. ucSimDataType = SIM_SWEEP;
  349. bSweepAscending = TRUE;
  350. }
  351. }
  352. /**************************************************************************
  353. * TemperatureSensor::button_AdvancedUpdate_Click
  354. *
  355. * Validates and updates product information, from user input (GUI)
  356. *
  357. * returns: N/A
  358. *
  359. **************************************************************************/
  360. void TemperatureSensor::button_AdvancedUpdate_Click(System::Object^ sender, System::EventArgs^ e)
  361. {
  362. this->label_AdvancedError->Visible = false;
  363. this->label_AdvancedError->Text = "Error: ";
  364. //convert and catch failed conversions
  365. try{
  366. commonData->usMfgID = System::Convert::ToUInt16(this->textBox_ManfIDChange->Text);
  367. }
  368. catch(...){
  369. this->label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " MFID");
  370. this->label_AdvancedError->Visible = true;
  371. }
  372. try{
  373. commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_SerialNumChange->Text);
  374. }
  375. catch(...){
  376. label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " Ser#");
  377. label_AdvancedError->Visible = true;
  378. }
  379. try{
  380. commonData->ucHwVersion = System::Convert::ToByte(this->textBox_HardwareVerChange->Text);
  381. }
  382. catch(...){
  383. label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " HWVr");
  384. label_AdvancedError->Visible = true;
  385. }
  386. try{
  387. commonData->ucSwVersion = System::Convert::ToByte(this->textBox_SoftwareVerChange->Text);
  388. }
  389. catch(...){
  390. label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " SWVr");
  391. label_AdvancedError->Visible = true;
  392. }
  393. try{
  394. commonData->usModelNum = System::Convert::ToUInt16(this->textBox_ModelNumChange->Text);
  395. }
  396. catch(...){
  397. label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " Mdl#");
  398. label_AdvancedError->Visible = true;
  399. }
  400. }
  401. /**************************************************************************
  402. * TemperatureSensor::numericUpDown_Prm_CurTemp_ValueChanged
  403. *
  404. * Validates and updates the current temperature value, from user input (GUI)
  405. *
  406. * returns: N/A
  407. *
  408. **************************************************************************/
  409. void TemperatureSensor::numericUpDown_Prm_CurTemp_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  410. {
  411. // This value is raised whenever the value changes, even if internally
  412. // Only update the current temp if set by the user (not sweeping)
  413. if(this->numericUpDown_Prm_CurTemp->Enabled)
  414. {
  415. sCurTemp = System::Convert::ToInt16((this->numericUpDown_Prm_CurTemp->Value)*100);
  416. TemperatureData->sCurrentTemp = sCurTemp;
  417. ForceUpdate();
  418. }
  419. }
  420. /**************************************************************************
  421. * TemperatureSensor::numericUpDown_Prm_MinMaxTemp_ValueChanged
  422. *
  423. * If the user has changed the min or max temperature, validate that
  424. * minimum < current < maximum
  425. *
  426. * returns: N/A
  427. *
  428. **************************************************************************/
  429. void TemperatureSensor::numericUpDown_Prm_MinMaxTemp_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  430. {
  431. // This event is raised whenever the min and max value change, even if internally
  432. // Check min<max if in min/max mode, and force min<cur<max
  433. if(this->numericUpDown_Prm_MinTemp->Value < this->numericUpDown_Prm_MaxTemp->Value)
  434. {
  435. sMinTemp = System::Convert::ToInt16((this->numericUpDown_Prm_MinTemp->Value)*100);
  436. sMaxTemp = System::Convert::ToInt16((this->numericUpDown_Prm_MaxTemp->Value)*100);
  437. if(sCurTemp > sMaxTemp)
  438. {
  439. sCurTemp = sMaxTemp;
  440. this->numericUpDown_Prm_CurTemp->Value = System::Convert::ToDecimal(sCurTemp)/100;
  441. ForceUpdate();
  442. }
  443. else if(sCurTemp < sMinTemp)
  444. {
  445. sCurTemp = sMinTemp;
  446. this->numericUpDown_Prm_CurTemp->Value = System::Convert::ToDecimal(sCurTemp)/100;
  447. ForceUpdate();
  448. }
  449. }
  450. else
  451. {
  452. // If the values were invalid, set numeric values to last valid values
  453. this->numericUpDown_Prm_MinTemp->Value = System::Convert::ToDecimal(sMinTemp)/100;
  454. this->numericUpDown_Prm_MaxTemp->Value = System::Convert::ToDecimal(sMaxTemp)/100;
  455. }
  456. }
  457. /**************************************************************************
  458. * TemperatureSensor::numericUpDown_Prm_24HrHighLow_ValueChanged
  459. *
  460. * Updates the 24Hr Low and 24Hr High variable when the user
  461. * changes the value in the box
  462. *
  463. * returns: N/A
  464. *
  465. **************************************************************************/
  466. void TemperatureSensor::numericUpDown_Prm_24HrHighLow_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  467. {
  468. TemperatureData->s24HrHigh = System::Convert::ToInt16((this->numericUpDown_Prm_24HrHigh->Value)*10);
  469. TemperatureData->s24HrLow = System::Convert::ToInt16((this->numericUpDown_Prm_24HrLow->Value)*10);
  470. ForceUpdate();
  471. }
  472. /**************************************************************************
  473. * TemperatureSensor::radioButton_Time_CheckedChanged
  474. *
  475. * Updates TxInfo (only 4hz version currently) bitfield regarding time capabilities
  476. * for use in data page 0
  477. *
  478. * returns: N/A
  479. *
  480. **************************************************************************/
  481. void TemperatureSensor::radioButton_Time_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  482. {
  483. if(this->radioButton_UTCTime_NotSupported->Checked)
  484. {
  485. TemperatureData->ucTxInfo = TemperatureData->TXINFO_P5HZ | TemperatureData->UTC_TIME_NOT_SUPPORTED;
  486. }
  487. else if(this->radioButton_UTCTime_NotSet->Checked)
  488. {
  489. TemperatureData->ucTxInfo = TemperatureData->TXINFO_P5HZ | TemperatureData->UTC_TIME_NOT_SET;
  490. }
  491. else
  492. {
  493. TemperatureData->ucTxInfo = TemperatureData->TXINFO_P5HZ | TemperatureData->UTC_TIME_SET;
  494. }
  495. if(this->radioButton_LocalTime_NotSupported->Checked)
  496. {
  497. TemperatureData->ucTxInfo |= TemperatureData->LOCAL_TIME_NOT_SUPPORTED;
  498. }
  499. else if(this->radioButton_LocalTime_NotSet->Checked)
  500. {
  501. TemperatureData->ucTxInfo |= TemperatureData->LOCAL_TIME_NOT_SET;
  502. }
  503. else
  504. {
  505. TemperatureData->ucTxInfo |= TemperatureData->LOCAL_TIME_SET;
  506. }
  507. }
  508. /**************************************************************************
  509. * TemperatureSensor::checkBox_Bat_Status_CheckedChanged
  510. *
  511. * Enables and disables the battery voltage GUI elements
  512. *
  513. * returns: N/A
  514. *
  515. **************************************************************************/
  516. void TemperatureSensor::checkBox_Bat_Status_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  517. {
  518. if (this->checkBox_Bat_Status->Checked == TRUE)
  519. {
  520. commonData->bBattPageEnabled = TRUE;
  521. this->comboBoxBatStatus->Enabled = TRUE;
  522. this->label_Bat_ElpTimeDisplay->Enabled = TRUE;
  523. this->textBox_Bat_ElpTimeChange->Enabled = TRUE;
  524. this->checkBox_Bat_Voltage->Enabled = TRUE;
  525. this->checkBox_Bat_Voltage->Checked = TRUE;
  526. this->numericUpDown_Bat_VoltFrac->Enabled = TRUE;
  527. this->numericUpDown_Bat_VoltInt->Enabled = TRUE;
  528. this->groupBox_Resol->Enabled = TRUE;
  529. this->button_Bat_ElpTimeUpdate->Enabled = TRUE;
  530. // update the variables
  531. UpdateBatStatus();
  532. if (this->radioButton_Bat_Elp16Units->Checked)
  533. commonData->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
  534. if (this->radioButton_Bat_Elp2Units->Checked)
  535. commonData->eTimeResolution = CommonData::TimeResolution::TWO;
  536. commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
  537. commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
  538. commonData->usBatVoltage256 |= System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
  539. }
  540. else
  541. {
  542. commonData->bBattPageEnabled = FALSE;
  543. this->comboBoxBatStatus->Enabled = FALSE;
  544. this->label_Bat_ElpTimeDisplay->Enabled = FALSE;
  545. this->textBox_Bat_ElpTimeChange->Enabled = FALSE;
  546. this->checkBox_Bat_Voltage->Enabled = FALSE;
  547. this->checkBox_Bat_Voltage->Checked = FALSE;
  548. this->numericUpDown_Bat_VoltFrac->Enabled = FALSE;
  549. this->numericUpDown_Bat_VoltInt->Enabled = FALSE;
  550. this->groupBox_Resol->Enabled = FALSE;
  551. this->button_Bat_ElpTimeUpdate->Enabled = FALSE;
  552. }
  553. }
  554. /**************************************************************************
  555. * TemperatureSensor::checkBox_Bat_Voltage_CheckedChanged
  556. *
  557. * Enables and disables the battery voltage numeric upDown
  558. *
  559. * returns: N/A
  560. *
  561. **************************************************************************/
  562. void TemperatureSensor::checkBox_Bat_Voltage_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  563. {
  564. if (this->checkBox_Bat_Voltage->Checked == TRUE)
  565. {
  566. this->numericUpDown_Bat_VoltInt->Enabled = TRUE;
  567. this->numericUpDown_Bat_VoltFrac->Enabled = TRUE;
  568. commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
  569. commonData->usBatVoltage256 |= System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
  570. }
  571. else
  572. {
  573. this->numericUpDown_Bat_VoltInt->Enabled = FALSE;
  574. this->numericUpDown_Bat_VoltFrac->Enabled = FALSE;
  575. commonData->usBatVoltage256 = commonData->BATTERY_VOLTAGE_INVALID;
  576. }
  577. }
  578. /**************************************************************************
  579. * TemperatureSensor::numericUpDown_Bat_VoltInt_ValueChanged
  580. *
  581. * changes the coarse battery voltage
  582. *
  583. * returns: N/A
  584. *
  585. **************************************************************************/
  586. void TemperatureSensor::numericUpDown_Bat_VoltInt_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  587. {
  588. commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
  589. }
  590. /**************************************************************************
  591. * TemperatureSensor::numericUpDown_Bat_VoltFrac_ValueChanged
  592. *
  593. * changes the fractional battery voltage
  594. *
  595. * returns: N/A
  596. *
  597. **************************************************************************/
  598. void TemperatureSensor::numericUpDown_Bat_VoltFrac_ValueChanged(System::Object^ sender, System::EventArgs^ e)
  599. {
  600. commonData->usBatVoltage256 = System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
  601. }
  602. /**************************************************************************
  603. * TemperatureSensor::comboBoxBatStatus_SelectedIndexChanged
  604. *
  605. * changes the battery status
  606. *
  607. * returns: N/A
  608. *
  609. **************************************************************************/
  610. void TemperatureSensor::comboBoxBatStatus_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
  611. {
  612. UpdateBatStatus();
  613. }
  614. /**************************************************************************
  615. * TemperatureSensor::UpdateBatStatus
  616. *
  617. * Updates the battery status
  618. *
  619. * returns: N/A
  620. *
  621. **************************************************************************/
  622. void TemperatureSensor::UpdateBatStatus()
  623. {
  624. if (this->comboBoxBatStatus->Text->Equals("New"))
  625. {
  626. commonData->eBatStatus = CommonData::BatStatus::NEW;
  627. }
  628. else if (this->comboBoxBatStatus->Text->Equals("Good"))
  629. {
  630. commonData->eBatStatus = CommonData::BatStatus::GOOD;
  631. }
  632. else if (this->comboBoxBatStatus->Text->Equals("Ok"))
  633. {
  634. commonData->eBatStatus = CommonData::BatStatus::OK;
  635. }
  636. else if (this->comboBoxBatStatus->Text->Equals("Low"))
  637. {
  638. commonData->eBatStatus = CommonData::BatStatus::LOW;
  639. }
  640. else if (this->comboBoxBatStatus->Text->Equals("Critical"))
  641. {
  642. commonData->eBatStatus = CommonData::BatStatus::CRITICAL;
  643. }
  644. else if (this->comboBoxBatStatus->Text->Equals("Invalid"))
  645. {
  646. commonData->eBatStatus = CommonData::BatStatus::INVALID;
  647. }
  648. }
  649. /**************************************************************************
  650. * TemperatureSensor::button_Bat_ElpTimeUpdate_Click
  651. *
  652. * changes the elapsed battery time
  653. *
  654. * returns: N/A
  655. *
  656. **************************************************************************/
  657. void TemperatureSensor::button_Bat_ElpTimeUpdate_Click(System::Object^ sender, System::EventArgs^ e)
  658. {
  659. ulTotalTime = System::Convert::ToUInt32(this->textBox_Bat_ElpTimeChange->Text);
  660. commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
  661. }
  662. /**************************************************************************
  663. * TemperatureSensor::radioButton_Bat_Elp2Units_CheckedChanged
  664. *
  665. * changes the elapsed battery time units
  666. *
  667. * returns: N/A
  668. *
  669. **************************************************************************/
  670. void TemperatureSensor::radioButton_Bat_Elp2Units_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  671. {
  672. if (this->radioButton_Bat_Elp2Units->Checked)
  673. commonData->eTimeResolution = CommonData::TimeResolution::TWO;
  674. }
  675. /**************************************************************************
  676. * TemperatureSensor::radioButton_Bat_Elp2Units_CheckedChanged
  677. *
  678. * changes the elapsed battery time units
  679. *
  680. * returns: N/A
  681. *
  682. **************************************************************************/
  683. void TemperatureSensor::radioButton_Bat_Elp16Units_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  684. {
  685. if (this->radioButton_Bat_Elp16Units->Checked)
  686. commonData->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
  687. }
  688. /**************************************************************************
  689. * TemperatureSensor::radioButton_Default_4Hz_CheckedChanged
  690. *
  691. * changes the default Tx rate
  692. *
  693. * returns: N/A
  694. *
  695. **************************************************************************/
  696. void TemperatureSensor::radioButton_Default_4Hz_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
  697. {
  698. if(this->radioButton_Default_4Hz->Checked)
  699. {
  700. b4HzDefault = true;
  701. TemperatureData->b4HzRotation = true;TemperatureData->ucTxInfo = TemperatureData->TXINFO_4HZ; // Set initial transmission info (5Hz, 1 page)
  702. TemperatureData->usMessagePeriod = TemperatureData->MESG_4HZ_PERIOD;
  703. requestUpdateMesgPeriod(TemperatureData->MESG_4HZ_PERIOD);
  704. }
  705. else
  706. {
  707. b4HzDefault = false;
  708. TemperatureData->b4HzRotation = false;
  709. TemperatureData->ucTxInfo = TemperatureData->TXINFO_P5HZ; // Set initial transmission info (5Hz, 1 page)
  710. TemperatureData->usMessagePeriod = TemperatureData->MESG_P5HZ_PERIOD;
  711. requestUpdateMesgPeriod(TemperatureData->MESG_P5HZ_PERIOD);
  712. }
  713. }