libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
esp_wifi_client.hpp
1#pragma once
2
3#include "esp_def.hpp"
4#include "esp_event.h"
5#include "esp_netif.h"
6#include "esp_wifi.h"
7#include "net/wifi_client.hpp"
8
9namespace LibXR
10{
11
19{
20 public:
22
23 bool Enable() override;
24
25 void Disable() override;
26
27 WifiError Connect(const Config& config) override;
28
29 WifiError Disconnect() override;
30
31 bool IsConnected() const override;
32
33 IPAddressRaw GetIPAddress() const override;
34
35 MACAddressRaw GetMACAddress() const override;
36
37 WifiError Scan(ScanResult* out_list, size_t max_count, size_t& out_found) override;
38
39 int GetRSSI() const override;
40
41 private:
42 bool RegisterHandlers();
43 void UnregisterHandlers();
44 void ResetConnectionState();
45 void DrainEvents();
46
54 static void EventHandler(void* arg, esp_event_base_t event_base, int32_t event_id,
55 void* event_data);
56
57 static inline bool is_initialized_ =
58 false;
59 static inline esp_netif_t* netif_ = nullptr;
60
61 bool init_ok_ = false;
62 bool enabled_ = false;
63 bool handlers_registered_ = false;
64 bool connected_ = false;
65 bool got_ip_ = false;
66 char ip_str_[16] = {};
67 esp_event_handler_instance_t wifi_connected_handler_ = nullptr;
68 esp_event_handler_instance_t wifi_disconnected_handler_ = nullptr;
69 esp_event_handler_instance_t got_ip_handler_ = nullptr;
70 esp_event_handler_instance_t lost_ip_handler_ = nullptr;
71
72 LibXR::Semaphore semaphore_;
73};
74
75} // namespace LibXR
ESP32 Wi-Fi 客户端实现 / ESP32 Wi-Fi client implementation.
MACAddressRaw GetMACAddress() const override
获取当前 MAC 地址 / Get MAC address
IPAddressRaw GetIPAddress() const override
获取当前 IP 地址 / Get current IP address
WifiError Connect(const Config &config) override
连接到指定 WiFi 网络 / Connect to a WiFi network
void Disable() override
禁用网络接口(WiFi) / Disable the network interface
int GetRSSI() const override
获取当前 WiFi 信号强度(RSSI) / Get current signal strength
bool Enable() override
启用网络接口(WiFi) / Enable the network interface
WifiError Disconnect() override
断开当前 WiFi 连接 / Disconnect from the WiFi network
bool IsConnected() const override
检查是否已连接 / Check if currently connected
WifiError Scan(ScanResult *out_list, size_t max_count, size_t &out_found) override
扫描可用网络 / Scan for available WiFi networks
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
Definition semaphore.hpp:23
WiFi 客户端接口 / WiFi Client Interface.
WifiError
WiFi 错误码 / Enumeration of WiFi error codes.
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
原始 IPv4 地址 / Raw IPv4 address
Definition net.hpp:19
原始 MAC 地址 / Raw MAC address
Definition net.hpp:65
WiFi 连接配置 / WiFi connection configuration.
WiFi 扫描结果 / WiFi scan result.