Files
bolar_2/main/connectivity/wifi_transport.h
2026-11-27 16:38:11 +08:00

70 lines
2.4 KiB
C++

#pragma once
#include "connectivity/wifi_types.h"
#include <cstddef>
#include <cstdint>
namespace borla {
enum class WifiTransportEventType : uint8_t {
kStarted,
kGotIp,
kDisconnected,
kReconnectRequested,
kCellularOn,
kCellularOff,
kCellularUnavailable,
kCellularBootOn,
};
struct WifiTransportEvent {
WifiTransportEventType type = WifiTransportEventType::kStarted;
uint16_t disconnect_reason = 0;
};
class IWifiTransportObserver {
public:
virtual ~IWifiTransportObserver() = default;
virtual void OnWifiTransportEvent(
const WifiTransportEvent& event) = 0;
};
class IWifiTransport {
public:
virtual ~IWifiTransport() = default;
virtual bool Start(IWifiTransportObserver& observer) = 0;
virtual void Stop() = 0;
// Stop() only halts the driver; it keeps tens of KB of internal RAM in
// static/dynamic packet buffers. ReleaseDriver() tears the driver all the
// way down so that memory is available to something else — currently the
// BLE controller, which needs ~65 KB internal and cannot coexist with an
// idle-but-initialised WiFi driver on this board. The next Start() brings
// the driver back up. Default is a no-op for transports without one.
virtual void ReleaseDriver() {}
// Selects a trimmed buffer configuration for the next InitializeDriver().
//
// The default profile wants ~36 KB of internal RAM, most of it 10 static
// 1600-byte RX buffers. That is unaffordable in exactly one place: BLE
// provisioning, where the BT controller already holds ~53 KB and the
// driver has to come back up to test the credential the phone just sent.
// Field log: free=44287 at that moment, esp_wifi_init consumed 34 KB and
// then failed on the tenth RX buffer with ESP_ERR_NO_MEM, so the app
// reported "connection failed" on a perfectly good password.
//
// That link only has to associate and pull a DHCP lease before the driver
// is stopped again and the phone reboots the device, so throughput is
// irrelevant there. Everywhere else the default profile stays.
virtual void UseLowMemoryProfile(bool enabled) { (void)enabled; }
virtual bool Connect(const WifiCredential& credential) = 0;
virtual bool Scan(
WifiNetwork* output,
size_t capacity,
size_t* count) = 0;
virtual WifiLinkInfo GetLinkInfo() const = 0;
virtual bool RequestNetworkSwitch() { return false; }
};
} // namespace borla