1 /*
2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 /*chipsea_ohos proguard begin*/
16 #include "cs_proguard.h"
17 /*chipsea_ohos proguard end*/
18 #include "cs_target_config.h"
19 #if APP_SUPPORT_SPP == 1
20 #include "cs_adp_api.h"
21 #include "al_rtos.h"
22 #include "app_spp.h"
23 #include "app_test.h"
24 #include "app_bt.h"
25
26 static app_spp_tx_done_t app_spp_tx_done_func = NULL;
27 #if MAX_THROUGHPUT_TEST == 1
28 uint8_t spp_test_buffer[650] = {0x1,};
29
app_spp_send_test_data(void)30 void app_spp_send_test_data(void)
31 {
32 //TRACE("APP:spp_send_test_data\n");
33 app_spp_send_data(spp_test_buffer, 650);
34 }
35
app_spp_connect_test(void)36 void app_spp_connect_test(void)
37 {
38 BT_ADDR temp_bdaddr = {0xa1,0xc0,0x00,0x45,0x56,0x67};
39 //0x77,0xEE,0xAE,0x77,0xAE,0xAE
40 //0xAE,0xAE,0x77,0xAE,0xEE,0x77
41 app_spp_connect(&temp_bdaddr);
42 }
43
44 #endif
45
46
app_spp_send_data(uint8_t * ptrData,uint16_t length)47 void app_spp_send_data(uint8_t* ptrData, uint16_t length)
48 {
49 cs_adp_spp_send_data(ptrData, length);
50 }
51
52
app_spp_register_tx_done(app_spp_tx_done_t callback)53 void app_spp_register_tx_done(app_spp_tx_done_t callback)
54 {
55 TRACE("APP:register tx done cb = 0x%x\n",callback);
56 app_spp_tx_done_func = callback;
57 }
58
app_spp_init(void)59 void app_spp_init(void)
60 {
61 TRACE("APP:app_spp_init\n");
62 #if MAX_THROUGHPUT_TEST == 1
63 app_spp_register_tx_done(app_spp_send_test_data);
64 #endif
65 }
66
app_spp_connect(BT_ADDR * bdaddr)67 void app_spp_connect(BT_ADDR * bdaddr)
68 {
69 app_spp_init();
70 TRACE("APP:app_spp_connect \n");
71 cs_adp_spp_connect(bdaddr);
72 }
73
app_spp_msg_handle(CS_EVENT * event)74 void app_spp_msg_handle(CS_EVENT *event)
75 {
76 CS_ADP_SPP_EVENT *cs_spp_msg = (CS_ADP_SPP_EVENT *)event->Param;
77
78 switch(event->EventId){
79 case CS_ADP_SPP_CONNECTED_IND:
80 if(cs_spp_msg->sppparam == 0){
81 TRACE("APP:spp connect ind\n");
82 app_bt_set_scan_mode(BT_NOSCAN);
83 }else{
84
85 }
86
87 break;
88 case CS_ADP_SPP_CONNECTED_CNF:
89 if(cs_spp_msg->sppparam == 0){
90 TRACE("APP:spp connect cnf\n");
91 app_bt_set_scan_mode(BT_NOSCAN);
92 #if MAX_THROUGHPUT_TEST == 1 && TEST_MODE_ROLE_SEND == 1
93 app_spp_send_test_data();
94 #endif
95 #if SCO_CVSD_PLC_TEST == 1 && TEST_MODE_ROLE_SEND == 1
96 app_test_connect_sco(NULL);
97 #endif
98 }else{
99
100 }
101 break;
102 case CS_ADP_SPP_DISCONNECTED:
103 TRACE("APP:spp disconnected reason = %d",cs_spp_msg->sppparam);
104 if(cs_spp_msg->sppparam == 0){
105 app_spp_tx_done_func = NULL;
106 }else{
107
108 }
109 break;
110 case CS_ADP_SPP_DATA_SENT:
111 {
112 //adpspptxdone *tx_done = (adpspptxdone *)cs_spp_msg->sppparam;
113 if(app_spp_tx_done_func)
114 {
115 app_spp_tx_done_func();
116 }
117 }
118 break;
119 case CS_ADP_SPP_DATA_IND:
120 {
121 adpspprxdone *rx_done = (adpspprxdone *)cs_spp_msg->sppparam;
122 if(*rx_done->pRxBuf != 0)
123 {
124 TRACE("APP:spp_receive_data");
125 }
126 }
127 break;
128 default:
129 break;
130 }
131 }
132
133 #endif
134