bt_demo.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "ql_api_osi.h"
  16. #include "ql_api_bt.h"
  17. #include "ql_log.h"
  18. #define QL_BT_LOG_LEVEL QL_LOG_LEVEL_INFO
  19. #define QL_BT_LOG(msg, ...) QL_LOG(QL_BT_LOG_LEVEL, "ql_bt_DEMO", msg, ##__VA_ARGS__)
  20. #define QL_BT_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_bt_DEMO", msg, ##__VA_ARGS__)
  21. ql_bt_visible_mode_e scan_mode = QL_BT_PAGE_AND_INQUIRY_ENABLE;
  22. ql_bt_ble_local_name_s bt_local_name =
  23. {
  24. .name = "移远BT",
  25. .code_type = QL_BT_BLE_NAME_CODE_UTF8,
  26. };
  27. ql_errcode_bt_e ql_bt_demo_get_state()
  28. {
  29. ql_errcode_bt_e ret;
  30. ql_bt_state_e bt_state;
  31. ret = ql_bt_get_state(&bt_state);
  32. if (ret != QL_BT_SUCCESS)
  33. {
  34. QL_BT_LOG("error=%x", ret);
  35. }
  36. else
  37. {
  38. QL_BT_LOG("bt_state=%d",(int)bt_state);
  39. }
  40. return ret;
  41. }
  42. ql_errcode_bt_e ql_bt_demo_start()
  43. {
  44. ql_errcode_bt_e ret;
  45. ret = ql_bt_start();
  46. if (ret == QL_BT_SUCCESS)
  47. {
  48. QL_BT_LOG("sucess");
  49. }
  50. else if (ret == QL_BT_ALREADY_STARTED_ERR)
  51. {
  52. QL_BT_LOG("already started");
  53. }
  54. else
  55. {
  56. QL_BT_LOG("error=%x", ret);
  57. }
  58. return ret;
  59. }
  60. /*
  61. ql_errcode_bt_e ql_bt_demo_get_scanmde()
  62. {
  63. ql_errcode_bt_e ret;
  64. ql_bt_visible_mode_e scan_mode;
  65. ret = ql_classic_bt_get_scanmode(&scan_mode);
  66. if (ret == QL_BT_SUCCESS)
  67. {
  68. QL_BT_LOG("scan_mode=%d",(int)scan_mode);
  69. }
  70. else
  71. {
  72. QL_BT_LOG("error=%x", ret);
  73. }
  74. return ret;
  75. }
  76. ql_errcode_bt_e ql_be_demo_set_scanmode()
  77. {
  78. ql_errcode_bt_e ret;
  79. ret = ql_classic_bt_set_scanmode(scan_mode);
  80. if (ret == QL_BT_SUCCESS)
  81. {
  82. QL_BT_LOG("sucess");
  83. }
  84. else
  85. {
  86. QL_BT_LOG("error=%x", ret);
  87. }
  88. return ret;
  89. }
  90. */
  91. ql_errcode_bt_e ql_bt_demo_get_local_name()
  92. {
  93. ql_errcode_bt_e ret;
  94. ql_bt_ble_local_name_s bt_local_name;
  95. memset(bt_local_name.name,0x00,sizeof(bt_local_name.name));
  96. ret = ql_bt_ble_get_localname(&bt_local_name);
  97. if (ret == QL_BT_SUCCESS)
  98. {
  99. QL_BT_LOG("bt_local_name:%s",bt_local_name.name);
  100. }
  101. else
  102. {
  103. QL_BT_LOG("error=%x", ret);
  104. }
  105. return ret;
  106. }
  107. ql_errcode_bt_e ql_bt_demo_set_local_name()
  108. {
  109. ql_errcode_bt_e ret;
  110. ret = ql_bt_ble_set_localname(bt_local_name);
  111. if (ret == QL_BT_SUCCESS)
  112. {
  113. QL_BT_LOG("sucess");
  114. }
  115. else
  116. {
  117. QL_BT_LOG("error=%x", ret);
  118. }
  119. return ret;
  120. }
  121. ql_errcode_bt_e ql_bt_demo_stop()
  122. {
  123. ql_errcode_bt_e ret;
  124. ret = ql_bt_stop();
  125. if (ret == QL_BT_SUCCESS)
  126. {
  127. QL_BT_LOG("sucess");
  128. }
  129. else
  130. {
  131. QL_BT_LOG("error=%x", ret);
  132. }
  133. return ret;
  134. }