-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathBleOutputReceiver.cpp
More file actions
36 lines (30 loc) · 954 Bytes
/
Copy pathBleOutputReceiver.cpp
File metadata and controls
36 lines (30 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "BleOutputReceiver.h"
#include "BleReportUtils.h"
#include <algorithm>
BleOutputReceiver::BleOutputReceiver(uint16_t outputReportLength)
{
this->outputReportLength = outputReportLength;
outputBuffer = new uint8_t[outputReportLength];
}
BleOutputReceiver::~BleOutputReceiver()
{
// Release memory
if (outputBuffer)
{
delete[] outputBuffer;
}
}
void BleOutputReceiver::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo& connInfo)
{
// Retrieve data sent from the host
std::string value = pCharacteristic->getValue();
const uint8_t* raw = (const uint8_t*)value.c_str();
size_t length = 0;
const uint8_t* data = stripReportIdIfPresent(raw, value.length(), outputReportLength, length);
// Store the received data in the buffer
for (size_t i = 0; i < std::min(length, (size_t)outputReportLength); i++)
{
outputBuffer[i] = data[i];
}
outputFlag = true;
}