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

📄 rfidreaderinstanceobject.cpp

📁 270的linux说明
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*/

//==============================================================================
// RfidReaderInstanceObject.cpp 
//       Declaration of the class RfidReaderInstance
//==============================================================================
#include "IntelMobile/Base/base_Exception.h"#include "IntelMobile/Base/base_InstanceObject.h"
#include "./RfidReaderInstanceObject.h"#include "inc/Base/base_Exception.h"
#include "inc/Base/VectorTemplateMacros.h"
#include "Utility/StringHelper.h"using namespace Intel::Mobile::Rfid;
//==============================================================================
// C_Tor()
//==============================================================================
RfidReaderInstance::RfidReaderInstance( void *pImpl )
: InstanceObject		( pImpl ),
Manufacturer			( *this ),
Name					( *this ),
SerialNumber			( *this ),
FirmwareRevision		( *this ),
ConnectionInterface		( *this ),
BaudRate				( *this ),
SerialPort				( *this ),
Protocols				( *this ),
SupportedProtocols		( *this ),
Enabled					( *this ),
PowerLevel				( *this ),
OperatingFrequencies	( *this ),
TagFound				( Intel::Mobile::Base::Event::eTagFound, *this),
DeviceAvailable			( Intel::Mobile::Base::Event::eDeviceAvailable, *this),
m_bOpened				( false ),
m_nOpenCount			( 0 )
{
	if ( m_pImpl != NULL )
	{
		Intel::Mobile::BaseAPI::InstanceObject* pImpl = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);

		Manufacturer.Init( pImpl->GetPropertyByName("Manufacturer", "String" ) );
		Name.Init( pImpl->GetPropertyByName("Name", "String") );
		SerialNumber.Init( pImpl->GetPropertyByName("SerialNumber", "String") );
		FirmwareRevision.Init( pImpl->GetPropertyByName("FirmwareRevision", "String") );
		ConnectionInterface.Init( pImpl->GetPropertyByName("ConnectionInterface", "Int", "ConnectionInterfaceEnumProperty" ) );
		BaudRate.Init( pImpl->GetPropertyByName("BaudRate", "Int", "BaudRateEnumProperty" ) );
		SerialPort.Init( pImpl->GetPropertyByName("SerialPort", "Int") );
		Protocols.Init( pImpl->GetPropertyByName("Protocols", "StringArray") );
		SupportedProtocols.Init( pImpl->GetPropertyByName("SupportedProtocols", "StringArray") );
		Enabled.Init( pImpl->GetPropertyByName("Enabled", "Bool") );
		PowerLevel.Init( pImpl->GetPropertyByName("PowerLevel", "Int") );
		OperatingFrequencies.Init( pImpl->GetPropertyByName("OperatingFrequencies", "IntArray") );
	}
}

//==============================================================================
// D_Tor()
//==============================================================================
RfidReaderInstance::~RfidReaderInstance()
{
	if (m_flag)
	{
		//Close the device if still opened 
		while (( m_bOpened ) && ( m_nOpenCount > 0 ))
		{
			Close();
		}

		if (m_pImpl)
		{
			Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if (pAPI_Instance)
			{
				delete pAPI_Instance;
			}
			m_pImpl = NULL;
		}
	}
}

//==============================================================================
// GetType()
//==============================================================================
StringObject RfidReaderInstance::GetType() const
{ 
	if (m_pImpl)
	{
		Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
		if (pAPI_Instance)
		{
			TRYBLOCK { 
				IntelMobileChar* pType = pAPI_Instance->GetType(); 
				StringObject sType( pType );
				delete[] pType;
				return sType;
			} CATCHBLOCK
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "GetType");
	}
	else
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "GetType");

}

//==============================================================================
// GetKey()
//==============================================================================
StringObject RfidReaderInstance::GetKey() const
{ 
	if (m_pImpl)
	{
		Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
		if (pAPI_Instance)
		{
			TRYBLOCK {
				IntelMobileChar* pKey = pAPI_Instance->GetKey();
				StringObject sKey( pKey );
				delete[] pKey;
				return sKey;
			} CATCHBLOCK
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "GetKey");
	}
	else
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "GetKey");

}

//==============================================================================

bool RfidReaderInstance::StartReadingTags()
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "StartReadingTags", "" );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;
					CStringHelper::Str2Param( wsRtn, bRet );
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StartReadingTags");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StartReadingTags");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StartReadingTags");
	}
	return bRet;
}

bool RfidReaderInstance::StopReadingTags()
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "StopReadingTags", "" );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;
					CStringHelper::Str2Param( wsRtn, bRet );
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StopReadingTags");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StopReadingTags");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "StopReadingTags");
	}

	return bRet;
}

