|
|
@@ -23,8 +23,6 @@
|
|
|
#endif
|
|
|
// ========================================
|
|
|
|
|
|
-#define CAN_SLEEP_TIME 50
|
|
|
-
|
|
|
// 十六进制转字符串
|
|
|
std::string hexToString(uint8_t hex) {
|
|
|
return QString("%1").arg(hex, 2, 16, QChar('0')).toUpper().toStdString();
|
|
|
@@ -70,12 +68,12 @@ CANClient::CANClient(QObject *parent)
|
|
|
#elif defined(CAN_MODE_PHYSICAL)
|
|
|
qInfo() << "[CAN] 模式: 物理CAN (生产环境)";
|
|
|
// 物理CAN:需要完整配置
|
|
|
- system("ifconfig can0 down");
|
|
|
- system("ip link set up can0 type can bitrate 1000000 restart-ms 100");
|
|
|
+ system("sudo ifconfig can0 down");
|
|
|
+ system("sudo ip link set up can0 type can bitrate 1000000 restart-ms 100");
|
|
|
#else
|
|
|
qWarning() << "[CAN] 警告: 未选择CAN模式,使用默认物理CAN配置";
|
|
|
- system("ifconfig can0 down");
|
|
|
- system("ip link set up can0 type can bitrate 1000000 restart-ms 100");
|
|
|
+ system("sudo ifconfig can0 down");
|
|
|
+ system("sudo ip link set up can0 type can bitrate 1000000 restart-ms 100");
|
|
|
#endif
|
|
|
|
|
|
// 初始化插件
|
|
|
@@ -85,30 +83,6 @@ CANClient::CANClient(QObject *parent)
|
|
|
|
|
|
connectDevice();
|
|
|
|
|
|
-// m_readControlTimer = new QTimer(this);
|
|
|
-// m_readControlTimer->setInterval(300);
|
|
|
-// connect(m_readControlTimer, &QTimer::timeout, this, [this]() {
|
|
|
-// readKeyBaseControlStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// readLockControlStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// });
|
|
|
-// m_readControlTimer->start();
|
|
|
-
|
|
|
-// m_readStatusTimer = new QTimer(this);
|
|
|
-// m_readStatusTimer->setInterval(200);
|
|
|
-// connect(m_readStatusTimer, &QTimer::timeout, this, [this]() {
|
|
|
-// readKeyRFIDStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// readLockRFIDStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// readKeyBaseStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// readLockStatusAsync();
|
|
|
-// msleep(CAN_SLEEP_TIME);
|
|
|
-// });
|
|
|
-// m_readStatusTimer->start();
|
|
|
-
|
|
|
connect(this, &CANClient::workingKeyChanged, this, &CANClient::slotWorkingKeyChanged);
|
|
|
connect(this, &CANClient::workingLocksChanged, this, &CANClient::slotWorkingLocksChanged);
|
|
|
|
|
|
@@ -177,23 +151,23 @@ void CANClient::run()
|
|
|
qInfo() << "CAN监听线程启动!";
|
|
|
|
|
|
while (m_threadstatus) {
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
+ for (int i = 0; i < 20; i++) {
|
|
|
readDeviceInfoAsync(i);
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
}
|
|
|
- readKeyBaseStatusAsync();
|
|
|
+ readAllKeyBaseStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
- readLockStatusAsync();
|
|
|
+ readAllLocksStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
|
|
|
- readKeyBaseControlStatusAsync();
|
|
|
+ readAllKeyBaseControlStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
- readLockControlStatusAsync();
|
|
|
+ readAllLocksControlStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
|
|
|
- readKeyRFIDStatusAsync();
|
|
|
+ readAllKeyRFIDStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
- readLockRFIDStatusAsync();
|
|
|
+ readAllLocksRFIDStatusAsync();
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
}
|
|
|
qInfo() << "CAN监听线程退出!";
|
|
|
@@ -416,6 +390,7 @@ void CANClient::slotUpdateKeyBaseControl(quint8 nodeId, const CANKeyBaseControlS
|
|
|
|
|
|
bool isWrite = false;
|
|
|
CANKeyBaseChargeStatus writeStatus;
|
|
|
+ writeStatus.nodeId = nodeId;
|
|
|
|
|
|
if (m_keyBaseStatus[nodeId].leftHasKey && !status.leftLocked) {
|
|
|
writeStatus.leftLocked = true;
|
|
|
@@ -430,13 +405,13 @@ void CANClient::slotUpdateKeyBaseControl(quint8 nodeId, const CANKeyBaseControlS
|
|
|
emit signalReturnKey();
|
|
|
}
|
|
|
}
|
|
|
-// else if (!m_keyBaseStatus[nodeId].leftHasKey && status.leftLocked) {
|
|
|
-// writeStatus.leftLocked = false;
|
|
|
-// writeStatus.leftWorking = true;
|
|
|
-// writeStatus.leftChargeEnable = false;
|
|
|
-// writeStatus.leftChargeState = ChargeState::Charging;
|
|
|
-// isWrite = true;
|
|
|
-// }
|
|
|
+ else if (!m_keyBaseStatus[nodeId].leftHasKey && status.leftLocked) {
|
|
|
+ writeStatus.leftLocked = false;
|
|
|
+ writeStatus.leftWorking = true;
|
|
|
+ writeStatus.leftChargeEnable = false;
|
|
|
+ writeStatus.leftChargeState = ChargeState::Charging;
|
|
|
+ isWrite = true;
|
|
|
+ }
|
|
|
if (m_keyBaseStatus[nodeId].rightHasKey && !status.rightLocked) {
|
|
|
writeStatus.rightLocked = true;
|
|
|
writeStatus.rightWorking = true;
|
|
|
@@ -450,13 +425,13 @@ void CANClient::slotUpdateKeyBaseControl(quint8 nodeId, const CANKeyBaseControlS
|
|
|
emit signalReturnKey();
|
|
|
}
|
|
|
}
|
|
|
-// else if (!m_keyBaseStatus[nodeId].rightHasKey && status.rightLocked) {
|
|
|
-// writeStatus.rightLocked = false;
|
|
|
-// writeStatus.rightWorking = true;
|
|
|
-// writeStatus.rightChargeEnable = false;
|
|
|
-// writeStatus.rightChargeState = ChargeState::Charging;
|
|
|
-// isWrite = true;
|
|
|
-// }
|
|
|
+ else if (!m_keyBaseStatus[nodeId].rightHasKey && status.rightLocked) {
|
|
|
+ writeStatus.rightLocked = false;
|
|
|
+ writeStatus.rightWorking = true;
|
|
|
+ writeStatus.rightChargeEnable = false;
|
|
|
+ writeStatus.rightChargeState = ChargeState::Charging;
|
|
|
+ isWrite = true;
|
|
|
+ }
|
|
|
|
|
|
if (isWrite) {
|
|
|
writeKeyBaseChargeControlAsync(writeStatus);
|
|
|
@@ -474,6 +449,8 @@ void CANClient::slotUpdateLockedStatus(quint8 nodeId, const CANLocksControl &sta
|
|
|
|
|
|
bool isWrite = false;
|
|
|
CANLocksControl writeStatus;
|
|
|
+ writeStatus.nodeId = nodeId;
|
|
|
+
|
|
|
for (int i = 0; i < status.lockNums.length(); i++) {
|
|
|
int lockNum = status.lockNums[i];
|
|
|
QMap<int, bool> lockHasKeyMap = m_locksControlStatus[nodeId].lockHasKeyMap;
|
|
|
@@ -493,10 +470,17 @@ void CANClient::slotUpdateLockedStatus(quint8 nodeId, const CANLocksControl &sta
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// else if ((lockHasKeyMap.find(lockNum) != lockHasKeyMap.end() && !lockHasKeyMap[lockNum]) &&
|
|
|
-// (lockLockedMap.find(lockNum) != lockLockedMap.end() && lockLockedMap[lockNum])) {
|
|
|
+ else if ((lockHasKeyMap.find(lockNum) != lockHasKeyMap.end() && !lockHasKeyMap[lockNum]) &&
|
|
|
+ (lockLockedMap.find(lockNum) != lockLockedMap.end() && lockLockedMap[lockNum])) {
|
|
|
+ writeStatus.lockNums.append(lockNum);
|
|
|
+ writeStatus.lockLockedMap.insert(lockNum, false);
|
|
|
+ writeStatus.lockWorkMap.insert(lockNum, true);
|
|
|
+ isWrite = true;
|
|
|
+ }
|
|
|
+// if ((lockHasKeyMap.find(lockNum) != lockHasKeyMap.end() && !lockHasKeyMap[lockNum]) &&
|
|
|
+// (lockLockedMap.find(lockNum) != lockLockedMap.end() && !lockLockedMap[lockNum])) {
|
|
|
// writeStatus.lockNums.append(lockNum);
|
|
|
-// writeStatus.lockLockedMap.insert(lockNum, false);
|
|
|
+// writeStatus.lockLockedMap.insert(lockNum, true);
|
|
|
// writeStatus.lockWorkMap.insert(lockNum, true);
|
|
|
// isWrite = true;
|
|
|
// }
|
|
|
@@ -682,20 +666,36 @@ QString CANClient::parseRFIDCard(const QByteArray& data)
|
|
|
return cardStr;
|
|
|
}
|
|
|
|
|
|
-bool CANClient::verifyNodeID(quint8 deviceNodeId, quint8& returnNodeId)
|
|
|
+//bool CANClient::verifyNodeID(quint8 deviceNodeId, quint8& returnNodeId)
|
|
|
+//{
|
|
|
+// if (!m_deviceOfNodeId.values().contains(deviceNodeId)) {
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+
|
|
|
+// quint8 nodeId = 0;
|
|
|
+// for (auto iter = m_deviceOfNodeId.begin(); iter != m_deviceOfNodeId.end(); ++iter) {
|
|
|
+// if (iter.value() == deviceNodeId) {
|
|
|
+// nodeId = iter.key();
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// returnNodeId = nodeId;
|
|
|
+// return true;
|
|
|
+//}
|
|
|
+
|
|
|
+bool CANClient::verifyAllNodeID(quint8 deviceNodeId, QList<quint8> &returnNodeId)
|
|
|
{
|
|
|
if (!m_deviceOfNodeId.values().contains(deviceNodeId)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- quint8 nodeId = 0;
|
|
|
+ QList<quint8> nodeIds;
|
|
|
for (auto iter = m_deviceOfNodeId.begin(); iter != m_deviceOfNodeId.end(); ++iter) {
|
|
|
if (iter.value() == deviceNodeId) {
|
|
|
- nodeId = iter.key();
|
|
|
- break;
|
|
|
+ nodeIds.append(iter.key());
|
|
|
}
|
|
|
}
|
|
|
- returnNodeId = nodeId;
|
|
|
+ returnNodeId = nodeIds;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -789,16 +789,23 @@ void CANClient::readDeviceInfoAsync(quint8 nodeId)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readKeyBaseStatusAsync()
|
|
|
+void CANClient::readAllKeyBaseStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_EKEY_NODEID, nodeIds)) {
|
|
|
CANKeyBaseStatus emptyStatus;
|
|
|
- emit keyBaseStatusRead(nodeId, emptyStatus);
|
|
|
+ emit keyBaseStatusRead(-1, emptyStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readKeyBaseStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readKeyBaseStatusAsync(quint8 nodeId)
|
|
|
+{
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, CAN_EKEY_STATUS_INDEX, CAN_EKEY_STATUS_SUBINDEX);
|
|
|
// qDebug() << "发送readKeyBaseStatusAsync帧 FrameId: 0x" << QString::number(frame.frameId(), 16) << "Data:" << frame.payload().toHex().toUpper();
|
|
|
sendFrameAsync(frame, [this, nodeId](const QCanBusFrame& respFrame) {
|
|
|
@@ -828,43 +835,6 @@ void CANClient::readKeyBaseStatusAsync()
|
|
|
// << ",左充电:" << (status.leftCharging ? "充电中" : "未充电")
|
|
|
// << "; 右钥匙:" << (status.rightHasKey ? "有" : "无")
|
|
|
// << ",右充电:" << (status.rightCharging ? "充电中" : "未充电");
|
|
|
- QMutexLocker locker(&m_insertDataMutex);
|
|
|
-
|
|
|
-// bool prevLeftHasKey = false, prevRightHasKey = false;
|
|
|
-// if (m_keyBaseStatus.find(nodeId) != m_keyBaseStatus.end()) {
|
|
|
-// prevLeftHasKey = m_keyBaseStatus[nodeId].leftHasKey;
|
|
|
-// prevRightHasKey = m_keyBaseStatus[nodeId].rightHasKey;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (!m_keyBaseStatus.isEmpty()) {
|
|
|
-// if (!prevLeftHasKey && status.leftHasKey) {
|
|
|
-// qInfo() << "[归还检测] 检测到左钥匙插入!";
|
|
|
-
|
|
|
-// if (m_keyRFIDStatus.find(nodeId) != m_keyRFIDStatus.end() &&
|
|
|
-// !m_keyRFIDStatus[nodeId].leftKeyRFID.isEmpty() &&
|
|
|
-// m_keyRFIDStatus[nodeId].leftKeyRFID != "00000000") {
|
|
|
-// qInfo() << "[归还检测] 左钥匙:NFC卡号:" << m_keyRFIDStatus[nodeId].leftKeyRFID;
|
|
|
-
|
|
|
-//// emit nfcDeviceDetected(m_keyRFIDStatus[nodeId].leftKeyRFID, "key", 0);
|
|
|
-// } else {
|
|
|
-// qWarning() << "[归还检测] 左钥匙存在但无法读取NFC";
|
|
|
-// emit nfcDeviceError("key", 0);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else if (prevLeftHasKey && !status.leftHasKey) {
|
|
|
-// qInfo() << "[取出检测] 检测到左钥匙取出!";
|
|
|
-// if (m_keyRFIDStatus.find(nodeId) != m_keyRFIDStatus.end() &&
|
|
|
-// !m_keyRFIDStatus[nodeId].leftKeyRFID.isEmpty() &&
|
|
|
-// m_keyRFIDStatus[nodeId].leftKeyRFID != "00000000") {
|
|
|
-// qInfo() << "[取出检测] 左钥匙:NFC卡号:" << m_keyRFIDStatus[nodeId].leftKeyRFID;
|
|
|
-
|
|
|
-// emit signalPopDevices(m_keyRFIDStatus[nodeId].leftKeyRFID, "key", 0);
|
|
|
-// } else {
|
|
|
-// qWarning() << "[取出检测] 左钥匙存在但无法读取NFC";
|
|
|
-// emit nfcDeviceError("key", 0);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
else {
|
|
|
qWarning() << "[KeyBase] 读取状态失败";
|
|
|
@@ -875,16 +845,23 @@ void CANClient::readKeyBaseStatusAsync()
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readKeyBaseControlStatusAsync()
|
|
|
+void CANClient::readAllKeyBaseControlStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_EKEY_NODEID, nodeIds)) {
|
|
|
CANKeyBaseControlStatus emptyStatus;
|
|
|
- emit keyBaseControlStatusRead(nodeId, emptyStatus);
|
|
|
+ emit keyBaseControlStatusRead(-1, emptyStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readKeyBaseControlStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readKeyBaseControlStatusAsync(quint8 nodeId)
|
|
|
+{
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, CAN_FASTENER_CONTROL_INDEX, CAN_FASTENER_CONTROL_SUBINDEX);
|
|
|
sendFrameAsync(frame, [this, nodeId](const QCanBusFrame& respFrame) {
|
|
|
CANKeyBaseControlStatus status;
|
|
|
@@ -914,29 +891,6 @@ void CANClient::readKeyBaseControlStatusAsync()
|
|
|
|
|
|
status.success = true;
|
|
|
|
|
|
-// bool prevLeftHasKey = false, prevRightHasKey = false;
|
|
|
-// if (m_keyBaseControlStatus.find(nodeId) != m_keyBaseControlStatus.end()) {
|
|
|
-// prevLeftHasKey = m_keyBaseControlStatus[nodeId].leftLocked;
|
|
|
-// prevRightHasKey = m_keyBaseControlStatus[nodeId].rightLocked;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (!m_keyBaseControlStatus.isEmpty()) {
|
|
|
-// if (!prevLeftHasKey && status.leftLocked) {
|
|
|
-// qInfo() << "[归还检测] 检测到左钥匙插入!";
|
|
|
-
|
|
|
-// if (m_keyRFIDStatus.find(nodeId) != m_keyRFIDStatus.end() &&
|
|
|
-// !m_keyRFIDStatus[nodeId].leftKeyRFID.isEmpty() &&
|
|
|
-// m_keyRFIDStatus[nodeId].leftKeyRFID != "00000000") {
|
|
|
-// qInfo() << "[归还检测] 左钥匙:NFC卡号:" << m_keyRFIDStatus[nodeId].leftKeyRFID;
|
|
|
-
|
|
|
-// emit nfcDeviceDetected(m_keyRFIDStatus[nodeId].leftKeyRFID, "key", 0);
|
|
|
-// } else {
|
|
|
-// qWarning() << "[归还检测] 左钥匙存在但无法读取NFC";
|
|
|
-// emit nfcDeviceError("key", 0);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
// qInfo() << "[KeyBase] 左钥匙:" << (status.leftLocked ? "锁住" : "未锁")
|
|
|
// << ",左充电:" << (status.leftCharging ? "充电中" : "未充电") << (status.leftBuckleFault ? "故障" : "正常")
|
|
|
// << "; 右钥匙:" << (status.rightLocked ? "锁住" : "未锁")
|
|
|
@@ -951,15 +905,23 @@ void CANClient::readKeyBaseControlStatusAsync()
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readLockStatusAsync()
|
|
|
+void CANClient::readAllLocksStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- emit lockStatusRead(nodeId, CANLockControlStatus());
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_LOCK_NODEID, nodeIds)) {
|
|
|
+ CANLockControlStatus emptyStatus;
|
|
|
+ emit lockStatusRead(-1, emptyStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readLockStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readLockStatusAsync(quint8 nodeId)
|
|
|
+{
|
|
|
// 构建SDO读帧:索引0x6010(锁状态),子索引0x00,1字节数据
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, CAN_LOCK_STATUS_INDEX, CAN_LOCK_STATUS_SUBINDEX);
|
|
|
|
|
|
@@ -991,55 +953,7 @@ void CANClient::readLockStatusAsync()
|
|
|
}
|
|
|
// qDebug() << "FrameId: 0x" << QString::number(respFrame.frameId(), 16) << "Data:" << respFrame.payload().toHex().toUpper();
|
|
|
status.success = true;
|
|
|
-
|
|
|
-// // ========== 检测锁插入(用于归还流程) ==========
|
|
|
-// QMutexLocker locker(&m_insertDataMutex);
|
|
|
-
|
|
|
-// // 获取之前的锁状态
|
|
|
-// QMap<int, bool> prevLockHasKeyMap;
|
|
|
-// if (m_locksControlStatus.find(nodeId) != m_locksControlStatus.end()) {
|
|
|
-// prevLockHasKeyMap = m_locksControlStatus[nodeId].lockHasKeyMap;
|
|
|
-// }
|
|
|
-// if (!m_locksControlStatus.isEmpty()) {
|
|
|
-// // 检测每个锁位的插入(从无到有)
|
|
|
-// for (int i = 0; i < 5; i++) {
|
|
|
-// bool prevHasLock = prevLockHasKeyMap.contains(i) ? prevLockHasKeyMap[i] : false;
|
|
|
-// bool currHasLock = status.lockHasKeyMap.contains(i) ? status.lockHasKeyMap[i] : false;
|
|
|
-
|
|
|
-// if (!prevHasLock && currHasLock) {
|
|
|
-// qInfo() << "[归还检测] 检测到" << (i+1) << "号锁插入!";
|
|
|
-// // 锁插入,获取NFC卡号
|
|
|
-// if (m_locksRFIDStatus.find(nodeId) != m_locksRFIDStatus.end() &&
|
|
|
-// m_locksRFIDStatus[nodeId].lockRFIDMap.contains(i) &&
|
|
|
-// !m_locksRFIDStatus[nodeId].lockRFIDMap[i].isEmpty() &&
|
|
|
-// m_locksRFIDStatus[nodeId].lockRFIDMap[i] != "00000000") {
|
|
|
-// qInfo() << "[归还检测]" << (i+1) << "号锁NFC卡号:" << m_locksRFIDStatus[nodeId].lockRFIDMap[i];
|
|
|
-
|
|
|
-// emit nfcDeviceDetected(m_locksRFIDStatus[nodeId].lockRFIDMap[i], "lock", i);
|
|
|
-// emit signalLockNfcDeviceDetected(m_locksRFIDStatus[nodeId].lockRFIDMap[i]);
|
|
|
-// } else {
|
|
|
-// qWarning() << "[归还检测]" << (i+1) << "号锁存在但无法读取NFC";
|
|
|
-// emit nfcDeviceError("lock", i);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// else if (prevHasLock && !currHasLock) {
|
|
|
-// qInfo() << "[取出检测] 检测到" << (i+1) << "号锁取出!";
|
|
|
-// qDebug() << m_locksRFIDStatus[nodeId].lockRFIDMap[i];
|
|
|
-// if (m_locksRFIDStatus.find(nodeId) != m_locksRFIDStatus.end() &&
|
|
|
-// m_locksRFIDStatus[nodeId].lockRFIDMap.contains(i) &&
|
|
|
-// !m_locksRFIDStatus[nodeId].lockRFIDMap[i].isEmpty() &&
|
|
|
-// m_locksRFIDStatus[nodeId].lockRFIDMap[i] != "00000000") {
|
|
|
-// qInfo() << "[取出检测]" << (i+1) << "号锁NFC卡号:" << m_locksRFIDStatus[nodeId].lockRFIDMap[i];
|
|
|
-
|
|
|
-// emit signalPopDevices(m_locksRFIDStatus[nodeId].lockRFIDMap[i], "lock", i);
|
|
|
-// } else {
|
|
|
-// qWarning() << "[取出检测]" << (i+1) << "号锁存在但无法读取NFC";
|
|
|
-// emit nfcDeviceError("lock", i);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // ====================================================
|
|
|
+ status.nodeId = nodeId;
|
|
|
|
|
|
if (m_locksControlStatus.find(nodeId) == m_locksControlStatus.end()) {
|
|
|
m_locksControlStatus.insert(nodeId, status);
|
|
|
@@ -1057,15 +971,23 @@ void CANClient::readLockStatusAsync()
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readLockControlStatusAsync()
|
|
|
+void CANClient::readAllLocksControlStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- emit lockControlStatusRead(nodeId, CANLocksControl());
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_LOCK_NODEID, nodeIds)) {
|
|
|
+ CANLocksControl emptyStatus;
|
|
|
+ emit lockControlStatusRead(-1, emptyStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readLockControlStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME * 2);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readLockControlStatusAsync(quint8 nodeId)
|
|
|
+{
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, CAN_LOCK_CONTROL_INDEX, CAN_LOCK_CONTROL_SUBINDEX);
|
|
|
sendFrameAsync(frame, [this, nodeId](const QCanBusFrame& respFrame) {
|
|
|
CANLocksControl status;
|
|
|
@@ -1103,11 +1025,7 @@ void CANClient::readLockControlStatusAsync()
|
|
|
|
|
|
void CANClient::writeSingleLockBuckleAsync(const CANSingleLockStatus& status)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ quint8 nodeId = status.nodeId;
|
|
|
|
|
|
if (!checkLockNumValid(status.lockNum)) {
|
|
|
emit lockBuckleWrite(false, status.lockNum, status.isLocked);
|
|
|
@@ -1148,11 +1066,7 @@ void CANClient::writeSingleLockBuckleAsync(const CANSingleLockStatus& status)
|
|
|
|
|
|
void CANClient::writeLockBuckleAsync(const CANLocksControl &status)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ quint8 nodeId = status.nodeId;
|
|
|
|
|
|
uint8_t dataByte = 0x00;
|
|
|
uint8_t workByte = 0x00;
|
|
|
@@ -1208,14 +1122,8 @@ void CANClient::writeLockBuckleAsync(const CANLocksControl &status)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readTemperatureAsync()
|
|
|
+void CANClient::readTemperatureAsync(quint8 nodeId)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, CAN_EKEY_TEMPERATURE_INDEX, CAN_EKEY_TEMPERATURE_SUBINDEX);
|
|
|
sendFrameAsync(frame, [this, nodeId](const QCanBusFrame& respFrame) {
|
|
|
double leftTemp = 0.0, rightTemp = 0.0;
|
|
|
@@ -1248,16 +1156,24 @@ void CANClient::readTemperatureAsync()
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readKeyRFIDStatusAsync()
|
|
|
+void CANClient::readAllKeyRFIDStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_EKEY_NODEID, nodeIds)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readKeyRFIDStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readKeyRFIDStatusAsync(quint8 nodeId)
|
|
|
+{
|
|
|
// 初始化钥匙RFID状态
|
|
|
CANKeyRFIDStatus keyStatus;
|
|
|
+ keyStatus.nodeId = nodeId;
|
|
|
keyStatus.leftKeyRFID = "";
|
|
|
keyStatus.rightKeyRFID = "";
|
|
|
keyStatus.leftKeyReadSuccess = false;
|
|
|
@@ -1299,7 +1215,7 @@ void CANClient::readKeyRFIDStatusAsync()
|
|
|
emit nfcDeviceDetected(currHasLock, "key", 0);
|
|
|
}
|
|
|
else if (prevLeftHasKey != currHasLock && (currHasLock.isEmpty() || currHasLock == "00000000")) {
|
|
|
- qInfo() << "[取出检测] 左钥匙:NFC卡号:" << currHasLock;
|
|
|
+ qInfo() << "[取出检测] 左钥匙:NFC卡号:" << prevLeftHasKey;
|
|
|
|
|
|
emit signalPopDevices(prevLeftHasKey, "key", 0);
|
|
|
}
|
|
|
@@ -1388,14 +1304,21 @@ void CANClient::readKeyRFIDStatusAsync()
|
|
|
msleep(CAN_SLEEP_TIME);
|
|
|
}
|
|
|
|
|
|
-void CANClient::readSingleKeyRFIDAsync(bool isLeftKey)
|
|
|
+void CANClient::readAllLocksRFIDStatusAsync()
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
+ QList<quint8> nodeIds;
|
|
|
+ if (!verifyAllNodeID(CAN_DEVICE_LOCK_NODEID, nodeIds)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ for (int i = 0; i < nodeIds.count(); i++) {
|
|
|
+ readLockRFIDStatusAsync(nodeIds[i]);
|
|
|
+ msleep(CAN_SLEEP_TIME);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CANClient::readSingleKeyRFIDAsync(quint8 nodeId, bool isLeftKey)
|
|
|
+{
|
|
|
quint16 rfidIndex = isLeftKey ? CAN_LEFT_EKEY_CARD_INDEX : CAN_RIGHT_EKEY_CARD_INDEX;
|
|
|
quint8 rfidSubIndex = isLeftKey ? CAN_LEFT_EKEY_CARD_SUBINDEX: CAN_RIGHT_EKEY_CARD_SUBINDEX;
|
|
|
QCanBusFrame frame = buildReadFrame(nodeId, rfidIndex, rfidSubIndex);
|
|
|
@@ -1426,16 +1349,11 @@ void CANClient::readSingleKeyRFIDAsync(bool isLeftKey)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readLockRFIDStatusAsync()
|
|
|
+void CANClient::readLockRFIDStatusAsync(quint8 nodeId)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
// 初始化锁RFID状态
|
|
|
CANLockRFIDStatus lockStatus;
|
|
|
+ lockStatus.nodeId = nodeId;
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
lockStatus.lockRFIDMap.insert(i, "");
|
|
|
lockStatus.lockReadSuccessMap.insert(i, false);
|
|
|
@@ -1494,7 +1412,7 @@ void CANClient::readLockRFIDStatusAsync()
|
|
|
}
|
|
|
else if (prevHasLock != currHasLock && (currHasLock.isEmpty() || currHasLock == "00000000")) {
|
|
|
qInfo() << "[取出检测] 检测到" << (lockNum+1) << "号锁被取出!";
|
|
|
- qInfo() << "[取出检测]" << (lockNum+1) << "号锁NFC卡号:" << currHasLock;
|
|
|
+ qInfo() << "[取出检测]" << (lockNum+1) << "号锁NFC卡号:" << prevHasLock;
|
|
|
emit signalPopDevices(prevHasLock, "lock", lockNum);
|
|
|
}
|
|
|
}
|
|
|
@@ -1529,14 +1447,8 @@ void CANClient::readLockRFIDStatusAsync()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CANClient::readSingleLockRFIDAsync(int lockNum)
|
|
|
+void CANClient::readSingleLockRFIDAsync(quint8 nodeId, int lockNum)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_LOCK_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
if (!checkLockNumValid(lockNum)) {
|
|
|
emit singleLockRFIDRead(lockNum, false, "");
|
|
|
return;
|
|
|
@@ -1571,15 +1483,10 @@ void CANClient::readSingleLockRFIDAsync(int lockNum)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void CANClient::readKeyBaseChargeStatusAsync()
|
|
|
+void CANClient::readKeyBaseChargeStatusAsync(quint8 nodeId)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
-
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
CANKeyBaseChargeStatus chargeStatus;
|
|
|
+ chargeStatus.nodeId = nodeId;
|
|
|
chargeStatus.leftChargeEnable = false;
|
|
|
chargeStatus.rightChargeEnable = false;
|
|
|
chargeStatus.leftChargeState = ChargeState::Uncharged;
|
|
|
@@ -1625,11 +1532,13 @@ bool CANClient::openEKey(QString& keyNFC)
|
|
|
|
|
|
for (auto iter = m_keyBaseStatus.begin(); iter != m_keyBaseStatus.end(); ++iter) {
|
|
|
if (iter->leftHasKey) {
|
|
|
+ chargeStatus.nodeId = iter.key();
|
|
|
chargeStatus.leftLocked = true;
|
|
|
chargeStatus.leftWorking = true;
|
|
|
chargeStatus.leftChargeEnable = true;
|
|
|
chargeStatus.leftChargeState = ChargeState::Charging;
|
|
|
|
|
|
+ unlockStatus.nodeId = iter.key();
|
|
|
unlockStatus.leftLocked = true;
|
|
|
unlockStatus.leftWorking = true;
|
|
|
unlockStatus.leftChargeEnable = false;
|
|
|
@@ -1641,11 +1550,13 @@ bool CANClient::openEKey(QString& keyNFC)
|
|
|
break;
|
|
|
}
|
|
|
if (iter->rightHasKey) {
|
|
|
+ chargeStatus.nodeId = iter.key();
|
|
|
chargeStatus.rightLocked = true;
|
|
|
chargeStatus.rightWorking = true;
|
|
|
chargeStatus.rightChargeEnable = true;
|
|
|
chargeStatus.rightChargeState = ChargeState::Charging;
|
|
|
|
|
|
+ unlockStatus.nodeId = iter.key();
|
|
|
unlockStatus.rightLocked = true;
|
|
|
unlockStatus.rightWorking = true;
|
|
|
unlockStatus.rightChargeEnable = false;
|
|
|
@@ -1668,6 +1579,7 @@ bool CANClient::unlockEKey()
|
|
|
{
|
|
|
CANKeyBaseChargeStatus chargeStatus;
|
|
|
for (auto iter = m_keyBaseStatus.begin(); iter != m_keyBaseStatus.end(); ++iter) {
|
|
|
+ chargeStatus.nodeId = iter.key();
|
|
|
if (iter->leftHasKey) {
|
|
|
chargeStatus.leftLocked = false;
|
|
|
chargeStatus.leftWorking = true;
|
|
|
@@ -1734,6 +1646,7 @@ bool CANClient::unlockLocks(const QList<int>& lockNums)
|
|
|
for (auto iter = m_locksControlStatus.begin(); iter != m_locksControlStatus.end(); ++iter) {
|
|
|
for (auto hasKeyIter = iter->lockHasKeyMap.begin(); hasKeyIter != iter->lockHasKeyMap.end(); ++hasKeyIter) {
|
|
|
if (hasKeyIter.value() && lockNums.contains(hasKeyIter.key())) {
|
|
|
+ lockStatus.nodeId = iter.key();
|
|
|
lockStatus.lockNums.append(hasKeyIter.key());
|
|
|
lockStatus.lockLockedMap.insert(hasKeyIter.key(), false);
|
|
|
lockStatus.lockWorkMap.insert(hasKeyIter.key(), true);
|
|
|
@@ -1755,35 +1668,12 @@ bool CANClient::unlockLocks(const QList<int>& lockNums)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool CANClient::lockingEKey(quint8 nodeId, bool leftKey, bool rightKey)
|
|
|
-{
|
|
|
- Q_UNUSED(nodeId);
|
|
|
- CANKeyBaseChargeStatus chargeStatus;
|
|
|
-
|
|
|
- if (leftKey) {
|
|
|
- chargeStatus.leftLocked = true;
|
|
|
- chargeStatus.leftWorking = true;
|
|
|
- chargeStatus.leftChargeEnable = true;
|
|
|
- chargeStatus.leftChargeState = ChargeState::Charging;
|
|
|
-
|
|
|
- }
|
|
|
- if (rightKey) {
|
|
|
- chargeStatus.rightLocked = true;
|
|
|
- chargeStatus.rightWorking = true;
|
|
|
- chargeStatus.rightChargeEnable = true;
|
|
|
- chargeStatus.rightChargeState = ChargeState::Charging;
|
|
|
- }
|
|
|
- writeKeyBaseChargeControlAsync(chargeStatus);
|
|
|
- msleep(CAN_SLEEP_TIME);
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
void CANClient::unlockEKey(const QString &keyNFC)
|
|
|
{
|
|
|
CANKeyBaseChargeStatus chargeStatus;
|
|
|
|
|
|
for (auto iter = m_keyRFIDStatus.begin(); iter != m_keyRFIDStatus.end(); ++iter) {
|
|
|
-// int nodeId = iter.key();
|
|
|
+ chargeStatus.nodeId = iter.key();
|
|
|
if (keyNFC == iter->leftKeyRFID) {
|
|
|
chargeStatus.leftLocked = false;
|
|
|
chargeStatus.leftWorking = true;
|
|
|
@@ -1810,10 +1700,11 @@ void CANClient::unlockEKey(const QString &keyNFC)
|
|
|
void CANClient::unlockLock(const QString &lockNFC)
|
|
|
{
|
|
|
CANLocksControl lockStatus;
|
|
|
- // 暂时只处理一个5路锁
|
|
|
+
|
|
|
for (auto iter = m_locksRFIDStatus.begin(); iter != m_locksRFIDStatus.end(); ++iter) {
|
|
|
for (auto hasKeyIter = iter->lockRFIDMap.begin(); hasKeyIter != iter->lockRFIDMap.end(); ++hasKeyIter) {
|
|
|
if (hasKeyIter.value() == lockNFC) {
|
|
|
+ lockStatus.nodeId = iter.key();
|
|
|
lockStatus.lockNums.append(hasKeyIter.key());
|
|
|
lockStatus.lockLockedMap.insert(hasKeyIter.key(), false);
|
|
|
lockStatus.lockWorkMap.insert(hasKeyIter.key(), true);
|
|
|
@@ -1828,11 +1719,11 @@ void CANClient::unlockLock(const QString &lockNFC)
|
|
|
|
|
|
void CANClient::writeKeyBaseChargeControlAsync(CANKeyBaseChargeStatus& chargeStatus)
|
|
|
{
|
|
|
- quint8 nodeId = 0;
|
|
|
+ quint8 nodeId = chargeStatus.nodeId;
|
|
|
|
|
|
- if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+// if (!verifyNodeID(CAN_DEVICE_EKEY_NODEID, nodeId)) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
// ========== 写入卡扣充电使能 ==========
|
|
|
uint8_t statusByte = 0x00;
|
|
|
@@ -1953,8 +1844,8 @@ QString CANClient::getLockRFID(int lockNum)
|
|
|
return itemRFID.lockRFIDMap[lockNum];
|
|
|
}
|
|
|
}
|
|
|
- readLockRFIDStatusAsync();
|
|
|
- msleep(CAN_SLEEP_TIME);
|
|
|
+// readLockRFIDStatusAsync();
|
|
|
+// msleep(CAN_SLEEP_TIME);
|
|
|
return QString();
|
|
|
}
|
|
|
|