hal_scan_manage.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*Includes ----------------------------------------------*/
  2. #include "system.h"
  3. #include "ble_comm.h"
  4. #include "hal_scan_manage.h"
  5. static scan_reslt_t scan_reslt_head ={
  6. .handle = NULL,
  7. .next =NULL,
  8. .scanname =NULL
  9. };
  10. void hal_ble_scan_result_Regist(scan_reslt_t *cb){
  11. scan_reslt_t *target = &scan_reslt_head;
  12. while(NULL != target->next){
  13. if(target->next == cb)return;//¼ì²éÊÇ·ñÒѾ­´æÔÚ
  14. target = target->next;
  15. }
  16. cb->next = NULL;
  17. target->next = cb;
  18. }
  19. void hal_ble_scan_result_Clear(scan_reslt_t *cb){
  20. scan_reslt_t *target = &scan_reslt_head;
  21. while(NULL != target->next){
  22. if(cb == target->next){
  23. target->next = cb->next;
  24. return;
  25. }
  26. target = target->next;
  27. }
  28. }
  29. static void scan_report_cb(uint8_t *adv_data, uint16_t adv_data_len,int8_t rssi)
  30. {
  31. scan_reslt_t *target = &scan_reslt_head;
  32. while(NULL != target->next){
  33. if(NULL != target->next->scanname){
  34. if(advdata_name_find(adv_data, adv_data_len,target->next->scanname)){
  35. target->next->scanflag =1;
  36. }
  37. }
  38. target = target->next;
  39. }
  40. }
  41. static void hal_scan_process(void)
  42. {
  43. scan_reslt_t *target = &scan_reslt_head;
  44. while(NULL != target->next){
  45. if(target->next->scanflag){
  46. target->next->scanflag =0;
  47. if(target->next->handle)
  48. target->next->handle();
  49. }
  50. target = target->next;
  51. }
  52. }
  53. void hal_ble_scan_Init(void)
  54. {
  55. advdata_report_Evt_Regist(scan_report_cb);
  56. Process_Start(10,"hal_scan_process",hal_scan_process);
  57. }