diff --git a/libraries/ESPhost/src/CEspCommunication.cpp b/libraries/ESPhost/src/CEspCommunication.cpp index adb3d46c7..d47f00d6e 100644 --- a/libraries/ESPhost/src/CEspCommunication.cpp +++ b/libraries/ESPhost/src/CEspCommunication.cpp @@ -137,6 +137,15 @@ bool CEspCom::getMsgForStation(CMsg &msg) { return false; } +/* -------------------------------------------------------------------------- */ +int CEspCom::peekMsgSizeForStation() { +/* -------------------------------------------------------------------------- */ + if(CEspCom::rxStationQueue.size() > 0) { + return CEspCom::rxStationQueue.front().get_size(); + } + return 0; +} + /* -------------------------------------------------------------------------- */ bool CEspCom::getMsgForSoftAp(CMsg &msg) { /* -------------------------------------------------------------------------- */ diff --git a/libraries/ESPhost/src/CEspCommunication.h b/libraries/ESPhost/src/CEspCommunication.h index b6b1f81f9..cfe8b1cea 100644 --- a/libraries/ESPhost/src/CEspCommunication.h +++ b/libraries/ESPhost/src/CEspCommunication.h @@ -60,6 +60,7 @@ class CEspCom { static bool storeStationMsg(CMsg &msg); static bool storeSoftApMsg(CMsg &msg); static bool getMsgForStation(CMsg &msg); + static int peekMsgSizeForStation(); static bool getMsgForSoftAp(CMsg &msg); static void clearStationRx(); diff --git a/libraries/ESPhost/src/CEspControl.cpp b/libraries/ESPhost/src/CEspControl.cpp index f6b363a8d..af1afddef 100644 --- a/libraries/ESPhost/src/CEspControl.cpp +++ b/libraries/ESPhost/src/CEspControl.cpp @@ -68,12 +68,11 @@ int CEspControl::process_test_messages(CCtrlMsgWrapper* response) { return 0; } - /* -------------------------------------------------------------------------- */ uint8_t *CEspControl::getStationRx(uint8_t &if_num, uint16_t &dim) { /* -------------------------------------------------------------------------- */ uint8_t *rv = nullptr; - CMsg msg; + CMsg msg; __disable_irq(); bool res = CEspCom::getMsgForStation(msg); if(!res) { @@ -91,6 +90,16 @@ uint8_t *CEspControl::getStationRx(uint8_t &if_num, uint16_t &dim) { return rv; } +/* -------------------------------------------------------------------------- */ +uint16_t CEspControl::peekStationRxMsgSize() { +/* -------------------------------------------------------------------------- */ + uint16_t res; + __disable_irq(); + res = CEspCom::peekMsgSizeForStation(); + __enable_irq(); + return res; +} + /* -------------------------------------------------------------------------- */ uint8_t *CEspControl::getSoftApRx(uint8_t &if_num, uint16_t &dim) { /* -------------------------------------------------------------------------- */ diff --git a/libraries/ESPhost/src/CEspControl.h b/libraries/ESPhost/src/CEspControl.h index 798cc52bf..51846c492 100644 --- a/libraries/ESPhost/src/CEspControl.h +++ b/libraries/ESPhost/src/CEspControl.h @@ -137,6 +137,7 @@ class CEspControl { int sendBuffer(ESP_INTERFACE_TYPE type, uint8_t num, uint8_t *buf, uint16_t dim); uint8_t *getStationRx(uint8_t &if_num, uint16_t &dim); + uint16_t peekStationRxMsgSize(); uint8_t *getSoftApRx(uint8_t &if_num, uint16_t &dim); diff --git a/libraries/lwIpWrapper/src/CNetIf.cpp b/libraries/lwIpWrapper/src/CNetIf.cpp index bbdacb5e2..75d2329c0 100644 --- a/libraries/lwIpWrapper/src/CNetIf.cpp +++ b/libraries/lwIpWrapper/src/CNetIf.cpp @@ -1374,27 +1374,28 @@ void CWifiStation::task() /* -------------------------------------------------------------------------- */ /* get messages and process it */ uint8_t if_num; - uint16_t dim; + uint16_t dim = 0; uint8_t* buf = nullptr; + struct pbuf* p = nullptr; + /* shall we verify something about if_num??? */ do { - buf = CEspControl::getInstance().getStationRx(if_num, dim); - - if (buf != nullptr) { - // Serial.println("Wifi Station - msg rx"); - - struct pbuf* p = pbuf_alloc(PBUF_RAW, dim, PBUF_RAM); - if (p != NULL) { + dim = CEspControl::getInstance().peekStationRxMsgSize(); + if (dim > 0) + { + p = pbuf_alloc(PBUF_RAW, dim, PBUF_RAM); + if (p != nullptr) + { + buf = CEspControl::getInstance().getStationRx(if_num, dim); /* Copy ethernet frame into pbuf */ pbuf_take((struct pbuf*)p, (uint8_t*)buf, (uint32_t)dim); - delete[] buf; - if (ni.input(p, &ni) != ERR_OK) { pbuf_free(p); } + delete[] buf; } } - } while(buf != nullptr); + } while(dim > 0 && p != nullptr); #if LWIP_DHCP