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

📄 dlgpgbustopology.cpp

📁 1394测试程序
💻 CPP
字号:
// DlgPgBusTopology.cpp : implementation file
//

#include "stdafx.h"
#include "TestApp.h"
#include "DlgPgBusTopology.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgPgBusTopology dialog


CDlgPgBusTopology::CDlgPgBusTopology(CWnd* pParent /*=NULL*/)
	: CDialogPage(CDlgPgBusTopology::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgPgBusTopology)
	m_CheckForceRoot = FALSE;
	m_ValResetGenerationCount = 0;
	m_CheckUseLocalNode = FALSE;
	m_uintForceRoot = 0;
	m_uintGapCount = 0;
	m_uintInverse = 0;
	m_uintPacketId = 0;
	m_uintPhyId = 0;
	m_uintSetGapCount = 0;
	m_uintReserved2 = 0;
	m_uintReserved1 = 0;
	//}}AFX_DATA_INIT

	m_ThreadRunning = FALSE;

}


void CDlgPgBusTopology::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgPgBusTopology)
	DDX_Check(pDX, IDC_CHECK_FORCE_ROOT, m_CheckForceRoot);
	DDX_Text(pDX, IDC_EDIT_GENERATION_COUNT, m_ValResetGenerationCount);
	DDX_Check(pDX, IDC_CHECK_MAX_SPEED, m_CheckUseLocalNode);
	DDX_Text(pDX, IDC_EDIT_FORCE_ROOT, m_uintForceRoot);
	DDX_Text(pDX, IDC_EDIT_GAP_COUNT, m_uintGapCount);
	DDX_Text(pDX, IDC_EDIT_INVERSE, m_uintInverse);
	DDX_Text(pDX, IDC_EDIT_PACKET_ID, m_uintPacketId);
	DDX_Text(pDX, IDC_EDIT_PHY_ID, m_uintPhyId);
	DDX_Text(pDX, IDC_EDIT_SET_GAP_COUNT, m_uintSetGapCount);
	DDX_Text(pDX, IDC_EDIT_RESERVED2, m_uintReserved2);
	DDX_Text(pDX, IDC_EDIT_RESERVED1, m_uintReserved1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgPgBusTopology, CDialog)
	//{{AFX_MSG_MAP(CDlgPgBusTopology)
	ON_BN_CLICKED(IDC_BUTTON_GET_GENERATION, OnButtonGetGeneration)
	ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
	ON_BN_CLICKED(IDC_BUTTON_EN_RES_NOTIFY, OnButtonEnResNotify)
	ON_BN_CLICKED(IDC_BUTTON_DIS_RES_NOTIFY, OnButtonDisResNotify)
//	ON_MESSAGE(WM_USER_THREAD_TERMINATED,OnMessageThreadTerminated)
	ON_MESSAGE(WM_USER_BUS_RESET,OnMessageBusReset)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_PCP_SEND, OnButtonPcpSend)
	ON_BN_CLICKED(IDC_BUTTON_SPEED_BETWEEN_DEVICES, OnButtonSpeedBetweenDevices)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CDlgPgBusTopology message handlers


BOOL CDlgPgBusTopology::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// set initial state of some controls
//	UpdateEditBoxesStates();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


//
// Message Handler for WM_USER_THREAD_TERMINATED
// called in the context of main thread
//



//
// Message Handler for WM_USER_BUS_RESET
// called in the context of main thread
//
long CDlgPgBusTopology::OnMessageBusReset(UINT nID, LPARAM lParam)
{
	// just display a message
	PrintOut("!!! BUS RESET !!!"NL);

	return 0;
}


void CDlgPgBusTopology::OnDestroy() 
{
	// this instance is about to be closed
	// stop m_ResetHandler if running
	if ( m_ThreadRunning == TRUE ) {
		// shutdown worker thread
		// this call blocks until the thread has terminated
//		m_ResetHandler.ShutdownThread();	
		// save state of worker thread
		m_ThreadRunning = FALSE;
		// close instance
//		m_ResetHandler.Close();
	}

	CDialog::OnDestroy();
}


