Cristi Stoican / Mbed 2 deprecated Migration

Dependencies:   BLE_API mbed nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BTDevice.hpp Source File

BTDevice.hpp

00001 #ifndef _BTdevice_
00002 #define _BTdevice_
00003 
00004 #include "ble/BLE.h"
00005 #include <Gap.h>
00006 #include "ControllerParams.hpp"
00007 #include "Controller.hpp"
00008 #include "CmdEnums.hpp"
00009 
00010 #define TXRX_BUF_LEN    20
00011 
00012 #define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
00013 #define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
00014 #define BLE_UUIDS_RX_CHARACTERISTIC      0x0003 /**< The UUID of the RX Characteristic. */
00015 
00016 // The Nordic UART Service
00017 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
00018 static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
00019 static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
00020 static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
00021 
00022 
00023 uint8_t txPayload[TXRX_BUF_LEN] = {0};
00024 uint8_t rxPayload[TXRX_BUF_LEN] = {0};
00025 
00026 
00027 static uint8_t rx_buf[TXRX_BUF_LEN];
00028 static uint8_t rx_len=0;
00029 
00030 
00031 GattCharacteristic  txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
00032                                       
00033 GattCharacteristic  rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
00034                                       
00035 GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
00036 
00037 GattService         uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
00038 
00039 
00040 
00041 class BTDevice {
00042     
00043     public:
00044         BTDevice(BLE _ble);
00045         BTDevice();
00046         void sendMsg(char *buf, uint16_t length);
00047         int readMsg(uint8_t buf[TXRX_BUF_LEN], uint16_t expectedLen);
00048 
00049         void attachController(Controller *c);
00050         void setCtrlRef(float ref);
00051         void setCtrlParams(ControllerParams &cp);
00052 
00053         void interpretCmd(uint8_t cmd[TXRX_BUF_LEN]);
00054         ~BTDevice();        
00055 
00056     //friend void getTokens(uint8_t cmd[TXRX_BUF_LEN], BTDevive&, SysObj&, SysObjTypes&, Actions&, uint8_t actionParams[TXRX_BUF_LEN]);
00057         
00058     private:
00059         BLE ble;
00060         Controller *ctrl;
00061         float out;
00062 };
00063 #endif