diff --git a/components/BLEManager/BLEGapServer.cpp b/components/BLEManager/BLEGapServer.cpp index 6657f8f..ac0e971 100644 --- a/components/BLEManager/BLEGapServer.cpp +++ b/components/BLEManager/BLEGapServer.cpp @@ -1761,8 +1761,9 @@ std::vector BLEGapServer::generateManufacturerData(uint16_t manufacture // Convert serial number from ascii hex to binary (will be like BCD) auto serialNoBytes = Raft::getBytesFromHexStr(serialNo.c_str(), MAX_SERIAL_NO_BYTES); - // Use the last N digits of the serial number - uint32_t maxSerialNoBytes = _bleConfig.advManufTotalByteLimit - manufacturerData.size(); + // Use the last N digits of the serial number (none if the ID and fixed data already fill the limit) + uint32_t maxSerialNoBytes = _bleConfig.advManufTotalByteLimit > manufacturerData.size() ? + _bleConfig.advManufTotalByteLimit - manufacturerData.size() : 0; uint32_t startPos = serialNoBytes.size() > maxSerialNoBytes ? serialNoBytes.size() - maxSerialNoBytes : 0; manufacturerData.insert(manufacturerData.end(), serialNoBytes.begin() + startPos, serialNoBytes.begin() + serialNoBytes.size()); } diff --git a/components/BLEManager/BLEGattServer.cpp b/components/BLEManager/BLEGattServer.cpp index 46f7653..d71073b 100644 --- a/components/BLEManager/BLEGattServer.cpp +++ b/components/BLEManager/BLEGattServer.cpp @@ -558,18 +558,33 @@ bool BLEGattServer::handleSubscription(struct ble_gap_event * pEvent, String& st if (isResponseChar) subscribed = (pEvent->subscribe.cur_notify != 0) || (pEvent->subscribe.cur_indicate != 0); statusStr = "subscribe attr_handle=" + String(pEvent->subscribe.attr_handle) + - " reason=" + getHSErrorMsg(pEvent->subscribe.reason) + + " reason=" + getSubscribeReasonName(pEvent->subscribe.reason) + " prevNotify=" + String(pEvent->subscribe.prev_notify) + " curNotify=" + String(pEvent->subscribe.cur_notify) + " prevInd=" + String(pEvent->subscribe.prev_indicate) + " curInd=" + String(pEvent->subscribe.cur_indicate); #ifdef DEBUG_RESP_SUBSCRIPTION - LOG_W(MODULE_PREFIX, "handleSubscription connHandle %d responseChar %s subscribed %s", pEvent->subscribe.conn_handle, - isResponseChar ? "YES" : "NO", subscribed ? "YES" : "NO"); + LOG_W(MODULE_PREFIX, "handleSubscription connHandle %d responseChar %s subscribed %s %s", pEvent->subscribe.conn_handle, + isResponseChar ? "YES" : "NO", subscribed ? "YES" : "NO", statusStr.c_str()); #endif return isResponseChar; } +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Name of the reason for a subscribe event (it isn't an error code) +///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +const char* BLEGattServer::getSubscribeReasonName(uint8_t reason) +{ + switch (reason) + { + case BLE_GAP_SUBSCRIBE_REASON_WRITE: return "write"; + case BLE_GAP_SUBSCRIBE_REASON_TERM: return "term"; + case BLE_GAP_SUBSCRIBE_REASON_RESTORE: return "restore"; + default: return "unknown"; + } +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Get HS error message ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/components/BLEManager/BLEGattServer.h b/components/BLEManager/BLEGattServer.h index a2bf216..55251b1 100644 --- a/components/BLEManager/BLEGattServer.h +++ b/components/BLEManager/BLEGattServer.h @@ -106,6 +106,8 @@ class BLEGattServer // Get HS error message static String getHSErrorMsg(int errorCode); + // Name of the reason for a subscribe event (CCCD written, connection ended, or restored when bonded) + static const char* getSubscribeReasonName(uint8_t reason); // Outbound BLEGattOutbound& getOutbound()