#include "interfaceserver.h" #include "smartlightshm.h" InterfaceServer::InterfaceServer(QObject *parent) : QTcpServer(parent) { threadList.clear(); } void InterfaceServer::start() { if(!this->listen(QHostAddress::Any,55010)){ exit(-1); } } void InterfaceServer::closeThread() { InterfaceThread *pThread = static_cast(sender()); if(pThread){ QList::iterator i; for(i=threadList.begin();i!=threadList.end();i++){ InterfaceThread *thread = *i; emit SetCommData("0008",1,QString("close thread:%1").arg(thread->cmdID())); if(thread==pThread){ threadList.removeAll(thread); pThread->deleteLater(); break; } } } } void InterfaceServer::incomingConnection(qintptr socketDescriptor) { InterfaceThread *thread = new InterfaceThread(socketDescriptor,this); connect(thread,&InterfaceThread::finished,this,&InterfaceServer::closeThread); connect(thread,&InterfaceThread::resetRequest,this,&InterfaceServer::resetRequest); connect(thread,&InterfaceThread::requestRealTimeData,this,&InterfaceServer::requestRealTimeData); connect(thread,&InterfaceThread::requestSetParameters,this,&InterfaceServer::requestSetParameters); connect(thread,&InterfaceThread::CommData,this,&InterfaceServer::CommData); threadList.append(thread); //来自平台的数据信号 thread->start(); } void InterfaceServer::setEchoString(QString CommId, QString EchoString) { emit SetCommData(CommId, 1, "EchoString"); QList::iterator i; for(i=threadList.begin();i!=threadList.end();i++){ InterfaceThread *thread = *i; emit SetCommData(CommId,1,QString("check thread:%1").arg(thread->cmdID())); // if(thread->chkCmdID(CommId)){ thread->setEchoString(EchoString); break; // } } } void InterfaceServer::resetRequest(QString deviceID, int commandType, int parameterType, int pseq){ emit SetResetRequest(deviceID,commandType,parameterType,pseq); } void InterfaceServer::requestRealTimeData(QString deviceID, int commandType, int parameterType, int pn, int queryNumber, int startPoint) { emit SetRequestRealTimeData(deviceID, commandType, parameterType, pn, queryNumber, startPoint); } void InterfaceServer::requestSetParameters(QString deviceID, int commandType, int parameterType, QString tmp) { emit SetRequestSetParameters(deviceID, commandType, parameterType, tmp); } void InterfaceServer::CommData(QString deviceID, int dir, QString data) { emit SetCommData(deviceID, dir, data); }