bolar_2 backup
This commit is contained in:
104
main/connectivity/dual_network_transport.h
Normal file
104
main/connectivity/dual_network_transport.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#pragma once
|
||||
|
||||
#include "connectivity/cellular_transport.h"
|
||||
#include "connectivity/dual_network_policy.h"
|
||||
#include "connectivity/wifi_transport.h"
|
||||
#include "core/task_stack_budget.h"
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
|
||||
#include <esp_timer.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/portmacro.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
namespace borla {
|
||||
|
||||
class DualNetworkTransport final : public IWifiTransport,
|
||||
public IWifiTransportObserver,
|
||||
public ICellularTransportObserver {
|
||||
public:
|
||||
DualNetworkTransport(IWifiTransport& wifi, ICellularTransport& cellular,
|
||||
DualNetworkPolicyConfig config);
|
||||
|
||||
bool Initialize();
|
||||
bool Start(IWifiTransportObserver& observer) override;
|
||||
void Stop() override;
|
||||
// 2026-9-7 ckkj add: 彻底拆除内部 WiFi 驱动释放内部 RAM(BLE 好友模式
|
||||
// 挂起时由 ConnectivityManager 调用);不发布事件,下一步 Start() 重建驱动。
|
||||
void ReleaseDriver() override;////
|
||||
bool Connect(const WifiCredential& credential) override;
|
||||
bool Scan(WifiNetwork* output, size_t capacity, size_t* count) override;
|
||||
WifiLinkInfo GetLinkInfo() const override;
|
||||
bool RequestNetworkSwitch() override;
|
||||
|
||||
void OnWifiTransportEvent(const WifiTransportEvent& event) override;
|
||||
void OnCellularTransportEvent(const CellularTransportEvent& event) override;
|
||||
|
||||
NetworkBearer SelectedBearer() const { return selected_bearer_.load(); }
|
||||
|
||||
private:
|
||||
enum class EventType : uint8_t {
|
||||
kStart,
|
||||
kStop,
|
||||
kConnect,
|
||||
kWifiStarted,
|
||||
kWifiGotIp,
|
||||
kWifiDisconnected,
|
||||
kCellularStarted,
|
||||
kCellularGotIp,
|
||||
kCellularDisconnected,
|
||||
kMonitor,
|
||||
kManualSwitch,
|
||||
};
|
||||
|
||||
struct Event {
|
||||
EventType type = EventType::kStart;
|
||||
uint16_t reason = 0;
|
||||
WifiCredential credential {};
|
||||
};
|
||||
|
||||
static constexpr size_t kQueueDepth = 20;
|
||||
static constexpr uint32_t kMonitorIntervalMs = 5000;
|
||||
static constexpr uint32_t kModemProbeIntervalMs = 30000;
|
||||
|
||||
static void TaskEntry(void* context);
|
||||
static void MonitorTimerCallback(void* context);
|
||||
[[noreturn]] void Run();
|
||||
bool Post(const Event& event);
|
||||
void Handle(const Event& event);
|
||||
void Execute(const DualNetworkPolicyResult& result);
|
||||
void Execute(DualNetworkActionType action);
|
||||
void PublishUpstream(const WifiTransportEvent& event);
|
||||
uint64_t NowMs() const;
|
||||
|
||||
IWifiTransport& wifi_;
|
||||
ICellularTransport& cellular_;
|
||||
DualNetworkPolicyConfig config_;
|
||||
DualNetworkPolicy policy_;
|
||||
|
||||
mutable portMUX_TYPE state_lock_ = portMUX_INITIALIZER_UNLOCKED;
|
||||
IWifiTransportObserver* upstream_ = nullptr;
|
||||
WifiCredential pending_credential_ {};
|
||||
bool pending_wifi_connect_ = false;
|
||||
bool wifi_ready_ = false;
|
||||
bool initial_started_published_ = false;
|
||||
ModemPresence modem_presence_ = ModemPresence::kUnknown;
|
||||
uint64_t last_modem_probe_ms_ = 0;
|
||||
|
||||
QueueHandle_t queue_ = nullptr;
|
||||
StaticQueue_t queue_control_ {};
|
||||
alignas(Event)
|
||||
std::array<uint8_t, kQueueDepth * sizeof(Event)> queue_storage_ {};
|
||||
TaskHandle_t task_ = nullptr;
|
||||
SemaphoreHandle_t stop_completed_ = nullptr;
|
||||
StaticSemaphore_t stop_completed_control_ {};
|
||||
esp_timer_handle_t monitor_timer_ = nullptr;
|
||||
bool initialized_ = false;
|
||||
std::atomic<NetworkBearer> selected_bearer_ { NetworkBearer::kNone };
|
||||
};
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user