Commit abb7cb7b by 郭峰

Revert "Merge branch 'feature-1007488' into 'master'"

This reverts merge request !30
parent 25af28ce
......@@ -153,7 +153,7 @@ void* AlgorithmTaskManage::schedulingAlgorithm(int scheType) {
} else if (scheType == 0x03) {
return schedulingAlgorithmTemplate(faceReconitionHandles, mtxFace);
} else {
qDebug() << "参数错误";
qInfo() << "参数错误";
return nullptr;
}
}
......@@ -170,10 +170,10 @@ void AlgorithmTaskManage::executeFindDoesItExistEmployee(const cv::Mat &source,s
if (selectedFaceReconition!=nullptr && !selectedFaceReconition->getImageChanged()) {
selectedFaceReconition->setIsRunning(true);
// 调用选定对象的doesItExistEmployee函数
qDebug() << "人脸识别算法抢到===>sn"<<sSn<<selectedFaceReconition;
selectedFaceReconition->doesItExistEmployee(sSn,source, faces);
qInfo() << "人脸识别算法抢到===>sn"<<sSn<<selectedFaceReconition;
selectedFaceReconition->doesItExistEmployee(source, faces);
} else {
qDebug() << "没有可用的selectedFaceReconition对象可以调度";
qInfo() << "没有可用的selectedFaceReconition对象可以调度";
return ;
}
}
......@@ -192,10 +192,10 @@ void AlgorithmTaskManage::executeFindlicensePlateNumber(const cv::Mat &source, Q
if (selectedLicensePlate!=nullptr) {
selectedLicensePlate->setIsRunning(true);
// 调用选定对象的findHuManCar函数
qDebug() << "车牌调度算法抢到===>sn"<<sSn<<selectedLicensePlate;
qInfo() << "车牌调度算法抢到===>sn"<<sSn<<selectedLicensePlate;
selectedLicensePlate->licensePlateNumber(source, lpNumber,plate, currentTime);
} else {
qDebug() << "没有可用的selectedLicensePlate对象可以调度";
qInfo() << "没有可用的selectedLicensePlate对象可以调度";
return ;
}
}
......@@ -214,11 +214,11 @@ int AlgorithmTaskManage::executeFindHuManCar(const cv::Mat &source, int res,
selectedHumanDetection->setIsRunning(true);
// 调用选定对象的findHuManCar函数
qDebug() << "人形调度算法抢到===>sn"<<sSn<<"res"<<selectedHumanDetection;
int detectionResult = selectedHumanDetection->findHuManCar(source, res,resMap, sSn,heightReference,currentPlate);
qInfo() << "人形调度算法抢到===>sn"<<sSn<<"res"<<selectedHumanDetection;
int detectionResult = selectedHumanDetection->findHuManCar(source, res,resMap, heightReference,currentPlate);
return detectionResult;
} else {
qDebug() << "没有可用的HumanDetection对象可以调度";
qInfo() << "没有可用的HumanDetection对象可以调度";
return -2;
}
}
......@@ -74,7 +74,7 @@ int CameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort, QString sUserName
loginParam->nCnnType=EDEV_CNN_TYPE_AUTO;
int loginResult =XSDK_DevLoginSyn(loginParam,nTimeout);
if(loginResult<0){
qInfo() << QString("SN(%1): 登录设备失败").arg(sSn);;
qInfo() << "登录设备失败";
return loginResult;
}
this->hDevice=loginResult;
......@@ -270,34 +270,32 @@ void CameraHandle::cameraParameterUpdate(vides_data::responseConfig &cloudConfig
}
}
if(this->face_frequency!=cloudConfig.faceConfig.faceFrequency){
this->face_frequency=cloudConfig.faceConfig.faceFrequency;
}
float carConfidenceMax=cloudConfig.licensePlateConfig.carConfidenceMax;
float carConfidenceMin=cloudConfig.licensePlateConfig.carConfidenceMin;
this->setCarConfidenceMaxAndMin(carConfidenceMax,carConfidenceMin);
}
void CameraHandle::initFaceFrequency(uint64 face_frequency){
this->face_frequency=face_frequency;
}
void CameraHandle::initSdkRealTimeDevSnapSyn(int syn_timer,uint64 face_frequency)
{
connect(dev_snap_syn_timer, &QTimer::timeout, this, [this]() {
this->sdkRealTimeDevSnapSyn();
void CameraHandle::initSdkRealTimeDevSnapSyn(int hDevice,int syn_timer,uint64 face_frequency) {
connect(dev_snap_syn_timer, &QTimer::timeout, this, [this,hDevice]() {
this->sdkRealTimeDevSnapSyn(hDevice);
},Qt::QueuedConnection);
this->face_frequency=face_frequency;
dev_snap_syn_timer->start(syn_timer);
}
void CameraHandle::sdkRealTimeDevSnapSyn() {
void CameraHandle::sdkRealTimeDevSnapSyn(int hDevice) {
QThreadPool* threadPool = QThreadPool::globalInstance();
auto taskSyn = [this]() {
sdkDevSnapSyn(this->hDevice, this->channel);
auto taskSyn = [this, hDevice]() {
sdkDevSnapSyn(hDevice, this->channel);
};
if (threadPool->activeThreadCount() >= threadPool->maxThreadCount()) {
qInfo() << QString("SN(%1): 任务积压,跳过本次执行").arg(sSn);
qInfo() << "任务积压,跳过本次执行";
return;
}
auto taskRunnable = new TaskRunnable(taskSyn, hDevice, this->channel, RunFunction::SdkDevSnapSyn);
......@@ -370,7 +368,7 @@ void CameraHandle::sdkDownloadFileByTime(XSDK_HANDLE hDevice,int id,
}
int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
if (!semaphore.tryAcquire()) {
qInfo() << QString("SN(%1): sdkDevSnapSyn:正在执行线程").arg(sSn);
qInfo() <<sSn<<"sdkDevSnapSyn:正在执行线程";
return -1;
}
ScopeSemaphoreExit guard([this]() {
......@@ -397,7 +395,7 @@ int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
cv::Mat image;
MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
qint64 currentTime= QDateTime::currentSecsSinceEpoch();
mediaFaceImage->FaceImageCallBack(hObject,this->channel,image,sSn);
mediaFaceImage->FaceImageCallBack(hObject,this->channel,image);
if (image.empty())
{
......@@ -415,11 +413,11 @@ int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
if(hDevice<=0){
qInfo() << QString("SN(%1): 相机断线").arg(sSn);
qInfo() << "相机断线";
return;
}
if (!semaphore.tryAcquire()) {
qInfo() << QString("SN(%1): callbackFunction:正在执行线程").arg(sSn);;
qInfo() << sSn<<"callbackFunction:正在执行线程";
return ;
}
ScopeSemaphoreExit guard([this]() {
......@@ -428,14 +426,17 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
cv::Mat image;
MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
qint64 currentTime= QDateTime::currentSecsSinceEpoch();
int ret=mediaFaceImage->FaceImageCallBack(hDevice,nChannel, image,sSn);
int ret=mediaFaceImage->FaceImageCallBack(hDevice,nChannel, image);
if (ret < 0) {
offlineCount++; // 累加计数器
qInfo() << "offlineCount: " << loginParam->sDevId<<offlineCount;
if (offlineCount >= 3) { // 判断是否连续3次返回0
qInfo() <<QString("SN(%1): 设备离线").arg(sSn);
qInfo() << "设备离线";
QString ip=QString::fromUtf8(loginParam->sDevId);
bool is_ping=vides_data::pingAddress(ip);
qDebug() << sSn<<":ping 的结果"<<is_ping;
qInfo() << "ping 的结果"<<is_ping;
if(is_ping){
deviceReboot();
......@@ -456,12 +457,11 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
}
if (image.empty())
{
qInfo()<<QString("SN(%1): Failed to read the image").arg(sSn);
qInfo() << "Failed to read the image";
return ;
}
if (image.rows <= 0 || image.cols <= 0 || image.channels() <= 0) {
qInfo()<<QString("SN(%1): 图像尺寸或通道数不正确,需排查原因").arg(sSn);
qInfo() << "图像尺寸或通道数不正确,需排查原因";
return ;
}
updateImage(image, currentTime);
......@@ -483,9 +483,8 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
}
}
qInfo() << QString("SN(%1): 最新车牌%2,当前区域车牌:%3").arg(sSn).arg(newInfo.getLicensePlate()).arg(park->getCurrentPlate().getLicensePlate());
qInfo() << QString("SN(%1): 区域:%2,数量:%3").arg(sSn).arg(park->getSpaceIndex()).arg(count);
qInfo() << "最新车牌" << newInfo.getLicensePlate() << "区域当前车牌" << park->getCurrentPlate().getLicensePlate();
qInfo() << "不同的区域:" << park->getSpaceIndex() << ",数量:" << count;
if (count>= 3) {
//第一次进场 当前车牌就是进来这个,老车牌就是空
if(park->getCurrentPlate().getLicensePlate().length()<=0){
......@@ -500,17 +499,17 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
std::map<int,int>resMap;
int car_size =algorithmTaskManage.executeFindHuManCar(frame,0x01,currentPlates,resMap,sSn,heightReference);
qInfo()<<QString("SN(%1): 当前车形数量:%2").arg(sSn).arg(car_size);
qInfo()<<sSn<<":"<<"当前车形数量:"<<car_size;
if (car_size <= 0 && car_size!=-2) {
qInfo()<<QString("SN(%1): 区域:%2出场").arg(sSn).arg(park->getSpaceIndex());
qInfo() << sSn<<"区域:"<<park->getSpaceIndex() << ": 出场:";
//如果有车辆检测到并且不在停车区域内部,视为出场
park->setCurrentPlate(newInfo);
result = Exit;
}else {
// 没有车辆或车辆在停车区域内部,移除队列
park->removeNoQueue();
qDebug()<<QString("SN(%1): no出场::%2").arg(sSn).arg(car_size);
qInfo() << sSn << ": no出场:" << car_size;
}
}else{
//当前不为空,新车,新车入场,老车出场
......@@ -602,8 +601,8 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
int faSize =0;
std::vector<vides_data::ParkingArea> currentPlates;
int uniforms=0x00;
qInfo()<<"updateImage"<<algorithmPermissions;
std::map<int,int>resMap;
qInfo()<<QString("SN(%1): 相机算法:%2").arg(sSn).arg(algorithmPermissions);
if ((algorithmPermissions & 0x01<<3) != 0) {
//穿工服算法
if ((algorithmPermissions & 0x01<<2) != 0) {
......@@ -621,20 +620,17 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
}
}
if(uniforms==-2 || faSize==-2){
qInfo()<<QString("SN(%1): 没有可用的HumanDetection对象可以调度").arg(sSn);
qInfo() << "没有可用的HumanDetection对象可以调度";
return ;
}
QPoint point_info(faSize,uniforms);
if(isChanged(point_info,faceMapWorker)){
qInfo()<<QString("SN(%1): 人形计算器:%2").arg(sSn).arg(faceCount);
qInfo()<<QString("SN(%1): 人形频率:%2").arg(sSn).arg(face_frequency);
if(faceCount.load(std::memory_order_relaxed)%face_frequency==0){
int worker=0x00;
if ((algorithmPermissions & 0x01<<2) != 0) {
worker = (faSize - uniforms > 0) ? (faSize - uniforms) : 0;
}
qInfo()<<"工作人数==>"<<worker;
vides_data::response* resp=httpService.httpPostFacePopulation(imgs,faSize,worker,sSn,currentTime);
if (resp->code!= 0) {
......@@ -643,17 +639,10 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
httpService.setHttpUrl(httpUrl);
vides_data::response* img_resp = httpService.httpPostFacePopulation(num_imgs,faSize,worker,sSn,currentTime);
if (img_resp->code != 0) {
qInfo()<<QString("SN(%1):不加图片人数变化推送信息推送失败,失败信息%2").arg(sSn).arg(img_resp->msg);
}else {
qInfo()<<QString("SN(%1): 不加图片人数变化推送信息推送成功").arg(sSn);
qInfo()<<"不加图片人数变化推送信息推送失败";
}
instace.deleteObj(img_resp);
}else{
qInfo()<<QString("SN(%1): 人数变化推送失败,失败信息%2").arg(sSn).arg(resp->msg);
}
}else {
qInfo()<<QString("SN(%1): 人数变化推送成功").arg(sSn);
}
instace.deleteObj(resp);
......@@ -691,16 +680,13 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
httpService.setHttpUrl(httpUrl);
vides_data::response* img_resp = httpService.httpPostFaceReconition(faceReconition);
if (img_resp->code != 0) {
qInfo()<<QString("SN(%1): 不加图片人脸信息推送失败,失败信息%2,人脸id%3").arg(sSn).arg(resp->msg).arg(face.id);
}else {
qInfo()<<QString("SN(%1): 不加图片人脸信息推送成功").arg(sSn);
qInfo()<<"不加图片人脸信息推送失败";
qInfo()<<"不加图片识别人code"<<resp->code;
qInfo()<<"不加图片识别人msg"<<resp->msg;
qInfo()<<"不加图片识别人脸信息推送失败"<<face.id;
}
instace.deleteObj(img_resp);
}else {
qInfo()<<QString("SN(%1): 人脸信息推送失败,失败信息%2").arg(sSn).arg(resp->msg);
}
}else{
qInfo()<<QString("SN(%1): 人脸信息推送成功").arg(sSn);
}
instace.deleteObj(resp);
}
......@@ -721,23 +707,18 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
httpService.setHttpUrl(httpUrl);
vides_data::response* img_resp=httpService.httpPostUniforms(num_imgs,strUniform, sSn,currentTime);
if (img_resp->code != 0) {
qInfo()<<QString("SN(%1): 不加图片推送未穿工服人数失败,失败信息%2").arg(sSn).arg(img_resp->msg);
}else {
qInfo()<<QString("SN(%1): 不加图片推送未穿工服人数成功").arg(sSn);
qInfo()<<"不加图片推送未穿工服人数失败";
}
instace.deleteObj(img_resp);
}else{
qInfo()<<QString("SN(%1): 推送未穿工服人数失败,失败信息%2").arg(sSn).arg(resp->msg);
}
}else{
qInfo()<<QString("SN(%1): 推送未穿工服人数成功").arg(sSn);
}
instace.deleteObj(resp);
}
}
}
}else{
qDebug()<<sSn<<":人形识别算法关闭,只有车牌算法了";
qInfo()<<"人形识别算法关闭,只有车牌算法了";
}
//关闭车牌识别
if ((algorithmPermissions & 0x01) == 0) {
......@@ -776,6 +757,8 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
}
}
vides_data::requestLicensePlate newPlate;
newPlate.sn=sSn;
......@@ -801,7 +784,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
if (parkAreaMap != parkMap.end()) {
value = parkAreaMap->second; // 成功找到,获取
} else {
qInfo()<<QString("SN(%1): 区域%2不存在").arg(sSn).arg(key);
qInfo()<<sSn<<"==>区域不存在:"<<key;
continue;
}
vides_data::requestLicensePlate resultPlate;
......@@ -810,7 +793,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
algorithmTaskManage.executeFindlicensePlateNumber(areaMat, lpNumber,resultPlate,currentTime,sSn);
std::list<vides_data::LicensePlate>ps =resultPlate.plates;
qInfo()<<QString("SN(%1):区域:%2识别的车牌信息是:%3").arg(sSn).arg(key).
qInfo()<<QString("sn==>%1,区域:%2识别的车牌信息是:%3").arg(sSn).arg(key).
arg(lpNumber);
if(ps.size()==0){
int res=-1;
......@@ -845,13 +828,13 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
RecognizedInfo recognizedInfo;
if (maxPlate.new_color=="蓝牌" && maxPlate.new_plate.length() != 7) {
qDebug()<<QString("SN(%1): 蓝牌车牌号%2,recognition.new_plate.length()=%3").arg(sSn).arg(maxPlate.new_plate).arg(maxPlate.new_plate.length());
qInfo()<<sSn<<"==>蓝牌车牌号:"<<maxPlate.new_plate<<"===>recognition.new_plate.length():"<<maxPlate.new_plate.length();
continue;
} else if (maxPlate.new_color=="绿牌新能源" && maxPlate.new_plate.length() != 8) {
qDebug()<<QString("SN(%1): 绿牌车牌号%2,recognition.new_plate.length()=%3").arg(sSn).arg(maxPlate.new_plate).arg(maxPlate.new_plate.length());
qInfo()<<sSn<<"==>绿牌车牌号:"<<maxPlate.new_plate<<"===>recognition.new_plate.length():"<<maxPlate.new_plate.length();
continue;
} else if (maxPlate.new_plate.length() < 7) {
qDebug()<<QString("SN(%1): 非绿牌蓝牌车牌号%2,recognition.new_plate.length()=%3").arg(sSn).arg(maxPlate.new_plate).arg(maxPlate.new_plate.length());
qInfo()<<sSn<<"==>非绿牌蓝牌车牌号:"<<maxPlate.new_plate<<"===>recognition.new_plate.length():"<<maxPlate.new_plate.length();
continue;
}
if(maxPlate.text_confidence>=carConfidenceMax){
......@@ -868,8 +851,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
this->checkAndUpdateCurrentPlate(value,areaMat,recognizedInfo,res);
}
if(maxPlate.text_confidence<=carConfidenceMin){
qDebug()<<QString("SN(%1): recognition.text_confidence<=instace.getCarConfidenceMin:%2").arg(sSn).arg(carConfidenceMin);
qInfo()<<sSn<<"==>recognition.text_confidence<=instace.getCarConfidenceMin"<<carConfidenceMin;
continue;
}
if(maxPlate.text_confidence>carConfidenceMin
......@@ -888,6 +870,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
maxPlate.img=imgs;
maxPlate.new_color=recognizedInfo.getColor();
newPlate.plates.push_back(std::move(maxPlate));
qInfo()<<QString("当前进入ps.size()>0 --> res == Exit || res == Mobilization 是当前校验返回结果是:%1").arg(res);
}
if(res==ExitAndMobilization){
maxPlate.areaLocation=value->getArea();
......@@ -900,8 +883,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
}
if(newPlate.plates.size()>0){
foreach (auto var, newPlate.plates) {
qInfo()<<QString("SN(%1): 识别的车牌号是:%2").arg(sSn).arg(var.new_plate);
qInfo()<<QString("sn:%1 =>识别的车牌号是:%2").arg(sSn).arg(var.new_plate);
}
licensePlateRecognitionResults(newPlate);
}
......@@ -960,37 +942,17 @@ void CameraHandle::licensePlateRecognitionResults(vides_data::requestLicensePlat
httpService.setHttpUrl(httpUrl);
vides_data::response* img_resp = httpService.httpLicensePlateRecognition(location, result);
if (img_resp->code != 0) {
qInfo()<<QString("SN(%1): 车牌不加图片上传失败:失败信息%2").arg(sSn).arg(img_resp->msg);
}else{
qInfo()<<QString("SN(%1): 车牌不加图片上传成功").arg(sSn);
qInfo()<<"车牌不加图片上传失败";
}
instace.deleteObj(img_resp);
}else{
qInfo()<<QString("SN(%1): 车牌识别结果上传失败:失败信息%2").arg(sSn).arg(resp->msg);
qInfo()<<"licensePlateRecognitionResults:车牌识别结果失败";
// 在达到最大重试次数且仍然没有成功的情况下执行相应的处理逻辑
}
}
instace.deleteObj(resp);
}
bool CameraHandle::isWifiConnect(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
char szOutBuffer[4000] = { 0 };
int nInOutSize = sizeof(szOutBuffer);
// 获取并解析配置
int nResult = XSDK_DevGetSysConfigSyn(hDevice, JK_NetWork_Wifi, szOutBuffer, &nInOutSize, 3000, EXCMD_CONFIG_GET);
qInfo()<<szOutBuffer;
if (nResult >= 0) {
cfg.Parse(szOutBuffer);
return strlen(cfg.SSID.Value())>0;
} else {
printf("Failed to get Wi-Fi configuration. Error code: %d\n", nResult);
return false;
}
}
void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
char szOutBuffer[4000] = { 0 };
int nInOutSize = sizeof(szOutBuffer);
......@@ -1006,97 +968,8 @@ void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
}
}
void CameraHandle::sdkWifi(QString &pwd,QString &ssid){
/**
* @brief CameraHandle::resetGb28181
* 1. 关闭对应摄像头GB28181
2. 修改设备IP并保存当前IP
3. 定时(增加配置 默认5s)后修改为原IP(保证本地NVR可用)
4. 启动GB28181
需注意和定时任务对比GB28181配置冲突处理
需确认修改IP后抓图是否正常,如不正常需在命令开始前增加删除句柄,命令完成后增加句柄以保证抓图实时性
*/
int CameraHandle::resetGb28181(){
NonConnectedCameraHandle *connectedCameraHandle =NonConnectedCameraHandle::getInstance();
int old=hDevice;
MainWindow::sp_this->setIsResetting(true);
bool is_wifi=false;
ScopeSemaphoreExit guard([]() {
MainWindow::sp_this->setIsResetting(false);
});
this->updateSdkDevStatus(false);
QString ip=QString::fromUtf8(loginParam->sDevId);
QString reachableIp= vides_data::findReachableIp();
if (!reachableIp.isEmpty()) {
qInfo()<<QString("SN(%1): 未使用的IP地址%2").arg(sSn).arg(reachableIp);
} else {
qInfo()<<QString("SN(%1): 找不到可使用的IP地址").arg(sSn);
return -1;
}
this->hDevice=-1;
MainWindow::sp_this->modifySnMapIp(sSn,url);
vides_data::localDevice device;
device.reachableIp=reachableIp;
device.sSn=sSn;
bool result= connectedCameraHandle->changeCameraIp(device);
int newHandle=-1;
if(!result ){
result=connectedCameraHandle->wifiChangeIp(reachableIp,false,old,sSn);
is_wifi=true;
if(result){
//老句柄抓图不正常了
int sdk_handle=this->sdkDevLoginSyn(reachableIp,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000);
if(sdk_handle<0){
qInfo()<<QString("SN(%1): WIFI新句柄生成失败").arg(sSn);
return -1;
}else {
qInfo()<<QString("SN(%1): WIFI新句柄生成成功").arg(sSn);
newHandle=sdk_handle;
this->hDevice=-1;
XSDK_DevLogout(old);
}
}
}
// 阻塞等待5秒
QThread::sleep(5);
QString old_ip;
MainWindow::sp_this->findSnMapIp(this->sSn,old_ip);
if(old_ip.length()>0){
if(is_wifi){
result=connectedCameraHandle->wifiChangeIp(old_ip,true,newHandle,sSn);
int sdk_handle=this->sdkDevLoginSyn(old_ip,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000);
if(sdk_handle<0){
qInfo()<<QString("SN(%1): WIFI新句柄生成失败").arg(sSn);
}else {
XSDK_DevLogout(newHandle);
qInfo()<<QString("SN(%1): WIFI新句柄生成成功").arg(sSn);
}
}else {
device.reachableIp=old_ip;
device.sSn=sSn;
bool result= connectedCameraHandle->changeCameraIp(device);
if(result){
int sdk_handle=this->sdkDevLoginSyn(old_ip,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000);
if(sdk_handle<0){
qInfo()<<QString("SN(%1): 有线新句柄生成失败").arg(sSn);
}else {
XSDK_DevLogout(old);
qInfo()<<QString("SN(%1): 有线新句柄生成成功").arg(sSn);
}
}
}
}
return this->updateSdkDevStatus(true);
}
bool CameraHandle::sdkWifi(QString &pwd,QString &ssid){
Common & instace= Common::getInstance();
XSDK_CFG::NetWork_Wifi wif;
printWifi(hDevice,wif);
......@@ -1104,33 +977,21 @@ bool CameraHandle::sdkWifi(QString &pwd,QString &ssid){
const char * cpwd= byPwd.data();
wif.Keys.SetValue(cpwd);
QString reachableIp= vides_data::findReachableIp();
QString hex=instace.DecIpToHexIp(reachableIp);
QByteArray && byJson = ssid.toUtf8();
QByteArray && byJson = ssid.toUtf8();
const char * cssid= byJson.data();
wif.SSID.SetValue(cssid);
wif.Enable.SetValue(true);
wif.KeyType.SetValue(1);
wif.EncrypType.SetValue("AES");
wif.Auth.SetValue("WPA2PSK");
QByteArray && byHex = hex.toUtf8();
const char * c_hex= byHex.data();
wif.HostIP.SetValue(c_hex);
//wif.HostIP.SetValue(newc_ip);
const char* wipCfg = wif.ToString();
qInfo()<<"wipCfg==>"<<wipCfg;
char szOutBuffer[512] = { 0 };
int nLen = sizeof(szOutBuffer);
int res =XSDK_DevSetSysConfigSyn(hDevice, JK_NetWork_Wifi, wipCfg, strlen(wipCfg), szOutBuffer, &nLen, 3000, EXCMD_CONFIG_SET);
if(res<0){
qInfo()<<QString("SN(%1): 修改wifi失败:%2").arg(sSn).arg(res);
return false;
}
qInfo() << "修改wifi失败";
}
deviceReboot();
return true;
}
void CameraHandle::sdkDevSystemTimeZoneSyn(QString &time){
......@@ -1142,23 +1003,23 @@ void CameraHandle::sdkDevSystemTimeZoneSyn(QString &time){
int res = XSDK_DevSetSysConfigSyn(hDevice, JK_System_TimeZone, zoneCfg, strlen(zoneCfg), outBuffer, &nInOutBufSize, 3000, EXCMD_CONFIG_GET);
if(res<0){
qInfo()<<QString("SN(%1): FirstUserTimeZone 修改失败").arg(sSn);
qInfo() << "FirstUserTimeZone:修改失败";
}
res=XSDK_DevSynTime(hDevice,cTime,0);
if(res<0){
qInfo()<<QString("SN(%1): sdkDevSystemTimeZoneSyn修改失败").arg(sSn);
qInfo() << "sdkDevSystemTimeZoneSyn:修改失败";
}
}
//录像设置
void CameraHandle::sdkRecordCfg(const char * recordJson){
qInfo()<<recordJson;
char szOutBuffer[512] = { 0 };
int nLen = sizeof(szOutBuffer);;
int res=XSDK_DevSetSysConfigSyn(hDevice,JK_Record,recordJson,strlen(recordJson),szOutBuffer,&nLen,3000,EXCMD_CONFIG_SET);
if(res<0){
qInfo()<<QString("SN(%1): sdkRecordCfg 录像设置->修改失败").arg(sSn);
qInfo() << "sdkRecordCfg 录像设置->修改失败"<<res;
}
}
//配置编码设置
......@@ -1167,24 +1028,16 @@ void CameraHandle::sdkEncodeCfg(const char* pCfg){
int nLen = sizeof(szOutBuffer);
int res=XSDK_DevSetSysConfigSyn(hDevice,JK_Simplify_Encode,pCfg,strlen(pCfg),szOutBuffer,&nLen,3000,EXCMD_CONFIG_SET);
if(res<0){
qInfo()<<QString("SN(%1): sdkEncodeCfg 配置编码设置->修改失败").arg(sSn);
qInfo() << "sdkEncodeCfg 配置编码设置->修改失败"<<res;
}
}
int CameraHandle::updateSdkDevStatus(bool status){
this->isOperateGb28181.store(true, std::memory_order_release);
ScopeSemaphoreExit streamGuard([this]() {
isOperateGb28181.store(false, std::memory_order_release);
});
char szOutBuffer[40960]={ 0 };
int nInOutSize = sizeof(szOutBuffer);
int res= XSDK_DevGetSysConfigSyn(hDevice,JK_NetWork_SPVMN,szOutBuffer,&nInOutSize,4000,EXCMD_CONFIG_GET);
if(res<0){
qInfo()<<QString("SN(%1): GB28181可远程开关").arg(sSn);
qInfo() << sSn<<"GB28181可远程开关"<<res;
return 0 ;
}
XSDK_CFG::NetWork_SPVMN config;
......@@ -1195,10 +1048,6 @@ int CameraHandle::updateSdkDevStatus(bool status){
return res;
}
void CameraHandle::updateSdkDevSpvMn(vides_data::responseGb28181 *gb28181){
if(isOperateGb28181.load(std::memory_order_acquire)){
qInfo()<<QString("SN(%1): mqtt正在操作GB28181").arg(sSn);
return ;
}
char szOutBuffer[40960]={ 0 };
int nInOutSize = sizeof(szOutBuffer);
int res= XSDK_DevGetSysConfigSyn(hDevice,JK_NetWork_SPVMN,szOutBuffer,&nInOutSize,4000,EXCMD_CONFIG_GET);
......@@ -1281,7 +1130,7 @@ void CameraHandle::sdkDevSpvMn(const char *spvMn){
int nLen = sizeof(szOutBuffer);
int res=XSDK_DevSetSysConfigSyn(hDevice,JK_NetWork_SPVMN,spvMn,strlen(spvMn),szOutBuffer,&nLen,3000,EXCMD_CONFIG_SET);
if(res<0){
qInfo() <<sSn<< ":sdkDevSpvMn 28181->修改失败"<<res;
qInfo() << "sdkDevSpvMn 28181->修改失败"<<res;
}
}
int CameraHandle::deviceReboot(){
......@@ -1292,7 +1141,7 @@ int CameraHandle::deviceReboot(){
const char* pCfg = cfg.ToString();
nRet = XSDK_DevSetSysConfig(hDevice, JK_OPMachine, pCfg, strlen(pCfg), 1, 3000, EXCMD_SYSMANAGER_REQ);
if(nRet<0){
qInfo() << sSn<<":重启相机失败"<<nRet;
qInfo() << sSn<<"重启相机失败"<<nRet;
return 0 ;
}
QString ip=QString::fromUtf8(loginParam->sDevId);
......@@ -1310,7 +1159,7 @@ int CameraHandle::deviceShutdown()
const char* pCfg = cfg.ToString();
nRet = XSDK_DevSetSysConfig(hDevice, JK_OPMachine, pCfg, strlen(pCfg), 1, 3000, EXCMD_SYSMANAGER_REQ);
if(nRet<0){
qInfo()<<QString("SN(%1): 设备关机失败:%2").arg(sSn).arg(nRet);
qInfo() << sSn<<"设备关机失败"<<nRet;
return 0;
}
......
......@@ -14,7 +14,6 @@
#include "Json_Header/NetWork_Wifi.h"
#include "Json_Header/SystemInfo.h"
#include "Json_Header/OPMachine.h"
#include "NonConnectedCameraHandle.h"
#include "mainwindow.h"
#include "ParkingSpaceInfo.h"
#include "hyper_lpr_sdk.h"
......@@ -32,7 +31,6 @@
#include <opencv2/opencv.hpp>
#include <QSemaphore>
#include <atomic>
#include <arpa/inet.h>
enum CAR_INFORMATION {
Exit, //出场
......@@ -63,7 +61,7 @@ public:
//相机参数更新
void cameraParameterUpdate(vides_data::responseConfig &cloudConfig);
void initSdkRealTimeDevSnapSyn(int syn_timer,uint64 face_frequency);
void initSdkRealTimeDevSnapSyn(int hDevice,int syn_timer,uint64 face_frequency);
void notificationUpdateImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence);
......@@ -87,12 +85,10 @@ public:
void printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg);
bool isWifiConnect(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg);
void setCarConfidenceMaxAndMin(float carConfidenceMax,float carConfidenceMin);
//设置相机连接的wifi
bool sdkWifi(QString &pwd,QString &ssid);
void sdkWifi(QString &pwd,QString &ssid);
//时间设置
void sdkDevSystemTimeZoneSyn(QString &time);
//录像设置
......@@ -111,8 +107,6 @@ public:
int deviceShutdown();
//获取固件版本
void findFirmwareVersion(QString &firmwareVersion);
//复位GB28181
int resetGb28181();
//获取ip
void findIp(QString &ip);
......@@ -133,10 +127,6 @@ public:
void setMediaHandle(int mediaHandle);
void initAlgorithmPermissions(__uint8_t algorithm);
void initFaceFrequency(uint64 face_frequency);
void initParkingSpaceInfo(const std::list<vides_data::responseArea>&areas);
bool compareLists(const std::list<vides_data::responseArea>& newAreas);
......@@ -168,7 +158,7 @@ signals:
void afterDownloadFile( int id,int recognitionType,QString ossUrl);
private slots:
void sdkRealTimeDevSnapSyn();
void sdkRealTimeDevSnapSyn(int hDevice);
void pushRecordToCloud(int id,int recognitionType,QString ossUrl);
//void releaseSemaphore();
......@@ -205,9 +195,6 @@ private :
int image_save;
std::atomic<uint64> faceCount;
std::atomic<bool> isOperateGb28181{false};
uint64 face_frequency;
__uint8_t algorithmPermissions;
......
......@@ -62,37 +62,6 @@ void Common::setImages(QString images){
images.append("/");
this->images=images;
}
QString Common::DecIpToHexIp(const QString& decIp) {
// 将 IP 地址按点号分割成多个部分
QStringList parts = decIp.split(".");
// 检查 IP 地址是否有效(应包含 4 个部分)
if (parts.size() != 4) {
return QString(); // 如果无效,返回空字符串
}
QString hexIp; // 用于存储最终的十六进制表示
// 从最后一个部分开始遍历
for (int i = 3; i >= 0; --i) {
// 将每个部分转换为整数
bool ok;
int part = parts[i].toInt(&ok);
if (!ok) return QString(); // 如果转换失败,返回空字符串
// 将整数转换为十六进制字符串,并在必要时补零
QString hexPart = QString::number(part, 16).rightJustified(2, '0');
// 将十六进制字符串添加到结果中
hexIp.append(hexPart);
}
// 在结果前添加 "0x" 以表示十六进制
hexIp.prepend("0x");
return hexIp; // 返回最终的十六进制表示
}
QString Common::GetLocalIp() {
QString ipAddress;
QList<QHostAddress> list = QNetworkInterface::allAddresses();
......
......@@ -10,7 +10,7 @@
#include <QCryptographicHash>
#include <QMessageAuthenticationCode>
#include <QNetworkInterface>
#include <map>
#include <QDebug>
class Common
{
......@@ -39,14 +39,11 @@ public:
QString getVideoDownload();
void setVideoDownload(QString videoDownload);
QString getImages();
void setImages(QString images);
QString GetLocalIp();
QString DecIpToHexIp(const QString& decIp);
template <typename T>
const T& clamp(const T& v, const T& lo, const T& hi)
{
......@@ -64,7 +61,6 @@ private:
QString videoOut;
QString videoDownload;
QString images;
Common();
~Common();
......
......@@ -192,7 +192,7 @@ cv::Mat FaceReconitionHandle::loadImageFromByteStream(const QString& filePath) {
void FaceReconitionHandle::doesItExistEmployee(const QString &sn,const cv::Mat &source,std::list<vides_data::faceRecognitionResult>&faces){
void FaceReconitionHandle::doesItExistEmployee(const cv::Mat &source,std::list<vides_data::faceRecognitionResult>&faces){
thread_time.store(QDateTime::currentMSecsSinceEpoch(), std::memory_order_release);
ScopeSemaphoreExit streamGuard([this]() {
isRunning.store(false, std::memory_order_release);
......@@ -211,14 +211,14 @@ void FaceReconitionHandle::doesItExistEmployee(const QString &sn,const cv::Mat &
ret = HF_CreateImageStream(&imageData, &imageSteamHandle);
if (ret != HSUCCEED) {
qInfo()<<QString("SN(%1): image handle error:%2").arg(sn).arg((long)imageSteamHandle,0,10);
qInfo()<<QString("image handle error:%1").arg((long) imageSteamHandle,0,10);
return ;
}
HF_MultipleFaceData multipleFaceData = {0};
HF_FaceContextRunFaceTrack(ctxHandle, imageSteamHandle, &multipleFaceData);
if (multipleFaceData.detectedNum <= 0) {
qInfo()<<QString("SN(%1): 未检测到人脸").arg(sn);
qInfo()<<QString("search 未检测到人脸");
return ;
}
......@@ -227,12 +227,11 @@ void FaceReconitionHandle::doesItExistEmployee(const QString &sn,const cv::Mat &
HInt32 featureNum;
HF_GetFeatureLength(ctxHandle, &featureNum);
for(int j=0;j< multipleFaceData.detectedNum; ++j){
//qInfo()<<QString("doesItExistEmployee==>面部索引: %1").arg(j);
qDebug() << QString("SN(%1): 面部索引:%2").arg(sn).arg(j);
qInfo()<<QString("doesItExistEmployee==>面部索引: %1").arg(j);
std::vector<float> newfeature(featureNum,0.0f);
ret = HF_FaceFeatureExtractCpy(ctxHandle, imageSteamHandle, multipleFaceData.tokens[j], newfeature.data());
if(ret != HSUCCEED) {
qInfo() << QString("SN(%1): 特征提取出错:%2").arg(sn).arg(ret);
qInfo()<<QString("特征提取出错: %1").arg(ret);
HF_ReleaseImageStream(imageSteamHandle);
return ;
}
......@@ -249,12 +248,13 @@ void FaceReconitionHandle::doesItExistEmployee(const QString &sn,const cv::Mat &
HFloat confidence;
ret = HF_FeaturesGroupFeatureSearch(ctxHandle, feature, &confidence, &searchIdentity);
if (ret != HSUCCEED) {
qInfo() << QString("SN(%1): 搜索失败:%2").arg(sn).arg(ret);
qInfo()<<QString("搜索失败: %1").arg(ret);
return ;
}
qInfo() << QString("SN(%1): 搜索置信度:%2").arg(sn).arg(confidence);
qInfo() << QString("SN(%1): 匹配到的tag:%2").arg(sn).arg(searchIdentity.tag);
qInfo() << QString("SN(%1): 匹配到的customId:%2").arg(sn).arg(searchIdentity.customId);
qInfo()<<QString("搜索置信度: %1").arg(confidence);
qInfo()<<QString("匹配到的tag: %1").arg(searchIdentity.tag);
qInfo()<<QString("匹配到的customId: %1").arg(searchIdentity.customId);
// Face Pipeline
//printf("人脸特征数量: %d", faceNum);
if (confidence > configConfidence) {
......@@ -275,7 +275,7 @@ void FaceReconitionHandle::doesItExistEmployee(const QString &sn,const cv::Mat &
// printf("image released");
} else {
//printf("image release error: %ld", ret);
qInfo() << QString("SN(%1): image release error:%2").arg(sn).arg(ret);
qInfo()<<QString("image release error: %1").arg(ret);
}
}
......@@ -33,7 +33,7 @@ public:
void setImageChanged(bool imageChanged);
void doesItExistEmployee(const QString &sn,const cv::Mat &source,std::list<vides_data::faceRecognitionResult>&face);
void doesItExistEmployee(const cv::Mat &source,std::list<vides_data::faceRecognitionResult>&face);
void initSourceImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence);
......
......@@ -161,7 +161,7 @@ vides_data::response *HttpService::httpFindCameras(QString &serialNumber,vides_d
}else{
qInfo()<<m_httpClient.errorCode();
resp->code=2;
resp->msg=m_httpClient.errorCode();
resp->msg=OPERATION_FAILED;
}
return resp;
}
......@@ -354,6 +354,11 @@ vides_data::response *HttpService::httpPostFacePopulation(QByteArray &img,int &h
resp->code=map["code"].toInt();
resp->msg=map["message"].toString();
}else{
qInfo()<<"httpPostFacePopulation===>";
qInfo()<<m_httpClient.errorCode();
qInfo()<<m_httpClient.errorString();
qInfo()<<"httpPostFacePopulation===>end";
resp->code=2;
resp->msg=m_httpClient.errorCode();
}
......@@ -506,6 +511,7 @@ vides_data::response *HttpService::httpDeviceConfig(const QString &serialNumber,
QJsonObject faceConfigObj = dataObj["faceConfig"].toObject();
config.faceConfig.isOn = faceConfigObj["isOn"].toBool();
config.faceConfig.faceNumbers = faceConfigObj["faceNumbers"].toInt();
config.faceConfig.faceFrequency = faceConfigObj["faceFrequency"].toInt();
config.faceConfig.confidence = faceConfigObj["confidence"].toVariant().toFloat();
config.faceConfig.updateAt = faceConfigObj["updateAt"].toVariant().toULongLong();
config.faceConfig.faceLen=faceConfigObj["faceLen"].toInt();
......@@ -536,7 +542,6 @@ vides_data::response *HttpService::httpDeviceConfig(const QString &serialNumber,
QJsonObject humanConfigObj = dataObj["humanConfig"].toObject();
config.humanConfig.isOn=humanConfigObj["isOn"].toBool();
config.humanConfig.updateAt = humanConfigObj["updateAt"].toVariant().toULongLong();
config.humanConfig.faceFrequency = humanConfigObj["faceFrequency"].toVariant().toUInt();
// 解析 devicesConfig
QJsonObject devicesConfigObj = dataObj["camera"].toObject();
......
......@@ -7,7 +7,7 @@ HttpClient::HttpClient(QObject *parent)
{
m_networkAccessManager = new QNetworkAccessManager(this);
m_timer = new QTimer(this);
m_timer->setInterval(8000);
m_timer->setInterval(6000);
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
}
......
......@@ -77,7 +77,7 @@ void HumanDetection::setHuManParameter(int &uniformColor){
}
//0 人形 1 车形 2 工服
int HumanDetection::findHuManCar(const cv::Mat &source, int res,std::map<int,int>&reMap,QString &sSn, float &heightReference, std::vector<vides_data::ParkingArea> &currentPlate) {
int HumanDetection::findHuManCar(const cv::Mat &source, int res,std::map<int,int>&reMap, float &heightReference, std::vector<vides_data::ParkingArea> &currentPlate) {
thread_time.store(QDateTime::currentMSecsSinceEpoch(), std::memory_order_release);
TCV_CameraStream *stream = TCV_CreateCameraStream();
......@@ -100,7 +100,8 @@ int HumanDetection::findHuManCar(const cv::Mat &source, int res,std::map<int,int
if (res == 0x00 || res == 0x02) {
num = TCV_HumanDetectorGetNumOfHuman(detector);
qInfo() << QString("SN(%1): 获取人形数量:%2").arg(sSn).arg(num);
qInfo()<<"TCV_HumanDetectorGetNumOfHuman==>"<<num;
if (num == 0) return num; // 无行人检测结果,提前返回
std::vector<TCV_ObjectLocation> results(num);
TCV_HumanDetectorGetHumanLocation(detector, results.data(), num);
......@@ -132,6 +133,8 @@ int HumanDetection::findHuManCar(const cv::Mat &source, int res,std::map<int,int
}
reMap[0x02] = count_no_uniform; // 未穿工服的行人数量
reMap[0x00] = count_all; // 所有满足条件的行人数量
qInfo()<<"count_all==>"<<count_all;
qInfo()<<"count_no_uniform==>"<<count_no_uniform;
num = (res == 0x00) ? count_all : count_no_uniform;
}
......
......@@ -16,7 +16,7 @@ public:
float carShapeConfidence);
~HumanDetection();
int findHuManCar(const cv::Mat &source,int res,std::map<int,int>&reMap,QString &sSn,
int findHuManCar(const cv::Mat &source,int res,std::map<int,int>&reMap,
float &heightReference, std::vector<vides_data::ParkingArea> &currentPlate);
void setHuManParameter(int &uniformColor);
......
......@@ -82,6 +82,7 @@ void LicensePlateRecognition::oldLicensePlateNumber(const cv::Mat &source,const
} else {
type = types[results.plates[i].type];
}
qInfo()<<QString("车牌号:%1").arg(results.plates[i].code);
QString plateResult = QString("第%1个,%2,车牌号:%3,置信度:%4,左上角点x坐标:%5,左上角点y坐标:%6,右下角点x坐标:%7,右下角点y坐标:%8")
.arg(i + 1).arg(type.c_str()).arg(results.plates[i].code)
.arg(results.plates[i].text_confidence).arg(results.plates[i].x1, 0, 'Q', 4)
......@@ -167,6 +168,7 @@ void LicensePlateRecognition::licensePlateNumber(const cv::Mat &source, QString
newPlate.new_color=QString::fromStdString(type);
QString car_nuber=QString::fromUtf8(results.plates[i].code);
replaceWith1And0(car_nuber);
qInfo()<<"I O (i o)大小写替换为 1 0结果:==>"<<car_nuber;
newPlate.new_plate=car_nuber;
newPlate.text_confidence=results.plates[i].text_confidence;
vides_data::ParkingArea area;
......
......@@ -12,7 +12,7 @@
#include <QTextStream>
#include <QTextCodec>
const int g_logLimitSize = 45;
const int g_logLimitSize = 5;
struct LogHandlerPrivate {
LogHandlerPrivate();
......
......@@ -25,7 +25,7 @@ LogHandlerPrivate::LogHandlerPrivate() {
openAndBackupLogFile();
// 十分钟检查一次日志文件创建时间
renameLogFileTimer.setInterval(1000 * 60 * 10); // TODO: 可从配置文件读取
renameLogFileTimer.setInterval(1000*2); // TODO: 可从配置文件读取
renameLogFileTimer.start();
QObject::connect(&renameLogFileTimer, &QTimer::timeout, [this] {
QMutexLocker locker(&LogHandlerPrivate::logMutex);
......@@ -91,16 +91,9 @@ void LogHandlerPrivate::openAndBackupLogFile() {
logFile->close();
delete logOut;
delete logFile;
QDate renameDate = logFileCreatedDate;
if (logFileCreatedDate == QDate::currentDate()) {
renameDate = QDate::currentDate().addDays(-1); // 设置为昨天的日期
}
QString newLogPath = logDir.absoluteFilePath(renameDate.toString("yyyy-MM-dd.log"));
// QFile::rename(logPath, newLogPath); // 将原始日志文件重命名为新的文件名
QFile::copy(logPath, newLogPath);
QFile::remove(logPath);
QString newLogPath = logDir.absoluteFilePath(logFileCreatedDate.toString("yyyy-MM-dd.log"));
QFile::rename(logPath, newLogPath); // 将原始日志文件重命名为新的文件名
logFile = new QFile(logPath);
logOut = (logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) ? new QTextStream(logFile) : nullptr;
......@@ -112,8 +105,8 @@ void LogHandlerPrivate::openAndBackupLogFile() {
// 检测当前日志文件大小
void LogHandlerPrivate::checkLogFiles() {
// 如果 protocal.log 文件大小超过55M,重新创建一个日志文件,原文件存档为yyyy-MM-dd_hhmmss.log
if (logFile->size() > 1024*1024*g_logLimitSize) {
// 如果 protocal.log 文件大小超过5M,重新创建一个日志文件,原文件存档为yyyy-MM-dd_hhmmss.log
if (logFile->size() > 1024*g_logLimitSize) {
logFile->flush();
logFile->close();
delete logOut;
......@@ -121,11 +114,7 @@ void LogHandlerPrivate::checkLogFiles() {
QString logPath = logDir.absoluteFilePath("today.log"); // 日志的路径
QString newLogPath = logDir.absoluteFilePath(logFileCreatedDate.toString("yyyy-MM-dd.log"));
// QFile::rename(logPath, newLogPath);
QFile::copy(logPath, newLogPath);
QFile::remove(logPath);
QFile::rename(logPath, newLogPath);
logFile = new QFile(logPath);
logOut = (logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) ? new QTextStream(logFile) : NULL;
logFileCreatedDate = QDate::currentDate();
......
......@@ -230,7 +230,7 @@ int MediaFaceImage::ToFile(const char* pFileName, const void* pData, int nLength
// return pInOutBufferSize; // pOutBuffer由智能指针管理,此处无需手动释放
//}
int MediaFaceImage::FaceImageCallBack(XSDK_HANDLE hMedia, int nChannel, cv::Mat &image,QString &sSn) {
int MediaFaceImage::FaceImageCallBack(XSDK_HANDLE hMedia, int nChannel, cv::Mat &image) {
const int BufferSize = 1024 * 1024 * 2; // 缓冲区大小
image.release(); // 释放之前的图像
std::unique_ptr<unsigned char[]> pOutBuffer(new unsigned char[BufferSize]); // 智能指针管理内存
......@@ -238,7 +238,7 @@ int MediaFaceImage::FaceImageCallBack(XSDK_HANDLE hMedia, int nChannel, cv::Mat
int ret = XSDK_DevSnapSyn(hMedia, nChannel, "", pOutBuffer.get(), &pInOutBufferSize);
if (ret < 0 || pInOutBufferSize <= 0) {
qInfo() << QString("SN(%1): 同步设备端抓图失败").arg(sSn);;
qInfo() << "同步设备端抓图失败";
return -1;
}
......@@ -249,12 +249,12 @@ int MediaFaceImage::FaceImageCallBack(XSDK_HANDLE hMedia, int nChannel, cv::Mat
try {
cv::Mat decodedImage = cv::imdecode(buffer, cv::IMREAD_UNCHANGED);
if (decodedImage.empty()) {
qInfo() << QString("SN(%1): 图像解码失败").arg(sSn);;
qInfo() << "图像解码失败";
return -1;
}
image = std::move(decodedImage);
} catch (const cv::Exception& e) {
qInfo() << QString("SN(%1): 图像解码过程中捕获异常:%2").arg(sSn).arg(e.what());
qInfo() << "图像解码过程中捕获异常:" << e.what();
return -1;
}
......@@ -281,3 +281,4 @@ int MediaFaceImage::CameraImage(XSDK_HANDLE hMedia,int nChannel,std::vector<ucha
// 返回实际填入Vector的数据大小
return pInOutBufferSize;
}
......@@ -18,7 +18,7 @@ public:
static MediaFaceImage* getInstance(); // 单例模式获取实例的静态成员函数
void ParserImageData(const unsigned char* pData, int nDataLen, char* pJpg, int* nJpgLen, char* pJson);
int FaceImageCallBack(XSDK_HANDLE hMedia,int nChannel,cv::Mat &image,QString &sSn);
int FaceImageCallBack(XSDK_HANDLE hMedia,int nChannel,cv::Mat &image);
int CameraImage(XSDK_HANDLE hMedia,int nChannel,std::vector<uchar> &buffer);
int ToFile(const char* pFileName, const void* pData, int nLenght);
......@@ -34,7 +34,6 @@ public:
void clearCurrentDevice(int hObject);
void setMap(int &key,CameraHandle*value);
private:
MediaFaceImage(); // 构造函数声明为私有
~MediaFaceImage(); // 析构函数声明为私有
......
......@@ -174,7 +174,7 @@ void MqttSubscriber::connectionLost(char* cause) {
int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_message* m) {
QString topic(topicName);
QString payload = QString::fromUtf8(reinterpret_cast<const char*>(m->payload), m->payloadlen);
QJsonObject msgBodyOb;
vides_data::responseMqttData response;
QJsonDocument jsonDoc = QJsonDocument::fromJson(payload.toUtf8());
if (!jsonDoc.isNull() && jsonDoc.isObject()) {
......@@ -182,92 +182,47 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
response.msg_type = jsonObj["msg_type"].toInt();
response.sn = jsonObj["sn"].toString();
response.uniq = jsonObj["uniq"].toString();
if(response.msg_type==6 || response.msg_type==7){
// 解析 msg_body 字段
if (jsonObj.contains("msg_body")) {
QString msgBodyStr = jsonObj["msg_body"].toString();
// 将 msg_body 字符串转换为 QJsonDocument
QJsonDocument msgBodyDoc = QJsonDocument::fromJson(msgBodyStr.toUtf8());
if (!msgBodyDoc.isNull() && msgBodyDoc.isObject()) {
msgBodyOb = msgBodyDoc.object();
} else {
qInfo() << "Failed to parse msg_body as a JSON object.";
}
}
}
} else {
qInfo() << "Failed to parse JSON payload";
}
//1开 2关 3 重启 4 GB28181开 5 GB28181 关 6 一键配网 7 WIFI配留 8 复位GB28181
int res = -2;
CameraHandle* cameraHandle = MainWindow::sp_this->findHandle(response.sn);
int hDevice=0;
if (cameraHandle == nullptr ) {
if(response.msg_type == 6){
hDevice=-1;
}else {
if (cameraHandle == nullptr) {
qInfo() << "不存在该相机";
res = -1;
}
} else {
switch (response.msg_type) {
case 2: res = cameraHandle->deviceShutdown(); break;
case 3: res = cameraHandle->deviceReboot(); break;
case 4: res = cameraHandle->updateSdkDevStatus(true); break;
case 5: res = cameraHandle->updateSdkDevStatus(false); break;
case 6: hDevice = cameraHandle->getHdevice(); break;
case 7: {
if (msgBodyOb.contains("username") && msgBodyOb.contains("password")) {
QString username = msgBodyOb["username"].toString();
QString password = msgBodyOb["password"].toString();
res = (cameraHandle->sdkWifi(password, username) ? 0 : 0x01);
} else {
qInfo() << "IP username not found in msg_body.";
qInfo() << "IP password not found in msg_body.";
if (response.msg_type == 2) {
res = cameraHandle->deviceShutdown();
} else if (response.msg_type == 3) {
res = cameraHandle->deviceReboot();
} else if (response.msg_type == 4) {
res = cameraHandle->updateSdkDevStatus(true);
} else if (response.msg_type == 5) {
res = cameraHandle->updateSdkDevStatus(false);
}
break;
}
case 8: res = (cameraHandle->resetGb28181() ? 0 : 0x01); break;
default: qInfo() << "Unknown message type"; break;
}
}
if (response.msg_type == 6) {
NonConnectedCameraHandle *connectedCameraHandle =NonConnectedCameraHandle::getInstance();
QString ipAddress ;
// 提取 ip 地址
if (msgBodyOb.contains("ip") && msgBodyOb["ip"].isString()) {
ipAddress = msgBodyOb["ip"].toString();
qInfo() << "IP Address: " << ipAddress;
} else {
qInfo() << "IP address not found in msg_body.";
}
res=connectedCameraHandle->distributionNetwork(ipAddress,response.sn,hDevice);
}
vides_data::requestMqttData request;
request.code = (res >= 0) ? 0 : 0x01;
request.msg = (res >= 0) ?"成功":"失败";
request.uniq= response.uniq;
sendSubscriptionConfirmation(request,response.sn);
request.uniq = response.uniq;
request.sn = response.sn;
sendSubscriptionConfirmation(request);
MQTTAsync_freeMessage(&m);
MQTTAsync_free(topicName);
return 1;
}
void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn) {
QString responseTopic = "/thingshub/" +response.uniq+ "/device/post";
void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response) {
QString responseTopic = "/thingshub/" + response.sn + "/device/post";
QByteArray bResponseTopic = responseTopic.toUtf8();
char* cResponseTopic = bResponseTopic.data();
qInfo()<<QString("SN(%1): sendSubscriptionConfirmation->cResponseTopic%2").arg(sn).arg(cResponseTopic);
qInfo() << "sendSubscriptionConfirmation" << cResponseTopic;
// response.sn
QJsonObject json;
json["code"] = response.code;
json["msg"] = response.msg;
json["uniq"] = response.uniq;
QJsonDocument jsonDoc(json);
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact);
MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
......
......@@ -45,7 +45,7 @@ private:
void onPublishSuccess(MQTTAsync_successData* response);
void onPublishFailure(MQTTAsync_failureData* response);
void sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn);
void sendSubscriptionConfirmation(const vides_data::requestMqttData& response);
static MqttSubscriber* instance;
};
......
#include "NonConnectedCameraHandle.h"
#include "mainwindow.h"
NonConnectedCameraHandle* NonConnectedCameraHandle::m_instance = nullptr; // 初始化指针为空
NonConnectedCameraHandle::NonConnectedCameraHandle()
{
}
NonConnectedCameraHandle::~NonConnectedCameraHandle()
{
}
NonConnectedCameraHandle* NonConnectedCameraHandle::getInstance()
{
if (m_instance == nullptr) // 检查指针是否为空
{
m_instance = new NonConnectedCameraHandle(); // 创建新的实例并指向它
}
return m_instance; // 返回指向实例的指针
}
bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
QString localMac, subnetMask, gateway;
bool success =vides_data::GetNetworkInfoByQNetworkInterface(localMac, subnetMask, gateway);
if (!success) {
qInfo() <<QString("SN(%1): 获取本地MAC失败").arg(device.sSn);
return false ;
}
QByteArray && byJson = localMac.toUtf8();
const char * mac= byJson.data();
QByteArray && byJsonIp = device.reachableIp.toUtf8();
const char * charIp= byJsonIp.data();
signed char newEncryptPsw[512] = { 0 };
int nMaxCount = 100;
SXSDK_CONFIG_NET_COMMON* pRet = new SXSDK_CONFIG_NET_COMMON[nMaxCount];
SXSDK_CONFIG_NET_COMMON* pDevice = nullptr;
ScopeSemaphoreExit guard([&pRet]() {
delete [] pRet;
});
memset(pRet, 0, sizeof(SXSDK_CONFIG_NET_COMMON) * nMaxCount);
int nCount = XSDK_SearchDevicesSyn(pRet, nMaxCount);
if (nCount <= 0) {
qInfo() << QString("SN(%1): 有线搜索不到设备").arg(device.sSn);
return false;
}
for (int i = 0; i < nCount; i++) {
qInfo() << QString("[%1][IP:%2.%3.%4.%5][SN:%6][Mac:%7]")
.arg(i)
.arg(pRet[i].HostIP.c[0])
.arg(pRet[i].HostIP.c[1])
.arg(pRet[i].HostIP.c[2])
.arg(pRet[i].HostIP.c[3])
.arg(pRet[i].sSn)
.arg(pRet[i].sMac);
if (QString(pRet[i].sSn) == device.sSn) {
pDevice = new SXSDK_CONFIG_NET_COMMON;
memset(pDevice, 0, sizeof(SXSDK_CONFIG_NET_COMMON));
memcpy(pDevice, &pRet[i], sizeof(SXSDK_CONFIG_NET_COMMON));
break;
}
}
if (pDevice == nullptr) {
qInfo() << QString("SN(%1): 有线未找到匹配的设备").arg(device.sSn);
} else {
// 处理找到的设备信息
qInfo() << QString("有线找到匹配的设备: SN(%1) IP:%2.%3.%4.%5 Mac:%6")
.arg(pDevice->sSn)
.arg(pDevice->HostIP.c[0])
.arg(pDevice->HostIP.c[1])
.arg(pDevice->HostIP.c[2])
.arg(pDevice->HostIP.c[3])
.arg(pDevice->sMac);
// 在这里进行设备IP地址的更改操作
SXSDK_CONFIG_NET_COMMON_V2 devInfo;
memset(&devInfo, 0, sizeof(SXSDK_CONFIG_NET_COMMON_V2));
QString new_ip=QString("%1.%2.%3.%4")
.arg(pDevice->HostIP.c[0])
.arg(pDevice->HostIP.c[1])
.arg(pDevice->HostIP.c[2])
.arg(pDevice->HostIP.c[3]);
if(vides_data::isInSameSubnet(device.reachableIp,new_ip,subnetMask)){
device.isMask=true;
}else{
device.isMask=false;
}
device.nDevPort=pDevice->TCPPort;
XSDK_EncryptPassword("", newEncryptPsw, 512);
device.UserName= QString::fromUtf8(pDevice->DefaultUser,sizeof(pDevice->DefaultUser));
device.password= QString::fromUtf8(pDevice->DefaultPwd,sizeof(pDevice->DefaultPwd));
devInfo.HostIP.l= inet_addr(charIp);
devInfo.Gateway.l = inet_addr(gateway.toStdString().c_str());
devInfo.Submask.l = inet_addr(subnetMask.toStdString().c_str());
strcpy(devInfo.HostName, pDevice->HostName);
devInfo.HttpPort = pDevice->HttpPort;
strcpy(devInfo.LocalMac, mac);
devInfo.MaxBps = pDevice->MaxBps;
devInfo.MaxConn = pDevice->MaxConn;
devInfo.MonMode = pDevice->MonMode;
devInfo.nPasswordType = 1;
strcpy(devInfo.sMac, pDevice->sMac);
strcpy(devInfo.Password, (const char*)newEncryptPsw);
devInfo.SSLPort = pDevice->SSLPort;
devInfo.TCPPort = pDevice->TCPPort;
devInfo.TransferPlan = pDevice->TransferPlan;
devInfo.UDPPort = pDevice->UDPPort;
strcpy(devInfo.UserName, pDevice->DefaultUser);
int nRet = XSDK_ModifyDevIP((const char*)&devInfo, sizeof(SXSDK_CONFIG_NET_COMMON_V2), 10000);
delete pDevice;
if(nRet<0){
qInfo()<<QString("SN(%1): 有线修复ip失败错误码:%2").arg(device.sSn).arg(nRet);
return false;
}
}
return true;
}
bool NonConnectedCameraHandle::wifiChangeIp(QString &Ip, bool is_connect,
int h_device,QString &sSn){
Common & instace= Common::getInstance();
XSDK_CFG::NetWork_Wifi wif;
printWifi(h_device,wif);
if(is_connect){
if(!isWifiConnect(h_device,wif)){
qInfo()<<QString("SN(%1): 不是wifi连接").arg(sSn);
return false;
}
}
QString hex=instace.DecIpToHexIp(Ip);
QByteArray && byIp = hex.toUtf8();
const char * cpIp= byIp.data();
wif.HostIP.SetValue(cpIp);
wif.Enable.SetValue(true);
wif.KeyType.SetValue(1);
wif.EncrypType.SetValue("AES");
wif.Auth.SetValue("WPA2PSK");
const char* wipCfg = wif.ToString();
char szOutBuffer[512] = { 0 };
int nLen = sizeof(szOutBuffer);
int res =XSDK_DevSetSysConfigSyn(h_device, JK_NetWork_Wifi, wipCfg, strlen(wipCfg), szOutBuffer, &nLen, 3000, EXCMD_CONFIG_SET);
if(res<0){
qInfo()<<QString("SN(%1): 无线修改wifi失败:%2").arg(sSn).arg(res);
return false;
}
return true;
}
bool NonConnectedCameraHandle::isWifiConnect(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
char szOutBuffer[4000] = { 0 };
int nInOutSize = sizeof(szOutBuffer);
// 获取并解析配置
int nResult = XSDK_DevGetSysConfigSyn(hDevice, JK_NetWork_Wifi, szOutBuffer, &nInOutSize, 3000, EXCMD_CONFIG_GET);
qInfo()<<szOutBuffer;
if (nResult >= 0) {
cfg.Parse(szOutBuffer);
return strlen(cfg.SSID.Value())>0;
} else {
printf("Failed to get Wi-Fi configuration. Error code: %d\n", nResult);
return false;
}
}
void NonConnectedCameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
char szOutBuffer[4000] = { 0 };
int nInOutSize = sizeof(szOutBuffer);
// 获取并解析配置
int nResult = XSDK_DevGetSysConfigSyn(hDevice, JK_NetWork_Wifi, szOutBuffer, &nInOutSize, 3000, EXCMD_CONFIG_GET);
qInfo()<<szOutBuffer;
if (nResult >= 0) {
cfg.Parse(szOutBuffer);
} else {
printf("Failed to get Wi-Fi configuration. Error code: %d\n", nResult);
}
}
int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
QString sUserName, QString sPassword, int nTimeout) {
SXSDKLoginParam *loginParam=new SXSDKLoginParam();
ScopeSemaphoreExit guard([&loginParam]() {
Common & instace= Common::getInstance();
MainWindow::sp_this->setIsResetting(false);
instace.deleteObj(loginParam);
});
QByteArray byteArray = sDevId.toUtf8();
char* cDevid=byteArray.data();
strcpy(loginParam->sDevId, cDevid);
loginParam->nDevPort=nDevPort;
QByteArray byteName = sUserName.toUtf8();
char* cName=byteName.data();
strcpy(loginParam->sUserName, cName);
if(sPassword.length()>0){
QByteArray bytePassword = sPassword.toUtf8();
strcpy(loginParam->sPassword, bytePassword.constData());
}else{
strcpy(loginParam->sPassword, "");
}
loginParam->nCnnType=EDEV_CNN_TYPE_AUTO;
int loginResult =XSDK_DevLoginSyn(loginParam,nTimeout);
if(loginResult<0){
qInfo() << QString("SN(%1): 登录设备失败").arg("NonConnectedCameraHandle");;
return loginResult;
}
return loginResult;
}
bool NonConnectedCameraHandle::distributionNetwork(QString &ip,QString &sSn,int hDevice ){
if(vides_data::pingAddress(ip)){
qInfo()<<QString("SN(%1): 当前ip已被使用%2").arg(sSn).arg(ip);
}
int old=hDevice;
MainWindow::sp_this->setIsResetting(true);
ScopeSemaphoreExit guard([]() {
MainWindow::sp_this->setIsResetting(false);
});
vides_data::localDevice device;
QString reachableIp;
if(ip.length()>0){
reachableIp=ip;
qInfo()<<QString("SN(%1): reachableIpIP地址%2").arg(sSn).arg(ip);
qInfo()<<QString("SN(%1): IP地址%2").arg(sSn).arg(reachableIp);
}else {
reachableIp= vides_data::findReachableIp();
if (!reachableIp.isEmpty()) {
qInfo()<<QString("SN(%1): 未使用的IP地址%2").arg(sSn).arg(reachableIp);
} else {
qInfo()<<QString("SN(%1): 找不到可使用的IP地址").arg(sSn);
return false ;
}
}
device.reachableIp=reachableIp;
device.sSn=sSn;
device.isMask=true;
//不在同一网段,改ip不成功则失败
//在同一网段,改IP不成功则登录后尝试改wif'
bool result= changeCameraIp(device);
if(!result ){
if(!device.isMask ){
return false;
}else {
if(old<0){
old=sdkDevLoginSyn(reachableIp,device.nDevPort,device.UserName,device.password,3000);
if(old<0){
qInfo()<<QString("SN(%1): WIFI修改IP,新生成句柄失败").arg(sSn);
}else {
result=wifiChangeIp(reachableIp,false,old,sSn);
}
}else {
qInfo()<<QString("newIP(%1): wifiChangeIp").arg(reachableIp);
result=wifiChangeIp(reachableIp,false,old,sSn);
XSDK_DevLogout(old);
}
}
}
return result;
}
#ifndef NONCONNECTEDCAMERAHANDLE_H
#define NONCONNECTEDCAMERAHANDLE_H
#include "XSDKPublic.h"
#include "XNetSDKSyn.h"
#include "XNetSDKDefine.h"
#include "VidesData.h"
#include "Common.h"
#include "ScopeSemaphoreExit.h"
#include "Json_Header/NetWork_NetCommon.h"
#include "Json_Header/NetWork_Wifi.h"
#include <arpa/inet.h>
class NonConnectedCameraHandle
{
public:
static NonConnectedCameraHandle* getInstance(); // 单例模式获取实例的静态成员函数
//有线修改相机ip
bool changeCameraIp(vides_data::localDevice &device);
//无线修改相机ip
bool wifiChangeIp(QString &Ip, bool is_connect, int h_device,QString &sn);
bool isWifiConnect(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg);
void printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg);
bool distributionNetwork(QString &ip,QString &sSn,int hDevice);
int sdkDevLoginSyn(QString sDevId, int nDevPort,
QString sUserName, QString sPassword, int nTimeout) ;
private:
NonConnectedCameraHandle(); // 构造函数声明为私有
~NonConnectedCameraHandle(); // 析构函数声明为私有
static NonConnectedCameraHandle* m_instance; // 指向实例的指针
};
#endif // NONCONNECTEDCAMERAHANDLE_H
......@@ -10,6 +10,7 @@ ParkingSpaceInfo::ParkingSpaceInfo(){
}
ParkingSpaceInfo::~ParkingSpaceInfo(){
qInfo() << "ParkingSpaceInfo:关闭";
}
void ParkingSpaceInfo::addQueue(RecognizedInfo &info){
QMutexLocker locker(&queueMutex);
......
......@@ -48,6 +48,8 @@ struct requestDeviceStatus
std::list<requestCameraInfo>camera_info_list;
requestDeviceStatus() {}
};
struct responseStsCredentials{
QString access_key_id;
QString access_key_secret;
......@@ -107,19 +109,6 @@ struct localDeviceStatus
QString password;
localDeviceStatus() {}
};
struct localDevice
{
QString sSn;
QString reachableIp;
bool isMask;
int nDevPort;
int TCPPort;
int ChannelNum;
QString UserName;
QString password;
localDevice() {}
};
struct requestFaceReconition
{
QString id;
......@@ -261,6 +250,7 @@ struct Camera {
struct FaceConfig {
bool isOn;
int faceNumbers;
uint64 faceFrequency;
float confidence;
int faceLen;
quint64 updateAt;
......@@ -291,7 +281,7 @@ struct UniformConfig {
};
struct HumanConfig{
bool isOn;
uint64 faceFrequency;
int humanDetectionLen;
quint64 updateAt;
};
......@@ -323,11 +313,10 @@ struct responseMqttData{
uint8_t msg_type;
QString sn;
QString uniq;
QString msg_body;
};
struct requestMqttData{
QString msg;
QString sn;
int code;
QString uniq;
};
......@@ -411,66 +400,16 @@ inline QString getDefaultGateway() {
return gateway;
}
inline void convertQStringToSXSDK_IPAddress(const QString& ipString, SXSDK_IPAddress& hostIP) {
QHostAddress address(ipString);
quint32 ip = address.toIPv4Address();
hostIP.c[0] = (ip >> 24) & 0xFF;
hostIP.c[1] = (ip >> 16) & 0xFF;
hostIP.c[2] = (ip >> 8) & 0xFF;
hostIP.c[3] = ip & 0xFF;
}
inline bool isInSameSubnet(const QString &ip1, const QString &ip2, const QString &mask)
{
QHostAddress address1(ip1);
QHostAddress address2(ip2);
QHostAddress subnetMask(mask);
// 将IP地址和子网掩码从QHostAddress转换成quint32形式
quint32 addr1 = address1.toIPv4Address();
quint32 addr2 = address2.toIPv4Address();
quint32 maskAddr = subnetMask.toIPv4Address();
// 进行AND操作
quint32 result1 = addr1 & maskAddr;
quint32 result2 = addr2 & maskAddr;
// 比较结果
return result1 == result2;
}
// 获取本地 MAC 地址、子网掩码和网关IP
inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask, QString &gateway) {
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, interfaces) {
if (interface.flags().testFlag(QNetworkInterface::IsUp) &&
interface.flags().testFlag(QNetworkInterface::IsRunning) &&
!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
mac = interface.hardwareAddress();
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
foreach (QNetworkAddressEntry entry, addressEntries) {
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
subnetMask = entry.netmask().toString();
gateway = entry.broadcast().toString(); // 这里假设网关是广播地址
return true;
}
}
}
}
return false; // Return false if no suitable interface is found
}
inline bool pingAddress(const QString &address) {
QProcess process;
QString program = "ping";
QStringList arguments;
#ifdef Q_OS_WIN
#ifdef Q_OS_WIN
arguments << "-n" << "1" << address;
#else
#else
arguments << "-c" << "1" << address;
#endif
#endif
process.start(program, arguments);
if (!process.waitForStarted()) {
......@@ -486,28 +425,11 @@ inline bool pingAddress(const QString &address) {
QString output(process.readAllStandardOutput());
// 简单的 Ping 成功检查逻辑
#ifdef Q_OS_WIN
#ifdef Q_OS_WIN
return output.contains("TTL=");
#else
#else
return output.contains("1 packets transmitted, 1 received");
#endif
}
inline QString findReachableIp() {
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
for (const QHostAddress &address : ipAddressesList) {
if (address.protocol() == QAbstractSocket::IPv4Protocol && !address.isLoopback()) {
QString ipAddress = address.toString();
QString currentSubnet = ipAddress.left(ipAddress.lastIndexOf('.') + 1); // 返回子网部分
for (int i = 254; i >= 1; --i) { // 从 254 开始递减
QString ip = currentSubnet + QString::number(i);
if (!pingAddress(ip)) {
return ip;
}
}
}
}
return QString(); // 如果没有找到可用的 IP 地址,则返回空字符串
#endif
}
inline int GetCpuIdByAsm_arm(char* cpu_id)
......
......@@ -13,8 +13,6 @@ TEMPLATE = app
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += APP_VERSION=\\\"1.3.2\\\"
DEFINES += QT_MESSAGELOGCONTEXT
DEFINES += QT_NO_DEBUG_OUTPUT
QMAKE_LIBDIR += /usr/local/lib
......@@ -26,9 +24,6 @@ INCLUDEPATH+=/usr/local/include/human
INCLUDEPATH+=/usr/local/include/CImg
INCLUDEPATH+=/usr/local/include/mqtt
# 禁用所有警告
QMAKE_CXXFLAGS += -w
......@@ -108,8 +103,7 @@ SOURCES += \
FaceReconitionHandle.cpp \
AlgorithmTaskManage.cpp \
BaseAlgorithm.cpp \
MqttSubscriber.cpp \
NonConnectedCameraHandle.cpp
MqttSubscriber.cpp
HEADERS += \
Common.h \
......@@ -129,8 +123,7 @@ HEADERS += \
FaceReconitionHandle.h \
AlgorithmTaskManage.h \
BaseAlgorithm.h \
MqttSubscriber.h \
NonConnectedCameraHandle.h
MqttSubscriber.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
......
......@@ -3,7 +3,7 @@
MainWindow* MainWindow::sp_this=nullptr;
MainWindow::MainWindow():isResetting(false)
MainWindow::MainWindow()
{
sp_this=this;
......@@ -133,7 +133,6 @@ MainWindow::MainWindow():isResetting(false)
this->mqttConfig= config.mqttConfig;
runOrRebootMqtt(mqttConfig,httpurl,serialNumber);
}
void MainWindow::runOrRebootMqtt(vides_data::MqttConfig &mqtt_config,QString &httpUrl,QString &serialNumber){
MqttSubscriber* subscriber = MqttSubscriber::getInstance(this);
subscriber->init(mqtt_config,httpUrl,serialNumber);
......@@ -209,34 +208,7 @@ void MainWindow::divParameterUpdate(vides_data::responseConfig &cloudConfig,QStr
}
}
void MainWindow::modifySnMapIp(QString &sn,QString &ip){
qSetting->beginGroup("SnMapIp");
QStringList lokeys = qSetting->childKeys();
bool keyExists = false;
// 遍历现有键
foreach(QString lk, lokeys) {
// 如果键存在,修改对应的值
if(lk == sn) {
qSetting->setValue(lk, ip);
keyExists = true;
break;
}
}
// 如果键不存在,添加新键值对
if(!keyExists) {
qSetting->setValue(sn, ip);
}
qSetting->endGroup();
}
void MainWindow::findSnMapIp(QString &sn,QString &ip){
// 直接通过键路径获取 IP 地址
ip = qSetting->value(QString("SnMapIp/%1").arg(sn), "").toString();
}
CameraHandle* MainWindow::findHandle(QString sn){
for (auto it = faceDetectionParkingPushs.begin(); it != faceDetectionParkingPushs.end(); ++it) {
......@@ -492,15 +464,9 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){
void MainWindow::clearOfflineCameraHandle(QString sDevId, int nDevPort) {
emit shutdownSignals(sDevId,nDevPort);
}
void MainWindow::setIsResetting(bool running) {
this->isResetting.store(running, std::memory_order_release);
}
//平台有 盒子没有 盒子开启
//平台没有 盒子有 盒子关闭
void MainWindow::startCamera(const QString &httpurl){
if(this->isResetting.load(std::memory_order_acquire)){
qInfo()<<"正在执行复位GB28181 程序,请等待";
}
Common & instace= Common::getInstance();
MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
QString nonConstHttpUrl = std::remove_const<QString>::type(httpurl);
......@@ -534,10 +500,10 @@ void MainWindow::startCamera(const QString &httpurl){
}
vides_data::responseConfig cloudConfig;
HttpService http_config(httpurl);
vides_data::response *res_config= http_config.httpDeviceConfig(serialNumber,cloudConfig);
httpService.setHttpUrl(httpurl);
vides_data::response *res_config= httpService.httpDeviceConfig(serialNumber,cloudConfig);
if(res_config->code!=0){
qInfo()<<"请求远程商户配置失败"<<res_config->msg<<res_config->code;
qInfo()<<"请求远程商户配置失败";
instace.deleteObj(res_config);
return ;
}
......@@ -550,10 +516,12 @@ void MainWindow::startCamera(const QString &httpurl){
QString ipAddress= QString("%1.%2.%3.%4").arg(localDevice->HostIP.c[0]).arg(localDevice->HostIP.c[1]).arg(localDevice->HostIP.c[2]).arg(localDevice->HostIP.c[3]);
//this->gatewayRandomIp(ipAddress);
QString key = ipAddress + ":" + QString::number(localDevice->TCPPort);
HttpService http_device(httpurl);
httpService.setHttpUrl(httpurl);
vides_data::responseConfig devConfig;
vides_data::response *devRes=http_device.httpDeviceConfig(device.sSn,devConfig);
vides_data::response *devRes=httpService.httpDeviceConfig(device.sSn,devConfig);
if(devRes->code!=0){
qInfo()<<"请求相机配置失败";
instace.deleteObj(devRes);
......@@ -588,24 +556,8 @@ void MainWindow::startCamera(const QString &httpurl){
reStatus.camera_info_list.push_front(camera_info);
HttpService http_gb28181(httpurl);
vides_data::response *res=http_gb28181.httpFindGb28181Config(camera_info.sSn);
if(res->code!=0){
qInfo()<<"请求摄像头gb28181配置失败";
instace.deleteObj(res);
return;
}
vides_data::responseGb28181 *gb281 = reinterpret_cast<vides_data::responseGb28181*>(res->data);
offlineCameraHandle->updateSdkDevSpvMn(gb281);
instace.deleteObj(gb281);
instace.deleteObj(res);
__uint8_t new_algorithm= intToUint8t(devConfig.faceConfig.isOn,devConfig.licensePlateConfig.isOn,devConfig.uniformConfig.isOn,devConfig.humanConfig.isOn);
uint64 face_frequency=devConfig.humanConfig.faceFrequency;
offlineCameraHandle->initFaceFrequency(face_frequency);
offlineCameraHandle->cameraParameterUpdate(devConfig);
offlineCameraHandle->initAlgorithmPermissions(new_algorithm);
if(!offlineCameraHandle->compareLists(device.areas)){
......@@ -628,8 +580,9 @@ void MainWindow::startCamera(const QString &httpurl){
// 清空 localDevices 容器
localDevices.clear();
}
HttpService http_div(httpurl);
vides_data::response *res=http_div.httpPostDeviceStatus(reStatus);
httpService.setHttpUrl(httpurl);
vides_data::response *res=httpService.httpPostDeviceStatus(reStatus);
if(res->code!=0){
qInfo()<<"盒子状态上报失败 code:"<<res->code<<"msg:"<<res->msg;
}
......@@ -771,6 +724,7 @@ void MainWindow::initEncodeToString(QString &enCodeJson) {
}
bool MainWindow::iniWorkSpVMn(vides_data::responseGb28181 *gb28181,QString &workSpWMn,QString &sn){
qInfo()<<"iniWorkSpVMn=="<<sn;
QString jsonfile=QCoreApplication::applicationDirPath()+"/camera_config.json";
bool isEqual=true;
......@@ -1021,6 +975,8 @@ __uint8_t MainWindow::intToUint8t(bool faceAlgorithm, bool licensePlateAlgorithm
// 车牌识别对应最低位(第0位)
result |= (licensePlateAlgorithm ? 1 : 0);
qInfo()<<"算法结果"<<result;
return result;
}
void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data::responseConfig &devConfig,const std::list<vides_data::responseArea>&areas,std::list<vides_data::requestCameraInfo>&camera_info_list){
......@@ -1032,10 +988,9 @@ void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data:
CameraHandle * cameraHandle =new CameraHandle(parameter.sDevId,parameter.httpUrl,parameter.sSn,parameter.channel,image_save,heightReference,devConfig);
int sdk_handle=cameraHandle->sdkDevLoginSyn(parameter.sDevId,parameter.nDevPort,parameter.sUserName,parameter.sPassword,3000);
qDebug() << QString("SN(%1): 句柄为%2").arg(parameter.sSn).arg(sdk_handle);
qInfo()<<"句柄为2:"<<sdk_handle;
if(sdk_handle<=0){
qInfo() << QString("SN(%1): 登录失败").arg(parameter.sSn);
qInfo() << "登录失败";
return ;
}
mediaFaceImage->setMap(sdk_handle,cameraHandle);
......@@ -1047,11 +1002,11 @@ void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data:
int synTime=devConfig.camera.devSnapSynTimer;
uint64 face_frequency=devConfig.humanConfig.faceFrequency;
uint64 face_frequency=devConfig.faceConfig.faceFrequency;
float carConfidenceMax=devConfig.licensePlateConfig.carConfidenceMax;
float carConfidenceMin=devConfig.licensePlateConfig.carConfidenceMin;
cameraHandle->initSdkRealTimeDevSnapSyn(synTime,face_frequency);
cameraHandle->initSdkRealTimeDevSnapSyn(sdk_handle,synTime,face_frequency);
cameraHandle->setCarConfidenceMaxAndMin(carConfidenceMax,carConfidenceMin);
// QString pwd="admin2024";
......@@ -1061,11 +1016,10 @@ void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data:
camera_info.sSn=parameter.sSn;
camera_info.ip_addr=parameter.sDevId;
cameraHandle->findFirmwareVersion(camera_info.firmware_version);
modifySnMapIp(parameter.sSn,parameter.sDevId);
camera_info_list.push_front(camera_info);
camera_info_list.push_front(camera_info);
__uint8_t new_algorithm= intToUint8t(devConfig.faceConfig.isOn,devConfig.licensePlateConfig.isOn,devConfig.uniformConfig.isOn,devConfig.humanConfig.isOn);
__uint8_t new_algorithm= (devConfig.faceConfig.isOn,devConfig.licensePlateConfig.isOn,devConfig.uniformConfig.isOn,devConfig.humanConfig.isOn);
cameraHandle->initAlgorithmPermissions(new_algorithm);
cameraHandle->initParkingSpaceInfo(areas);
......
......@@ -52,8 +52,6 @@ public:
CameraHandle* findHandle(QString sn);
void modifySnMapIp(QString &sn,QString &ip);
void findSnMapIp(QString &sn,QString &ip);
void sendJsonResponse(QTcpSocket* socket, int code, const QString& data, const QString& msg);
void sendEmptyResponse(QTcpSocket* socket);
......@@ -84,8 +82,6 @@ public:
void deleteCloudNotCamer (const std::map<QString,vides_data::localDeviceStatus*>& localDevices,
const std::list<vides_data::responseDeviceStatus>& devices);
void setIsResetting(bool running);
~MainWindow();
signals:
......@@ -125,7 +121,6 @@ private:
vides_data::MqttConfig mqttConfig;
std::atomic<bool> isResetting;
};
#endif // MAINWINDOW_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment