Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: YeonwooSung/esp32-snippets
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: COM8/esp32-snippets
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 9 files changed
  • 1 contributor

Commits on Aug 8, 2020

  1. Copy the full SHA
    b10c85a View commit details
  2. Ported nkolban/pull/994

    COM8 committed Aug 8, 2020
    Copy the full SHA
    b34f44b View commit details

Commits on Jun 9, 2021

  1. Copy the full SHA
    170d1ae View commit details
Showing with 1,124 additions and 1,297 deletions.
  1. +17 −0 .vscode/settings.json
  2. +36 −39 cpp_utils/BLEAddress.cpp
  3. +12 −10 cpp_utils/BLEAddress.h
  4. +362 −416 cpp_utils/BLEDevice.cpp
  5. +4 −19 cpp_utils/CMakeLists.txt
  6. +105 −143 cpp_utils/FreeRTOS.cpp
  7. +40 −42 cpp_utils/FreeRTOS.h
  8. +452 −525 cpp_utils/WiFi.cpp
  9. +96 −103 cpp_utils/WiFi.h
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"files.associations": {
"*.txt": "plaintext",
"*.tcc": "cpp",
"optional": "cpp",
"istream": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"array": "cpp",
"functional": "cpp",
"regex": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
}
}
75 changes: 36 additions & 39 deletions cpp_utils/BLEAddress.cpp
Original file line number Diff line number Diff line change
@@ -7,25 +7,26 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)

#include "BLEAddress.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <string.h>
#include <stdio.h>
#include <string.h>

#include <iomanip>
#include <sstream>
#include <string>

#include "BLEAddress.h"
#ifdef ARDUINO_ARCH_ESP32
#include "esp32-hal-log.h"
#endif


/**
* @brief Create an address from the native ESP32 representation.
* @param [in] address The native representation.
*/
BLEAddress::BLEAddress(esp_bd_addr_t address) {
memcpy(m_address, address, ESP_BD_ADDR_LEN);
} // BLEAddress

BLEAddress::BLEAddress(esp_bd_addr_t address, esp_ble_wl_addr_type_t type) {
m_type = type;
memcpy(m_address, address, ESP_BD_ADDR_LEN);
} // BLEAddress

/**
* @brief Create an address from a hex string
@@ -38,38 +39,32 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
*
* @param [in] stringAddress The hex representation of the address.
*/
BLEAddress::BLEAddress(std::string stringAddress) {
if (stringAddress.length() != 17) return;

int data[6];
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
m_address[0] = (uint8_t) data[0];
m_address[1] = (uint8_t) data[1];
m_address[2] = (uint8_t) data[2];
m_address[3] = (uint8_t) data[3];
m_address[4] = (uint8_t) data[4];
m_address[5] = (uint8_t) data[5];
} // BLEAddress
BLEAddress::BLEAddress(std::string stringAddress, esp_ble_wl_addr_type_t type) {
m_type = type;
if (stringAddress.length() != 17) return;

int data[6];
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
m_address[0] = (uint8_t)data[0];
m_address[1] = (uint8_t)data[1];
m_address[2] = (uint8_t)data[2];
m_address[3] = (uint8_t)data[3];
m_address[4] = (uint8_t)data[4];
m_address[5] = (uint8_t)data[5];
} // BLEAddress

/**
* @brief Determine if this address equals another.
* @param [in] otherAddress The other address to compare against.
* @return True if the addresses are equal.
*/
bool BLEAddress::equals(BLEAddress otherAddress) {
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
} // equals

bool BLEAddress::equals(BLEAddress otherAddress) { return memcmp(otherAddress.getNative(), m_address, 6) == 0 && m_type == otherAddress.m_type; } // equals

/**
* @brief Return the native representation of the address.
* @return The native representation of the address.
*/
esp_bd_addr_t *BLEAddress::getNative() {
return &m_address;
} // getNative

esp_bd_addr_t *BLEAddress::getNative() { return &m_address; } // getNative

/**
* @brief Convert a BLE address to a string.
@@ -83,13 +78,15 @@ esp_bd_addr_t *BLEAddress::getNative() {
* @return The string representation of the address.
*/
std::string BLEAddress::toString() {
std::stringstream stream;
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[0] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[1] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[2] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[3] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[4] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[5];
return stream.str();
} // toString
std::stringstream stream;
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[0] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[1] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[2] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[3] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[4] << ':';
stream << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *)(m_address))[5];
return stream.str();
} // toString

esp_ble_wl_addr_type_t BLEAddress::getType() const { return m_type; }
#endif
22 changes: 12 additions & 10 deletions cpp_utils/BLEAddress.h
Original file line number Diff line number Diff line change
@@ -9,25 +9,27 @@
#define COMPONENTS_CPP_UTILS_BLEADDRESS_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <esp_gap_ble_api.h> // ESP32 BLE
#include <string>
#include <esp_gap_ble_api.h> // ESP32 BLE

#include <string>

/**
* @brief A %BLE device address.
*
* Every %BLE device has a unique address which can be used to identify it and form connections.
*/
class BLEAddress {
public:
BLEAddress(esp_bd_addr_t address);
BLEAddress(std::string stringAddress);
bool equals(BLEAddress otherAddress);
esp_bd_addr_t* getNative();
std::string toString();
public:
BLEAddress(esp_bd_addr_t address, esp_ble_wl_addr_type_t type = BLE_WL_ADDR_TYPE_RANDOM);
BLEAddress(std::string stringAddress, esp_ble_wl_addr_type_t type = BLE_WL_ADDR_TYPE_RANDOM);
bool equals(BLEAddress otherAddress);
esp_bd_addr_t* getNative();
std::string toString();
esp_ble_wl_addr_type_t getType() const;

private:
esp_bd_addr_t m_address;
private:
esp_bd_addr_t m_address;
esp_ble_wl_addr_type_t m_type;
};

#endif /* CONFIG_BT_ENABLED */
Loading