bolar_1 date 2026-7-1 d:/proc
This commit is contained in:
62
main/boards/dual_network_board.h
Normal file
62
main/boards/dual_network_board.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
#include "wifi_board.h"
|
||||
#include "ml307_board.h"
|
||||
#include "settings.h"
|
||||
#include <memory>
|
||||
#include <esp_system.h>
|
||||
#include <esp_log.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
enum class NetworkType {
|
||||
WIFI,
|
||||
ML307
|
||||
};
|
||||
|
||||
// Dual network board: loads network type from NVS, initializes only one per boot.
|
||||
// Switch = save new type to NVS + reboot (old project approach).
|
||||
class DualNetworkBoard : public Board {
|
||||
public:
|
||||
DualNetworkBoard(gpio_num_t ml307_tx_pin, gpio_num_t ml307_rx_pin,
|
||||
gpio_num_t ml307_dtr_pin = GPIO_NUM_NC);
|
||||
virtual ~DualNetworkBoard() = default;
|
||||
|
||||
NetworkType GetNetworkType() const { return network_type_; }
|
||||
|
||||
// Save target type to NVS and reboot
|
||||
void SwitchNetworkType();
|
||||
|
||||
// True if booted into WiFi config AP mode
|
||||
bool IsWifiConfigMode() const;
|
||||
|
||||
// Board interface — network methods delegated to current_board_
|
||||
std::string GetBoardType() const override;
|
||||
NetworkInterface* GetNetwork() override;
|
||||
void StartNetwork() override;
|
||||
bool IsNetworkConnected() const override;
|
||||
void SetPowerSaveMode(bool enabled) override;
|
||||
|
||||
// Hardware methods — return nullptr, subclass must override
|
||||
AudioCodec* GetAudioCodec() override { return nullptr; }
|
||||
Led* GetLed() override { return nullptr; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Board> current_board_;
|
||||
NetworkType network_type_ = NetworkType::WIFI;
|
||||
|
||||
gpio_num_t ml307_tx_pin_;
|
||||
gpio_num_t ml307_rx_pin_;
|
||||
gpio_num_t ml307_dtr_pin_;
|
||||
|
||||
// WiFi monitor: detect WiFi loss and switch to 4G
|
||||
static constexpr int WIFI_CHECK_INTERVAL_MS = 5000;
|
||||
static constexpr int WIFI_FAILOVER_TIMEOUT_MS = 30000;
|
||||
static constexpr int WIFI_RSSI_THRESHOLD = -80;
|
||||
static constexpr int WIFI_WEAK_SIGNAL_COUNT = 6;
|
||||
|
||||
TaskHandle_t wifi_monitor_task_ = nullptr;
|
||||
void StartWifiMonitor();
|
||||
static void WifiMonitorTaskFunc(void* arg);
|
||||
};
|
||||
Reference in New Issue
Block a user