form_BT.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:232k
源码类别:

MTK

开发平台:

C++ Builder

  1. //--------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. // BT
  5. #ifndef  _BT_HCI_COMMON_H_
  6. #include "bt_hci_common.h"
  7. #endif
  8. #ifndef  _BT_POWER_H_
  9. #include "bt_power.h"
  10. #endif
  11. // form
  12. #ifndef _FORM_BT_H_
  13. #include "form_BT.h"
  14. #endif
  15. #ifndef _FORM_MAIN_H_
  16. #include "form_main.h"
  17. #endif
  18. // misc
  19. #ifndef  _MISC_BT_H_
  20. #include "misc_bt.h"
  21. #endif
  22. #ifndef  _FT_UTILS_H_
  23. #include "ft_utils.h"
  24. #endif
  25. #ifndef  _FILE_UTILS_H_
  26. #include "file_utils.h"
  27. #endif
  28. #ifndef  _TIME_UTILS_H_
  29. #include "time_utils.h"
  30. #endif
  31. // MF_Setup
  32. #ifndef  _MFSETUPUTIL_H_
  33. #include "mfsetuputil.h"
  34. #endif
  35. // message
  36. #ifndef _META_LAB_MSG_H_
  37. #include "meta_lab_msg.h"
  38. #endif
  39. // security
  40. #ifndef _SLA_CHALLENGE_H_
  41. #include "sla_challenge.h"
  42. #endif
  43. // EDGE PC card
  44. #ifndef  _PCMCIA_POWER_H_
  45. #include "pcmcia_power.h"
  46. #endif
  47. //---------------------------------------------------------------------------
  48. #define DRAW_MASK_HCI_CATEGORY  0x01
  49. #define DRAW_MASK_HCI_GROUP     0x02
  50. #define DRAW_MASK_HCI_COMMAND   0x04
  51. #define DRAW_MASK_HCI_PARAMETER 0x08
  52. #define HCI_NAME_COL_IDX       0
  53. #define HCI_BYTE_COL_IDX       1
  54. #define HCI_VALUE_COL_IDX      2
  55. //---------------------------------------------------------------------------
  56. #pragma package(smart_init)
  57. #pragma resource "*.dfm"
  58. TfrmBT *frmBT;
  59. extern bool g_bHideEnable;
  60. //---------------------------------------------------------------------------
  61. static void ConfirmCallback_HCI(void)
  62. {
  63.     frmBT->ConfirmCallback_HCI();
  64. }
  65. //---------------------------------------------------------------------------
  66. static void ConfirmCallback_SetupHCIFile(void)
  67. {
  68.     frmBT->ConfirmCallback_SetupHCIFile();
  69. }
  70. //---------------------------------------------------------------------------
  71. static void ConfirmCallback_RFTX(void)
  72. {
  73.     frmBT->ConfirmCallback_RFTX();
  74. }
  75. //---------------------------------------------------------------------------
  76. static void ConfirmCallback_RFRX(void)
  77. {
  78.     frmBT->ConfirmCallback_RFRX();
  79. }
  80. //---------------------------------------------------------------------------
  81. static void ConfirmCallback_RFEnterTestMode(void)
  82. {
  83.     frmBT->ConfirmCallback_RFEnterTestMode();
  84. }
  85. //---------------------------------------------------------------------------
  86. static void CNF_PKT(void)
  87. {
  88.     frmBT->CNF_PKT();
  89. }
  90. //---------------------------------------------------------------------------
  91. static void CNF_PKT_Stop(void)
  92. {
  93.     frmBT->CNF_PKT_Stop();
  94. }
  95. //---------------------------------------------------------------------------
  96. static void CNF_PKT_TCI(void)
  97. {   frmBT->CNF_PKT_TCI();
  98. }
  99. //---------------------------------------------------------------------------
  100. static void CNF_PKT_Read_TxRxCount( void )
  101. {   frmBT->CNF_PKT_Read_TxRxCount();
  102. }
  103. //---------------------------------------------------------------------------
  104. static void CNF_PKT_Read_EDRTxRxCount(void)
  105. {
  106.     frmBT->CNF_PKT_Read_EDRTxRxCount();
  107. }
  108. //---------------------------------------------------------------------------
  109. static void ConfirmCallback_SetupSCTFile( void )
  110. {   frmBT->ConfirmCallback_SetupSCTFile();
  111. }
  112. //---------------------------------------------------------------------------
  113. static void ConfirmCallback_SCT( void )
  114. {   frmBT->ConfirmCallback_SCT();
  115. }
  116. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. static void  ConfirmCallback_QueryBDAddress( void )
  118. {   frmBT->ConfirmCallback_QueryBDAddress();
  119. }
  120. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. static void ConfirmCallback_ChangePCL( void )
  122. {   frmBT->ConfirmCallback_ChangePCL();
  123. }
  124. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. static void CNF_CT_ReadLocalBDAddr( void )
  126. {   frmBT->CNF_CT_ReadLocalBDAddr();
  127. }
  128. //---------------------------------------------------------------------------
  129. static void CNF_CT_WriteLocalBDAddr( void )
  130. {   frmBT->CNF_CT_WriteLocalBDAddr();
  131. }
  132. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  133. static void  CNF_CT_Reset( void )
  134. {   frmBT->CNF_CT_Reset();
  135. }
  136. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. static void  CNF_CT_Scan( void )
  138. {   frmBT->CNF_CT_Scan();
  139. }
  140. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. static void CNF_CT_AutoAccept( void )
  142. {   frmBT->CNF_CT_AutoAccept();
  143. }
  144. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. static void  CNF_CT_Inquiry( void )
  146. {   frmBT->CNF_CT_Inquiry();
  147. }
  148. //---------------------------------------------------------------------------
  149. static void  CNF_CT_InquiryCancel( void )
  150. {   frmBT->CNF_CT_InquiryCancel();
  151. }
  152. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153. static void  CNF_CT_EnterPIN( void )
  154. {   frmBT->CNF_CT_EnterPIN();
  155. }
  156. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157. static void  CNF_CT_ConnectACL( void )
  158. {   frmBT->CNF_CT_ConnectACL();
  159. }
  160. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. static void CNF_CT_DisconnectACL( void )
  162. {   frmBT->CNF_CT_DisconnectACL();
  163. }
  164. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165. static void  CNF_CT_ChangeACLPacketType( void )
  166. {   frmBT->CNF_CT_ChangeACLPacketType();
  167. }
  168. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169. static void  CNF_CT_ConnectSCO(void)
  170. {
  171.     frmBT->CNF_CT_ConnectSCO();
  172. }
  173. //---------------------------------------------------------------------------
  174. static void CNF_CT_DisconnectSCO(void)
  175. {
  176.     frmBT->CNF_CT_DisconnectSCO();
  177. }
  178. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179. static void  CNF_TT_Scan(void)
  180. {   frmBT->CNF_TT_Scan();
  181. }
  182. //---------------------------------------------------------------------------
  183. static void  CNF_TT_AutoAccept( void )
  184. {   frmBT->CNF_TT_AutoAccept();
  185. }
  186. //---------------------------------------------------------------------------
  187. static void  CNF_TT_ConnectACL( void )
  188. {   frmBT->CNF_TT_ConnectACL();
  189. }
  190. //---------------------------------------------------------------------------
  191. static void  CNF_TT_DisconnectACL( void )
  192. {   frmBT->CNF_TT_DisconnectACL();
  193. }
  194. //---------------------------------------------------------------------------
  195. static void  CNF_TT_ChangeACLPacketType( void )
  196. {   frmBT->CNF_TT_ChangeACLPacketType();
  197. }
  198. //---------------------------------------------------------------------------
  199. static void  CNF_TT_TxData( void )
  200. {   frmBT->CNF_TT_TxData();
  201. }
  202. //--------------------------------------------------------------------------
  203. static void  CNF_TT_RxData(void)
  204. {  frmBT->CNF_TT_RxData();
  205. }
  206. //---------------------------------------------------------------------------
  207. static void  CNF_TT_Stop_RxData(void)
  208. {  frmBT->CNF_TT_Stop_RxData();
  209. }
  210. //---------------------------------------------------------------------------
  211. __fastcall TfrmBT::TfrmBT(TComponent* Owner)
  212.         : TForm(Owner)
  213. {
  214.     // RF test
  215.     m_edtRFTxAccessCode[0] = edtRFTxAccessCode0;
  216.     m_edtRFTxAccessCode[1] = edtRFTxAccessCode1;
  217.     m_edtRFTxAccessCode[2] = edtRFTxAccessCode2;
  218.     m_edtRFTxAccessCode[3] = edtRFTxAccessCode3;
  219.     m_edtRFTxAccessCode[4] = edtRFTxAccessCode4;
  220.     m_edtRFTxAccessCode[5] = edtRFTxAccessCode5;
  221.     m_edtRFTxAccessCode[6] = edtRFTxAccessCode6;
  222.     m_edtRFTxAccessCode[7] = edtRFTxAccessCode7;
  223.    // m_edtRFNAP[0] = edtRFNAP0;
  224.    // m_edtRFNAP[1] = edtRFNAP1;
  225.    // m_edtRFNAP[2] = edtRFNAP2;
  226.    // m_edtRFNAP[3] = edtRFNAP3;
  227.    // m_edtRFUAP[0] = edtRFUAP0;
  228.    // m_edtRFUAP[1] = edtRFUAP1;
  229.    // m_edtRFLAP[0] = edtRFLAP0;
  230.    // m_edtRFLAP[1] = edtRFLAP1;
  231.    // m_edtRFLAP[2] = edtRFLAP2;
  232.    // m_edtRFLAP[3] = edtRFLAP3;
  233.    // m_edtRFLAP[4] = edtRFLAP4;
  234.    // m_edtRFLAP[5] = edtRFLAP5;
  235.     // Packet test
  236.     m_cbPKTType[0]  = cbPKTDM1;
  237.     m_cbPKTType[1]  = cbPKTDH1;
  238.     m_cbPKTType[2]  = cbPKTDM3;
  239.     m_cbPKTType[3]  = cbPKTDH3;
  240.     m_cbPKTType[4]  = cbPKTDM5;
  241.     m_cbPKTType[5]  = cbPKTDH5;
  242.     m_cbPKTType[6]  = cbPKTHV1;
  243.     m_cbPKTType[7]  = cbPKTHV2;
  244.     m_cbPKTType[8]  = cbPKTHV3;
  245.     m_cbPKTType[9] = cbPKTEV3;
  246.     m_cbPKTType[10] = cbPKTEV4;
  247.     m_cbPKTType[11] = cbPKTEV5;
  248.     m_cbPKTType[12] = cbPK2DH1;
  249.     m_cbPKTType[13] = cbPK2EV3;
  250.     m_cbPKTType[14] = cbPK2DH3;
  251.     m_cbPKTType[15] = cbPK2EV5;
  252.     m_cbPKTType[16] = cbPK2DH5;
  253.     m_cbPKTType[17] = cbPK3EV3;
  254.     m_cbPKTType[18] = cbPK3DH1;
  255.     m_cbPKTType[19] = cbPK3DH3;
  256.     m_cbPKTType[20] = cbPK3EV5;
  257.     m_cbPKTType[21] = cbPK3DH5;
  258.     m_edtPKTDataLen[0]  = edtPKTDM1DataLen;
  259.     m_edtPKTDataLen[1]  = edtPKTDH1DataLen;
  260.     m_edtPKTDataLen[2]  = edtPKTDM3DataLen;
  261.     m_edtPKTDataLen[3]  = edtPKTDH3DataLen;
  262.     m_edtPKTDataLen[4]  = edtPKTDM5DataLen;
  263.     m_edtPKTDataLen[5]  = edtPKTDH5DataLen;
  264.     m_edtPKTPollPeriod[0]  = edtPKTDM1PollPeriod;
  265.     m_edtPKTPollPeriod[1]  = edtPKTDH1PollPeriod;
  266.     m_edtPKTPollPeriod[2]  = edtPKTDM3PollPeriod;
  267.     m_edtPKTPollPeriod[3]  = edtPKTDH3PollPeriod;
  268.     m_edtPKTPollPeriod[4]  = edtPKTDM5PollPeriod;
  269.     m_edtPKTPollPeriod[5]  = edtPKTDH5PollPeriod;
  270.     m_edtPKTPollPeriod[6]  = edtPKTHV1PollPeriod;
  271.     m_edtPKTPollPeriod[7]  = edtPKTHV2PollPeriod;
  272.     m_edtPKTPollPeriod[8]  = edtPKTHV3PollPeriod;
  273.     m_edtPKTPollPeriod[9] = edtPKTEV3PollPeriod;
  274.     m_edtPKTPollPeriod[10] = edtPKTEV4PollPeriod;
  275.     m_edtPKTPollPeriod[11] = edtPKTEV5PollPeriod;
  276.     m_edtPKTPollPeriod[12] = edtPKT2DH1PollPeriod;
  277.     m_edtPKTPollPeriod[13] = edtPKT2EV3PollPeriod;
  278.     m_edtPKTPollPeriod[14] = edtPKT2DH3PollPeriod;
  279.     m_edtPKTPollPeriod[15] = edtPKT2EV5PollPeriod;
  280.     m_edtPKTPollPeriod[16] = edtPKT2DH5PollPeriod;
  281.     m_edtPKTPollPeriod[17] = edtPKT3EV3PollPeriod;
  282.     m_edtPKTPollPeriod[18] = edtPKT3DH1PollPeriod;
  283.     m_edtPKTPollPeriod[19] = edtPKT3DH3PollPeriod;
  284.     m_edtPKTPollPeriod[20] = edtPKT3EV5PollPeriod;
  285.     m_edtPKTPollPeriod[21] = edtPKT3DH5PollPeriod;
  286.     m_edtPKTPktCount[0]  = edtPKTDM1PktCount;
  287.     m_edtPKTPktCount[1]  = edtPKTDH1PktCount;
  288.     m_edtPKTPktCount[2]  = edtPKTDM3PktCount;
  289.     m_edtPKTPktCount[3]  = edtPKTDH3PktCount;
  290.     m_edtPKTPktCount[4]  = edtPKTDM5PktCount;
  291.     m_edtPKTPktCount[5]  = edtPKTDH5PktCount;
  292.     m_edtPKTPktCount[6]  = edtPKTHV1PktCount;
  293.     m_edtPKTPktCount[7]  = edtPKTHV2PktCount;
  294.     m_edtPKTPktCount[8]  = edtPKTHV3PktCount;
  295.     m_edtPKTPktCount[9] = edtPKTEV3PktCount;
  296.     m_edtPKTPktCount[10] = edtPKTEV4PktCount;
  297.     m_edtPKTPktCount[11] = edtPKTEV5PktCount;
  298.     m_edtPKTPktCount[12] = edtPKT2DH1PktCount;
  299.     m_edtPKTPktCount[13] = edtPKT2EV3PktCount;
  300.     m_edtPKTPktCount[14] = edtPKT2DH3PktCount;
  301.     m_edtPKTPktCount[15] = edtPKT2EV5PktCount;
  302.     m_edtPKTPktCount[16] = edtPKT2DH5PktCount;
  303.     m_edtPKTPktCount[17] = edtPKT3EV3PktCount;
  304.     m_edtPKTPktCount[18] = edtPKT3DH1PktCount;
  305.     m_edtPKTPktCount[19] = edtPKT3DH3PktCount;
  306.     m_edtPKTPktCount[20] = edtPKT3EV5PktCount;
  307.     m_edtPKTPktCount[21] = edtPKT3DH5PktCount;
  308.     m_edtPKTTesterTXCount[0]  = edtPKTTesterDM1TXCount;
  309.     m_edtPKTTesterTXCount[1]  = edtPKTTesterDH1TXCount;
  310.     m_edtPKTTesterTXCount[2]  = edtPKTTesterDM3TXCount;
  311.     m_edtPKTTesterTXCount[3]  = edtPKTTesterDH3TXCount;
  312.     m_edtPKTTesterTXCount[4]  = edtPKTTesterDM5TXCount;
  313.     m_edtPKTTesterTXCount[5]  = edtPKTTesterDH5TXCount;
  314.     m_edtPKTTesterTXCount[6]  = edtPKTTesterHV1TXCount;
  315.     m_edtPKTTesterTXCount[7]  = edtPKTTesterHV2TXCount;
  316.     m_edtPKTTesterTXCount[8]  = edtPKTTesterHV3TXCount;
  317.     m_edtPKTTesterTXCount[9]  = edtPKTTesterEV3TXCount;
  318.     m_edtPKTTesterTXCount[10] = edtPKTTesterEV4TXCount;
  319.     m_edtPKTTesterTXCount[11] = edtPKTTesterEV5TXCount;
  320.     m_edtPKTTesterTXCount[12] = edtPKTTester2DH1TXCount;
  321.     m_edtPKTTesterTXCount[13] = edtPKTTester2EV3TXCount;
  322.     m_edtPKTTesterTXCount[14] = edtPKTTester2DH3TXCount;
  323.     m_edtPKTTesterTXCount[15] = edtPKTTester2EV5TXCount;
  324.     m_edtPKTTesterTXCount[16] = edtPKTTester2DH5TXCount;
  325.     m_edtPKTTesterTXCount[17] = edtPKTTester3EV3TXCount;
  326.     m_edtPKTTesterTXCount[18] = edtPKTTester3DH1TXCount;
  327.     m_edtPKTTesterTXCount[19] = edtPKTTester3DH3TXCount;
  328.     m_edtPKTTesterTXCount[20] = edtPKTTester3EV5TXCount;
  329.     m_edtPKTTesterTXCount[21] = edtPKTTester3DH5TXCount;
  330.     m_edtPKTTesterRXCount[0]  = edtPKTTesterDM1RXCount;
  331.     m_edtPKTTesterRXCount[1]  = edtPKTTesterDH1RXCount;
  332.     m_edtPKTTesterRXCount[2]  = edtPKTTesterDM3RXCount;
  333.     m_edtPKTTesterRXCount[3]  = edtPKTTesterDH3RXCount;
  334.     m_edtPKTTesterRXCount[4]  = edtPKTTesterDM5RXCount;
  335.     m_edtPKTTesterRXCount[5]  = edtPKTTesterDH5RXCount;
  336.     m_edtPKTTesterRXCount[6]  = edtPKTTesterHV1RXCount;
  337.     m_edtPKTTesterRXCount[7]  = edtPKTTesterHV2RXCount;
  338.     m_edtPKTTesterRXCount[8]  = edtPKTTesterHV3RXCount;
  339.     m_edtPKTTesterRXCount[9]  = edtPKTTesterEV3RXCount;
  340.     m_edtPKTTesterRXCount[10] = edtPKTTesterEV4RXCount;
  341.     m_edtPKTTesterRXCount[11] = edtPKTTesterEV5RXCount;
  342.     m_edtPKTTesterRXCount[12] = edtPKTTester2DH1RXCount;
  343.     m_edtPKTTesterRXCount[13] = edtPKTTester2EV3RXCount;
  344.     m_edtPKTTesterRXCount[14] = edtPKTTester2DH3RXCount;
  345.     m_edtPKTTesterRXCount[15] = edtPKTTester2EV5RXCount;
  346.     m_edtPKTTesterRXCount[16] = edtPKTTester2DH5RXCount;
  347.     m_edtPKTTesterRXCount[17] = edtPKTTester3EV3RXCount;
  348.     m_edtPKTTesterRXCount[18] = edtPKTTester3DH1RXCount;
  349.     m_edtPKTTesterRXCount[19] = edtPKTTester3DH3RXCount;
  350.     m_edtPKTTesterRXCount[20] = edtPKTTester3EV5RXCount;
  351.     m_edtPKTTesterRXCount[21] = edtPKTTester3DH5RXCount;
  352.     m_edtPKTDUTTXCount[0]  = edtPKTDUTDM1TXCount;
  353.     m_edtPKTDUTTXCount[1]  = edtPKTDUTDH1TXCount;
  354.     m_edtPKTDUTTXCount[2]  = edtPKTDUTDM3TXCount;
  355.     m_edtPKTDUTTXCount[3]  = edtPKTDUTDH3TXCount;
  356.     m_edtPKTDUTTXCount[4]  = edtPKTDUTDM5TXCount;
  357.     m_edtPKTDUTTXCount[5]  = edtPKTDUTDH5TXCount;
  358.     m_edtPKTDUTTXCount[6]  = edtPKTDUTHV1TXCount;
  359.     m_edtPKTDUTTXCount[7]  = edtPKTDUTHV2TXCount;
  360.     m_edtPKTDUTTXCount[8]  = edtPKTDUTHV3TXCount;
  361.     m_edtPKTDUTTXCount[9]  = edtPKTDUTEV3TXCount;
  362.     m_edtPKTDUTTXCount[10] = edtPKTDUTEV4TXCount;
  363.     m_edtPKTDUTTXCount[11] = edtPKTDUTEV5TXCount;
  364.     m_edtPKTDUTTXCount[12] = edtPKTDUT2DH1TXCount;
  365.     m_edtPKTDUTTXCount[13] = edtPKTDUT2EV3TXCount;
  366.     m_edtPKTDUTTXCount[14] = edtPKTDUT2DH3TXCount;
  367.     m_edtPKTDUTTXCount[15] = edtPKTDUT2EV5TXCount;
  368.     m_edtPKTDUTTXCount[16] = edtPKTDUT2DH5TXCount;
  369.     m_edtPKTDUTTXCount[17] = edtPKTDUT3EV3TXCount;
  370.     m_edtPKTDUTTXCount[18] = edtPKTDUT3DH1TXCount;
  371.     m_edtPKTDUTTXCount[19] = edtPKTDUT3DH3TXCount;
  372.     m_edtPKTDUTTXCount[20] = edtPKTDUT3EV5TXCount;
  373.     m_edtPKTDUTTXCount[21] = edtPKTDUT3DH5TXCount;
  374.     m_edtPKTDUTRXCount[0]  = edtPKTDUTDM1RXCount;
  375.     m_edtPKTDUTRXCount[1]  = edtPKTDUTDH1RXCount;
  376.     m_edtPKTDUTRXCount[2]  = edtPKTDUTDM3RXCount;
  377.     m_edtPKTDUTRXCount[3]  = edtPKTDUTDH3RXCount;
  378.     m_edtPKTDUTRXCount[4]  = edtPKTDUTDM5RXCount;
  379.     m_edtPKTDUTRXCount[5]  = edtPKTDUTDH5RXCount;
  380.     m_edtPKTDUTRXCount[6]  = edtPKTDUTHV1RXCount;
  381.     m_edtPKTDUTRXCount[7]  = edtPKTDUTHV2RXCount;
  382.     m_edtPKTDUTRXCount[8]  = edtPKTDUTHV3RXCount;
  383.     m_edtPKTDUTRXCount[9]  = edtPKTDUTEV3RXCount;
  384.     m_edtPKTDUTRXCount[10] = edtPKTDUTEV4RXCount;
  385.     m_edtPKTDUTRXCount[11] = edtPKTDUTEV5RXCount;
  386.     m_edtPKTDUTRXCount[12] = edtPKTDUT2DH1RXCount;
  387.     m_edtPKTDUTRXCount[13] = edtPKTDUT2EV3RXCount;
  388.     m_edtPKTDUTRXCount[14] = edtPKTDUT2DH3RXCount;
  389.     m_edtPKTDUTRXCount[15] = edtPKTDUT2EV5RXCount;
  390.     m_edtPKTDUTRXCount[16] = edtPKTDUT2DH5RXCount;
  391.     m_edtPKTDUTRXCount[17] = edtPKTDUT3EV3RXCount;
  392.     m_edtPKTDUTRXCount[18] = edtPKTDUT3DH1RXCount;
  393.     m_edtPKTDUTRXCount[19] = edtPKTDUT3DH3RXCount;
  394.     m_edtPKTDUTRXCount[20] = edtPKTDUT3EV5RXCount;
  395.     m_edtPKTDUTRXCount[21] = edtPKTDUT3DH5RXCount;
  396.     m_pT_CWT = NULL;
  397.     // module test
  398.     lblItem[ 0] = lblItem1;   lblItem[10] = lblItem11;   lblItem[20] = lblItem21;
  399.     lblItem[ 1] = lblItem2;   lblItem[11] = lblItem12;   lblItem[21] = lblItem22;
  400.     lblItem[ 2] = lblItem3;   lblItem[12] = lblItem13;
  401.     lblItem[ 3] = lblItem4;   lblItem[13] = lblItem14;   m_rbTestItem[0] = m_rbMTTestItem0;
  402.     lblItem[ 4] = lblItem5;   lblItem[14] = lblItem15;   m_rbTestItem[1] = m_rbMTTestItem1;
  403.     lblItem[ 5] = lblItem6;   lblItem[15] = lblItem16;   m_rbTestItem[2] = m_rbMTTestItem2;
  404.     lblItem[ 6] = lblItem7;   lblItem[16] = lblItem17;   m_rbTestItem[3] = m_rbMTTestItem3;
  405.     lblItem[ 7] = lblItem8;   lblItem[17] = lblItem18;   m_rbTestItem[4] = m_rbMTTestItem4;
  406.     lblItem[ 8] = lblItem9;   lblItem[18] = lblItem19;
  407.     lblItem[ 9] = lblItem10;  lblItem[19] = lblItem20;
  408.     for (int n = 0; n < BT_MT_TESTCASE_NUM; n++)
  409.     {
  410.         Script[n] = 0;
  411.     }
  412.     ActIdx = -1;
  413.     m_pvSendHCIPar = NULL;
  414.     m_pvReceiveHCIPar = NULL;
  415.     Init();
  416.     WindowProc = SubClassWndProc;
  417. }
  418. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  419. void TfrmBT::AllocateVector( void )
  420. {
  421.     if( NULL == m_pvSendHCIPar )
  422.         m_pvSendHCIPar    = new vector<S_BT_HCI_PARAMETER>;
  423.     if( NULL == m_pvReceiveHCIPar )
  424.         m_pvReceiveHCIPar = new vector<S_BT_HCI_PARAMETER>;
  425. }
  426. //---------------------------------------------------------------------------
  427. void TfrmBT::DeAllocateVector( void )
  428. {
  429.     if( m_pvSendHCIPar != NULL )
  430.     {
  431.         if( ! m_pvSendHCIPar->empty() )
  432.         {
  433.             m_pvSendHCIPar->erase( m_pvSendHCIPar->begin(), m_pvSendHCIPar->end() );
  434.         }
  435.         delete m_pvSendHCIPar;
  436.     }
  437.     if( m_pvReceiveHCIPar != NULL )
  438.     {
  439.         if( ! m_pvReceiveHCIPar->empty() )
  440.         {
  441.             m_pvReceiveHCIPar->erase( m_pvReceiveHCIPar->begin(), m_pvReceiveHCIPar->end() );
  442.         }
  443.         delete m_pvReceiveHCIPar;
  444.     }
  445. }
  446. //---------------------------------------------------------------------------
  447. void TfrmBT::Init(void)
  448. {
  449.      m_bInit             = true;
  450.      btnHCIStart->Enabled = true;
  451.      btnRFTxStart->Enabled = true;
  452. //     btnRFRxStart->Enabled = true;
  453.      btnPKTStart->Enabled = true;
  454.      btnPKTConnectDUT->Enabled = true;
  455.      m_btnMTConnect->Enabled = m_cbMETAMode->Checked;
  456.      shpPKTConnect->Brush->Color = clRed;
  457.      m_shpMTConnect->Brush->Color = clRed;
  458.      m_bConnectTargetok = false;
  459.      m_bConnectingTarget = false;
  460. }
  461. //---------------------------------------------------------------------------
  462. void __fastcall TfrmBT::FormHide(TObject *Sender)
  463. {
  464.     m_sCWT.iBootStop = BOOT_STOP;
  465.     AbortConnectWithTarget();
  466. }
  467. //==============================================================================
  468. void _fastcall TfrmBT::SubClassWndProc( Messages::TMessage &Message)
  469. {
  470.     switch ( Message.Msg )
  471.     {
  472.         case WM_ML_BT_BD_ADDRESS_MSG:
  473.         {
  474.             DisplayPKTBDAddress( (E_BT_PACKET_DEVICE_T) Message.WParam );
  475.         }
  476.         break;
  477.         case WM_ML_BT_START_MONITOR_MSG:
  478.         {
  479.             MonitorTimer->Enabled = true; 
  480.         }
  481.         break;
  482. //        case WM_ML_BT_DISPLAY_SCT_UI_MSG:
  483. //        {
  484. //        }
  485. //        break;
  486.         
  487.         case WM_ML_BT_PRINT_MSG:
  488.         {
  489.             switch( (E_BT_PAGEIDX) Message.WParam )
  490.             {
  491.                 case PAGEIDX_BT_HCI:
  492.                 {
  493.                     FillHCIResult();
  494.                 }
  495.                 break;
  496.                 case PAGEIDX_BT_RF:
  497.                 {   FillRFResult();
  498.                 }
  499.                 break;
  500.                 case PAGEIDX_BT_PKT:
  501.                 {   FillPKTResult();
  502.                 }
  503.                 break;
  504.                 case PAGEIDX_BT_SCT:
  505.                 {   FillSCTResult();
  506.                 }
  507.                 break;
  508.                 case PAGEIDX_BT_TT:
  509.                 {   FillTTResult();
  510.                 }
  511.                 break;
  512.                 case PAGEIDX_BT_CT:
  513.                 {   FillCTResult();
  514.                 }
  515.                 break;
  516.             }
  517.         }
  518.         break;
  519.         case WM_ML_BT_PIN_MSG:
  520.         {
  521.             btnCTEnterPIN->Enabled = true;
  522.             ShowHintLabel( edtCTPIN, "Please enter PIN code" );
  523.         }
  524.         break;
  525.         case MW_ML_BT_CONNECT_MSG:
  526.         {
  527.             switch( (E_BT_PAGEIDX) Message.WParam )
  528.             {
  529.                 case PAGEIDX_BT_CT:
  530.                 {
  531.                     ReDrawCTFields( DRAM_MASK_CT_DISCOVERED_LIST |
  532.                                     DRAM_MASK_CT_CONNECT_LIST    |
  533.                                     DRAM_MASK_CT_ACL_STATUS      |
  534.                                     DRAM_MASK_CT_BUTTON );
  535.                     sbCT->Panels->Items[0]->Text = (AnsiString)"  Connect from remote BT device";
  536.                 }
  537.                 break;
  538.                 case PAGEIDX_BT_TT:
  539.                 {
  540.                     m_sBTTTRes = m_cBT_TT_Obj.Get_TTResult();
  541.                     ReDrawTTFields( DRAM_MASK_TT_ACL_STATUS      |
  542.                                     DRAM_MASK_TT_BUTTON );
  543.                     sbTT->Panels->Items[0]->Text = (AnsiString)"  Connect from remote BT device";
  544.                 }
  545.                 break;
  546.             }
  547.         }
  548.         break;
  549.         case WM_ML_BT_DISCONNECT_MSG:
  550.         {
  551.             switch( (E_BT_PAGEIDX) Message.WParam )
  552.             {
  553.                 case PAGEIDX_BT_CT:
  554.                 {
  555.                     ReDrawCTFields( DRAM_MASK_CT_DISCOVERED_LIST |
  556.                                     DRAM_MASK_CT_CONNECT_LIST    |
  557.                                     DRAM_MASK_CT_ACL_STATUS      |
  558.                                     DRAM_MASK_CT_BUTTON );
  559.                     sbCT->Panels->Items[0]->Text = (AnsiString)"  Disconnect from remote BT device";
  560.                 }
  561.                 break;
  562.                 case PAGEIDX_BT_TT:
  563.                 {
  564.                     m_sBTTTRes = m_cBT_TT_Obj.Get_TTResult();
  565.                     ReDrawTTFields( DRAM_MASK_TT_ACL_STATUS      |
  566.                                     DRAM_MASK_TT_BUTTON );
  567.                     sbTT->Panels->Items[0]->Text = (AnsiString)"  Disconnect from remote BT device";
  568.                 }
  569.                 break;
  570.             }
  571.         }
  572.         break;
  573.         case WM_ML_BT_TT_TX_STATUS:
  574.         {
  575.             unsigned int ui_pkt_length = (unsigned int) Message.WParam;
  576.             unsigned int ui_used_time;
  577.             if (BT_TT_VER_0 == m_eTtVer)
  578.             {
  579.                 S_TIME time;
  580.                 time = ::Get_CurrentTime();
  581.                 int msec = DifferenceMiniSec(&m_sTTTxStartTime, &time);
  582.                 ui_used_time = (unsigned int) msec;
  583.             }
  584.             else
  585.             {
  586.                 ui_used_time = (unsigned int) Message.LParam;
  587.             }
  588.             if (0 == ui_used_time)
  589.             {
  590.                 return;
  591.             }
  592.             int data_len = edtTTDataLen->Text.ToInt();
  593.             float tx_throughput = 1000.0 * ui_pkt_length / ui_used_time;
  594.             int count = ui_pkt_length/data_len;
  595.             char str[64];
  596.             sprintf(str, "%.3f", tx_throughput);
  597.             stTTTxCount->Caption = IntToStr(count);
  598.             stTTTxThroughput->Caption = (AnsiString) str;
  599.             if (count >= edtTTPacketCount->Text.ToInt())
  600.             {
  601.                 CurrentPageReset();
  602.             }
  603.         }
  604.         break;
  605.         case WM_ML_BT_TT_RX_STATUS:
  606.         {
  607.             unsigned int ui_pkt_length = (unsigned int) Message.WParam;
  608.             unsigned int ui_used_time;
  609.             if (BT_TT_VER_0 == m_eTtVer)
  610.             {
  611.                 S_TIME time;
  612.                 time = ::Get_CurrentTime();
  613.                 int msec = DifferenceMiniSec(&m_sTTRxStartTime, &time);
  614.                 ui_used_time = (unsigned int) msec;
  615.             }
  616.             else
  617.             {
  618.                 ui_used_time = (unsigned int) Message.LParam;
  619.             }
  620.             if (0 == ui_used_time)
  621.             {
  622.                 return;
  623.             }
  624.            // int data_len = edtTTDataLen->Text.ToInt();
  625.             float rx_throughput = 1000.0 * ui_pkt_length / ui_used_time;
  626.             char str[64];
  627.             sprintf(str, "%.3f", rx_throughput);
  628.             stTTRxBytes->Caption = IntToStr(ui_pkt_length);
  629.             stTTRxThroughput->Caption = (AnsiString) str;
  630.         }
  631.         break;
  632.         default:
  633.              this->WndProc( Message );
  634.         break;
  635.     }
  636. }
  637. //===========================================================================
  638. ////////////////////////////  Form event handler   //////////////////////////
  639. //===========================================================================
  640. void __fastcall TfrmBT::FormCreate(TObject *Sender)
  641. {
  642.     m_bFirstFormShow = true;
  643.     // allocate memory
  644.     m_pHCILog = new TStringList;
  645.     m_pRFLog  = new TStringList;
  646.     m_pPKTLog = new TStringList;
  647.     m_pSCTLog = new TStringList;
  648.     m_pCTLog  = new TStringList;
  649.     m_pTTLog  = new TStringList;
  650.     AllocateVector();
  651.     if( rbHCICategory->Checked )
  652.     {
  653.         cbHCICategory->Enabled = true;
  654.         cbHCIGroup->Enabled    = false;
  655.     }
  656.     else
  657.     {
  658.         cbHCICategory->Enabled = false;
  659.         cbHCIGroup->Enabled    = true;
  660.     }
  661.     // RF test
  662.     cbRFTxPattern->ItemIndex = 0;
  663.     // packet test
  664.     cbPKTBaudRate->ItemIndex = 0;
  665.     // throughput test
  666.     m_cbTTScanType->ItemIndex = 3;
  667.     // connection test
  668.     cbCTScanType->ItemIndex = 3;
  669.     m_uiInquiryTimeout = edtCTInquiryTimeout->Text.ToInt() * 1.28 * 1000;
  670.     m_sBTPIN.uc_pin_len = 4;
  671.     for( int i=0; i<m_sBTPIN.uc_pin_len; i++ )
  672.         m_sBTPIN.uc_PIN[i] = '0';
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TfrmBT::FormActivate(TObject *Sender)
  676. {
  677.     if (m_bInit)
  678.     {
  679.         m_bInit = false;
  680.         ApplyHideProperty();
  681.         BT_ModuleID_S* p_bt_module_id = frmMainSel->Get_BTMoudleID();
  682.         m_cBtId = p_bt_module_id->id;
  683.         
  684.         DisplayBtRfTestUi();
  685.         DisplayBtPktTestUi();
  686.         DisplayBtThroughputTestUi();
  687.         DisplayBtConnectionTestUi();
  688.         CBTPOWER BT_POWER_Obj;
  689.         BT_POWER_Obj.REQ_Power_On_Main_BT_Start();
  690.         m_eTtVer = m_cBT_TT_Obj.Query_TtTestVersion();
  691.     }
  692. }
  693. //---------------------------------------------------------------------------
  694. void __fastcall TfrmBT::FormClose(TObject *Sender, TCloseAction &Action)
  695. {
  696.     // HCI file
  697.     SaveHCIFile();
  698.     AbortConnectWithTarget();
  699. }
  700. //---------------------------------------------------------------------------
  701. void __fastcall TfrmBT::FormDestroy(TObject *Sender)
  702. {
  703.     // free memory
  704.     if( m_pHCILog )
  705.         delete  m_pHCILog;
  706.     if( m_pRFLog )
  707.         delete  m_pRFLog;
  708.     if( m_pPKTLog )
  709.         delete  m_pPKTLog;
  710.     if( m_pSCTLog )
  711.         delete  m_pSCTLog;
  712.     if(  m_pTTLog )
  713.         delete  m_pTTLog;
  714.     if( m_pCTLog )
  715.         delete  m_pCTLog;
  716.         
  717.     DeAllocateVector();
  718.     if( m_bConnectTargetok )
  719.     {
  720.         META_ShutDownTarget_r( m_META_HANDLE_Obj.Get_SecondHandle() );
  721.         META_DisconnectWithTarget_r( m_META_HANDLE_Obj.Get_SecondHandle() );
  722.         m_bConnectTargetok = false;
  723.     }
  724.     if( NULL == m_pT_CWT )
  725.         m_sCWT.iBootStop = BOOT_STOP;
  726.     WaitForSingleObject( m_sCWT.METADLL_Connect_Event, 5000 );
  727.     // release handle
  728.     m_META_HANDLE_Obj.REQ_ReleaseSecondHandle_Start();
  729. }
  730. //===========================================================================
  731. void TfrmBT::DisplayBtRfTestUi(void)
  732. {
  733.     cbRFTxType->Clear();
  734.     AnsiString as_nonedr_pkt_name[] =
  735.     {
  736.         "NULL",
  737.         "POLL",
  738.         "FHS",
  739.         "DM1",
  740.         "DH1",
  741.         "HV1",
  742.         "HV2",
  743.         "HV3",
  744.         "DV",
  745.         "AUX",
  746.         "DM3",
  747.         "DH3",
  748.         "DM5",
  749.         "DH5",
  750.         "EV3",
  751.         "EV4",
  752.         "EV5"
  753.     };
  754.     for (int i=0; i<BT_RF_TX_NONEDR_IDX_COUNT; i++)
  755.     {
  756.         cbRFTxType->Items->Add(as_nonedr_pkt_name[i]);
  757.     }
  758.     if (BTMODULE_MT6611 == m_cBtId)
  759.     {
  760.         AnsiString as_edr_pkt_name[] =
  761.         {
  762.             "2-DH1",
  763.             "2-EV3",
  764.             "2-DH3",
  765.             "2-EV5",
  766.             "2-DH5",
  767.             "3-EV3",
  768.             "3-DH1",
  769.             "3-DH3",
  770.             "3-EV5",
  771.             "3-DH5"
  772.         };
  773.         for (int i=0; i<BT_RF_TX_IDX_COUNT-BT_RF_TX_NONEDR_IDX_COUNT; i++)
  774.         {
  775.             cbRFTxType->Items->Add(as_edr_pkt_name[i]);
  776.         }
  777.     }
  778.     cbRFTxType->ItemIndex = 0;
  779. }
  780. //---------------------------------------------------------------------------
  781. void TfrmBT::DisplayBtPktTestUi(void)
  782. {
  783.     bool b_visible = (BTMODULE_MT6611 == m_cBtId);
  784.     for (int i=BT_PACKET_IDX_2DH1; i<BT_PACKET_IDX_COUNT; i++)
  785.     {
  786.         m_cbPKTType[i]->Visible = b_visible;
  787.         m_edtPKTPollPeriod[i]->Visible = b_visible;
  788.         m_edtPKTPktCount[i]->Visible = b_visible;
  789.         m_edtPKTTesterTXCount[i]->Visible = b_visible;
  790.         m_edtPKTTesterRXCount[i]->Visible = b_visible;
  791.         m_edtPKTDUTTXCount[i]->Visible = b_visible;
  792.         m_edtPKTDUTRXCount[i]->Visible = b_visible;
  793.     }
  794. }
  795. //---------------------------------------------------------------------------
  796. void TfrmBT::DisplayBtThroughputTestUi(void)
  797. {
  798.     bool b_eco_support = (BTMODULE_MT6611 == m_cBtId);
  799.     m_cbTT2DH1->Visible = b_eco_support;
  800.     m_cbTT2DH3->Visible = b_eco_support;
  801.     m_cbTT2DH5->Visible = b_eco_support;
  802.     m_cbTT3DH1->Visible = b_eco_support;
  803.     m_cbTT3DH3->Visible = b_eco_support;
  804.     m_cbTT3DH5->Visible = b_eco_support;
  805.     if (b_eco_support)
  806.     {
  807.         edtTTDataLen->Text = "1021";
  808.     }
  809.     else
  810.     {
  811.         edtTTDataLen->Text = "339";
  812.     }
  813. }
  814. //---------------------------------------------------------------------------
  815. void TfrmBT::DisplayBtConnectionTestUi(void)
  816. {
  817.     bool b_edr_support = (BTMODULE_MT6611 == m_cBtId);
  818.     cbCT2DH1->Visible = b_edr_support;
  819.     cbCT2DH3->Visible = b_edr_support;
  820.     cbCT2DH5->Visible = b_edr_support;
  821.     cbCT3DH1->Visible = b_edr_support;
  822.     cbCT3DH3->Visible = b_edr_support;
  823.     cbCT3DH5->Visible = b_edr_support;
  824.     AnsiString as_SCO_NONEDR_PKT[] =
  825.     {
  826.         "HV1",
  827.         "HV2",
  828.         "HV3",
  829.         "EV3",
  830.         "EV4",
  831.         "EV5"
  832.     };
  833.     cbCTSCOPktType->Clear();
  834.     for (int i=0; i<SCO_PKT_NONEDR_IDX_COUNT; i++)
  835.     {
  836.         cbCTSCOPktType->Items->Add(as_SCO_NONEDR_PKT[i]);
  837.     }
  838.     if (b_edr_support)
  839.     {
  840.         AnsiString as_SCO_EDR_PKT[] =
  841.         {
  842.             "2-EV3",
  843.             "3-EV3",
  844.             "2-EV5",
  845.             "3-EV5"
  846.         };
  847.         for (int i=0; i<SCO_PKT_IDX_COUNT-SCO_PKT_IDX_2EV3; i++)
  848.         {
  849.             cbCTSCOPktType->Items->Add(as_SCO_EDR_PKT[i]);
  850.         }
  851.     }    
  852.     cbCTSCOPktType->ItemIndex = 0;
  853. }
  854. //---------------------------------------------------------------------------
  855. void  TfrmBT::CurrentPageReset( void )
  856. {
  857.     switch (m_pctlToolSel->ActivePageIndex)
  858.     {
  859.         case PAGEIDX_BT_HCI:
  860.         {
  861.             btnHCIStart->Enabled = true;
  862.             btnHCIStart->Tag = 0;
  863.         }
  864.         break;
  865.         case PAGEIDX_BT_RF:
  866.         {
  867.             btnRFTxStart->Enabled = true;
  868.             btnRFTxStart->Tag = 0;
  869.            // btnRFRxStart->Enabled = true;
  870.            // btnRFRxStart->Tag = 0;
  871.             btnRFEnterTestMode->Enabled = true;
  872.             btnRFQueryBdAddr->Enabled = true;
  873.             btnRFChangeLevel->Enabled = false;
  874.         }
  875.         break;
  876.         case PAGEIDX_BT_PKT:
  877.         {
  878.             cbPKTDM1->Enabled = true;
  879.             cbPKTDH1->Enabled = true;
  880.             cbPKTDM3->Enabled = true;
  881.             cbPKTDH3->Enabled = true;
  882.             cbPKTDM5->Enabled = true;
  883.             btnPKTConnectDUT->Enabled = true;
  884.             btnPKTStart->Enabled = true;
  885.             btnPKTStart->Tag = 0;
  886.         }
  887.         break;
  888.         case PAGEIDX_BT_SCT:
  889.         {
  890.             btnSCTStart->Enabled = true;
  891.             btnSCTStart->Tag = 0;
  892.         }
  893.         break;
  894.         case PAGEIDX_BT_TT:
  895.         {
  896.             ReDrawTTFields( DRAM_MASK_TT_BUTTON );
  897.         }
  898.         break;
  899.         case PAGEIDX_BT_CT:
  900.         {
  901.             btnCTLDIRead->Enabled = true;
  902.             btnCTLDIWrite->Enabled = true;
  903.             btnCTEnterPIN->Enabled = true;
  904.            // btnCTConnectSCO->Enabled = true;
  905.           //  btnCTScanStart->Enabled = true;
  906.           //  btnCTScanStart->Tag = 0;
  907.             btnCTInquiryStart->Enabled = true;
  908.             btnCTInquiryStart->Tag = 0;
  909.            // btnCTConnect->Enabled = true;
  910.            // btnCTDisconnect->Enabled = true;
  911.            // btnCTChangeAclPktType->Enabled = true;
  912.             btnCTResetLD->Enabled = true;
  913.             ReDrawCTFields( DRAM_MASK_CT_BUTTON );
  914.         }
  915.         break;
  916.     }
  917. }
  918. //---------------------------------------------------------------------------
  919. void  TfrmBT::CurrentPageLock( void )
  920. {
  921.     switch(m_pctlToolSel->ActivePageIndex)
  922.     {
  923.         case PAGEIDX_BT_HCI:
  924.         {   btnHCIStart->Enabled = false;
  925.             btnHCIStart->Tag = 1;
  926.         }
  927.         break;
  928.         case PAGEIDX_BT_RF:
  929.         {
  930.             btnRFTxStart->Enabled = false;
  931.             btnRFTxStart->Tag = 1;
  932.            // btnRFRxStart->Enabled = false;
  933.            // btnRFRxStart->Tag = 1;
  934.             btnRFEnterTestMode->Enabled = false;
  935.             btnRFQueryBdAddr->Enabled = false;
  936.             if( cbRFTxPowerCtrl->Checked )
  937.             {
  938.                 btnRFChangeLevel->Enabled = true;
  939.             }    
  940.         }
  941.         break;
  942.         case PAGEIDX_BT_PKT:
  943.         {
  944.             btnPKTConnectDUT->Enabled = false;
  945.             btnPKTStart->Enabled = false;
  946.             btnPKTStart->Tag = 1;
  947.         }
  948.         break;
  949.         case PAGEIDX_BT_SCT:
  950.         {
  951.             btnSCTStart->Enabled = false;
  952.             btnSCTStart->Tag = 1;
  953.         }
  954.         break;
  955.         case PAGEIDX_BT_TT:
  956.         {
  957.             btnTTScan->Enabled = false;
  958.             btnTTAutoAccept->Enabled = false;
  959.             btnTTConnect->Enabled = false;
  960.             btnTTDisconnect->Enabled = false;
  961.             btnTTChangeACLPacketType->Enabled = false;
  962.             btnTTTxStart->Enabled = false;
  963.             btnTTTxStart->Tag = 1;
  964.             btnTTRxStart->Enabled = false;
  965.             btnTTRxStart->Tag = 1;
  966.         }
  967.         break;
  968.         case PAGEIDX_BT_CT:
  969.         {
  970.             btnCTLDIRead->Enabled = false;
  971.             btnCTLDIWrite->Enabled = false;
  972.             btnCTScan->Enabled = false;
  973.             btnCTAutoAccept->Enabled = false;
  974.             btnCTEnterPIN->Enabled = false;
  975.             btnCTConnectSCO->Enabled = false;
  976.             btnCTDisconnectSCO->Enabled = false;
  977.            // btnCTScanStart->Enabled = false;
  978.            // btnCTScanStart->Tag = 1;
  979.             btnCTInquiryStart->Enabled = false;
  980.             btnCTInquiryStart->Tag = 1;
  981.             btnCTInquiryStart->Enabled = false;
  982.             btnCTConnectACL->Enabled = false;
  983.             btnCTDisconnectACL->Enabled = false;
  984.             btnCTChangeAclPktType->Enabled = false;
  985.             btnCTResetLD->Enabled = false;
  986.         }
  987.         break;
  988.     }
  989. }
  990. //---------------------------------------------------------------------------
  991. bool  TfrmBT::CheckHCIFields( void )
  992. {
  993.     return true;
  994. }
  995. //---------------------------------------------------------------------------
  996. bool  TfrmBT::CheckRFFields( E_CHECK_MASK_RF check_mask )
  997. {
  998.     AnsiString text;
  999.     if( CHECK_MASK_RF_TX == check_mask )
  1000.     {
  1001.         // pattern
  1002.         if( cbRFTxPattern->Text.AnsiCompareIC("0000") == 0 )
  1003.         {   m_sBtRf.e_pattern = BT_TX_ALL_ZEROS;
  1004.         }
  1005.         else if( cbRFTxPattern->Text.AnsiCompareIC("1111") == 0 )
  1006.         {   m_sBtRf.e_pattern = BT_TX_ALL_ONES;
  1007.         }
  1008.         else if( cbRFTxPattern->Text.AnsiCompareIC("1010") == 0 )
  1009.         {   m_sBtRf.e_pattern = BT_TX_ALTER_BITS;
  1010.         }
  1011.         else if( cbRFTxPattern->Text.AnsiCompareIC("1100") == 0 )
  1012.         {   m_sBtRf.e_pattern = BT_TX_ONES_ZEROS;
  1013.         }
  1014.         else if( cbRFTxPattern->Text.AnsiCompareIC("pseudorandom bit sequence") == 0 )
  1015.         {   m_sBtRf.e_pattern = BT_TX_PSEUDO_RANDOM;
  1016.         }
  1017.         else if( cbRFTxPattern->Text.AnsiCompareIC("loopback ACL with whitening") == 0 )
  1018.         {   m_sBtRf.e_pattern = BT_TX_LOOPBACK_ACL_WITH_WHITENING;
  1019.         }
  1020.         else if( cbRFTxPattern->Text.AnsiCompareIC("loopback SCO with whitening") == 0 )
  1021.         {   m_sBtRf.e_pattern = BT_TX_LOOPBACK_SCO_WITH_WHITENING;
  1022.         }
  1023.        // else if( cbRFTxPattern->Text.AnsiCompareIC("loopback ACL without whitening") == 0 )
  1024.        // {   m_sBtRf.e_pattern = BT_TX_LOOPBACK_ACL_WITHOUT_WHITENING;
  1025.        // }
  1026.         else
  1027.         {   m_sBtRf.e_pattern = BT_TX_LOOPBACK_SCO_WITHOUT_WHITENING;
  1028.         }
  1029.     }
  1030.     else
  1031.     {
  1032.         m_sBtRf.e_pattern = BT_RX_TEST;
  1033.     }
  1034.     // whiten
  1035.     if( cbRFTxWhiten->Checked )
  1036.     {   m_sBtRf.e_whiten = BT_TX_WHITEN_ON;
  1037.     }
  1038.     else
  1039.     {   m_sBtRf.e_whiten = BT_TX_WHITEN_OFF;
  1040.     }
  1041.     // freuency type
  1042.     if( rbRFTxSingleFreq->Checked )
  1043.     {
  1044.         m_sBtRf.e_freq_type = BT_FREQ_SINGLE;
  1045.     }
  1046.     else
  1047.     {   m_sBtRf.e_freq_type = BT_FREQ_HOPPING;
  1048.     }
  1049.     // packet
  1050.     if( cbRFTxType->Text.AnsiCompareIC("NULL") == 0 )
  1051.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_NULL;
  1052.     }
  1053.     else if( cbRFTxType->Text.AnsiCompareIC("POLL") == 0 )
  1054.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_POLL;
  1055.     }
  1056.     else if( cbRFTxType->Text.AnsiCompareIC("FHS") == 0 )
  1057.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_FHS;
  1058.     }
  1059.     else if( cbRFTxType->Text.AnsiCompareIC("DM1") == 0 )
  1060.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DM1;
  1061.     }
  1062.     else if( cbRFTxType->Text.AnsiCompareIC("DH1") == 0 )
  1063.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DH1;
  1064.     }
  1065.     else if( cbRFTxType->Text.AnsiCompareIC("HV1") == 0 )
  1066.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_HV1;
  1067.     }
  1068.     else if( cbRFTxType->Text.AnsiCompareIC("HV2") == 0 )
  1069.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_HV2;
  1070.     }
  1071.     else if( cbRFTxType->Text.AnsiCompareIC("HV3") == 0 )
  1072.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_HV3;
  1073.     }
  1074.     else if( cbRFTxType->Text.AnsiCompareIC("DV") == 0 )
  1075.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DV;
  1076.     }
  1077.     else if( cbRFTxType->Text.AnsiCompareIC("AUX") == 0 )
  1078.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_AUX;
  1079.     }
  1080.     else if( cbRFTxType->Text.AnsiCompareIC("DM3") == 0 )
  1081.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DM3;
  1082.     }
  1083.     else if( cbRFTxType->Text.AnsiCompareIC("DH3") == 0 )
  1084.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DH3;
  1085.     }
  1086.     else if( cbRFTxType->Text.AnsiCompareIC("DM5") == 0 )
  1087.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DM5;
  1088.     }
  1089.     else if( cbRFTxType->Text.AnsiCompareIC("DH5") == 0 )
  1090.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_DH5;
  1091.     }
  1092.     else if( cbRFTxType->Text.AnsiCompareIC("EV3") == 0 )
  1093.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_EV3;
  1094.     }
  1095.     else if( cbRFTxType->Text.AnsiCompareIC("EV4") == 0 )
  1096.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_EV4;
  1097.     }
  1098.     else if( cbRFTxType->Text.AnsiCompareIC("EV5") == 0 )
  1099.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_EV5;
  1100.     }
  1101.     else if( cbRFTxType->Text.AnsiCompareIC("2-DH1") == 0 )
  1102.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_2DH1;
  1103.     }
  1104.     else if( cbRFTxType->Text.AnsiCompareIC("2-EV3") == 0 )
  1105.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_2EV3;
  1106.     }
  1107.     else if( cbRFTxType->Text.AnsiCompareIC("2-DH3") == 0 )
  1108.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_2DH3;
  1109.     }
  1110.     else if( cbRFTxType->Text.AnsiCompareIC("2-EV5") == 0 )
  1111.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_2EV5;
  1112.     }
  1113.     else if( cbRFTxType->Text.AnsiCompareIC("2-DH5") == 0 )
  1114.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_2DH5;
  1115.     }
  1116.     else if( cbRFTxType->Text.AnsiCompareIC("3-EV3") == 0 )
  1117.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_3EV3;
  1118.     }
  1119.     else if( cbRFTxType->Text.AnsiCompareIC("3-DH1") == 0 )
  1120.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_3DH1;
  1121.     }
  1122.     else if( cbRFTxType->Text.AnsiCompareIC("3-DH3") == 0 )
  1123.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_3DH3;
  1124.     }
  1125.     else if( cbRFTxType->Text.AnsiCompareIC("3-EV5") == 0 )
  1126.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_3EV5;
  1127.     }
  1128.     else if( cbRFTxType->Text.AnsiCompareIC("3-DH5") == 0 )
  1129.     {   m_sBtRf.e_packet_type = BT_RF_PACKET_3DH5;
  1130.     }
  1131.         // power control
  1132. #if 0
  1133.     }
  1134.     else // RX
  1135.     {
  1136.         // freuency type
  1137.         if( rbRFRxSingleFreq->Checked )
  1138.         {
  1139.             m_sBtRf.e_freq_type = BT_FREQ_SINGLE;
  1140.         }
  1141.         else
  1142.         {   m_sBtRf.e_freq_type = BT_FREQ_HOPPING;
  1143.         }
  1144.         // packet
  1145.         if( rbRFRxContRx->Checked )
  1146.         {   m_sBtRf.e_packet_type = BT_TX_PACKET_CONT_RX;
  1147.         }
  1148.         else
  1149.         {   m_sBtRf.e_packet_type = BT_TX_PACKET_BURST_RX;
  1150.         }
  1151.     }
  1152. #endif
  1153.     text = edtRFTxSignleFreq->Text;      if( !IsValidBTFreq( text, m_sBtRf.uc_freq ) )         {  edtRFTxSignleFreqCheck(edtRFTxSignleFreq);        return false;   }
  1154. //    text = edtRFTxSignleFreq->Text;      if( !IsValidBTFreq( text, m_sBtRf.uc_rx_freq ) )         {  edtRFRxSignleFreqCheck(edtRFTxSignleFreq);        return false;   }
  1155.     text = edtRFTxDataLen->Text;      if( !IsValidBTTxDataLength( text, m_sBtRf.us_data_len, Get_RFTxDataMinLen(cbRFTxType->ItemIndex), Get_RFTxDataMaxLen(cbRFTxType->ItemIndex) ) )         {  edtRFTxDataLenCheck(edtRFTxDataLen);        return false;   }
  1156.     text = edtRFTxPollPeriod->Text;   if( !IsValidBTTxPollPeriod( text, m_sBtRf.uc_poll_period ) )      {  edtRFTxPollPeriodCheck(edtRFTxPollPeriod);        return false;   }
  1157.     // power control
  1158.     if( cbRFTxPowerCtrl->Checked )
  1159.     {   m_sBtRf.e_power_ctrl = BT_TX_POWER_CTRL_ON;
  1160.     }
  1161.     else
  1162.     {   m_sBtRf.e_power_ctrl = BT_TX_POWER_CTRL_OFF;
  1163.     }
  1164.     text = edtRFTxLevel->Text;      if( !IsValidBTTxPcl( text, m_sBtRf.uc_pcl ) )         {  edtRFTxLevelCheck(edtRFTxLevel);        return false;   }
  1165.     // access code
  1166.     for( int i=0; i<(sizeof(m_sBtRf.s_access_code.uc_access_code)/sizeof(m_sBtRf.s_access_code.uc_access_code[0])); i++ )
  1167.     {   text = m_edtRFTxAccessCode[i]->Text;      if( !IsValidHexBTTxAccessCode( text, m_sBtRf.s_access_code.uc_access_code[i] ) )         {  edtRFTxAccessCodeCheck(m_edtRFTxAccessCode[i]);        return false;   }
  1168.     }
  1169.     return true;
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void  TfrmBT::ShowHintLabel( TControl *sender, char* hint )
  1173. {
  1174.    TPoint pt0 = this->ClientOrigin;
  1175.    TPoint pt1 = sender->ClientOrigin;
  1176.    lblHint->Left = (pt1.x-pt0.x);
  1177.    lblHint->Top  = (pt1.y-pt0.y)+sender->Height+3;
  1178.    lblHint->Caption = hint;
  1179.    lblHint->Visible = true;
  1180.    HintTimer->Enabled = true;
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. void __fastcall TfrmBT::HintTimerTimer(TObject *Sender)
  1184. {
  1185.     HintTimer->Enabled = false;
  1186.     lblHint->Visible = false;
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TfrmBT::btnHCIFileClick(TObject *Sender)
  1190. {
  1191.     char str[512];
  1192.     bool ok;
  1193.     ok = dlgOpenHCIFile->Execute();
  1194.     if (!::CheckFileExist(dlgOpenHCIFile->FileName))
  1195.     {
  1196.         ok = false;
  1197.     }
  1198.     
  1199.     if( !ok )
  1200.     {
  1201.         sbHCI->Panels->Items[0]->Text = (AnsiString) "  Load HCI file fail";
  1202.         return;
  1203.     }
  1204.     m_sBTHCI.hPostMsgDestHandle = this->Handle;
  1205.     m_sBTHCI.filename           = dlgOpenHCIFile->FileName;
  1206.     m_sBTHCI.log                = m_pHCILog;
  1207.     m_BT_HCI_Obj.ConfirmCallback = ::ConfirmCallback_SetupHCIFile;
  1208.     m_BT_HCI_Obj.REQ_Read_From_File_Start( m_sBTHCI );
  1209.     sbHCI->Panels->Items[0]->Text = (AnsiString) "  Setup HCI file progressing";
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void TfrmBT::ConfirmCallback_SetupHCIFile(void)
  1213. {
  1214.     E_METAAPP_RESULT_T state = m_BT_HCI_Obj.Get_ConfirmState();
  1215.     switch (state)
  1216.     {
  1217.         case METAAPP_SUCCESS:
  1218.         {
  1219.             stHCIFile->Caption = m_sBTHCI.filename;
  1220.             if( rbHCICategory->Checked )
  1221.             {
  1222.                 m_pvHCICategory = m_BT_HCI_Obj.Get_HciCategoryVector();
  1223.                 DisplayHCIUI( DRAW_MASK_HCI_CATEGORY | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  1224.             }
  1225.             else
  1226.             {
  1227.                 m_pvHCIGroup = m_BT_HCI_Obj.Get_HciGroupVector();
  1228.                 DisplayHCIUI( DRAW_MASK_HCI_GROUP | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  1229.             }
  1230.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Setup HCI file successfully";
  1231.         }
  1232.         break;
  1233.         case METAAPP_FAIL:
  1234.         {
  1235.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Setup HCI file fail";
  1236.             Application->MessageBox( "Execution Fail : Setup HCI file", "FAIL", MB_OK );
  1237.         }
  1238.         break;
  1239.         case METAAPP_TIMEOUT:
  1240.         {
  1241.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Setup HCI file timeout";
  1242.             Application->MessageBox("Execution Timeout : Setup HCI file", "TIMEOUT", MB_OK);
  1243.         }
  1244.         break;
  1245.         case METAAPP_STOP:
  1246.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Setup HCI file stop";
  1247.         break;
  1248.     }
  1249.     CurrentPageReset();
  1250. }
  1251. //---------------------------------------------------------------------------
  1252. void TfrmBT::DisplayHCIUI( int draw_mask, int category_group_idx, int cmd_idx )
  1253. {
  1254.     static vector<S_BT_HCI_CATEGORY>:: iterator iter_category;
  1255.     static vector<S_BT_HCI_GROUP>:: iterator iter_group;
  1256.     vector<S_BT_HCI_COMMAND>:: iterator iter_cmd;
  1257.     vector<S_BT_HCI_PARAMETER>:: iterator iter_par;
  1258.     S_BT_HCI_CATEGORY category;
  1259.     S_BT_HCI_GROUP group;
  1260.     S_BT_HCI_COMMAND command;
  1261.     S_BT_HCI_PARAMETER parameter;
  1262.     if( rbHCICategory->Checked )
  1263.     {
  1264.         if( draw_mask & DRAW_MASK_HCI_CATEGORY )
  1265.         {
  1266.             cbHCICategory->Clear();
  1267.             // display category
  1268.             for( iter_category = m_pvHCICategory->begin(); iter_category != m_pvHCICategory->end(); iter_category++ )
  1269.             {
  1270.                 category = *iter_category;
  1271.                 cbHCICategory->Items->Add( category.as_category_name );
  1272.             }
  1273.             iter_category = m_pvHCICategory->begin();
  1274.             cbHCICategory->ItemIndex = category_group_idx;
  1275.         }
  1276.         // display command
  1277.         if( draw_mask & DRAW_MASK_HCI_COMMAND )
  1278.         {
  1279.             for( iter_category = m_pvHCICategory->begin(); iter_category != m_pvHCICategory->end(); iter_category++ )
  1280.             {
  1281.                 category = *iter_category;
  1282.                 if( category.as_category_name.AnsiCompareIC(cbHCICategory->Text) == 0 )
  1283.                 {
  1284.                     break;
  1285.                 }
  1286.             }
  1287.             cbHCICommand->Clear();
  1288.             for( iter_cmd = iter_category->v_cmd.begin(); iter_cmd != iter_category->v_cmd.end(); iter_cmd++ )
  1289.             {
  1290.                 command = *iter_cmd;
  1291.                 cbHCICommand->Items->Add( command.as_cmd_name );
  1292.             }
  1293.             cbHCICommand->ItemIndex = cmd_idx;
  1294.         }
  1295.         // display parameter
  1296.         if( draw_mask & DRAW_MASK_HCI_PARAMETER )
  1297.         {
  1298.             // sgSendHCI->EditorMode = true;
  1299.             for( iter_cmd = iter_category->v_cmd.begin(); iter_cmd != iter_category->v_cmd.end(); iter_cmd++ )
  1300.             {
  1301.                 command = *iter_cmd;
  1302.                 if( command.as_cmd_name.AnsiCompareIC(cbHCICommand->Text) == 0 )
  1303.                 {
  1304.                     if( ! m_pvSendHCIPar->empty() )
  1305.                     {
  1306.                         m_pvSendHCIPar->erase( m_pvSendHCIPar->begin(), m_pvSendHCIPar->end() );
  1307.                     }
  1308.                     if( ! m_pvReceiveHCIPar->empty() )
  1309.                     {
  1310.                         m_pvReceiveHCIPar->erase( m_pvReceiveHCIPar->begin(), m_pvReceiveHCIPar->end() );
  1311.                     }
  1312.                     char str[20];
  1313.                     sprintf( str, "%X", iter_cmd->us_opcode );
  1314.                     stHCIOpcode->Caption = str;
  1315.                     sprintf( str, "%X", iter_cmd->uc_last_event );
  1316.                     stHCILastEvent->Caption = str;
  1317.                     edtHCITimeout->Text = iter_cmd->ui_ms_timeout;
  1318.                     // send parameter
  1319.                     if( 0 == iter_cmd->ui_send_num )
  1320.                     {
  1321.                         sgSendHCI->FixedCols = 3;
  1322.                         sgSendHCI->FixedRows = 1;
  1323.                         sgSendHCI->ColCount = 4;
  1324.                         sgSendHCI->RowCount = 2;
  1325.                         sgSendHCI->Cells[HCI_NAME_COL_IDX][1] = "";
  1326.                         sgSendHCI->Cells[HCI_BYTE_COL_IDX][1] = "";
  1327.                         sgSendHCI->Cells[HCI_VALUE_COL_IDX][1] = "";
  1328.                     }
  1329.                     else
  1330.                     {
  1331.                         sgSendHCI->FixedCols = 2;
  1332.                         sgSendHCI->FixedRows = 1;
  1333.                         sgSendHCI->ColCount = 4;
  1334.                         sgSendHCI->RowCount = iter_cmd->ui_send_num+1;
  1335.                         for (unsigned int i=0; i<iter_cmd->ui_send_num; i++ )
  1336.                         {
  1337.                             iter_par = iter_cmd->v_send_par.begin() + i;
  1338.                             parameter = *iter_par;
  1339.                             sgSendHCI->Cells[HCI_NAME_COL_IDX][i+1] = iter_par->as_name;
  1340.                             sgSendHCI->Cells[HCI_BYTE_COL_IDX][i+1] = IntToStr( iter_par->ui_bytes );
  1341.                             AnsiString as_value;
  1342.                             if( rbHCIDec->Checked )
  1343.                             {
  1344.                                 BTHCIValue_To_AnsiString( iter_par->s_value, as_value );
  1345.                                 sgSendHCI->Cells[HCI_VALUE_COL_IDX][i+1] = as_value;
  1346.                             }
  1347.                             else
  1348.                             {
  1349.                                 BTHCIValue_To_Hex_AnsiString( iter_par->s_value, as_value );
  1350.                                 sgSendHCI->Cells[HCI_VALUE_COL_IDX][i+1] = as_value;
  1351.                             }
  1352.                             S_BT_HCI_PARAMETER hci_par;
  1353.                            // for( int j=0; j<BT_HCI_VALUE_SIZE; j++ )
  1354.                           //  {
  1355.                           //      parameter.s_value.uc_value[j] = 0;
  1356.                           //  }
  1357.                            // parameter.s_value.uc_nz_byte = 0;
  1358.                             m_pvSendHCIPar->push_back( parameter );
  1359.                         }
  1360.                     }
  1361.                     // receive parameter
  1362.                     if( 0 == iter_cmd->ui_receive_num )
  1363.                     {
  1364.                         sgReceiveHCI->FixedCols = 3;
  1365.                         sgReceiveHCI->FixedRows = 1;
  1366.                         sgReceiveHCI->ColCount = 4;
  1367.                         sgReceiveHCI->RowCount = 2;
  1368.                         sgReceiveHCI->Cells[HCI_NAME_COL_IDX][1] = "";
  1369.                         sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][1] = "";
  1370.                         sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][1] = "";
  1371.                     }
  1372.                     else
  1373.                     {
  1374.                         sgReceiveHCI->FixedCols = 2;
  1375.                         sgReceiveHCI->FixedRows = 1;
  1376.                         sgReceiveHCI->ColCount = 4;
  1377.                        // sgReceiveHCI->RowCount = iter_cmd->ui_receive_num+1;
  1378.                         int count = 0;
  1379.                         for (unsigned int i=0; i<iter_cmd->ui_receive_num; i++)
  1380.                         {
  1381.                             iter_par = iter_cmd->v_receive_par.begin() + i;
  1382.                             parameter = *iter_par;
  1383.                             if( iter_par->b_show )
  1384.                             {
  1385.                                 sgReceiveHCI->Cells[HCI_NAME_COL_IDX][count+1] = iter_par->as_name;
  1386.                                 sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][count+1] = IntToStr( iter_par->ui_bytes );
  1387.                                 sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][count+1] = IntToStr( 0 );
  1388.                                 count++;
  1389.                             }
  1390.                             for( int j=0; j<BT_HCI_VALUE_SIZE; j++ )
  1391.                             {
  1392.                                 parameter.s_value.uc_value[j] = 0;
  1393.                             }
  1394.                             parameter.s_value.uc_nz_byte = 0;
  1395.                             m_pvReceiveHCIPar->push_back( parameter );
  1396.                         }
  1397.                         sgReceiveHCI->RowCount = count+1;
  1398.                     }
  1399.                     break;
  1400.                 }
  1401.             }
  1402.         }
  1403.     }
  1404.     else // group
  1405.     {
  1406.         if( draw_mask & DRAW_MASK_HCI_GROUP )
  1407.         {
  1408.             // display group
  1409.             cbHCIGroup->Clear();
  1410.             for( iter_group = m_pvHCIGroup->begin(); iter_group != m_pvHCIGroup->end(); iter_group++ )
  1411.             {
  1412.                 group = *iter_group;
  1413.                 cbHCIGroup->Items->Add( group.as_group_name );
  1414.             }
  1415.             iter_group = m_pvHCIGroup->begin();
  1416.             cbHCIGroup->ItemIndex = category_group_idx;
  1417.         }
  1418.         // display command
  1419.         if( draw_mask & DRAW_MASK_HCI_COMMAND )
  1420.         {
  1421.             for( iter_group = m_pvHCIGroup->begin(); iter_group != m_pvHCIGroup->end(); iter_group++ )
  1422.             {
  1423.                 group = *iter_group;
  1424.                 if( group.as_group_name.AnsiCompareIC(cbHCIGroup->Text) == 0 )
  1425.                 {
  1426.                     break;
  1427.                 }
  1428.             }
  1429.             cbHCICommand->Clear();
  1430.             for( iter_cmd = iter_group->v_cmd.begin(); iter_cmd != iter_group->v_cmd.end(); iter_cmd++ )
  1431.             {
  1432.                 command = *iter_cmd;
  1433.                 cbHCICommand->Items->Add( command.as_cmd_name );
  1434.             }
  1435.             cbHCICommand->ItemIndex = cmd_idx;
  1436.         }
  1437.         // display parameter
  1438.         if( draw_mask & DRAW_MASK_HCI_PARAMETER )
  1439.         {
  1440.             // sgSendHCI->EditorMode = true;
  1441.             for( iter_cmd = iter_group->v_cmd.begin(); iter_cmd != iter_group->v_cmd.end(); iter_cmd++ )
  1442.             {
  1443.                 command = *iter_cmd;
  1444.                 if( command.as_cmd_name.AnsiCompareIC(cbHCICommand->Text) == 0 )
  1445.                 {
  1446.                     if( ! m_pvSendHCIPar->empty() )
  1447.                     {
  1448.                         m_pvSendHCIPar->erase( m_pvSendHCIPar->begin(), m_pvSendHCIPar->end() );
  1449.                     }
  1450.                     if( ! m_pvReceiveHCIPar->empty() )
  1451.                     {
  1452.                         m_pvReceiveHCIPar->erase( m_pvReceiveHCIPar->begin(), m_pvReceiveHCIPar->end() );
  1453.                     }
  1454.                     char str[20];
  1455.                     sprintf( str, "%X", iter_cmd->us_opcode );
  1456.                     stHCIOpcode->Caption = str;
  1457.                     sprintf( str, "%X", iter_cmd->uc_last_event );
  1458.                     stHCILastEvent->Caption = str;
  1459.                     edtHCITimeout->Text = iter_cmd->ui_ms_timeout;
  1460.                     // send parameter
  1461.                     if( 0 == iter_cmd->ui_send_num )
  1462.                     {
  1463.                         sgSendHCI->FixedCols = 3;
  1464.                         sgSendHCI->FixedRows = 1;
  1465.                         sgSendHCI->ColCount  = 4;
  1466.                         sgSendHCI->RowCount  = 2;
  1467.                         sgSendHCI->Cells[HCI_NAME_COL_IDX][1] = "";
  1468.                         sgSendHCI->Cells[HCI_BYTE_COL_IDX][1] = "";
  1469.                         sgSendHCI->Cells[2][1] = "";
  1470.                     }
  1471.                     else
  1472.                     {
  1473.                         sgSendHCI->FixedCols = 2;
  1474.                         sgSendHCI->FixedRows = 1;
  1475.                         sgSendHCI->ColCount = 4;
  1476.                         sgSendHCI->RowCount = iter_cmd->ui_send_num+1;
  1477.                         for (unsigned int i=0; i<iter_cmd->ui_send_num; i++)
  1478.                         {
  1479.                             iter_par = iter_cmd->v_send_par.begin() + i;
  1480.                             parameter = *iter_par;
  1481.                             sgSendHCI->Cells[HCI_NAME_COL_IDX][i+1] = iter_par->as_name;
  1482.                             sgSendHCI->Cells[HCI_BYTE_COL_IDX][i+1] = IntToStr( iter_par->ui_bytes );
  1483.                             AnsiString as_value;
  1484.                             if( rbHCIDec->Checked )
  1485.                             {
  1486.                                 BTHCIValue_To_AnsiString( iter_par->s_value, as_value );
  1487.                                 sgSendHCI->Cells[HCI_VALUE_COL_IDX][i+1] = as_value;
  1488.                             }
  1489.                             else
  1490.                             {
  1491.                                 BTHCIValue_To_Hex_AnsiString( iter_par->s_value, as_value );
  1492.                                 sgSendHCI->Cells[HCI_VALUE_COL_IDX][i+1] = as_value;
  1493.                             }
  1494.                            // for( int j=0; j<BT_HCI_VALUE_SIZE; j++ )
  1495.                            // {
  1496.                            ////     parameter.s_value.uc_value[j] = 0;
  1497.                            // }
  1498.                            // parameter.s_value.uc_nz_byte = 0;
  1499.                             m_pvSendHCIPar->push_back( parameter );
  1500.                         }
  1501.                     }
  1502.                     // receive parameter
  1503.                     if( 0 == iter_cmd->ui_receive_num )
  1504.                     {
  1505.                         sgReceiveHCI->FixedCols = 3;
  1506.                         sgReceiveHCI->FixedRows = 1;
  1507.                         sgReceiveHCI->ColCount = 4;
  1508.                         sgReceiveHCI->RowCount = 2;
  1509.                         sgReceiveHCI->Cells[HCI_NAME_COL_IDX][1] = "";
  1510.                         sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][1] = "";
  1511.                         sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][1] = "";
  1512.                     }
  1513.                     else
  1514.                     {
  1515.                         sgReceiveHCI->FixedCols = 2;
  1516.                         sgReceiveHCI->FixedRows = 1;
  1517.                         sgReceiveHCI->ColCount = 4;
  1518.                        // sgReceiveHCI->RowCount = iter_cmd->ui_receive_num+1;
  1519.                         int count = 0;
  1520.                         for (unsigned int i=0; i<iter_cmd->ui_receive_num; i++)
  1521.                         {
  1522.                             iter_par = iter_cmd->v_receive_par.begin() + i;
  1523.                             parameter = *iter_par;
  1524.                             if( iter_par->b_show )
  1525.                             {
  1526.                                 sgReceiveHCI->Cells[HCI_NAME_COL_IDX][count+1] = iter_par->as_name;
  1527.                                 sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][count+1] = IntToStr( iter_par->ui_bytes );
  1528.                                 sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][count+1] = IntToStr( 0 );
  1529.                                 count++;
  1530.                             }
  1531.                             for( int j=0; j<BT_HCI_VALUE_SIZE; j++ )
  1532.                             {
  1533.                                 parameter.s_value.uc_value[j] = 0;
  1534.                             }
  1535.                             parameter.s_value.uc_nz_byte = 0;
  1536.                             m_pvReceiveHCIPar->push_back( parameter );
  1537.                         }
  1538.                         sgReceiveHCI->RowCount = count+1;
  1539.                     }
  1540.                     break;
  1541.                 }
  1542.             }
  1543.         }
  1544.     }
  1545. }
  1546. //---------------------------------------------------------------------------
  1547. void  TfrmBT::DisplayHCIFile( void )
  1548. {
  1549.     AnsiString as_HCI_file = read_HCI_File("MF_setup.txt", Application->ExeName);
  1550.     ReadHCIFile( as_HCI_file );
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. void  TfrmBT::SaveHCIFile( void )
  1554. {
  1555.     if( stHCIFile->Caption.AnsiCompareIC("") != 0 )
  1556.     {    write_HCI_File( "MF_setup.txt", Application->ExeName, stHCIFile->Caption );
  1557.     }
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. void TfrmBT::ReadHCIFile( AnsiString asFileName )
  1561. {
  1562.     if( ! CheckFileExist(asFileName) )
  1563.     {
  1564.         return;
  1565.     }
  1566.     m_sBTHCI.hPostMsgDestHandle = this->Handle;
  1567.     m_sBTHCI.filename           = asFileName;
  1568.     m_sBTHCI.log                = m_pHCILog;
  1569.    // m_BT_HCI_Obj.ConfirmCallback = ::ConfirmCallback_SetupHCIFile;
  1570.    // m_BT_HCI_Obj.REQ_Read_From_File_Start( m_sBTHCI );
  1571.     bool ok = m_BT_HCI_Obj.REQ_Read_Last_HCI_File_Start( m_sBTHCI );
  1572.     if( ok )
  1573.     {
  1574.         stHCIFile->Caption = m_sBTHCI.filename;
  1575.         if( rbHCICategory->Checked )
  1576.         {
  1577.             m_pvHCICategory = m_BT_HCI_Obj.Get_HciCategoryVector();
  1578.             DisplayHCIUI( DRAW_MASK_HCI_CATEGORY | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  1579.         }
  1580.         else
  1581.         {
  1582.             m_pvHCIGroup = m_BT_HCI_Obj.Get_HciGroupVector();
  1583.             DisplayHCIUI( DRAW_MASK_HCI_GROUP | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  1584.         }
  1585.         sbHCI->Panels->Items[0]->Text = (AnsiString)"  Setup HCI file successfully";
  1586.     }
  1587. }
  1588. //--------------------------------------------------------------------------
  1589. bool TfrmBT::ComposeHCICommand( S_BT_HCI &hci )
  1590. {
  1591.     S_BT_HCI_VALUE s_value;
  1592.     //unsigned char parameter_len=0;
  1593.     int row, byte_idx, str_idx;
  1594.     int value;
  1595.   //  char value_str[256];
  1596.     int byte_num;
  1597.     int hci_cmd_max_len;
  1598.     hci_cmd_max_len = sizeof(hci.s_hci_cmd.m_cmd)/sizeof(hci.s_hci_cmd.m_cmd[0]);
  1599.     for( int i=0; i<hci_cmd_max_len; i++ )
  1600.         hci.s_hci_cmd.m_cmd[i] = '';
  1601.     // opcode
  1602.     if( ! IsValidHexBTHCIOpcode( stHCIOpcode->Caption, hci.s_hci_cmd.m_opcode ) )
  1603.         return false;
  1604.     // last event index
  1605.     if( ! IsValidHexBTHCIEventIndex( stHCILastEvent->Caption, hci.uc_last_event ) )
  1606.         return false;
  1607.    // hci.s_hci_cmd.m_cmd[0] = hci.s_hci_cmd.m_opcode & 0x00FF ;
  1608.    // hci.s_hci_cmd.m_cmd[1] = (hci.s_hci_cmd.m_opcode & 0xFF00)>>8 ;
  1609.     // parameter length
  1610.    // for( row=1; row<sgSendHCI->RowCount; row++ )
  1611.    // {
  1612.    //     parameter_len += sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt();
  1613.    // }
  1614.    // hci.s_hci_cmd.m_cmd[2] = parameter_len;
  1615.     // parameter
  1616.     hci.s_hci_cmd.m_len = 0;
  1617.     for( row=1; row<sgSendHCI->RowCount; row++ )
  1618.     {
  1619.         if( sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].AnsiCompareIC("") == 0 )
  1620.             return true;
  1621.         byte_num = sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt();
  1622.         if( rbHCIHex->Checked )
  1623.         {
  1624.             AnsiString_Hex_To_BTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], s_value );
  1625.             //itoa( value, value_str, 10 );
  1626.         }
  1627.         else
  1628.         {
  1629.             AnsiString_To_BTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], s_value );
  1630.         }
  1631.        // for( str_idx=0; str_idx<hci_cmd_max_len; str_idx++ )
  1632.        // {
  1633.        //     if(  0 == value_str[str_idx] )
  1634.        //     {
  1635.        //        value_str_len = str_idx;
  1636.        //        break;
  1637.        //     }
  1638.        // }
  1639.         for( byte_idx=0; byte_idx<byte_num; byte_idx++ )
  1640.         {
  1641.             if( byte_idx < s_value.uc_nz_byte )
  1642.             {
  1643.                 hci.s_hci_cmd.m_cmd[hci.s_hci_cmd.m_len] = s_value.uc_value[byte_idx];
  1644.             }
  1645.             else
  1646.             {   hci.s_hci_cmd.m_cmd[hci.s_hci_cmd.m_len] = 0;
  1647.             }
  1648.             hci.s_hci_cmd.m_len++;
  1649.         }
  1650.     }
  1651.     return true;
  1652. }
  1653. //--------------------------------------------------------------------------
  1654. bool  TfrmBT::DeComposeHCIEvent( BT_HCI_EVENT &event )
  1655. {
  1656.     if( sgReceiveHCI->Cells[HCI_NAME_COL_IDX][1].AnsiCompareIC("") == 0 )  // no event parameter
  1657.          return true;
  1658.     static vector<S_BT_HCI_CATEGORY>:: iterator iter_category;
  1659.     static vector<S_BT_HCI_GROUP>:: iterator iter_group;
  1660.     vector<S_BT_HCI_COMMAND>:: iterator iter_cmd;
  1661.     vector<S_BT_HCI_PARAMETER>:: iterator iter_par;
  1662.     S_BT_HCI_PARAMETER sParameter;
  1663.    // int row;
  1664. //     vector<S_BT_HCI_PARAMETER>:: iterator iter_par;
  1665.      int idx = 0;
  1666.      if( ! m_pvReceiveHCIPar->empty() )
  1667.      {
  1668.          m_pvReceiveHCIPar->erase(m_pvReceiveHCIPar->begin(), m_pvReceiveHCIPar->end() );
  1669.      }
  1670.    // S_BT_HCI_CATEGORY category;
  1671.    // S_BT_HCI_GROUP group;
  1672.    // S_BT_HCI_COMMAND command;
  1673.    // S_BT_HCI_PARAMETER parameter;
  1674.     if( rbHCICategory->Checked )
  1675.     {
  1676.         for( iter_category = m_pvHCICategory->begin(); iter_category != m_pvHCICategory->end(); iter_category++ )
  1677.         {
  1678.             AnsiString as_category_name = iter_category->as_category_name.Trim();
  1679.             AnsiString as_text = cbHCICategory->Text.Trim();
  1680.             if( as_category_name.AnsiCompareIC(as_text) == 0 )
  1681.                 break;
  1682.         }
  1683.         for( iter_cmd = iter_category->v_cmd.begin(); iter_cmd != iter_category->v_cmd.end(); iter_cmd++ )
  1684.         {
  1685.             AnsiString as_cmd_name = iter_cmd->as_cmd_name.Trim();
  1686.             AnsiString as_text = cbHCICommand->Text.Trim();
  1687.             if( as_cmd_name.AnsiCompareIC(as_text) == 0 )
  1688.                 break;
  1689.         }
  1690.         for (unsigned int i=0; i<iter_cmd->ui_receive_num; i++ )
  1691.         {
  1692.             iter_par = iter_cmd->v_receive_par.begin() + i;
  1693.             sParameter = *iter_par;
  1694.             for( int i=0; i<BT_HCI_VALUE_SIZE; i++ )
  1695.             {   sParameter.s_value.uc_value[i] = 0;
  1696.             }
  1697.             sParameter.s_value.uc_nz_byte = 0;
  1698.             for (unsigned int i=0; i<sParameter.ui_bytes; i++)
  1699.             {
  1700.                 sParameter.s_value.uc_value[i] = (char) event.m_parms[idx];
  1701.                 idx++;
  1702.                 if( sParameter.s_value.uc_value[i] != 0 )
  1703.                     sParameter.s_value.uc_nz_byte++;
  1704.             }
  1705.             m_pvReceiveHCIPar->push_back( sParameter );
  1706.         }
  1707.     }
  1708.     else
  1709.     {
  1710.         for( iter_group = m_pvHCIGroup->begin(); iter_group != m_pvHCIGroup->end(); iter_group++ )
  1711.         {
  1712.             AnsiString as_group_name = iter_group->as_group_name.Trim();
  1713.             AnsiString as_text = cbHCIGroup->Text.Trim();
  1714.             if( as_group_name.AnsiCompareIC(as_text) == 0 )
  1715.                 break;
  1716.         }
  1717.         for( iter_cmd = iter_group->v_cmd.begin(); iter_cmd != iter_group->v_cmd.end(); iter_cmd++ )
  1718.         {
  1719.             AnsiString as_cmd_name = iter_cmd->as_cmd_name.Trim();
  1720.             AnsiString as_text = cbHCICommand->Text.Trim();
  1721.             if( as_cmd_name.AnsiCompareIC(as_text) == 0 )
  1722.                 break;
  1723.         }
  1724.         for (unsigned int i=0; i<iter_cmd->ui_receive_num; i++ )
  1725.         {
  1726.             iter_par = iter_cmd->v_receive_par.begin() + i;
  1727.             sParameter = *iter_par;
  1728.             for( int i=0; i<BT_HCI_VALUE_SIZE; i++ )
  1729.             {   sParameter.s_value.uc_value[i] = 0;
  1730.             }
  1731.             sParameter.s_value.uc_nz_byte = 0;
  1732.             for (unsigned int i=0; i<sParameter.ui_bytes; i++ )
  1733.             {
  1734.                 sParameter.s_value.uc_value[i] = (char) event.m_parms[idx];
  1735.                 idx++;
  1736.                 if( sParameter.s_value.uc_value[i] != 0 )
  1737.                     sParameter.s_value.uc_nz_byte++;
  1738.             }
  1739.             m_pvReceiveHCIPar->push_back( sParameter );
  1740.         }
  1741.     }
  1742. #if 0
  1743.      for( row=1; row<sgReceiveHCI->RowCount; row++ )
  1744.      {
  1745.          sParameter.as_name  = sgReceiveHCI->Cells[HCI_NAME_COL_IDX][row];
  1746.          sParameter.ui_bytes = sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt();
  1747.          for( int i=0; i<BT_HCI_VALUE_SIZE; i++ )
  1748.          {   sParameter.s_value.uc_value[i] = 0;
  1749.          }
  1750.          sParameter.s_value.uc_nz_byte = 0;
  1751.          for( int i=0; i<sParameter.ui_bytes; i++ )
  1752.          {
  1753.              sParameter.s_value.uc_value[i] = (char) event.m_parms[HCI_EVENT_PARAMETER_START_IDX+idx];
  1754.              idx++;
  1755.              if( sParameter.s_value.uc_value[i] != 0 )
  1756.                  sParameter.s_value.uc_nz_byte++;
  1757.          }
  1758.          m_pvReceiveHCIPar->push_back( sParameter );
  1759.      }
  1760. #endif
  1761.     return true;
  1762. }
  1763. //--------------------------------------------------------------------------
  1764. void  TfrmBT::ReDrawHCIFields( E_DRAM_MASK_HCI draw_mask )
  1765. {
  1766.     vector<S_BT_HCI_PARAMETER>:: iterator iter_par;
  1767.     if( draw_mask & DRAM_MASK_HCI_SEND )
  1768.     {
  1769.         for( int row=1; row<sgSendHCI->RowCount; row++ )
  1770.         {
  1771.             for( iter_par = m_pvSendHCIPar->begin(); iter_par != m_pvSendHCIPar->end(); iter_par++ )
  1772.             {
  1773.                 AnsiString as_name = sgSendHCI->Cells[HCI_NAME_COL_IDX][row];
  1774.                 if( iter_par->as_name.AnsiCompareIC( as_name ) == 0 )
  1775.                 {
  1776.                     AnsiString as_hci_value;
  1777.                     if( rbHCIDec->Checked )
  1778.                     {
  1779.                         BTHCIValue_To_AnsiString( iter_par->s_value, as_hci_value );
  1780.                     }
  1781.                     else
  1782.                     {   BTHCIValue_To_Hex_AnsiString( iter_par->s_value, as_hci_value );
  1783.                     }
  1784.                     sgSendHCI->Cells[HCI_VALUE_COL_IDX][row] = as_hci_value;
  1785.                     break;
  1786.                 }
  1787.             }
  1788.         }
  1789.     }
  1790.     if( draw_mask & DRAM_MASK_HCI_RECEIVE )
  1791.     {
  1792.         AnsiString ansi_str;
  1793. //        iter_par = m_sRxEvent.v_par.begin();
  1794.         for(int row=1; row<sgReceiveHCI->RowCount; row++ )
  1795.         {
  1796.             for( iter_par = m_pvReceiveHCIPar->begin(); iter_par != m_pvReceiveHCIPar->end(); iter_par++ )
  1797.             {
  1798.                 AnsiString as_name = sgReceiveHCI->Cells[HCI_NAME_COL_IDX][row];
  1799.                 if( iter_par->as_name.AnsiCompareIC( as_name ) == 0 )
  1800.                 {
  1801.                     AnsiString as_hci_value;
  1802.                     if( rbHCIDec->Checked )
  1803.                     {
  1804.                         BTHCIValue_To_AnsiString( iter_par->s_value, as_hci_value );
  1805.                     }
  1806.                     else
  1807.                     {   BTHCIValue_To_Hex_AnsiString( iter_par->s_value, as_hci_value );
  1808.                     }
  1809.                     sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][row] = as_hci_value;
  1810.                     break;
  1811.                 }
  1812.             }
  1813.            // BTHCIValue_To_AnsiString( iter_par->s_value, ansi_str );
  1814.            // sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][row] = ansi_str;
  1815.            // iter_par++;
  1816.         }
  1817.     }
  1818. }
  1819. //--------------------------------------------------------------------------
  1820. void TfrmBT::FillHCIResult( void )
  1821. {
  1822.     for(int i=0; i<m_pHCILog->Count; i++ )
  1823.     {
  1824.         AnsiString as = m_pHCILog->Strings[i];
  1825.         memHCIResult->Lines->Add( as );
  1826.     }
  1827.     m_pHCILog->Clear();
  1828. }
  1829. //--------------------------------------------------------------------------
  1830. void TfrmBT::FillRFResult( void )
  1831. {
  1832.     for(int i=0; i<m_pRFLog->Count; i++ )
  1833.     {
  1834.         AnsiString as = m_pRFLog->Strings[i];
  1835.         memRFResult->Lines->Add( as );
  1836.     }
  1837.     m_pRFLog->Clear();
  1838. }
  1839. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1840. void TfrmBT::DisplayPKTBDAddress( E_BT_PACKET_DEVICE_T obj )
  1841. {
  1842.     AnsiString as_bd_addr;
  1843.     if( BT_PACKET_TESTER == obj )
  1844.     {
  1845.         BDAddress_To_Hex_AnsiString( m_BT_PKT_Obj.Get_TesterBDAddress(), as_bd_addr );
  1846.         stPKTTesterBDAddr->Caption = as_bd_addr;
  1847.     }
  1848.     else
  1849.     {
  1850.         BDAddress_To_Hex_AnsiString( m_BT_PKT_Obj.Get_DUTBDAddress(), as_bd_addr );
  1851.         stPKTDUTBDAddr->Caption = as_bd_addr;
  1852.     }
  1853. }
  1854. //--------------------------------------------------------------------------
  1855. void TfrmBT::FillPKTResult( void )
  1856. {
  1857.     for(int i=0; i<m_pPKTLog->Count; i++ )
  1858.     {
  1859.         AnsiString as = m_pPKTLog->Strings[i];
  1860.         memPKTResult->Lines->Add( as );
  1861.     }
  1862.     m_pPKTLog->Clear();
  1863. }
  1864. //---------------------------------------------------------------------------
  1865. void __fastcall TfrmBT::cbHCIGroupChange(TObject *Sender)
  1866. {
  1867.     DisplayHCIUI( DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, cbHCIGroup->ItemIndex, 0 );
  1868. }
  1869. //---------------------------------------------------------------------------
  1870. void __fastcall TfrmBT::cbHCICommandChange(TObject *Sender)
  1871. {
  1872.     DisplayHCIUI( DRAW_MASK_HCI_PARAMETER, cbHCIGroup->ItemIndex, cbHCICommand->ItemIndex );    
  1873. }
  1874. //---------------------------------------------------------------------------
  1875. void __fastcall TfrmBT::btnHCISendClick(TObject *Sender)
  1876. {
  1877.     if( ! CheckSendHCIValue() )
  1878.     {
  1879.         return;
  1880.     }
  1881.     m_sBTHCI.hPostMsgDestHandle = this->Handle;
  1882.     m_sBTHCI.filename           = stHCIFile->Caption;
  1883.     m_sBTHCI.log                = m_pHCILog;
  1884.     m_sBTHCI.ui_ms_timeout      = edtHCITimeout->Text.ToInt();
  1885.     ComposeHCICommand( m_sBTHCI );
  1886.     CurrentPageLock();
  1887.     sbHCI->Panels->Items[0]->Text = (AnsiString) "  Send HCI command progressing";
  1888.     m_BT_HCI_Obj.ConfirmCallback  = ::ConfirmCallback_HCI;
  1889.     m_BT_HCI_Obj.REQ_Start( m_sBTHCI );
  1890. }
  1891. //---------------------------------------------------------------------------
  1892. void TfrmBT::ConfirmCallback_HCI(void)
  1893. {
  1894.     E_METAAPP_RESULT_T state = m_BT_HCI_Obj.Get_ConfirmState();
  1895.     switch (state)
  1896.     {
  1897.         case METAAPP_SUCCESS:
  1898.         {
  1899.             m_sHCIEventFmt = m_BT_HCI_Obj.Get_HCIEvent();
  1900.             DeComposeHCIEvent(m_sHCIEventFmt);
  1901.             ReDrawHCIFields(DRAM_MASK_HCI_RECEIVE);
  1902.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Send HCI command successfully";
  1903.         }
  1904.         break;
  1905.         case METAAPP_FAIL:
  1906.         {
  1907.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Send HCI command fail";
  1908.             Application->MessageBox( "Execution Fail : Send HCI command", "FAIL", MB_OK );
  1909.         }
  1910.         break;
  1911.         case METAAPP_TIMEOUT:
  1912.         {
  1913.             Force_BT_Stop(false);
  1914.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Send HCI command timeout";
  1915.             Application->MessageBox( "Execution Timeout : Send HCI command", "TIMEOUT", MB_OK );
  1916.         }
  1917.         break;
  1918.         case METAAPP_CANCEL:
  1919.         case METAAPP_STOP:
  1920.         {
  1921.             sbHCI->Panels->Items[0]->Text = (AnsiString)"  Send HCI command stop";
  1922.         }
  1923.         break;
  1924.     }
  1925.     CurrentPageReset();
  1926. }
  1927. //===========================================================================
  1928. /////////////////////////////////  RF test  /////////////////////////////////
  1929. //===========================================================================
  1930. void TfrmBT::ReDrawRFFields( E_DRAM_MASK_RF draw_mask )
  1931. {
  1932.     if( draw_mask & DRAM_MASK_RF_BD_ADDRESS )
  1933.     {
  1934.         AnsiString as_bd_addr;
  1935.         BDAddress_To_Hex_Colon_AnsiString( m_sRFBdAddr, as_bd_addr );
  1936.         edtRFBDAddress->Text = as_bd_addr;
  1937.     }
  1938.     if( draw_mask & DRAM_MASK_RF_ACCESS_CODE )
  1939.     {
  1940.         char str[20];
  1941.         // access code
  1942.         for( int i=0; i<(sizeof(m_sBtRf.s_access_code.uc_access_code)/sizeof(m_sBtRf.s_access_code.uc_access_code[0])); i++ )
  1943.         {
  1944.             sprintf( str, "%X", m_sBtRf.s_access_code.uc_access_code[i] );
  1945.             m_edtRFTxAccessCode[i]->Text = str;
  1946.         }
  1947.     }
  1948.     if( draw_mask & DRAM_MASK_RF_TX_OTHERS )
  1949.     {
  1950.         edtRFTxSignleFreq->Text = IntToStr( m_sBtRf.uc_freq );
  1951.         edtRFTxDataLen->Text    = IntToStr( m_sBtRf.us_data_len );
  1952.         edtRFTxPollPeriod->Text = IntToStr( m_sBtRf.uc_poll_period );
  1953.         edtRFTxLevel->Text      = IntToStr( m_sBtRf.uc_pcl );
  1954.     }
  1955.    // if( draw_mask & DRAM_MASK_RF_RX )
  1956.    // {
  1957.    //     edtRFRxSignleFreq->Text = IntToStr( m_sBtRf.uc_freq );
  1958.    // }
  1959. }
  1960. //---------------------------------------------------------------------------
  1961. void __fastcall TfrmBT::edtRFTxSignleFreqCheck(TObject *Sender)
  1962. {
  1963.     unsigned char  uc_data;
  1964.     AnsiString  text;
  1965.     TEdit *edit = (TEdit*)Sender;
  1966.     char  hint[] =
  1967.     {   " value should be 0~255 "
  1968.     };
  1969.     text = edit->Text;
  1970.     if( !IsValidBTFreq( text, uc_data ) )
  1971.     {
  1972.         edit->Text = 78;
  1973.         ShowHintLabel( edit, hint );
  1974.         edit->SetFocus();
  1975.         return;
  1976.     }
  1977.     m_sBtRf.uc_freq = uc_data;
  1978. }
  1979. //-------------------------------------------------------------------------
  1980. unsigned short TfrmBT::Get_RFTxDataDefaultLen(int index)
  1981. {
  1982.     unsigned short us_default_len[] =
  1983.     {
  1984.         0,// NULL
  1985.         0,// POLL
  1986.         0,// FHS
  1987.         17,// DM1
  1988.         27,// DH1
  1989.         10,// HV1
  1990.         20,// HV2
  1991.         30,// HV3
  1992.         19,// DV
  1993.         10,// AUX
  1994.         121,// DM3
  1995.         183,// DH3
  1996.         224,// DM5
  1997.         339,// DH5
  1998.         30,// EV3
  1999.         120,// EV4
  2000.         180,//EV5
  2001.          54,// 2-DH1
  2002.          60,// 2-EV3
  2003.         367,// 2-DH3
  2004.         360,// 2-EV5
  2005.         679,// 2-DH5
  2006.          90,// 3-EV3
  2007.          83,// 3-DH1
  2008.         552,// 3-DH3
  2009.         540,// 3-EV5
  2010.        1021 // 3-DH5
  2011.     };
  2012.     return us_default_len[index];
  2013. }
  2014. //--------------------------------------------------------------------------
  2015. unsigned short TfrmBT::Get_RFTxDataMinLen( int index )
  2016. {
  2017.     unsigned short us_min_len[] =
  2018.     {
  2019.         0,// NULL
  2020.         0,// POLL
  2021.         0,// FHS
  2022.         0,// DM1
  2023.         0,// DH1
  2024.         10,// HV1
  2025.         20,// HV2
  2026.         30,// HV3
  2027.         10,// DV
  2028.         0,// AUX
  2029.         0,// DM3
  2030.         0,// DH3
  2031.         0,// DM5
  2032.         0,// DH5
  2033.         1,// EV3
  2034.         1,// EV4
  2035.         1,//EV5
  2036.         0,// 2-DH1
  2037.         1,// 2-EV3
  2038.         0,// 2-DH3
  2039.         1,// 2-EV5
  2040.         0,// 2-DH5
  2041.         1,// 3-EV3
  2042.         0,// 3-DH1
  2043.         0,// 3-DH3
  2044.         1,// 3-EV5
  2045.         0// 3-DH5
  2046.     };
  2047.     return us_min_len[index];
  2048. }
  2049. //--------------------------------------------------------------------------
  2050. unsigned short TfrmBT::Get_RFTxDataMaxLen( int index )
  2051. {
  2052.     unsigned short us_max_len[] =
  2053.     {
  2054.         0,// NULL
  2055.         0,// POLL
  2056.         0,// FHS
  2057.         17,// DM1
  2058.         27,// DH1
  2059.         10,// HV1
  2060.         20,// HV2
  2061.         30,// HV3
  2062.         19,// DV
  2063.         255,// AUX
  2064.         121,// DM3
  2065.         183,// DH3
  2066.         224,// DM5
  2067.         339,// DH5
  2068.         30,// EV3
  2069.         120,// EV4
  2070.         180,//EV5
  2071.         54,// 2-DH1
  2072.          60,// 2-EV3
  2073.         367,// 2-DH3
  2074.         360,// 2-EV5
  2075.         679,// 2-DH5
  2076.          90,// 3-EV3
  2077.          83,// 3-DH1
  2078.         552,// 3-DH3
  2079.         540,// 3-EV5
  2080.        1021 // 3-DH5
  2081.     };
  2082.     return us_max_len[index];
  2083. }
  2084. //---------------------------------------------------------------------------
  2085. void TfrmBT::DisplayRFDefaultDataLen( void )
  2086. {
  2087.     unsigned short len = Get_RFTxDataDefaultLen(cbRFTxType->ItemIndex);
  2088.     edtRFTxDataLen->Text = IntToStr( len );
  2089. }
  2090. //---------------------------------------------------------------------------
  2091. void __fastcall TfrmBT::edtRFTxDataLenCheck(TObject *Sender)
  2092. {
  2093.     unsigned short  us_min_len = Get_RFTxDataMinLen(cbRFTxType->ItemIndex);
  2094.     unsigned short  us_max_len = Get_RFTxDataMaxLen(cbRFTxType->ItemIndex);
  2095.     unsigned short  us_data;
  2096.     AnsiString  text;
  2097.     AnsiString  as_hint;
  2098.     TEdit *edit = (TEdit*)Sender;
  2099.     if( us_min_len != us_max_len )
  2100.     {
  2101.         as_hint = " value should be " + IntToStr( us_min_len ) +"~" + IntToStr( us_max_len );
  2102.     }
  2103.     else
  2104.     {   as_hint = " value should be " + IntToStr( us_min_len );
  2105.     }
  2106.     text = edit->Text;
  2107.     if( !IsValidBTTxDataLength( text, us_data, Get_RFTxDataMinLen(cbRFTxType->ItemIndex), Get_RFTxDataMaxLen(cbRFTxType->ItemIndex) ) )
  2108.     {
  2109.         edit->Text = Get_RFTxDataDefaultLen(cbRFTxType->ItemIndex);
  2110.         ShowHintLabel( edit, as_hint.c_str() );
  2111.         edit->SetFocus();
  2112.         return;
  2113.     }
  2114.     m_sBtRf.us_data_len = us_data;
  2115. }
  2116. //---------------------------------------------------------------------------
  2117. void __fastcall TfrmBT::edtRFTxPollPeriodCheck(TObject *Sender)
  2118. {
  2119.     unsigned char  uc_data;
  2120.     AnsiString  text;
  2121.     TEdit *edit = (TEdit*)Sender;
  2122.     char  hint[] =
  2123.     {   " value should be 0~255 "
  2124.     };
  2125.     text = edit->Text;
  2126.     if( !IsValidBTTxPollPeriod( text, uc_data ) )
  2127.     {
  2128.         edit->Text = 0;
  2129.         ShowHintLabel( edit, hint );
  2130.         edit->SetFocus();
  2131.         return;
  2132.     }
  2133.     m_sBtRf.uc_poll_period = uc_data;
  2134. }
  2135. //---------------------------------------------------------------------------
  2136. void __fastcall TfrmBT::edtRFTxLevelCheck(TObject *Sender)
  2137. {
  2138.     unsigned char  uc_data;
  2139.     AnsiString  text;
  2140.     TEdit *edit = (TEdit*)Sender;
  2141.     char  hint[] =
  2142.     {   " value should be 1~7 "
  2143.     };
  2144.     text = edit->Text;
  2145.     if( !IsValidBTTxPcl( text, uc_data ) )
  2146.     {
  2147.         edit->Text = 7;
  2148.         ShowHintLabel( edit, hint );
  2149.         edit->SetFocus();
  2150.         return;
  2151.     }
  2152.     m_sBtRf.uc_pcl = uc_data;
  2153. }
  2154. //---------------------------------------------------------------------------
  2155. void __fastcall TfrmBT::edtRFTxAccessCodeCheck(TObject *Sender)
  2156. {
  2157.     unsigned char  uc_data;
  2158.     AnsiString  text;
  2159.     TEdit *edit = (TEdit*)Sender;
  2160.     char  hint[] =
  2161.     {   " value should be 0~255 "
  2162.     };
  2163.     text = edit->Text;
  2164.     if( !IsValidHexBTTxAccessCode( text, uc_data ) )
  2165.     {
  2166.         edit->Text = 0;
  2167.         ShowHintLabel( edit, hint );
  2168.         edit->SetFocus();
  2169.         return;
  2170.     }
  2171.     m_sBtRf.s_access_code.uc_access_code[edit->Tag] = uc_data;
  2172. }
  2173. //---------------------------------------------------------------------------
  2174. //---------------------------------------------------------------------------
  2175. void __fastcall TfrmBT::btnRFTxStartClick(TObject *Sender)
  2176. {
  2177.     if( rbRFTx->Checked )
  2178.     {
  2179.         if( ! CheckRFFields( CHECK_MASK_RF_TX ) )
  2180.         {
  2181.             sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF TX fail";
  2182.             Application->MessageBox( "Execution Failure : BT RF TX", "FAILURE", MB_OK );
  2183.             return;
  2184.         }
  2185.     }
  2186.     else
  2187.     {
  2188.         if( ! CheckRFFields( CHECK_MASK_RF_RX ) )
  2189.         {
  2190.             sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF RX fail";
  2191.             Application->MessageBox( "Execution Failure : BT RF RX", "FAILURE", MB_OK );
  2192.             return;
  2193.         }
  2194.     }
  2195.     m_sBtRf.hPostMsgDestHandle = this->Handle;
  2196.     m_sBtRf.log                = m_pRFLog;
  2197.     m_sBtRf.e_test_type        = BT_TX;
  2198.     CurrentPageLock();
  2199.     if( rbRFTx->Checked )
  2200.     {
  2201.         sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF TX progressing";
  2202.         m_BT_RF_Obj.ConfirmCallback  = ::ConfirmCallback_RFTX;
  2203.     }
  2204.     else
  2205.     {
  2206.         sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF RX progressing";
  2207.         m_BT_RF_Obj.ConfirmCallback  = ::ConfirmCallback_RFRX;
  2208.     }
  2209.     m_BT_RF_Obj.REQ_Start( m_sBtRf );
  2210. }
  2211. //---------------------------------------------------------------------------
  2212. void TfrmBT::ConfirmCallback_RFTX(void)
  2213. {
  2214.     E_METAAPP_RESULT_T state = m_BT_RF_Obj.Get_ConfirmState();
  2215.     switch (state)
  2216.     {
  2217.         case METAAPP_SUCCESS:
  2218.         {
  2219.             sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX progressing";
  2220.         }
  2221.         break;
  2222.         case METAAPP_FAIL:
  2223.         {
  2224.             sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX fail";
  2225.             Application->MessageBox( "Execution Failure : BT RF TX", "FAILURE", MB_OK );
  2226.             Application->BringToFront();
  2227.             CurrentPageReset();
  2228.         }
  2229.         break;
  2230.         case METAAPP_TIMEOUT:
  2231.         {
  2232.              Force_BT_Stop( true );
  2233.              sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX timeout";
  2234.              Application->MessageBox( "Execution Timeout : BT RF TX", "TIMEOUT", MB_OK );
  2235.              CurrentPageReset();
  2236.         }
  2237.         break;
  2238.         case METAAPP_CANCEL:
  2239.         case METAAPP_STOP:
  2240.         {
  2241.              sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX stop";
  2242.              CurrentPageReset();
  2243.         }
  2244.         break;
  2245.     }
  2246. }
  2247. //--------------------------------------------------------------------------
  2248. void TfrmBT::SyncLAPAndAccessCode( void )
  2249. {
  2250.     unsigned int syncHi;
  2251.     unsigned int syncLo;
  2252.     unsigned int a_lap = 0;
  2253.     char lap_string[9];
  2254.     unsigned char hex_string[3];
  2255.     char sync_string[16];
  2256.     // transform LAP string to 32bit value
  2257.     //GetDlgItemText(IDC_LAP, lap_string, 9);
  2258.     AnsiString as_lap;
  2259.     for( int i=BD_ADDRESS_LAP_LEN-1; i>=0; i-- )
  2260.     {   as_lap += m_edtRFLAP[i]->Text;
  2261.     }
  2262.     AnsiString_Hex_To_UnsignedInt( as_lap, a_lap );
  2263.    // for(int i = 0; i < 6; i++)
  2264.    //    lap_string[i] = lap_string[i+2];
  2265.    // ascii_hex_string_2_hex_string((unsigned char *)lap_string, hex_string, 6);
  2266.    // a_lap = hex_string[0] << 16;
  2267.    /// a_lap |= hex_string[1] << 8;
  2268.     //a_lap |= hex_string[2];
  2269.     // 32 bit LAP --> 64 bit Access Word
  2270.     Build_Sync_Word(a_lap, &syncHi, &syncLo);
  2271.     // print 64 bit Access Word
  2272.     sprintf(sync_string, "%08X%08X", syncHi, syncLo);
  2273.    // SetDlgItemText(IDC_SYNC, sync_string);
  2274.     m_sBtRf.s_access_code.uc_access_code[7] = (syncHi>>24) & 0x000000FF;
  2275.     m_sBtRf.s_access_code.uc_access_code[6] = (syncHi>>16) & 0x000000FF;
  2276.     m_sBtRf.s_access_code.uc_access_code[5] = (syncHi>>8 ) & 0x000000FF;
  2277.     m_sBtRf.s_access_code.uc_access_code[4] = (syncHi    ) & 0x000000FF;
  2278.     m_sBtRf.s_access_code.uc_access_code[3] = (syncLo>>24) & 0x000000FF;
  2279.     m_sBtRf.s_access_code.uc_access_code[2] = (syncLo>>16) & 0x000000FF;
  2280.     m_sBtRf.s_access_code.uc_access_code[1] = (syncLo>>8 ) & 0x000000FF;
  2281.     m_sBtRf.s_access_code.uc_access_code[0] = (syncLo    ) & 0x000000FF;
  2282. }
  2283. //--------------------------------------------------------------------------
  2284. // 32 bit LAP --> 64 bit Access Word
  2285. void TfrmBT::Build_Sync_Word(const unsigned int a_lap, unsigned int* pSyncHi, unsigned int* pSyncLo)
  2286. {
  2287.     unsigned int BCHgeneratorHi = 026053423665L;
  2288.     unsigned int BCHgeneratorLo = (1L << 29);
  2289.     const unsigned int p_PNsequenceHi = 0x83848D96L;
  2290.     const unsigned int p_PNsequenceLo = 0xBBCC54FCL;
  2291.     const unsigned int B_BitsA23_0 = 0x2C000000U;
  2292.     const unsigned int B_BitsA23_1 = 0x13000000U;
  2293.     unsigned int x_infoBits;
  2294.     unsigned int x_encodeBits;
  2295.     unsigned int regHi, regLo;
  2296.     unsigned int count;
  2297.     #define BIT23 0x00800000L
  2298.     #define BIT31 0x80000000UL
  2299.     /* V0.8 p126                                                                */
  2300.     /* Step 1   Format the 30 information bits to encode  LAP + Barker Sequence */
  2301.     /*          x(D) = a(D) +D^24 B_A23(D)                                      */
  2302.     if (a_lap&BIT23)                       /* Toggle bits 5:0                */
  2303.         x_infoBits = a_lap | B_BitsA23_1;
  2304.     else
  2305.         x_infoBits = a_lap | B_BitsA23_0;
  2306.     /* Step 2   Add (Exor) the information covering part of the PN sequence     */
  2307.     /*          x~(D) = x(D) + p34 + p35D + ... + p63D^29                       */
  2308.     x_encodeBits =  (x_infoBits ^ (p_PNsequenceHi>>2)) << 2;
  2309.     /* Step 3   Generate parity bits of BCH(64,30)                              */
  2310.     /*          c~(D) = D^34 x~(D) mod g(D)                                     */
  2311.     /* Initialise                                                               */
  2312.     regHi = x_encodeBits;
  2313.     regLo = 0;
  2314.     /* Generate remainder      64 bit dividend, 35 bit divisor                  */
  2315.     count = 0;
  2316.     while (++count <= 64 - 35 + 1)      /* Reduce/Shift the remaining 30 bits*/
  2317.     {
  2318.         if (regHi&BIT31)                 /* Reduce                            */
  2319.         {
  2320.             regHi ^= BCHgeneratorHi;
  2321.             regLo ^= BCHgeneratorLo;
  2322.         }
  2323.         regHi = (regHi<<1) + (regLo>>31);/*Shift full register                */
  2324.         regLo <<= 1;
  2325.     }
  2326.     /* Step 4   Create the BCH codeword                                         */
  2327.     /*          s~(D) = D^34 x~(D) + c~(D)    Note: Exor Addition               */
  2328.     /* Step 5   Add the PN Sequence                                             */
  2329.     /*          s(D) = s(D) + p(D)            Note: Exor Addition               */
  2330.     *pSyncLo = ((regHi<<2)  ^ (regLo>>30))    ^ p_PNsequenceLo;
  2331.     *pSyncHi = ((regHi>>30) ^ (x_encodeBits)) ^ p_PNsequenceHi;
  2332.     /* Hardware ? */
  2333.     /* Step 6   Prepend and append the (DC-free preamble and trailer            */
  2334.     /*          y(D = F_c0(D) + D^4 s(D) + D^68 F_a23(D)                        */
  2335. }
  2336. //---------------------------------------------------------------------------
  2337. //void __fastcall TfrmBT::edtRFTxLapCheck(TObject *Sender)
  2338. //{
  2339. //    unsigned int  ui_data;
  2340. //    AnsiString  text;
  2341. //    TEdit *edit = (TEdit*)Sender;
  2342. //    char  hint[] =
  2343. //    {   " value should be 0~4294967296 "
  2344. //    };
  2345. //
  2346. //    text = edit->Text;
  2347. //    if( !IsValidHexBTLAP( text, ui_data ) )
  2348. //    {
  2349. //        edit->Text = 0;
  2350. //        ShowHintLabel( edit, hint );
  2351. //        edit->SetFocus();
  2352. //        return;
  2353. //    }
  2354. //
  2355. //    m_sBtRf.ui_lap = ui_data;
  2356. //    SyncLAPAndAccessCode();
  2357. //    ReDrawRFFields( DRAM_MASK_RF_ACCESS_CODE );
  2358. //}
  2359. //---------------------------------------------------------------------------
  2360. void __fastcall TfrmBT::btnRFRxStartClick(TObject *Sender)
  2361. {
  2362.     if( ! CheckRFFields( CHECK_MASK_RF_RX ) )
  2363.     {
  2364.         sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF RX fail";
  2365.         Application->MessageBox( "Execution Failure : BT RF RX", "FAILURE", MB_OK );
  2366.         return;
  2367.     }
  2368.     m_sBtRf.hPostMsgDestHandle = this->Handle;
  2369.     m_sBtRf.log                = m_pRFLog;
  2370.     m_sBtRf.e_test_type        = BT_RX;
  2371.     CurrentPageLock();
  2372.     sbRF->Panels->Items[0]->Text = (AnsiString) "  BT RF RX progressing";
  2373.     m_BT_RF_Obj.ConfirmCallback  = ::ConfirmCallback_RFRX;
  2374.     m_BT_RF_Obj.REQ_Start( m_sBtRf );
  2375. }
  2376. //---------------------------------------------------------------------------
  2377. void  TfrmBT::ConfirmCallback_RFRX(void)
  2378. {
  2379.     E_METAAPP_RESULT_T state = m_BT_RF_Obj.Get_ConfirmState();
  2380.     switch (state)
  2381.     {
  2382.         case METAAPP_SUCCESS:
  2383.         {
  2384.             sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX progressing";
  2385.         }
  2386.         break;
  2387.         case METAAPP_FAIL:
  2388.         {
  2389.             sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX fail";
  2390.             Application->MessageBox( "Execution Failure : BT RF TX", "FAILURE", MB_OK );
  2391.             Application->BringToFront();
  2392.             CurrentPageReset();
  2393.         }
  2394.         break;
  2395.         case METAAPP_TIMEOUT:
  2396.         {
  2397.              Force_BT_Stop( true );
  2398.              sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX timeout";
  2399.              Application->MessageBox( "Execution Timeout : BT RF TX", "TIMEOUT", MB_OK );
  2400.              CurrentPageReset();
  2401.         }
  2402.         break;
  2403.         case METAAPP_CANCEL:
  2404.         case METAAPP_STOP:
  2405.         {
  2406.              sbRF->Panels->Items[0]->Text = (AnsiString)"  BT RF TX stop";
  2407.              CurrentPageReset();
  2408.         }
  2409.         break;
  2410.     }
  2411. }
  2412. //--------------------------------------------------------------------------
  2413. void __fastcall TfrmBT::rbHCICategoryClick(TObject *Sender)
  2414. {
  2415.     cbHCICategory->Enabled = true;
  2416.     cbHCIGroup->Enabled    = false;
  2417.     m_pvHCICategory = m_BT_HCI_Obj.Get_HciCategoryVector();
  2418.     DisplayHCIUI( DRAW_MASK_HCI_CATEGORY | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  2419. }
  2420. //---------------------------------------------------------------------------
  2421. void __fastcall TfrmBT::rbHCIGroupClick(TObject *Sender)
  2422. {
  2423.     cbHCICategory->Enabled = false;
  2424.     cbHCIGroup->Enabled    = true;
  2425.     m_pvHCIGroup = m_BT_HCI_Obj.Get_HciGroupVector();
  2426.     DisplayHCIUI( DRAW_MASK_HCI_GROUP | DRAW_MASK_HCI_COMMAND | DRAW_MASK_HCI_PARAMETER, 0, 0 );
  2427. }
  2428. //---------------------------------------------------------------------------
  2429. void __fastcall TfrmBT::FormShow(TObject *Sender)
  2430. {
  2431.     if (m_bFirstFormShow)
  2432.     {
  2433.         m_bFirstFormShow = false;
  2434.         m_META_HANDLE_Obj.REQ_AllocateSecondHandle_Start();
  2435.         unsigned short ComPortCount = MAX_SUPPORT_COM_NUM;
  2436.         int result = ComPortEnumerate( m_usComPortArray, &ComPortCount );
  2437.         if (result)
  2438.         {
  2439.             Application->MessageBox("Enumerate COM port fail", "FAIL", MB_OK);
  2440.             return;
  2441.         }
  2442.         for (int i=0; i<ComPortCount; i++)
  2443.         {
  2444.             cbPKTCOM->Items->Add((AnsiString) "COM" + IntToStr( m_usComPortArray[i]));
  2445.             m_cbMTBT2COM->Items->Add((AnsiString) "COM" + IntToStr( m_usComPortArray[i]));
  2446.         }
  2447.         cbPKTCOM->ItemIndex = 0;
  2448.         m_cbMTBT2COM->ItemIndex = 0;
  2449.         // string grid
  2450.         sgSendHCI->Cells[HCI_NAME_COL_IDX][0] = "Send Parameter";
  2451.         sgSendHCI->Cells[HCI_BYTE_COL_IDX][0] = "Bytes";
  2452.         if( rbHCIDec->Checked )
  2453.         {
  2454.             sgSendHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value";
  2455.         }
  2456.         else
  2457.         {
  2458.             sgSendHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value (Hex)";
  2459.         }
  2460.         sgReceiveHCI->Cells[HCI_NAME_COL_IDX][0] = "Receive Parameter";
  2461.         sgReceiveHCI->Cells[HCI_BYTE_COL_IDX][0] = "Bytes";
  2462.         if( rbHCIDec->Checked )
  2463.         {
  2464.             sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value";
  2465.         }
  2466.         else
  2467.         {
  2468.             sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value (Hex)";
  2469.         }
  2470.         // HCI file
  2471.         DisplayHCIFile();
  2472.         // RF
  2473.         DisplayRFDefaultDataLen();
  2474.         // module test
  2475.         ReloadScriptFiles();
  2476.         UpdateProcessGroup();
  2477.     }
  2478. }
  2479. //---------------------------------------------------------------------------
  2480. void __fastcall TfrmBT::glbTimerTimer(TObject *Sender)
  2481. {
  2482.     glbTimer->Enabled = false;
  2483.     glbTimer->Interval = 1000;
  2484.     glbTimer->Enabled = true;
  2485.         
  2486. }
  2487. //---------------------------------------------------------------------------
  2488. void __fastcall TfrmBT::btnPKTConnectDUTClick(TObject *Sender)
  2489. {
  2490.     shpPKTConnect->Brush->Color = clRed;
  2491.     m_sCWT.i_meta_handle = m_META_HANDLE_Obj.Get_SecondHandle();
  2492.     SetMetaConnectReq(m_sCWT.META_connect_req);
  2493.     m_sCWT.neSuccess = on_PKTConnectWithTarget_Success;
  2494.     m_sCWT.neByUser  = on_PKTConnectWithTarget_ByUser;
  2495.     AbortConnectWithTarget();
  2496.     m_pT_CWT = new T_META_ConnectWithTarget(true, &m_sCWT);
  2497.     if (NULL != m_pT_CWT)
  2498.     {
  2499.         m_pT_CWT->FreeOnTerminate = true;
  2500.         m_pT_CWT->OnTerminate = on_PKTConnectWithTarget_Fail;
  2501.         m_pT_CWT->Priority = tpHighest;
  2502.     }
  2503.     else
  2504.     {
  2505.         m_pPKTLog->Add( DateToStr(Date()) +  " " + TimeToStr(Time()) +
  2506.                              " FAIL: connect with target"
  2507.                             );
  2508.         PostMessage(
  2509.                               this->Handle,
  2510.                               WM_ML_BT_PRINT_MSG,
  2511.                               0,
  2512.                               0
  2513.                             );
  2514.                  return;
  2515.     }
  2516.     if( NULL != m_pT_CWT )
  2517.     {
  2518.         m_pT_CWT->Resume();
  2519.     }
  2520. }
  2521. //---------------------------------------------------------------------------
  2522. void __fastcall TfrmBT::on_PKTConnectWithTarget_Success(TObject *Sender)
  2523. {
  2524.     if (PAGEIDX_BT_PKT == m_pctlToolSel->ActivePageIndex)
  2525.     {
  2526.         shpPKTConnect->Brush->Color = clYellow;
  2527.     }
  2528.     else
  2529.     {
  2530.         m_shpMTConnect->Brush->Color = clYellow;
  2531.     }
  2532.     m_bConnectTargetok = true;
  2533.     CBTPOWER BT_POWER_Obj;
  2534.     BT_POWER_Obj.REQ_Power_On_Second_BT_Start();
  2535. }
  2536. //---------------------------------------------------------------------------
  2537. void __fastcall TfrmBT::on_PKTConnectWithTarget_Fail(TObject *Sender)
  2538. {
  2539. }
  2540. //---------------------------------------------------------------------------
  2541. void __fastcall TfrmBT::on_PKTConnectWithTarget_ByUser(TObject *Sender)
  2542. {
  2543. }
  2544. //---------------------------------------------------------------------------
  2545. void TfrmBT::SetMetaConnectReq(META_Connect_Req &META_connect_req)
  2546. {
  2547.     AnsiString  as_BootTimeout, as_METAConnectTimeout;
  2548.     int com_index;
  2549.     int baudrate_index;
  2550.     if (PAGEIDX_BT_PKT == m_pctlToolSel->ActivePageIndex)
  2551.     {
  2552.         com_index = cbPKTCOM->ItemIndex;
  2553.         baudrate_index = cbPKTBaudRate->ItemIndex;
  2554.     }
  2555.     else
  2556.     {
  2557.         com_index = m_cbMTBT2COM->ItemIndex;
  2558.         baudrate_index = m_cbMTBT2Baud->ItemIndex;
  2559.     }
  2560.     as_BootTimeout = read_Boot_timeout("MF_setup.txt", Application->ExeName);
  2561.     if (as_BootTimeout.AnsiCompareIC("infinite") == 0)
  2562.     {
  2563.         META_connect_req.boot_meta_arg.m_ms_boot_timeout = BOOT_INFINITE;
  2564.     }
  2565.     else
  2566.     {
  2567.         META_connect_req.boot_meta_arg.m_ms_boot_timeout = as_BootTimeout.ToInt();
  2568.     }
  2569.     META_connect_req.com_port = m_usComPortArray[com_index];
  2570.     META_connect_req.boot_meta_arg.m_bbchip_type = frmMainSel->Get_CurBBChipType();
  2571.     META_connect_req.boot_meta_arg.m_ext_clock = frmMainSel->Get_CurExternalClockType();
  2572.     switch ((E_BAUD_RATE_INDEX) baudrate_index)
  2573.     {
  2574.         case BAUD_RATE_AUTO_INDEX:
  2575.         {
  2576.             META_connect_req.baudrate[0] = META_BAUD57600;
  2577.             META_connect_req.baudrate[1] = META_BAUD115200;
  2578.             META_connect_req.baudrate[2] = META_BAUD230400;
  2579.             META_connect_req.baudrate[3] = META_BAUD460800;
  2580.             META_connect_req.baudrate[4] = META_BAUD921600;
  2581.             META_connect_req.baudrate[5] = META_BAUD_END;
  2582.         }
  2583.         break;
  2584.         case BAUD_RATE_57600_INDEX:
  2585.         {
  2586.              META_connect_req.baudrate[0] = META_BAUD57600;
  2587.              META_connect_req.baudrate[1] = META_BAUD_END;
  2588.         }
  2589.         break;
  2590.         case BAUD_RATE_115200_INDEX:
  2591.         {
  2592.              META_connect_req.baudrate[0] = META_BAUD115200;
  2593.              META_connect_req.baudrate[1] = META_BAUD_END;
  2594.         }
  2595.         break;
  2596.         case BAUD_RATE_230400_INDEX:
  2597.         {
  2598.              META_connect_req.baudrate[0] = META_BAUD230400;
  2599.              META_connect_req.baudrate[1] = META_BAUD_END;
  2600.         }
  2601.         break;
  2602.         case BAUD_RATE_460800_INDEX:
  2603.         {
  2604.              META_connect_req.baudrate[0] = META_BAUD460800;
  2605.              META_connect_req.baudrate[1] = META_BAUD_END;
  2606.         }
  2607.         break;
  2608.         case BAUD_RATE_921600_INDEX:
  2609.         {
  2610.              META_connect_req.baudrate[0] = META_BAUD921600;
  2611.              META_connect_req.baudrate[1] = META_BAUD_END;
  2612.         }
  2613.         break;
  2614.         default: // set baud rate = AUTO
  2615.         {
  2616.              META_connect_req.baudrate[0] = META_BAUD115200;
  2617.              META_connect_req.baudrate[1] = META_BAUD_END;
  2618.         }
  2619.         break;
  2620.     }
  2621.     META_connect_req.flowctrl = META_SW_FLOWCTRL;
  2622.     as_METAConnectTimeout = read_META_Connect_timeout("MF_setup.txt", Application->ExeName);
  2623.     META_connect_req.ms_connect_timeout = as_METAConnectTimeout.ToInt();
  2624.     META_connect_req.boot_meta_arg.m_cb_in_brom_stage = NULL;
  2625.     META_connect_req.boot_meta_arg.m_cb_in_brom_stage_arg = NULL;
  2626.     // security
  2627.     META_connect_req.boot_meta_arg.m_speedup_brom_baudrate = _TRUE; //115200
  2628.     META_connect_req.boot_meta_arg.m_ready_power_on_wnd_handle = NULL;
  2629.     META_connect_req.boot_meta_arg.m_ready_power_on_wparam = NULL;
  2630.     META_connect_req.boot_meta_arg.m_ready_power_on_lparam = NULL;
  2631.     META_connect_req.boot_meta_arg.m_auth_handle = frmMainSel->Get_SLA_Object()->Get_AuthHandle();
  2632.     META_connect_req.boot_meta_arg.m_cb_sla_challenge = SLA_Challenge;
  2633.     META_connect_req.boot_meta_arg.m_cb_sla_challenge_arg = NULL;
  2634.     META_connect_req.boot_meta_arg.m_cb_sla_challenge_end = SLA_Challenge_END;
  2635.     META_connect_req.boot_meta_arg.m_cb_sla_challenge_end_arg = NULL;
  2636.     // EDGE PC card
  2637.    // META_connect_req.boot_meta_arg.m_cb_com_init_stage = ::cb_PowerOnOxford;
  2638.   //  META_connect_req.boot_meta_arg.m_cb_com_init_stage_arg = NULL;
  2639. }
  2640. //---------------------------------------------------------------------------
  2641. void TfrmBT::ReDrawPKTFields(E_DRAM_MASK_PKT draw_mask)
  2642. {
  2643.     if (draw_mask & DRAM_MASK_PKT_MONITOR)
  2644.     {
  2645.         int count;
  2646.         if (BTMODULE_MT6611 != m_cBtId)
  2647.         {
  2648.             count = BT_PACKET_IDX_NONEDR_COUNT;
  2649.         }
  2650.         else
  2651.         {
  2652.             count = BT_PACKET_IDX_COUNT;
  2653.         }
  2654.         for (int i=0; i<count; i++)
  2655.         {
  2656.             if (m_cbPKTType[i]->Checked)
  2657.             {
  2658.                 m_edtPKTTesterTXCount[i]->Text = IntToStr( m_sBTMonCnf.s_tester_monitor.ui_tx_pkt_count[i] );
  2659.                 m_edtPKTTesterRXCount[i]->Text = IntToStr( m_sBTMonCnf.s_tester_monitor.ui_rx_pkt_count[i] );
  2660.                 m_edtPKTDUTTXCount[i]->Text    = IntToStr( m_sBTMonCnf.s_dut_monitor.ui_tx_pkt_count[i] );
  2661.                 m_edtPKTDUTRXCount[i]->Text    = IntToStr( m_sBTMonCnf.s_dut_monitor.ui_rx_pkt_count[i] );
  2662.             }    
  2663.         }
  2664.     }
  2665. }
  2666. //---------------------------------------------------------------------------
  2667. bool TfrmBT::IsPKTTestFinish( E_BT_PACKET_IDX idx )
  2668. {   return m_sPKTStatus.b_finish[idx];
  2669. }
  2670. //---------------------------------------------------------------------------
  2671. bool TfrmBT::IsAllPKTTestFinish( void )
  2672. {
  2673.     for( int i=0; i<BT_PACKET_IDX_COUNT; i++ )
  2674.     {
  2675.         if( m_cbPKTType[i]->Checked )
  2676.         {
  2677.             if(  ! m_sPKTStatus.b_finish[i] )
  2678.                 return false;
  2679.         }        
  2680.     }
  2681.     return true;
  2682. }
  2683. //----------------------------------------------------------------------------
  2684. bool TfrmBT::SetPKTFinish(E_BT_PACKET_IDX idx)
  2685. {
  2686.     if (idx >= BT_PACKET_IDX_COUNT)
  2687.     {
  2688.         return false;
  2689.     }
  2690.     unsigned int ui_tester_tx = m_edtPKTTesterTXCount[idx]->Text.ToInt();
  2691.     unsigned int ui_tester_rx = m_edtPKTTesterRXCount[idx]->Text.ToInt();
  2692.     unsigned int ui_dut_tx    = m_edtPKTDUTTXCount[idx]->Text.ToInt();
  2693.     unsigned int ui_dut_rx    = m_edtPKTDUTRXCount[idx]->Text.ToInt();
  2694.     unsigned int ui_pkt_count = m_edtPKTPktCount[idx]->Text.ToInt();
  2695.     if( (ui_tester_tx == m_uiPKTLastTesterTx) ||
  2696.         (ui_tester_rx == m_uiPKTLastTesterRx) ||
  2697.         (ui_dut_tx    == m_uiPKTLastDutTx)    ||
  2698.         (ui_dut_rx    == m_uiPKTLastDutRx)
  2699.       )
  2700.     {
  2701.         m_uiPKTCount++;
  2702.     }
  2703.     else
  2704.     {   m_uiPKTCount = 0;
  2705.     }
  2706.     if( (ui_tester_tx >= ui_pkt_count ) &&
  2707.         ( ui_tester_rx >= ui_pkt_count ) &&
  2708.         ( ui_dut_tx    >= ui_pkt_count ) &&
  2709.         ( ui_dut_rx    >= ui_pkt_count ) ||
  2710.         ( m_uiPKTCount > 3             )
  2711.       )
  2712.     {    m_sPKTStatus.b_finish[idx] = true;
  2713.          m_uiPKTLastTesterTx = 0;
  2714.          m_uiPKTLastTesterRx = 0;
  2715.          m_uiPKTLastDutTx    = 0;
  2716.          m_uiPKTLastDutRx    = 0;
  2717.          m_uiPKTCount        = 0;
  2718.     }
  2719.     else
  2720.     {
  2721.          m_sPKTStatus.b_finish[idx] = false;
  2722.          m_uiPKTLastTesterTx = ui_tester_tx;
  2723.          m_uiPKTLastTesterRx = ui_tester_rx;
  2724.          m_uiPKTLastDutTx    = ui_dut_tx;
  2725.          m_uiPKTLastDutRx    = ui_dut_rx;
  2726.     }
  2727.     return true;
  2728. }
  2729. //---------------------------------------------------------------------------
  2730. bool TfrmBT::IsPKTTestRunning( E_BT_PACKET_IDX idx )
  2731. {
  2732.     if( PKT_STATE_IDLE == m_sPKTStatus.e_state[idx] )
  2733.         return false;
  2734.     else
  2735.         return true;
  2736. }
  2737. //---------------------------------------------------------------------------
  2738. bool TfrmBT::CheckPKTFields( E_CHECK_MASK_PKT mark )
  2739. {
  2740. #if 0
  2741.     AnsiString_To_Hex_BDAddress( stTesterBDAddr->Caption, m_sBTPKT.s_tester_bd_addr );
  2742.     AnsiString_To_Hex_BDAddress( stDUTBDAddr->Caption, m_sBTPKT.s_dut_bd_addr );
  2743.     if( cbPKTDM1->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DM1) )  )
  2744.     {
  2745.         //m_sBTPKT.e_p1  = BT_ACL_P1_DM1;
  2746.         //m_sBTPKT.e_p2  = BT_ACL_P2_DM1;
  2747.         //m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2748.         //m_sBTPKT.e_idx = BT_PACKET_IDX_DM1;
  2749.     }
  2750.     else if( cbPKTDH1->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DH1) )  )
  2751.     {
  2752.         //m_sBTPKT.e_p1  = BT_ACL_P1_DH1;
  2753.        // m_sBTPKT.e_p2  = BT_ACL_P2_DH1;
  2754.        // m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2755.         m_sBTPKT.e_idx = BT_PACKET_IDX_DH1;
  2756.     }
  2757.     else if( cbPKTDM3->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DM3) )  )
  2758.     {
  2759.         //m_sBTPKT.e_p1  = BT_ACL_P1_DM3;
  2760.         //m_sBTPKT.e_p2  = BT_ACL_P2_DM3;
  2761.         //m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2762.         m_sBTPKT.e_idx = BT_PACKET_IDX_DM3;
  2763.     }
  2764.     else if( cbPKTDH3->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DH3) )  )
  2765.     {
  2766.         //m_sBTPKT.e_p1  = BT_ACL_P1_DH3;
  2767.         //m_sBTPKT.e_p2  = BT_ACL_P2_DH3;
  2768.         //m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2769.         m_sBTPKT.e_idx = BT_PACKET_IDX_DH3;
  2770.     }
  2771.     else if( cbPKTDM5->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DM5) )  )
  2772.     {
  2773.         //m_sBTPKT.e_p1  = BT_ACL_P1_DM5;
  2774.        // m_sBTPKT.e_p2  = BT_ACL_P2_DM5;
  2775.        // m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2776.         m_sBTPKT.e_idx = BT_PACKET_IDX_DM5;
  2777.     }
  2778.     else if( cbPKTDH5->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_DH5) )  )
  2779.     {
  2780.         //m_sBTPKT.e_p1  = BT_ACL_P1_DH5;
  2781.         //m_sBTPKT.e_p2  = BT_ACL_P2_DH5;
  2782.         //m_sBTPKT.e_sco = BT_SCO_UNKNOWN;
  2783.         m_sBTPKT.e_idx = BT_PACKET_IDX_DH5;
  2784.     }
  2785.     else if( cbPKTHV1->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_HV1) )  )
  2786.     {
  2787.         m_sBTPKT.e_p1  = BT_ACL_P1_HV1;
  2788.         m_sBTPKT.e_p2  = BT_ACL_P2_HV1;
  2789.         m_sBTPKT.e_sco = BT_SCO_HV1;
  2790.         m_sBTPKT.e_idx = BT_PACKET_IDX_HV1;
  2791.     }
  2792.     else if( cbPKTHV2->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_HV2) )  )
  2793.     {
  2794.         m_sBTPKT.e_p1  = BT_ACL_P1_HV2;
  2795.         m_sBTPKT.e_p2  = BT_ACL_P2_HV2;
  2796.         m_sBTPKT.e_sco = BT_SCO_HV2;
  2797.         m_sBTPKT.e_idx = BT_PACKET_IDX_HV2;
  2798.     }
  2799.     else if( cbPKTHV3->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_HV3) )  )
  2800.     {
  2801.         m_sBTPKT.e_p1  = BT_ACL_P1_HV3;
  2802.         m_sBTPKT.e_p2  = BT_ACL_P2_HV3;
  2803.         m_sBTPKT.e_sco = BT_SCO_HV3;
  2804.         m_sBTPKT.e_idx = BT_PACKET_IDX_HV3;
  2805.     }
  2806.     else if( cbPKTEV3->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_EV3) )  )
  2807.     {
  2808.         m_sBTPKT.e_p1  = BT_ACL_P1_EV3;
  2809.         m_sBTPKT.e_p2  = BT_ACL_P2_EV3;
  2810.         m_sBTPKT.e_sco = BT_SCO_EV3;
  2811.         m_sBTPKT.e_idx = BT_PACKET_IDX_EV3;
  2812.     }
  2813.     else if( cbPKTEV4->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_EV4) )  )
  2814.     {
  2815.         m_sBTPKT.e_p1  = BT_ACL_P1_EV4;
  2816.         m_sBTPKT.e_p2  = BT_ACL_P2_EV4;
  2817.         m_sBTPKT.e_sco = BT_SCO_EV4;
  2818.         m_sBTPKT.e_idx = BT_PACKET_IDX_EV4;
  2819.     }
  2820.     else if( cbPKTEV5->Checked && (! IsPKTTestFinish(BT_PACKET_IDX_EV5) )  )
  2821.     {
  2822.         m_sBTPKT.e_p1  = BT_ACL_P1_EV5;
  2823.         m_sBTPKT.e_p2  = BT_ACL_P2_EV5;
  2824.         m_sBTPKT.e_sco = BT_SCO_EV5;
  2825.         m_sBTPKT.e_idx = BT_PACKET_IDX_EV5;
  2826.     }
  2827.     AnsiString text;
  2828.     if( BT_PACKET_IDX_DH5 >= m_sBTPKT.e_idx )
  2829.     {
  2830.         text = m_edtPKTDataLen[m_sBTPKT.e_idx]->Text;      if( !IsValidBTTxDataLength( text, m_sBTPKT.us_packet_length, 0, 65535 ) )         {  edtPKTDataLenCheck(m_edtPKTDataLen[m_sBTPKT.e_idx]);        return false;   }
  2831.     }
  2832.     text = m_edtPKTPollPeriod[m_sBTPKT.e_idx]->Text;      if( !IsValidBTTxPollPeriod( text, m_sBTPKT.uc_poll_period ) )         {  edtPKTDataLenCheck(m_edtPKTPollPeriod[m_sBTPKT.e_idx]);        return false;   }
  2833.     text = m_edtPKTPktCount[m_sBTPKT.e_idx]->Text;      if( !IsValidBTTxPacketCount( text, m_sBTPKT.ui_packet_count ) )         {  edtPKTCountCheck(m_edtPKTPktCount[m_sBTPKT.e_idx]);        return false;   }
  2834. #endif
  2835.     if( CHECK_MASK_PKT_TCI == mark )
  2836.     {
  2837.         AnsiString text;
  2838.         text = m_edtPKTPollPeriod[m_sBTTCI.e_idx]->Text;      if( !IsValidBTTxPollPeriod( text, m_sBTTCI.uc_poll_period ) )         {  edtPKTDataLenCheck(m_edtPKTPollPeriod[m_sBTTCI.e_idx]);        return false;   }
  2839.         text = m_edtPKTPktCount[m_sBTTCI.e_idx]->Text;      if( !IsValidBTTxPacketCount( text, m_sBTTCI.ui_packet_count ) )         {  edtPKTCountCheck(m_edtPKTPktCount[m_sBTTCI.e_idx]);        return false;   }
  2840.         if( BT_PACKET_IDX_DH5 >= m_sBTTCI.e_idx )
  2841.         {
  2842.             text = m_edtPKTDataLen[m_sBTTCI.e_idx]->Text;      if( !IsValidBTTxDataLength( text, m_sBTTCI.us_packet_length, 0, 65535 ) )         {  edtPKTDataLenCheck(m_edtPKTDataLen[m_sBTTCI.e_idx]);        return false;   }
  2843.         }
  2844.         else
  2845.         {
  2846.             switch( m_sBTTCI.e_idx )
  2847.             {
  2848.                 case BT_PACKET_IDX_HV1:
  2849.                      m_sBTTCI.us_packet_length = 10;
  2850.                 break;
  2851.                 case BT_PACKET_IDX_HV2:
  2852.                      m_sBTTCI.us_packet_length = 20;
  2853.                 break;
  2854.                 case BT_PACKET_IDX_HV3:
  2855.                      m_sBTTCI.us_packet_length = 30;
  2856.                 break;
  2857.                 case BT_PACKET_IDX_EV3:
  2858.                      m_sBTTCI.us_packet_length = 30;
  2859.                 break;
  2860.                 case BT_PACKET_IDX_EV4:
  2861.                      m_sBTTCI.us_packet_length = 120;
  2862.                 break;
  2863.                 case BT_PACKET_IDX_EV5:
  2864.                      m_sBTTCI.us_packet_length = 180;
  2865.                 break;
  2866.             }
  2867.         }
  2868.     }
  2869.     return true;
  2870. }
  2871. //-------------------------------------------------------------------------
  2872. unsigned short TfrmBT::Get_PKTTxDataDefaultLen( E_BT_PACKET_IDX index )
  2873. {
  2874.     unsigned short us_default_len[] =
  2875.     {
  2876.         17, // DM1
  2877.         27, // DH1,
  2878.         10, // HV1,
  2879.         20, // HV2,
  2880.         30, // HV3,
  2881.        121, // DM3,
  2882.        183, // DH3,
  2883.        224, // DM5,
  2884.        339, // DH5,
  2885.         30, // EV3,
  2886.        120, // EV4,
  2887.        180, //EV5,
  2888.        // BT 2.0
  2889.         54, // 2-DH1,
  2890.         60, // 2-EV3,
  2891.        367, // 2-DH3,
  2892.        360, // 2-EV5,
  2893.        679, // 2-DH5,
  2894.         90, // 3-EV3,
  2895.         83, // 3-DH1,
  2896.        552, // 3-DH3,
  2897.        540, // 3-EV5,
  2898.       1021, // 3-DH5,
  2899.     };
  2900.     return us_default_len[index];
  2901. }
  2902. //--------------------------------------------------------------------------
  2903. unsigned short TfrmBT::Get_PKTTxDataMinLen( E_BT_PACKET_IDX index )
  2904. {
  2905.     unsigned short us_min_len[] =
  2906.     {
  2907.         0, // DM1
  2908.         0, // DH1,
  2909.         10, // HV1,
  2910.         20, // HV2,
  2911.         30, // HV3,
  2912.          0, // DM3,
  2913.          0, // DH3,
  2914.          0, // DM5,
  2915.          0, // DH5,
  2916.          1, // EV3,
  2917.          1, // EV4,
  2918.          1, //EV5,
  2919.          // BT 2.0
  2920.          0, // 2-DH1,
  2921.          1, // 2-EV3,
  2922.          0, // 2-DH3,
  2923.          1, // 2-EV5,
  2924.          0, // 2-DH5,
  2925.          1, // 3-EV3,
  2926.          0, // 3-DH1,
  2927.          0, // 3-DH3,
  2928.          1, // 3-EV5,
  2929.          0, // 3-DH5,
  2930.     };
  2931.     return us_min_len[index];
  2932. }
  2933. //--------------------------------------------------------------------------
  2934. unsigned short TfrmBT::Get_PKTTxDataMaxLen( E_BT_PACKET_IDX index )
  2935. {
  2936.     unsigned char us_max_len[] =
  2937.     {
  2938.         17, // DM1
  2939.         27, // DH1,
  2940.         10, // HV1,
  2941.         20, // HV2,
  2942.         30, // HV3,
  2943.        121, // DM3,
  2944.        183, // DH3,
  2945.        224, // DM5,
  2946.        339, // DH5,
  2947.         30, // EV3,
  2948.        120, // EV4,
  2949.        180, //EV5,
  2950.        // BT 2.0
  2951.         54, // 2-DH1,
  2952.         60, // 2-EV3,
  2953.        367, // 2-DH3,
  2954.        360, // 2-EV5,
  2955.        679, // 2-DH5,
  2956.         90, // 3-EV3,
  2957.         83, // 3-DH1,
  2958.        552, // 3-DH3,
  2959.        540, // 3-EV5,
  2960.       1021, // 3-DH5,
  2961.     };
  2962.     return us_max_len[index];
  2963. }
  2964. //---------------------------------------------------------------------------
  2965. void __fastcall TfrmBT::btnPKTStartClick(TObject *Sender)
  2966. {
  2967.     if( ! CheckPKTFields( CHECK_MASK_PKT ) )
  2968.     {
  2969.         sbPKT->Panels->Items[0]->Text = (AnsiString) "  BT packet test fail";
  2970.         Application->MessageBox( "Execution Failure : BT packet test", "FAILURE", MB_OK );
  2971.         return;
  2972.     }
  2973.     for( int i=0; i<BT_PACKET_IDX_COUNT; i++ )
  2974.     {
  2975.         m_sPKTStatus.b_finish[i] = false;
  2976.         m_sPKTStatus.e_state[i]  = PKT_STATE_IDLE;
  2977.     }
  2978.     m_sBTPKT.hPostMsgDestHandle = this->Handle;
  2979.     m_sBTPKT.log                = m_pPKTLog;
  2980.     CurrentPageLock();
  2981.     sbPKT->Panels->Items[0]->Text = (AnsiString) "  BT packet test progressing";
  2982.     MonitorTimer->Enabled = false;
  2983.     m_uiPKTLastTesterTx = 0;
  2984.     m_uiPKTLastTesterRx = 0;
  2985.     m_uiPKTLastDutTx    = 0;
  2986.     m_uiPKTLastDutRx    = 0;
  2987.     m_uiPKTCount        = 0;
  2988.     m_BT_PKT_Obj.ConfirmCallback = ::CNF_PKT;
  2989.     m_BT_PKT_Obj.REQ_Start( m_sBTPKT );
  2990. }
  2991. //---------------------------------------------------------------------------
  2992. void TfrmBT::CNF_PKT(void)
  2993. {
  2994.     E_METAAPP_RESULT_T state = m_BT_PKT_Obj.Get_ConfirmState();
  2995.     switch (state)
  2996.     {
  2997.         case METAAPP_SUCCESS:
  2998.         {
  2999.             MonitorTimer->Enabled = true;
  3000.             // m_sHCIEventFmt = m_BT_HCI_Obj.Get_HCIEvent();
  3001.            // DeComposeHCIEvent( m_sHCIEventFmt );
  3002.            // ReDrawHCIFields( DRAM_MASK_HCI_RECEIVE );
  3003.            // sbPKT->Panels->Items[0]->Text = (AnsiString)"  BT packet test successfully";
  3004.         }
  3005.         break;
  3006.         case METAAPP_FAIL:
  3007.         {
  3008.             CurrentPageReset();
  3009.             sbPKT->Panels->Items[0]->Text = (AnsiString)"  BT packet test fail";
  3010.             Application->MessageBox( "Execution Fail : BT packet test", "FAIL", MB_OK );
  3011.         }
  3012.         break;
  3013.         case METAAPP_TIMEOUT:
  3014.         {
  3015.             CurrentPageReset();
  3016.             sbPKT->Panels->Items[0]->Text = (AnsiString)"  BT packet test timeout";
  3017.             Application->MessageBox( "Execution Timeout : BT packet test", "TIMEOUT", MB_OK );
  3018.         }
  3019.         break;
  3020.         case METAAPP_CANCEL:
  3021.         case METAAPP_STOP:
  3022.         {
  3023.             CurrentPageReset();
  3024.             sbPKT->Panels->Items[0]->Text = (AnsiString)"  BT packet test stop";
  3025.         }    
  3026.         break;
  3027.     }
  3028. }
  3029. //---------------------------------------------------------------------------
  3030. void __fastcall TfrmBT::rbHCIDecClick(TObject *Sender)
  3031. {
  3032.     sgSendHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value";
  3033.     sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value";
  3034.     ReDrawHCIFields( DRAM_MASK_HCI_SEND | DRAM_MASK_HCI_RECEIVE );
  3035. }
  3036. //---------------------------------------------------------------------------
  3037. void __fastcall TfrmBT::rbHCIHexClick(TObject *Sender)
  3038. {
  3039.     sgSendHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value (Hex)";
  3040.     sgReceiveHCI->Cells[HCI_VALUE_COL_IDX][0] = "Value (Hex)";
  3041.     ReDrawHCIFields( DRAM_MASK_HCI_SEND | DRAM_MASK_HCI_RECEIVE );
  3042. }
  3043. //---------------------------------------------------------------------------
  3044. bool  TfrmBT::CheckSendHCIValue( void )
  3045. {
  3046.     S_BT_HCI_VALUE hci_value;
  3047.     vector<S_BT_HCI_PARAMETER>:: iterator iter;
  3048.     bool ok;
  3049.     for( int row=1; row<sgSendHCI->RowCount; row++ )
  3050.     {
  3051.         AnsiString as_name = sgSendHCI->Cells[HCI_NAME_COL_IDX][row];
  3052.         if( rbHCIDec->Checked )
  3053.         {
  3054.             if( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row].AnsiCompareIC("") == 0 )
  3055.             {
  3056.                 return true;
  3057.             }
  3058.             for( iter = m_pvSendHCIPar->begin(); iter != m_pvSendHCIPar->end(); iter++ )
  3059.             {
  3060.                 if( iter->as_name.AnsiCompareIC( as_name ) == 0 )
  3061.                 {
  3062.                    // iter->ui_bytes = sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt();
  3063.                    // iter->s_value = hci_value;
  3064.                     break;
  3065.                 }
  3066.             }
  3067.             if( iter->b_rangecheck )
  3068.             {   ok = IsValidDecBTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], (unsigned char)sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt(), hci_value, iter->s_min_value, iter->s_max_value ) ;
  3069.                 if( ! ok )
  3070.                 {
  3071.                     AnsiString as_min_range, as_max_range;
  3072.                     BTHCIValue_To_AnsiString( iter->s_min_value, as_min_range );
  3073.                     BTHCIValue_To_AnsiString( iter->s_max_value, as_max_range );
  3074.                     AnsiString as_msg = "Execution Fail : value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect, range : " + as_min_range + "~" + as_max_range;
  3075.                     sbHCI->Panels->Items[0]->Text = (AnsiString)"  value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3076.                     Application->MessageBox( as_msg.c_str(), "FAIL", MB_OK );
  3077.                     return false;
  3078.                 }
  3079.             }
  3080.             else
  3081.             {   ok = IsValidDecBTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], (unsigned char)sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt(), hci_value ) ;
  3082.                 if( ! ok )
  3083.                 {
  3084.                     AnsiString as_msg = "Execution Fail : value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3085.                     sbHCI->Panels->Items[0]->Text = (AnsiString)"  value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3086.                     Application->MessageBox( as_msg.c_str(), "FAIL", MB_OK );
  3087.                     return false;
  3088.                 }    
  3089.             }
  3090.         }
  3091.         else
  3092.         {
  3093.             if( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row].AnsiCompareIC("") == 0 )
  3094.             {
  3095.                 return true;
  3096.             }
  3097.             for( iter = m_pvSendHCIPar->begin(); iter != m_pvSendHCIPar->end(); iter++ )
  3098.             {
  3099.                 if( iter->as_name.AnsiCompareIC( as_name ) == 0 )
  3100.                 {
  3101.                    // iter->ui_bytes = sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt();
  3102.                    // iter->s_value = hci_value;
  3103.                     break;
  3104.                 }
  3105.             }
  3106.             if( iter->b_rangecheck )
  3107.             {   ok = IsValidHexBTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], (unsigned char)sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt(), hci_value, iter->s_min_value, iter->s_max_value ) ;
  3108.                 if( ! ok )
  3109.                 {
  3110.                     AnsiString as_min_range, as_max_range;
  3111.                     BTHCIValue_To_Hex_AnsiString( iter->s_min_value, as_min_range );
  3112.                     BTHCIValue_To_Hex_AnsiString( iter->s_max_value, as_max_range );
  3113.                     AnsiString as_msg = "Execution Fail : value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect, range : 0x" + as_min_range + "~0x" + as_max_range;
  3114.                     sbHCI->Panels->Items[0]->Text = (AnsiString)"  value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3115.                     Application->MessageBox( as_msg.c_str(), "FAIL", MB_OK );
  3116.                     return false;
  3117.                 }
  3118.             }
  3119.             else
  3120.             {
  3121.                 ok = IsValidHexBTHCIValue( sgSendHCI->Cells[HCI_VALUE_COL_IDX][row], (unsigned char)sgSendHCI->Cells[HCI_BYTE_COL_IDX][row].ToInt(), hci_value ) ;
  3122.                 if( ! ok )
  3123.                 {
  3124.                     AnsiString as_msg = "Execution Fail : value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3125.                     sbHCI->Panels->Items[0]->Text = (AnsiString)"  value of parameter " + sgSendHCI->Cells[HCI_NAME_COL_IDX][row] + " incorrect";
  3126.                     Application->MessageBox( as_msg.c_str(), "FAIL", MB_OK );
  3127.                     return false;
  3128.                 }
  3129.             }
  3130.         }
  3131.     }
  3132.     return true;
  3133. }
  3134. //---------------------------------------------------------------------------
  3135. void __fastcall TfrmBT::sgSendHCICheck(TObject *Sender)
  3136. {
  3137.     CheckSendHCIValue();    
  3138. }
  3139. //---------------------------------------------------------------------------
  3140. void __fastcall TfrmBT::edtHCITimeoutCheck(TObject *Sender)
  3141. {
  3142.     int data;
  3143.     AnsiString text;
  3144.     TEdit *edit = (TEdit*)Sender;
  3145.     char  hint[] = " Timeout is not valid ";
  3146.     text = edit->Text;
  3147.     if (!IsValidTimeout(text, data))
  3148.     {
  3149.         ShowHintLabel(edit, hint);
  3150.         edit->Text = IntToStr( HCI_DEFAULT_TIMEOUT_MS );
  3151.         edit->SetFocus();
  3152.         return;
  3153.     }
  3154.     m_sBTHCI.ui_ms_timeout = (unsigned int) data;
  3155. }
  3156. //---------------------------------------------------------------------------
  3157. //---------------------------------------------------------------------------
  3158. void __fastcall TfrmBT::cbRFTxTypeChange(TObject *Sender)
  3159. {
  3160.     DisplayRFDefaultDataLen();    
  3161. }
  3162. //---------------------------------------------------------------------------
  3163. void __fastcall TfrmBT::edtRFRxSignleFreqCheck(TObject *Sender)
  3164. {
  3165.     unsigned char  uc_data;
  3166.     AnsiString  text;
  3167.     TEdit *edit = (TEdit*)Sender;
  3168.     char  hint[] =
  3169.     {   " value should be 0~255 "
  3170.     };
  3171.     text = edit->Text;
  3172.     if( !IsValidBTFreq( text, uc_data ) )
  3173.     {
  3174.         edit->Text = 78;
  3175.         ShowHintLabel( edit, hint );
  3176.         edit->SetFocus();
  3177.         return;
  3178.     }
  3179.     m_sBtRf.uc_freq = uc_data;
  3180. }
  3181. //===========================================================================
  3182. /////////////////////////////  Packet test   ////////////////////////////////
  3183. //===========================================================================
  3184. void TfrmBT::AbortConnectWithTarget(void)
  3185. {
  3186.     m_sCWT.iBootStop = BOOT_STOP;
  3187.     if (m_bConnectTargetok)
  3188.     {
  3189.         META_ShutDownTarget_r(m_META_HANDLE_Obj.Get_SecondHandle());
  3190.         META_DisconnectWithTarget_r(m_META_HANDLE_Obj.Get_SecondHandle());
  3191.         m_bConnectTargetok = false;
  3192.     }
  3193.     if (NULL != m_pT_CWT)
  3194.     {
  3195.         WaitForSingleObject(m_sCWT.METADLL_Connect_Event, 5000);
  3196.     }
  3197. }
  3198. //---------------------------------------------------------------------------
  3199. bool TfrmBT::IsNewTciRequired(void)
  3200. {
  3201.     TCheckBox *cbPkt20[] =
  3202.     {
  3203.         cbPKTDM1,
  3204.         cbPKTDH1,
  3205.         cbPKTDM3,
  3206.         cbPKTDH3,
  3207.         cbPKTDM5,
  3208.         cbPKTDH5,
  3209.         cbPKTHV1,
  3210.         cbPKTHV2,
  3211.         cbPKTHV3,
  3212.         cbPKTEV3,
  3213.         cbPKTEV4,
  3214.         cbPKTEV5,
  3215.         cbPK2DH1,
  3216.         cbPK2EV3,
  3217.         cbPK2DH3,
  3218.         cbPK2EV5,
  3219.         cbPK2DH5,
  3220.         cbPK3EV3,
  3221.         cbPK3DH1,
  3222.         cbPK3DH3,
  3223.         cbPK3EV5,
  3224.         cbPK3DH5
  3225.     };
  3226.     int total_num;
  3227.     if (BTMODULE_MT6611 != m_cBtId)
  3228.     {
  3229.         total_num = BT_PACKET_IDX_NONEDR_COUNT;
  3230.     }
  3231.     else
  3232.     {
  3233.         total_num = BT_PACKET_IDX_COUNT;
  3234.     }
  3235.     for (int i=0; i<total_num; i++)
  3236.     {
  3237.         if (cbPkt20[i]->Checked &&
  3238.             (!IsPKTTestFinish((E_BT_PACKET_IDX) i))
  3239.            )
  3240.         {
  3241.             if (IsPKTTestRunning((E_BT_PACKET_IDX) i))
  3242.             {
  3243.                 return false;
  3244.             }
  3245.             else
  3246.             {
  3247.                 m_sBTTCI.e_idx = (E_BT_PACKET_IDX) i;
  3248.                 return true;
  3249.             }
  3250.         }
  3251.     }
  3252.     return false;
  3253. #if 0
  3254.     if (cbPKTDM1->Checked                       &&
  3255.         (!IsPKTTestFinish(BT_PACKET_IDX_DM1))
  3256.       )
  3257.     {
  3258.         if (IsPKTTestRunning(BT_PACKET_IDX_DM1))
  3259.         {
  3260.             return false;
  3261.         }
  3262.         else
  3263.         {
  3264.             m_sBTTCI.e_idx = BT_PACKET_IDX_DM1;