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 #include "BTDevice.hpp"
stoicancristi 0:b5906c81772b 2
stoicancristi 0:b5906c81772b 3 BTDevice::BTDevice() {
stoicancristi 0:b5906c81772b 4 this->ctrl = NULL;
stoicancristi 0:b5906c81772b 5 }
stoicancristi 0:b5906c81772b 6
stoicancristi 0:b5906c81772b 7 BTDevice::BTDevice(BLE _ble):ble(_ble){}
stoicancristi 0:b5906c81772b 8
stoicancristi 0:b5906c81772b 9 BTDevice::~BTDevice() {
stoicancristi 0:b5906c81772b 10 delete this->ctrl;
stoicancristi 0:b5906c81772b 11 }
stoicancristi 0:b5906c81772b 12
stoicancristi 0:b5906c81772b 13 void BTDevice::sendMsg(char *buf, uint16_t length) {
stoicancristi 0:b5906c81772b 14 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), (const uint8_t*)buf, length);
stoicancristi 0:b5906c81772b 15 }
stoicancristi 0:b5906c81772b 16
stoicancristi 0:b5906c81772b 17 int BTDevice::readMsg(uint8_t buf[TXRX_BUF_LEN], uint16_t expectedLen) {
stoicancristi 0:b5906c81772b 18 uint16_t bytesRead;
stoicancristi 0:b5906c81772b 19 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
stoicancristi 0:b5906c81772b 20
stoicancristi 0:b5906c81772b 21 return (bytesRead == expectedLen)? bytesRead : -1;
stoicancristi 0:b5906c81772b 22 }
stoicancristi 0:b5906c81772b 23
stoicancristi 0:b5906c81772b 24 void BTDevice::attachController(Controller *c) {
stoicancristi 0:b5906c81772b 25 this->ctrl = c;
stoicancristi 0:b5906c81772b 26 }
stoicancristi 0:b5906c81772b 27
stoicancristi 0:b5906c81772b 28 void BTDevice::setCtrlRef(float ref) {
stoicancristi 0:b5906c81772b 29 this->ctrl->updateRef(ref);
stoicancristi 0:b5906c81772b 30 }
stoicancristi 0:b5906c81772b 31
stoicancristi 0:b5906c81772b 32 void BTDevice::setCtrlParams(ControllerParams &cp) {
stoicancristi 0:b5906c81772b 33 this->ctrl->updateParams(cp);
stoicancristi 0:b5906c81772b 34 }
stoicancristi 0:b5906c81772b 35