diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode.h b/ZoomPipeline_FuncSvr/smartlink/st_clientnode.h index dcb79f7e7f40e56ca13b4bc1a989630fcacd9e24..8b92b51d9c2fa79be235fc54337c2cebfa057ec0 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode.h @@ -45,10 +45,12 @@ protected: //Message Dealers, imp in st_clientnode_msgdeal.cpp bool Deal_BoxToServer_Messages(); - //0x0001 msg, stMsg_HostRegistReq + //0x1000<->0x1800 msg, stMsg_HostRegistReq QMutex m_mutex_equipID; bool RegisitNewNode(); quint32 AssignNewEquipID(const QString & serial); + //0x1001<->0x1801 msg, stMsg_HostLogonReq + bool LoginSvr(); //data items diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_impdeal.cpp b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_impdeal.cpp index e838cdfa6234c6d77b0e1798a4f8d1a819068473..ffbe14447533011fe5995d9f70045a9fd94b2b92 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_impdeal.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_impdeal.cpp @@ -140,5 +140,110 @@ quint32 st_clientNode::AssignNewEquipID(const QString & serial) } return id; } +bool st_clientNode::LoginSvr() +{ + SMARTLINK_MSG_APP * pAppLayer = + (SMARTLINK_MSG_APP *)( + ((const char *)(m_currentBlock.constData())) + +sizeof(SMARTLINK_MSG)-1); + //form Msgs + quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header) + +sizeof(stMsg_HostLogonRsp); + QByteArray array(sizeof(SMARTLINK_MSG) + nMsgLen - 1,0); + char * ptr = array.data(); + SMARTLINK_MSG * pMsg = (SMARTLINK_MSG *)ptr; + SMARTLINK_MSG_APP * pApp = (SMARTLINK_MSG_APP *)(((unsigned char *) + (ptr))+sizeof(SMARTLINK_MSG)-1 + ); + pMsg->Mark = 0x55AA; + pMsg->version = m_currentHeader.version; + pMsg->SerialNum = m_currentHeader.SerialNum; + pMsg->Priority = m_currentHeader.Priority; + pMsg->Reserved1 = 0; + pMsg->source_id = (quint32)((quint64)(m_currentHeader.destin_id) & 0xffffffff ); + + pMsg->destin_id = (quint32)((quint64)(m_currentHeader.source_id) & 0xffffffff );; + + pMsg->data_length = nMsgLen; + pMsg->Reserved2 = 0; + + pApp->header.AskID = m_current_app_header.header.AskID; + pApp->header.MsgType = 0x1801; + pApp->header.MsgFmtVersion = m_current_app_header.header.MsgFmtVersion; + + stMsg_HostLogonRsp & reply = pApp->MsgUnion.msg_HostLogonRsp; + + //Check the database, find current equipment info + QSqlDatabase db = m_pClientTable->dbRes()->databse(m_pClientTable->Database_UserAcct()); + + reply.DoneCode = 3; + strcpy(reply.TextInfo,"Unknown error"); + if (db.isValid()==true && db.isOpen()==true ) + { + QSqlQuery query(db); + QString strSerial ; + for (int i=0;i<64;i++) + { + strSerial+= pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i]; + } + QString sql = "select host_serial_num,equip_id from instruments where host_serial_num = ?;"; + query.prepare(sql); + query.addBindValue(strSerial); + + if (true==query.exec()) + { + if (query.next()) + { + bool bOk = false; + int ncurrid = query.value(1).toInt(&bOk); + if (bOk==true) + { + if (ncurrid>=0x0010000 && ncurrid <=0x0FFFFFFF) + { + reply.ID = ncurrid; + reply.DoneCode = 1; + strcpy(reply.TextInfo,"Re-regisit Succeed."); + } + else + { + reply.ID = AssignNewEquipID(strSerial); + if (reply.ID>=0x0010000 && reply.ID <=0x0FFFFFFF) + { + reply.DoneCode = 0; + strcpy(reply.TextInfo,"First-regisit Succeed."); + } + else + strcpy(reply.TextInfo,"Equip ID resource error."); + } + } + else + strcpy(reply.TextInfo,"Raw Dev ID Is Invalid."); + } + else + { + // No such device + strcpy(reply.TextInfo,"No such device ID."); + } + } + else + { + strcpy(reply.TextInfo,"Server Access Error."); + emit evt_Message(tr("Database Access Error :")+query.lastError().text()); + } + } + else + { + //Server db is currently not accessable, wait. + strcpy(reply.TextInfo,"Server Not Accessable Now."); + } + + + //Send back + emit evt_SendDataToClient(this->sock(),array); + + + + return reply.DoneCode==2?false:true; +} } diff --git a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_msgdeal.cpp b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_msgdeal.cpp index 1cc70bbe325cdcb38be283cad3e889a14ee62171..a637182cf2a4f7251196344e1f10b832c1912946 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_clientnode_msgdeal.cpp +++ b/ZoomPipeline_FuncSvr/smartlink/st_clientnode_msgdeal.cpp @@ -4,6 +4,7 @@ namespace SmartLink{ bool st_clientNode::Deal_BoxToServer_Messages() { + bool res = true; //The bytes left to recieve. qint32 bytesLeft = m_currentHeader.data_length + sizeof(SMARTLINK_MSG) - 1 -m_currentMessageSize ; @@ -40,20 +41,35 @@ bool st_clientNode::Deal_BoxToServer_Messages() + sizeof (stMsg_HostRegistReq)) { emit evt_Message(tr("Broken Message stMsg_HostRegistReq, size not correct.")); - emit evt_close_client(this->sock()); - return false; + res = false; } - return this->RegisitNewNode(); + else + res = this->RegisitNewNode(); + break; + case 0x1001: + if (bytesLeft>0) + // message is not complete, return + return true; + if (m_currentMessageSize!= + sizeof(SMARTLINK_MSG) - 1 + + sizeof (SMARTLINK_MSG_APP::tag_app_layer_header) + + sizeof (stMsg_HostLogonReq)) + { + emit evt_Message(tr("Broken Message stMsg_HostLogonReq, size not correct.")); + res = false; + } + else + res = this->LoginSvr(); break; default: emit evt_Message(tr("Message type not supported.")); - emit evt_close_client(this->sock()); + res = false; break; } m_currentBlock.clear(); - return true; + return res; } } diff --git a/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h b/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h index 9b658649b55eb4b5d424a95bc01069472f3a5a8e..60d1865511a900400e8c1eb82a550b9c7a81b9ad 100644 --- a/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h +++ b/ZoomPipeline_FuncSvr/smartlink/st_msg_applayer.h @@ -22,6 +22,12 @@ typedef struct tag_stMsg_HostRegistRsp{ __UINT32_TYPE__ ID; }stMsg_HostRegistRsp; +//Host Log request +//SMARTLINK_MSG_APP::MsgType = 0x1001 +typedef struct tag_stMsg_HostLogonReq{ + __UINT32_TYPE__ ID; + char HostSerialNum[64]; +} stMsg_HostLogonReq; typedef struct tag_smartlink_app_layer{ struct tag_app_layer_header{ @@ -33,6 +39,8 @@ typedef struct tag_smartlink_app_layer{ { stMsg_HostRegistReq msg_HostRegistReq; stMsg_HostRegistRsp msg_HostRegistRsp; + stMsg_HostLogonReq msg_HostLogonReq; + stMsg_HostLogonRsp msg_HostLogonRsp; }MsgUnion; } SMARTLINK_MSG_APP; @@ -55,6 +63,20 @@ typedef struct tag_stMsg_HostRegistRsp{ unsigned __int32 ID; }stMsg_HostRegistRsp; +//Host Log request +//SMARTLINK_MSG_APP::MsgType = 0x1001 +typedef struct tag_stMsg_HostLogonReq{ + unsigned __int32 ID; + char HostSerialNum[64]; +} stMsg_HostLogonReq; + +//Host Log response +//SMARTLINK_MSG_APP::MsgType = 0x1801 +typedef struct tag_stMsg_HostLogonRsp{ + unsigned __int8 DoneCode; + char TextInfo[64]; +} stMsg_HostLogonRsp; + typedef struct tag_smartlink_app_layer{ struct tag_app_layer_header{ @@ -66,6 +88,8 @@ typedef struct tag_smartlink_app_layer{ { stMsg_HostRegistReq msg_HostRegistReq; stMsg_HostRegistRsp msg_HostRegistRsp; + stMsg_HostLogonReq msg_HostLogonReq; + stMsg_HostLogonRsp msg_HostLogonRsp; }MsgUnion; } SMARTLINK_MSG_APP;