bool RfidReaderInstance::ReadTags(unsigned __int32 SearchTime, TagInfoArray* TagInfo)
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileString wsParams = CStringHelper::Param2Str(SearchTime);

					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "ReadTags", (IntelMobileChar *)wsParams.c_str() );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;

					vector<IntelMobileString> wsVec;
					CStringHelper::Str2ParamVect(wsRtn, wsVec, FIRST_SPLITTER);
					int j = 0;
					for ( vector<IntelMobileString>::iterator itr = wsVec.begin();
						itr != wsVec.end();
						itr ++ )
					{
						if ( 0 == j )
						{
							CStringHelper::Str2Param( *itr, bRet );
							j++;
						}
						else if ( j > 0 )
						{
							vector<IntelMobileString> wsSubVec;
							CStringHelper::Str2ParamVect(*itr, wsSubVec, SECOND_SPLITTER);
							struct TagInfo sTagInfo;
							int k = 0;
							for ( vector<IntelMobileString>::iterator subItr = wsSubVec.begin();
								subItr != wsSubVec.end();
								subItr ++ )
							{
								switch ( k )
								{
								case 0: 
									{
										sTagInfo.TagId = (*subItr).c_str();
										break;
									}
								case 1:
									{
										int iType;
										CStringHelper::Str2Param(*subItr, iType);
										sTagInfo.TagType = iType;
										break;
									}
								case 2:
									{
										bool bSecured;
										CStringHelper::Str2Param(*subItr, bSecured);
										sTagInfo.TagSecured = bSecured;
										break;
									}
								default:
									{
										throw "Returned string unmatched.";
									}
								}
								k++;
							}
							if ( 0 != k )
							{
								TagInfo->Insert(sTagInfo);
							}
						}
					}
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadTags");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadTags");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadTags");
	}

	return bRet;							
}

bool RfidReaderInstance::ReadUserData(ByteArray* Data)
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileString wsParams = "0";

					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "ReadUserData", (IntelMobileChar *)wsParams.c_str() );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;

					vector<IntelMobileString> wsVec;
					CStringHelper::Str2ParamVect(wsRtn, wsVec, FIRST_SPLITTER);
					int j = 0;
					for ( vector<IntelMobileString>::iterator itr = wsVec.begin();
						itr != wsVec.end();
						itr ++, j++ )
					{
						if ( 0 == j )
						{
							CStringHelper::Str2Param( *itr, bRet );
						}
						else if ( 1 == j )
						{
							vector<BYTE> vecData;
							CStringHelper::Str2Param(*itr, vecData);

							for ( vector<BYTE>::const_iterator itr = vecData.begin();
								itr != vecData.end();
								itr ++ )
							{
								BYTE byte = *itr;
								Data->Insert( byte );
							}						
						}
						else 
						{
							throw "Returned string unmatched.";
						}
					}
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}

	return bRet;							
}

bool RfidReaderInstance::ReadUserData(StringObject TagId, ByteArray* Data)
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileString wsParams = "1";
					wsParams.append(FIRST_SPLITTER);
					wsParams.append(TagId.GetValue());

					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "ReadUserData", (IntelMobileChar *)wsParams.c_str() );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;

					vector<IntelMobileString> wsVec;
					CStringHelper::Str2ParamVect(wsRtn, wsVec, FIRST_SPLITTER);
					int j = 0;
					for ( vector<IntelMobileString>::iterator itr = wsVec.begin();
						itr != wsVec.end();
						itr ++, j++ )
					{
						if ( 0 == j )
						{
							CStringHelper::Str2Param( *itr, bRet );
						}
						else if ( 1 == j )
						{
							vector<BYTE> vecData;
							CStringHelper::Str2Param(*itr, vecData);

							for ( vector<BYTE>::const_iterator itr = vecData.begin();
								itr != vecData.end();
								itr ++ )
							{
								BYTE byte = *itr;
								Data->Insert( byte );
							}
						}
						else 
						{
							throw "Returned string unmatched.";
						}
					}
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}

	return bRet;	
}

bool RfidReaderInstance::ReadUserData(StringObject TagId, StringObject Password, ByteArray* Data)
{
	bool bRet = false;
	if ( m_bOpened )
	{
		if ( m_pImpl )
		{
			Intel::Mobile::BaseAPI::InstanceObject* pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl);
			if ( pAPI_Instance )
			{
				TRYBLOCK {
					IntelMobileString wsParams = "2";
					wsParams.append(FIRST_SPLITTER);
					wsParams.append(TagId.GetValue());
					wsParams.append(FIRST_SPLITTER);
					wsParams.append(Password.GetValue());

					IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "ReadUserData", (IntelMobileChar *)wsParams.c_str() );
					IntelMobileString wsRtn = infoString;
					delete[] infoString;

					vector<IntelMobileString> wsVec;
					CStringHelper::Str2ParamVect(wsRtn, wsVec, FIRST_SPLITTER);
					int j = 0;
					for ( vector<IntelMobileString>::iterator itr = wsVec.begin();
						itr != wsVec.end();
						itr ++, j++ )
					{
						if ( 0 == j )
						{
							CStringHelper::Str2Param( *itr, bRet );
						}
						else if ( 1 == j )
						{
							vector<BYTE> vecData;
							CStringHelper::Str2Param(*itr, vecData);

							for ( vector<BYTE>::const_iterator itr = vecData.begin();
								itr != vecData.end();
								itr ++ )
							{
								BYTE byte = *itr;
								Data->Insert( byte );
							}
						}
						else 
						{
							throw "Returned string unmatched.";
						}
					}
				} CATCHBLOCK
			}
			else
				THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
		}
		else
			THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}
	else
	{
		THROWNE("Intel::Mobile::Rfid::RfidReaderInstance", "ReadUserData");
	}

	return bRet;	
}

bool RfidReaderInstance::WriteUserData(ByteArray& Data)
{
	bool bRet = false;

⌨️ 快捷键说明

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