You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.9 KiB
C++

#include "SetupService.h"
#include "device/Device.h"
#include "device/DeviceManager.h"
#include "logger/LogManager.h"
#include "frame/Frame.h"
SetupService *SetupService::m_pInstance = nullptr;
QMutex SetupService::m_mutex;
//
// 串口发送数据
//
void SetupService::SendData(unsigned char cmd, std::string data, int msec, unsigned char from)
{
Device *device = DeviceManager::GetInstance()->GetCurrDevice();
if(device == nullptr)
{
logInfo("串口尚未打开!");
return;
}
if(m_currStatus == SYS_STATUS_BUSY)
{
logInfo("系统忙!");
return;
}
device->SendData(cmd, data, msec);
m_currCmd = cmd;
m_currStatus = SYS_STATUS_BUSY;
m_currCmdFrom = from;
}
void SetupService::SendData(unsigned char cmd, Data *data, int msec, unsigned char from)
{
Device *device = DeviceManager::GetInstance()->GetCurrDevice();
if(device == nullptr)
{
logInfo("串口尚未打开!");
return;
}
if(m_currStatus == SYS_STATUS_BUSY)
{
logInfo("系统忙!");
return;
}
device->SendData(cmd, data, msec);
m_currCmd = cmd;
m_currStatus = SYS_STATUS_BUSY;
m_currCmdFrom = from;
}
void SetupService::slot_recvData(QString portName, unsigned char cmd, QByteArray recvData)
{
if(cmd != m_currCmd)
{
#ifdef _DEBUG
logDebug(tr("接收到非本次请求数据 - cmd: [%1]%2, data: %3").arg(cmd).arg(QString::fromStdString(getCmdName(cmd))).arg(recvData.toHex().data()));
#else
logInfo(tr("接收到非本次请求数据 - cmd: %1").arg(QString::fromStdString(getCmdName(cmd))));
#endif
}
else
{
#ifdef _DEBUG
logDebug(tr("接收数据 - cmd: [%1]%2, data: %3").arg(cmd).arg(QString::fromStdString(getCmdName(cmd))).arg(recvData.toHex().data()));
#else
logInfo(tr("接收数据 - cmd: %1").arg(QString::fromStdString(getCmdName(cmd))));
#endif
}
switch(cmd)
{
case FRAME_CMD_SET_TIME : //processSetTimeRsp(portName, recvData); break;
case FRAME_CMD_GET_TIME : //processGetTimeRsp(portName, recvData); break;
case FRAME_CMD_SET_SERIAL_NUMBER: //processSetSerialNumberRsp(portName, recvData); break;
case FRAME_CMD_GET_SERIAL_NUMBER: //processGetSerialNumberRsp(portName, recvData); break;
case FRAME_CMD_SET_DEVICE_NAME : //processSetDeviceNameRsp(portName, recvData); break;
case FRAME_CMD_GET_DEVICE_NAME : //processGetDeviceNameRsp(portName, recvData); break;
case FRAME_CMD_SET_DEVICE_NUMBER: //processSetDeviceNumberRsp(portName, recvData); break;
case FRAME_CMD_GET_DEVICE_NUMBER: //processGetDeviceNumberRsp(portName, recvData); break;
case FRAME_CMD_GET_RECORD : //processGetRecordRsp(portName, recvData); break;
case FRAME_CMD_CLS_RECORD : //processClsRecordRsp(portName, recvData); break;
case FRAME_CMD_SET_OPERATOR : //processSetOperatorRsp(portName, recvData); break;
case FRAME_CMD_GET_OPERATOR : //processGetOperatorRsp(portName, recvData); break;
emit recv_base_setup_rsp(portName, cmd, recvData);
break;
case FRAME_CMD_SET_LOCK_STATUS : //processSetLockStatusRsp(portName, recvData); break;
if(m_currCmdFrom == 0)
{
emit recv_base_setup_rsp(portName, cmd, recvData);
}
else if(m_currCmdFrom == 1)
{
emit recv_advance_setup_rsp(portName, cmd, recvData);
}
break;
case FRAME_CMD_SET_PASSWORD : //processSetPasswordRsp(portName, recvData); break;
case FRAME_CMD_SET_USAGE_COUNT : //processSetUsageCountRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_FALLBACK: //processSetParamRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_TORQUE : //processSetParamTorqueRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_BOLT : //processSetParamBoltRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_ANGLE : //processSetParamAngleRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_GEAR : //processSetParamGearRsp(portName, recvData); break;
case FRAME_CMD_SET_PARAM_SENSOR : //processSetParamSensorRsp(portName, recvData); break;
emit recv_advance_setup_rsp(portName, cmd, recvData);
break;
default:
logInfo(tr("Unknown CMD[%1]!").arg(cmd));
break;
}
if(cmd == FRAME_CMD_GET_RECORD)
{
// // 如果帧类型为结束帧,则设置状态为空闲
// if(recvData.length()>0 && recvData.at(0) == 0x02)
// {
// m_currStatus = SYS_STATUS_IDLE;
// //m_bSucc = true;
// }
}
else
{
m_currStatus = SYS_STATUS_IDLE;
//m_bSucc = true;
}
}
void SetupService::slot_getRecordFinish(int result)
{
logInfo(tr("get record result[%1]").arg(result));
m_currStatus = SYS_STATUS_IDLE;
}
//
// 串口设备接收消息超时事件
//
void SetupService::slot_recvTimeout(QString portName)
{
#ifdef _DEBUG
logInfo("接收消息超时!");
#endif
m_currStatus = SYS_STATUS_IDLE;
}