Commit 483aea37 by “liusq”

修改一建配置ip

parent eb6e5838
......@@ -412,47 +412,6 @@ int CameraHandle::callbackFunction(XSDK_HANDLE hObject, QString &szString) {
updateImage(image, currentTime);
}
/**
增加一键配网mqtt命令
对应设备连接局域网得情况下可通过盒子配置IP,实现快捷配网。
消息输入IP时配置为对应IP,不输入时则自动配置相同局域网网段ip
* @brief CameraHandle::distributionNetwork
*/
bool CameraHandle::distributionNetwork(QString &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);
});
QString reachableIp;
MainWindow::sp_this->modifySnMapIp(sSn,url);
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 ;
}
}
bool result= changeCameraIp(reachableIp);
if(!result ){
qInfo()<<QString("newIP(%1): wifiChangeIp").arg(reachableIp);
result=wifiChangeIp(reachableIp,false,old);
}
return result;
}
void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
if(hDevice<=0){
......@@ -1058,10 +1017,11 @@ void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
需确认修改IP后抓图是否正常,如不正常需在命令开始前增加删除句柄,命令完成后增加句柄以保证抓图实时性
*/
int CameraHandle::resetGb28181(){
NonConnectedCameraHandle *connectedCameraHandle =NonConnectedCameraHandle::getInstance();
int old=hDevice;
MainWindow::sp_this->setIsResetting(true);
bool is_wifi=false;
ScopeSemaphoreExit guard([this]() {
ScopeSemaphoreExit guard([]() {
MainWindow::sp_this->setIsResetting(false);
});
this->updateSdkDevStatus(false);
......@@ -1075,10 +1035,14 @@ int CameraHandle::resetGb28181(){
}
this->hDevice=-1;
MainWindow::sp_this->modifySnMapIp(sSn,url);
bool result= changeCameraIp(reachableIp);
vides_data::localDevice device;
device.reachableIp=reachableIp;
device.sSn=sSn;
bool result= connectedCameraHandle->changeCameraIp(device);
int newHandle=-1;
if(!result ){
result=wifiChangeIp(reachableIp,false,old);
result=connectedCameraHandle->wifiChangeIp(reachableIp,false,old,sSn);
is_wifi=true;
if(result){
//老句柄抓图不正常了
......@@ -1101,7 +1065,7 @@ int CameraHandle::resetGb28181(){
MainWindow::sp_this->findSnMapIp(this->sSn,old_ip);
if(old_ip.length()>0){
if(is_wifi){
result=wifiChangeIp(old_ip,true,newHandle);
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);
......@@ -1111,7 +1075,9 @@ int CameraHandle::resetGb28181(){
}
}else {
bool result= this->changeCameraIp(old_ip);
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){
......@@ -1128,166 +1094,9 @@ int CameraHandle::resetGb28181(){
return this->updateSdkDevStatus(true);
}
bool CameraHandle::changeCameraIp(QString &reachableIp){
QString localMac, subnetMask, gateway;
bool success =vides_data::GetNetworkInfoByQNetworkInterface(localMac, subnetMask, gateway);
if (!success) {
qInfo() <<QString("SN(%1): 获取本地MAC失败").arg(sSn);
return false ;
}
QByteArray && byJson = localMac.toUtf8();
const char * mac= byJson.data();
QByteArray && byJsonIp = 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(sSn);
delete[] pRet;
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) == 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(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));
XSDK_EncryptPassword("", newEncryptPsw, 512);
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, loginParam->sUserName);
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(sSn).arg(nRet);
return false;
}
}
return true;
}
bool CameraHandle::wifiChangeIp(QString &Ip, bool is_connect, int h_device){
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=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;
}
QString CameraHandle::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; // 返回最终的十六进制表示
}
bool CameraHandle::sdkWifi(QString &pwd,QString &ssid){
Common & instace= Common::getInstance();
XSDK_CFG::NetWork_Wifi wif;
printWifi(hDevice,wif);
......@@ -1296,7 +1105,7 @@ bool CameraHandle::sdkWifi(QString &pwd,QString &ssid){
wif.Keys.SetValue(cpwd);
QString reachableIp= vides_data::findReachableIp();
QString hex=DecIpToHexIp(reachableIp);
QString hex=instace.DecIpToHexIp(reachableIp);
QByteArray && byJson = ssid.toUtf8();
const char * cssid= byJson.data();
......
......@@ -14,6 +14,7 @@
#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"
......@@ -58,7 +59,6 @@ public:
void clearCameraHandle();
bool distributionNetwork(QString &ip);
// void rebindTimer(int hDevice);
//相机参数更新
void cameraParameterUpdate(vides_data::responseConfig &cloudConfig);
......@@ -91,11 +91,6 @@ public:
void setCarConfidenceMaxAndMin(float carConfidenceMax,float carConfidenceMin);
QString DecIpToHexIp(const QString& decIp);
//修改相机IP
bool wifiChangeIp(QString &Ip,bool is_connect, int h_device);
//设置相机连接的wifi
bool sdkWifi(QString &pwd,QString &ssid);
//时间设置
......@@ -118,8 +113,6 @@ public:
void findFirmwareVersion(QString &firmwareVersion);
//复位GB28181
int resetGb28181();
//修改相机ip
bool changeCameraIp(QString &reachableIp);
//获取ip
void findIp(QString &ip);
......
......@@ -63,7 +63,36 @@ void Common::setImages(QString images){
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();
......
......@@ -45,6 +45,8 @@ public:
QString GetLocalIp();
QString DecIpToHexIp(const QString& decIp);
template <typename T>
const T& clamp(const T& v, const T& lo, const T& hi)
{
......
......@@ -281,4 +281,3 @@ int MediaFaceImage::CameraImage(XSDK_HANDLE hMedia,int nChannel,std::vector<ucha
// 返回实际填入Vector的数据大小
return pInOutBufferSize;
}
......@@ -34,6 +34,7 @@ public:
void clearCurrentDevice(int hObject);
void setMap(int &key,CameraHandle*value);
private:
MediaFaceImage(); // 构造函数声明为私有
~MediaFaceImage(); // 析构函数声明为私有
......
......@@ -182,6 +182,7 @@ 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();
......@@ -193,51 +194,58 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
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);
if (cameraHandle == nullptr) {
int hDevice=0;
if (cameraHandle == nullptr ) {
if(response.msg_type == 6){
hDevice=-1;
}else {
qInfo() << "不存在该相机";
res = -1;
} else {
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);
}else if (response.msg_type == 6) {
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=cameraHandle->distributionNetwork(ipAddress);
}else if (response.msg_type == 7) {
// 提取 ip 地址
} 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)==true?0:0x01);
res = (cameraHandle->sdkWifi(password, username) ? 0 : 0x01);
} else {
qInfo() << "IP username not found in msg_body.";
qInfo() << "IP password not found in msg_body.";
}
break;
}
else if (response.msg_type == 8) {
res=(cameraHandle->resetGb28181()==true?0:0x01);
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) ?"成功":"失败";
......
#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
......@@ -107,7 +107,18 @@ 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
{
......@@ -409,6 +420,24 @@ inline void convertQStringToSXSDK_IPAddress(const QString& ipString, SXSDK_IPAdd
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) {
......
......@@ -108,7 +108,8 @@ SOURCES += \
FaceReconitionHandle.cpp \
AlgorithmTaskManage.cpp \
BaseAlgorithm.cpp \
MqttSubscriber.cpp
MqttSubscriber.cpp \
NonConnectedCameraHandle.cpp
HEADERS += \
Common.h \
......@@ -128,7 +129,8 @@ HEADERS += \
FaceReconitionHandle.h \
AlgorithmTaskManage.h \
BaseAlgorithm.h \
MqttSubscriber.h
MqttSubscriber.h \
NonConnectedCameraHandle.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
......
......@@ -1061,9 +1061,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);
__uint8_t new_algorithm= intToUint8t(devConfig.faceConfig.isOn,devConfig.licensePlateConfig.isOn,devConfig.uniformConfig.isOn,devConfig.humanConfig.isOn);
cameraHandle->initAlgorithmPermissions(new_algorithm);
......
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