#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <esp_log.h>
#include "BLEValue.h"
static const char* LOG_TAG="BLEValue";
BLEValue::BLEValue() {
m_accumulation = "";
m_value = "";
m_readOffset = 0;
}
void BLEValue::addPart(std::string part) {
ESP_LOGD(LOG_TAG, ">> addPart: length=%d", part.length());
m_accumulation += part;
}
void BLEValue::addPart(uint8_t* pData, size_t length) {
ESP_LOGD(LOG_TAG, ">> addPart: length=%d", length);
m_accumulation += std::string((char *)pData, length);
}
void BLEValue::cancel() {
ESP_LOGD(LOG_TAG, ">> cancel");
m_accumulation = "";
m_readOffset = 0;
}
void BLEValue::commit() {
ESP_LOGD(LOG_TAG, ">> commit");
if (m_accumulation.length() == 0) {
return;
}
setValue(m_accumulation);
m_accumulation = "";
m_readOffset = 0;
}
uint8_t* BLEValue::getData() {
return (uint8_t*)m_value.data();
}
size_t BLEValue::getLength() {
return m_value.length();
}
uint16_t BLEValue::getReadOffset() {
return m_readOffset;
}
std::string BLEValue::getValue() {
return m_value;
}
void BLEValue::setReadOffset(uint16_t readOffset) {
m_readOffset = readOffset;
}
void BLEValue::setValue(std::string value) {
m_value = value;
}
void BLEValue::setValue(uint8_t* pData, size_t length) {
m_value = std::string((char*)pData, length);
}
#endif