EJEMPLO NRF5X

Fork of BLE_Driver by TESIS SATUROMETRICA

Committer:
Ferszt
Date:
Mon Aug 22 01:00:45 2016 +0000
Revision:
0:9b6cb48c1cc3
Child:
1:ed0c2ae35bc2
Libreria Terminada.; Falta documentacion.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ferszt 0:9b6cb48c1cc3 1 #include "BLE_Driver.h"
Ferszt 0:9b6cb48c1cc3 2 #include "mbed.h"
Ferszt 0:9b6cb48c1cc3 3
Ferszt 0:9b6cb48c1cc3 4 /* Instancias de las clases necesarias para el BLE*/
Ferszt 0:9b6cb48c1cc3 5 BLEDevice ble;
Ferszt 0:9b6cb48c1cc3 6 UARTService *uart;
Ferszt 0:9b6cb48c1cc3 7
Ferszt 0:9b6cb48c1cc3 8 /* Implementacion de los callback de la BLE_API.
Ferszt 0:9b6cb48c1cc3 9 * Es importante notar que ambas funciones hacen un llamado a callbackBLE, que es el callback de esta libreria, implementado en el main de la aplicación. */
Ferszt 0:9b6cb48c1cc3 10 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
Ferszt 0:9b6cb48c1cc3 11 {
Ferszt 0:9b6cb48c1cc3 12 ble.startAdvertising();
Ferszt 0:9b6cb48c1cc3 13 callbackBLE(1);
Ferszt 0:9b6cb48c1cc3 14 }
Ferszt 0:9b6cb48c1cc3 15
Ferszt 0:9b6cb48c1cc3 16 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
Ferszt 0:9b6cb48c1cc3 17 {
Ferszt 0:9b6cb48c1cc3 18 callbackBLE(2);
Ferszt 0:9b6cb48c1cc3 19 }
Ferszt 0:9b6cb48c1cc3 20
Ferszt 0:9b6cb48c1cc3 21 /* Funciones de lectura y escritura */
Ferszt 0:9b6cb48c1cc3 22
Ferszt 0:9b6cb48c1cc3 23 void putBLE(const char* data){
Ferszt 0:9b6cb48c1cc3 24 if (uart) uart->write(data, strlen(data));
Ferszt 0:9b6cb48c1cc3 25 }
Ferszt 0:9b6cb48c1cc3 26
Ferszt 0:9b6cb48c1cc3 27 uint8_t getBLE(void){
Ferszt 0:9b6cb48c1cc3 28 return uart->_getc();
Ferszt 0:9b6cb48c1cc3 29 }
Ferszt 0:9b6cb48c1cc3 30
Ferszt 0:9b6cb48c1cc3 31 /* Inicializaciones */
Ferszt 0:9b6cb48c1cc3 32
Ferszt 0:9b6cb48c1cc3 33 void iniBLE(const char* name){
Ferszt 0:9b6cb48c1cc3 34 /* inicializa BLE en modo uart */
Ferszt 0:9b6cb48c1cc3 35 ble.init();
Ferszt 0:9b6cb48c1cc3 36 uart = new UARTService(ble);
Ferszt 0:9b6cb48c1cc3 37
Ferszt 0:9b6cb48c1cc3 38 /* inicializa los callbacks a utilizar */
Ferszt 0:9b6cb48c1cc3 39 ble.onDisconnection(disconnectionCallback);
Ferszt 0:9b6cb48c1cc3 40 ble.onConnection(connectionCallback);
Ferszt 0:9b6cb48c1cc3 41
Ferszt 0:9b6cb48c1cc3 42 /* configuracion del advertising */
Ferszt 0:9b6cb48c1cc3 43 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
Ferszt 0:9b6cb48c1cc3 44 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Ferszt 0:9b6cb48c1cc3 45 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
Ferszt 0:9b6cb48c1cc3 46 (const uint8_t *)name, strlen(name)); // sizeof cambiando por strlen al agretar el parametro name.
Ferszt 0:9b6cb48c1cc3 47 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
Ferszt 0:9b6cb48c1cc3 48 (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
Ferszt 0:9b6cb48c1cc3 49
Ferszt 0:9b6cb48c1cc3 50 ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
Ferszt 0:9b6cb48c1cc3 51 ble.startAdvertising();
Ferszt 0:9b6cb48c1cc3 52 }