use hex to save shortaddr.
This commit is contained in:
parent
192c121549
commit
89d85b7036
@ -2,6 +2,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <zlog.h>
|
#include <zlog.h>
|
||||||
|
#include "common/common_func.hpp"
|
||||||
|
|
||||||
extern zlog_category_t *zct;
|
extern zlog_category_t *zct;
|
||||||
extern zlog_category_t *zbt;
|
extern zlog_category_t *zbt;
|
||||||
@ -31,11 +32,13 @@ int ShortAddrCfg::ReadCfg(std::map<uint16_t, int>& short_addr_map) {
|
|||||||
|
|
||||||
uint16_t short_addr;
|
uint16_t short_addr;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
std::string short_addr_str;
|
||||||
|
char *end_ptr;
|
||||||
for (const auto &item : root) {
|
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();
|
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;
|
short_addr_map[short_addr] = index;
|
||||||
}
|
}
|
||||||
return 0;
|
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) {
|
int ShortAddrCfg::WriteCfg(std::map<uint16_t, int> &short_addr_map) {
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
char buf[8] = {0};
|
||||||
for (auto it = short_addr_map.begin(); it != short_addr_map.end(); ++it) {
|
for (auto it = short_addr_map.begin(); it != short_addr_map.end(); ++it) {
|
||||||
Json::Value item;
|
Json::Value item;
|
||||||
item["id"] = it->second;
|
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);
|
root.append(item);
|
||||||
}
|
}
|
||||||
Json::StyledStreamWriter streamWriter;
|
Json::StyledStreamWriter streamWriter;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user