Commit 483aea37 by “liusq”

修改一建配置ip

parent eb6e5838
......@@ -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,15 +182,17 @@ 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();
// 解析 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.";
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 {
......@@ -199,51 +201,57 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
//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) {
qInfo() << "不存在该相机";
res = -1;
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 地址
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) ?"成功":"失败";
request.uniq= response.uniq;
sendSubscriptionConfirmation(request,response.sn);
MQTTAsync_freeMessage(&m);
MQTTAsync_free(topicName);
return 1;
......
#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,14 +420,32 @@ 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) {
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)) {
interface.flags().testFlag(QNetworkInterface::IsRunning) &&
!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
mac = interface.hardwareAddress();
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
......
......@@ -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,8 +1061,9 @@ 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