0712提交
This commit is contained in:
@@ -315,81 +315,109 @@ bool udpComm::pushMsgToQueue(unsigned char *m)
|
||||
|
||||
bool udpComm::clearMsgQueue()
|
||||
{
|
||||
while(!m_qReceiveCcuStateBuffer.empty())
|
||||
m_qReceiveCcuStateBuffer.pop();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexCcuState);
|
||||
while(!m_qReceiveCcuStateBuffer.empty())
|
||||
m_qReceiveCcuStateBuffer.pop();
|
||||
}
|
||||
|
||||
while(!m_qReceiveCcuSetParmBuffer.empty())
|
||||
m_qReceiveCcuSetParmBuffer.pop();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexCcuSetParm);
|
||||
while(!m_qReceiveCcuSetParmBuffer.empty())
|
||||
m_qReceiveCcuSetParmBuffer.pop();
|
||||
}
|
||||
|
||||
while(!m_qReceiveDisHighVolBusBuffer.empty())
|
||||
m_qReceiveDisHighVolBusBuffer.pop();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighVolBus);
|
||||
while(!m_qReceiveDisHighVolBusBuffer.empty())
|
||||
m_qReceiveDisHighVolBusBuffer.pop();
|
||||
}
|
||||
|
||||
while(!m_qReceiveDisHighAVolBusBuffer.empty())
|
||||
m_qReceiveDisHighAVolBusBuffer.pop();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighAVolBus);
|
||||
while(!m_qReceiveDisHighAVolBusBuffer.empty())
|
||||
m_qReceiveDisHighAVolBusBuffer.pop();
|
||||
}
|
||||
|
||||
while(!m_qReceiveDisHighBVolBusBuffer.empty())
|
||||
m_qReceiveDisHighBVolBusBuffer.pop();
|
||||
|
||||
while(!m_qReceiveDisLowBusBuffer.empty())
|
||||
m_qReceiveDisLowBusBuffer.pop();
|
||||
return true;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighBVolBus);
|
||||
while(!m_qReceiveDisHighBVolBusBuffer.empty())
|
||||
m_qReceiveDisHighBVolBusBuffer.pop();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisLowBus);
|
||||
while(!m_qReceiveDisLowBusBuffer.empty())
|
||||
m_qReceiveDisLowBusBuffer.pop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_CcuStateFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveCcuStateBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveCcuStateBuffer.front().first;
|
||||
m = m_qReceiveCcuStateBuffer.front().second;
|
||||
m_qReceiveCcuStateBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexCcuState);
|
||||
if(m_qReceiveCcuStateBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveCcuStateBuffer.front().first;
|
||||
m = m_qReceiveCcuStateBuffer.front().second;
|
||||
m_qReceiveCcuStateBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_CcuSetParmFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveCcuSetParmBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveCcuSetParmBuffer.front().first;
|
||||
m = m_qReceiveCcuSetParmBuffer.front().second;
|
||||
m_qReceiveCcuSetParmBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexCcuSetParm);
|
||||
if(m_qReceiveCcuSetParmBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveCcuSetParmBuffer.front().first;
|
||||
m = m_qReceiveCcuSetParmBuffer.front().second;
|
||||
m_qReceiveCcuSetParmBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_disHighVolBusFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveDisHighVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighVolBusBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighVolBus);
|
||||
if(m_qReceiveDisHighVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighVolBusBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_disHighAVolBusFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveDisHighAVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighAVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighAVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighAVolBusBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighAVolBus);
|
||||
if(m_qReceiveDisHighAVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighAVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighAVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighAVolBusBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_disLowMainBusFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveDisHighBVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighBVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighBVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighBVolBusBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisHighBVolBus);
|
||||
if(m_qReceiveDisHighBVolBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisHighBVolBusBuffer.front().first;
|
||||
m = m_qReceiveDisHighBVolBusBuffer.front().second;
|
||||
m_qReceiveDisHighBVolBusBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udpComm::popMsgFormQueue(double &time,msg_disLowBusFbMsg &m)
|
||||
{
|
||||
if(m_qReceiveDisLowBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisLowBusBuffer.front().first;
|
||||
m = m_qReceiveDisLowBusBuffer.front().second;
|
||||
m_qReceiveDisLowBusBuffer.pop();
|
||||
return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutexDisLowBus);
|
||||
if(m_qReceiveDisLowBusBuffer.empty())
|
||||
return false;
|
||||
time = m_qReceiveDisLowBusBuffer.front().first;
|
||||
m = m_qReceiveDisLowBusBuffer.front().second;
|
||||
m_qReceiveDisLowBusBuffer.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -528,32 +556,19 @@ bool udpComm::sendCcuColCmd(const ccuColCmd cmd)
|
||||
msgBuf = reinterpret_cast<unsigned char *>(msg);
|
||||
cc = calculateChecksum(msgBuf,sizeof(msg_CcuColCmdMsg));
|
||||
msg->checkCode = static_cast<cChecksum>(cc & 0xFF);
|
||||
try
|
||||
{
|
||||
if(udpScoket == nullptr) {
|
||||
throw std::runtime_error("UDP socket not initialized");
|
||||
|
||||
bool sendResult = false;
|
||||
try {
|
||||
sendResult = sendMsg(msgBuf,sizeof(msg_CcuColCmdMsg));
|
||||
if (!sendResult) {
|
||||
LOG_F(ERROR, "Failed to send CCU command");
|
||||
}
|
||||
if(ccuHost.empty() || ccuPort <= 0 || ccuPort > 65535) {
|
||||
throw std::runtime_error("Invalid CCU address: " + ccuHost + ":" + std::to_string(ccuPort));
|
||||
}
|
||||
sendMsg(msgBuf,sizeof(msg_CcuColCmdMsg));
|
||||
}
|
||||
catch(const std::invalid_argument& e)
|
||||
{
|
||||
std::cerr << "Invalid argument error in CCU command: " << e.what() << '\n';
|
||||
LOG_F(ERROR, "Invalid argument in CCU command: %s", e.what());
|
||||
delete msg;
|
||||
return false;
|
||||
}
|
||||
catch(const std::out_of_range& e)
|
||||
{
|
||||
std::cerr << "Out of range error in CCU command: " << e.what() << '\n';
|
||||
LOG_F(ERROR, "Out of range in CCU command: %s", e.what());
|
||||
delete msg;
|
||||
return false;
|
||||
} catch (const std::exception& e) {
|
||||
LOG_F(ERROR, "Exception in sendCcuColCmd: %s", e.what());
|
||||
}
|
||||
|
||||
delete msg;
|
||||
return true;
|
||||
return sendResult;
|
||||
}
|
||||
bool udpComm::sendCcuSetParmCmd(const ccuSetParmCmd cmd)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user