123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include "smartlightserver.h"
- #include "smartlightshm.h"
- SmartLightServer::SmartLightServer(QObject *parent) : QTcpServer(parent)
- {
- threadList.clear();
- }
- void SmartLightServer::start(){
- if(!this->listen(QHostAddress::Any,ServerPort)){
- exit(-1);
- }
- }
- void SmartLightServer::incomingConnection(qintptr socketDescriptor){
- SmartLightCommThread *thread = new SmartLightCommThread(socketDescriptor,this);
- connect(thread,&SmartLightCommThread::CommData,this,&SmartLightServer::eCommData);
- connect(thread,&SmartLightCommThread::getEAlarm,this,&SmartLightServer::egetEAlarm);
- connect(thread,&SmartLightCommThread::getEAnalogValue,this,&SmartLightServer::egetEAnalogValue);
- connect(thread,&SmartLightCommThread::getERealtimeValue,this,&SmartLightServer::getERealtimeValue);
- connect(thread,&SmartLightCommThread::finished,this,&SmartLightServer::closeThread);
- thread->start();
- threadList.append(thread);
- }
- void SmartLightServer::eCommData(QString DeviceID, int dir, QString data)
- {
- emit CommData(DeviceID, dir, data);
- }
- void SmartLightServer::egetEAlarm(QString DeviceCode, int erc, int sta, int arg1, int arg2, int arg3, float value, float v2, QString others, QDateTime t)
- {
- emit getEAlarm(DeviceCode,erc,sta,arg1,arg2,arg3,value,v2,others,t);
- }
- void SmartLightServer::egetEAnalogValue(QString DeviceCode, int point, float ave, float rtv, QDateTime t, float maxv, QDateTime maxt, float minv, QDateTime mint)
- {
- emit getEAnalogValue(DeviceCode,point,ave,rtv,t,maxv,maxt,minv,mint);
- }
- void SmartLightServer::egetERealtimeValue(QString DeviceCode, int point, float rtv, QDateTime t)
- {
- emit getERealtimeValue(DeviceCode, point, rtv,t);
- }
- void SmartLightServer::mk_EventList_qry(QString deviceId, quint8 type, quint8 cur, quint8 num)
- {
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(QString::compare(thread->deviceID(),deviceId)==0){
- thread->mk_EventList_qry(deviceId,type,cur,num);
- break;
- }
- }
- }
- void SmartLightServer::mk_ResetList_qry(QString deviceId, int commandType, QString parameterType, int pseq)
- {
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(QString::compare(thread->deviceID(),deviceId)==0){
- emit CommData(deviceId, 1, "servicedeviceId");
- if(commandType==2){
- thread->reset_command(deviceId);
- break;
- }else if(commandType==11){
- if(QString::compare(parameterType,"f9")==0){
- thread->query_parameters_commandf9(deviceId,parameterType);
- break;
- }else{
- thread->query_parameters_command(deviceId,parameterType,pseq);
- break;
- }
- }
- }
- }
- }
- void SmartLightServer::mk_realtime_qry(QString deviceId, int commandType, int parameterType, int pn, int queryNumber, int startPoint)
- {
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(QString::compare(thread->deviceID(),deviceId)==0){
- if(commandType==12){
- if(parameterType==2||parameterType==3||parameterType==4||parameterType==25){
- thread->request_real_time_data_command(deviceId,parameterType);
- break;
- }else if(parameterType==9||parameterType==10||parameterType==11||parameterType==12||parameterType==17||parameterType==33||parameterType==34||parameterType==35||parameterType==36||parameterType==37||parameterType==38||parameterType==39||parameterType==100){
- thread->request_real_time_data_command2(deviceId,parameterType,pn,queryNumber,startPoint);
- break;
- }
- }else if(commandType==5){
- if(parameterType==2||parameterType==1||parameterType==3||parameterType==9){
- thread->request_control_command(deviceId,parameterType,pn,queryNumber,startPoint);
- break;
- }
- }else if(commandType==14){
- thread->request_event_data_command(deviceId,parameterType,pn,queryNumber);
- break;
- }
- }
- }
- }
- void SmartLightServer::mk_set_parameters_qry(QString deviceId, int commandType, int parameterType, QString data_list)
- {
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(QString::compare(thread->deviceID(),deviceId)==0){
- if(commandType==4){
- if(parameterType==9){
- thread->request_set_parameters_command(deviceId,parameterType,data_list);
- emit CommData(deviceId, 2, "++++++++++ceshi+++++++++++");
- break;
- }
- }
- }
- }
- }
- void SmartLightServer::mk_hisData_qry(QString deviceId, quint16 f_pno, quint16 f_fno, QDateTime t1, QDateTime t2, quint8 sep, quint8 num)
- {
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(QString::compare(thread->deviceID(),deviceId)==0){
- thread->mk_hisData_qry(deviceId, f_pno, f_fno, t1, t2, sep, num);
- break;
- }
- }
- }
- void SmartLightServer::closeThread()
- {
- SmartLightCommThread *pThread = static_cast<SmartLightCommThread *>(sender());
- if(pThread){
- QList<SmartLightCommThread *>::iterator i;
- for(i=threadList.begin();i!=threadList.end();i++){
- SmartLightCommThread *thread = *i;
- if(thread==pThread){
- threadList.removeAll(thread);
- pThread->deleteLater();
- break;
- }
- }
- }
- }
|