wangzhibo
2026-08-26 70481429367ca00144b24f118cbfdfb28b02967d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "system.h"
#include "ssid_manager.h"
 
#include <string>
 
static std::string wifi_history_json;
 
static void AppendJsonEscapedString(std::string& output, const std::string& value) {
    output.push_back('"');
    for (char ch : value) {
        if (ch == '"' || ch == '\\') {
            output.push_back('\\');
        }
        output.push_back(ch);
    }
    output.push_back('"');
}
 
extern "C" const char *WIFI_Get_History_List(void) {
    auto ssid_list = SsidManager::GetInstance().GetSsidList();
 
    wifi_history_json.clear();
    wifi_history_json += "{\"count\":";
    wifi_history_json += std::to_string(ssid_list.size());
    wifi_history_json += ",\"wifi\":[";
 
    for (size_t i = 0; i < ssid_list.size(); ++i) {
        if (i > 0) {
            wifi_history_json.push_back(',');
        }
        wifi_history_json += "{\"index\":";
        wifi_history_json += std::to_string(i);
        wifi_history_json += ",\"ssid\":";
        AppendJsonEscapedString(wifi_history_json, ssid_list[i].ssid);
        wifi_history_json.push_back('}');
    }
 
    wifi_history_json += "]}";
    return wifi_history_json.c_str();
}
 
extern "C" void WIFI_Delete_All(void) {
    SsidManager::GetInstance().Clear();
}