📄 communicationctrl.cpp
字号:
// CommunicationCtrl.cpp: implementation of the CCommunicationCtrl class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "..\ZDUSBMP_DUT.h"
#include "CommunicationCtrl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCommunicationCtrl::CCommunicationCtrl()
{
ConnectPort = 0;
dTimeout = 0;
dTimes=0;
}
CCommunicationCtrl::~CCommunicationCtrl()
{
}
void CCommunicationCtrl::SetTimeout(DWORD dwTime)
{
dTimeout = dwTime;
}
void CCommunicationCtrl::SetConnectPort(int dPort)
{
ConnectPort = dPort;
}
void CCommunicationCtrl::ClearSendBuff()
{
memset(OutBuff, 0x00, 25);//clear
}
void CCommunicationCtrl::ClearReceiverBuff()
{
memset(InBuff, 0x00, 25);//clear
}
bool CCommunicationCtrl::SetHandle(char cClass)
{
bool bRet;
mCmdHandle.cHANDLE = CMD_HAND;
mCmdHandle.cClass = cClass;
switch(cClass){
case CMD_CLASS_SEND:
bRet = true;
break;
case CMD_CLASS_REPLY:
bRet = true;
break;
case CMD_CLASS_BINDWITH:
bRet = true;
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
bool CCommunicationCtrl::GetHandle(CMD_HANDLE* mhCmd)
{
switch(mhCmd->cClass){
case CMD_CLASS_SEND:
*mhCmd = mSendCmd.mHand;
return true;
break;
case CMD_CLASS_REPLY:
*mhCmd = mReplyCmd.mHand;
return true;
break;
case CMD_CLASS_BINDWITH:
*mhCmd = mBindwithCmd.mHand;
return true;
break;
}
return FALSE;
}
bool CCommunicationCtrl::CheckHandle(CMD_HANDLE mhCmd)
{
if (mhCmd.cHANDLE != CMD_HAND) return FALSE;
switch(mhCmd.cClass){
case CMD_CLASS_SEND:
case CMD_CLASS_REPLY:
case CMD_CLASS_BINDWITH:
return true;
break;
}
return FALSE;
}
void CCommunicationCtrl::SetSendCmd(char cCmd, int dCh, int dPower, int dAnt,
DWORD dwInterval, DWORD dwLength, DWORD dwTXAmount)
{
char tmp;
SetHandle(CMD_CLASS_SEND);
mSendCmd.mHand = mCmdHandle;
mSendCmd.cCmd = cCmd;
mSendCmd.cChannel = (char)dCh;
mSendCmd.cTXPower = (char)dPower;
mSendCmd.cAntenna = (char)dAnt;
//DWORD = 32-bit => [0000]-[0000-000][0-0000-00][00-0000-0][000-0000]
tmp = char(dwInterval & 0x7f);
mSendCmd.cwInterval[0] = tmp;
tmp = char(dwInterval>>7 & 0x7f);
mSendCmd.cwInterval[1] = tmp;
tmp = char(dwInterval>>14 & 0x7f);
mSendCmd.cwInterval[2] = tmp;
tmp = char(dwInterval>>21 & 0x7f);
mSendCmd.cwInterval[3] = tmp;
tmp = char(dwInterval>>28 & 0x0f);
mSendCmd.cwInterval[4] = tmp;
tmp = char(dwLength & 0x7f);
mSendCmd.cLength[0] = tmp;
tmp = char(dwLength>>7 & 0x7f);
mSendCmd.cLength[1] = tmp;
tmp = char(dwLength>>14 & 0x7f);
mSendCmd.cLength[2] = tmp;
tmp = char(dwLength>>21 & 0x7f);
mSendCmd.cLength[3] = tmp;
tmp = char(dwLength>>28 & 0x0f);
mSendCmd.cLength[4] = tmp;
tmp = char(dwTXAmount & 0x7f);
mSendCmd.cTXAmount[0] = tmp;
tmp = char(dwTXAmount>>7 & 0x7f);
mSendCmd.cTXAmount[1] = tmp;
tmp = char(dwTXAmount>>14 & 0x7f);
mSendCmd.cTXAmount[2] = tmp;
tmp = char(dwTXAmount>>21 & 0x7f);
mSendCmd.cTXAmount[3] = tmp;
tmp = char(dwTXAmount>>28 & 0x0f);
mSendCmd.cTXAmount[4] = tmp;
memcpy(OutBuff, &mSendCmd, sizeof(SNED_COMMAND) );
}
bool CCommunicationCtrl::GetSendCmd(char* cCmd, int* dCh, int* dPower, int* dAnt,
DWORD* dwInterval, DWORD* dwLength, DWORD* dwTXAmount)
{
DWORD tmp;
memcpy(&mSendCmd, InBuff, sizeof(SNED_COMMAND) );
mCmdHandle = mSendCmd.mHand;
*cCmd = mSendCmd.cCmd;
*dCh = (int)mSendCmd.cChannel;
*dPower = (int)mSendCmd.cTXPower;
*dAnt = (int)mSendCmd.cAntenna;
//DWORD = 32-bit => [0000]-[0000-000][0-0000-00][00-0000-0][000-0000]
tmp = DWORD(mSendCmd.cwInterval[4] & 0x0f)<<28;
tmp |= DWORD(mSendCmd.cwInterval[3] & 0x7f)<<21;
tmp |= DWORD(mSendCmd.cwInterval[2] & 0x7f)<<14;
tmp |= DWORD(mSendCmd.cwInterval[1] & 0x7f)<<7;
tmp |= DWORD(mSendCmd.cwInterval[0] & 0x7f);
*dwInterval = tmp;
tmp = DWORD(mSendCmd.cLength[4] & 0x0f)<<28;
tmp |= DWORD(mSendCmd.cLength[3] & 0x7f)<<21;
tmp |= DWORD(mSendCmd.cLength[2] & 0x7f)<<14;
tmp |= DWORD(mSendCmd.cLength[1] & 0x7f)<<7;
tmp |= DWORD(mSendCmd.cLength[0] & 0x7f);
*dwLength = tmp;
tmp = DWORD(mSendCmd.cTXAmount[4] & 0x0f)<<28;
tmp |= DWORD(mSendCmd.cTXAmount[3] & 0x7f)<<21;
tmp |= DWORD(mSendCmd.cTXAmount[2] & 0x7f)<<14;
tmp |= DWORD(mSendCmd.cTXAmount[1] & 0x7f)<<7;
tmp |= DWORD(mSendCmd.cTXAmount[0] & 0x7f);
*dwTXAmount = tmp;
return true;
}
bool CCommunicationCtrl::CheckSendCmd(char cCmd, int dCh, int dPower, int dAnt,
DWORD dwInterval, DWORD dwLength, DWORD dwTXAmount)
{
if (cCmd<1 || cCmd>2) return FALSE;
if (dCh<1 || dCh>14) return FALSE;
if (dPower<1 || dPower>15) return FALSE;
if (dAnt<1 || dAnt>2) return FALSE;
if (dwInterval<1 || dwInterval>0x7fffffff) return FALSE;
if (dwLength<46 || dwLength>1500) return FALSE;
if (dwTXAmount<1 || dwTXAmount>0x7fffffff) return FALSE;
return true;
}
void CCommunicationCtrl::SetReplyCmd(char cResult, char cValue)
{
SetHandle(CMD_CLASS_REPLY);
mReplyCmd.mHand = mCmdHandle;
mReplyCmd.bIsSuccess = cResult;
mReplyCmd.cValue = cValue;
memcpy(OutBuff, &mReplyCmd, sizeof(REPLY_COMMAND) );
}
bool CCommunicationCtrl::GetReplyCmd(char *cResult, char *cValue)
{
memcpy(&mReplyCmd, InBuff, sizeof(REPLY_COMMAND) );
mCmdHandle = mReplyCmd.mHand;
*cResult = mReplyCmd.bIsSuccess;
*cValue = (int)mReplyCmd.cValue;
return true;
}
bool CCommunicationCtrl::CheckReplyCmd(char cResult, char cValue)
{
if (cResult<0 || cResult>1) return FALSE;
if (cValue<1 || cValue>5) return FALSE;
return true;
}
void CCommunicationCtrl::SetBindwithCmd(char cQue)
{
SetHandle(CMD_CLASS_BINDWITH);
mBindwithCmd.mHand = mCmdHandle;
mBindwithCmd.cRequest = cQue;
memset(&mBindwithCmd.cTestValues, CMD_BINDWITH_QUEST_VALUE, 10);
memcpy(OutBuff, &mBindwithCmd, sizeof(BINDWITH_COMMAND) );
}
bool CCommunicationCtrl::GetBindwithCmd(char* cQue)
{
memcpy(&mBindwithCmd, InBuff, sizeof(BINDWITH_COMMAND) );
mCmdHandle = mBindwithCmd.mHand;
*cQue = (int)mBindwithCmd.cRequest;
return true;
}
bool CCommunicationCtrl::CheckBindwithCmd(char cQue)
{
if (cQue<1 || cQue>2) return FALSE;
for(int i=0; i<10; i++){
if (mBindwithCmd.cTestValues[i] != 0x55)
return FALSE;
}
return true;
}
void CCommunicationCtrl::ClearSendCmd()
{
char tmp[25];
memset(tmp, 0x00, 25);
memcpy(&mSendCmd, tmp, sizeof(SNED_COMMAND) );
mCmdHandle = mBindwithCmd.mHand;
}
void CCommunicationCtrl::ClearReplyCmd()
{
char tmp[25];
memset(tmp, 0x00, 25);
memcpy(&mReplyCmd, tmp, sizeof(REPLY_COMMAND) );
mCmdHandle = mReplyCmd.mHand;
}
void CCommunicationCtrl::ClearBindwithCmd()
{
char tmp[25];
memset(tmp, 0x00, 25);
memcpy(&mBindwithCmd, tmp, sizeof(BINDWITH_COMMAND) );
mCmdHandle = mBindwithCmd.mHand;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -