📄 global.cpp
字号:
#include "stdafx.h"
#include "test1394show.h"
#include "EnumBox.h"
#include "global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// global variables
// global device instance
CTest1394 g_CurrentDev;
int g_DeviceNumber = -1;
// default interface GUID(1394驱动GUID,唯一标示)
// const GUID g_Test1394DefaultIID = TEST1394_IID;
// 指定调用VHPD驱动程序(2004.2.12)
const GUID g_Test1394DefaultIID = TEST1394_IID ;
// device list
HDEVINFO g_DevList = NULL;
DWORD g_ResetGenerationCount = 0;
// list containing the open non-modal dialogs
CObList g_NonModalDialogList;
// NOTE: we use values from enum VHPD_BUS_SPEED (see vhpd1394.h)
EnumBoxEntry g_SpeedSelectorTab[] = {
{ _T("100 MBit/s"), SPEED_FLAGS_100 },
{ _T("200 MBit/s"), SPEED_FLAGS_200 },
{ _T("400 MBit/s"), SPEED_FLAGS_400 },
{ NULL, 0 } // end of table
};
/*
EnumBoxEntry g_SlaveModeTab[] = {
{ _T("Generic Mode"), Generic },
{ _T("Data Receiving Mode"), Receiver },
{ _T("Data Transmitting Mode"), Transmitter },
{ NULL, 0 } // end of table
};
// NOTE: we use values from enum VHPD_LOCK_TYPE (see vhpd1394.h)
EnumBoxEntry g_LockTypeTab[] = {
{ _T("MASK_SWAP"), MaskSwap },
{ _T("COMPARE_SWAP"), CompareSwap },
{ _T("FETCH_ADD"), FetchAdd },
{ _T("LITTLE_ADD"), LittleAdd },
{ _T("BOUNDED_ADD"), BoundedAdd },
{ _T("WRAP_ADD"), WrapAdd },
{ NULL, 0 } // end of table
};
EnumBoxEntry g_IsoSourceTab[] = {
{ _T("Isochronous channel"), IsoSrcChan },
{ _T("Local File/Memory"), SrcFile },
{ NULL, 0 } // end of table
};
EnumBoxEntry g_IsoDestinationTab[] = {
{ _T("Isochronous channel"), IsoDstChan },
{ _T("Local File/Memory"), DstFile },
{ NULL, 0 } // end of table
};
*/
/////////////////////////////////////////////////////////////////////////////
// global functions
//
// print to output window
//
// Note:
// This is a global function that is called from any thread context.
// It is not possible to call MFC objects from a thread context that is
// created by using non-MFC means.
// So we use PostMessage to access the OutputWindow.
//
void PrintOut(LPTSTR pstrMsg)
{
// theApp.m_MainDlg.OutputString(pstrMsg);
/* const int buffersize = 2048;
va_list argptr;
char buffer[buffersize];
// print to buffer
va_start(argptr,format);
_vsnprintf(buffer,buffersize-1,format,argptr);
buffer[buffersize-1] = 0;
// send buffer to output window (synchronous behavior)
// theApp.SendMsgToOutputWin(WM_USER_PRINT_OUT,0,(long)buffer);
va_end(argptr);
*/
}
// print error message according to ErrorCode, returns ErrorCode
DWORD PrintError(DWORD ErrorCode, DWORD Flags/*= E_ERROR*/, const char *Prefix/*=NULL*/)
{
char ErrBuffer[MAX_ERROR_MSG_LENGTH];
char Buffer[MAX_ERROR_MSG_LENGTH];
if ( ErrorCode != 0 ) {
// build message string
if ( Prefix!=NULL ) {
// _snprintf(Buffer,sizeof(Buffer),"%s %s", Prefix, CVhpd::ErrorText(ErrBuffer,sizeof(ErrBuffer),ErrorCode));
} else {
// _snprintf(Buffer,sizeof(Buffer),"%s", CVhpd::ErrorText(ErrBuffer,sizeof(ErrBuffer),ErrorCode));
}
// print to output window
// PrintOut("%s"NL,Buffer);
if ( Flags&E_FATAL ) {
// display message box
::AfxMessageBox(Buffer, MB_OK, MB_ICONEXCLAMATION);
}
}
return ErrorCode;
}
// message box
void DisplayMessageBox(const char *format, ...)
{
char buffer[2048];
va_list argptr;
// print to buffer
va_start(argptr,format);
_vsnprintf(buffer,sizeof(buffer)-1,format,argptr);
buffer[sizeof(buffer)-1] = 0;
// display message box
::AfxMessageBox(buffer, MB_OK, MB_ICONEXCLAMATION);
va_end(argptr);
}
// swap bytes
void SwapBytes(ULONG* val)
{
ULONG Byte0, Byte1, Byte2, Byte3;
Byte0 = *val & 0xff;
Byte1 = (*val & 0xff00) >> 8;
Byte2 = (*val & 0xff0000) >> 16;
Byte3 = (*val & 0xff000000) >> 24;
*val = ((Byte0 << 24) & 0xff000000)
| ((Byte1 << 16) & 0xff0000)
| ((Byte2 << 8) & 0xff00)
| (Byte3 & 0xff);
}
/*
// display configuration ROM information
void PrintConfigRom(SPEC1394_CONFIG_ROM_HEAD ConfigRomHead)
{
// make values more readable
SwapBytes(&ConfigRomHead.Information);
SwapBytes(&ConfigRomHead.BusName);
SwapBytes(&ConfigRomHead.BusInfoBlockCaps);
SwapBytes(&ConfigRomHead.NodeID[0]);
SwapBytes(&ConfigRomHead.NodeID[1]);
SwapBytes(&ConfigRomHead.RootDirFirst);
// show information on output window
PrintOut("Device configuration information:"NL);
PrintOut(" Configuration ROM"NL);
PrintOut(" InfoLength: %02d quadlets"NL, ((ConfigRomHead.Information>>24)&0xff));
PrintOut(" CRCLength : %02d quadlets"NL,((ConfigRomHead.Information>>16)&0xff));
PrintOut(" CRC : 0x%04X "NL,(ConfigRomHead.Information&0xffff));
PrintOut(" Bus Name : 0x%08X"NL, ConfigRomHead.BusName);
PrintOut(NL" Vendor ID : 0x%06X"NL, ((ConfigRomHead.NodeID[0]>>8)&0xffffff));
PrintOut(" Chip ID : 0x%02X %08X"NL,(ConfigRomHead.NodeID[0]&0xff),ConfigRomHead.NodeID[1]);
PrintOut(NL" Node Capabilities:"NL);
PrintOut(" Max. write payload : %d bytes"NL, 0x1<<(((ConfigRomHead.BusInfoBlockCaps>>12)&0xf)+1));
PrintOut(" Cycle clock accuracy: %d parts per million"NL, ((ConfigRomHead.BusInfoBlockCaps>>16)&0xff));
PrintOut(" Capability flags : irmc=%d cmc=%d isc=%d bmc=%d"NL,
((ConfigRomHead.BusInfoBlockCaps>>31)&0x1),
((ConfigRomHead.BusInfoBlockCaps>>30)&0x1),
((ConfigRomHead.BusInfoBlockCaps>>29)&0x1),
((ConfigRomHead.BusInfoBlockCaps>>28)&0x1));
PrintOut(NL" Root directory (first quadlet): 0x%08X"NL, ConfigRomHead.RootDirFirst);
}
// display SID packet information
void PrintSIDPacket(SPEC1394_SELF_ID_PACKET Pack)
{
// test for primary SID packet
if ( !Pack.Zero ) {
PrintOut(" Primary SID packet:"NL);
PrintOut(" Sending node: %d Active LINK: %d Contender:%d"NL,
Pack.Phys_ID, Pack.Link_Active, Pack.Contender);
PrintOut(" PHY Speed: %d PHY delay: %d Power class: %d"NL,
Pack.Speed, Pack.Delay, Pack.Power_Class);
PrintOut(" GapCount: %d"NL, Pack.Gap_Count);
PrintOut(" Port status: (0)->%s (1)->%s (2)->%s"NL,
(Pack.Port0==0) ? "Unknown" : (Pack.Port0==1) ? "Not Active" : (Pack.Port0==2) ? "to Parent" : "to Child",
(Pack.Port1==0) ? "Unknown" : (Pack.Port1==1) ? "Not Active" : (Pack.Port1==2) ? "to Parent" : "to Child",
(Pack.Port2==0) ? "Unknown" : (Pack.Port2==1) ? "Not Active" : (Pack.Port2==2) ? "to Parent" : "to Child");
PrintOut(" More packets: %d"NL, Pack.More_Packets);
}
PrintOut(NL);
}
*/
HDEVINFO CreateDeviceList(const GUID *InterfaceGuid)
{
HDEVINFO h;
h = SetupDiGetClassDevs(
(GUID*)InterfaceGuid, // LPGUID ClassGuid,
NULL, // PCTSTR Enumerator,
NULL, // HWND hwndParent,
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT // DWORD Flags
);
return ( (h==INVALID_HANDLE_VALUE) ? NULL : h );
}
void DestroyDeviceList(HDEVINFO DeviceList)
{
if ( DeviceList!=NULL ) {
SetupDiDestroyDeviceInfoList(DeviceList);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -