📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SEEDDEC2407.h"
#include "seeddecusb.h"
#include "ezusbsys.h"
#include "UsbvreqDialog.h"
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define VR_USB_VERION 0xB8
char PIPE_TYPE_STRINGS[4][4] =
{
"CTL",
"ISO",
"BLK",
"INT"
};
char PIPE_DIRECTION[2][4] =
{
"OUT",
"IN "
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_TEST_GETDEVICE, OnTestGetdevice)
ON_COMMAND(ID_TEST_GETCONFIG, OnTestGetconfig)
ON_COMMAND(ID_TEST_GETSTRING, OnTestGetstring)
ON_COMMAND(ID_TEST_GETPIPEINFO, OnTestGetpipeinfo)
ON_COMMAND(ID_USB_20OR11, OnUsb20or11)
ON_COMMAND(ID_BULK_READ, OnBulkRead)
ON_COMMAND(ID_BULK_WRITE, OnBulkWrite)
ON_COMMAND(ID_TEST_VENDOR, OnTestVendor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnTestGetdevice()
{
// TODO: Add your command handler code here
PVOID psx2_device= 0;
psx2_device = Sx2GetDeviceDesc();
if(psx2_device== NULL)
{
AfxMessageBox("操作失败,请复位SEED-DEC2407系统!");
}
/*显示获取的描述表*/
theApp.Out("*********************************************************************\n");
theApp.Out("the current cy7c68001's device descriptor is:\n");
theApp.Out("-----------------------------------------------------------\n");
theApp.Out(" Vendor ID is: 0x%x \n ",((pUsb_Device_Descriptor)psx2_device )->idVendor);
theApp.Out(" Product ID is: 0x%x \n",((pUsb_Device_Descriptor)psx2_device )->idProduct);
theApp.Out(" Device ID is: 0x%x \n",((pUsb_Device_Descriptor)psx2_device )->bcdDevice);
theApp.Out(" Maximum Packet Size is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->bMaxPacketSize0);
theApp.Out(" Device class is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->bDeviceClass);
theApp.Out(" Device sub-class is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->bDeviceSubClass);
theApp.Out(" Manufacturer string index is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->iManufacturer);
theApp.Out(" Product string index is: 0x%x \n",((pUsb_Device_Descriptor)psx2_device )->idProduct);
theApp.Out(" Serial number string index is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->iSerialNumber);
theApp.Out(" Number of configurations is: 0x%x\n",((pUsb_Device_Descriptor)psx2_device )->bNumConfigurations);
theApp.Out("\n\n");
}
void CMainFrame::OnTestGetconfig()
{
// TODO: Add your command handler code here
//显示USB的配置信息
int i = 0;
PVOID psx2_config = 0;
psx2_config = Sx2GetconfigDesc();
pUsb_Configuration_Descriptor pCD = (pUsb_Configuration_Descriptor) psx2_config;
PUSB_INTERFACE_DESCRIPTOR pID = NULL;
PUSB_ENDPOINT_DESCRIPTOR pED = NULL;
if(psx2_config == NULL)
{
AfxMessageBox("操作失败,请复位SEED-DEC2407系统!");
}
/*显示获取的描述表*/
theApp.Out("*********************************************************************\n");
theApp.Out("The current cy7c68001's configuration Decriptor is:\n");
theApp.Out(" bLength: 0x%x\n", pCD->bLength);
theApp.Out(" bDescriptorType: %d\n", pCD->bDescriptorType);
theApp.Out(" wTotalLength: %d (0x%x)\n", pCD->wTotalLength, pCD->wTotalLength);
theApp.Out(" bNumInterfaces: %d\n", pCD->bNumInterfaces);
theApp.Out(" bConfigurationValue: %d\n", pCD->bConfigurationValue);
theApp.Out(" iConfiguration: %d\n", pCD->iConfiguration);
theApp.Out(" bmAttributes: 0x%x\n", pCD->bmAttributes);
theApp.Out(" MaxPower: %d\n", pCD->MaxPower);
theApp.Out("***********************************\n");
/*显示接口的描述表*/
for( pID = (PUSB_INTERFACE_DESCRIPTOR) (((char*)pCD) + pCD->bLength);
pID < (PUSB_INTERFACE_DESCRIPTOR) (((char*)pCD) + pCD->wTotalLength);
pID->bLength)
{
theApp.Out("Interface Descriptor: \n");
theApp.Out("-----------------------------------\n");
theApp.Out(" bLength: 0x%x\n", pID->bLength);
theApp.Out(" bDescriptorType: %d\n", pID->bDescriptorType);
theApp.Out(" bInterfaceNumber: %d\n", pID->bInterfaceNumber);
theApp.Out(" bAlternateSetting: %d\n", pID->bAlternateSetting);
theApp.Out(" bNumEndpoints: %d\n", pID->bNumEndpoints);
theApp.Out(" bInterfaceClass: %d (0x%x)\n", pID->bInterfaceClass, pID->bInterfaceClass);
theApp.Out(" bInterfaceSubClass: %d (0x%x)\n", pID->bInterfaceSubClass, pID->bInterfaceSubClass);
theApp.Out(" bInterfaceProtocol: %d (0x%x)\n", pID->bInterfaceProtocol, pID->bInterfaceProtocol);
theApp.Out(" iInterface: %d\n", pID->iInterface);
theApp.Out("************************************\n");
// 显示节点的描述表
pED = (PUSB_ENDPOINT_DESCRIPTOR) (((char*)pID) + pID->bLength);
for (i=0;i<pID->bNumEndpoints;i++)
{
theApp.Out("Endpoint Descriptor %d \n", i);
theApp.Out("-----------------------------------\n");
theApp.Out(" bLength: 0x%x\n", pED->bLength);
theApp.Out(" bDescriptorType: %d\n", pED->bDescriptorType);
theApp.Out(" bEndpointAddress: 0x%x\n", pED->bEndpointAddress);
theApp.Out(" bmAttributes: 0x%x\n", pED->bmAttributes);
theApp.Out(" wMaxPacketSize: %d\n", pED->wMaxPacketSize);
theApp.Out(" bInterval: %d\n", pED->bInterval);
theApp.Out("*************************************\n");
pED = (PUSB_ENDPOINT_DESCRIPTOR) (((char*)pED) + (pED->bLength));
}
// pointer should grow
pID = (PUSB_INTERFACE_DESCRIPTOR) (char*)pED;
}
}
void CMainFrame::OnTestGetstring()
{
// TODO: Add your command handler code here
char viewstr[100];
int i = 0;
PVOID psx2_string= 0;
int stringindex = 1;
psx2_string = Sx2GetStringDesc(stringindex++);
if(psx2_string == NULL)
{
AfxMessageBox("操作失败,请复位SEED-DEC2407系统!");
}
for(i =0;i<(((pUsb_String_Descriptor)psx2_string)->bLength)/2-1;i++)
{
viewstr[i] = ((pUsb_String_Descriptor)psx2_string)->bString[i*2];
}
viewstr[i] = '\0';
/*显示获取的描述表*/
theApp.Out("*********************************************************************\n");
theApp.Out("the current cy7c68001's string Decriptor is:\n");
theApp.Out("-----------------------------------\n");
theApp.Out("%s ",viewstr);
psx2_string = Sx2GetStringDesc(stringindex++);
if(psx2_string == NULL)
{
AfxMessageBox("操作失败,请复位SEED-DEC2407系统!");
}
for(i =0;i<(((pUsb_String_Descriptor)psx2_string)->bLength)/2-1;i++)
{
viewstr[i] = ((pUsb_String_Descriptor)psx2_string)->bString[i*2];
}
viewstr[i] = '\0';
theApp.Out("%s\n\n ",viewstr);
}
void CMainFrame::OnTestGetpipeinfo()
{
// 显示节点的信息
int i = 0;
USBD_INTERFACE_INFORMATION Sx2InterfaceInfo;
PUSBD_INTERFACE_INFORMATION pSx2InterfaceInfo = &Sx2InterfaceInfo;
PUSBD_PIPE_INFORMATION pPipe;
/*获得USB的接口信息*/
if(TRUE !=Sx2GetPipeInfo((PVOID)&Sx2InterfaceInfo))
{
return;
}
pPipe = pSx2InterfaceInfo->Pipes;
theApp.Out("*********************************************************************\n");
theApp.Out("The pipe information is :\n");
theApp.Out("------------------------------------------------\n");
theApp.Out("Interface Size %d\n",pSx2InterfaceInfo->Length);
for(i= 0; i < (int) pSx2InterfaceInfo->NumberOfPipes;i++)
{
theApp.Out( " Pipe: %2d Type: %s Endpoint: %2d %s MaxPktSize: 0x%x\n",
i,
PIPE_TYPE_STRINGS[pPipe[i].PipeType],
(pPipe[i].EndpointAddress & 0x0F),PIPE_DIRECTION[(pPipe[i].EndpointAddress >> 7)],
pPipe[i].MaximumPacketSize);
}
theApp.Out("\n");
}
void CMainFrame::OnUsb20or11()
{
// TODO: Add your command handler code here
//得到USB工作在2.0标准,还是1.1标准
/*命令请求定义*/
char buffer1[64];
VENDOR_OR_CLASS_REQUEST_CONTROL myRequest;
ULONG venderlong;
int recnBytes = 0;
/*发送命令,使DSP先定入固定的数据*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -