提交 a360689b authored 作者: blu's avatar blu

new feature entropy filter to ignore gray frame without iframe

上级 aec49ee7
......@@ -341,7 +341,7 @@ togo_end:
// sn
// {"sn":string, "updatetime": string, "lastboot": string}
int _validateSn(const json &info) {
if(info.count("sn") == 0||info.count("updatetime") == 0||info.count("lastboot") == 0) {
if(info.count("sn") == 0 || info["sn"].size() == 0) {
spdlog::error("invalid sn config:{}", info.dump());
return -1;
}
......@@ -380,7 +380,8 @@ togo_end:
// replace camera addr, user, password, cloud-addr
spdlog::debug("new config: {}", _config_default_tmpl);
return setValue(_config_default_tmpl, LVDB_KEY_CONFIG, fileName, NULL);
json j = json::parse(_config_default_tmpl);
return setLocalConfig(j);
}
}
......@@ -388,6 +389,7 @@ togo_end:
};
int setSn(json &info, string fileName){
info["lastupdated"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
return setValue(info, LVDB_KEY_SN, fileName, _validateSn);
};
......@@ -430,10 +432,19 @@ togo_end:
};
int setLocalConfig(json &config, string key, string fileName){
if(config.count("data") == 0) {
spdlog::error("setLocalConfig no data field");
return -1;
}
json j;
j["lastupdated"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
j["data"] = config["data"];
if(key.empty()) {
return setValue(config, LVDB_KEY_CONFIG, fileName, _validateConfig);
return setValue(j, LVDB_KEY_CONFIG, fileName, _validateConfig);
}else{
return setValue(config, key, fileName, _validateConfig);
return setValue(j, key, fileName, _validateConfig);
}
};
......
......@@ -46,7 +46,7 @@ class HttpSrv{
json &data = newConfig["data"];
for(auto &[k, v]: data.items()) {
// this is one evmgr
if(v.count(k) == 0||v.size()==0) {
if(v.count("sn") == 0||v["sn"] != k) {
ret["code"] = 2;
ret["msg"] = "evcloudsvc invalid value for key " + k;
spdlog::error(ret["msg"].get<string>());
......@@ -81,16 +81,23 @@ class HttpSrv{
}
}
// update evmgr config
auto lastupdated = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
json evmgrData;
v["lastupdated"] = lastupdated;
evmgrData[k] = v;
evmgrData["data"] = data;
//save
LVDB::setLocalConfig(evmgrData, k);
int r = LVDB::setLocalConfig(evmgrData, k);
if(r < 0) {
string msg = "failed to save config " + k + " -> " + evmgrData.dump();
spdlog::error(msg);
ret["code"] = r;
ret["msg"] = msg;
}
} // for evmgr
// save configmap
if(ret >= 0) {
LVDB::setValue(this->configMap, "configmap");
}
ret["data"] = newConfig["data"];
}
}catch(exception &e) {
......
......@@ -41,6 +41,25 @@ class HttpSrv{
res.set_content(this->info.dump(), "text/json");
});
svr.Post("/info", [this](const Request& req, Response& res){
json ret;
ret["code"] = 0;
ret["msg"] = "ok";
string sn = req.get_param_value("sn");
if(sn.empty()){
ret["code"] = 1;
ret["msg"] = "no sn in param";
}else{
json info;
info["sn"] = sn;
// TODO:
info["lastboot"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
LVDB::setSn(info);
}
res.set_content(this->info.dump(), "text/json");
});
svr.Get("/config", [this](const Request& req, Response& res){
LVDB::getLocalConfig(this->config);
res.set_content(this->config.dump(), "text/json");
......@@ -54,7 +73,6 @@ class HttpSrv{
try{
json newConfig;
newConfig["data"] = json::parse(req.body)["data"];
newConfig["lastupdated"] = ret["time"];
LVDB::setLocalConfig(newConfig);
spdlog::info("evmgr new config: {}", newConfig.dump());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论