hal_name.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "hal_dfu.h"
  2. #include "system.h"
  3. #include "ble_comm.h"
  4. static uint8_t ScanNameflag =1;
  5. static uint8_t AdvNameflag =1;
  6. static char AdvNameBuff[NRF_BLE_SCAN_NAME_MAX_LEN] = {0};
  7. static char ScanNameBuff[NRF_BLE_SCAN_NAME_MAX_LEN] = {0};
  8. void hal_setScanName(char *Scanname,uint8_t length){
  9. if(NULL == Scanname || length > NRF_BLE_SCAN_NAME_MAX_LEN || 0 == length)return;
  10. memset(ScanNameBuff,0,length);
  11. memcpy(ScanNameBuff,Scanname,length);
  12. ScanNameflag =1;
  13. }
  14. void hal_setAdvName(char *advname,uint8_t length){
  15. if(NULL == advname || length > NRF_BLE_SCAN_NAME_MAX_LEN || 0 == length)return;
  16. memset(advname,0,length);
  17. memcpy(advname,advname,length);
  18. AdvNameflag =1;
  19. }
  20. void hal_name_process(void){
  21. static uint8_t Scanstate =0;
  22. switch(Scanstate){
  23. case 0:
  24. if(ScanNameflag){ScanNameflag=0;
  25. Scanstate =1;
  26. if(host_isconnect())host_disconnect();
  27. }
  28. break;
  29. case 1:
  30. if(host_isconnect()){host_disconnect();}
  31. else {
  32. ST_scan_stop();
  33. host_set_scan_name(ScanNameBuff,strlen(ScanNameBuff));
  34. ST_scan_start();
  35. Scanstate = 0;
  36. }
  37. break;
  38. default:Scanstate =0;break;
  39. }
  40. static uint8_t Advstate =0;
  41. switch(Advstate){
  42. case 0:
  43. if(ScanNameflag){ScanNameflag=0;
  44. Advstate =1;
  45. if(slave_isconnect()) slave_disconnect();
  46. }
  47. break;
  48. case 1:
  49. if(host_isconnect()){host_disconnect();}
  50. else {
  51. ST_scan_stop();
  52. host_set_scan_name(ScanNameBuff,strlen(ScanNameBuff));
  53. ST_scan_start();
  54. Advstate = 0;
  55. }
  56. break;
  57. default:Scanstate =0;break;
  58. }
  59. }
  60. void hal_name_init(void){
  61. Process_Start(1000,"hal_name",hal_name_process);
  62. }