void CDlgPgBusTopology::OnButtonGetGeneration() 
{
	ULONG       generationCount;
	// call driver (through class library)
	DWORD Status = g_CurrentDev.GetResetGenerationCount(&generationCount);
	if (Status == STATUS_SUCCESS) {
		// update display
		m_ValResetGenerationCount=generationCount;
		UpdateData(FALSE);

		// update global var, must be thread-save
		InterlockedExchange((LPLONG)(&g_ResetGenerationCount), m_ValResetGenerationCount);

		PrintOut("Get current reset generation count was successful."NL);
	} else {
		PrintOut(NL"GetResetGenerationCount() failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);
/*	VHPD_GENERATION_COUNT GenCount;

	// call driver (through class library)
	DWORD Status = g_CurrentDev.GetResetGenerationCount(&GenCount);
	if (Status == STATUS_SUCCESS) {
		// update display
		m_ValResetGenerationCount=GenCount.Count;
		UpdateData(FALSE);

		// update global var, must be thread-save
		InterlockedExchange((LPLONG)(&g_ResetGenerationCount), m_ValResetGenerationCount);

		PrintOut("Get current reset generation count was successful."NL);
	} else {
		PrintOut(NL"GetResetGenerationCount() failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);*/
}


void CDlgPgBusTopology::OnButtonReset() 
{
	ULONG Flags;
	Flags = 0;
	if ( UpdateData(TRUE) ) 
	{
		if( m_CheckForceRoot )
			Flags |= BUS_RESET_FLAGS_FORCE_ROOT;
		// call driver (through class library)
		DWORD Status = g_CurrentDev.ForceBusReset(Flags);
		if ( Status == STATUS_SUCCESS ) {
			PrintOut("Bus Reset successfully initiated."NL);
		} 
		else 
		{
			PrintOut(NL"ForceBusReset() failed"NL);
			PrintError(Status);
		}	
		PrintOut(NL);
	}
/*	VHPD_BUS_RESET BusResetParams;
	::ZeroMemory(&BusResetParams,sizeof(BusResetParams));

	// get user parameters from dialog
	if ( UpdateData(TRUE) ) {
		// put user parameters to input structure
		if ( m_CheckForceRoot == TRUE ) {
			BusResetParams.Flags |= VHPD_FLAG_RESET_FORCE_ROOT;
		}

		// call driver (through class library)
		DWORD Status = g_CurrentDev.ForceBusReset(&BusResetParams);
		if (Status == STATUS_SUCCESS) {
			PrintOut("Bus Reset successfully initiated."NL);
		} else {
			PrintOut(NL"ForceBusReset() failed"NL);
			PrintError(Status);
		}	
		PrintOut(NL);
	}
*/
}


void CDlgPgBusTopology::OnButtonEnResNotify() 
{
	ULONG   fulFlags;
	fulFlags = REGISTER_NOTIFICATION_ROUTINE;

	DWORD Status = g_CurrentDev.BusResetNotification(fulFlags);
	if (Status == STATUS_SUCCESS) 
	{
		PrintOut("Bus Reset Notification successfully initiated."NL);
	} 
	else 
	{
		PrintOut(NL"Bus Reset Notification failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);
/*
	// init members of worker thread
	m_ResetHandler.SetParentWnd(GetSafeHwnd());

	// create a new instance of the device
	Status = m_ResetHandler.Open(g_DeviceNumber,g_DevList,&g_Test1394DefaultIID);
	if (Status != STATUS_SUCCESS) {
		PrintOut(NL"Open device %d failed"NL,g_DeviceNumber);
		PrintError(Status);
		DisplayMessageBox("Failed to create new instance of device %d (Status 0x%08X)",g_DeviceNumber,Status);
		return;
	}

	// start worker thread
	if (!m_ResetHandler.StartThread()) {
		PrintOut("Start Thread failed"NL);
	} else {
		m_ThreadRunning = TRUE;
		PrintOut("Bus Reset Notification Handler installed"NL);
	}
*/
}


void CDlgPgBusTopology::OnButtonDisResNotify() 
{
	DWORD Status;
	ULONG   fulFlags;
	fulFlags = DEREGISTER_NOTIFICATION_ROUTINE;
	Status = g_CurrentDev.BusResetNotification(fulFlags);
	if (Status == STATUS_SUCCESS) 
	{
		PrintOut("Bus Reset Notification successfully disabled."NL);
	} 
	else 
	{
		PrintOut(NL"Bus Reset Notification failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);
/*	// shutdown worker thread
	// this call blocks until the thread has terminated
	m_ResetHandler.ShutdownThread();	
	// save state of worker thread
	m_ThreadRunning = FALSE;
	// close instance
	m_ResetHandler.Close();*/
}

void CDlgPgBusTopology::OnButtonPcpSend() 
{
	PHY_CONFIGURATION_PACKET    phyConfigPacket;
	/*
	typedef struct _PHY_CONFIGURATION_PACKET 
	{
		ULONG               PCP_Phys_ID:6;          // Byte 0 - Bits 0-5
		ULONG               PCP_Packet_ID:2;        // Byte 0 - Bits 6-7
		ULONG               PCP_Gap_Count:6;        // Byte 1 - Bits 0-5
		ULONG               PCP_Set_Gap_Count:1;    // Byte 1 - Bit 6
		ULONG               PCP_Force_Root:1;       // Byte 1 - Bit 7
		ULONG               PCP_Reserved1:8;        // Byte 2 - Bits 0-7
		ULONG               PCP_Reserved2:8;        // Byte 3 - Bits 0-7
		ULONG               PCP_Inverse;            // Inverse quadlet
	} PHY_CONFIGURATION_PACKET, *PPHY_CONFIGURATION_PACKET;
	*/
    DWORD                       Status;

//    TRACE(TL_TRACE, (hWnd, "Enter w1394_SendPhyConfigPacket\r\n"));

    phyConfigPacket.PCP_Phys_ID = 0;
    phyConfigPacket.PCP_Packet_ID = 0;
    phyConfigPacket.PCP_Gap_Count = 0;
    phyConfigPacket.PCP_Set_Gap_Count = 0;
    phyConfigPacket.PCP_Force_Root = 0;
    phyConfigPacket.PCP_Reserved1 = 0;
    phyConfigPacket.PCP_Reserved2 = 0;
    phyConfigPacket.PCP_Inverse = 0;
	if( UpdateData(TRUE) ) 
	{
		phyConfigPacket.PCP_Phys_ID = m_uintPhyId;
		phyConfigPacket.PCP_Packet_ID = m_uintPacketId;
		phyConfigPacket.PCP_Gap_Count = m_uintGapCount;
		phyConfigPacket.PCP_Set_Gap_Count = m_uintSetGapCount;
		phyConfigPacket.PCP_Force_Root = m_uintForceRoot;
		phyConfigPacket.PCP_Reserved1 = m_uintReserved1;
		phyConfigPacket.PCP_Reserved2 = m_uintReserved2;
		phyConfigPacket.PCP_Inverse = m_uintInverse;

		Status = g_CurrentDev.SendPhyConfigPacket(&phyConfigPacket);
		if (Status == STATUS_SUCCESS) {
			PrintOut("PHY Config Packet successfully sent."NL);
		} else {
			PrintOut(NL"SendPhyConfigPacket() failed"NL);
			PrintError(Status);
		}	
		PrintOut(NL);
	}
	
/*
	::ZeroMemory(&SendPCP, sizeof(VHPD_SEND_PHY_CONFIG_PACKET));

	if ( UpdateData(TRUE) ) {
		if ( m_CheckPCPForceRoot ) {
			SendPCP.PhyConfigPacket.u.ForceRoot = 1;
			SendPCP.PhyConfigPacket.u.NewRootID = m_ValPCPNewRootID;
		}
		if ( m_CheckPCPUpdGapCount ) {
			SendPCP.PhyConfigPacket.u.UpdateGapCount = 1;
			SendPCP.PhyConfigPacket.u.NewGapCount = m_ValPCPNewGapCountValue;
		}
		SendPCP.PhyConfigPacket.Inverse = ~SendPCP.PhyConfigPacket.u.Quadlet;
	}

	// call driver (through class library)
	DWORD Status = g_CurrentDev.SendPhyConfigPacket(&SendPCP);
	if (Status == STATUS_SUCCESS) {
		PrintOut("PHY Config Packet successfully sent."NL);
	} else {
		PrintOut(NL"SendPhyConfigPacket() failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);*/
}



//DEL void CDlgPgBusTopology::UpdateEditBoxesStates()
//DEL {
//DEL 	// edit box IDC_EDIT_PCP_NEWROOT
//DEL 	if ( m_ButtonPCPForceRoot.GetCheck()==0 ) {
//DEL 		// checkbox is unchecked
//DEL 		m_EditCtrlPCPNewRootID.EnableWindow(FALSE);
//DEL 	} else {
//DEL 		// checkbox is checked
//DEL 		m_EditCtrlPCPNewRootID.EnableWindow(TRUE);
//DEL 	}
//DEL 
//DEL 	// edit box IDC_EDIT_PCP_NEWGAPCOUNT
//DEL 	if ( m_ButtonPCPUpdGapCount.GetCheck()==0 ) {
//DEL 		// checkbox is unchecked
//DEL 		m_EditCtrlPCPNewGapCountValue.EnableWindow(FALSE);
//DEL 	} else {
//DEL 		// checkbox is checked
//DEL 		m_EditCtrlPCPNewGapCountValue.EnableWindow(TRUE);
//DEL 	}
//DEL }

void CDlgPgBusTopology::OnButtonSpeedBetweenDevices() 
{
	GET_MAX_SPEED_BETWEEN_DEVICES   getMaxSpeed;
	/*
	typedef struct _GET_MAX_SPEED_BETWEEN_DEVICES {
		//input
		ULONG           fulFlags;//0:the calling   USE_LOCAL_NODE:the computer itself
		ULONG           ulNumberOfDestinations;//目标设备个数
		ULONG           hDestinationDeviceObjects[64];//目标设备的设备对象队列
		//output
		ULONG           fulSpeed;//最大速度
	} GET_MAX_SPEED_BETWEEN_DEVICES, *PGET_MAX_SPEED_BETWEEN_DEVICES;
	*/
	if ( UpdateData(TRUE)	) 
	{
		getMaxSpeed.fulFlags = 0;
		if ( m_CheckUseLocalNode ) //USE_LOCAL_NODE
		{
			getMaxSpeed.fulFlags = USE_LOCAL_NODE;
		}
		//设定目标设备参数,现不知道怎样设
		getMaxSpeed.ulNumberOfDestinations = 0;
		// call driver (through class library)		
		DWORD Status = g_CurrentDev.GetSpeedBetweenDevices(&getMaxSpeed);	
		if ( Status == STATUS_SUCCESS ) 
		{}
		else
		{}
	}
}

⌨️ 快捷键说明

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