123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #ifndef KBF_NET_H
- #define KBF_NET_H
- #include <string>
- #include <esp_netif.h>
- namespace kbf::net {
- /** @brief Tag used for logging. */
- static constexpr const char *TAG = "kbf::net";
- /**
- * @brief Stores a MAC address.
- */
- class MAC {
- public:
- MAC() : addr{0, 0, 0, 0, 0, 0} {};
- explicit MAC(const uint8_t addr[6]);
- /** @brief MAC address as uint8_t[6] */
- uint8_t addr[6]{};
- /**
- * @brief Returns the MAC address as std::string.
- *
- * @return the address in "aa:bb:cc:dd:ee:ff" format
- */
- [[nodiscard]] std::string str() const;
- };
- /**
- * @brief Sets the base MAC address of the device.
- *
- * @note This function must be called before the WiFi driver is initialized,
- * i.e. before kbf::wifi::init().
- *
- * @param MAC address to use
- */
- void setMac(const MAC &mac);
- /**
- * @brief Gets the base MAC address of the device.
- *
- * @return MAC address in use
- */
- MAC getMac();
- /**
- * @brief Stores an IPv4 address.
- */
- class IP {
- public:
- IP() : addr{0} {};
- /**
- * @brief Instantiate from esp_ip4_addr.
- *
- * @param addr esp_ip4_addr
- */
- explicit IP(esp_ip4_addr addr) : addr(addr.addr) {};
- /**
- * @brief Returns the IPv4 address as a std::string.
- *
- * @return the address in "123.123.123.123" format
- */
- [[nodiscard]] std::string str() const;
- private:
- uint32_t addr;
- };
- }
- #endif //KBF_NET_H
|