Conditionally compile code for specific roles.

This allows NimBLE options in menuconfig to reduce code size based on
the roles selected (scan/advertising/central/peripheral).

Significant code space can be saved by removing unnecessary roles for the application.
This commit is contained in:
h2zero
2020-05-13 22:03:56 -06:00
parent 3d6f8b691e
commit 03cb7b21d9
53 changed files with 2335 additions and 2012 deletions

View File

@@ -3,7 +3,7 @@
*
* Created: on March 6, 2020
* Author H2zero
*
*
* Originally:
*
* BLEValue.cpp
@@ -14,15 +14,18 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include "nimconfig.h"
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
#include "NimBLEValue.h"
#include "NimBLELog.h"
static const char* LOG_TAG="NimBLEValue";
NimBLEValue::NimBLEValue() {
m_accumulation = "";
m_value = "";
m_readOffset = 0;
m_accumulation = "";
m_value = "";
m_readOffset = 0;
} // NimBLEValue
@@ -32,8 +35,8 @@ NimBLEValue::NimBLEValue() {
* @param [in] part A message part being added.
*/
void NimBLEValue::addPart(const std::string &part) {
NIMBLE_LOGD(LOG_TAG, ">> addPart: length=%d", part.length());
m_accumulation += part;
NIMBLE_LOGD(LOG_TAG, ">> addPart: length=%d", part.length());
m_accumulation += part;
} // addPart
@@ -44,8 +47,8 @@ void NimBLEValue::addPart(const std::string &part) {
* @param [in] length The number of bytes being added.
*/
void NimBLEValue::addPart(const uint8_t* pData, size_t length) {
NIMBLE_LOGD(LOG_TAG, ">> addPart: length=%d", length);
m_accumulation += std::string((char*) pData, length);
NIMBLE_LOGD(LOG_TAG, ">> addPart: length=%d", length);
m_accumulation += std::string((char*) pData, length);
} // addPart
@@ -53,9 +56,9 @@ void NimBLEValue::addPart(const uint8_t* pData, size_t length) {
* @brief Cancel the current accumulation.
*/
void NimBLEValue::cancel() {
NIMBLE_LOGD(LOG_TAG, ">> cancel");
m_accumulation = "";
m_readOffset = 0;
NIMBLE_LOGD(LOG_TAG, ">> cancel");
m_accumulation = "";
m_readOffset = 0;
} // cancel
@@ -66,12 +69,12 @@ void NimBLEValue::cancel() {
* we now have the complete message and commit the change as a unit.
*/
void NimBLEValue::commit() {
NIMBLE_LOGD(LOG_TAG, ">> commit");
// If there is nothing to commit, do nothing.
if (m_accumulation.length() == 0) return;
setValue(m_accumulation);
m_accumulation = "";
m_readOffset = 0;
NIMBLE_LOGD(LOG_TAG, ">> commit");
// If there is nothing to commit, do nothing.
if (m_accumulation.length() == 0) return;
setValue(m_accumulation);
m_accumulation = "";
m_readOffset = 0;
} // commit
@@ -80,7 +83,7 @@ void NimBLEValue::commit() {
* @return A pointer to the data.
*/
uint8_t* NimBLEValue::getData() {
return (uint8_t*) m_value.data();
return (uint8_t*) m_value.data();
}
@@ -89,7 +92,7 @@ uint8_t* NimBLEValue::getData() {
* @return The length of the data in bytes.
*/
size_t NimBLEValue::getLength() {
return m_value.length();
return m_value.length();
} // getLength
@@ -98,7 +101,7 @@ size_t NimBLEValue::getLength() {
* @return The read offset into the read.
*/
uint16_t NimBLEValue::getReadOffset() {
return m_readOffset;
return m_readOffset;
} // getReadOffset
@@ -106,7 +109,7 @@ uint16_t NimBLEValue::getReadOffset() {
* @brief Get the current value.
*/
std::string NimBLEValue::getValue() {
return m_value;
return m_value;
} // getValue
@@ -115,7 +118,7 @@ std::string NimBLEValue::getValue() {
* @param [in] readOffset The offset into the read.
*/
void NimBLEValue::setReadOffset(uint16_t readOffset) {
m_readOffset = readOffset;
m_readOffset = readOffset;
} // setReadOffset
@@ -123,7 +126,7 @@ void NimBLEValue::setReadOffset(uint16_t readOffset) {
* @brief Set the current value.
*/
void NimBLEValue::setValue(const std::string &value) {
m_value = value;
m_value = value;
} // setValue
@@ -133,8 +136,8 @@ void NimBLEValue::setValue(const std::string &value) {
* @param [in] The length of the new current value.
*/
void NimBLEValue::setValue(const uint8_t* pData, size_t length) {
m_value = std::string((char*) pData, length);
m_value = std::string((char*) pData, length);
} // setValue
#endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
#endif // CONFIG_BT_ENABLED