Commit eb6e5838 by “liusq”

复位gb28181和配置WIFI

parent 8f978a25
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <QSemaphore> #include <QSemaphore>
#include <atomic> #include <atomic>
#include <arpa/inet.h>
enum CAR_INFORMATION { enum CAR_INFORMATION {
Exit, //出场 Exit, //出场
...@@ -57,11 +58,12 @@ public: ...@@ -57,11 +58,12 @@ public:
void clearCameraHandle(); void clearCameraHandle();
bool distributionNetwork(QString &ip);
// void rebindTimer(int hDevice); // void rebindTimer(int hDevice);
//相机参数更新 //相机参数更新
void cameraParameterUpdate(vides_data::responseConfig &cloudConfig); void cameraParameterUpdate(vides_data::responseConfig &cloudConfig);
void initSdkRealTimeDevSnapSyn(int hDevice,int syn_timer,uint64 face_frequency); void initSdkRealTimeDevSnapSyn(int syn_timer,uint64 face_frequency);
void notificationUpdateImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence); void notificationUpdateImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence);
...@@ -85,10 +87,17 @@ public: ...@@ -85,10 +87,17 @@ public:
void printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg); 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); void setCarConfidenceMaxAndMin(float carConfidenceMax,float carConfidenceMin);
QString DecIpToHexIp(const QString& decIp);
//修改相机IP
bool wifiChangeIp(QString &Ip,bool is_connect, int h_device);
//设置相机连接的wifi //设置相机连接的wifi
void sdkWifi(QString &pwd,QString &ssid); bool sdkWifi(QString &pwd,QString &ssid);
//时间设置 //时间设置
void sdkDevSystemTimeZoneSyn(QString &time); void sdkDevSystemTimeZoneSyn(QString &time);
//录像设置 //录像设置
...@@ -107,6 +116,10 @@ public: ...@@ -107,6 +116,10 @@ public:
int deviceShutdown(); int deviceShutdown();
//获取固件版本 //获取固件版本
void findFirmwareVersion(QString &firmwareVersion); void findFirmwareVersion(QString &firmwareVersion);
//复位GB28181
int resetGb28181();
//修改相机ip
bool changeCameraIp(QString &reachableIp);
//获取ip //获取ip
void findIp(QString &ip); void findIp(QString &ip);
...@@ -162,7 +175,7 @@ signals: ...@@ -162,7 +175,7 @@ signals:
void afterDownloadFile( int id,int recognitionType,QString ossUrl); void afterDownloadFile( int id,int recognitionType,QString ossUrl);
private slots: private slots:
void sdkRealTimeDevSnapSyn(int hDevice); void sdkRealTimeDevSnapSyn();
void pushRecordToCloud(int id,int recognitionType,QString ossUrl); void pushRecordToCloud(int id,int recognitionType,QString ossUrl);
//void releaseSemaphore(); //void releaseSemaphore();
...@@ -199,6 +212,9 @@ private : ...@@ -199,6 +212,9 @@ private :
int image_save; int image_save;
std::atomic<uint64> faceCount; std::atomic<uint64> faceCount;
std::atomic<bool> isOperateGb28181{false};
uint64 face_frequency; uint64 face_frequency;
__uint8_t algorithmPermissions; __uint8_t algorithmPermissions;
......
...@@ -62,6 +62,8 @@ void Common::setImages(QString images){ ...@@ -62,6 +62,8 @@ void Common::setImages(QString images){
images.append("/"); images.append("/");
this->images=images; this->images=images;
} }
QString Common::GetLocalIp() { QString Common::GetLocalIp() {
QString ipAddress; QString ipAddress;
QList<QHostAddress> list = QNetworkInterface::allAddresses(); QList<QHostAddress> list = QNetworkInterface::allAddresses();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QMessageAuthenticationCode> #include <QMessageAuthenticationCode>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <map>
#include <QDebug> #include <QDebug>
class Common class Common
{ {
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
QString getVideoDownload(); QString getVideoDownload();
void setVideoDownload(QString videoDownload); void setVideoDownload(QString videoDownload);
QString getImages(); QString getImages();
void setImages(QString images); void setImages(QString images);
...@@ -61,6 +62,7 @@ private: ...@@ -61,6 +62,7 @@ private:
QString videoOut; QString videoOut;
QString videoDownload; QString videoDownload;
QString images; QString images;
Common(); Common();
~Common(); ~Common();
......
...@@ -174,7 +174,7 @@ void MqttSubscriber::connectionLost(char* cause) { ...@@ -174,7 +174,7 @@ void MqttSubscriber::connectionLost(char* cause) {
int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_message* m) { int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_message* m) {
QString topic(topicName); QString topic(topicName);
QString payload = QString::fromUtf8(reinterpret_cast<const char*>(m->payload), m->payloadlen); QString payload = QString::fromUtf8(reinterpret_cast<const char*>(m->payload), m->payloadlen);
QJsonObject msgBodyOb;
vides_data::responseMqttData response; vides_data::responseMqttData response;
QJsonDocument jsonDoc = QJsonDocument::fromJson(payload.toUtf8()); QJsonDocument jsonDoc = QJsonDocument::fromJson(payload.toUtf8());
if (!jsonDoc.isNull() && jsonDoc.isObject()) { if (!jsonDoc.isNull() && jsonDoc.isObject()) {
...@@ -182,10 +182,21 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess ...@@ -182,10 +182,21 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
response.msg_type = jsonObj["msg_type"].toInt(); response.msg_type = jsonObj["msg_type"].toInt();
response.sn = jsonObj["sn"].toString(); response.sn = jsonObj["sn"].toString();
response.uniq = jsonObj["uniq"].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.";
}
}
} else { } else {
qInfo() << "Failed to parse JSON payload"; qInfo() << "Failed to parse JSON payload";
} }
//1开 2关 3 重启 4 GB28181开 5 GB28181 关 6 一键配网 7 WIFI配留 8 复位GB28181
int res = -2; int res = -2;
CameraHandle* cameraHandle = MainWindow::sp_this->findHandle(response.sn); CameraHandle* cameraHandle = MainWindow::sp_this->findHandle(response.sn);
if (cameraHandle == nullptr) { if (cameraHandle == nullptr) {
...@@ -200,29 +211,55 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess ...@@ -200,29 +211,55 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
res = cameraHandle->updateSdkDevStatus(true); res = cameraHandle->updateSdkDevStatus(true);
} else if (response.msg_type == 5) { } else if (response.msg_type == 5) {
res = cameraHandle->updateSdkDevStatus(false); 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 地址
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);
} else {
qInfo() << "IP username not found in msg_body.";
qInfo() << "IP password not found in msg_body.";
}
}
else if (response.msg_type == 8) {
res=(cameraHandle->resetGb28181()==true?0:0x01);
} }
} }
vides_data::requestMqttData request; vides_data::requestMqttData request;
request.code = (res >= 0) ? 0 : 0x01; request.code = (res >= 0) ? 0 : 0x01;
request.uniq = response.uniq; request.msg = (res >= 0) ?"成功":"失败";
request.sn = response.sn; request.uniq= response.uniq;
sendSubscriptionConfirmation(request); sendSubscriptionConfirmation(request,response.sn);
MQTTAsync_freeMessage(&m); MQTTAsync_freeMessage(&m);
MQTTAsync_free(topicName); MQTTAsync_free(topicName);
return 1; return 1;
} }
void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response) { void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn) {
QString responseTopic = "/thingshub/" + response.sn + "/device/post"; QString responseTopic = "/thingshub/" +response.uniq+ "/device/post";
QByteArray bResponseTopic = responseTopic.toUtf8(); QByteArray bResponseTopic = responseTopic.toUtf8();
char* cResponseTopic = bResponseTopic.data(); char* cResponseTopic = bResponseTopic.data();
qInfo() << "sendSubscriptionConfirmation" << cResponseTopic; qInfo()<<QString("SN(%1): sendSubscriptionConfirmation->cResponseTopic%2").arg(sn).arg(cResponseTopic);
// response.sn
QJsonObject json; QJsonObject json;
json["code"] = response.code; json["code"] = response.code;
json["uniq"] = response.uniq; json["msg"] = response.msg;
QJsonDocument jsonDoc(json); QJsonDocument jsonDoc(json);
QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact); QByteArray payload = jsonDoc.toJson(QJsonDocument::Compact);
MQTTAsync_message pubmsg = MQTTAsync_message_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer;
......
...@@ -45,7 +45,7 @@ private: ...@@ -45,7 +45,7 @@ private:
void onPublishSuccess(MQTTAsync_successData* response); void onPublishSuccess(MQTTAsync_successData* response);
void onPublishFailure(MQTTAsync_failureData* response); void onPublishFailure(MQTTAsync_failureData* response);
void sendSubscriptionConfirmation(const vides_data::requestMqttData& response); void sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn);
static MqttSubscriber* instance; static MqttSubscriber* instance;
}; };
......
...@@ -48,8 +48,6 @@ struct requestDeviceStatus ...@@ -48,8 +48,6 @@ struct requestDeviceStatus
std::list<requestCameraInfo>camera_info_list; std::list<requestCameraInfo>camera_info_list;
requestDeviceStatus() {} requestDeviceStatus() {}
}; };
struct responseStsCredentials{ struct responseStsCredentials{
QString access_key_id; QString access_key_id;
QString access_key_secret; QString access_key_secret;
...@@ -109,6 +107,8 @@ struct localDeviceStatus ...@@ -109,6 +107,8 @@ struct localDeviceStatus
QString password; QString password;
localDeviceStatus() {} localDeviceStatus() {}
}; };
struct requestFaceReconition struct requestFaceReconition
{ {
QString id; QString id;
...@@ -312,10 +312,11 @@ struct responseMqttData{ ...@@ -312,10 +312,11 @@ struct responseMqttData{
uint8_t msg_type; uint8_t msg_type;
QString sn; QString sn;
QString uniq; QString uniq;
QString msg_body;
}; };
struct requestMqttData{ struct requestMqttData{
QString sn; QString msg;
int code; int code;
QString uniq; QString uniq;
}; };
...@@ -399,16 +400,48 @@ inline QString getDefaultGateway() { ...@@ -399,16 +400,48 @@ inline QString getDefaultGateway() {
return gateway; 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;
}
// 获取本地 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) { inline bool pingAddress(const QString &address) {
QProcess process; QProcess process;
QString program = "ping"; QString program = "ping";
QStringList arguments; QStringList arguments;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
arguments << "-n" << "1" << address; arguments << "-n" << "1" << address;
#else #else
arguments << "-c" << "1" << address; arguments << "-c" << "1" << address;
#endif #endif
process.start(program, arguments); process.start(program, arguments);
if (!process.waitForStarted()) { if (!process.waitForStarted()) {
...@@ -424,11 +457,28 @@ inline bool pingAddress(const QString &address) { ...@@ -424,11 +457,28 @@ inline bool pingAddress(const QString &address) {
QString output(process.readAllStandardOutput()); QString output(process.readAllStandardOutput());
// 简单的 Ping 成功检查逻辑 // 简单的 Ping 成功检查逻辑
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return output.contains("TTL="); return output.contains("TTL=");
#else #else
return output.contains("1 packets transmitted, 1 received"); return output.contains("1 packets transmitted, 1 received");
#endif #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 地址,则返回空字符串
} }
inline int GetCpuIdByAsm_arm(char* cpu_id) inline int GetCpuIdByAsm_arm(char* cpu_id)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
MainWindow* MainWindow::sp_this=nullptr; MainWindow* MainWindow::sp_this=nullptr;
MainWindow::MainWindow() MainWindow::MainWindow():isResetting(false)
{ {
sp_this=this; sp_this=this;
...@@ -133,6 +133,7 @@ MainWindow::MainWindow() ...@@ -133,6 +133,7 @@ MainWindow::MainWindow()
this->mqttConfig= config.mqttConfig; this->mqttConfig= config.mqttConfig;
runOrRebootMqtt(mqttConfig,httpurl,serialNumber); runOrRebootMqtt(mqttConfig,httpurl,serialNumber);
} }
void MainWindow::runOrRebootMqtt(vides_data::MqttConfig &mqtt_config,QString &httpUrl,QString &serialNumber){ void MainWindow::runOrRebootMqtt(vides_data::MqttConfig &mqtt_config,QString &httpUrl,QString &serialNumber){
MqttSubscriber* subscriber = MqttSubscriber::getInstance(this); MqttSubscriber* subscriber = MqttSubscriber::getInstance(this);
subscriber->init(mqtt_config,httpUrl,serialNumber); subscriber->init(mqtt_config,httpUrl,serialNumber);
...@@ -208,7 +209,34 @@ void MainWindow::divParameterUpdate(vides_data::responseConfig &cloudConfig,QStr ...@@ -208,7 +209,34 @@ 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){ CameraHandle* MainWindow::findHandle(QString sn){
for (auto it = faceDetectionParkingPushs.begin(); it != faceDetectionParkingPushs.end(); ++it) { for (auto it = faceDetectionParkingPushs.begin(); it != faceDetectionParkingPushs.end(); ++it) {
...@@ -464,9 +492,15 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){ ...@@ -464,9 +492,15 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){
void MainWindow::clearOfflineCameraHandle(QString sDevId, int nDevPort) { void MainWindow::clearOfflineCameraHandle(QString sDevId, int nDevPort) {
emit shutdownSignals(sDevId,nDevPort); emit shutdownSignals(sDevId,nDevPort);
} }
//平台有 盒子没有 盒子开启
void MainWindow::setIsResetting(bool running) {
this->isResetting.store(running, std::memory_order_release);
}
//平台没有 盒子有 盒子关闭 //平台没有 盒子有 盒子关闭
void MainWindow::startCamera(const QString &httpurl){ void MainWindow::startCamera(const QString &httpurl){
if(this->isResetting.load(std::memory_order_acquire)){
qInfo()<<"正在执行复位GB28181 程序,请等待";
}
Common & instace= Common::getInstance(); Common & instace= Common::getInstance();
MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance(); MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
QString nonConstHttpUrl = std::remove_const<QString>::type(httpurl); QString nonConstHttpUrl = std::remove_const<QString>::type(httpurl);
...@@ -554,6 +588,21 @@ void MainWindow::startCamera(const QString &httpurl){ ...@@ -554,6 +588,21 @@ void MainWindow::startCamera(const QString &httpurl){
reStatus.camera_info_list.push_front(camera_info); 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); __uint8_t new_algorithm= intToUint8t(devConfig.faceConfig.isOn,devConfig.licensePlateConfig.isOn,devConfig.uniformConfig.isOn,devConfig.humanConfig.isOn);
uint64 face_frequency=devConfig.humanConfig.faceFrequency; uint64 face_frequency=devConfig.humanConfig.faceFrequency;
offlineCameraHandle->initFaceFrequency(face_frequency); offlineCameraHandle->initFaceFrequency(face_frequency);
...@@ -1002,7 +1051,7 @@ void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data: ...@@ -1002,7 +1051,7 @@ void MainWindow::initCameras(vides_data::cameraParameters &parameter,vides_data:
float carConfidenceMax=devConfig.licensePlateConfig.carConfidenceMax; float carConfidenceMax=devConfig.licensePlateConfig.carConfidenceMax;
float carConfidenceMin=devConfig.licensePlateConfig.carConfidenceMin; float carConfidenceMin=devConfig.licensePlateConfig.carConfidenceMin;
cameraHandle->initSdkRealTimeDevSnapSyn(sdk_handle,synTime,face_frequency); cameraHandle->initSdkRealTimeDevSnapSyn(synTime,face_frequency);
cameraHandle->setCarConfidenceMaxAndMin(carConfidenceMax,carConfidenceMin); cameraHandle->setCarConfidenceMaxAndMin(carConfidenceMax,carConfidenceMin);
// QString pwd="admin2024"; // QString pwd="admin2024";
......
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
CameraHandle* findHandle(QString sn); 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 sendJsonResponse(QTcpSocket* socket, int code, const QString& data, const QString& msg);
void sendEmptyResponse(QTcpSocket* socket); void sendEmptyResponse(QTcpSocket* socket);
...@@ -82,6 +84,8 @@ public: ...@@ -82,6 +84,8 @@ public:
void deleteCloudNotCamer (const std::map<QString,vides_data::localDeviceStatus*>& localDevices, void deleteCloudNotCamer (const std::map<QString,vides_data::localDeviceStatus*>& localDevices,
const std::list<vides_data::responseDeviceStatus>& devices); const std::list<vides_data::responseDeviceStatus>& devices);
void setIsResetting(bool running);
~MainWindow(); ~MainWindow();
signals: signals:
...@@ -121,6 +125,7 @@ private: ...@@ -121,6 +125,7 @@ private:
vides_data::MqttConfig mqttConfig; vides_data::MqttConfig mqttConfig;
std::atomic<bool> isResetting;
}; };
#endif // MAINWINDOW_H #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