📄 usbreader.cpp
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: $
// $Revision: 1.1.1.1 $
// $Author: KevinM $
// $Date: 2003/09/29 18:19:04 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 1997-2003 (c) Pixelworks Inc.
//
// Pixelworks owns the sole copyright to this software. Under international
// copyright laws you (1) may not make a copy of this software except for
// the purposes of maintaining a single archive copy, (2) may not derive
// works herefrom, (3) may not distribute this work to others. These rights
// are provided for information clarification, other restrictions of rights
// may apply as well.
//
// This is an unpublished work.
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> WARRANTEE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Pixelworks Inc. MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE USE OF
// THIS SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE.
// --------------------------------------------------------------------------
//
// UsbReader.cpp: implementation of the CUsbReader class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UsbReader.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
static void GetStringFromHex( CString& strHex, LPBYTE pByte,
int nCount)
{
LPBYTE p = pByte;
int n = nCount;
LPBYTE t = p;
CString strLine;
CString strChar;
for( int i = 0; i < n; i++ ) {
strChar.Format("%02x ", *t++ );
strLine += strChar;
}
strHex = strLine + "\n";
}
static int nTotal = 0;
static nPacket = 0;
static void DisplayHexPacket(LPBYTE pByte, int nCount)
{
int nData = 0;
nTotal += nCount;
CString strPacket;
strPacket.Format("RX: P%04d B:%05d T:%05d \n", nPacket++, nCount, nTotal);
OutputDebugString(strPacket);
while (nData < nCount)
{
CString strTmp;
CString strLine;
int nLen = 16;
if (nData + nLen > nCount)
nLen = (nCount - nData);
strLine.Format(" 0x%04x Data: ", nData);
GetStringFromHex(strTmp, &pByte[nData], nLen);
OutputDebugString(strLine + strTmp);
nData += nLen;
}
OutputDebugString("\n");
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CUsbReader::CUsbReader()
{
AllocateBuffers(256, 5);
CircBuf.SetSize(4096);
m_nMaxPacketSize = 0;
}
CUsbReader::~CUsbReader()
{
FreeBuffers();
}
int CUsbReader::FetchBytes(LPBYTE pBytes, int nCount, char cMarker)
{
int nGot = CircBuf.ReadBytes(pBytes, nCount, 1000, cMarker);
return nGot;
}
void CUsbReader::Flush()
{
CircBuf.Flush();
}
static int nReaderCount = 0;
void CUsbReader::ProcessData(CUsbIoBuf* Buf)
{
nReaderCount++;
if ( Buf->Status == USBIO_ERR_SUCCESS )
{
CircBuf.AddBytes((BYTE*)Buf->Buffer(), Buf->BytesTransferred);
DisplayHexPacket((BYTE*)Buf->Buffer(), Buf->BytesTransferred);
Buf->BytesTransferred = 0;
}
}
void CUsbReader::BufErrorHandler(CUsbIoBuf* Buf)
{
switch (Buf->Status)
{
case USBIO_ERR_CANCELED:
::OutputDebugString("RD: USBIO_ERR_CANCELED\n");
//ResetPipe();
break;
}
}
int CUsbReader::GetAvailData()
{
return CircBuf.GetAvailBytes();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -