Cristi Stoican / Mbed 2 deprecated Migration

Dependencies:   BLE_API mbed nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BTDevice.cpp Source File

BTDevice.cpp

00001 #include "BTDevice.hpp"
00002 
00003 BTDevice::BTDevice() {
00004     this->ctrl = NULL;
00005 }
00006 
00007 BTDevice::BTDevice(BLE _ble):ble(_ble){}
00008 
00009 BTDevice::~BTDevice() { 
00010     delete this->ctrl; 
00011 } 
00012 
00013 void BTDevice::sendMsg(char *buf, uint16_t length) {
00014     ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), (const uint8_t*)buf, length);
00015 }
00016 
00017 int BTDevice::readMsg(uint8_t buf[TXRX_BUF_LEN], uint16_t expectedLen) {
00018     uint16_t bytesRead;
00019     ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
00020     
00021     return (bytesRead == expectedLen)? bytesRead : -1;
00022 }
00023 
00024 void BTDevice::attachController(Controller *c) { 
00025     this->ctrl = c; 
00026 }
00027 
00028 void BTDevice::setCtrlRef(float ref) {
00029     this->ctrl->updateRef(ref);
00030 }
00031 
00032 void BTDevice::setCtrlParams(ControllerParams &cp) {
00033     this->ctrl->updateParams(cp);
00034 }
00035