peripheralStateNotificationCB
生活随笔
收集整理的這篇文章主要介紹了
peripheralStateNotificationCB
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 /*********************************************************************
2 * @fn peripheralStateNotificationCB 外圍設(shè)備 狀態(tài) 通知 回調(diào)函數(shù)
3 *
4 * @brief Notification from the profile of a state change. 通知來自于profile的狀態(tài)改變!
5 *
6 * @param@param newState - new state 形參:新狀態(tài),類型是一個枚舉變量
7 *
8 * @return@return none
9 */
10 static void peripheralStateNotificationCB( gaprole_States_t newState )
11 {
12 #ifdef PLUS_BROADCASTER //暫時不知 不作任何處理,2016年12月16日15:14:51
13 static uint8 first_conn_flag = 0;
14 #endif // PLUS_BROADCASTER
15
16
17 switch ( newState )
18 {
19 case GAPROLE_STARTED: //GAP 任務(wù) 開始,但 并不廣播 的狀態(tài)
20 {
21 uint8 ownAddress[B_ADDR_LEN]; //定義一個 存放 設(shè)備 地址的 buffer
22 uint8 systemId[DEVINFO_SYSTEM_ID_LEN];//定義一個存放 設(shè)備ID buffer
23
24 //GAP 任務(wù)獲取 設(shè)備 地址放到 ownAddress 臨時 buffer中
25
26 GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);
27
28 // use 6 bytes of device address for 8 bytes of system ID value
29 systemId[0] = ownAddress[0];
30 systemId[1] = ownAddress[1];
31 systemId[2] = ownAddress[2];
32
33 // set middle bytes to zero
34 systemId[4] = 0x00;
35 systemId[3] = 0x00;
36
37 // shift three bytes up
38 systemId[7] = ownAddress[5];
39 systemId[6] = ownAddress[4];
40 systemId[5] = ownAddress[3];
41
42 //設(shè)備信息設(shè)置參數(shù) 系統(tǒng)ID 為 設(shè)備 地址的 前三個字節(jié)+00+后三個字節(jié)
43
44 DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);
45
46 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
47 // Display device address
48 HalLcdWriteString( bdAddr2Str( ownAddress ), HAL_LCD_LINE_2 );
49 HalLcdWriteString( "Initialized", HAL_LCD_LINE_3 );
50 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
51 }
52 break;
53
54 case GAPROLE_ADVERTISING://GAP 任務(wù) 開始廣播 的狀態(tài)
55 {
56 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
57 HalLcdWriteString( "Advertising", HAL_LCD_LINE_3 );
58 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
59 }
60 break;
61
62 #ifdef PLUS_BROADCASTER //暫時不知 不作任何處理,2016年12月16日15:14:51
63 /* After a connection is dropped a device in PLUS_BROADCASTER will continue
64 * sending non-connectable advertisements and shall sending this change of
65 * state to the application. These are then disabled here so that sending
66 * connectable advertisements can resume.
67 */
68 case GAPROLE_ADVERTISING_NONCONN:
69 {
70 uint8 advertEnabled = FALSE;
71
72 // Disable non-connectable advertising.
73 GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
74 &advertEnabled);
75
76 // Reset flag for next connection.
77 first_conn_flag = 0;
78 }
79 break;
80 #endif //PLUS_BROADCASTER
81
82 case GAPROLE_CONNECTED://GAP 任務(wù) 已經(jīng)連接的狀態(tài)
83 {
84 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
85 HalLcdWriteString( "Connected", HAL_LCD_LINE_3 );
86 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
87
88 #ifdef PLUS_BROADCASTER
89 // Only turn advertising on for this state when we first connect
90 // otherwise, when we go from connected_advertising back to this state
91 // we will be turning advertising back on.
92 if ( first_conn_flag == 0 )
93 {
94 uint8 advertEnabled = FALSE; // Turn on Advertising
95
96 // Disable connectable advertising.
97 GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
98 &advertEnabled);
99
100 // Set to true for non-connectabel advertising.
101 advertEnabled = TRUE;
102
103 // Enable non-connectable advertising.
104 GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8),
105 &advertEnabled);
106
107 first_conn_flag = 1;
108 }
109 #endif // PLUS_BROADCASTER
110 }
111 break;
112
113 case GAPROLE_CONNECTED_ADV://GAP 任務(wù)連接狀態(tài)下 進行廣播 的狀態(tài)
114 {
115 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
116 HalLcdWriteString( "Connected Advertising", HAL_LCD_LINE_3 );
117 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
118 }
119 break;
120 case GAPROLE_WAITING://GAP 任務(wù) 等待進行 周期性廣播的 狀態(tài)
121 {
122 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
123 HalLcdWriteString( "Disconnected", HAL_LCD_LINE_3 );
124 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
125
126 #ifdef PLUS_BROADCASTER
127 uint8 advertEnabled = TRUE;
128
129 // Enabled connectable advertising.
130 GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8),
131 &advertEnabled);
132 #endif //PLUS_BROADCASTER
133 }
134 break;
135
136 case GAPROLE_WAITING_AFTER_TIMEOUT://GAP 任務(wù) 處于連接超時狀態(tài), 等待 執(zhí)行 進行 周期性廣播的 狀態(tài)
137 {
138 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
139 HalLcdWriteString( "Timed Out", HAL_LCD_LINE_3 );
140 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
141
142 #ifdef PLUS_BROADCASTER
143 // Reset flag for next connection.
144 first_conn_flag = 0;
145 #endif //#ifdef (PLUS_BROADCASTER)
146 }
147 break;
148
149 case GAPROLE_ERROR://GAP 任務(wù)處于 無效的狀態(tài),暫時不太理解,2016年12月16日15:18:39
150 {
151 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
152 HalLcdWriteString( "Error", HAL_LCD_LINE_3 );
153 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
154 }
155 break;
156
157 default://傳入的GAP 狀態(tài)參數(shù)有錯
158 {
159 #if (defined HAL_LCD) && (HAL_LCD == TRUE)
160 HalLcdWriteString( "", HAL_LCD_LINE_3 );
161 #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
162 }
163 break;
164
165 }
166
167 gapProfileState = newState;
168
169 #if !defined( CC2540_MINIDK )
170 VOID gapProfileState; // added to prevent compiler warning with 添加編譯器 警告 事件
171 // "CC2540 Slave" configurations
172 #endif
173
174
175 }
?
?
截圖 比較好看一點:
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/suozhang/p/6198122.html
總結(jié)
以上是生活随笔為你收集整理的peripheralStateNotificationCB的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 首次构建android studio g
- 下一篇: 梦到上楼梯捡钱是什么意思