You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.9 KiB
54 lines
1.9 KiB
#include "config_service.h"
|
|
|
|
#include "project_dep.h"
|
|
|
|
static config_t _config;
|
|
static config_t _default_val_config;
|
|
|
|
#define TAG "config"
|
|
static void dump_config(config_t *pcfg) {
|
|
ZLOGI(TAG, "=============== config ===============");
|
|
ZLOGI(TAG, "obtaining_ip_mode : %s", obtaining_ip_mode_to_string(pcfg->obtaining_ip_mode));
|
|
ZLOGI(TAG, "ip : %s", inet_ntoa(pcfg->ip));
|
|
ZLOGI(TAG, "gw : %s", inet_ntoa(pcfg->gw));
|
|
ZLOGI(TAG, "netmask : %s", inet_ntoa(pcfg->netmask));
|
|
ZLOGI(TAG, "mac : %02x:%02x:%02x:%02x:%02x:%02x", pcfg->mac[0], pcfg->mac[1], pcfg->mac[2], pcfg->mac[3], pcfg->mac[4], pcfg->mac[5]);
|
|
ZLOGI(TAG, "======================================");
|
|
}
|
|
static void create_default_config() { //
|
|
_default_val_config.config_mark = FLASH_MASK_VAL;
|
|
IP4_ADDR((ip4_addr_t *)&_default_val_config.ip, 192, 168, 8, 10);
|
|
IP4_ADDR((ip4_addr_t *)&_default_val_config.gw, 192, 168, 8, 1);
|
|
IP4_ADDR((ip4_addr_t *)&_default_val_config.netmask, 255, 255, 255, 0);
|
|
_default_val_config.obtaining_ip_mode = obtaining_ip_mode_type_static; // dhcp
|
|
|
|
static mac_t mac;
|
|
xs_id_generate_random_mac(&mac);
|
|
memcpy(&_default_val_config.mac[0], mac.mac, 6);
|
|
// ZLOGD(TAG, "random mac is %02x:%02x:%02x:%02x:%02x:%02x", mac.mac[0], mac.mac[1], mac.mac[2], mac.mac[3], mac.mac[4], mac.mac[5]);
|
|
// dump_config(&_default_val_config);
|
|
}
|
|
|
|
void config_init(void) {
|
|
ZLOGI(TAG, "config_init");
|
|
|
|
/**
|
|
* @brief 构造默认配置
|
|
*/
|
|
create_default_config();
|
|
/**
|
|
* @brief flash初始化
|
|
*/
|
|
xs_flash_init(&_config, &_default_val_config, sizeof(config_t) / 4);
|
|
|
|
// ZLOGI(TAG, "xs_flash_is_first_run: %d", xs_flash_is_first_run());
|
|
// ZLOGI(TAG, "");
|
|
|
|
/**
|
|
* @brief 打印配置信息
|
|
*/
|
|
dump_config(&_config);
|
|
}
|
|
config_t *config_get(void) { return &_config; }
|
|
void config_flush(void) { return xs_flash_flush(); }
|
|
void config_factory_reset(void) { xs_flash_factory_reset(); }
|