app_pair - 副本.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*********************************************************************
  2. * INCLUDES
  3. */
  4. #include "app_pair.h"
  5. #include "hal_ws2812.h"
  6. #include "ble_comm.h"
  7. #include "app_flash.h"
  8. #include "hal_charge.h"
  9. #include "hal_ble_common.h"
  10. #include "bsp_time.h"
  11. #include "hal_ble_client.h"
  12. #include "hal_ble_host.h"
  13. #include "hal_led.h"
  14. #include "ble_advertising.h"
  15. #define PAIR_DEBUGLOG_ENABLE 1
  16. #if PAIR_DEBUGLOG_ENABLE
  17. #define PAIR_DEBUG_LOG(format,...) SEGGER_RTT_printf(0,format, ##__VA_ARGS__);
  18. #else
  19. #define PAIR_DEBUG_LOG(format,...) ;
  20. #endif
  21. static uint8_t isScan = 0;
  22. static uint8_t ScanFinishFlag =0;
  23. static char pair_name[8]={0};
  24. void Pair_adv_cb(ble_gap_evt_adv_report_t const * p_adv_report)
  25. {
  26. if(p_adv_report->rssi>-20 && p_adv_report->data.len==15 ){
  27. // PAIR_DEBUG_LOG("rssi %d: tx_power:%d\r\n",p_adv_report->rssi,p_adv_report->tx_power);
  28. // PAIR_DEBUG_LOG("addr:");for(int i=0;i<6;i++){PAIR_DEBUG_LOG("%02X,",p_adv_report->peer_addr.addr[5-i]);}PAIR_DEBUG_LOG("\r\n");
  29. if(p_adv_report->data.p_data[5]==0 && ScanFinishFlag==0 && p_adv_report->data.p_data[8] == 'S' && p_adv_report->data.p_data[9] == 'H' && p_adv_report->data.p_data[10] == '_'){
  30. ScanFinishFlag =1;
  31. memset(pair_name,0,sizeof(pair_name));
  32. memcpy(pair_name,&p_adv_report->data.p_data[8],7);
  33. PAIR_DEBUG_LOG("p_data:");for(int i=0;i<p_adv_report->data.len;i++){PAIR_DEBUG_LOG("%02X,",p_adv_report->data.p_data[i]);}PAIR_DEBUG_LOG("\r\n");
  34. PAIR_DEBUG_LOG("name:(%s)\r\n",pair_name);
  35. }
  36. }
  37. // uint16_t information =0;
  38. //// if(p_adv_report->rssi>-70)PAIR_DEBUG_LOG("Scan Some Data\r\n");
  39. // if(p_adv_report->rssi>-20 && p_adv_report->type.scan_response && 29 == p_adv_report->data.len && ScanFinishFlag ==0){
  40. // PAIR_DEBUG_LOG("rssi %d: type:%02X\r\n",p_adv_report->rssi,p_adv_report->type.scan_response);
  41. // for(int i=0;i<6;i++){
  42. // PAIR_DEBUG_LOG("%02X,",p_adv_report->data.p_data[i]);
  43. // }PAIR_DEBUG_LOG("\r\n");
  44. // memset(pair_name,0,sizeof(pair_name));
  45. // PAIR_DEBUG_LOG("data[%d]:",p_adv_report->data.len);
  46. // information = (uint16_t)(((uint16_t)p_adv_report->data.p_data[21]<<8) | p_adv_report->data.p_data[20]);
  47. // memcpy(pair_name,&p_adv_report->data.p_data[22],7);
  48. //
  49. // if(pair_name[0] == 'S' && pair_name[1] == 'H' && pair_name[2] == '_'){
  50. // PAIR_DEBUG_LOG("match(%s)\r\n",pair_name);
  51. // ScanFinishFlag =1;
  52. // }
  53. // }
  54. }
  55. static void app_pair_flash_save(void){
  56. uint8_t i=0;
  57. uint8_t config =0;
  58. //保存数据到备份区域里面
  59. for (i = 0; i < 6; i++){
  60. mBackup.macAddr_L[i] = mFlash.macHost[i]; //主机地址
  61. mBackup.macAddr_R[i] = mFlash.mClient.macAddr[i]; //从机地址
  62. }
  63. mFlash.mClient.isConfig ='C';
  64. mBackup.hardVersion = mFlash.mClient.hardVersion;
  65. mBackup.sotfVersion = mFlash.mClient.sotfVersion;
  66. mBackup.isConfig = mFlash.mClient.isConfig;
  67. if (Flash_SaveBackup() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair, "pair save backup fail");}
  68. PAIR_DEBUG_LOG("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
  69. PAIR_DEBUG_LOG("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
  70. PAIR_DEBUG_LOG("mFlash.macHost:%02X %02X %02X \n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
  71. if (Flash_DeleteAllStep() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair, "pair clear step fail");}
  72. memset(&mFlash.mStep, 0, sizeof(FlashStep_t));
  73. if (Flash_SaveInfomation() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair, "Flash_SaveInfomation fail");}
  74. if(mFlash.mClient.isConfig == 'C')
  75. config =1;
  76. }
  77. enum{
  78. Pair_ex_init =0,
  79. Pair_ex_MAC_Diffrent,
  80. Pair_ex_MAC_Same,
  81. Pair_ex_nocharge,
  82. Pair_ex_charge
  83. };
  84. static uint8_t GetMacAddrFlag =Pair_ex_init;
  85. static uint8_t GetMacAddr[6]={0};
  86. static void app_ble_send_mac(){
  87. uint8_t buf[32];
  88. uint8_t L=0;
  89. uint8_t mymac[6];
  90. Get_MACaddr(mymac);
  91. memcpy(buf,mymac,6);
  92. L +=6;
  93. // //硬件版本
  94. // buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>24);
  95. // buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>16);
  96. // buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>8);
  97. // buf[L++] = (uint8_t)((uint32_t)HARDWARE_VERSION>>0);
  98. // //软件版本
  99. // buf[L++] = (uint8_t)(SOFTWARE_VERSION>>8);
  100. // buf[L++] = (uint8_t)(SOFTWARE_VERSION>>0);
  101. //
  102. // buf[L++] = charge;
  103. if(mFlash.isHost)
  104. BLE_Client_Tx_Send(0,BLE_PAIR,buf,L);
  105. else
  106. BLE_Host_Tx_Send(0,BLE_PAIR,buf,L);
  107. // PAIR_DEBUG_LOG(">>>>>app_ble_send_mac =%d \r\n",mFlash.isHost);
  108. }
  109. static void app_pair_Left_Process(void)
  110. {
  111. static uint8_t state =0;
  112. static uint8_t blink_cnt =0;
  113. static uint8_t led_state =0;
  114. static uint8_t Lastcharge_state = BLE_CHARGE_PULLOUT;
  115. char buf[16];
  116. if(!mFlash.isHost){return;}
  117. // PAIR_DEBUG_LOG("left state:%d\r\n",state);
  118. uint8_t charge_state_c = hal_charge_Getstate();
  119. switch(state){//ble_advertising_init_t init;
  120. case 0:
  121. if((charge_state_c == BLE_CHARGE_INSERT || charge_state_c == BLE_CHARGE_DONE)){
  122. PAIR_DEBUG_LOG("<<<<<<<<<<<<<<<<<<<<<<<<\r\n");
  123. PAIR_DEBUG_LOG("start scan\r\n");
  124. advdata_report_Evt_Regist(Pair_adv_cb);
  125. ST_scan_stop();
  126. host_set_scan_name((char *)"***********",sizeof("***********"));
  127. ST_scan_start();
  128. state =1;
  129. advertising_stop();
  130. SetScanResponse(1,1);
  131. // slave_set_adv_name("SH_0000",7);
  132. slave_adv_init();
  133. advertising_start();
  134. }
  135. if(blink_cnt >0){ blink_cnt = 0;
  136. LED_Stop(LED_PAIR);
  137. }
  138. break;
  139. case 1:
  140. if(!(charge_state_c == BLE_CHARGE_INSERT || charge_state_c == BLE_CHARGE_DONE)){
  141. PAIR_DEBUG_LOG("charge out\r\n");
  142. // advdata_report_Evt_del(Pair_adv_cb);
  143. ST_scan_stop();
  144. state = 0;
  145. advertising_stop();
  146. SetScanResponse(0,0);
  147. // slave_set_adv_name("SH_1111",7);
  148. slave_adv_init();
  149. advertising_start();
  150. LED_Stop(LED_PAIR);
  151. }
  152. // if(ScanFinishFlag){
  153. // state =2;
  154. // tim = TIME_GetTicks();
  155. // advdata_report_Evt_del(Pair_adv_cb);
  156. // if(host_isconnect()){host_disconnect();}
  157. // host_set_scan_name(pair_name,strlen(pair_name));
  158. // ST_scan_start();
  159. // Process_UpdatePeroid(app_pair_Right_Process,100);
  160. // }
  161. // else if(!(charge_state_c == BLE_CHARGE_INSERT || charge_state_c == BLE_CHARGE_DONE)){
  162. // PAIR_DEBUG_LOG("charge out\r\n");
  163. // advdata_report_Evt_del(Pair_adv_cb);
  164. // nrf_ble_scan_stop();
  165. // state =5;
  166. // }
  167. break;
  168. }
  169. // if(charge_state_c != Lastcharge_state){
  170. //
  171. // advertising_stop();
  172. // PAIR_DEBUG_LOG("charge_state_c:%d\r\n",charge_state_c);
  173. // if(charge_state_c)SetScanResponse(1,1);
  174. // else SetScanResponse(0,1);
  175. // slave_adv_init();
  176. // advertising_start();
  177. //
  178. // }
  179. // Lastcharge_state =charge_state_c;
  180. //
  181. // switch(state){
  182. // case 0:
  183. // if(Pair_ex_MAC_Diffrent == GetMacAddrFlag){
  184. // app_pair_flash_save();
  185. // state =1;
  186. // Process_SetHoldOn(app_pair_Left_Process,1);
  187. // Process_UpdatePeroid(app_pair_Left_Process,500);
  188. // blink_cnt =0;
  189. // led_state =0;
  190. // if(slave_isconnect()){slave_disconnect();}
  191. // PAIR_DEBUG_LOG(">>>>>ST_scan_start =0 \r\n");
  192. // memset(buf,0,sizeof(buf));
  193. //
  194. // sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  195. // PAIR_DEBUG_LOG("scanName(%d):%s\n",strlen(buf),buf);
  196. // host_set_scan_name(buf,strlen(buf));
  197. // ST_scan_stop();
  198. // ST_scan_start();
  199. // }
  200. // else if(Pair_ex_MAC_Same == GetMacAddrFlag){
  201. // state =1;
  202. // Process_SetHoldOn(app_pair_Left_Process,1);
  203. // Process_UpdatePeroid(app_pair_Left_Process,500);
  204. // blink_cnt =0;
  205. // led_state =0;
  206. // }
  207. // GetMacAddrFlag =Pair_ex_init;
  208. // break;
  209. // case 1:
  210. // if(charge_state_c != BLE_CHARGE_PULLOUT){
  211. // if(blink_cnt++ <=20){
  212. // if(led_state ==0){led_state=1;
  213. // LED_Start(LED_PAIR,COLOR_BLUE);
  214. // }
  215. // else{led_state=0;
  216. // LED_Start(LED_PAIR,COLOR_BLACK);
  217. // }
  218. // }
  219. // else{
  220. // state =2;
  221. // LED_Stop(LED_PAIR);
  222. // }
  223. // }else{
  224. // state =2;
  225. // LED_Stop(LED_PAIR);
  226. // }
  227. //
  228. // break;
  229. // case 2:
  230. // LED_Stop(LED_PAIR);
  231. // state =0;
  232. // Process_SetHoldOn(app_pair_Left_Process,0);
  233. // Process_UpdatePeroid(app_pair_Left_Process,1000);
  234. // GetMacAddrFlag =Pair_ex_init;
  235. // break;
  236. // default:
  237. // break;
  238. // }
  239. }
  240. static BLE_Host_Tx_t mBLE_Host_T_PAIR_R = {
  241. .n = 10,
  242. .t = 100,
  243. .cb = 0,
  244. };
  245. static uint8_t Blink_flag =0;
  246. static void app_pair_Right_Process(void)
  247. {
  248. static uint8_t connetflag =0;
  249. static uint8_t state =0;
  250. static uint32_t tim =0;
  251. char buf[16];
  252. static uint8_t Lastcharge_state = BLE_CHARGE_PULLOUT;
  253. static uint8_t blink_cnt =0;
  254. static uint8_t led_state =0;
  255. if(mFlash.isHost){
  256. if(isScan)nrf_ble_scan_stop();
  257. return;
  258. }
  259. // PAIR_DEBUG_LOG("1");
  260. uint8_t charge_state_c = hal_charge_Getstate();
  261. // PAIR_DEBUG_LOG("Right Lastcharge_state %d,charge_state_c:%d\r\n",Lastcharge_state,charge_state_c);
  262. // PAIR_DEBUG_LOG("state:%d\r\n",state);
  263. // uint8_t charge_state_c = hal_charge_Getstate();
  264. // if(charge_state_c != Lastcharge_state){
  265. //
  266. // advertising_stop();
  267. // PAIR_DEBUG_LOG("charge_state_c:%d\r\n",charge_state_c);
  268. // if(charge_state_c)SetScanResponse(1,1);
  269. // else SetScanResponse(0,1);
  270. // slave_adv_init();
  271. // advertising_start();
  272. //
  273. // }
  274. // Lastcharge_state =charge_state_c;
  275. switch(state){//ble_advertising_init_t init;
  276. case 0:
  277. if((charge_state_c == BLE_CHARGE_INSERT || charge_state_c == BLE_CHARGE_DONE)){
  278. PAIR_DEBUG_LOG("<<<<<<<<<<<<<<<<<<<<<<<<\r\n");
  279. PAIR_DEBUG_LOG("start scan\r\n");
  280. advdata_report_Evt_Regist(Pair_adv_cb);
  281. ST_scan_stop();
  282. host_set_scan_name((char *)"***********",sizeof("***********"));
  283. ST_scan_start();
  284. state =1;
  285. ScanFinishFlag = 0;
  286. }
  287. break;
  288. case 1:
  289. if(!(charge_state_c == BLE_CHARGE_INSERT || charge_state_c == BLE_CHARGE_DONE)){
  290. PAIR_DEBUG_LOG("charge out\r\n");
  291. // advdata_report_Evt_del(Pair_adv_cb);
  292. ST_scan_stop();
  293. state = 0;
  294. LED_Stop(LED_PAIR);
  295. if(host_isconnect())host_disconnect();
  296. }
  297. if(ScanFinishFlag>0){ScanFinishFlag = 0;
  298. state =1;
  299. tim = TIME_GetTicks();
  300. advdata_report_Evt_del(Pair_adv_cb);
  301. if(host_isconnect()){host_disconnect();}
  302. host_set_scan_name(pair_name,strlen(pair_name));
  303. ST_scan_start();
  304. PAIR_DEBUG_LOG("ST_scan_start*********************\n");
  305. // Process_UpdatePeroid(app_pair_Right_Process,100);
  306. }
  307. if(host_isconnect()){ static uint8_t buf = 0;
  308. PAIR_DEBUG_LOG("1");
  309. if(connetflag==0){ connetflag = 1;
  310. // BLE_Host_Tx_Send(&mBLE_Host_T_PAIR_R,BLE_PAIR,&buf,1);
  311. ST_scan_stop();
  312. }
  313. app_ble_send_mac();
  314. // PAIR_DEBUG_LOG("1");
  315. // if(host_isconnect())host_disconnect();
  316. }
  317. break;
  318. case 2:
  319. if(charge_state_c == BLE_CHARGE_PULLOUT){
  320. PAIR_DEBUG_LOG("Pair_ex_MAC_Same == Pair_ex_nocharge\r\n");
  321. state =5;
  322. host_disconnect();
  323. }
  324. else if(Pair_ex_nocharge == GetMacAddrFlag){
  325. PAIR_DEBUG_LOG("Pair_ex_MAC_Same == Pair_ex_nocharge\r\n");
  326. host_disconnect();
  327. }
  328. else if(Pair_ex_MAC_Diffrent == GetMacAddrFlag){
  329. app_pair_flash_save();
  330. PAIR_DEBUG_LOG("app_pair_flash_save\r\n");
  331. state =3;
  332. }
  333. else if(Pair_ex_MAC_Same == GetMacAddrFlag){
  334. state =4;
  335. ST_scan_stop();
  336. Process_SetHoldOn(app_pair_Right_Process,1);
  337. Process_UpdatePeroid(app_pair_Right_Process,500);
  338. blink_cnt =0;
  339. led_state =0;
  340. host_disconnect();
  341. }
  342. else if(host_isconnect()){
  343. // app_ble_send_mac(Pair_ex_charge);s
  344. }
  345. break;
  346. case 3:
  347. memset(buf,0,sizeof(buf));
  348. sprintf(buf,"%02X%02X%02X%02X%02X%02X",mFlash.macHost[0],mFlash.macHost[1],mFlash.macHost[2],mFlash.mClient.macAddr[3],mFlash.mClient.macAddr[4],mFlash.mClient.macAddr[5]);
  349. PAIR_DEBUG_LOG("advName(%d):%s\n",strlen(buf),buf);
  350. slave_set_adv_name(buf,strlen(buf));
  351. advertising_stop();
  352. slave_adv_init();
  353. PAIR_DEBUG_LOG(">>>>>>>>advertising_start =0 \r\n");
  354. advertising_start();
  355. state =4;
  356. tim = TIME_GetTicks();
  357. Process_SetHoldOn(app_pair_Right_Process,1);
  358. Process_UpdatePeroid(app_pair_Right_Process,500);
  359. blink_cnt =0;
  360. led_state =0;
  361. ST_scan_stop();
  362. host_disconnect();
  363. break;
  364. case 4:
  365. if(charge_state_c != BLE_CHARGE_PULLOUT){
  366. if(blink_cnt++ <=20){
  367. if(led_state ==0){led_state=1;
  368. LED_Start(LED_PAIR,COLOR_BLUE);
  369. }
  370. else{led_state=0;
  371. LED_Start(LED_PAIR,COLOR_BLACK);
  372. }
  373. }
  374. else{
  375. state =5;
  376. LED_Stop(LED_PAIR);
  377. }
  378. }
  379. else{
  380. state =5;
  381. LED_Stop(LED_PAIR);
  382. }
  383. break;
  384. case 5:
  385. ScanFinishFlag =0;
  386. state =0;
  387. GetMacAddrFlag =Pair_ex_init;
  388. PAIR_DEBUG_LOG("app_pair ending\r\n");
  389. PAIR_DEBUG_LOG(">>>>>>>>>>>>>>>>>>>>>>>>\r\n");
  390. advdata_report_Evt_del(Pair_adv_cb);
  391. if(host_isconnect()){host_disconnect();}
  392. ST_scan_stop();
  393. host_set_scan_name((char *)"***********",sizeof("***********"));
  394. Process_SetHoldOn(app_pair_Right_Process,0);
  395. LED_Stop(LED_PAIR);
  396. Process_UpdatePeroid(app_pair_Right_Process,1000);
  397. break;
  398. default:state =0;break;
  399. }
  400. Lastcharge_state = charge_state_c;
  401. }
  402. static uint8_t blink_cnt =0;
  403. static void cb_Host_BLE_PAIR(void* handle)
  404. {
  405. PAIR_DEBUG_LOG(">>>>>>>>cb_Host_BLE_PAIR =0;\r\n");
  406. if(host_isconnect()){host_disconnect();}
  407. blink_cnt = 1;
  408. LED_Start(LED_PAIR,COLOR_BLUE);
  409. // ST_scan_stop();
  410. uint8_t ret =0,i =0;
  411. uint8_t mymacbuf[6];
  412. //
  413. BLE_Host_Rx_t* target = handle;
  414. // PAIR_DEBUG_LOG(">>>>>>>>cb_Host_BLE_PAIR =%d \r\n",target->datLen);
  415. // if(target->datLen != 13)return;
  416. memcpy(GetMacAddr,target->pDat,sizeof(GetMacAddr));
  417. // uint32_t hv = ((uint32_t)target->pDat[6]<<24)| ((uint32_t)target->pDat[7]<<16) | ((uint32_t)target->pDat[8]<<8) | ((uint32_t)target->pDat[9]<<0);
  418. // uint16_t sv = ((uint16_t)target->pDat[10]<<8) | ((uint16_t)target->pDat[11]<<0);
  419. //
  420. // for(i=0;i<6;i++){
  421. // if(mFlash.macHost[i] != GetMacAddr[i]){
  422. // ret =1;
  423. // break;
  424. // }
  425. // }
  426. // PAIR_DEBUG_LOG("target->pDat[12] %d\n",target->pDat[12]);
  427. if(mFlash.mClient.hardVersion != hv || mFlash.mClient.sotfVersion != sv || ret !=0){
  428. PAIR_DEBUG_LOG("host config:%d %d %d %d\n",hv,sv,ret);
  429. PAIR_DEBUG_LOG("mFlash.mClient:%d %d %d %d\n\n",mFlash.mClient.hardVersion,mFlash.mClient.sotfVersion,mFlash.mClient.isConfig,ret);
  430. mFlash.mClient.hardVersion = hv;
  431. mFlash.mClient.sotfVersion = sv;
  432. Get_MACaddr(mymacbuf);
  433. for(i=0;i<6;i++){
  434. mFlash.mClient.macAddr[i] = mymacbuf[i]; //从机自身mac地址
  435. mFlash.macHost[i] = GetMacAddr[i]; //主机发过来的mac地址
  436. }
  437. GetMacAddrFlag =Pair_ex_MAC_Diffrent;
  438. }
  439. }
  440. }
  441. static void cb_Client_BLE_PAIR(void* handle)
  442. {
  443. // uint8_t ret =0;
  444. // uint8_t i =0;
  445. // uint8_t mymacbuf[6];
  446. // BLE_Client_Rx_t* target = handle;
  447. if(hal_charge_Getstate() == BLE_CHARGE_PULLOUT )return;
  448. // static uint8_t buf = 0;
  449. // BLE_Client_Tx_Send(0,BLE_PAIR,&buf,1);
  450. app_ble_send_mac();
  451. blink_cnt = 1;
  452. LED_Start(LED_PAIR,COLOR_BLUE);
  453. PAIR_DEBUG_LOG(">>>>>>>>cb_Client_BLE_PAIR =0;\r\n");
  454. // uint8_t charge_state_c = hal_charge_Getstate();
  455. // PAIR_DEBUG_LOG(">>>>>>>>cb_Client_BLE_PAIR =0;\r\n");
  456. // if(target->datLen != 13)return;
  457. //
  458. // memcpy(GetMacAddr,target->pDat,sizeof(GetMacAddr));
  459. // uint32_t hv = ((uint32_t)target->pDat[6]<<24)| ((uint32_t)target->pDat[7]<<16) | ((uint32_t)target->pDat[8]<<8) | ((uint32_t)target->pDat[9]<<0);
  460. // uint16_t sv = ((uint16_t)target->pDat[10]<<8) | ((uint16_t)target->pDat[11]<<0);
  461. //
  462. // for(i=0;i<6;i++){
  463. // if(mFlash.mClient.macAddr[i] != GetMacAddr[i]){
  464. // ret =1;
  465. // break;
  466. // }
  467. // }
  468. //
  469. // if(mFlash.mClient.hardVersion != hv || mFlash.mClient.sotfVersion != sv || ret !=0){
  470. // PAIR_DEBUG_LOG("mFlash config:%d %d %d %d\n\n",mFlash.mClient.hardVersion,mFlash.mClient.sotfVersion,mFlash.mClient.isConfig,ret);
  471. // mFlash.mClient.hardVersion = hv;
  472. // mFlash.mClient.sotfVersion = sv;
  473. // Get_MACaddr(mymacbuf);
  474. // for(i=0;i<6;i++){
  475. // mFlash.mClient.macAddr[i] = GetMacAddr[i]; //收到的从机mac地址
  476. // mFlash.macHost[i] = mymacbuf[i]; //主机本身mac地址
  477. // }
  478. // GetMacAddrFlag =1;
  479. // }
  480. // else GetMacAddrFlag =2;
  481. // app_ble_send_mac(Pair_ex_nocharge);
  482. }
  483. void app_led_blink_process(){
  484. if(blink_cnt>0){
  485. if(blink_cnt%2) LED_SetColor(LED_PAIR,COLOR_BLUE);
  486. else LED_SetColor(LED_PAIR,COLOR_BLACK);
  487. if(blink_cnt>=20){
  488. blink_cnt = 0;
  489. LED_Stop(LED_PAIR);
  490. }
  491. blink_cnt++;
  492. }
  493. }
  494. void app_pair_Initialize(void)
  495. {
  496. Process_Start(100,"app_pair_Right_Process",app_pair_Right_Process);
  497. Process_Start(100,"app_pair_Left",app_pair_Left_Process);
  498. Process_Start(500,"Blink_flag",app_led_blink_process);
  499. uint8_t config =0;
  500. if(mFlash.mClient.isConfig == 'C')config =1;
  501. SetScanResponse(0,config);
  502. BLE_Client_Rx_Regist(BLE_PAIR,cb_Client_BLE_PAIR);
  503. BLE_Host_Rx_Regist(BLE_PAIR,cb_Host_BLE_PAIR);
  504. }