Quellcode durchsuchen

Bug Fixes on EspNow & BLE Server.

xnecas vor 2 Wochen
Ursprung
Commit
8f75dfaa7f

+ 3 - 0
src/BleSerial/Server/BleSerialServer.cpp

@@ -42,8 +42,11 @@ bool BleSerialServer::begin(const char *server_name)
         return false;
 
     // Customize characteristics
+    uint8_t uiDescValue[2] = {0x00, 0x00};
+    _xTxDescriptor.setValue(uiDescValue, 2);
     _pTxCharacteristic->addDescriptor(&_xTxDescriptor);
 
+    _xRxDescriptor.setValue(uiDescValue, 2);
     _pRxCharacteristic->addDescriptor(&_xRxDescriptor);
     _pRxCharacteristic->setCallbacks(&_xRxCharCallbacks);
 

+ 12 - 12
src/EspNowSerial/EspNowSerial.cpp

@@ -42,12 +42,16 @@ esp_err_t EspNowSerial::add_peer_encrypted(EspMacAddress peer_address, CcmpMaste
     return esp_now_add_peer(&peer_info);
 }
 
+esp_now_send_status_t EspNowSerial::get_send_status()
+{
+    return EspNowSerial::_instance->_data_sent;
+}
+
 esp_err_t EspNowSerial::begin(uint8_t channel, bool broadcast, CcmpMasterKey pmk)
 {
     _broadcast = broadcast;                                             // set broadcast flag
     EspNowSerial::_instance = this;                                     // attach global instance as this object
-    _rx_queue.init();                                                    // init rx buffer
-    _data_sent = 1;                                                     // reset data sent flag
+    _rx_queue.init();                                                   // init rx buffer
 
     WiFi.mode(_wifi_mode);                                              // set device as a Wi-Fi Station
     esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);               // force WiFi channel
@@ -110,10 +114,7 @@ int EspNowSerial::peek()
 }
 
 size_t EspNowSerial::write(uint8_t value)
-{ 
-    if (!_data_sent)
-        return 0;
-   
+{    
    uint8_t buffer[1] = {value};
    esp_err_t result = esp_now_send(nullptr, buffer, 1);
 
@@ -124,22 +125,21 @@ size_t EspNowSerial::write(uint8_t value)
 };
 
 size_t EspNowSerial::write(const uint8_t *buffer, size_t size)
-{
-    if (!_data_sent)
-        return 0;
-    
-    _data_sent = 0;     // reset data sent flag
+{    
+    // send new data
     esp_err_t result = esp_now_send(nullptr, buffer, size);
 
     if (result != ESP_OK)
+    {
         return 0;
+    }
     
     return size;
 }
 
 void EspNowSerial::_on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status) 
 {
-    EspNowSerial::_instance->_data_sent = 1;
+    EspNowSerial::_instance->_data_sent = status;
 }
 
 void EspNowSerial::_on_data_recv(const uint8_t *mac_addr, const uint8_t *data, int len) 

+ 14 - 7
src/EspNowSerial/EspNowSerial.h

@@ -81,6 +81,13 @@ public:
      */
     esp_err_t add_peer_encrypted(EspMacAddress peer_address, CcmpMasterKey lmk);
 
+    /** 
+     * @brief Get status of last transmit.
+     * 
+     * @return status
+    */
+    esp_now_send_status_t get_send_status();
+
     /**
      * @brief Get the number of bytes available for reading.
      *
@@ -152,17 +159,17 @@ private:
                               const uint8_t *data,
                               int len);
 
-    wifi_mode_t _wifi_mode;                     ///< Configured WiFi mode
-    wifi_interface_t _wifi_if;                  ///< WiFi interface in use
+    wifi_mode_t _wifi_mode;                                        ///< Configured WiFi mode
+    wifi_interface_t _wifi_if;                                     ///< WiFi interface in use
 
-    bool _has_pmk{false};                       ///< Indicates whether PMK is set
-    bool _broadcast{false};                     ///< Broadcast mode flag
+    bool _has_pmk{false};                                          ///< Indicates whether PMK is set
+    bool _broadcast{false};                                        ///< Broadcast mode flag
 
-    static EspNowSerial *_instance;             ///< Singleton instance for callbacks
+    static EspNowSerial *_instance;                                ///< Singleton instance for callbacks
 
-    uint8_t _data_sent{1};                      ///< TX completion flag
+    esp_now_send_status_t _data_sent{ESP_NOW_SEND_SUCCESS};        ///< TX completion flag
 
-    IoQueue<ESP_NOW_MAX_DATA_LEN> _rx_queue;    ///< Internal RX buffer
+    IoQueue<ESP_NOW_MAX_DATA_LEN> _rx_queue;                       ///< Internal RX buffer
 };
 
 #endif // _ESPNOW_SERIAL_H_