dsf

Dependencies:   BLE_API mbed nRF51822

Committer:
stoicancristi
Date:
Sun Feb 05 16:31:58 2017 +0000
Revision:
0:b5906c81772b
BLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stoicancristi 0:b5906c81772b 1 #ifndef _BTdevice_
stoicancristi 0:b5906c81772b 2 #define _BTdevice_
stoicancristi 0:b5906c81772b 3
stoicancristi 0:b5906c81772b 4 #include "ble/BLE.h"
stoicancristi 0:b5906c81772b 5 #include <Gap.h>
stoicancristi 0:b5906c81772b 6 #include "ControllerParams.hpp"
stoicancristi 0:b5906c81772b 7 #include "Controller.hpp"
stoicancristi 0:b5906c81772b 8 #include "CmdEnums.hpp"
stoicancristi 0:b5906c81772b 9
stoicancristi 0:b5906c81772b 10 #define TXRX_BUF_LEN 20
stoicancristi 0:b5906c81772b 11
stoicancristi 0:b5906c81772b 12 #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */
stoicancristi 0:b5906c81772b 13 #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */
stoicancristi 0:b5906c81772b 14 #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */
stoicancristi 0:b5906c81772b 15
stoicancristi 0:b5906c81772b 16 // The Nordic UART Service
stoicancristi 0:b5906c81772b 17 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
stoicancristi 0:b5906c81772b 18 static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
stoicancristi 0:b5906c81772b 19 static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
stoicancristi 0:b5906c81772b 20 static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
stoicancristi 0:b5906c81772b 21
stoicancristi 0:b5906c81772b 22
stoicancristi 0:b5906c81772b 23 uint8_t txPayload[TXRX_BUF_LEN] = {0};
stoicancristi 0:b5906c81772b 24 uint8_t rxPayload[TXRX_BUF_LEN] = {0};
stoicancristi 0:b5906c81772b 25
stoicancristi 0:b5906c81772b 26
stoicancristi 0:b5906c81772b 27 static uint8_t rx_buf[TXRX_BUF_LEN];
stoicancristi 0:b5906c81772b 28 static uint8_t rx_len=0;
stoicancristi 0:b5906c81772b 29
stoicancristi 0:b5906c81772b 30
stoicancristi 0:b5906c81772b 31 GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
stoicancristi 0:b5906c81772b 32
stoicancristi 0:b5906c81772b 33 GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
stoicancristi 0:b5906c81772b 34
stoicancristi 0:b5906c81772b 35 GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
stoicancristi 0:b5906c81772b 36
stoicancristi 0:b5906c81772b 37 GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
stoicancristi 0:b5906c81772b 38
stoicancristi 0:b5906c81772b 39
stoicancristi 0:b5906c81772b 40
stoicancristi 0:b5906c81772b 41 class BTDevice {
stoicancristi 0:b5906c81772b 42
stoicancristi 0:b5906c81772b 43 public:
stoicancristi 0:b5906c81772b 44 BTDevice(BLE _ble);
stoicancristi 0:b5906c81772b 45 BTDevice();
stoicancristi 0:b5906c81772b 46 void sendMsg(char *buf, uint16_t length);
stoicancristi 0:b5906c81772b 47 int readMsg(uint8_t buf[TXRX_BUF_LEN], uint16_t expectedLen);
stoicancristi 0:b5906c81772b 48
stoicancristi 0:b5906c81772b 49 void attachController(Controller *c);
stoicancristi 0:b5906c81772b 50 void setCtrlRef(float ref);
stoicancristi 0:b5906c81772b 51 void setCtrlParams(ControllerParams &cp);
stoicancristi 0:b5906c81772b 52
stoicancristi 0:b5906c81772b 53 void interpretCmd(uint8_t cmd[TXRX_BUF_LEN]);
stoicancristi 0:b5906c81772b 54 ~BTDevice();
stoicancristi 0:b5906c81772b 55
stoicancristi 0:b5906c81772b 56 //friend void getTokens(uint8_t cmd[TXRX_BUF_LEN], BTDevive&, SysObj&, SysObjTypes&, Actions&, uint8_t actionParams[TXRX_BUF_LEN]);
stoicancristi 0:b5906c81772b 57
stoicancristi 0:b5906c81772b 58 private:
stoicancristi 0:b5906c81772b 59 BLE ble;
stoicancristi 0:b5906c81772b 60 Controller *ctrl;
stoicancristi 0:b5906c81772b 61 float out;
stoicancristi 0:b5906c81772b 62 };
stoicancristi 0:b5906c81772b 63 #endif