58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
#include <unistd.h>
|
|
#include <limits.h>
|
|
#include <stdexcept>
|
|
#include "logger.hpp"
|
|
|
|
using ordered_json = nlohmann::ordered_json;
|
|
|
|
struct MQTTTopics
|
|
{
|
|
std::string uplink_1;
|
|
std::string uplink_2;
|
|
std::string downlink;
|
|
std::string downlink2;
|
|
};
|
|
|
|
struct MQTTPorts
|
|
{
|
|
int config_port;
|
|
int uplink_1_port;
|
|
int uplink_2_port;
|
|
int downlink_port;
|
|
int downlink2_port;
|
|
};
|
|
|
|
struct MQTTConfig
|
|
{
|
|
std::string device_id;
|
|
std::string vin;
|
|
std::string server_ip;
|
|
int server_port;
|
|
std::string client_id;
|
|
std::string username;
|
|
std::string password;
|
|
int qos;
|
|
int keep_alive;
|
|
bool clean_session;
|
|
MQTTTopics topics;
|
|
MQTTPorts ports;
|
|
|
|
static MQTTConfig load_from_file(const std::string &filepath);
|
|
// 用完整 JSON 对象更新原始配置中已有字段
|
|
bool update_mqtt_config(const ordered_json &new_values,
|
|
const std::string &filepath = "config.json");
|
|
};
|
|
|
|
std::string get_executable_dir();
|
|
std::string get_executable_dir_file_path(const std::string &filename);
|
|
|
|
// 全局配置变量
|
|
extern MQTTConfig g_mqtt_config;
|