|
|
@@ -58,6 +58,7 @@ InteractiveCAN::InteractiveCAN()
|
|
|
connect(this, &InteractiveCAN::signalPostRequestData, m_httpClient, &HttpClient::slotPostRequestData);
|
|
|
connect(m_httpClient, &HttpClient::signalResponseUploadJobTicket, this, &InteractiveCAN::slotHttpResponseUploadJobTicket);
|
|
|
connect(m_httpClient, &HttpClient::signalResponseUploadPositionInfo, this, &InteractiveCAN::slotHttpResponseUploadPositionInfo);
|
|
|
+ connect(m_httpClient, &HttpClient::signalResponseUpdateBackLock, this, &InteractiveCAN::slotHttpResponseUpdateBackLock);
|
|
|
|
|
|
m_bleConnectTimer = new QTimer(this);
|
|
|
connect(m_bleConnectTimer, &QTimer::timeout, this, &InteractiveCAN::slotSearchBLE);
|
|
|
@@ -65,9 +66,15 @@ InteractiveCAN::InteractiveCAN()
|
|
|
|
|
|
connect(m_bleClient, &BLEClient::tokenReceived, this, [this](const BLEToken& token) {
|
|
|
if (token.success && m_bleConnectTimer) {
|
|
|
+ if (m_startGetWorkTicketResultFlag) {
|
|
|
+ m_bleClient->startGetWorkTicketResult();
|
|
|
+ }
|
|
|
m_okOpenKey = true;
|
|
|
m_finishedFlags = false; // 表示新的一轮开始了
|
|
|
+ m_startGetWorkTicketResultFlag = false;
|
|
|
+ m_okSendJobTicket = false;
|
|
|
m_checkedFlags = true;
|
|
|
+ m_searchedBLE = false;
|
|
|
m_bleConnectTimer->stop();
|
|
|
if (WorkNodeFormModel::instance()->modelType() == QString("isolation")) {
|
|
|
createJobTicket();
|
|
|
@@ -115,17 +122,21 @@ void InteractiveCAN::createJobTicket()
|
|
|
void InteractiveCAN::createColockJobTicket()
|
|
|
{
|
|
|
QJsonArray pointsList = WorkNodeFormModel::instance()->pointsList();
|
|
|
+ qDebug() << "[createColockJobTicket]: " << pointsList;
|
|
|
if (pointsList.isEmpty()) return;
|
|
|
|
|
|
+ m_pointAndLockRfids.clear();
|
|
|
m_lockRFIDs.clear();
|
|
|
|
|
|
for (int i = 0; i < pointsList.count(); i++) {
|
|
|
QJsonObject pointItem = pointsList[i].toObject();
|
|
|
|
|
|
- if (pointItem.contains("lockNfc")) {
|
|
|
+ if (pointItem.contains("lockNfc") && pointItem.contains("pointNfc")) {
|
|
|
+ m_pointAndLockRfids.insert(pointItem.value("pointNfc").toString(), pointItem.value("lockNfc").toString());
|
|
|
m_lockRFIDs.insert(i, pointItem.value("lockNfc").toString());
|
|
|
}
|
|
|
}
|
|
|
+ qDebug() << "[createColockJobTicket]: " << m_pointAndLockRfids;
|
|
|
createJobTicket();
|
|
|
}
|
|
|
|
|
|
@@ -158,6 +169,8 @@ void InteractiveCAN::httpRequestPostUploadJobTicket()
|
|
|
jsonRoot.insert("keyNfcList", keyNfcListArray);
|
|
|
jsonRoot.insert("lockNfcList", lockNfcListArray);
|
|
|
|
|
|
+ qDebug() << "[httpRequestPostUploadJobTicket]: " << url;
|
|
|
+
|
|
|
QJsonDocument jsonDoc(jsonRoot);
|
|
|
QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Compact);
|
|
|
|
|
|
@@ -202,14 +215,18 @@ void InteractiveCAN::httpRequestPostUploadPositionInfo(const QJsonDocument &doc)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// QJsonObject jsonRoot;
|
|
|
+ QJsonObject jsonRoot;
|
|
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
qint64 timestampSeconds = currentDateTime.toMSecsSinceEpoch();
|
|
|
|
|
|
QString url = Config()->uploadPositionInfoUrl;
|
|
|
- qDebug() << "[httpRequestPostUploadPositionInfo]" << pointsInfo;
|
|
|
+ qDebug() << "[httpRequestPostUploadPositionInfo]" << pointsInfo << url;
|
|
|
+
|
|
|
+ jsonRoot.insert("keyNfc", m_keyNFC);
|
|
|
+ jsonRoot.insert("hardwareCode", Config()->m_systemMACAddr);
|
|
|
+ jsonRoot.insert("list", pointsInfo);
|
|
|
|
|
|
- QJsonDocument jsonDoc(pointsInfo);
|
|
|
+ QJsonDocument jsonDoc(jsonRoot);
|
|
|
QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Compact);
|
|
|
|
|
|
emit signalPostRequestData(timestampSeconds, url, jsonData, NULL, GetInteractiveData()->m_token);
|
|
|
@@ -221,6 +238,7 @@ void InteractiveCAN::httpRequestPostUpdatePointUnlock(const QJsonDocument &doc)
|
|
|
QJsonObject rootObj = doc.object();
|
|
|
if (!rootObj.contains("data")) return;
|
|
|
|
|
|
+ QJsonObject jsonRoot;
|
|
|
QJsonArray pointsInfo;
|
|
|
|
|
|
int nodeId = WorkNodeFormModel::instance()->workId();
|
|
|
@@ -257,13 +275,42 @@ void InteractiveCAN::httpRequestPostUpdatePointUnlock(const QJsonDocument &doc)
|
|
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
qint64 timestampSeconds = currentDateTime.toMSecsSinceEpoch();
|
|
|
|
|
|
- QString url = Config()->updateUncolockUrl;
|
|
|
+ QString url = Config()->updatePointUnlock;
|
|
|
|
|
|
+ jsonRoot.insert("keyNfc", m_keyNFC);
|
|
|
+ jsonRoot.insert("hardwareCode", Config()->m_systemMACAddr);
|
|
|
+ jsonRoot.insert("list", pointsInfo);
|
|
|
|
|
|
- QJsonDocument jsonDoc(pointsInfo);
|
|
|
+ QJsonDocument jsonDoc(jsonRoot);
|
|
|
+ QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Compact);
|
|
|
+ qDebug() << jsonDoc;
|
|
|
+
|
|
|
+ emit signalPostRequestData(timestampSeconds, url, jsonData, NULL, GetInteractiveData()->m_token);
|
|
|
+}
|
|
|
+
|
|
|
+void InteractiveCAN::httpRequestPostUpdateBackLock(const QList<QString> &lockNfcs)
|
|
|
+{
|
|
|
+ QJsonArray locksInfo;
|
|
|
+
|
|
|
+ int nodeId = WorkNodeFormModel::instance()->workId();
|
|
|
+
|
|
|
+ for (int i = 0; i < lockNfcs.count(); i++) {
|
|
|
+ QJsonObject infoItem;
|
|
|
+ infoItem.insert("nodeId", nodeId);
|
|
|
+ infoItem.insert("lockNfc", lockNfcs[i]);
|
|
|
+ infoItem.insert("hardwareCode", Config()->m_systemMACAddr);
|
|
|
+
|
|
|
+ locksInfo.append(infoItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
+ qint64 timestampSeconds = currentDateTime.toMSecsSinceEpoch();
|
|
|
+
|
|
|
+ QString url = Config()->updateBackLock;
|
|
|
+
|
|
|
+ QJsonDocument jsonDoc(locksInfo);
|
|
|
QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Compact);
|
|
|
qDebug() << jsonDoc;
|
|
|
- qDebug() << pointsInfo;
|
|
|
|
|
|
emit signalPostRequestData(timestampSeconds, url, jsonData, NULL, GetInteractiveData()->m_token);
|
|
|
}
|
|
|
@@ -304,11 +351,22 @@ void InteractiveCAN::checkEKeyStatus()
|
|
|
|
|
|
void InteractiveCAN::getJobTicketInfo(quint8 nodeId, bool isLeftKey)
|
|
|
{
|
|
|
+ qDebug() << "[getJobTicketInfo]: " << m_checkedFlags;
|
|
|
if (m_checkedFlags) {
|
|
|
m_checkedFlags = false;
|
|
|
m_canClient->lockingEKey(nodeId, isLeftKey, !isLeftKey);
|
|
|
|
|
|
- m_bleClient->startGetWorkTicketResult();
|
|
|
+// m_bleClient->startGetWorkTicketResult();
|
|
|
+ if (m_bleClient) {
|
|
|
+ qDebug() << "[getJobTicketInfo]: ss" << m_bleClient->isConnected();
|
|
|
+ if (m_bleClient->isConnected()) {
|
|
|
+ m_bleClient->startGetWorkTicketResult();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_startGetWorkTicketResultFlag = true;
|
|
|
+ m_bleClient->connectDevice(m_currentKeyMAC, "keyLock");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -366,6 +424,7 @@ void InteractiveCAN::slotHttpResponseGetIsolationPointInfo(QByteArray data)
|
|
|
if (vDataObj.contains("pointNfc")) {
|
|
|
info.equipRfidNo = vDataObj.value("pointNfc").toString();
|
|
|
}
|
|
|
+
|
|
|
if (WorkNodeFormModel::instance()->modelType() == QString("isolation")) {
|
|
|
m_pointInfo.append(info);
|
|
|
if (m_pointInfo.length() == m_isolationPoints.length()) {
|
|
|
@@ -373,9 +432,11 @@ void InteractiveCAN::slotHttpResponseGetIsolationPointInfo(QByteArray data)
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
-// info.target = 1;
|
|
|
+ info.target = 1;
|
|
|
+ if (m_pointAndLockRfids.find(info.equipRfidNo) != m_pointAndLockRfids.end()) {
|
|
|
+ info.infoRfidNo = m_pointAndLockRfids[info.equipRfidNo];
|
|
|
+ }
|
|
|
m_pointInfo.append(info);
|
|
|
- qDebug() << "[slotHttpResponseGetIsolationPointInfo]" << m_isolationPoints;
|
|
|
if (m_pointInfo.length() == m_isolationPoints.length()) {
|
|
|
if (m_okOpenKey) {
|
|
|
sendJobTicket();
|
|
|
@@ -404,6 +465,9 @@ void InteractiveCAN::slotHttpResponseUploadJobTicket(QByteArray data)
|
|
|
int codeValue = rootObj.value("code").toInt();
|
|
|
if(codeValue == 200 || codeValue == 0) {
|
|
|
// qDebug() << "[slotHttpResponseUploadJobTicket]" << jsonDoc;
|
|
|
+ if (m_bleClient) {
|
|
|
+// m_bleClient->disconnectDevice();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -450,6 +514,27 @@ void InteractiveCAN::slotHttpResponseUpdatePointUnlock(QByteArray data)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void InteractiveCAN::slotHttpResponseUpdateBackLock(QByteArray data)
|
|
|
+{
|
|
|
+ QJsonParseError error;
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
|
|
+ if (error.error != QJsonParseError::NoError) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ qDebug() << "[slotHttpResponseUpdateBackLock]" << jsonDoc;
|
|
|
+ if (jsonDoc.isNull() || jsonDoc.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ QJsonObject rootObj = jsonDoc.object();
|
|
|
+ if(rootObj.contains("code")) {
|
|
|
+ int codeValue = rootObj.value("code").toInt();
|
|
|
+ if(codeValue == 200 || codeValue == 0) {
|
|
|
+ m_getLockedRfidFlag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void InteractiveCAN::slotUpdateColockStatus(const QString& cardNfc)
|
|
|
{
|
|
|
// TODO: 更新共锁人状态
|
|
|
@@ -463,9 +548,11 @@ void InteractiveCAN::slotUpdateColockStatus(const QString& cardNfc)
|
|
|
QString modelType = WorkNodeFormModel::instance()->modelType();
|
|
|
if (modelType == QString("isolation")) {
|
|
|
url = Config()->updateColockUrl;
|
|
|
- } else if (modelType == QString("releaseIsolation")) {
|
|
|
+ }
|
|
|
+ else if (modelType == QString("releaseIsolation")) {
|
|
|
url = Config()->updateUncolockUrl;
|
|
|
}
|
|
|
+ qDebug() << "[slotUpdateColockStatus]: " << url << modelType;
|
|
|
|
|
|
jsonRoot.insert("nodeId", m_taskCode);
|
|
|
jsonRoot.insert("cardNfc", cardNfc);
|
|
|
@@ -569,7 +656,7 @@ void InteractiveCAN::getLockRFIDs(QMap<int, QString> &rfids)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ qDebug() << m_lockRFIDs;
|
|
|
if (m_okOpenKey) {
|
|
|
sendJobTicket();
|
|
|
}
|
|
|
@@ -577,6 +664,7 @@ void InteractiveCAN::getLockRFIDs(QMap<int, QString> &rfids)
|
|
|
|
|
|
void InteractiveCAN::sendJobTicket()
|
|
|
{
|
|
|
+ qDebug() << m_pointInfo.count() << m_lockRFIDs.count() << m_isolationPoints.count();
|
|
|
if (m_pointInfo.count() != m_lockRFIDs.count() || m_lockRFIDs.count() != m_isolationPoints.count()) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -589,6 +677,9 @@ void InteractiveCAN::sendJobTicket()
|
|
|
pointItem.insert("equipName", iter->equipName);
|
|
|
pointItem.insert("equipRfidNo", iter->equipRfidNo);
|
|
|
pointItem.insert("target", iter->target);
|
|
|
+ if (iter->target > 0) {
|
|
|
+ pointItem.insert("infoRfidNo", iter->infoRfidNo);
|
|
|
+ }
|
|
|
pointListArray.append(pointItem);
|
|
|
}
|
|
|
|
|
|
@@ -654,18 +745,22 @@ void InteractiveCAN::slotUnlockEKey(const CANKeyBaseChargeStatus& status)
|
|
|
{
|
|
|
if (status.success) {
|
|
|
if (m_okOpenKey) {
|
|
|
- m_okUnlockKey = true;
|
|
|
- if (!m_okSendJobTicket) {
|
|
|
+ QMutexLocker locker(&m_mutex);
|
|
|
+ if (!m_okUnlockKey) {
|
|
|
// 上传作业票信息
|
|
|
httpRequestPostUploadJobTicket();
|
|
|
+
|
|
|
+// httpRequestPostInsertUnlockKey();
|
|
|
}
|
|
|
+ m_okUnlockKey = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InteractiveCAN::slotUnlockLocks(bool success)
|
|
|
+void InteractiveCAN::slotUnlockLocks(bool success, const QList<QString>& lockRfids)
|
|
|
{
|
|
|
if (success) {
|
|
|
+// QMutexLocker locker(&m_mutex);
|
|
|
if (m_okOpenKey) {
|
|
|
m_okUnlockLocks = true;
|
|
|
if (WorkNodeFormModel::instance()->modelType() == QString("isolation")) {
|
|
|
@@ -677,6 +772,15 @@ void InteractiveCAN::slotUnlockLocks(bool success)
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ if (WorkNodeFormModel::instance()->modelType() == QString("releaseIsolation")) {
|
|
|
+ if (!m_getLockedRfidFlag) {
|
|
|
+ m_getLockedRfidFlag = true;
|
|
|
+ qDebug() << "[slotUnlockLocks]: " << lockRfids;
|
|
|
+ httpRequestPostUpdateBackLock(lockRfids);
|
|
|
+
|
|
|
+ emit signalUpdateBackLockStatus(lockRfids);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -693,7 +797,12 @@ void InteractiveCAN::slotSearchBLE()
|
|
|
void InteractiveCAN::slotOkSearchedBLE(bool success)
|
|
|
{
|
|
|
if (success) {
|
|
|
- m_bleClient->connectDevice(m_currentKeyMAC, "keyLock");
|
|
|
+ if (m_bleClient->isConnected()) {
|
|
|
+ createColockJobTicket();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ m_bleClient->connectDevice(m_currentKeyMAC, "keyLock");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|