bolar_1 date 2026-7-1 d:/proc
This commit is contained in:
84
main/system_info.cc
Normal file
84
main/system_info.cc
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "system_info.h"
|
||||
|
||||
#include <esp_mac.h>
|
||||
#include <esp_chip_info.h>
|
||||
#include <esp_app_desc.h>
|
||||
#include <esp_heap_caps.h>
|
||||
#include <esp_system.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_flash.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#define TAG "SystemInfo"
|
||||
|
||||
std::string SystemInfo::GetMacAddress()
|
||||
{
|
||||
// Use base MAC as device unique ID (independent of WiFi/BLE/4G)
|
||||
// On ESP32-S3: BASE == WIFI_STA, so this is backward compatible
|
||||
uint8_t mac[6];
|
||||
esp_read_mac(mac, ESP_MAC_BASE);
|
||||
char buf[18];
|
||||
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
std::string SystemInfo::BleMacToBaseMac(const std::string& ble_mac)
|
||||
{
|
||||
// ESP32-S3: BLE MAC = BASE MAC + 2
|
||||
// Convert BLE MAC back to BASE MAC for device identification
|
||||
uint8_t mac[6];
|
||||
sscanf(ble_mac.c_str(), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
|
||||
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
|
||||
// Subtract 2 from the 48-bit MAC (handle borrow)
|
||||
uint64_t val = 0;
|
||||
for (int i = 0; i < 6; i++) val = (val << 8) | mac[i];
|
||||
val -= 2;
|
||||
for (int i = 5; i >= 0; i--) { mac[i] = val & 0xFF; val >>= 8; }
|
||||
char buf[18];
|
||||
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetChipModelName()
|
||||
{
|
||||
return CONFIG_IDF_TARGET;
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetAppVersion()
|
||||
{
|
||||
const esp_app_desc_t* desc = esp_app_get_description();
|
||||
return desc ? desc->version : "unknown";
|
||||
}
|
||||
|
||||
std::string SystemInfo::GetUserAgent()
|
||||
{
|
||||
return std::string("borla-s3/") + GetAppVersion();
|
||||
}
|
||||
|
||||
uint32_t SystemInfo::GetFreeHeapSize()
|
||||
{
|
||||
return esp_get_free_heap_size();
|
||||
}
|
||||
|
||||
uint32_t SystemInfo::GetMinimumFreeHeapSize()
|
||||
{
|
||||
return esp_get_minimum_free_heap_size();
|
||||
}
|
||||
|
||||
uint32_t SystemInfo::GetFlashSize()
|
||||
{
|
||||
uint32_t flash_size = 0;
|
||||
esp_flash_get_size(nullptr, &flash_size);
|
||||
return flash_size;
|
||||
}
|
||||
|
||||
void SystemInfo::PrintHeapStats()
|
||||
{
|
||||
ESP_LOGI(TAG, "Free heap: %lu, Min free: %lu, PSRAM free: %lu",
|
||||
(unsigned long)esp_get_free_heap_size(),
|
||||
(unsigned long)esp_get_minimum_free_heap_size(),
|
||||
(unsigned long)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
Reference in New Issue
Block a user