📄 udpserver.c
字号:
memset(temppsw,0,7);
memcpy(tempname,(pUserData->userinfo.name),10);
memcpy(temppsw,(pUserData->userinfo.psw),6);
Uart_Printf("tempname = ");
for (i=0;i<10;i++)
{
Uart_Printf("%.2x",tempname[i]);
}
Uart_Printf("\n");
Uart_Printf("temppsw = ");
for (i=0;i<6;i++)
{
Uart_Printf("%.2x",temppsw[i]);
}
Uart_Printf("\n");
#endif
//解密
decode = Des_Go(tempstr,tempstr,16,key[((pMsg->keyNo)%10)], sizeof(key[((pMsg->keyNo)%10)]), DECRYPT);
if(1 != decode)
{
//Uart_Printf("Des_Go: failure\n");
//Uart_Printf("tempstr: %s\n",tempstr);
return CI_FAILURE;
}
#if 0
Uart_Printf("pass Des_Go\n");
Uart_Printf("tempstr = ");
for (i=0;i<16;i++)
{
Uart_Printf("%c",tempstr[i]);
}
Uart_Printf("\n");
#endif
memcpy(name,tempstr,10);
memcpy(psw,(tempstr+10),6);
//Uart_Printf("name = %s\n",name);
//Uart_Printf("psw = %s\n",psw);
errCode = CheckUserData(name,psw,&userNo);
switch (errCode)
{
case USER_INPUT_ERR:
{
Data.errCode = CI_FAILURE;
Data.failCode = USER_INPUT_ERR;
Data.userinfo = pUserData->userinfo;
break;
}
case USER_NOT_EXIST:
{
//Uart_Printf("UserProc: USER_NOT_EXIST\n ");
Data.errCode = CI_FAILURE;
Data.failCode = USER_NOT_EXIST;
Data.userinfo = pUserData->userinfo;
//memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Varify_UserInfo));
#if 0
memcpy(Data.userinfo.name,pUserData->userinfo.name,11);
memcpy(Data.userinfo.psw,pUserData->userinfo.psw,7);
//Uart_Printf("1 \n ");
Data.userinfo.keyNo = pUserData->userinfo.keyNo;
//Uart_Printf("2 \n ");
Data.userinfo.status = pUserData->userinfo.status;
//Uart_Printf("3 \n ");
Data.userinfo.Validtime = 5;
//Uart_Printf("4 \n ");
pUserData->userinfo.Validtime = 6;
//Uart_Printf("5 \n ");
Data.userinfo.Validtime = pUserData->userinfo.Validtime;
//Uart_Printf("UserProc: USER_NOT_EXIST break\n ");
#endif
//Uart_Printf("UserProc: USER_NOT_EXIST break\n ");
break;
}
case USER_PSW_ERR:
{
Data.errCode = CI_FAILURE;
Data.failCode = USER_PSW_ERR;
Data.userinfo = pUserData->userinfo;
break;
}
case USER_VALID:
{
userdata[userNo].status = USER_ONLINE_STATUS;
userdata[userNo].keyNo = pMsg->keyNo;
Data.errCode = CI_SUCCESS;
Data.userinfo = pUserData->userinfo;
}
}
//Uart_Printf("msg.msgBody\n");
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Varify_UserInfo));
msg.msgLenth = sizeof(struct Varify_UserInfo);
//Uart_Printf("msg.msgLenth = %d!!!!!! \n",msg.msgLenth);
//Uart_Printf("CheckUserData past: errCode = %d!!!!!! ",errCode);
sendmessage(conn,&msg);
errCode = CI_SUCCESS;
break;
}
case USER_OUT_MSG:
{
//Uart_Printf("DataProc: stop\n");
struct Varify_UserInfo Data;
Data.errCode = CI_FAILURE;
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Varify_UserInfo));
msg.msgLenth = sizeof(struct Varify_UserInfo);
sendmessage(conn,&msg);
errCode = CI_SUCCESS;
break;
}
default:
{
return CI_FAILURE;
}
}
return errCode;
}
_US DataProc(struct netconn *conn,struct CS_Msg_Struct * pMsg)
{
struct Data_Collection_Msg Data;
struct CS_Msg_Struct msg;
if ((NULL == pMsg)||(NULL == conn))
{
return CI_FAILURE;
}
msg.m_id = pMsg->m_id;
msg.msgType = pMsg->msgType;
msg.keyNo = pMsg->keyNo;
switch (pMsg->msgType)
{
case DATA_COLLECTION_START:
{
//Uart_Printf("DataProc: start\n");
Data.errCode = CI_SUCCESS;
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Data_Collection_Msg));
msg.msgLenth = sizeof(struct Data_Collection_Msg);
sendmessage(conn,&msg);
SampleFlag = 1;
break;
}
case DATA_COLLECTION_STOP:
{
//Uart_Printf("DataProc: stop\n");
Data.errCode = CI_SUCCESS;
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Data_Collection_Msg));
msg.msgLenth = sizeof(struct Data_Collection_Msg);
sendmessage(conn,&msg);
SampleFlag = 0;
break;
}
default:
{
return CI_FAILURE;
}
}
return CI_SUCCESS;
}
//灯操作
_US TempProc(struct netconn *conn,struct CS_Msg_Struct * pMsg)
{
struct Temp_Collection_Msg Data;
struct CS_Msg_Struct msg;
if ((NULL == pMsg)||(NULL == conn))
{
return CI_FAILURE;
}
msg.m_id = pMsg->m_id;
msg.msgType = pMsg->msgType;
msg.keyNo = pMsg->keyNo;
switch (pMsg->msgType)
{
case TEMP_OPEN:
{
//Uart_Printf("TempProc: start\n");
TEMP_Display(1);
Data.errCode = CI_SUCCESS;
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Temp_Collection_Msg));
msg.msgLenth = sizeof(struct Temp_Collection_Msg);
sendmessage(conn,&msg);
break;
}
case TEMP_CLOSE:
{
//Uart_Printf("TempProc: stop\n");
TEMP_Display(0);
Data.errCode = CI_SUCCESS;
memcpy((_UC *)msg.msgBody,(_UC *)(&Data),sizeof(struct Temp_Collection_Msg));
msg.msgLenth = sizeof(struct Temp_Collection_Msg);
sendmessage(conn,&msg);
break;
}
default:
{
return CI_FAILURE;
}
}
return CI_SUCCESS;
}
//消息发送
_US sendmessage(struct netconn *conn,struct CS_Msg_Struct * pMsg)
{
struct netbuf *sendbuf;
//加密临时变量
char enbefore[8];//加密前
char enafter[8];//加密后
char enCode;
char *codeptr;
char *tlptr;
if ((NULL == pMsg)||(NULL == conn))
{
return CI_FAILURE;
}
//Uart_Printf("come into sendmessage!!! ");
memset((char *)enbefore,0,8);
memset((char *)enafter,0,8);
codeptr = (char *)(pMsg->code);
tlptr = (char *)&(pMsg->msgType);
//将msgType与lenth字段进行加密
memcpy(enbefore,tlptr,8);
//请求keyNo时用通用key进行加密,其他消息用得到的key
if (254 == pMsg->keyNo)
{
enCode = Des_Go(enafter,enbefore,8,comkey, sizeof(comkey), ENCRYPT);
}
else
{
enCode = Des_Go(enafter,enbefore,8,key[((pMsg->keyNo)%10)], sizeof(key[((pMsg->keyNo)%10)]), ENCRYPT);
}
if(1 != enCode)
{
return CI_FAILURE;
}
//拷贝到code
memcpy(codeptr,enafter,8);
sendbuf = netbuf_new();
netbuf_ref(sendbuf,(char *)pMsg, (_US)(pMsg->msgLenth+24));
netconn_send(conn, sendbuf);
//netconn_send(conn, strbuf, strLen, NETCONN_COPY);
netbuf_delete(sendbuf);
//Uart_Printf("sendmessage");
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -