提交 6aa5624f 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

Change the fix-length serial nums to variant

上级 e0774521
......@@ -153,8 +153,14 @@ void MainDialog::on_pushButton_regisit_clicked()
return;
}
saveIni();
QString strSerial = ui->plainTextEdit_boxSerialNum->toPlainText();
std::string strStdSerial = strSerial.toStdString();
const char * pSrc = strStdSerial.c_str();
int nMaxLen = strStdSerial.length();
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_HostRegistReq);
+sizeof(stMsg_HostRegistReq) + nMaxLen /*Length Include \0*/;
QByteArray array(sizeof(SMARTLINK_MSG) + nMsgLen - 1,0);
char * ptr = array.data();
SMARTLINK_MSG * pMsg = (SMARTLINK_MSG *)ptr;
......@@ -177,11 +183,8 @@ void MainDialog::on_pushButton_regisit_clicked()
pApp->header.AskID = 0x01;
pApp->header.MsgType = 0x1000;
pApp->header.MsgFmtVersion = 0x01;
QString strSerial = ui->plainTextEdit_boxSerialNum->toPlainText();
std::string strStdSerial = strSerial.toStdString();
const char * pSrc = strStdSerial.c_str();
int nMaxLen = strStdSerial.length();
for (int i=0;i<64;i++)
for (int i=0;i<=nMaxLen;i++)
pApp->MsgUnion.msg_HostRegistReq.HostSerialNum[i] =
i<nMaxLen?pSrc[i]:0;
//3/10 possibility to send a data block to server
......@@ -196,8 +199,15 @@ void MainDialog::on_pushButton_Login_clicked()
return;
}
saveIni();
QString strSerial = ui->plainTextEdit_boxSerialNum->toPlainText();
std::string strStdSerial = strSerial.toStdString();
const char * pSrc = strStdSerial.c_str();
int nMaxLen = strStdSerial.length();
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_HostLogonReq);
+sizeof(stMsg_HostLogonReq) + nMaxLen /*\0 included*/;
QByteArray array(sizeof(SMARTLINK_MSG) + nMsgLen - 1,0);
char * ptr = array.data();
SMARTLINK_MSG * pMsg = (SMARTLINK_MSG *)ptr;
......@@ -220,11 +230,8 @@ void MainDialog::on_pushButton_Login_clicked()
pApp->header.AskID = 0x01;
pApp->header.MsgType = 0x1001;
pApp->header.MsgFmtVersion = 0x01;
QString strSerial = ui->plainTextEdit_boxSerialNum->toPlainText();
std::string strStdSerial = strSerial.toStdString();
const char * pSrc = strStdSerial.c_str();
int nMaxLen = strStdSerial.length();
for (int i=0;i<64;i++)
for (int i=0;i<=nMaxLen;i++)
pApp->MsgUnion.msg_HostLogonReq.HostSerialNum[i] =
i<nMaxLen?pSrc[i]:0;
pApp->MsgUnion.msg_HostLogonReq.ID = ui->lineEdit_boxid->text().toUInt();
......@@ -240,8 +247,17 @@ void MainDialog::on_pushButton_clientLogin_clicked()
return;
}
saveIni();
QString strUserName = ui->lineEdit_username->text();
QString strPassWd = ui->lineEdit_password->text();
std::string strStdUserName = strUserName.toStdString();
const char * pSrcUsername = strStdUserName.c_str();
int nMaxLenUserName = strStdUserName.length();
std::string strStdPassword = strPassWd.toStdString();
const char * pSrcPassword = strStdPassword.c_str();
int nMaxLenPassword = strStdPassword.length();
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_ClientLoginReq);
+sizeof(stMsg_ClientLoginReq)+nMaxLenUserName+nMaxLenPassword+1;
QByteArray array(sizeof(SMARTLINK_MSG) + nMsgLen - 1,0);
char * ptr = array.data();
SMARTLINK_MSG * pMsg = (SMARTLINK_MSG *)ptr;
......@@ -264,22 +280,17 @@ void MainDialog::on_pushButton_clientLogin_clicked()
pApp->header.AskID = 0x01;
pApp->header.MsgType = 0x3000;
pApp->header.MsgFmtVersion = 0x01;
QString strUserName = ui->lineEdit_username->text();
QString strPassWd = ui->lineEdit_password->text();
std::string strStdUserName = strUserName.toStdString();
const char * pSrc = strStdUserName.c_str();
int nMaxLen = strStdUserName.length();
for (int i=0;i<32;i++)
pApp->MsgUnion.msg_ClientLoginReq.UserName[i] =
i<nMaxLen?pSrc[i]:0;
std::string strStdPassword = strPassWd.toStdString();
pSrc = strStdPassword.c_str();
nMaxLen = strStdPassword.length();
for (int i=0;i<32;i++)
pApp->MsgUnion.msg_ClientLoginReq.Password[i] =
i<nMaxLen?pSrc[i]:0;
for (int i=0;i<=nMaxLenUserName;i++)
pApp->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[i] =
i<nMaxLenUserName?pSrcUsername[i]:0;
for (int i=0;i<=nMaxLenPassword;i++)
pApp->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[i+nMaxLenUserName+1] =
i<nMaxLenPassword?pSrcPassword[i]:0;
pApp->MsgUnion.msg_ClientLoginReq.ClientVersion = 0;
......
......@@ -16,7 +16,16 @@ namespace SmartLink{
(const SMARTLINK_MSG_APP *)(
((const char *)(m_currentBlock.constData()))
+sizeof(SMARTLINK_MSG)-1);
//form Msgs
int nAppLen = m_currentBlock.length()- (sizeof(SMARTLINK_MSG)-1);
QString strSerial ;
for (int i=0;i<nAppLen /*64*/ && pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i]!=0 ;i++)
{
strSerial+= pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i];
m_serialNum[i] = pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i];
}
//form return Msgs
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_HostRegistRsp);
QByteArray array(sizeof(SMARTLINK_MSG) + nMsgLen - 1,0);
......@@ -53,12 +62,7 @@ namespace SmartLink{
if (db.isValid()==true && db.isOpen()==true )
{
QSqlQuery query(db);
QString strSerial ;
for (int i=0;i<64 && pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i]!=0 ;i++)
{
strSerial+= pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i];
m_serialNum[i] = pAppLayer->MsgUnion.msg_HostRegistReq.HostSerialNum[i];
}
QString sql = "select host_serial_num,equip_id,first_login from instruments where host_serial_num = ?;";
query.prepare(sql);
query.addBindValue(strSerial);
......@@ -137,6 +141,14 @@ namespace SmartLink{
(const SMARTLINK_MSG_APP *)(
((const char *)(m_currentBlock.constData()))
+sizeof(SMARTLINK_MSG)-1);
int nAppLen = m_currentBlock.length()- (sizeof(SMARTLINK_MSG)-1);
QString strSerial ;
for (int i=0;i<nAppLen && pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i]!=0;i++)
{
strSerial+= pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i];
m_serialNum[i] = pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i];
}
//form Msgs
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_HostLogonRsp);
......@@ -173,12 +185,7 @@ namespace SmartLink{
if (db.isValid()==true && db.isOpen()==true )
{
QSqlQuery query(db);
QString strSerial ;
for (int i=0;i<64 && pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i]!=0;i++)
{
strSerial+= pAppLayer->MsgUnion.msg_HostLogonReq.HostSerialNum[i];
m_serialNum[i] = 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);
......@@ -249,6 +256,21 @@ namespace SmartLink{
(const SMARTLINK_MSG_APP *)(
((const char *)(m_currentBlock.constData()))
+sizeof(SMARTLINK_MSG)-1);
int nAppLen = m_currentBlock.length()- (sizeof(SMARTLINK_MSG)-1) - sizeof (quint16);
QString strUserName, strPasswd ;
int nSwim = 0;
int usernameLen = 0, passwordlen = 0;
while (nSwim < nAppLen && pAppLayer->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[nSwim]!=0 )
{
m_username[usernameLen++] = pAppLayer->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[nSwim];
strUserName+= pAppLayer->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[nSwim];
++nSwim;
}
++nSwim;
while ( nSwim < nAppLen && pAppLayer->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[nSwim]!=0 )
strPasswd+= pAppLayer->MsgUnion.msg_ClientLoginReq.UserNameAndPasswd[nSwim++];
//form Msgs
quint16 nMsgLen = sizeof(SMARTLINK_MSG_APP::tag_app_layer_header)
+sizeof(stMsg_ClientLoginRsp);
......@@ -285,14 +307,6 @@ namespace SmartLink{
if (db.isValid()==true && db.isOpen()==true )
{
QSqlQuery query(db);
QString strUserName, strPasswd ;
for (int i=0;i<32 && pAppLayer->MsgUnion.msg_ClientLoginReq.UserName[i]!=0;i++)
{
m_username[i] = pAppLayer->MsgUnion.msg_ClientLoginReq.UserName[i];
strUserName+= pAppLayer->MsgUnion.msg_ClientLoginReq.UserName[i];
}
for (int i=0;i<32 && pAppLayer->MsgUnion.msg_ClientLoginReq.Password[i]!=0;i++)
strPasswd+= pAppLayer->MsgUnion.msg_ClientLoginReq.Password[i];
QString sql = "select user_name,user_id,password from users where user_name = ? and password = ?;";
query.prepare(sql);
......
......@@ -256,10 +256,10 @@ namespace SmartLink{
if (bytesLeft()>0)
// message is not complete, return
return true;
if (m_currentMessageSize!=
if (m_currentMessageSize>
sizeof(SMARTLINK_MSG) - 1
+ sizeof (SMARTLINK_MSG_APP::tag_app_layer_header)
+ sizeof (stMsg_HostRegistReq))
+ sizeof (stMsg_HostRegistReq)+64)
{
emit evt_Message(tr("Broken Message stMsg_HostRegistReq, size not correct."));
res = false;
......@@ -271,10 +271,10 @@ namespace SmartLink{
if (bytesLeft()>0)
// message is not complete, return
return true;
if (m_currentMessageSize!=
if (m_currentMessageSize>
sizeof(SMARTLINK_MSG) - 1
+ sizeof (SMARTLINK_MSG_APP::tag_app_layer_header)
+ sizeof (stMsg_HostLogonReq))
+ sizeof (stMsg_HostLogonReq)+64)
{
emit evt_Message(tr("Broken Message stMsg_HostLogonReq, size not correct."));
res = false;
......@@ -286,10 +286,10 @@ namespace SmartLink{
if (bytesLeft()>0)
// message is not complete, return
return true;
if (m_currentMessageSize!=
if (m_currentMessageSize>
sizeof(SMARTLINK_MSG) - 1
+ sizeof (SMARTLINK_MSG_APP::tag_app_layer_header)
+ sizeof (stMsg_ClientLoginReq))
+ sizeof (stMsg_ClientLoginReq)+66)
{
emit evt_Message(tr("Broken Message stMsg_ClientLoginReq, size not correct."));
res = false;
......
......@@ -11,14 +11,14 @@ namespace SmartLink{
//Host Reg request, send 64 byte Serial Num to Server
//SMARTLINK_MSG_APP::MsgType = 0x1000
typedef struct tag_stMsg_HostRegistReq{
char HostSerialNum[64];
char HostSerialNum[1];//max 64
}stMsg_HostRegistReq;
//Host Reg replay, send back 4 byte ID
//SMARTLINK_MSG_APP::MsgType = 0x1800
typedef struct tag_stMsg_HostRegistRsp{
__UINT8_TYPE__ DoneCode;//0 first ok, 1 ok 2 failed
char TextInfo[64];
//char TextInfo[64];
__UINT32_TYPE__ ID;
}stMsg_HostRegistRsp;
......@@ -26,22 +26,22 @@ namespace SmartLink{
//SMARTLINK_MSG_APP::MsgType = 0x1001
typedef struct tag_stMsg_HostLogonReq{
__UINT32_TYPE__ ID;
char HostSerialNum[64];
char HostSerialNum[1];//max 64
} stMsg_HostLogonReq;
//Host Log response
//SMARTLINK_MSG_APP::MsgType = 0x1801
typedef struct tag_stMsg_HostLogonRsp{
__UINT8_TYPE__ DoneCode;
char TextInfo[64];
//char TextInfo[64];
} stMsg_HostLogonRsp;
//User Login request
//SMARTLINK_MSG_APP::MsgType = 0x3000
typedef struct tag_stMsg_ClientLoginReq{
__UINT16_TYPE__ ClientVersion;
char UserName[32];
char Password[32];
char UserNameAndPasswd[1];
//char Password[32];
}stMsg_ClientLoginReq;
//User Log response
......@@ -49,7 +49,7 @@ namespace SmartLink{
typedef struct tag_stMsg_ClientLoginRsp{
__UINT8_TYPE__ DoneCode;
__UINT32_TYPE__ UserID;
char TextInfo[64];
//char TextInfo[64];
} stMsg_ClientLoginRsp;
//User Log response
......@@ -61,7 +61,7 @@ namespace SmartLink{
//Time Correct
typedef struct tag_stMsg_HostTimeCorrectRsp{
__UINT8_TYPE__ DoneCode;
char TextInfo[64];
//char TextInfo[64];
struct tag_stDateTime{
__UINT16_TYPE__ Year;
__UINT8_TYPE__ Month;
......@@ -82,7 +82,7 @@ namespace SmartLink{
//SMARTLINK_MSG_APP::MsgType = 0x1803
typedef struct tag_stMsg_UploadUserListRsp{
__UINT8_TYPE__ DoneCode;
char TextInfo[64];
//char TextInfo[64];
} stMsg_UploadUserListRsp;
//SMARTLINK_MSG_APP::MsgType = 0x1004
......@@ -93,7 +93,7 @@ namespace SmartLink{
//SMARTLINK_MSG_APP::MsgType = 0x1804
typedef struct tag_stMsg_DownloadUserListRsp{
__UINT8_TYPE__ DoneCode;
char TextInfo[64];
//char TextInfo[64];
__UINT16_TYPE__ UserNum;
__UINT32_TYPE__ pUserIDList[1];
} stMsg_DownloadUserListRsp;
......@@ -101,13 +101,13 @@ namespace SmartLink{
//0x3001
typedef struct tag_stMsg_ClientLogoutReq{
char UserName[32];
char UserName[1];//max 32
}stMsg_ClientLogoutReq;
//0x3801
typedef struct tag_stMsg_ClientLogoutRsp{
__UINT8_TYPE__ DoneCode;
char TextInfo[64];
//char TextInfo[64];
}stMsg_ClientLogoutRsp;
//SMARTLINK_MSG_APP::MsgType = 0x3002
......@@ -154,7 +154,7 @@ namespace SmartLink{
//Host Reg request, send 64 byte Serial Num to Server
//SMARTLINK_MSG_APP::MsgType = 0x1000
typedef struct tag_stMsg_HostRegistReq{
char HostSerialNum[64];
char HostSerialNum[1];//max 64
}stMsg_HostRegistReq;
......@@ -170,7 +170,7 @@ namespace SmartLink{
//SMARTLINK_MSG_APP::MsgType = 0x1001
typedef struct tag_stMsg_HostLogonReq{
unsigned __int32 ID;
char HostSerialNum[64];
char HostSerialNum[1];//max 64
} stMsg_HostLogonReq;
//Host Log response
......@@ -184,8 +184,8 @@ namespace SmartLink{
//SMARTLINK_MSG_APP::MsgType = 0x3000
typedef struct tag_stMsg_ClientLoginReq{
unsigned __int16 ClientVersion;
char UserName[32];
char Password[32];
char UserNameAndPasswd[1];//max 65
//char Password[1];//max 32
}stMsg_ClientLoginReq;
//User Log response
......@@ -246,7 +246,7 @@ namespace SmartLink{
//0x3001
typedef struct tag_stMsg_ClientLogoutReq{
char UserName[32];
char UserName[1];//max 32
}stMsg_ClientLogoutReq;
//0x3801
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册