| BlueNRG-1 DK: BLE examples

- Main Page
- Modules
- Files

- File List

SensorDemo_central_role_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : SensorDemo_central_role_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 25-August-2016
7 * Description : Code demostrating which emulates the BlueNRG-1 Sensor Demo applications available for smartphones (iOS and android)
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
186 /* Includes ------------------------------------------------------------------*/
187 #include <stdio.h>
188 #include <string.h>
189 #include "BlueNRG1_it.h"
190 #include "BlueNRG1_conf.h"
191 #include "ble_const.h"
192 #include "bluenrg1_stack.h"
193 #include "SDK_EVAL_Config.h"
194 #include "sleep.h"
195 #include "gatt_db.h"
196 #include "master_basic_profile.h"
197 #include "master_config.h"
198 #include "SensorDemo_config.h"
199
200 #ifndef DEBUG
201 #define DEBUG 0
202 #endif
203
204 #if DEBUG
205 #include <stdio.h>
206 #define PRINTF(...) printf(__VA_ARGS__)
207 #else
208 #define PRINTF(...)
209 #endif
210
211
212 /* Private variables ---------------------------------------------------------*/
213
214
215 /*******************************************************************************
216 * Function Name : main.
217 * Description : Main routine.
218 * Input : None.
219 * Output : None.
220 * Return : None.
221 *******************************************************************************/
222 int main(void)
223 {
224
225 uint32_t timeTemperature, currentTime;
226 uint8_t ret;
227
228 /* System Init */
229 SystemInit();
230
231 /* Identify BlueNRG1 platform */
232 SdkEvalIdentification();
233
234 /* Configure I/O communication channel */
235 SdkEvalComUartInit(UART_BAUDRATE);
236
237 /* Configure I/O communication channel */
238 SdkEvalComIOConfig(SdkEvalComIOProcessInputData);
239
240 /* BlueNRG-1 stack init */
241 ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
242 if (ret != BLE_STATUS_SUCCESS) {
243 PRINTF("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
244 while(1);
245 }
246
247 /* Master Init procedure */
248 if (deviceInit() != BLE_STATUS_SUCCESS) {
249 PRINTF("Error during the device init procedure\r\n");
250 }
251
252 /* Start Master Device Discovery procedure */
253 if (deviceDiscovery() != BLE_STATUS_SUCCESS) {
254 PRINTF("Error during the device discovery procedure\r\n");
255 }
256
257 PRINTF("Sensor Demo Central application\r\n");
258
259 /* Main loop */
260 while(1) {
261 /* BLE Stack Tick */
262 BTLE_StackTick();
263
264 /* Master Tick */
265 Master_Process();
266
267 /* Power Save management */
268 BlueNRG_Sleep(SLEEPMODE_WAKETIMER, 0, 0, 0);
269
270 /* Start the connection procedure */
271 if (masterContext.startDeviceDisc) {
272 deviceConnection();
273 masterContext.startDeviceDisc = FALSE;
274 }
275
276 /* Discovery characteristics of service to enable the notifications/indications */
277 if (masterContext.findCharacOfService) {
278 findCharcOfService();
279 masterContext.findCharacOfService = FALSE;
280 timeTemperature = HAL_VTimerGetCurrentTime_sysT32();
281 }
282
283 /* Enable the notifications/indications */
284 if (masterContext.enableNotif) {
285 enableSensorNotifications();
286 masterContext.enableNotif = FALSE;
287 timeTemperature = HAL_VTimerGetCurrentTime_sysT32();
288 }
289 /* Read the temperature sensor every 3 sec */
290 currentTime = HAL_VTimerGetCurrentTime_sysT32();
291 if ((HAL_VTimerDiff_ms_sysT32(currentTime, timeTemperature)) >= READ_TEMPERATURE_TIMEOUT) {
292 timeTemperature = HAL_VTimerGetCurrentTime_sysT32();
293 if (masterContext.connHandle != 0xFFFF)
294 readTemperature();
295 }
296 }
297 }
298
299 #ifdef USE_FULL_ASSERT
300 /*******************************************************************************
301 * Function Name : assert_failed
302 * Description : Reports the name of the source file and the source line number
303 * where the assert_param error has occurred.
304 * Input : - file: pointer to the source file name
305 * - line: assert_param error line source number
306 * Output : None
307 * Return : None
308 *******************************************************************************/
309 void assert_failed(uint8_t* file, uint32_t line)
310 {
311 /* User can add his own implementation to report the file name and line number,
312 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
313
314 /* Infinite loop */
315 while (1)
316 {}
317 }
318 #endif
319
320 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/