📄 main.c
字号:
/*++
Module Name:
Main.c
--*/
#include <windows.h>
#include <malloc.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include "resource.h"
#include "main.h"
#include <winioctl.h>
#include "..\..\..\..\drivers\ezusbdrv\ezusbsys.h"
HINSTANCE hGInstance = NULL;
BOOL CALLBACK bMainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL StopTest;
char *build_time = __TIME__;
char *build_date = __DATE__;
/*******************************
*WinMain: Windows Entry point *
********************************/
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hGInstance=hInstance;
if(DialogBox(hInstance,"MAIN_DIALOG",NULL,(DLGPROC)bMainDlgProc)==-1)
MessageBox(NULL,"Unable to create root dialog!","DialogBox failure",MB_ICONSTOP);
return 0;
}
void TestThread(
LPVOID lpParameter // thread data
)
{
HWND hDlg = (HWND) lpParameter;
HWND hOutputBox = NULL;
HANDLE hDevice = NULL;
char pcDriverName[MAX_DRIVER_NAME] = "";
BOOLEAN bResult = FALSE;
int nBytes = 0;
int nItems = 0;
ISO_TRANSFER_CONTROL IsoControl;
ULONG bytesToRead;
BOOL Success;
PUCHAR buffer = NULL;
ULONG packetsRead;
PUSBD_ISO_PACKET_DESCRIPTOR isoDesc;
ULONG i;
PUCHAR ptr;
ULONG pass = 0;
UCHAR count = 0;
ULONG framesRead = 0;
ULONG framesMissed = 0;
char tempbuff[256];
// Get a handle to the output box
hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
// Open the driver
GetDlgItemText (hDlg, IDC_DRIVER_NAME, pcDriverName, MAX_DRIVER_NAME);
if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Opened Driver Successfully");
} else {
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Driver");
hDevice = NULL;
return;
}
IsoControl.PacketSize = GetDlgItemInt(hDlg,IDC_ISO_PACKET_SIZE,&Success,FALSE);
IsoControl.PacketCount = GetDlgItemInt(hDlg,IDC_ISO_PACKETS,&Success,FALSE);
IsoControl.PipeNum = GetDlgItemInt(hDlg,IDC_ISO_PIPE,&Success,FALSE);
IsoControl.BufferCount = GetDlgItemInt(hDlg,IDC_ISO_BUFFER_COUNT,&Success,FALSE);
IsoControl.FramesPerBuffer = GetDlgItemInt(hDlg,IDC_ISO_FRAMES_PER_BUFFER,&Success,FALSE);
bytesToRead = IsoControl.PacketCount * (IsoControl.PacketSize + sizeof(USBD_ISO_PACKET_DESCRIPTOR));
buffer = (PUCHAR) malloc(bytesToRead);
if (!buffer)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"alloc Failed");
CloseHandle(hDevice);
return;
}
while (!StopTest)
{
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_READ_ISO_BUFFER,
&IsoControl,
sizeof(ISO_TRANSFER_CONTROL),
buffer,
bytesToRead,
&nBytes,
NULL);
if (bResult != TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Read ISO Buffer Failed");
break;
}
packetsRead = nBytes / (IsoControl.PacketSize + sizeof(USBD_ISO_PACKET_DESCRIPTOR));
ptr = buffer;
isoDesc = (PUSBD_ISO_PACKET_DESCRIPTOR) (buffer + (packetsRead * IsoControl.PacketSize));
for (i=0;i<packetsRead;i++)
{
framesRead++;
if (!(framesRead % 1000))
{
SetDlgItemInt(hDlg,IDC_FRAMES_READ,framesRead/1000,FALSE);
}
if (count != *ptr)
{
framesMissed++;
SetDlgItemInt(hDlg,IDC_FRAMES_MISSED,framesMissed,FALSE);
sprintf(tempbuff, "Missed frame = 0x%x",count);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
DumpBuffer(ptr,isoDesc[i].Length,hOutputBox);
count = *ptr;
}
count++;
if (isoDesc[i].Length != IsoControl.PacketSize)
{
framesMissed++;
SetDlgItemInt(hDlg,IDC_FRAMES_MISSED,framesMissed,FALSE);
sprintf(tempbuff, "Short Packet received");
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM) tempbuff);
}
ptr += IsoControl.PacketSize;
}
}
CloseHandle (hDevice);
free(buffer);
}
/**************************************************
* Main Dialog proc *
**************************************************/
BOOL CALLBACK bMainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hOutputBox = NULL;
HANDLE hDevice = NULL;
char pcDriverName[MAX_DRIVER_NAME] = "";
BOOLEAN bResult = FALSE;
int nBytes = 0;
int nItems = 0;
HFONT hFont = NULL;
ULONG ulLength = 0;
char tempbuff[256];
LARGE_INTEGER llnHPTimerFreq; // High Performance Timer: Frequency
LARGE_INTEGER llnHPT1; // High Performance Timer: Time 1
LARGE_INTEGER llnHPT2; // High Performance Timer: Time 2
LARGE_INTEGER llnT_uSec; // Time in microseconds
// Get a handle to the output box
hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
switch(message)
{
case WM_LBUTTONDOWN:
hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
MAINTAIN_OUTPUT_BOX (hOutputBox, nItems);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"you clicked");
break;
case WM_INITDIALOG:
// Get a handle to the output box
hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
// Setup the std system font
hFont = GetStockObject(SYSTEM_FONT);
SendMessage (hOutputBox, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE,0));
sprintf(tempbuff,"EZ-USB Isostrm - built %s %s",build_time,build_date);
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)tempbuff);
// Setup the default symbolic name for the device driver
SetDlgItemText (hDlg, IDC_DRIVER_NAME, "Ezusb-0");
SetDlgItemInt(hDlg,IDC_ISO_PIPE,0,FALSE);
SetDlgItemInt(hDlg,IDC_ISO_PACKETS,128,FALSE);
SetDlgItemInt(hDlg,IDC_ISO_PACKET_SIZE,64,FALSE);
SetDlgItemInt(hDlg,IDC_ISO_BUFFER_COUNT,2,FALSE);
SetDlgItemInt(hDlg,IDC_ISO_FRAMES_PER_BUFFER,8,FALSE);
SetDlgItemInt(hDlg,IDC_ISO_LOOP_COUNT,1,FALSE);
SetDlgItemInt(hDlg,IDC_TESTPASS,0,FALSE);
break; /*end WM_INITDIALOG case*/
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_ABOUT:
sprintf(tempbuff,"EZ-USB Isostrm - built %s %s",build_time,build_date);
MessageBox(hDlg, tempbuff,"About EZ-USB",MB_ICONINFORMATION);
break;
case IDOK:
case IDCANCEL:
EndDialog(hDlg,0);
break;
case IDC_CLEAR:
{
hOutputBox = GetDlgItem (hDlg, IDC_OUTPUT_BOX);
SendMessage (hOutputBox, LB_RESETCONTENT, 0, 0);
}
break;
case IDC_START_ISO_STREAM:
{
ISO_TRANSFER_CONTROL IsoControl;
ULONG pipenum;
BOOL Success;
ULONG count=0;
// Open the driver
GetDlgItemText (hDlg, IDC_DRIVER_NAME, pcDriverName, MAX_DRIVER_NAME);
if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
{
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Opened Driver Successfully");
} else {
SendMessage (hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Failed to Open Driver");
hDevice = NULL;
break;
}
IsoControl.PacketSize = GetDlgItemInt(hDlg,IDC_ISO_PACKET_SIZE,&Success,FALSE);
// reset the pipe
pipenum = GetDlgItemInt (hDlg, IDC_ISO_PIPE, NULL, FALSE);
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_RESETPIPE,
&pipenum,
sizeof(ULONG),
NULL,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -