Skip to content

Commit 3c14543

Browse files
committed
Fix BT Service is no set a started due to wrong API usage
1 parent 041658d commit 3c14543

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

esp3d/src/modules/bluetooth/BT_service.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
7171
BTService::setClientAddress(str);
7272
String stmp = "BT Connected with ";
7373
stmp += str;
74+
esp3d_log_d("BT Connected with %s", str);
7475
esp3d_commands.dispatch(stmp.c_str(), ESP3DClientType::all_clients, no_id,
7576
ESP3DMessageType::unique, ESP3DClientType::system,
7677
ESP3DAuthenticationLevel::admin);
@@ -83,6 +84,7 @@ static void my_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
8384
ESP3DClientType::system,
8485
ESP3DAuthenticationLevel::admin);
8586
BTService::setClientAddress("");
87+
esp3d_log_d("BT Disconnected");
8688
} break;
8789
default:
8890
break;
@@ -124,7 +126,7 @@ bool BTService::begin() {
124126
ESP3DMessageType::unique, ESP3DClientType::bluetooth,
125127
ESP3DAuthenticationLevel::admin);
126128
initAuthentication();
127-
129+
_started = res;
128130
return res;
129131
}
130132

@@ -150,7 +152,6 @@ bool BTService::reset() {
150152
* Check if BT is on and working
151153
*/
152154
bool BTService::started() {
153-
_started = btStarted();
154155
return _started;
155156
}
156157

@@ -222,6 +223,7 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) {
222223
}
223224
for (size_t i = 0; i < len; i++) {
224225
_lastflush = millis();
226+
esp3d_log_d("BTService::push2buffer: %c", sbuf[i]);
225227
if (esp3d_string::isRealTimeCommand(sbuf[i])) {
226228
flushChar(sbuf[i]);
227229
} else {
@@ -237,8 +239,11 @@ void BTService::push2buffer(uint8_t *sbuf, size_t len) {
237239

238240
size_t BTService::writeBytes(const uint8_t *buffer, size_t size) {
239241
if (availableForWrite() >= size) {
242+
esp3d_log_d("BTService::writeBytes: %d bytes", size);
240243
return SerialBT.write(buffer, size);
241244
} else {
245+
esp3d_log_d("BTService::writeBytes: %d bytes, not enough space",
246+
size);
242247
size_t sizetosend = size;
243248
size_t sizesent = 0;
244249
uint8_t *buffertmp = (uint8_t *)buffer;
@@ -278,11 +283,18 @@ const char *BTService::hostname() { return _btname.c_str(); }
278283

279284
bool BTService::dispatch(ESP3DMessage *message) {
280285
if (!message || !_started) {
286+
if (!message){
287+
esp3d_log_e("BTService::dispatch: No message");
288+
} else {
289+
esp3d_log_e("BTService::dispatch: BT not started");
290+
}
281291
return false;
282292
}
283293
if (message->size > 0 && message->data) {
284294
size_t sentcnt = writeBytes(message->data, message->size);
285295
if (sentcnt != message->size) {
296+
esp3d_log_e("BTService::dispatch:%s sent %d bytes, expected %d bytes",
297+
(const char *)message->data,sentcnt, message->size);
286298
return false;
287299
}
288300
esp3d_message_manager.deleteMsg(message);

0 commit comments

Comments
 (0)