Skip to content

Commit 9bcf9ab

Browse files
author
Veijo Pesonen
committed
Adds mbed-trace prints
1 parent 8f1a73f commit 9bcf9ab

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

ESP8266/ESP8266.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
#include "ESP8266.h"
1818
#include "Callback.h"
1919
#include "mbed_error.h"
20+
#include "mbed_trace.h"
2021
#include "nsapi_types.h"
2122
#include "PinNames.h"
2223

24+
#define TRACE_GROUP "ESPA" // ESP8266 AT layer
25+
2326
#include <cstring>
2427

2528
#define ESP8266_DEFAULT_BAUD_RATE 115200
@@ -442,6 +445,10 @@ nsapi_error_t ESP8266::open_udp(int id, const char *addr, int port, int local_po
442445

443446
_smutex.unlock();
444447

448+
if (done) {
449+
tr_debug("UDP socket %d opened", id);
450+
}
451+
445452
return done ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR;
446453
}
447454

@@ -488,6 +495,10 @@ nsapi_error_t ESP8266::open_tcp(int id, const char *addr, int port, int keepaliv
488495

489496
_smutex.unlock();
490497

498+
if (done) {
499+
tr_debug("TCP socket %d opened", id);
500+
}
501+
491502
return done ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR;
492503
}
493504

@@ -555,15 +566,13 @@ void ESP8266::_oob_packet_hdlr()
555566
pdu_len = sizeof(struct packet) + amount;
556567

557568
if ((_heap_usage + pdu_len) > MBED_CONF_ESP8266_SOCKET_BUFSIZE) {
558-
MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOBUFS), \
559-
"ESP8266::_packet_handler(): \"esp8266.socket-bufsize\"-limit exceeded, packet dropped");
569+
tr_debug("\"esp8266.socket-bufsize\"-limit exceeded, packet dropped");
560570
return;
561571
}
562572

563573
struct packet *packet = (struct packet *)malloc(pdu_len);
564574
if (!packet) {
565-
MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
566-
"ESP8266::_packet_handler(): Could not allocate memory for RX data");
575+
tr_debug("out of memory, unable to allocate memory for packet");
567576
return;
568577
}
569578
_heap_usage += pdu_len;
@@ -904,27 +913,37 @@ void ESP8266::_oob_socket_close_err()
904913

905914
void ESP8266::_oob_socket0_closed()
906915
{
907-
_sock_i[0].open = false;
916+
static const int id = 0;
917+
_sock_i[id].open = false;
918+
tr_debug("socket %d closed", id);
908919
}
909920

910921
void ESP8266::_oob_socket1_closed()
911922
{
912-
_sock_i[1].open = false;
923+
static const int id = 1;
924+
_sock_i[id].open = false;
925+
tr_debug("socket %d closed", id);
913926
}
914927

915928
void ESP8266::_oob_socket2_closed()
916929
{
917-
_sock_i[2].open = false;
930+
static const int id = 2;
931+
_sock_i[id].open = false;
932+
tr_debug("socket %d closed", id);
918933
}
919934

920935
void ESP8266::_oob_socket3_closed()
921936
{
922-
_sock_i[3].open = false;
937+
static const int id = 3;
938+
_sock_i[id].open = false;
939+
tr_debug("socket %d closed", id);
923940
}
924941

925942
void ESP8266::_oob_socket4_closed()
926943
{
927-
_sock_i[4].open = false;
944+
static const int id = 4;
945+
_sock_i[id].open = false;
946+
tr_debug("socket %d closed", id);
928947
}
929948

930949
void ESP8266::_oob_connection_status()
@@ -938,6 +957,7 @@ void ESP8266::_oob_connection_status()
938957
} else if (strcmp(status, "CONNECTED\n") == 0) {
939958
_conn_status = NSAPI_STATUS_CONNECTING;
940959
} else {
960+
tr_error("invalid AT cmd \'%s\'", status);
941961
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_EBADMSG), \
942962
"ESP8266::_oob_connection_status: invalid AT cmd\n");
943963
}

ESP8266Interface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ESP8266.h"
2222
#include "ESP8266Interface.h"
2323
#include "mbed_debug.h"
24+
#include "mbed_trace.h"
2425
#include "nsapi_types.h"
2526

2627
#ifndef MBED_CONF_ESP8266_DEBUG
@@ -35,6 +36,8 @@
3536
#define MBED_CONF_ESP8266_CTS NC
3637
#endif
3738

39+
#define TRACE_GROUP "ESPI" // ESP8266 Interface
40+
3841
#if defined MBED_CONF_ESP8266_TX && defined MBED_CONF_ESP8266_RX
3942
ESP8266Interface::ESP8266Interface()
4043
: _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG, MBED_CONF_ESP8266_RTS, MBED_CONF_ESP8266_CTS),

0 commit comments

Comments
 (0)