1
0

CustomDisplay.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "CustomDisplay.h"
  10. /**************************************************************************
  11. * CustomDisplay::ANT_eventNotification
  12. *
  13. * Process ANT channel event
  14. *
  15. * ucEventCode_: code of ANT channel event
  16. * pucEventBuffer_: pointer to buffer containing data received from ANT,
  17. * or a pointer to the transmit buffer in the case of an EVENT_TX
  18. *
  19. * returns: N/A
  20. *
  21. **************************************************************************/
  22. void CustomDisplay::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
  23. {
  24. switch(ucEventCode_)
  25. {
  26. case EVENT_RX_ACKNOWLEDGED:
  27. case EVENT_RX_BURST_PACKET: // intentional fall thru
  28. case EVENT_RX_BROADCAST:
  29. HandleReceive((UCHAR*) pucEventBuffer_);
  30. break;
  31. default:
  32. break;
  33. }
  34. }
  35. /**************************************************************************
  36. * CustomDisplay::InitializeSim
  37. *
  38. * Initializes simulator variables
  39. *
  40. * returns: N/A
  41. *
  42. **************************************************************************/
  43. void CustomDisplay::InitializeSim()
  44. {
  45. ulEventCounter = 0;
  46. bSendHex = FALSE;
  47. }
  48. /**************************************************************************
  49. * CustomDisplay::HandleReceive
  50. *
  51. * Since custom data does not follow a particular format, it is displayed
  52. * as received
  53. *
  54. * pucRxBuffer_: pointer to the buffer containing the received data
  55. *
  56. * returns: N/A
  57. *
  58. **************************************************************************/
  59. void CustomDisplay::HandleReceive(UCHAR* pucRxBuffer_){
  60. UCHAR i;
  61. System::String^ tempc;
  62. System::String^ temph;
  63. System::String^ tempi;
  64. for(i=0; i<8; ++i){
  65. tempc = System::String::Concat(tempc,System::Convert::ToChar(pucRxBuffer_[i])); // char
  66. temph = System::String::Concat(temph,"[",System::Convert::ToString(pucRxBuffer_[i],16),"]"); // hex
  67. tempi = System::String::Concat(tempi,"[",pucRxBuffer_[i].ToString(),"]"); // decimal
  68. }
  69. this->label_Calc_AsChar->Text = tempc;
  70. this->label_Calc_AsHex->Text = temph;
  71. this->label_Calc_AsInt->Text = tempi;
  72. }
  73. /**************************************************************************
  74. * CustomDisplay::radioButton_TranslateSelect_CheckedChanged
  75. *
  76. * Selects format of input box for message to send: Hex/Char
  77. *
  78. * pucRxBuffer_: pointer to the buffer containing the received data
  79. *
  80. * returns: N/A
  81. *
  82. **************************************************************************/
  83. System::Void CustomDisplay::radioButton_TranslateSelect_CheckedChanged(System::Object^ sender, System::EventArgs^ e){
  84. if(this->radioButton_asChar->Checked){
  85. this->textBox_customTxData->Text = "Max8Char";
  86. this->textBox_customTxData->MaxLength = 8;
  87. bSendHex = FALSE;
  88. }
  89. else if(this->radioButton_asHex->Checked){
  90. this->textBox_customTxData->Text = "00,00,00,00,00,00,00,00";
  91. this->textBox_customTxData->MaxLength = 23;
  92. bSendHex = TRUE;
  93. }
  94. }
  95. /**************************************************************************
  96. * CustomDisplay::button_SendAck_Click
  97. *
  98. * Validates and sends user data as an acknowledged messaage
  99. *
  100. * pucRxBuffer_: pointer to the buffer containing the received data
  101. *
  102. * returns: N/A
  103. *
  104. **************************************************************************/
  105. System::Void CustomDisplay::button_SendAck_Click(System::Object^ sender, System::EventArgs^ e){
  106. UCHAR i;
  107. UCHAR aucTxBuffer[8] = {0,0,0,0,0,0,0,0};
  108. // Validate data is not an empty string
  109. if(System::String::IsNullOrEmpty(this->textBox_customTxData->Text))
  110. {
  111. this->textBox_customTxData->Text = "Invalid Input, try again";
  112. return;
  113. }
  114. if(!bSendHex)
  115. {
  116. // Parse char string
  117. UCHAR ucTextLength = textBox_customTxData->Text->Length;
  118. for(i=0; i < ucTextLength; ++i)
  119. aucTxBuffer[i] = (UCHAR)textBox_customTxData->Text[i];
  120. while(i<8)
  121. aucTxBuffer[i++] = 0x00;
  122. }
  123. else
  124. {
  125. // Parse hex couplets
  126. array<System::String^>^ hexes = this->textBox_customTxData->Text->Split(',');
  127. UCHAR ucHexesLength = hexes->Length;
  128. try{
  129. if(ucHexesLength >8)
  130. throw "Too many commas";
  131. for(i=0; i<ucHexesLength; ++i)
  132. {
  133. if(hexes[i]->Length >2)
  134. throw "Incorrect couplet format";
  135. aucTxBuffer[i] = Byte::Parse(hexes[i],System::Globalization::NumberStyles::HexNumber);
  136. }
  137. while(i<8)
  138. aucTxBuffer[i++] = 0x00;
  139. }
  140. catch(...){
  141. this->textBox_customTxData->Text = "Invalid Input, try again";
  142. for(i=0; i<8; ++i)
  143. aucTxBuffer[i] = 0x00;
  144. return;
  145. }
  146. }
  147. requestAckMsg(aucTxBuffer);
  148. }