forked from h2zero/esp-nimble-cpp
Fix build with non-esp devices
This commit is contained in:
@ -522,15 +522,13 @@ bool NimBLEDevice::setPower(int8_t dbm, NimBLETxPowerType type) {
|
|||||||
# else
|
# else
|
||||||
(void)type; // unused
|
(void)type; // unused
|
||||||
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm);
|
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm);
|
||||||
ble_hci_vs_set_tx_pwr_cp cmd{dbm};
|
int rc = ble_phy_tx_power_set(dbm);
|
||||||
ble_hci_vs_set_tx_pwr_rp rsp{0};
|
|
||||||
int rc = ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_TX_PWR, &cmd, sizeof(cmd), &rsp, sizeof(rsp));
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
NIMBLE_LOGE(LOG_TAG, "failed to set TX power, rc: %04x\n", rc);
|
NIMBLE_LOGE(LOG_TAG, "failed to set TX power, rc: %04x\n", rc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", rsp.tx_power);
|
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", dbm);
|
||||||
return true;
|
return true;
|
||||||
# endif
|
# endif
|
||||||
} // setPower
|
} // setPower
|
||||||
@ -566,7 +564,7 @@ int NimBLEDevice::getPower(NimBLETxPowerType type) {
|
|||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
(void)type; // unused
|
(void)type; // unused
|
||||||
return ble_phy_txpwr_get();
|
return ble_phy_tx_power_get();
|
||||||
# endif
|
# endif
|
||||||
} // getPower
|
} // getPower
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#define CEIL_DIVIDE(a, b) (((a) + (b) - 1) / (b))
|
#define CEIL_DIVIDE(a, b) (((a) + (b) - 1) / (b))
|
||||||
#define ROUND_DIVIDE(a, b) (((a) + (b) / 2) / (b))
|
#define ROUND_DIVIDE(a, b) (((a) + (b) / 2) / (b))
|
||||||
// Retry
|
// Retry
|
||||||
constexpr TickType_t RetryTimeout = pdMS_TO_TICKS(50);
|
constexpr uint32_t RetryTimeout = 50;
|
||||||
constexpr int RetryCounter = 3;
|
constexpr int RetryCounter = 3;
|
||||||
|
|
||||||
NimBLEL2CAPChannel::NimBLEL2CAPChannel(uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks)
|
NimBLEL2CAPChannel::NimBLEL2CAPChannel(uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks)
|
||||||
@ -65,8 +65,6 @@ bool NimBLEL2CAPChannel::setupMemPool() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->stalledSemaphore = xSemaphoreCreateBinary();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +81,10 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
|
|||||||
|
|
||||||
if (stalled) {
|
if (stalled) {
|
||||||
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel waiting for unstall...");
|
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel waiting for unstall...");
|
||||||
xSemaphoreTake(this->stalledSemaphore, portMAX_DELAY);
|
NimBLETaskData taskData;
|
||||||
|
m_pTaskData = &taskData;
|
||||||
|
NimBLEUtils::taskWait(m_pTaskData, BLE_NPL_TIME_FOREVER);
|
||||||
|
m_pTaskData = nullptr;
|
||||||
stalled = false;
|
stalled = false;
|
||||||
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel unstalled!");
|
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel unstalled!");
|
||||||
}
|
}
|
||||||
@ -125,7 +126,7 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
|
|||||||
case BLE_HS_EBUSY:
|
case BLE_HS_EBUSY:
|
||||||
NIMBLE_LOGD(LOG_TAG, "ble_l2cap_send returned %d. Retrying shortly...", res);
|
NIMBLE_LOGD(LOG_TAG, "ble_l2cap_send returned %d. Retrying shortly...", res);
|
||||||
os_mbuf_free_chain(txd);
|
os_mbuf_free_chain(txd);
|
||||||
vTaskDelay(RetryTimeout);
|
ble_npl_time_delay(ble_npl_time_ms_to_ticks32(RetryTimeout));
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case ESP_OK:
|
case ESP_OK:
|
||||||
@ -247,8 +248,11 @@ int NimBLEL2CAPChannel::handleDataReceivedEvent(struct ble_l2cap_event* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int NimBLEL2CAPChannel::handleTxUnstalledEvent(struct ble_l2cap_event* event) {
|
int NimBLEL2CAPChannel::handleTxUnstalledEvent(struct ble_l2cap_event* event) {
|
||||||
|
if (m_pTaskData != nullptr) {
|
||||||
|
NimBLEUtils::taskRelease(*m_pTaskData, event->tx_unstalled.status);
|
||||||
|
}
|
||||||
|
|
||||||
NIMBLE_LOGI(LOG_TAG, "L2CAP COC 0x%04X transmit unstalled.", psm);
|
NIMBLE_LOGI(LOG_TAG, "L2CAP COC 0x%04X transmit unstalled.", psm);
|
||||||
xSemaphoreGive(this->stalledSemaphore);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +272,7 @@ int NimBLEL2CAPChannel::handleL2capEvent(struct ble_l2cap_event *event, void *ar
|
|||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
case BLE_L2CAP_EVENT_COC_CONNECTED:
|
||||||
returnValue = self->handleConnectionEvent(event);
|
returnValue = self->handleConnectionEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -20,10 +20,11 @@
|
|||||||
|
|
||||||
class NimBLEClient;
|
class NimBLEClient;
|
||||||
class NimBLEL2CAPChannelCallbacks;
|
class NimBLEL2CAPChannelCallbacks;
|
||||||
|
struct NimBLETaskData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Encapsulates a L2CAP channel.
|
* @brief Encapsulates a L2CAP channel.
|
||||||
*
|
*
|
||||||
* This class is used to encapsulate a L2CAP connection oriented channel, both
|
* This class is used to encapsulate a L2CAP connection oriented channel, both
|
||||||
* from the "server" (which waits for the connection to be opened) and the "client"
|
* from the "server" (which waits for the connection to be opened) and the "client"
|
||||||
* (which opens the connection) point of view.
|
* (which opens the connection) point of view.
|
||||||
@ -80,7 +81,7 @@ private:
|
|||||||
|
|
||||||
// Runtime handling
|
// Runtime handling
|
||||||
std::atomic<bool> stalled{false};
|
std::atomic<bool> stalled{false};
|
||||||
SemaphoreHandle_t stalledSemaphore = nullptr;
|
NimBLETaskData* m_pTaskData{nullptr};
|
||||||
|
|
||||||
// Allocate / deallocate NimBLE memory pool
|
// Allocate / deallocate NimBLE memory pool
|
||||||
bool setupMemPool();
|
bool setupMemPool();
|
||||||
|
Reference in New Issue
Block a user