use hex to save shortaddr.

This commit is contained in:
pandx 2024-11-11 10:00:53 +08:00
parent 192c121549
commit 89d85b7036

View File

@ -2,6 +2,7 @@
#include <fstream>
#include <json/json.h>
#include <zlog.h>
#include "common/common_func.hpp"
extern zlog_category_t *zct;
extern zlog_category_t *zbt;
@ -31,11 +32,13 @@ int ShortAddrCfg::ReadCfg(std::map<uint16_t, int>& short_addr_map) {
uint16_t short_addr;
int index = 0;
std::string short_addr_str;
char *end_ptr;
for (const auto &item : root) {
short_addr = item["short_addr"].asInt();
short_addr_str = item["short_addr"].asString();
short_addr = strtol(short_addr_str.c_str(), &end_ptr, 16);
index = item["id"].asInt();
zlog_info(zbt, "[ShortAddrCfg] index:%d, short addr:%d", index, short_addr);
zlog_info(zbt, "[ShortAddrCfg] index:%d, short addr:%02x", index, short_addr);
short_addr_map[short_addr] = index;
}
return 0;
@ -43,10 +46,13 @@ int ShortAddrCfg::ReadCfg(std::map<uint16_t, int>& short_addr_map) {
int ShortAddrCfg::WriteCfg(std::map<uint16_t, int> &short_addr_map) {
Json::Value root;
char buf[8] = {0};
for (auto it = short_addr_map.begin(); it != short_addr_map.end(); ++it) {
Json::Value item;
item["id"] = it->second;
item["short_addr"] = it->first;
memset(buf, 0, 8);
snprintf(buf, 8, "%02x%02x", UINT16_HIGH(it->first),UINT16_LOW(it->first));
item["short_addr"] = buf;
root.append(item);
}
Json::StyledStreamWriter streamWriter;