From 114e9783e9b7ad0e12fe24415fe34d75ee4b4af7 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期四, 24 一月 2019 13:42:28 +0800
Subject: [PATCH] test
---
QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 593 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 455 insertions(+), 138 deletions(-)
diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index 5505ad3..bc54682 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -21,6 +21,7 @@
//#include "HcRecord.h"
#include <time.h>
#include <dirent.h>
+
using namespace std;
devHttpServer_c::devHttpServer_c()
@@ -225,6 +226,20 @@
std::bind(&devHttpServer_c::editDevId, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4));
+ _HttpSrvRetRecieve.setInfo("^/findSdkRule$", "POST",
+ std::bind(&devHttpServer_c::findSdkRule, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4));
+ _HttpSrvRetRecieve.setInfo("^/editSdkRule$", "POST",
+ std::bind(&devHttpServer_c::editSdkRule, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4));
+ _HttpSrvRetRecieve.setInfo("^/getSnapshot$", "POST",
+ std::bind(&devHttpServer_c::getSnapshot, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3, std::placeholders::_4));
+
+
_HttpSrvRetRecieve.start();
_HttpSrvRetRecieve.waitForShutDown();
}
@@ -380,6 +395,7 @@
/*sdk login*/
ulRet = IMOS_MW_Login(username, passwd, ip, 0, szUserID);
if (ERR_COMMON_SUCCEED != ulRet) {
+ (VOID) IMOS_MW_Cleanup();
printf("Login error ulRet[%lu]", ulRet);
return false;
}
@@ -387,6 +403,8 @@
pstBasicInfo = (IMOS_MW_BASIC_DEVICE_INFO_S *) malloc(sizeof(IMOS_MW_BASIC_DEVICE_INFO_S));
ulRet = IMOS_MW_GetDeviceStatus(szUserID, 0, IMOS_MW_STATUS_BASIC_INFO, (void *) pstBasicInfo);
if (ERR_COMMON_SUCCEED != ulRet) {
+ (VOID) IMOS_MW_Logout(szUserID);
+ (VOID) IMOS_MW_Cleanup();
printf("GetDeviceStatus Error[%lu]\n", ulRet);
return false;
}
@@ -968,10 +986,10 @@
elem["str_brand"] = iter->str_brand.toStdString();
elem["str_reserved"] = iter->str_reserved.toStdString();
- Record_Cam_Sdk rec_sdk = db_c.searchCamSdkTableByCamId(iter->str_cam_dev_id);
- elem["str_sdks"] = rec_sdk.str_sdks.toStdString();
- elem["str_det_thr"] = rec_sdk.str_det_thr.toStdString();
- elem["str_cmp_thr"] = rec_sdk.str_cmp_thr.toStdString();
+// Record_Cam_Sdk rec_sdk = db_c.searchCamSdkTableByCamId(iter->str_cam_dev_id);
+// elem["str_sdks"] = rec_sdk.str_sdks.toStdString();
+// elem["str_det_thr"] = rec_sdk.str_det_thr.toStdString();
+// elem["str_cmp_thr"] = rec_sdk.str_cmp_thr.toStdString();
cout << elem.toStyledString() << endl;
@@ -982,7 +1000,8 @@
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
return out;
}
-
+#define ADD_CAMERA 0
+#define EDIT_CAMERA 1
//缂栬緫鎽勫儚鏈�
std::string devHttpServer_c::cam_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
DBG("ip:" << ip << "; port:" << port);
@@ -994,13 +1013,14 @@
Record_Cam_Dev rec;
Record_Cam_Sdk rec_sdk_old;
Record_Cam_Sdk rec_sdk;
-
+ int type=-1;
int dev_type = db_c.searchDevTypeFromConfigTable();
if (DEV_STORAGE == dev_type) {
return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
}
if (reader.parse(content, value)) {
+
unsigned char serialnumber[SERIALNO_LEN] = {0};
ret = getDevSerialNumber(value["str_ip"].asCString(), value["n_port"].asInt(),
value["str_username"].asCString(), \
@@ -1019,18 +1039,48 @@
rec.str_username = QString::fromStdString(value["str_username"].asString());
rec.str_password = QString::fromStdString(value["str_password"].asString());
rec.str_brand = QString::fromStdString(value["str_brand"].asString());
+ type=value["n_type"].asInt();
+// rec_sdk_old = db_c.searchCamSdkTableByCamId(rec.str_cam_dev_id);
- rec_sdk_old = db_c.searchCamSdkTableByCamId(rec.str_cam_dev_id);
-
- rec_sdk.str_cam_dev_id = rec.str_cam_dev_id;
- rec_sdk.str_sdks = QString::fromStdString(value["str_sdks"].asString());
- rec_sdk.str_det_thr = QString::fromStdString(value["str_det_thr"].asString());
- rec_sdk.str_cmp_thr = QString::fromStdString(value["str_cmp_thr"].asString());
-
- ret = db_c.updateCamAndSdkTable(rec, rec_sdk);
- if (!ret) {
- return "err_db_content";
+// rec_sdk.str_cam_dev_id = rec.str_cam_dev_id;
+// rec_sdk.str_sdks = QString::fromStdString(value["str_sdks"].asString());
+// rec_sdk.str_det_thr = QString::fromStdString(value["str_det_thr"].asString());
+// rec_sdk.str_cmp_thr = QString::fromStdString(value["str_cmp_thr"].asString());
+ bool is_exist=db_c.searchCamDevByCamId(rec.str_cam_dev_id);
+ if(ADD_CAMERA == type )
+ {
+ if(is_exist)
+ {
+ return "{\"ret_status\": \"璇峰嬁閲嶅娣诲姞!\"}";
+ }
+ else
+ {
+ ret =db_c.insertCamDevTable(rec);
+ if (!ret) {
+ return "err_db_content";
+ }
+ }
}
+ else if(EDIT_CAMERA == type )
+ {
+ if(is_exist)
+ {
+ ret = db_c.updateCamDevTable(rec);
+ if (!ret) {
+ return "err_db_content";
+ }
+ }
+ else
+ {
+ return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+ }
+ else
+ {
+ return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+
+
} else {
return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
@@ -1039,10 +1089,11 @@
db_c.updateConfigTableByDevType(DEV_CAMERA);
runAllApp();
}
- //edit camera's sdks
+ //edit camera's sdks
else/* if ((rec_sdk_old.str_sdks != rec_sdk.str_sdks) ||
(rec_sdk_old.str_det_thr != rec_sdk.str_det_thr) ||
- (rec_sdk_old.str_cmp_thr != rec_sdk.str_cmp_thr)) */{
+ (rec_sdk_old.str_cmp_thr != rec_sdk.str_cmp_thr)) */
+ {
killVideoAnalysFromHCApp();
sleep(1);
runAllApp();
@@ -1434,8 +1485,8 @@
if (reader.parse(content, value)) {
int cut_max_duration = value["cut_max_duration"].asInt();
-
- ret = db_c.updateConfigTableByCutDuration(cut_max_duration);
+ int cut_min_duration = value["cut_min_duration"].asInt();
+ ret = db_c.updateConfigTableByCutDuration(cut_max_duration, cut_min_duration);
} else {
return "{\"ret_status\": \"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
@@ -1459,10 +1510,11 @@
Json::Value value;
- int cut_max_duration = db_c.searchConfigTableWithinCutDuration();
- value["cut_max_duration"] = cut_max_duration;
+ Record_Config rec = db_c.searchConfigTableWithinServerInfo();
+ value["cut_max_duration"] = rec.n_cut_max_duration;
+ value["cut_min_duration"] = rec.n_cut_min_duration;
std::string out = value.toStyledString();
return out;
@@ -1657,6 +1709,7 @@
appConfig.setStringProperty("erlCookie", cookie);
appConfig.setStringProperty("erlPath", path);
appConfig.setStringProperty("erlFatherNode", FatherNodeName);
+ appConfig.setStringProperty("clusterID", clusterID);
appConfig.save();
// erlangDbTool->findAllNode();
//face search server reboot
@@ -1668,6 +1721,7 @@
appConfig.setStringProperty("erlCookie", "");
appConfig.setStringProperty("erlPath", "");
appConfig.setStringProperty("erlFatherNode", "");
+ appConfig.setStringProperty("clusterID", "");
appConfig.save();
delete erlangDbTool;
erlangDbTool = nullptr;
@@ -1994,33 +2048,45 @@
std::string img_base64 = value["img_base64"].asString();
std::string idcard = value["idcard"].asString();
std::string strUUID = value["uuid"].asString();
+// if (strUUID.size() > 0) {
+// bool ret_addPerson = false;
+// if (TableName.find("lt_") == 0) {
+// FieldValues fieldValues;
+// AddFaceData addFaceData;
+// //#todo update table
+// addFaceData.uuid = strUUID;
+// addFaceData.faceUrl = img_url;
+//
+// fieldValues.insert(std::make_pair("uuid", strUUID));
+// fieldValues.insert(std::make_pair("idCard", idcard));
+// m_SqliteFaceEncap.updateFace(TableName, addFaceData, fieldValues);
+// } else {
+// ret_addPerson = erlangDbTool->addPerson(strUUID, TableName, feature_base64, img_url, idcard);
+// }
+// }
cv::Mat image;
if (img_url.size() > 0) {
+
+ if (img_url.find("ManCarAnaly") != string::npos && img_url.find("group") != string::npos) {
+ auto pos = img_url.find("group");
+ auto img_tmp = img_url.substr(pos);
+ std::string img_str = "http://";
+ if (fdfsClient.fastFds != nullptr) {
+ img_str.append(fdfsClient.fastFds->getIp() + "/").append(img_tmp);
+ img_url.swap(img_str);
+ }
+ }
+
auto t_results = m_curlDownloadImg.download_jpeg(const_cast<char *>(img_url.c_str()));
+ DBG(img_url << "t_results size is " << t_results.all << " : " << t_results.buffer.size());
cvutil.buffer2CvMat(t_results.buffer, image);
} else if (img_base64.size() > 0) {
- img_url = "http://";
auto str_img = base64.Decode(img_base64.c_str(), img_base64.size());
std::vector<unsigned char> buffer(str_img.size());
memcpy(buffer.data(), str_img.data(), str_img.size());
cvutil.buffer2CvMat(buffer, image);
-
- fdfsClient.rwLock.rdlock();
- if (fdfsClient.fastFds != nullptr) {
- img_url.append(fdfsClient.fastFds->getIp() + "/");
- std::string t_strImg = "";
- if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
- img_url = "upload image fail";
- } else {
- img_url.append(t_strImg);
- img_url.clear();
- img_url = t_strImg;
-// img_url.append("/").append(t_strImg);
- }
- }
- fdfsClient.rwLock.unlock();
} else {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found img\"}");
return "";
@@ -2040,15 +2106,44 @@
if (faceResults.size() <= 0) {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found face\"}");
-// string str_path = "./img/";
-// str_path.append(AppUtil::getTimeString() + ".jpg");
-// cv::imwrite(str_path, image);
+ system("mkdir -p img");
+ string str_path = "./img/";
+ str_path.append(AppUtil::getTimeString() + ".jpg");
+ cv::imwrite(str_path, image);
return "";
// return "{\"error\":\"not found face\"}";
+ } else if (faceResults.size() > 1) {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\" 浠呮敮鎸佸崟浜鸿劯鍥剧墖 \"}");
+ return "";
}
for (auto &item : faceResults) {
feature_base64 = base64.Encode(item.feature.data(), item.feature.size());
+
+
+ int x = item.left;
+ int y = item.top;
+ int w = item.width;
+ int h = item.height;
+ cv::Rect t_rect = {x, y, w, h};
+ auto t_image = image(CvUtil::zoomRect(t_rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+ std::vector<uchar> buffer;
+ cvutil.cvMat2Buffer(t_image, buffer);
+ img_url = "http://";
+ fdfsClient.rwLock.rdlock();
+ if (fdfsClient.fastFds != nullptr) {
+ img_url.append(fdfsClient.fastFds->getIp() + "/");
+ std::string t_strImg = "";
+ if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
+ img_url = "upload image fail";
+ } else {
+ img_url.append(t_strImg);
+ img_url.clear();
+ img_url = t_strImg;
+// img_url.append("/").append(t_strImg);
+ }
+ }
+ fdfsClient.rwLock.unlock();
}
auto size = feature_base64.size();
// std::string uuid = "";
@@ -2317,14 +2412,14 @@
std::string picDate = value["picDate"].asString();
//std::string path_uuid = videoPath;//value["path_uuid"].asString();
- qint64 sub ;
- std::string path = getVideoPathByTime(picDate,devId,sub);
+ qint64 sub;
+ std::string path = getVideoPathByTime(picDate, devId, sub);
if (path.empty()) {
ERR("{\"error\":\"not find path\"}");
return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
}
- DBG("path="<<path);
+ DBG("path=" << path);
videoPath.clear();
videoPath = path;
@@ -2332,10 +2427,10 @@
// sub = (dt.toMSecsSinceEpoch() - dtFile.toMSecsSinceEpoch());
//#yanchi buchong
- // sub = sub > 3000 ? sub - 3000 : 0000;
+ // sub = sub > 3000 ? sub - 3000 : 0000;
//shijian yuejie buchang
- // sub = sub < 0 ? 0000 : sub;
- int haomiao = sub % 1000;
+ // sub = sub < 0 ? 0000 : sub;
+ int haomiao = (sub % 1000) > 50 ? ((sub % 1000) - 50) : 0;
sub /= 1000;
int m = sub;
int shi, fen, miao;
@@ -2344,10 +2439,10 @@
shi = m / 3600;
fen = m / 60 % 60;
miao = m % 60;
- sprintf(ch_time, "%02d:%02d:%02d.%03d", shi, fen, miao, haomiao);
- cout << ch_time << endl;
- } else printf("杈撳叆鏁板�煎お澶�");
+ sprintf(ch_time, "%02d:%02d:%02d.%02d", shi, fen, miao, haomiao / 10);
+ } else printf("杈撳叆鏁板�煎お澶�");
+ DBG("ch_time" << ch_time);
std::string str_time(ch_time);
//#todo 鎸夌収鏃堕棿鍛藉悕
std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
@@ -2357,9 +2452,27 @@
std::string str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
+
if (str_time > str_tmpTime) {
- ERR("{\"error\":\"Time error\"}" << str_time << " str_tmpTime " << str_tmpTime);
- str_time = str_tmpTime.size() > 0 ? str_tmpTime.substr(0, str_tmpTime.rfind(".")) : str_time;
+
+ //str_time = str_tmpTime.size() > 0 ? str_tmpTime : str_time;
+ qint64 v_time = getVideoTime(str_tmpTime) - 1000;
+ int haomiao = (v_time % 1000) > 50 ? ((v_time % 1000) - 50) : 0;
+ v_time /= 1000;
+ int m = v_time;
+ int shi, fen, miao;
+ char ch_time[128];
+ if (m / 3600 < 24) {
+ shi = m / 3600;
+ fen = m / 60 % 60;
+ miao = m % 60;
+ sprintf(ch_time, "%02d:%02d:%02d.%02d", shi, fen, miao, haomiao / 10);
+
+ } else printf("杈撳叆鏁板�煎お澶�");
+
+ str_time = ch_time;
+ ERR("{\"error\":\"Time error\"}" << str_time << " str_tmpTime " << str_tmpTime << " ch_time="
+ << ch_time);
// return "{\"error\":\"Time error\"}";
}
@@ -2414,25 +2527,19 @@
Json::Reader reader;
Json::Value value;
- if (reader.parse(content, value))
- {
+ if (reader.parse(content, value)) {
std::string devId = value["videoNum"].asString();
std::string picDate = value["picDate"].asString();
- qint64 sub;
- std::string path=getVideoPathByTime(picDate,devId,sub);
- if (path.empty())
- {
+ qint64 sub;
+ std::string path = getVideoPathByTime(picDate, devId, sub);
+ if (path.empty()) {
return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
- }
- else
- {
+ } else {
std::string result = "{\"file_path\":\"" + path + "\"}";
return result;
}
- }
- else
- {
+ } else {
return "{\"ret_status\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
}
@@ -2513,90 +2620,110 @@
return true;
}
- std::string devHttpServer_c::getVideoPathByTime(const std::string& time,const std::string& camId,qint64& sub)
- {
- std::string t_FilePath = appConfig.getStringProperty("cutPath");
+std::string devHttpServer_c::getVideoPathByTime(const std::string &time, const std::string &camId, qint64 &sub) {
+ std::string t_FilePath = appConfig.getStringProperty("cutPath");
- bool find=false;;
- if (t_FilePath.back() != '/') {
- t_FilePath.push_back('/');
- }
+ bool find = false;
+ if (t_FilePath.back() != '/') {
+ t_FilePath.push_back('/');
+ }
- QDateTime dt = QDateTime::fromString(QString::fromStdString(time), "yyyy-MM-dd hh:mm:ss:zzz");
+ QDateTime dt = QDateTime::fromString(QString::fromStdString(time), "yyyy-MM-dd hh:mm:ss:zzz");
- std::string t_strTime=dt.toString("yyyyMMddhh").toStdString();
- //# ./camIndex/YYYYMM/DD/
- t_FilePath.append(camId + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
- //YYYYMMDDHH
- t_FilePath.append(t_strTime.substr(0,10) + "/");
+ std::string t_strTime = dt.toString("yyyyMMddhh").toStdString();
+ //# ./camIndex/YYYYMM/DD/
+ t_FilePath.append(camId + "/" + t_strTime.substr(0, 6) + "/" + t_strTime.substr(6, 2) + "/");
+ //YYYYMMDDHH
+ t_FilePath.append(t_strTime.substr(0, 10) + "/");
- qint64 t=dt.toMSecsSinceEpoch();
- std::vector<std::string> vec=forEachFile(t_FilePath);
- std::sort(vec.begin(),vec.end());
- DBG("t_FilePath" << t_FilePath);
- DBG("vec.size()" << vec.size());
- int size=vec.size();
- for(int i=0;i<size;++i)
- {
- qint64 t1=QDateTime::fromString(QString::fromStdString(vec[i]), "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
- if(i+1<size)
- {
- qint64 t2=QDateTime::fromString(QString::fromStdString(vec[i+1]), "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
- if(t>=t1 && t<t2)
- {
- DBG("path="<<vec[i]);
- t_FilePath+=vec[i]+".mp4";
- sub=t-t1;
- find=true;
- break;
- }
+ qint64 t = dt.toMSecsSinceEpoch();
+ std::vector<std::string> vec = forEachFile(t_FilePath);
+ std::sort(vec.begin(), vec.end());
+// DBG("t_FilePath" << t_FilePath);
+// DBG("vec.size()" << vec.size());
+ int size = vec.size();
+ for (int i = 0; i < size; ++i) {
+ qint64 t1 = QDateTime::fromString(QString::fromStdString(vec[i]),
+ "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
+ if (i + 1 < size) {
+ qint64 t2 = QDateTime::fromString(QString::fromStdString(vec[i + 1]),
+ "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
+ if (t >= t1 && t < t2) {
+ DBG("path=" << vec[i]);
+ t_FilePath += vec[i] + ".mp4";
+ sub = t - t1;
+// find = sub < getVideoTime(t_FilePath);
+ break;
+ }
- }
- else
- {
- sub=t-t1;
- if(t>=t1 && sub<=3000)
- {
- DBG("path="<<vec[i]);
- t_FilePath+=vec[i]+".mp4";
- find=true;
- break;
- }
- }
+ } else {
+ sub = t - t1;
+ if (t >= t1) {
+ DBG("path=" << vec[i]);
+ t_FilePath += vec[i] + ".mp4";
+
+// find = sub < getVideoTime(t_FilePath);
+
+ DBG("find:" << find);
+ break;
+ }
+ }
- }
- DBG("sub="<<sub);
- if(!find)
- {
- t_FilePath="";
- }
- return t_FilePath;
+ }
+ DBG("sub=" << sub);
+// if (!find) {
+// t_FilePath = "";
+// }
+ return t_FilePath;
- }
- std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name)
- {
- std::vector<std::string> v;
- auto dir = opendir(dir_name.data());
- struct dirent *ent;
- int len = 0;
- if (dir) {
- while ((ent = readdir(dir)) != NULL) {
- std::string filename = std::string(ent->d_name);
- std::string temp;
- if(filename!="."&&filename!="..")
- {
+}
- temp = filename.substr(0, filename.rfind('.'));
- v.push_back(temp);
- }
+qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string &str_tmpTime) {
+// std::string cmd_getVideoFileTime(
+// " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
- }
- closedir(dir);
- }
- return v;
- }
+// str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
+ DBG("str_tmpTime:" << str_tmpTime);//00:00:06.89
+ qint64 len_ms = 0;
+
+ QStringList list = QString::fromStdString(str_tmpTime).split(":");
+ if (list.size() == 3) {
+ len_ms = list[0].toInt() * 60 * 60 * 1000;
+ len_ms += list[1].toInt() * 60 * 1000;
+
+ QStringList s = list[2].split(".");
+ if (s.size() == 2) {
+ len_ms += s[0].toInt() * 1000;
+ len_ms += s[1].toInt() * 10;
+ }
+
+ }
+ DBG("len_ms:" << len_ms);
+ return len_ms;
+}
+
+std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name) {
+ std::vector<std::string> v;
+ auto dir = opendir(dir_name.data());
+ struct dirent *ent;
+ int len = 0;
+ if (dir) {
+ while ((ent = readdir(dir)) != NULL) {
+ std::string filename = std::string(ent->d_name);
+ std::string temp;
+ if (filename != "." && filename != "..") {
+
+ temp = filename.substr(0, filename.rfind('.'));
+ v.push_back(temp);
+ }
+
+ }
+ closedir(dir);
+ }
+ return v;
+}
std::string devHttpServer_c::addPersons(std::string ip, unsigned int port, std::string content, PResponse &response) {
DBG("ip:" << ip << "; port:" << port);
@@ -2644,6 +2771,7 @@
} else {
str_result = "[]";
}
+ erlangDbTool->sendMessage();
return str_result;
} else {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
@@ -2778,10 +2906,199 @@
str_res = "{\"result\":\"-1\",\"msg\":\"error\",\"existDataBase\":[]}";
ERR(ex.what());
}
+ erlangDbTool->sendMessage();
return str_res;
} else {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
return "";
// return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
-}
\ No newline at end of file
+}
+
+std::string devHttpServer_c::editSdkRule(std::string ip, unsigned int port, std::string content, PResponse &response) {
+ Json::Reader reader;
+ Json::Value value;
+ Json::FastWriter writer;
+ if (reader.parse(content, value)) {
+ SdkRule rule;
+ rule.nSdkType = value["nSdkType"].asInt();
+ rule.nAlarmNumLowerLimit = value["nAlarmNumLowerLimit"].asInt();
+ rule.nAlarmNumUpperLimit = value["nAlarmNumUpperLimit"].asInt();
+ rule.nTriggerDelay = value["nTriggerDelay"].asInt();
+ rule.nTriggerTolerance = value["nTriggerTolerance"].asInt();
+ rule.nThreshold = value["nThreshold"].asInt();
+ rule.nQuality = value["nQuality"].asInt();
+ rule.nIsRun = value["nIsRun"].asInt();
+ rule.strBroadcast = value["nIsBroadcast"].asCString();
+ rule.strAreas = value["strAreas"].asCString();
+ rule.strCamId = value["strCamId"].asCString();
+ rule.strExAreas = value["strExAreas"].asCString();
+ rule.strLine = value["strLine"].asCString();
+ rule.strExLine = value["strExLine"].asCString();
+ if (rule.strCamId.isEmpty()) {
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+ if (rule.nSdkType <= SdkTypeStart || rule.nSdkType >= SdkTypeEnd) {
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+
+ for (int i = 0; i < value["weekRuleArray"].size(); ++i) {
+ Json::Value item = value["weekRuleArray"][i];
+ LActRuleWeekRecord weekRule;
+ weekRule.m_nSdkType = rule.nSdkType;
+ weekRule.m_nType = item["nType"].asInt();
+ weekRule.m_strCamId = rule.strCamId;
+ weekRule.m_strBegin = item["strBegin"].asCString();
+ weekRule.m_strEnd = item["strEnd"].asCString();
+ //rule.weekRuleVec.push_back(weekRule);
+ db_c.updateCameraWeekRule(weekRule);
+ }
+
+
+ if (db_c.updateSdkRule(rule)) {
+// if(rule.nIsRun==1)
+
+ killVideoAnalysFromHCApp();
+ sleep(1);
+ runAllApp();
+
+
+ return "{\"ret_status\": \"ok_ack\"}";
+ } else {
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+ } else {
+ return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ }
+}
+
+std::string devHttpServer_c::findSdkRule(std::string ip, unsigned int port, std::string content, PResponse &response) {
+ Json::Reader reader;
+ Json::Value value;
+
+ if (reader.parse(content, value)) {
+
+ QString strCamId = value["strCamId"].asCString();
+
+ SdkRuleMap ruleMap = db_c.searchSdkRuleByCamId(strCamId);
+
+ int count = ruleMap.size();
+
+ if (count > 0) {
+ Json::Value objs;
+ Json::Value obj;
+
+ for (auto rule:ruleMap) {
+ obj["nSdkType"] = rule.second.nSdkType;
+ obj["nAlarmNumLowerLimit"] = rule.second.nAlarmNumLowerLimit;
+ obj["nAlarmNumUpperLimit"] = rule.second.nAlarmNumUpperLimit;
+ obj["nTriggerDelay"] = rule.second.nTriggerDelay;
+ obj["nTriggerTolerance"] = rule.second.nTriggerTolerance;
+ obj["nThreshold"] = rule.second.nThreshold;
+ obj["nQuality"] = rule.second.nQuality;
+ obj["nIsRun"] = rule.second.nIsRun;
+ obj["nIsBroadcast"] = rule.second.strBroadcast.toStdString();
+ obj["strAreas"] = rule.second.strAreas.toStdString();
+ obj["strCamId"] = rule.second.strCamId.toStdString();
+ obj["strExAreas"] = rule.second.strExAreas.toStdString();
+ obj["strLine"] = rule.second.strLine.toStdString();
+ obj["strExLine"] = rule.second.strExLine.toStdString();
+ Json::Value weekRuleArray;
+
+
+ Json::Value weekRule;
+ std::vector<LActRuleWeekRecord> weekRuleVec = db_c.searchCameraWeekRuleByCamId(strCamId, rule.first);
+ for (int k = 0; k < weekRuleVec.size(); ++k) {
+ Json::Value weekRuleObj;
+ weekRuleObj["nSdkType"] = weekRuleVec[k].m_nSdkType;
+ weekRuleObj["strCamId"] = weekRuleVec[k].m_strCamId.toStdString();
+ weekRuleObj["strBegin"] = weekRuleVec[k].m_strBegin.toStdString();
+ weekRuleObj["strEnd"] = weekRuleVec[k].m_strEnd.toStdString();
+ weekRuleObj["nType"] = weekRuleVec[k].m_nType;
+ weekRule.append(weekRuleObj);
+ }
+ //weekRuleArray[j]=weekRule;
+
+
+ obj["weekRuleArray"] = weekRule;
+ objs.append(obj);
+ }
+ return objs.toStyledString();
+ } else {
+// return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ return "[]";
+ }
+ } else {
+ return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ }
+}
+
+std::string devHttpServer_c::getSnapshot(std::string ip, unsigned int port, std::string content, PResponse &response) {
+ Json::Reader reader;
+ Json::Value value;
+
+ if (reader.parse(content, value)) {
+
+ std::string ip = value["str_ip"].asString();
+// int port= value["n_port"].asInt();
+ int port = 554;
+ std::string username = value["str_username"].asString();
+ std::string pass = value["str_password"].asString();
+ std::string brand = value["str_brand"].asString();
+ std::string rtsp_url = rtspAddrBuild(ip, port, username, pass, brand);
+ if (rtsp_url.empty() )
+ {
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+// unsigned char serialnumber[SERIALNO_LEN] = {0};
+// int ret = getDevSerialNumber(ip.c_str(), port,username.c_str(),pass.c_str(),brand.c_str(),serialnumber);
+
+
+// if ((!ret) || (serialnumber[0] == 0))
+// {
+// return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+// }
+
+// std::string str_cam_dev_id = std::string((char *) serialnumber);//鎽勫儚鏈篿d cam_mac
+
+ std::string str_imgName = appConfig.getStringProperty("cutPath");
+ if (str_imgName.back() != '/') {
+ str_imgName.push_back('/');
+ }
+ str_imgName +=ip;
+ str_imgName +="-";
+ str_imgName += "snapshot.jpg";
+ //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg
+ std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25 -f image2 -s 1920*1080 -y " + str_imgName);
+ DBG(cmd);
+ system(cmd.c_str());
+
+ cv::Mat img = cv::imread(str_imgName);
+
+ if (img.empty()) {
+
+ return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
+ }
+ fdfsClient.rwLock.rdlock();
+ std::string strImgUrl = "http://";
+ if (fdfsClient.fastFds != nullptr) {
+ std::vector<unsigned char> buffer;
+ CvUtil::cvMat2Buffer(img, buffer);
+ std::string strImgUrlTmp = "";
+ fdfsClient.fastFds->uploadFile(buffer, strImgUrlTmp, "jpg");
+ strImgUrl.append(fdfsClient.fastFds->getIp() + "/" + strImgUrlTmp);
+ strImgUrl.clear();
+ strImgUrl = strImgUrlTmp;
+ }
+ fdfsClient.rwLock.unlock();
+ Json::Value result;
+ result["imgUrl"] = strImgUrl;
+
+ return result.toStyledString();
+
+
+ } else {
+ return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
+ }
+}
+
--
Gitblit v1.8.0