⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocol14443bhandler.cpp

📁 基于TI TRF7960的RFID读卡器主机端源代码
💻 CPP
字号:
/** @file
* Protocol14443BHandler.cpp
*
* INTEL CONFIDENTIAL
* Copyright 2006 Intel Corporation All Rights Reserved. 
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Intel Corporation or its
* suppliers or licensors. Title to the Material remains with Intel Corporation
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Intel or its suppliers and licensors.
* The Material is protected by worldwide copyright and trade secret laws and
* treaty provisions. No part of the Material may be used, copied, reproduced,
* modified, published, uploaded, posted, transmitted, distributed, or disclosed
* in any way without Intel抯 prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be express
* and approved by Intel in writing.
*
*/

#include "StdAfx.h"
#include "Protocol14443BHandler.h"
using namespace std;

const string REQUBCMD = "B004";		//Request Command
#define	CMD_LEN		1024
#define PUPI_LEN	10
#define MAX_PUPI	32

Protocol14443BHandler::~Protocol14443BHandler(void)
{
}

bool Protocol14443BHandler::getXWord (char **ppStr, char *pWord)
{
	char *p = *ppStr, *d;
	bool good = true;
	for (d = pWord; *p && *p != ',' && *p != ']'; ) 
	{
		if (! isxdigit(*p)) 
		{
			good = false;
			break;
		}
		*d++ = *p++;
	}
	*d = 0;
	*ppStr = p;
	return good;
}

bool Protocol14443BHandler::GetUID(char *pData, string& pupi)
{
	char cTmp[PUPI_LEN+1], *p = pData, *d;
	int  i;
	for (d = cTmp, i = 0; i < 2; i++)
		*d++ = *p++;
	*d = 0;
	if (strcmp(cTmp, "50"))
	    return false;
	for (d = cTmp, i = 0; i < 8; i++)
		*d++ = *p++;
	*d = 0;
	pupi = cTmp;
	return true;
}

RF_Status Protocol14443BHandler::GetUIDList(vector<string> &UidList)
{
	RF_Status Status = RF_Success;
	char cRet[CMD_LEN];
	DWORD dwSize = CMD_LEN;

	if (!mpCom->PackageAndWrite(REQUBCMD.c_str())) 
	{
		Status = RF_WriteFailure;
	}
	else if (!mpCom->portRead(cRet, &dwSize)) 
	{
		Status = RF_ReadFailure;
	}

	if ( (RF_WriteFailure == Status) || (RF_ReadFailure == Status) )
	{
		Status = RF_DeviceUnResponsive;
	}
	//strcpy(cRet, "60F40E[50A410638700000000002184]80T\n60F40E[50B410638700000000002184]80T");
	if (RF_Success == Status)
	{
		int i;
		char pData[64], *p;
		string pupi;
		for (p = cRet, i = 0; i < 4*MAX_PUPI; i++) 
		{
			// find next starting position
			p = strchr(p, '[');
			if (!p)
				break;
			p++;
			if (*p && (*p == ']' || *p == 'z' || *p == 'Z'))
				continue;
			// get the PUPI value
			if (!getXWord(&p, pData))
				continue;
			if (strlen(pData) != 24) 
			{
				//Short response data
				continue;
			}
			GetUID(pData, pupi);
			UidList.push_back(pupi);
		}
		if (UidList.empty())
		{
			Status = RF_UidNotFound;
		}
	}
	return Status;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -