#include <iostream>
|
#include <VideoServer/QiaoJia/DB/DBStruct.h>
|
#include <jsoncpp/json/json.h>
|
#include "http_configserver.h"
|
#include <QString>
|
#include <basic/util/app/AppConfig.h>
|
#include "net_config/net_config.h"
|
#include "HCNetSDK.h"
|
#include "univiewDriver.h"
|
#include <basic/util/app/AppPreference.hpp>
|
#include "HttpRequestWithCrul.hpp"
|
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
|
#include <GetUUId.h>
|
|
#include <uuid/uuid.h>
|
//#include "HcRecord.h"
|
#include <time.h>
|
#include <dirent.h>
|
#include "basic/pipe_element/ffmpeg/basic_struct_for_video_image.h"
|
|
#include "vss/controller/VssDevTblController.h"
|
#include "vss/controller/VssChannelTblController.h"
|
#include "vss/controller/VssDomainUnitTblController.h"
|
#include "vss/controller/VssLocalSettingTblController.h"
|
#include "vss/controller/VssUpperSvrTblController.h"
|
#include "vss/controller/CamDevController.h"
|
|
using namespace std;
|
|
devHttpServer_c::devHttpServer_c()
|
: _HttpSrvRetRecieve("0.0.0.0", 8083, 1), erlangDbTool(nullptr), m_SqliteFaceEncap("LocalDataDB") {
|
init();
|
}
|
|
devHttpServer_c::devHttpServer_c(std::string test)
|
: _HttpSrvRetRecieve("0.0.0.0", 8083, 1), erlangDbTool(nullptr), m_SqliteFaceEncap("LocalDataDB") {
|
|
fdfsClient.rwLock.wrlock();
|
fdfsClient.fastFds = new FastFds("WebFDSClient.conf");
|
fdfsClient.rwLock.unlock();
|
}
|
|
|
devHttpServer_c::devHttpServer_c(std::string ip, int port, int pthNum)
|
: _HttpSrvRetRecieve(ip, port, pthNum), erlangDbTool(nullptr), m_SqliteFaceEncap("LocalDataDB") {
|
|
auto erlNode = appConfig.getStringProperty("erlNode");
|
auto erlCookie = appConfig.getStringProperty("erlCookie");
|
auto erlPath = appConfig.getStringProperty("erlPath");
|
auto erlFatherNode = appConfig.getStringProperty("erlFatherNode");
|
if (erlNode.size() > 0 && erlCookie.size() > 0) {
|
string str_tmp = "DataWebserver";
|
erlangDbTool = new ErlangTool::ErlangDbTool(erlPath, erlNode, erlCookie, str_tmp);
|
if (erlangDbTool->initErlang() == 1) {
|
erlangDbTool->startNodeDb(erlFatherNode);
|
} else {
|
DBG("not is startNodeDb");
|
}
|
}
|
init();
|
}
|
|
devHttpServer_c::~devHttpServer_c() {
|
|
}
|
|
|
void devHttpServer_c::init(void) {
|
|
std::string strDevId = appConfig.getStringProperty("DEV_ID");
|
|
// DSVAD010120181119
|
m_batch = strDevId.substr(5, 2);
|
m_SerialNumber = strDevId.substr(7, 2);
|
|
DBG("DevID: " << strDevId << " Batch: " << m_batch << " SerNum: " << m_SerialNumber);
|
|
fdfsClient.rwLock.wrlock();
|
fdfsClient.fastFds = new FastFds("WebFDSClient.conf");
|
fdfsClient.rwLock.unlock();
|
|
_HttpSrvRetRecieve.setInfo("^/dev_show$", "POST", std::bind(&devHttpServer_c::dev_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/dev_edit$", "POST", std::bind(&devHttpServer_c::dev_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/devchn_show$", "POST", std::bind(&devHttpServer_c::devchn_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/devchn_edit$", "POST", std::bind(&devHttpServer_c::devchn_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/dev_search_chns$", "POST", std::bind(&devHttpServer_c::dev_search_chns, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/chk_chn_connet$", "POST", std::bind(&devHttpServer_c::chk_chn_connet, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/cam_edit$", "POST", std::bind(&devHttpServer_c::cam_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/cam_show$", "POST", std::bind(&devHttpServer_c::cam_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/chk_cam_connet$", "POST", std::bind(&devHttpServer_c::chk_cam_connet, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/chk_cam_disconnet$", "POST", std::bind(&devHttpServer_c::chk_cam_disconnet, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/dev_del$", "POST", std::bind(&devHttpServer_c::dev_del, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/cam_del$", "POST", std::bind(&devHttpServer_c::cam_del, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/server_info_edit$", "POST", std::bind(&devHttpServer_c::server_info_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/server_info_show$", "POST", std::bind(&devHttpServer_c::server_info_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/cut_dura_edit$", "POST", std::bind(&devHttpServer_c::cut_dura_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/cut_dura_show$", "POST", std::bind(&devHttpServer_c::cut_dura_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
//#data modifyCluName
|
_HttpSrvRetRecieve.setInfo("^/addNode$", "POST", std::bind(&devHttpServer_c::addNode, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/searchNode$", "POST", std::bind(&devHttpServer_c::searchNode, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/modifyCluName$", "POST", std::bind(&devHttpServer_c::modifyCluName, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/removeNode$", "POST", std::bind(&devHttpServer_c::removeNode, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/createDatabase$", "POST", std::bind(&devHttpServer_c::createDatabase, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/deleteDatabase$", "POST", std::bind(&devHttpServer_c::deleteDatabase, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/updateDatabase$", "POST", std::bind(&devHttpServer_c::updateDatabase, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/findAllDatabase$", "POST", std::bind(&devHttpServer_c::findAllDatabase, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/findLocalDatabase$", "POST", std::bind(&devHttpServer_c::findLocalDatabase, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/addPerson$", "POST", std::bind(&devHttpServer_c::addPerson, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/addPersons$", "POST", std::bind(&devHttpServer_c::addPersons, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/personIsExists$", "POST", std::bind(&devHttpServer_c::personIsExists, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/updatePersonByOldId$", "POST", std::bind(&devHttpServer_c::updatePersonByOldId, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3,
|
std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/delPerson$", "POST", std::bind(&devHttpServer_c::delPerson, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/loadFaceFeaData$", "POST", std::bind(&devHttpServer_c::loadFaceFeaData, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/netconfig_edit$", "POST", std::bind(&devHttpServer_c::netconfig_edit, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/netconfig_show$", "POST", std::bind(&devHttpServer_c::netconfig_show, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/getAlarmImageFromVideoFile$", "POST",
|
std::bind(&devHttpServer_c::getAlarmImageFromVideoFile, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/getRecordVideoPath$", "POST",
|
std::bind(&devHttpServer_c::getRecordVideoPath, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
|
_HttpSrvRetRecieve.setInfo("^/findDevId$", "POST",
|
std::bind(&devHttpServer_c::findDevId, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/editDevName$", "POST",
|
std::bind(&devHttpServer_c::editDevName, this,
|
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_3, std::placeholders::_4));
|
_HttpSrvRetRecieve.setInfo("^/editDevId$", "POST",
|
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));
|
|
|
BaseDao::initConnection();
|
BaseSqliteDao::setLDBTool(&db_c);
|
VssDevTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
VssChannelTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
VssDomainUnitTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
VssLocalSettingTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
CamDevController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
VssUpperSvrTblController::instance()->registerHttpServices(_HttpSrvRetRecieve);
|
|
|
_HttpSrvRetRecieve.start();
|
_HttpSrvRetRecieve.waitForShutDown();
|
}
|
|
|
//显示磁盘阵列
|
std::string devHttpServer_c::dev_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Value value;
|
Json::Value elem;
|
bool ret = false;
|
|
std::list<Record_Storage_Dev> rec_list = db_c.searchDeviceTableAll();
|
|
list<Record_Storage_Dev>::iterator iter;
|
|
for (iter = rec_list.begin(); iter != rec_list.end(); ++iter) {
|
elem["str_storage_dev_id"] = iter->str_storage_dev_id.toStdString();
|
elem["str_dev_name"] = iter->str_dev_name.toStdString();
|
elem["str_addr"] = iter->str_addr.toStdString();
|
elem["str_longitude"] = iter->str_longitude.toStdString();
|
elem["str_latitude"] = iter->str_latitude.toStdString();
|
elem["str_ip"] = iter->str_ip.toStdString();
|
elem["n_port"] = iter->n_port;
|
elem["str_username"] = iter->str_username.toStdString();
|
elem["str_password"] = iter->str_password.toStdString();
|
elem["tim_start_time"] = iter->tim_start_time.toString("yyyy-MM-dd hh:mm:ss").toStdString();
|
elem["n_duration"] = iter->n_duration;
|
elem["str_brand"] = iter->str_brand.toStdString();
|
elem["str_reserved"] = iter->str_reserved.toStdString();
|
cout << elem.toStyledString() << endl;
|
value.append(elem);
|
}
|
cout << value.toStyledString() << endl;
|
// std::string out = value.toStyledString();
|
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
|
|
return out;
|
}
|
|
//************************************
|
// Method: string_replace
|
// FullName: string_replace
|
// Access: public
|
// Returns: void
|
// Qualifier: 把字符串的strsrc替换成strdst
|
// Parameter: std::string & strBig
|
// Parameter: const std::string & strsrc
|
// Parameter: const std::string & strdst
|
//************************************
|
static void string_replace(std::string &strBig, const std::string &strsrc, const std::string &strdst) {
|
std::string::size_type pos = 0;
|
std::string::size_type srclen = strsrc.size();
|
std::string::size_type dstlen = strdst.size();
|
|
while ((pos = strBig.find(strsrc, pos)) != std::string::npos) {
|
strBig.replace(pos, srclen, strdst);
|
pos += dstlen;
|
}
|
}
|
|
static std::string rtspAddrBuild(std::string ip, const int port, std::string username,
|
std::string passwd, std::string brand) {
|
std::string rtsp_url;
|
if (brand == "haikang") {
|
rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
|
"/h264/ch1/main/av_stream";
|
} else if (brand == "dahua") {
|
//rtsp://username:password@ip:port/cam/realmonitor?channel=1&subtype=0
|
rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
|
"/cam/realmonitor?channel=1&subtype=0";
|
//TODO
|
} else if (brand == "yushi") {
|
rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
|
"/video1";
|
} else {
|
//TODO
|
}
|
|
return rtsp_url;
|
}
|
|
bool devHttpServer_c::getDevSerialNumber(const char *ip, const int port, const char *username, const char *passwd, \
|
const char *brand, unsigned char *serialNumber) const {
|
std::string strBrand(brand);
|
if (strBrand == "haikang") {
|
getHKDevSerialNumber(ip, port, username, passwd, serialNumber);
|
} else if (strBrand == "dahua") {
|
//TODO
|
} else if (strBrand == "yushi") {
|
return getUVDevSerialNumber(ip, username, passwd, serialNumber);
|
} else {
|
//TODO
|
}
|
|
return true;
|
}
|
|
bool devHttpServer_c::getHKDevSerialNumber(const char *ip, const int port, const char *username, const char *passwd,
|
unsigned char *serialNumber) const {
|
NET_DVR_Init();
|
//设置连接时间与重连时间
|
NET_DVR_SetConnectTime(2000, 1);
|
NET_DVR_SetReconnect(10000, true);
|
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
struLoginInfo.bUseAsynLogin = 0; //同步登录方式
|
strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址
|
struLoginInfo.wPort = port; //设备服务端口
|
strcpy(struLoginInfo.sUserName, username); //设备登录用户名
|
strcpy(struLoginInfo.sPassword, passwd); //设备登录密码
|
|
//设备信息, 输出参数
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
|
|
LONG m_lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
if (m_lUserID < 0) {
|
// printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
if (serialNumber != NULL) {
|
memcpy(serialNumber, struDeviceInfoV40.struDeviceV30.sSerialNumber, SERIALNO_LEN);//TODO获取磁盘阵列的设备id
|
string serialNO((char *) serialNumber);
|
|
string_replace(serialNO, " ", "_");
|
serialNO.copy(serialNumber, serialNO.length(), 0);
|
*(serialNumber + serialNO.length()) = '\0';
|
}
|
|
//注销用户
|
NET_DVR_Logout(m_lUserID);
|
//释放SDK资源
|
NET_DVR_Cleanup();
|
}
|
|
bool
|
devHttpServer_c::getUVDevSerialNumber(const char *ip, const char *username, const char *passwd,
|
unsigned char *serialNumber) const {
|
ULONG ulRet = 0;
|
CHAR szUserID[1024] = {0};
|
IMOS_MW_BASIC_DEVICE_INFO_S *pstBasicInfo = NULL;
|
|
ulRet = IMOS_MW_Initiate();
|
if (ERR_COMMON_SUCCEED != ulRet) {
|
printf("Initiate ret[%lu]", ulRet);
|
return false;
|
}
|
|
/*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;
|
}
|
|
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;
|
}
|
|
if (serialNumber != NULL) {
|
printf("SerialNumber :%s\n", pstBasicInfo->szSerialNumber);
|
strcpy((char *) serialNumber, pstBasicInfo->szSerialNumber);//TODO获取磁盘阵列的设备id
|
string serialNO((char *) serialNumber);
|
|
string_replace(serialNO, " ", "_");
|
serialNO.copy(serialNumber, serialNO.length(), 0);
|
*(serialNumber + serialNO.length()) = '\0';
|
free(pstBasicInfo);
|
}
|
|
(VOID) IMOS_MW_Logout(szUserID);
|
(VOID) IMOS_MW_Cleanup();
|
|
return true;
|
}
|
|
bool devHttpServer_c::getDevChnList(const char *ip, const int port, const char *username, const char *passwd, \
|
const char *brand, std::vector<int> &lvecUsefulChans) const {
|
std::string strBrand(brand);
|
if (strBrand == "haikang") {
|
NET_DVR_Init();
|
//设置连接时间与重连时间
|
NET_DVR_SetConnectTime(2000, 1);
|
NET_DVR_SetReconnect(10000, true);
|
|
//登录参数,包括设备地址、登录用户、密码等
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
struLoginInfo.bUseAsynLogin = 0; //同步登录方式
|
strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址
|
struLoginInfo.wPort = port; //设备服务端口
|
strcpy(struLoginInfo.sUserName, username); //设备登录用户名
|
strcpy(struLoginInfo.sPassword, passwd); //设备登录密码
|
|
//设备信息, 输出参数
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
|
|
LONG m_lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
if (m_lUserID < 0) {
|
// printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
|
NET_DVR_IPPARACFG_V40 ipOut;
|
long len;
|
int iGroupNO = 0 + 33;//33 offset
|
BOOL bret = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_IPPARACFG_V40, iGroupNO, &ipOut,
|
sizeof(NET_DVR_IPPARACFG_V40),
|
(LPDWORD) &len);
|
DWORD dErr = NET_DVR_GetLastError();
|
NET_DVR_PICCFG_V40 picOut;
|
|
bret = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_PICCFG_V40, iGroupNO, &picOut, sizeof(NET_DVR_PICCFG_V40),
|
(LPDWORD) &len);
|
dErr = NET_DVR_GetLastError();
|
lvecUsefulChans.clear();
|
for (int i = 0; i < ipOut.dwDChanNum; i++) {
|
if (ipOut.struStreamMode[i].uGetStream.struChanInfo.byEnable) {
|
|
BYTE byIPID, byIPIDHigh;
|
int iDevInfoIndex;
|
byIPID = ipOut.struStreamMode[i].uGetStream.struChanInfo.byIPID;
|
byIPIDHigh = ipOut.struStreamMode[i].uGetStream.struChanInfo.byIPIDHigh;
|
iDevInfoIndex = byIPIDHigh * 256 + byIPID - 1 - iGroupNO * 64;
|
// printf("IP channel no.%d is online, IP: %s\n", i + 1,
|
// ipOut.struIPDevInfo[iDevInfoIndex].struIP.sIpV4);
|
|
|
lvecUsefulChans.push_back(i + 33);
|
}
|
}
|
|
//注销用户
|
NET_DVR_Logout(m_lUserID);
|
//释放SDK资源
|
NET_DVR_Cleanup();
|
} else if (strBrand == "dahua") {
|
return false;//TODO
|
} else if (strBrand == "yushi") {
|
return false;//TODO
|
} else {
|
return false;//TODO
|
}
|
|
return true;
|
}
|
|
bool devHttpServer_c::loadCurrentVideo(const char *ip, const int port, const char *username, const char *passwd, \
|
const char *brand, const int chn, std::string &videopath) const {
|
std::string strBrand(brand);
|
if (strBrand == "haikang") {
|
NET_DVR_Init();
|
//设置连接时间与重连时间
|
NET_DVR_SetConnectTime(2000, 1);
|
NET_DVR_SetReconnect(10000, true);
|
|
//登录参数,包括设备地址、登录用户、密码等
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
struLoginInfo.bUseAsynLogin = 0; //同步登录方式
|
strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址
|
struLoginInfo.wPort = port; //设备服务端口
|
strcpy(struLoginInfo.sUserName, username); //设备登录用户名
|
strcpy(struLoginInfo.sPassword, passwd); //设备登录密码
|
|
//设备信息, 输出参数
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
|
|
LONG m_lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
if (m_lUserID < 0) {
|
// printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
NET_DVR_PLAYCOND struDownloadCond = {0};
|
struDownloadCond.dwChannel = chn;
|
|
time_t rowtime;
|
time(&rowtime);
|
time_t start_time = rowtime - 7200;
|
time_t end_time = rowtime - 7200 + 10;
|
struct tm *pStartTime = localtime(&start_time);
|
|
struDownloadCond.struStartTime.dwYear = pStartTime->tm_year + 1900;
|
struDownloadCond.struStartTime.dwMonth = pStartTime->tm_mon + 1;
|
struDownloadCond.struStartTime.dwDay = pStartTime->tm_mday;
|
struDownloadCond.struStartTime.dwHour = pStartTime->tm_hour;
|
struDownloadCond.struStartTime.dwMinute = pStartTime->tm_min;
|
struDownloadCond.struStartTime.dwSecond = pStartTime->tm_sec;
|
|
struct tm *pEndTime = localtime(&end_time);
|
struDownloadCond.struStopTime.dwYear = pEndTime->tm_year + 1900;
|
struDownloadCond.struStopTime.dwMonth = pEndTime->tm_mon + 1;
|
struDownloadCond.struStopTime.dwDay = pEndTime->tm_mday;
|
struDownloadCond.struStopTime.dwHour = pEndTime->tm_hour;
|
struDownloadCond.struStopTime.dwMinute = pEndTime->tm_min;
|
struDownloadCond.struStopTime.dwSecond = pEndTime->tm_sec;
|
|
std::string ip_t(ip);
|
std::string filePath = "./" + ip_t + ":" + \
|
std::to_string(port) + "-" + \
|
std::to_string(chn) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwYear) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwMonth) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwDay) + "_" + \
|
std::to_string(struDownloadCond.struStopTime.dwHour) + ":" + \
|
std::to_string(struDownloadCond.struStopTime.dwMinute) + ":" + \
|
std::to_string(struDownloadCond.struStopTime.dwSecond) + ".mp4";
|
|
std::string filePath_tmp = "./" + ip_t + ":" + \
|
std::to_string(port) + "-" + \
|
std::to_string(chn) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwYear) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwMonth) + "-" + \
|
std::to_string(struDownloadCond.struStopTime.dwDay) + "_" + \
|
std::to_string(struDownloadCond.struStopTime.dwHour) + ":" + \
|
std::to_string(struDownloadCond.struStopTime.dwMinute) + ":" + \
|
std::to_string(struDownloadCond.struStopTime.dwSecond) + "_tmp.mp4";
|
|
//---------------------------------------
|
//按时间下载
|
int hPlayback;
|
hPlayback = NET_DVR_GetFileByTime_V40(m_lUserID, (char *) filePath.c_str(), &struDownloadCond);
|
if (hPlayback < 0) {
|
printf("NET_DVR_GetFileByTime_V40 fail,last error %d\n", NET_DVR_GetLastError());
|
NET_DVR_Logout(m_lUserID);
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
//---------------------------------------
|
//开始下载
|
if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART, NULL, 0, NULL, NULL)) {
|
printf("Play back control failed [%d]\n", NET_DVR_GetLastError());
|
NET_DVR_Logout(m_lUserID);
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
int nPos = 0;
|
for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayback)) {
|
//printf("Be downloading... %d %%\n",nPos);
|
sleep(5); //millisecond
|
}
|
if (!NET_DVR_StopGetFile(hPlayback)) {
|
printf("failed to stop get file [%d]\n", NET_DVR_GetLastError());
|
NET_DVR_Logout(m_lUserID);
|
NET_DVR_Cleanup();
|
return false;
|
}
|
if (nPos < 0 || nPos > 100) {
|
printf("download err [%d]\n", NET_DVR_GetLastError());
|
NET_DVR_Logout(m_lUserID);
|
NET_DVR_Cleanup();
|
return false;
|
}
|
|
std::string cmd_transform = "ffmpeg -i " + filePath + " -strict -2 -vf scale=640:360 " + filePath_tmp;
|
system(cmd_transform.c_str());
|
std::string cmd_delsrc = "rm -f " + filePath;
|
system(cmd_delsrc.c_str());
|
videopath = filePath_tmp;
|
|
//注销用户
|
NET_DVR_Logout(m_lUserID);
|
//释放SDK资源
|
NET_DVR_Cleanup();
|
} else if (strBrand == "dahua") {
|
//TODO
|
} else if (strBrand == "yushi") {
|
//TODO
|
} else {
|
//TODO
|
}
|
|
return true;
|
}
|
|
#define DEV_NO_TYPE (0)
|
#define DEV_STORAGE (1)
|
#define DEV_CAMERA (2)
|
|
//编辑磁盘阵列
|
std::string devHttpServer_c::dev_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
|
int dev_type = db_c.searchDevTypeFromConfigTable();
|
if (DEV_CAMERA == dev_type) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
} else {
|
DBG("dev_type :" << dev_type);
|
}
|
|
Record_Storage_Dev dev_rec;
|
if (reader.parse(content, value)) {
|
dev_rec.str_dev_name = QString::fromStdString(value["str_dev_name"].asString());
|
dev_rec.n_total_chn = 0;
|
dev_rec.str_all_chn_num = "";
|
dev_rec.str_addr = QString::fromStdString(value["str_addr"].asString());
|
dev_rec.str_longitude = QString::fromStdString(value["str_longitude"].asString());
|
dev_rec.str_latitude = QString::fromStdString(value["str_latitude"].asString());
|
dev_rec.str_ip = QString::fromStdString(value["str_ip"].asString());
|
dev_rec.n_port = value["n_port"].asInt();
|
dev_rec.str_username = QString::fromStdString(value["str_username"].asString());
|
dev_rec.str_password = QString::fromStdString(value["str_password"].asString());
|
dev_rec.tim_start_time = QDateTime::fromString(QString::fromStdString(value["tim_start_time"].asString()), \
|
"yyyy-MM-dd hh:mm:ss");
|
dev_rec.n_duration = value["n_duration"].asInt();
|
dev_rec.str_brand = QString::fromStdString(value["str_brand"].asString());
|
dev_rec.str_reserved = "";
|
|
unsigned char serialnumber[SERIALNO_LEN] = {0};
|
ret = getDevSerialNumber(value["str_ip"].asCString(), value["n_port"].asInt(),
|
value["str_username"].asCString(), \
|
value["str_password"].asCString(), value["str_brand"].asCString(), serialnumber);
|
if ((!ret) || (serialnumber[0] == 0)) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
dev_rec.str_storage_dev_id = QString::fromLatin1((const char *) serialnumber);//获取磁盘阵列的设备id
|
std::cout << dev_rec.str_storage_dev_id.toStdString() << std::endl;
|
ret = db_c.updateDeviceTable(dev_rec);
|
} else {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
if (ret) {
|
if (DEV_NO_TYPE == dev_type) {
|
db_c.updateConfigTableByDevType(DEV_STORAGE);
|
runAllApp();
|
} else {
|
DBG("dev_type :" << dev_type);
|
}
|
|
Json::Value value_out;
|
value_out["str_storage_dev_id"] = dev_rec.str_storage_dev_id.toStdString();
|
std::string out = value_out.toStyledString();
|
|
return out;
|
} else {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
}
|
|
//搜索磁盘阵列通道
|
std::string
|
devHttpServer_c::dev_search_chns(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
|
if (!reader.parse(content, value_reader)) {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
Record_Storage_Dev rec = db_c.searchDeviceTableByDeviceId(
|
QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
//调用海康大华磁盘阵列sdk,获取磁盘的通道列表
|
std::vector<int> lvecUsefulChans;
|
getDevChnList(rec.str_ip.toStdString().c_str(), rec.n_port, rec.str_username.toStdString().c_str(), \
|
rec.str_password.toStdString().c_str(), rec.str_brand.toStdString().c_str(), lvecUsefulChans);
|
|
std::string str_result;
|
std::string str_tmp;
|
for (int i = 0; i < lvecUsefulChans.size(); i++) {
|
std::cout << lvecUsefulChans.at(i) << std::endl;
|
str_tmp = std::to_string(lvecUsefulChans.at(i));
|
str_result += str_tmp;
|
str_result += ",";
|
}
|
str_result = str_result.substr(0, str_result.length() - 1);
|
Json::Value value;
|
|
value["devchn_list"] = str_result;
|
std::string out = value.toStyledString();
|
|
return out;
|
}
|
|
//测试磁盘阵列通道连接
|
std::string
|
devHttpServer_c::chk_chn_connet(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
|
if (!reader.parse(content, value_reader)) {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
Record_Storage_Dev rec = db_c.searchDeviceTableByDeviceId(\
|
QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
|
//TODO
|
//调用海康大华磁盘阵列sdk,获取磁盘value_reader["str_storage_dev_id"].asString(),value_reader["n_chn"].asString()
|
std::string loadpath;
|
bool ret = loadCurrentVideo(rec.str_ip.toStdString().c_str(), \
|
rec.n_port, \
|
rec.str_username.toStdString().c_str(), \
|
rec.str_password.toStdString().c_str(), \
|
rec.str_brand.toStdString().c_str(), \
|
value_reader["n_chn"].asInt(), \
|
loadpath);
|
|
fdfsClient.rwLock.rdlock();
|
std::string vid_url = "http://";
|
if (fdfsClient.fastFds != nullptr) {
|
vid_url.append(fdfsClient.fastFds->getIp() + "/");
|
std::string t_strVid = "";
|
if (!fdfsClient.fastFds->uploadFile(loadpath, t_strVid)) {
|
vid_url = "upload video fail";
|
} else {
|
vid_url.append(t_strVid);
|
}
|
}
|
fdfsClient.rwLock.unlock();
|
std::string cmd_delsrc = "rm -f " + loadpath;
|
system(cmd_delsrc.c_str());
|
|
Json::Value value;
|
if (!ret) {
|
value["connect_status"] = "False";
|
value["video_url"] = "";
|
} else {
|
|
|
value["connect_status"] = "True";
|
value["video_url"] = vid_url;
|
}
|
|
std::string out = value.toStyledString();
|
|
return out;
|
}
|
|
static std::vector<int> string2vectorint(std::string str_list) {
|
std::vector<int> result_int;
|
char *property_list = const_cast<char *>(str_list.c_str());
|
const char *c_Analyse = ",";
|
char *t_property;
|
|
#ifdef linux
|
char *t_save = NULL;
|
t_property = strtok_r(property_list, c_Analyse, &t_save);
|
#else
|
t_property = strtok(property_list,c_Analyse);
|
#endif
|
|
while (t_property) {
|
std::string str_pro(t_property);
|
result_int.push_back(std::stoi(str_pro));
|
#ifdef linux
|
t_property = strtok_r(t_save, c_Analyse, &t_save);
|
#else
|
t_property = strtok(NULL,c_Analyse);
|
#endif
|
|
}
|
return result_int;
|
}
|
|
//显示磁盘阵列通道列表
|
std::string
|
devHttpServer_c::devchn_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
Json::Value value;
|
Json::Value elem;
|
Json::Value chn_unused;
|
bool ret = false;
|
|
if (reader.parse(content, value_reader)) {
|
QString dev_id = QString::fromStdString(value_reader["str_storage_dev_id"].asString());
|
|
std::list<Record_Cam_Chn> rec_list = db_c.searchChannelTableByDevlId(dev_id);
|
list<Record_Cam_Chn>::iterator iter;
|
|
Record_Storage_Dev rec = db_c.searchDeviceTableByDeviceId(
|
QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
std::vector<int> chns;
|
getDevChnList(rec.str_ip.toStdString().c_str(), rec.n_port, rec.str_username.toStdString().c_str(), \
|
rec.str_password.toStdString().c_str(), rec.str_brand.toStdString().c_str(), chns);
|
|
for (iter = rec_list.begin(); iter != rec_list.end(); ++iter) {
|
// elem["str_storage_dev_id"] = iter->str_storage_dev_id.toStdString();
|
elem["str_name"] = iter->str_name.toStdString();
|
elem["n_chn"] = iter->n_chn;
|
elem["str_addr"] = iter->str_addr.toStdString();
|
elem["str_longitude"] = iter->str_longitude.toStdString();
|
elem["str_latitude"] = iter->str_latitude.toStdString();
|
elem["str_reserved"] = iter->str_reserved.toStdString();
|
|
Record_Chn_Sdk rec_sdk = db_c.searchChnSdkTableByChannelId(iter->str_storage_dev_id, iter->n_chn);
|
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();
|
|
for (std::vector<int>::iterator it = chns.begin(); it != chns.end();) {
|
if (*it == iter->n_chn) {
|
it = chns.erase(it); //删除元素,返回值指向已删除元素的下一个位置
|
} else {
|
++it; //指向下一个位置
|
}
|
}
|
|
cout << elem.toStyledString() << endl;
|
value.append(elem);
|
}
|
|
for (std::vector<int>::iterator it1 = chns.begin(); it1 != chns.end(); it1++) {
|
chn_unused["n_chn"] = *it1;
|
cout << "*it1" << *it1 << endl;
|
value.append(chn_unused);
|
}
|
|
cout << value.toStyledString() << endl;
|
// std::string out = value.toStyledString();
|
std::string out = value.size() > 0 ? value.toStyledString() : "[]";
|
return out;
|
}
|
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
//编辑磁盘阵列通道
|
std::string
|
devHttpServer_c::devchn_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
Record_Chn_Sdk rec_sdk_old;
|
Record_Chn_Sdk rec_sdk;
|
|
if (reader.parse(content, value)) {
|
Record_Cam_Chn rec;
|
rec.str_storage_dev_id = QString::fromStdString(value["str_storage_dev_id"].asString());
|
rec.n_chn = value["n_chn"].asInt();
|
rec.str_name = QString::fromStdString(value["str_name"].asString());
|
rec.str_addr = QString::fromStdString(value["str_addr"].asString());
|
rec.str_longitude = QString::fromStdString(value["str_longitude"].asString());
|
rec.str_latitude = QString::fromStdString(value["str_latitude"].asString());
|
|
Record_Storage_Dev dev_rec = db_c.searchDeviceTableByDeviceId(rec.str_storage_dev_id);
|
rec.tim_do_time = dev_rec.tim_start_time;
|
rec.tim_update_time = QDateTime::currentDateTime();
|
|
rec_sdk_old = db_c.searchChnSdkTableByChannelId(rec.str_storage_dev_id, rec.n_chn);
|
|
rec_sdk.str_storage_dev_id = QString::fromStdString(value["str_storage_dev_id"].asString());
|
rec_sdk.n_chn = value["n_chn"].asInt();
|
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.updateDevChnAndSdk(rec, rec_sdk);
|
if (!ret) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
} else {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
//edit chn's sdks
|
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)) {
|
killVideoAnalysFromHCApp();
|
sleep(1);
|
runAllApp();
|
}
|
|
return "{\"ret_status\": \"ok_ack\"}";
|
}
|
|
void devHttpServer_c::killFaceSearchServerApp() const {
|
string local_passwd = appConfig.getStringProperty("localPasswd");
|
string cmd_kill = "sleep 1 && echo \"" + local_passwd + "\" | sudo -S pkill -9 FaceSearch";
|
system(cmd_kill.c_str());
|
DBG("system(\"sudo -S pkill -9 FaceSearchServer\");");
|
}
|
|
void devHttpServer_c::killVideoAnalysFromHCApp() const {
|
string local_passwd = appConfig.getStringProperty("localPasswd");
|
string cmd_kill_VideoAnalys = "echo \"" + local_passwd + "\" | sudo -S pkill -9 VideoAnalys";
|
system(cmd_kill_VideoAnalys.c_str());
|
string cmd_kill_VideoToIma = "echo \"" + local_passwd + "\" | sudo -S pkill -9 VideoToIma";
|
system(cmd_kill_VideoToIma.c_str());
|
DBG("system(\"sudo -S pkill -9 VideoAnalysFromHC\");");
|
}
|
|
void devHttpServer_c::runAllApp() const {
|
string buildAddr = appConfig.getStringProperty("buildAddr");
|
string cmd = "cd " + buildAddr + " && sh runAll.sh &";
|
system(cmd.c_str());
|
DBG("system(\"cd ~/Apps/QiaoJiaSystem/build/ && sh runAll.sh\");");
|
}
|
|
//显示摄像机列表
|
std::string devHttpServer_c::cam_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Value value;
|
Json::Value elem;
|
|
std::list<Record_Cam_Dev> rec_list = db_c.searchCamDevTableAll();
|
list<Record_Cam_Dev>::iterator iter;
|
|
for (iter = rec_list.begin(); iter != rec_list.end(); ++iter) {
|
// elem["str_storage_dev_id"] = iter->str_storage_dev_id.toStdString();
|
elem["str_cam_dev_id"] = iter->str_cam_dev_id.toStdString();
|
elem["str_name"] = iter->str_name.toStdString();
|
elem["str_addr"] = iter->str_addr.toStdString();
|
elem["str_longitude"] = iter->str_longitude.toStdString();
|
elem["str_latitude"] = iter->str_latitude.toStdString();
|
elem["str_ip"] = iter->str_ip.toStdString();
|
elem["n_port"] = iter->n_port;
|
elem["str_username"] = iter->str_username.toStdString();
|
elem["str_password"] = iter->str_password.toStdString();
|
elem["str_brand"] = iter->str_brand.toStdString();
|
elem["str_reserved"] = iter->str_reserved.toStdString();
|
|
SdkRuleMap ruleMap = db_c.searchSdkRuleByCamId(iter->str_cam_dev_id);
|
|
int count = ruleMap.size();
|
elem["nSdkTypes"] = Json::arrayValue;
|
|
if (count > 0) {
|
for (auto rule:ruleMap) {
|
elem["nSdkTypes"].append(rule.second.nSdkType);
|
}
|
}
|
// 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;
|
|
value.append(elem);
|
}
|
|
cout << value.toStyledString() << endl;
|
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);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
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(), \
|
value["str_password"].asCString(), value["str_brand"].asCString(), serialnumber);
|
if ((!ret) || (serialnumber[0] == 0)) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
rec.type = 0;
|
rec.str_cam_dev_id = QString::fromLatin1((const char *) serialnumber);//摄像机id cam_mac
|
rec.str_name = QString::fromStdString(value["str_name"].asString());
|
rec.str_addr = QString::fromStdString(value["str_addr"].asString());
|
rec.str_longitude = QString::fromStdString(value["str_longitude"].asString());
|
rec.str_latitude = QString::fromStdString(value["str_latitude"].asString());
|
rec.str_ip = QString::fromStdString(value["str_ip"].asString());
|
rec.n_port = value["n_port"].asInt();
|
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());
|
rec.str_reserved = QString::fromStdString(value["str_reserved"].asString());
|
type = value["n_type"].asInt();
|
// 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());
|
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\": \"传输错误,请检查!\"}";
|
}
|
|
if (DEV_NO_TYPE == dev_type) {//add new camera
|
db_c.updateConfigTableByDevType(DEV_CAMERA);
|
runAllApp();
|
}
|
//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)) */
|
{
|
killVideoAnalysFromHCApp();
|
sleep(1);
|
runAllApp();
|
}
|
|
Json::Value value_out;
|
value_out["str_cam_dev_id"] = rec.str_cam_dev_id.toStdString();
|
std::string out = value_out.toStyledString();
|
|
return out;
|
}
|
|
bool devHttpServer_c::cam_connect_video_start(std::string ip, int port, std::string username, std::string passwd, \
|
std::string brand) const {
|
|
if (brand == "haikang") {
|
bool ret = getHKDevSerialNumber(ip.c_str(), port, username.c_str(), passwd.c_str());
|
if (!ret) {
|
ERR("getHKDevSerialNumber ERR");
|
return false;
|
}
|
//调用rtsp流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
|
port = 554;//TODO
|
// std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
|
// "/h264/ch1/main/av_stream";
|
std::string rtsp_url = rtspAddrBuild(ip.c_str(), port, username.c_str(), passwd.c_str(), brand.c_str());
|
if (rtsp_url.empty()) {
|
return false;
|
}
|
|
DBG("rtsp_url:" << rtsp_url);
|
Json::Value json;
|
json["rtsp"] = rtsp_url;
|
|
//拼接json
|
string str_uuid;
|
uuid_t t_uuid;
|
char str[36];
|
uuid_generate(t_uuid);
|
uuid_unparse(t_uuid, str);
|
str_uuid = str;
|
|
std::string rtmpAddr = appConfig.getStringProperty("srsAddr");
|
std::string publish_basepath = rtmpAddr + "cam" + str_uuid;
|
DBG("publish_basepath:" << publish_basepath);
|
appPref.setStringData("publish.basepath", publish_basepath);
|
appPref.setIntData("pulish.width", 640);
|
appPref.setIntData("pulish.height", 360);
|
|
if (m_rtmp.find(ip) != m_rtmp.end()) {
|
if (m_rtmp[ip].appPC == nullptr) {
|
m_rtmp[ip].userCounter = 0;
|
m_rtmp[ip].appPC = new AppPipeController(0, json);
|
m_rtmp[ip].appPC->start();
|
}
|
m_rtmp[ip].userCounter++;
|
|
} else {
|
m_rtmp[ip].appPC = new AppPipeController(0, json);
|
m_rtmp[ip].appPC->start();
|
m_rtmp[ip].userCounter = 1;
|
}
|
|
DBG("m_rtmp[ip]->start(); ip:" << ip);
|
|
} else if (brand == "dahua") {
|
//rtsp://username:password@ip:port/cam/realmonitor?channel=1&subtype=0
|
return false;//TODO
|
} else if (brand == "yushi") {
|
// rtsp://admin:admin@192.168.8.8:554/video1
|
bool ret = getUVDevSerialNumber(ip.c_str(), username.c_str(), passwd.c_str());
|
if (!ret) {
|
ERR("getUVDevSerialNumber ERR");
|
return false;
|
}
|
|
port = 554;
|
// std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) +
|
// "/video1";
|
std::string rtsp_url = rtspAddrBuild(ip.c_str(), port, username.c_str(), passwd.c_str(), brand.c_str());
|
if (rtsp_url.empty()) {
|
return false;
|
}
|
DBG("rtsp_url:" << rtsp_url);
|
Json::Value json;
|
json["rtsp"] = rtsp_url;
|
|
//拼接json
|
string str_uuid;
|
uuid_t t_uuid;
|
char str[36];
|
uuid_generate(t_uuid);
|
uuid_unparse(t_uuid, str);
|
str_uuid = str;
|
|
std::string rtmpAddr = appConfig.getStringProperty("srsAddr");
|
std::string publish_basepath = rtmpAddr + "cam" + str_uuid;
|
DBG("publish_basepath:" << publish_basepath);
|
appPref.setStringData("publish.basepath", publish_basepath);
|
appPref.setIntData("pulish.width", 640);
|
appPref.setIntData("pulish.height", 360);
|
|
if (m_rtmp.find(ip) != m_rtmp.end()) {
|
if (m_rtmp[ip].appPC == nullptr) {
|
m_rtmp[ip].userCounter = 0;
|
m_rtmp[ip].appPC = new AppPipeController(0, json);
|
m_rtmp[ip].appPC->start();
|
}
|
m_rtmp[ip].userCounter++;
|
|
} else {
|
m_rtmp[ip].appPC = new AppPipeController(0, json);
|
m_rtmp[ip].appPC->start();
|
m_rtmp[ip].userCounter = 1;
|
}
|
|
DBG("m_rtmp[ip]->start(); ip:" << ip);
|
|
} else {
|
DBG("other brand");
|
return false;//TODO
|
}
|
|
return true;
|
}
|
|
bool devHttpServer_c::cam_connect_video_stop(std::string ip) const {
|
|
DBG("cam_connect_video_stop begin");
|
// if (m_rtmp.size() > 0) {
|
// auto it = m_rtmp.begin();
|
// while (it != m_rtmp.end()) {
|
// m_rtmp[it->first]->stop();
|
// m_rtmp[it->first]->wait();
|
// it++;
|
// }
|
// }
|
if (m_rtmp.find(ip) != m_rtmp.end()) {
|
if (m_rtmp[ip].appPC == nullptr) {
|
m_rtmp.erase(ip);
|
} else {
|
m_rtmp[ip].userCounter--;
|
|
if (m_rtmp[ip].userCounter == 0) {
|
m_rtmp[ip].appPC->stop();
|
m_rtmp[ip].appPC->wait();
|
m_rtmp.erase(ip);
|
}
|
}
|
}
|
DBG("cam_connect_video_stop end");
|
|
|
return true;
|
}
|
|
//测试摄像机连接
|
std::string
|
devHttpServer_c::chk_cam_connet(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
std::string out;
|
if (!reader.parse(content, value_reader)) {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
Json::Value value;
|
if (value_reader.isMember("id")) {
|
if (value_reader["id"].isNull()) return "{\"ret_status\": \"id内容有误,请检查!\"}";
|
value["connect_status"] = "True";
|
std::string rtmp_url = appConfig.getStringProperty("srsAddr");
|
rtmp_url.append("cam").append(value_reader["id"].asCString());
|
value["video_url"] = rtmp_url;
|
out = value.toStyledString();
|
|
} else {
|
//TODO
|
//调用rtsp流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
|
// std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) + "/h264/ch1/main/av_stream";
|
bool ret = cam_connect_video_start(value_reader["str_ip"].asString(), value_reader["n_port"].asInt(), \
|
value_reader["str_username"].asString(), value_reader["str_password"].asString(), \
|
value_reader["str_brand"].asString());
|
if (!ret) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
std::string rtmp_url = m_rtmp[value_reader["str_ip"].asCString()].appPC->getRtmp();
|
value["connect_status"] = "True";
|
value["video_url"] = rtmp_url;
|
out = value.toStyledString();
|
}
|
|
return out;
|
}
|
|
//测试摄像机连接
|
std::string
|
devHttpServer_c::chk_cam_disconnet(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
|
if (!reader.parse(content, value_reader)) {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
//TODO
|
//调用rtsp流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream
|
// std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) + "/h264/ch1/main/av_stream";
|
DBG("cam_connect_video_stop begin");
|
bool ret = cam_connect_video_stop(value_reader["str_ip"].asString());
|
if (!ret) {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
DBG("cam_connect_video_stop end");
|
|
Json::Value value;
|
value["ret_status"] = "ok_ack";
|
|
std::string out = value.toStyledString();
|
|
return out;
|
}
|
|
//删除磁盘阵列及对应通道列表
|
std::string devHttpServer_c::dev_del(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
|
int dev_type = db_c.searchDevTypeFromConfigTable();
|
if (DEV_CAMERA == dev_type) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
if (reader.parse(content, value_reader)) {
|
QString dev_id = QString::fromStdString(value_reader["str_storage_dev_id"].asString());
|
int ret = db_c.deleteDeviceTableAndChnAndSdk(dev_id);
|
if (ret) {
|
killVideoAnalysFromHCApp();
|
db_c.deleteLoadFileTablebyDevID(QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
db_c.deleteCutVideoTablebyDevID(QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
db_c.deleteSdkHdlTablebyDevID(QString::fromStdString(value_reader["str_storage_dev_id"].asString()));
|
int dev_record = db_c.searchDeviceNumber();
|
if (dev_record == 0) {
|
db_c.updateConfigTableByDevType(DEV_NO_TYPE);
|
} else {
|
runAllApp();
|
}
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "err_db";
|
}
|
}
|
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
//删除摄像机
|
std::string devHttpServer_c::cam_del(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value_reader;
|
|
int dev_type = db_c.searchDevTypeFromConfigTable();
|
if (DEV_STORAGE == dev_type) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
|
if (reader.parse(content, value_reader)) {
|
QString cam_id = QString::fromStdString(value_reader["str_cam_dev_id"].asString());
|
int ret = db_c.deleteCamDevandSdkByCamID(cam_id);
|
if (ret) {
|
killVideoAnalysFromHCApp();
|
int dev_record = db_c.searchCamDevNumber();
|
if (dev_record == 0) {
|
db_c.updateConfigTableByDevType(DEV_NO_TYPE);
|
} else {
|
runAllApp();
|
}
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "err_db";
|
}
|
}
|
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
//修改ip 端口等配置信息
|
std::string
|
devHttpServer_c::server_info_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
|
if (reader.parse(content, value)) {
|
Record_Config lRec;
|
lRec.str_alarm_ip = QString::fromStdString(value["alarm_ip"].asString());
|
lRec.n_alarm_port = value["alarm_port"].asInt();
|
lRec.str_web_pic_ip = QString::fromStdString(value["web_pic_ip"].asString());
|
lRec.n_web_pic_port = value["web_pic_port"].asInt();
|
lRec.str_es_pic_ip = QString::fromStdString(value["es_pic_ip"].asString());
|
lRec.n_es_pic_port = value["es_pic_port"].asInt();
|
if ((checkip(lRec.str_alarm_ip.toStdString())) &&
|
(checkip(lRec.str_web_pic_ip.toStdString())) &&
|
(checkip(lRec.str_es_pic_ip.toStdString()))) {
|
ret = db_c.updateConfigTableByServerInfo(lRec);
|
|
//#todo webserver
|
std::string cmd_web =
|
"sed -i '/tracker_server=/d' ./WebFDSClient.conf && sed -i '/\\\"host:port\\\"/atracker_server=" + \
|
value["web_pic_ip"].asString() + ":" + std::to_string(value["web_pic_port"].asInt()) + \
|
"' ./WebFDSClient.conf";//
|
std::cout << "cmd_web:" << cmd_web << std::endl;
|
system(cmd_web.c_str());
|
|
//#todo fastDfsClient
|
//system("sed -i '/tracker_server=/d' ./fastDfsClient.conf && sed -i '/\"host:port\"/atracker_server=192.168.1.188:22122' ./fastDfsClient.conf");
|
std::string cmd_es =
|
"sed -i '/tracker_server=/d' ./fastDfsClient.conf && sed -i '/\\\"host:port\\\"/atracker_server=" + \
|
value["es_pic_ip"].asString() + ":" + std::to_string(value["es_pic_port"].asInt()) + \
|
"' ./fastDfsClient.conf";
|
std::cout << "cmd_es:" << cmd_es << std::endl;
|
system(cmd_es.c_str());
|
|
//#todo config
|
{
|
fdfsClient.rwLock.wrlock();
|
if (fdfsClient.fastFds != nullptr) {
|
delete fdfsClient.fastFds;
|
}
|
fdfsClient.fastFds = new FastFds("./WebFDSClient.conf");
|
fdfsClient.rwLock.unlock();
|
}
|
|
// //# http client 127.0.0.1:9999/resetFdfs
|
// std::string http_cmd = "http://127.0.0.1:9999/resetFdfs";
|
// HttpRequestWithCrul httpRequestWithCrul;
|
// std::string response_bak = "";
|
// std::string postParams_bak = "";
|
// httpRequestWithCrul.curl_post_req("http://127.0.0.1:9999/resetFdfs", postParams_bak, response_bak);
|
}
|
} else {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
if (ret) {
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
}
|
|
//查询 ip 端口等配置信息
|
std::string
|
devHttpServer_c::server_info_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Value value;
|
|
Record_Config rec = db_c.searchConfigTableWithinServerInfo();
|
|
value["alarm_ip"] = rec.str_alarm_ip.toStdString();
|
value["alarm_port"] = rec.n_alarm_port;
|
value["web_pic_ip"] = rec.str_web_pic_ip.toStdString();
|
value["web_pic_port"] = rec.n_web_pic_port;
|
value["es_pic_ip"] = rec.str_es_pic_ip.toStdString();
|
value["es_pic_port"] = rec.n_es_pic_port;
|
|
std::string out = value.toStyledString();
|
|
return out;
|
}
|
|
//编辑 裁剪视频时长
|
std::string
|
devHttpServer_c::cut_dura_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
|
if (reader.parse(content, value)) {
|
int cut_max_duration = value["cut_max_duration"].asInt();
|
int cut_min_duration = value["cut_min_duration"].asInt();
|
ret = db_c.updateConfigTableByCutDuration(cut_max_duration, cut_min_duration);
|
|
} else {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
if (ret) {
|
killVideoAnalysFromHCApp();
|
sleep(1);
|
runAllApp();
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
}
|
|
//查询 裁剪视频时长
|
std::string
|
devHttpServer_c::cut_dura_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Value value;
|
|
|
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;
|
}
|
|
//设置本机netconfig netconfig_edit
|
std::string
|
devHttpServer_c::netconfig_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
unsigned char ip_old[15] = {0};
|
unsigned char netmask_old[15] = {0};
|
unsigned char gateway_old[15] = {0};
|
|
if (reader.parse(content, value)) {
|
std::string ip_addr = value["ipaddr"].asString();
|
std::string netmask = value["netmask"].asString();
|
std::string gateway = value["gateway"].asString();
|
|
//ipaddr
|
std::string net_ifname = appConfig.getStringProperty("netIfName");
|
if (!((GetIpAddress(net_ifname.c_str(), ip_old)) && \
|
(GetMaskAddress(net_ifname.c_str(), netmask_old)) && \
|
(GetGateWay(net_ifname.c_str(), gateway_old)))) {
|
// return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
std::string ip_old_temp((char *) ip_old);
|
std::string netmask_old_temp((char *) netmask_old);
|
std::string gateway_old_temp((char *) gateway_old);
|
|
if (!((ip_old_temp == ip_addr) && \
|
(netmask_old_temp == netmask) && \
|
(gateway_old_temp == gateway))) {
|
if (!((checkip(ip_addr)) && (checkMask(netmask)) && (checkip(gateway)))) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
ret = SetIpAddress(net_ifname.c_str(), ip_addr.c_str());
|
if (!ret) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
ret = SetMaskAddress(net_ifname.c_str(), netmask.c_str());
|
if (!ret) {
|
return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
ret = SetGateWay(net_ifname.c_str(), gateway_old_temp.c_str(), gateway.c_str());
|
if (!ret) {
|
//return "{\"ret_status\": \"内容有误,请检查!\"}";
|
}
|
|
//#todo /etc/network/interfaces
|
//system("sed -i '/tracker_server=/d' ./fastDfsClient.conf && sed -i '/\"host:port\"/atracker_server=192.168.1.188:22122' ./fastDfsClient.conf");
|
// system("sed -i 's/address .*$/address 192.168.1.111/g' test");
|
std::string cmd_ip =
|
"sed -i 's/address .*$/address " + ip_addr + "/g' /etc/network/interfaces";
|
std::cout << "cmd_ip:" << cmd_ip << std::endl;
|
system(cmd_ip.c_str());
|
|
//修改config.json
|
std::string strtmp = appConfig.getStringProperty("erlNode");
|
std::string::size_type pos = strtmp.find_last_of("@");
|
if (pos != std::string::npos) {
|
++pos;//保留sep '@'
|
strtmp.replace(pos, strtmp.size() - pos, ip_addr);
|
appConfig.setStringProperty("erlNode", strtmp);
|
}
|
|
strtmp = appConfig.getStringProperty("erlFatherNode");
|
pos = strtmp.find_last_of("@");
|
if (pos != std::string::npos) {
|
++pos;//保留sep '@'
|
strtmp.replace(pos, strtmp.size() - pos, ip_addr);
|
appConfig.setStringProperty("erlFatherNode", strtmp);
|
}
|
//ES_IP
|
appConfig.setStringProperty("ES_IP", ip_addr);
|
|
strtmp = appConfig.getStringProperty("srsAddr");
|
strtmp.replace(strtmp.begin() + 7, strtmp.begin() + strtmp.find(":1934/live/"), ip_addr);
|
appConfig.setStringProperty("srsAddr", strtmp);
|
appConfig.save();
|
|
sleep(10);
|
system("reboot");
|
}
|
} else {
|
return "{\"ret_status\": \"传输错误,请检查!\"}";
|
}
|
|
return "{\"ret_status\": \"ok_ack\"}";
|
}
|
|
//查询 本机netconfig netconfig_show
|
std::string
|
devHttpServer_c::netconfig_show(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
Json::Value value;
|
unsigned char netmask_old[15] = {0};
|
unsigned char gateway_old[15] = {0};
|
unsigned char ip_old[15] = {0};
|
|
std::string net_ifname = appConfig.getStringProperty("netIfName");
|
// if (!((GetIpAddress(net_ifname.c_str(), ip_old)) && \
|
// (GetMaskAddress(net_ifname.c_str(), netmask_old)) && \
|
// (GetGateWay(net_ifname.c_str(), gateway_old)))) {
|
// return "{\"ret_status\": \"内容有误,请检查!\"}";
|
// }
|
if (GetIpAddress(net_ifname.c_str(), ip_old)) {
|
std::string ip_old_temp((char *) ip_old);
|
value["ipaddr"] = ip_old_temp;
|
} else {
|
value["ipaddr"] = "";
|
}
|
|
if (GetMaskAddress(net_ifname.c_str(), netmask_old)) {
|
std::string netmask_old_temp((char *) netmask_old);
|
value["netmask"] = netmask_old_temp;
|
} else {
|
value["netmask"] = "";
|
}
|
|
if (GetGateWay(net_ifname.c_str(), gateway_old)) {
|
std::string gateway_old_temp((char *) gateway_old);
|
value["gateway"] = gateway_old_temp;
|
} else {
|
value["gateway"] = "";
|
}
|
|
std::string out = value.toStyledString();
|
|
return out;
|
}
|
|
std::string devHttpServer_c::addNode(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
Json::Reader reader;
|
Json::Value value;
|
bool ret = false;
|
if (reader.parse(content, value)) {
|
|
//#todo nodeName Automatic generated?
|
//#todo nodes have counter?
|
//#todo nodeName Automatic generated?
|
//#todo devId+num
|
std::string uuid = GetUUId::getUUID();
|
|
unsigned char ip_old[15] = {0};
|
std::string str_netIfName = appConfig.getStringProperty("netIfName");
|
GetIpAddress(str_netIfName.c_str(), ip_old);
|
std::string str_ip((char *) ip_old);
|
std::string nodeName = uuid.append("@" + str_ip);
|
|
std::string cookie = value["cookie"].asString();
|
std::string FatherNodeName = value["fatherNodeName"].asString();
|
|
//#todo ClusterID ClusterName
|
std::string clusterID = value["culID"].asString();
|
clusterID = clusterID.size() > 0 ? clusterID : GetUUId::getUUID();
|
std::string clusterName = value["culName"].asString();
|
std::string devID = value["devID"].asString();
|
std::string devName = value["devName"].asString();
|
|
|
std::string path = std::string("/opt/erlang/").append(nodeName.substr(0, nodeName.find("@")));
|
if (erlangDbTool != nullptr) {
|
//gaunbi node
|
//clear data
|
// erlangDbTool.stop();
|
delete erlangDbTool;
|
erlangDbTool = nullptr;
|
}
|
|
if (cookie.size() > 0 && (clusterID.size() > 0 || clusterName.size() > 0)) {
|
// erlangDbTool = new ErlangTool::ErlangDbTool(path, nodeName, cookie);
|
string str_tmp = "DataWebserver";
|
erlangDbTool = new ErlangTool::ErlangDbTool(path, nodeName, cookie, clusterID, clusterName, str_tmp);
|
bool ret = erlangDbTool->initErlang();
|
FatherNodeName = FatherNodeName.size() > 0 ? FatherNodeName : " ";
|
// FatherNodeName = clusterID.size() > 0 ? clusterID : " ";
|
ret = erlangDbTool->startNodeDb(FatherNodeName, devID);
|
|
if (ret) {
|
appConfig.setStringProperty("erlNode", nodeName);
|
appConfig.setStringProperty("erlCookie", cookie);
|
appConfig.setStringProperty("erlPath", path);
|
appConfig.setStringProperty("erlFatherNode", FatherNodeName);
|
appConfig.setStringProperty("clusterID", clusterID);
|
appConfig.save();
|
// erlangDbTool->findAllNode();
|
//face search server reboot
|
killFaceSearchServerApp();
|
runAllApp();
|
// sleep(4);
|
} else {
|
appConfig.setStringProperty("erlNode", "");
|
appConfig.setStringProperty("erlCookie", "");
|
appConfig.setStringProperty("erlPath", "");
|
appConfig.setStringProperty("erlFatherNode", "");
|
appConfig.setStringProperty("clusterID", "");
|
appConfig.save();
|
delete erlangDbTool;
|
erlangDbTool = nullptr;
|
}
|
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
} else {
|
std::string str_result = std::string("{\"result\":").append("\"数据有误\"}");
|
return str_result;
|
}
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查! \"}");
|
return "";
|
}
|
}
|
|
std::string devHttpServer_c::removeNode(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
bool ret = false;
|
|
if (erlangDbTool != nullptr) {
|
|
ret = erlangDbTool->removeNode();
|
|
appConfig.setStringProperty("erlNode", "");
|
appConfig.setStringProperty("erlCookie", "");
|
appConfig.setStringProperty("erlPath", "");
|
appConfig.setStringProperty("erlFatherNode", "");
|
appConfig.save();
|
delete erlangDbTool;
|
erlangDbTool = nullptr;
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
//#todo
|
system("pkill beam.*");
|
return str_result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
}
|
}
|
|
string devHttpServer_c::searchNode(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
ERR("{\"error\":\"节点不存在 \"}");
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
// sleep(1);
|
auto resu = erlangDbTool->findAllNode();
|
string json = "";
|
if (resu.size() > 0) {
|
auto t_itor = resu.begin();
|
m_cluster_id = t_itor->second.cluster_id;
|
m_cluster_name = t_itor->second.cluster_name;
|
json.append("{ \"cluster_id\":\"" + t_itor->second.cluster_id
|
+ "\",\"cluster_name\":\"" + t_itor->second.cluster_name + "\",\"list\":[");
|
for (auto &item : resu) {
|
string subJson = "{ ";
|
subJson.append("\"uuid\":\"" + item.second.uuid + "\",");
|
subJson.append("\"create_time\":\"" + item.second.create_time + "\",");
|
subJson.append("\"dev_id\":\"" + item.second.device_id + "\",");
|
//#todo
|
auto rec = db_c.searchConfigTableWithinServerInfo();
|
subJson.append("\"dev_name\":\"" + rec.dev_name.toStdString() + "\",");
|
|
string t_nodeId = item.second.node_id;
|
subJson.append(
|
"\"node_ip\":\"" + t_nodeId.substr(t_nodeId.find("@") + 1, t_nodeId.size() - t_nodeId.find("@")) +
|
"\",");
|
subJson.append("\"node_id\":\"" + item.second.node_id + "\"");
|
subJson.append("},");
|
json.append(subJson);
|
}
|
auto str = json.substr(0, json.size() - 1);
|
str.append("]}");
|
DBG(str);
|
return str;
|
} else {
|
ERR("resu is null");
|
// response->write(SimpleWeb::StatusCode::err_erlNodeIsNull, "{\"error\":\"err_erlNodeIsNull \"}");
|
return "{}";
|
}
|
}
|
|
string devHttpServer_c::modifyCluName(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
// bool ret = false;
|
|
if (reader.parse(content, value)) {
|
std::string cluster_id = value["cluster_id"].asString();
|
std::string cluster_name = value["cluster_name"].asString();
|
bool ret = false;
|
if (cluster_id.size() <= 0 || cluster_name.size() <= 0) {
|
return "{\"error\":\"参数错误,请检查!\"}";
|
}
|
|
ret = erlangDbTool->modifyCluName(cluster_id, cluster_name);
|
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查! \"}");
|
return "";
|
return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::createDatabase(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
// bool ret = false;
|
|
if (reader.parse(content, value)) {
|
std::string Uuid = value["uuid"].asString();
|
std::string TableType = value["TableType"].asString();
|
std::string TableName = value["TableName"].asString();
|
int SyncType = atoi(value["SyncType"].asCString());
|
std::string BwType = value["BwType"].asString();
|
std::string StartTime = value["StartTime"].asString();
|
std::string EndTime = value["EndTime"].asString();
|
|
std::string UploadFlag = value["IsSync"].asString();
|
UploadFlag = UploadFlag.empty() ? "0" : UploadFlag;
|
std::string CmpThreshold = value["threshold"].asString();
|
CmpThreshold = CmpThreshold.empty() ? "60" : CmpThreshold;
|
std::string Enabled = value["enabled"].asString();
|
Enabled = Enabled.empty() ? "1" : Enabled;
|
|
std::string createBy = value["createBy"].asString();
|
|
string str_uuid;
|
uuid_t t_uuid;
|
char str[36];
|
uuid_generate(t_uuid);
|
uuid_unparse(t_uuid, str);
|
str_uuid = str;
|
Uuid = Uuid.empty() ? str_uuid : Uuid;
|
// if (createBy == "analyDev") {
|
// Uuid = Uuid.empty() ? str_uuid : Uuid;
|
// } else if (createBy == "conCemter") {
|
// if (Uuid.empty()) {
|
// response->write(SimpleWeb::StatusCode::client_error_bad_request, "{\"error\":\"参数错误! \"}");
|
// return "";
|
// }
|
// }
|
|
|
bool ret = false;
|
FieldValues fieldValues;
|
fieldValues.insert(std::make_pair("uuid", Uuid));
|
fieldValues.insert(std::make_pair("tableName", TableName));
|
fieldValues.insert(std::make_pair("tableDesc", "ceshi"));
|
fieldValues.insert(std::make_pair("tableType", TableType));
|
fieldValues.insert(std::make_pair("bwType", BwType));
|
fieldValues.insert(std::make_pair("startTime", StartTime));
|
fieldValues.insert(std::make_pair("endTime", EndTime));
|
// #todo
|
fieldValues.insert(std::make_pair("create_by", createBy));
|
|
fieldValues.insert(std::make_pair("uploadFlag", UploadFlag));
|
fieldValues.insert(std::make_pair("cmpThreshold", CmpThreshold));
|
fieldValues.insert(std::make_pair("enabled", Enabled));
|
|
|
if (TableType == "person") {
|
if (SyncType == 1) {
|
//同步库
|
ret = erlangDbTool->createDatabase(Uuid, fieldValues);
|
} else if (SyncType == 0) {
|
TableName.insert(0, "lt_");
|
fieldValues["tableName"] = TableName;
|
//本地库
|
ret = m_SqliteFaceEncap.createTable(TableName, fieldValues);
|
}
|
} else if (TableType == "car") {
|
ERR(" not not_implemented");
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"类型错误,未实现! \"}");
|
return "";
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"类型错误,未识别! \"}");
|
return "";
|
}
|
|
|
//// #todo 上传。仅黑名单。
|
//// #TODO 根据createBy判断是否需要上传
|
// if (createBy == "analyDev" && BwType == "1") {
|
//// string &Uuid, string &TableName, string &SyncType, string &StartTime,string &EndTime,
|
//// string &UploadFlag, string &CmpThreshold, string &Enabled
|
// string str_SyncType(to_string(SyncType));
|
// UploadTaskToMonitorCenter(Uuid, TableName, str_SyncType, StartTime, EndTime, UploadFlag, CmpThreshold,
|
// Enabled);
|
// }
|
|
|
erlangDbTool->sendMessage();
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查! \"}");
|
return "";
|
return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::deleteDatabase(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
// bool ret = false;
|
|
if (reader.parse(content, value)) {
|
std::string uuid = value["uuid"].asString();
|
std::string TableType = value["TableType"].asString();
|
std::string TableName = value["TableName"].asString();
|
int SyncType = atoi(value["SyncType"].asCString());
|
|
bool ret = false;
|
if (SyncType == 1) {
|
//同步库
|
ret = erlangDbTool->deleteDatabase(TableType, TableName, SyncType);
|
} else if (SyncType == 0) {
|
//本地库
|
if (TableName.find("lt_") != 0) {
|
TableName.insert(0, "lt_");
|
}
|
ret = m_SqliteFaceEncap.deleteTable(TableName);
|
}
|
erlangDbTool->sendMessage();
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查! \"}");
|
return "";
|
return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::findAllDatabase(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在 \"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
|
auto resDB = erlangDbTool->findAllDatabase();
|
auto si = resDB.size();
|
if (resDB.size() > 0) {
|
// auto resType = erlangDbTool->findAllTypeInfo();
|
string json = "[";
|
for (auto &item : resDB) {
|
if (item.second.tableName.find("lt_") == 0) {
|
continue;
|
}
|
string subJson = "{ ";
|
subJson.append("\"uuid\":\"" + item.second.uuid + "\",");
|
subJson.append("\"tableName\":\"" + item.second.tableName + "\",");
|
subJson.append("\"tableType\":\"" + item.second.tableType + "\",");
|
// subJson.append("\"bwType\":\"" + resType[item.second.tableName].bwType + "\",");
|
subJson.append("\"bwType\":\"" + item.second.bwType + "\",");
|
//#todo modify
|
subJson.append("\"start_time\":\"" + item.second.startTime + "\",");
|
subJson.append("\"end_time\":\"" + item.second.endTime + "\"");
|
subJson.append("},");
|
json.append(subJson);
|
}
|
|
auto str = json.substr(0, json.size() - 1);
|
if (str.size() <= 1)
|
return "[]";
|
str.append("]");
|
return str;
|
} else {
|
// response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"size is 0 \"}");
|
// return "";
|
return "[]";
|
}
|
}
|
|
std::string devHttpServer_c::findLocalDatabase(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
string str_local = "lt_";
|
// auto resDB = erlangDbTool->findAllDatabase();
|
// auto si = resDB.size();
|
|
auto resDB = m_SqliteFaceEncap.getTableInfos();
|
|
if (resDB.size() > 0) {
|
string json = "[";
|
for (auto &item : resDB) {
|
string subJson = "{ ";
|
subJson.append("\"uuid\":\"" + item.uuid + "\",");
|
subJson.append("\"tableName\":\"" + item.tableName + "\",");
|
subJson.append("\"tableType\":\"" + item.tableType + "\",");
|
subJson.append("\"bwType\":\"" + item.bwType + "\",");
|
subJson.append("\"start_time\":\"" + item.startTime + "\",");
|
subJson.append("\"end_time\":\"" + item.endTime + "\"");
|
subJson.append("},");
|
json.append(subJson);
|
}
|
auto str = json.substr(0, json.size() - 1);
|
if (str.size() <= 1)
|
return "[]";
|
str.append("]");
|
return str;
|
} else {
|
// response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"size is 0\"}");
|
// return "";
|
return "[]";
|
}
|
}
|
|
std::string devHttpServer_c::addPerson(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
// DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string TableName = value["TableName"].asString();
|
std::string img_url = value["img_url"].asString();
|
auto tests = value["img_base64"].size();
|
auto ret = value["img_base64"].isString();
|
|
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);
|
}
|
} else {
|
std::string img_str = "http://";
|
if (fdfsClient.fastFds != nullptr) {
|
img_str.append(fdfsClient.fastFds->getIp() + "/").append(img_url);
|
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) {
|
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);
|
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found img\"}");
|
return "";
|
// return "{\"error\":\"not found img\"}";
|
}
|
|
thread::id pid = std::this_thread::get_id();
|
if (m_handleMap[pid] == nullptr) {
|
DBG("pid is " << pid);
|
m_handleMap[pid] = new CasiaFaceWrapperN;
|
}
|
CasiaFaceWrapperN *t_CasiaFaceWapper = m_handleMap[pid];
|
|
std::string feature_base64;
|
FaceImageN faceImage{image.cols, image.rows, image.step, image.data};
|
auto faceResults = t_CasiaFaceWapper->extractFace(faceImage);
|
|
if (faceResults.size() <= 0) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found face\"}");
|
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 = "";
|
bool ret_addPerson = false;
|
|
if (TableName.find("lt_") == 0) {
|
FieldValues fieldValues;
|
AddFaceData addFaceData;
|
addFaceData.feature.resize(faceResults[0].feature.size());
|
memcpy(addFaceData.feature.data(), faceResults[0].feature.data(), faceResults[0].feature.size());
|
|
//#todo uuid have value is update
|
if (strUUID.size() <= 0) {
|
// get Person id
|
|
strUUID = AppUtil::getPersonId(m_batch, m_SerialNumber);
|
addFaceData.uuid = strUUID;
|
addFaceData.faceUrl = img_url;
|
|
fieldValues.insert(std::make_pair("uuid", strUUID));
|
fieldValues.insert(std::make_pair("idCard", idcard));
|
auto t_id = m_SqliteFaceEncap.addFace(TableName, addFaceData, fieldValues);
|
ret_addPerson = t_id.size() > 0 ? true : false;
|
} else {
|
//#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 {
|
//#todo update data
|
// get Person id
|
strUUID = strUUID.size() > 0 ? strUUID : AppUtil::getPersonId(m_batch, m_SerialNumber);
|
ret_addPerson = erlangDbTool->addPerson(strUUID, TableName, feature_base64, img_url, idcard);
|
}
|
|
if (ret_addPerson && strUUID.size() > 0) {
|
std::string str_result = std::string("{\"uuid\":").append(
|
"\"" + strUUID + "\",\"img_url\":\"" + img_url + "\"}");
|
// usleep(100);
|
erlangDbTool->sendMessage();
|
//todo send person to backServer
|
HttpRequestWithCrul m_requestWithCrul;
|
|
std::thread sendPerson([&](std::string parm_uuid, std::string parm_img_url, std::string parm_idcard,
|
std::string parm_fea) {
|
Json::Value perInfos;
|
Json::Value perInfo;
|
// #todo get string from config.json file
|
// get
|
perInfo["id"] = parm_uuid;
|
perInfo["distributionIds"] = m_cluster_id;
|
perInfo["distributionNames"] = m_cluster_name;
|
auto rec = db_c.searchConfigTableWithinServerInfo();
|
perInfo["deviceId"] = rec.dev_id.toStdString();
|
perInfo["photos"] = parm_img_url;
|
// perInfo["featureBase"] = feature_base64;
|
perInfo["featureBase64"] = parm_fea;
|
perInfo["cardId"] = parm_idcard;
|
perInfos.append(perInfo);
|
|
std::string str_serIp = GET_STR_CONFIG("mainServerIp");
|
std::string str_serPort = GET_STR_CONFIG("mainServerPort");
|
|
// string sendUrl = "192.168.1.203:3697/addPerson/uploadToTemporary";
|
string sendUrl = str_serIp;
|
sendUrl.append(":").append(str_serPort).append("/addPerson/uploadToTemporary");
|
string postParams = perInfos.toStyledString();
|
string str_addRes;
|
|
m_requestWithCrul.curl_post_req(sendUrl, postParams, str_addRes);
|
}, strUUID, img_url, idcard, feature_base64);
|
sendPerson.detach();
|
|
return str_result;
|
} else {
|
std::string str_result = std::string("{\"error\":\"addPerson error\"}");
|
return str_result;
|
}
|
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
// return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::loadFaceFeaData(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string TableName = value["TableName"].asString();
|
|
|
if (TableName.find("lt_") == 0) {
|
auto t_resDB = m_SqliteFaceEncap.getFacesFromTable(TableName);
|
auto t_faceInfoCache = m_SqliteFaceEncap.getFaceInfoFromTable(TableName);
|
|
auto &resDB = *t_resDB;
|
if (resDB.size() > 0) {
|
string json = "[";
|
for (auto &item : resDB) {
|
string subJson = "{ ";
|
subJson.append("\"uuid\":\"" + item.second.uuid + "\",");
|
subJson.append("\"tableName\":\"" + TableName + "\",");
|
subJson.append("\"idcard\":\"" + t_faceInfoCache[item.second.uuid].idCard + "\",");
|
subJson.append("\"imgUrl\":\"" + item.second.faceurl + "\"");
|
// subJson.append("\"feature\":\"" + item.second.feature + "\",");
|
//#todo modifysvn upda svn comm
|
// subJson.append("\"start_time\":\"" + item.second.create_time + "\",");
|
// subJson.append("\"end_time\":\"" + item.second.update_time + "\"");
|
subJson.append("},");
|
json.append(subJson);
|
}
|
auto str = json.substr(0, json.size() - 1);
|
str.append("]");
|
return str;
|
}
|
} else {
|
auto resDB = erlangDbTool->loadFaceFeaData2(TableName);
|
if (resDB.size() > 0) {
|
string json = "[";
|
for (auto &item : resDB) {
|
string subJson = "{ ";
|
subJson.append("\"uuid\":\"" + item.second.id + "\",");
|
subJson.append("\"tableName\":\"" + TableName + "\",");
|
subJson.append("\"idcard\":\"" + item.second.idcard + "\",");
|
subJson.append("\"imgUrl\":\"" + item.second.img + "\"");
|
// subJson.append("\"feature\":\"" + item.second.feature + "\",");
|
//#todo modifysvn upda svn comm
|
// subJson.append("\"start_time\":\"" + item.second.create_time + "\",");
|
// subJson.append("\"end_time\":\"" + item.second.update_time + "\"");
|
subJson.append("},");
|
json.append(subJson);
|
}
|
auto str = json.substr(0, json.size() - 1);
|
str.append("]");
|
return str;
|
}
|
}
|
|
|
// response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"size is 0\"}");
|
// return "";
|
return "[]";
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
// return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::updateDatabase(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
// bool ret = false;
|
|
if (reader.parse(content, value)) {
|
std::string Uuid = value["uuid"].asString();
|
std::string TableType = value["TableType"].asString();
|
std::string TableName = value["TableName"].asString();
|
int SyncType = atoi(value["SyncType"].asCString());
|
std::string BwType = value["BwType"].asString();
|
std::string StartTime = value["StartTime"].asString();
|
std::string EndTime = value["EndTime"].asString();
|
//#更新底库管理表
|
FieldValues fieldValues;
|
fieldValues.insert(std::make_pair("uuid", Uuid));
|
fieldValues.insert(std::make_pair("tableName", TableName));
|
// fieldValues.insert(std::make_pair("tableDesc", "ceshi2"));
|
fieldValues.insert(std::make_pair("tableType", TableType));
|
fieldValues.insert(std::make_pair("bwType", BwType));
|
fieldValues.insert(std::make_pair("startTime", StartTime));
|
fieldValues.insert(std::make_pair("endTime", EndTime));
|
// fieldValues.insert(std::make_pair("create_by", "who"));
|
bool ret = false;
|
if (SyncType == 1) {
|
//同步库
|
ret = erlangDbTool->updateDatabase("sys_o_tables", fieldValues);
|
} else if (SyncType == 0) {
|
//本地库
|
if (TableName.find("lt_") != 0) {
|
TableName.insert(0, "lt_");
|
}
|
fieldValues.insert(std::make_pair("tableName", TableName));
|
|
ret = m_SqliteFaceEncap.updateTable("sys_o_tables", fieldValues);
|
}
|
|
erlangDbTool->sendMessage();
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string devHttpServer_c::delPerson(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string TableName = value["TableName"].asString();
|
std::string strUUID = value["uuid"].asString();
|
|
bool ret = false;
|
if (TableName.find("lt_") == 0) {
|
ret = m_SqliteFaceEncap.deleteFace(TableName, strUUID);
|
} else {
|
ret = erlangDbTool->delPerson(strUUID, TableName);
|
}
|
|
erlangDbTool->sendMessage();
|
std::string str_result = std::string("{\"result\":").append("\"" + std::to_string(ret) + "\"}");
|
return str_result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
// return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
|
std::string devHttpServer_c::getAlarmImageByPicDateAndDevId(const std::string &picDate, const std::string &devId,
|
PResponse &response) {
|
try {
|
if (!devId.empty() && !picDate.empty()) {
|
std::string videoPath;
|
qint64 sub;
|
std::string path = getVideoPathByPicDate(picDate, devId, sub);
|
|
if (path.empty()) {
|
ERR("{\"error\":\"not find path\"}");
|
return "{\"error\":\"未查到视频路径\"}";
|
}
|
DBG("path=" << path);
|
videoPath.clear();
|
videoPath = path;
|
|
|
|
// sub = (dt.toMSecsSinceEpoch() - dtFile.toMSecsSinceEpoch());
|
//#yanchi buchong
|
// sub = sub > 3000 ? sub - 3000 : 0000;
|
//shijian yuejie buchang
|
// sub = sub < 0 ? 0000 : sub;
|
int haomiao = (sub % 1000) > 50 ? ((sub % 1000) - 50) : 0;
|
sub /= 1000;
|
int m = sub;
|
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("输入数值太大");
|
DBG("ch_time" << ch_time);
|
std::string str_time(ch_time);
|
//#todo 按照时间命名
|
std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
|
|
std::string cmd_getVideoFileTime(
|
" ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
|
|
std::string str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
|
|
|
if (str_time > str_tmpTime) {
|
|
//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\"}";
|
}
|
|
std::string cmd("ffmpeg -ss " + str_time + " -i '" + videoPath + "' -y '" + str_imgName + "'");
|
DBG(cmd);
|
system(cmd.c_str());
|
|
cv::Mat img = cv::imread(str_imgName);
|
if (img.empty()) {
|
ERR("{\"error\":\"Video File error\"}");
|
return "{\"error\":\"视频文件错误\"}";
|
}
|
std::vector<unsigned char> buffer;
|
CvUtil::cvMat2Buffer(img, buffer);
|
std::string 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 {
|
std::string str_tmp_cmd("rm -f '" + str_imgName + "'");
|
system(str_tmp_cmd.c_str());
|
img_url.append(t_strImg);
|
img_url.clear();
|
img_url = t_strImg;
|
// img_url.append("/").append(t_strImg);
|
}
|
}
|
fdfsClient.rwLock.unlock();
|
std::string result("{\"img_url\":\"" + img_url + "\"}");
|
return result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
}
|
}
|
catch (std::exception ex) {
|
std::string message = "{\"error\":\"异常错误!";
|
message.append(const_cast<char *>(ex.what())).append("\"}");
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
|
return "";
|
}
|
}
|
|
|
std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
|
PResponse &response) {
|
INFO("ip:" << ip << "; port:" << port << "content: " << content);
|
Json::Reader reader;
|
Json::Value value;
|
try {
|
if (reader.parse(content, value)) {
|
std::string devId = value["videoNum"].asString();
|
std::string picDate = value["picDate"].asString();
|
std::string imgKey = value["imgKey"].asString();
|
//兼容旧版本
|
if (imgKey == "undefined" || imgKey.empty()) {
|
DBG("getAlarmImageByPicDateAndDevId " << imgKey);
|
return getAlarmImageByPicDateAndDevId(picDate, devId, response);
|
} else {
|
DBG("getAlarmImageByImageKeyAndDevId " << imgKey);
|
return getAlarmImageByImageKeyAndDevId(imgKey, devId, response);
|
}
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
ERR("ImageURL:传输错误,请检查");
|
return "";
|
}
|
}
|
catch (std::exception ex) {
|
std::string message = "{\"error\":\"异常错误!";
|
message.append(const_cast<char *>(ex.what())).append("\"}");
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
|
ERR("ImageURL:异常错误 " << ex.what());
|
return "";
|
}
|
}
|
|
|
std::string devHttpServer_c::getAlarmImageByImageKeyAndDevId(const std::string &imgKey, const std::string &devId,
|
PResponse &response) {
|
try {
|
if (!devId.empty() && !imgKey.empty()) {
|
std::string videoPath;
|
std::string path = getVideoPathByImgKey(imgKey, devId);
|
if (path.empty()) {
|
ERR("Not Find Path: " << path);
|
return "{\"error\":\"未查到视频路径\"}";
|
}
|
videoPath.clear();
|
videoPath = path;
|
|
VideoName_s_t videoSt = VideoName_s_t::fromString(path);
|
ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
|
|
//#todo 按照时间命名
|
std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
|
|
auto frameIdDiff = imgSt.m_frameId - videoSt.m_startFrameId;
|
char selectExpBuff[32] = {0};
|
std::string strSelectTemplate = R"#( -vf "select=eq(n\,%d)")#";
|
sprintf(selectExpBuff, strSelectTemplate.c_str(), frameIdDiff - 1);
|
if (videoSt.Valid() && imgSt.Valid()) {
|
std::string cmd("ffmpeg -i '" + videoPath + "'" + std::string(selectExpBuff) + " -vframes 1" + " -y '" +
|
str_imgName + "'");
|
INFO("Video To Image Cmd: " << cmd);
|
system(cmd.c_str());
|
} else {
|
ERR("Parse Video and Image Failed Path: " << path << " ImageId: " << imgKey);
|
return "{\"error\":\"未查到视频路径\"}";
|
}
|
|
cv::Mat img = cv::imread(str_imgName);
|
if (img.empty()) {
|
ERR("{\"error\":\"Video File error\"}");
|
return "{\"error\":\"视频文件错误\"}";
|
}
|
|
std::vector<unsigned char> buffer;
|
CvUtil::cvMat2Buffer(img, buffer);
|
std::string img_url = "http://";
|
fdfsClient.rwLock.rdlock();
|
if (fdfsClient.fastFds != nullptr) {
|
std::string t_strImg = "";
|
if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
|
img_url = "upload image fail";
|
ERR("Upload Image Failed " << str_imgName);
|
} else {
|
std::string str_tmp_cmd("rm -f '" + str_imgName + "'");
|
system(str_tmp_cmd.c_str());
|
img_url.append(t_strImg);
|
img_url.clear();
|
img_url = t_strImg;
|
}
|
}
|
fdfsClient.rwLock.unlock();
|
std::string result("{\"img_url\":\"" + img_url + "\"}");
|
INFO("ImageURL:" << img_url);
|
return result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
ERR("ImageURL:传输错误,请检查");
|
return "";
|
}
|
}
|
catch (std::exception ex) {
|
std::string message = "{\"error\":\"异常错误!";
|
message.append(const_cast<char *>(ex.what())).append("\"}");
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, message);
|
ERR("ImageURL:异常错误 " << ex.what());
|
return "";
|
}
|
}
|
|
|
std::string
|
devHttpServer_c::getRecordVideoPath(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
|
Json::Reader reader;
|
Json::Value value;
|
|
INFO("REQ From: " << ip << ":" << port << " Content:" << content);
|
if (reader.parse(content, value)) {
|
std::string devId = value["videoNum"].asString();
|
std::string picDate = value["picDate"].asString();
|
std::string imgKey = value["imgKey"].asString();
|
std::string path;
|
|
//兼容旧版本
|
if (imgKey == "undefined" || imgKey.empty()) {
|
qint64 sub;
|
path = getVideoPathByPicDate(picDate, devId, sub);
|
} else {
|
path = getVideoPathByImgKey(imgKey, devId);
|
}
|
//std::string path = getVideoPathByImgKey(imgKey, devId, sub);
|
ERR("VideoNum: " << devId << " PicDate: " << picDate << " imgKey: " << imgKey);
|
if (path.empty()) {
|
std::string strRsp = "{\"ret_status\":\"内容有误,请检查!\"}";
|
ERR("RSP:" << strRsp);
|
return strRsp;
|
} else {
|
std::string result = "{\"file_path\":\"" + path + "\"}";
|
INFO("RSP:" << result);
|
return result;
|
}
|
} else {
|
std::string strRsp = "{\"ret_status\":\"传输错误,请检查!\"}";
|
ERR("RSP:" << strRsp);
|
return strRsp;
|
}
|
}
|
|
|
std::string devHttpServer_c::findDevId(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
|
Record_Config rc = db_c.searchConfigTableWithinServerInfo();
|
|
Json::Value value;
|
value["dev_id"] = rc.dev_id.toStdString();
|
value["dev_name"] = rc.dev_name.toStdString();
|
|
return value.toStyledString();
|
|
}
|
|
std::string devHttpServer_c::editDevName(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string dev_name = value["dev_name"].asString();
|
if (dev_name.empty()) {
|
return "{\"ret_status\":\"内容有误,请检查!\"}";
|
}
|
|
if (db_c.updateDevNameConfigTable(QString::fromStdString(dev_name))) {
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "{\"ret_status\":\"内容有误,请检查!\"}";
|
}
|
|
} else {
|
return "{\"ret_status\":\"传输错误,请检查!\"}";
|
}
|
|
}
|
|
|
std::string devHttpServer_c::editDevId(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
//DSVAD010120181114
|
int dev_batch = value["dev_batch"].asInt();
|
int dev_sequence = value["dev_sequence"].asInt();
|
if (createDevId(dev_batch, dev_sequence)) {
|
return "{\"ret_status\": \"ok_ack\"}";
|
} else {
|
return "{\"ret_status\":\"传输错误,请检查!\"}";
|
}
|
|
} else {
|
return "{\"ret_status\":\"传输错误,请检查!\"}";
|
}
|
|
}
|
|
bool devHttpServer_c::createDevId(const int &dev_batch, const int &dev_sequence) {
|
// std::string dev_id="DSVAD";
|
char buf[12] = {0};
|
char dev_id[17] = {0};
|
|
time_t cur = time(nullptr);
|
|
strftime(buf, 12, "%Y%m%d", localtime(&cur));
|
sprintf(dev_id, "%s%02d%02d%s", "DSVAD", dev_batch, dev_sequence, buf);
|
|
|
if (strlen(dev_id) != 17) {
|
return false;
|
}
|
|
appConfig.setStringProperty("DEV_ID", dev_id);
|
appConfig.save();
|
//std::cout<<dev_id<<std::endl;
|
return true;
|
}
|
|
|
std::string devHttpServer_c::getVideoPathByPicDate(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('/');
|
}
|
|
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) + "/");
|
|
|
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) {
|
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;
|
|
}
|
|
|
std::string devHttpServer_c::GetVideoNameByImgKey(const std::string &imgKey, const std::string &strPath) {
|
static std::mutex g_mutex;
|
std::lock_guard<std::mutex> lock(g_mutex);
|
std::vector<std::string> vec = forEachFileByImgKey(strPath);
|
ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
|
if (!imgSt.Valid()) {
|
ERR("ParseImageName Failed : " << imgKey);
|
return "";
|
}
|
std::vector<VideoName_s_t> videoStVec;
|
for (const auto &item : vec) {
|
auto videoParseResult = VideoName_s_t::fromString(item);
|
if (videoParseResult.Valid()) {
|
if (videoParseResult.m_startFrameId <= imgSt.m_frameId &&
|
imgSt.m_frameId <= videoParseResult.m_endFrameId) {
|
auto imgTm = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
|
auto videoTm = AppUtil::ParseFromHypenTimeStr(videoParseResult.m_timeStamp);
|
if (AppUtil::IsRightAfterLeft(imgTm, videoTm)) {
|
videoStVec.emplace_back(videoParseResult);
|
INFO("Image " << imgKey << " Video: " << item << " Match");
|
} else {
|
ERR("Image " << imgKey << " Video: " << item << " Not Match");
|
}
|
} else {
|
ERR("ImageID: " << imgSt.m_frameId << " VideoRange: " << videoParseResult.m_startFrameId << " , "
|
<< videoParseResult.m_endFrameId);
|
}
|
|
} else {
|
ERR("VideoName : " << item << " Parse Failed");
|
}
|
}
|
|
if (videoStVec.size() >= 1) {
|
std::string strVideoName = strPath + videoStVec[0].ToVideoName();
|
INFO("ImageName: " << imgKey << " SingleMatchVideo: " << strVideoName);
|
return strVideoName;
|
} else {
|
ERR("ImageName: " << imgKey << " MatchVideoCount: " << videoStVec.size());
|
for (auto &item:vec) {
|
ERR("VideoName: " << item);
|
}
|
return "";
|
}
|
}
|
|
//新的根据图片名称获取路径的方法
|
std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId) {
|
INFO("GetVideoFor: " << imgKey << " CamID:" << camId);
|
ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
|
|
struct tm imgTime = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp);
|
char curFolder[128] = {0};
|
// 201901/26/2019012614 ---- 201901/26/2019012615 {年月}/{日}/{年月日时}/
|
sprintf(curFolder, "%04d%02d/%02d/%04d%02d%02d%02d/", imgTime.tm_year + 1900, imgTime.tm_mon + 1,
|
imgTime.tm_mday,
|
imgTime.tm_year + 1900, imgTime.tm_mon + 1, imgTime.tm_mday, imgTime.tm_hour);
|
std::string t_FilePath = appConfig.getStringProperty("cutPath");
|
std::string videoPath = t_FilePath + "/" + camId + "/" + std::string(curFolder);
|
return GetVideoNameByImgKey(imgKey, videoPath);
|
}
|
|
|
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/,//");
|
|
// 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::vector<std::string> devHttpServer_c::forEachFileByImgKey(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 != "..") {
|
v.push_back(filename);
|
}
|
|
}
|
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);
|
// DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
string strUUID = value["uuid"].asString();
|
auto perlists = value["personList"];
|
|
std::vector<SyncDB::AddPersonInfo> tmpPers;
|
// int lsize = perlists.size();
|
for (auto &item : perlists) {
|
SyncDB::AddPersonInfo addPersonInfo;
|
addPersonInfo.personid = item["personId"].asString();
|
addPersonInfo.idcard = item["idcard"].asString();
|
addPersonInfo.personPic = item["personPic"].asString();
|
addPersonInfo.feature = item["feature"].asString();
|
tmpPers.push_back(addPersonInfo);
|
}
|
|
auto ret_addPersons = erlangDbTool->addPersons(strUUID, tmpPers);
|
|
std::string str_result;
|
if (ret_addPersons.size() > 0) {
|
str_result = "[";
|
for (auto &item : ret_addPersons) {
|
string subJson = "{ ";
|
subJson.append("\"personId\":\"" + item.PersonId + "\",");
|
subJson.append("\"result\":\"" + item.Result + "\",");
|
subJson.append("\"msg\":\"" + item.msg + "\"");
|
subJson.append("},");
|
str_result.append(subJson);
|
}
|
auto str = str_result.substr(0, str_result.size() - 1);
|
str_result.swap(str.append("]"));
|
erlangDbTool->sendMessage();
|
} else {
|
str_result = "[]";
|
}
|
erlangDbTool->sendMessage();
|
return str_result;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
// return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string
|
devHttpServer_c::personIsExists(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string str_res;
|
try {
|
string strUUID = value["personId"].asString();
|
//#todo 连接失败的判断.
|
auto ret_resPerEits = erlangDbTool->personIsExistOnClu(strUUID);
|
std::string str_result = "[";
|
if (ret_resPerEits.size() > 0) {
|
for (auto &item : ret_resPerEits) {
|
// tableName ,uuid 无此人是id为null
|
if (item.uuid == "null") {
|
continue;
|
}
|
string subJson = "{ ";
|
subJson.append("\"tableName\":\"" + item.tableName + "\",");
|
subJson.append("\"uuid\":\"" + item.tableUuid + "\"");
|
subJson.append("},");
|
str_result.append(subJson);
|
}
|
auto str = str_result.substr(0, str_result.size() - 1);
|
if (str.size() <= 1) {
|
str_result = "[]";
|
} else {
|
str_result.swap(str.append("]"));
|
}
|
} else {
|
str_result = "[]";
|
}
|
if (str_result == "[]") {
|
str_res = "{\"result\":\"0\",\"msg\":\"success\",\"existDataBase\":[]}";
|
} else {
|
str_res = "{\"result\":\"1\",\"msg\":\"success\",\"existDataBase\":";
|
str_res.append(str_result).append("}");
|
}
|
} catch (std::exception ex) {
|
str_res = "{\"result\":\"-1\",\"msg\":\"error\",\"existDataBase\":[]}";
|
ERR(ex.what());
|
}
|
return str_res;
|
} else {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
|
return "";
|
// return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
std::string
|
devHttpServer_c::updatePersonByOldId(std::string ip, unsigned int port, std::string content, PResponse &response) {
|
DBG("ip:" << ip << "; port:" << port);
|
DBG("content: " << content);
|
if (erlangDbTool == nullptr) {
|
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"节点不存在\"}");
|
return "";
|
// return "{\"error\":\"erlang is null\"}";
|
}
|
|
Json::Reader reader;
|
Json::Value value;
|
|
if (reader.parse(content, value)) {
|
std::string str_res;
|
try {
|
string newPerId = value["newPerId"].asString();
|
string idcard = value["idcard"].asString();
|
string perPicUrl = value["perPicUrl"].asString();
|
string oldId = value["oldId"].asString();
|
string perFea = value["feature"].asString();
|
//#todo 连接失败的判断.
|
auto ret_resUpdPersRet = erlangDbTool->singlePersonUpdate(newPerId, oldId, idcard, perPicUrl, perFea);
|
std::string str_result = "[";
|
int notexist_conNum = 0;
|
if (ret_resUpdPersRet.size() > 0) {
|
for (auto &item : ret_resUpdPersRet) {
|
// tableName ,uuid 无此人是id为null
|
if (item.result == "true") {
|
continue;
|
}
|
if (item.result == "notexist") {
|
notexist_conNum++;
|
continue;
|
}
|
|
string subJson = "{ ";
|
subJson.append("\"tableName\":\"" + item.tableName + "\",");
|
subJson.append("\"uuid\":\"" + item.tableUuid + "\"");
|
subJson.append("},");
|
str_result.append(subJson);
|
}
|
auto str = str_result.substr(0, str_result.size() - 1);
|
if (str.size() <= 1) {
|
str_result = "[]";
|
} else {
|
str_result.swap(str.append("]"));
|
}
|
} else {
|
str_result = "error";
|
}
|
if (str_result == "[]") {
|
if (notexist_conNum == ret_resUpdPersRet.size()) {
|
str_res = "{\"result\":\"0\",\"msg\":\"success\",\"existDataBase\":[]}";
|
} else {
|
str_res = "{\"result\":\"1\",\"msg\":\"success\",\"existDataBase\":[]}";
|
}
|
} else if (str_result == "error") {
|
str_res = "{\"result\":\"-1\",\"msg\":\"error\",\"existDataBase\":[]}";
|
} else {
|
str_res = "{\"result\":\"-1\",\"msg\":\"success\",\"existDataBase\":";
|
str_res.append(str_result).append("}");
|
}
|
} catch (std::exception ex) {
|
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\":\"传输错误,请检查!\"}";
|
}
|
}
|
|
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);//摄像机id 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 + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " +
|
str_imgName);
|
// 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;
|
db_c.updateCamDevSnapshot(QString::fromStdString(ip), QString::fromStdString(strImgUrl));
|
|
return result.toStyledString();
|
|
|
} else {
|
return "{\"error\":\"传输错误,请检查!\"}";
|
}
|
}
|