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

📄 dlgpgallocateaddressrange.cpp

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

#include "stdafx.h"
#include "testapp.h"
#include "DlgPgAllocateAddressRange.h"
#include "ddx_ex.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgPgAllocateAddressRange dialog


CDlgPgAllocateAddressRange::CDlgPgAllocateAddressRange(CWnd* pParent /*=NULL*/)
	: CDialogPage(CDlgPgAllocateAddressRange::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgPgAllocateAddressRange)
	m_bUseBigEndian = FALSE;	
	
	m_bReadType = TRUE;
	m_bWriteType = TRUE;
	m_bLockType = TRUE;
	m_bBroadcastType = FALSE;

	m_dwCompOffsetHi = 0;
	m_dwCompOffsetLo = 0;
	m_dwLength = 512;
	m_dwMaxSegmentSize = 0;		
	
	m_nMeans = 0;
	m_bReadNotification = FALSE;
	m_bWriteNotification = FALSE;
	m_bLockNotification = FALSE;
	m_bNoNotification = TRUE;
	//}}AFX_DATA_INIT
}


void CDlgPgAllocateAddressRange::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgPgAllocateAddressRange)
	DDX_Check(pDX, IDC_CHECK_BIG_ENDIAN, m_bUseBigEndian);
	DDX_Check(pDX, IDC_CHECK_LOCK_NOTIFICATION, m_bLockNotification);
	DDX_Check(pDX, IDC_CHECK_LOCK_TYPE, m_bLockType);
	DDX_Check(pDX, IDC_CHECK_READ_NOTIFICATION, m_bReadNotification);
	DDX_Check(pDX, IDC_CHECK_READ_TYPE, m_bReadType);
	DDX_Check(pDX, IDC_CHECK_WRITE_TYPE, m_bWriteType);
//	DDX_Text(pDX, IDC_EDIT_COMPUTER_OFFSET_HIGH, m_dwCompOffsetHi);
//	DDX_Text(pDX, IDC_EDIT_COMPUTER_OFFSET_LOW, m_dwCompOffsetLo);
	DDX_Text(pDX, IDC_EDIT_LENGTH, m_dwLength);
	DDX_Text(pDX, IDC_EDIT_MAX_SEGMENT_SIZE, m_dwMaxSegmentSize);
	DDX_Check(pDX, IDC_CHECK_NO_NOTIFICATION, m_bNoNotification);
	DDX_Check(pDX, IDC_CHECK_BROADCAST_TYPE, m_bBroadcastType);
	DDX_Check(pDX, IDC_CHECK_WRITE_NOTIFICATION, m_bWriteNotification);
	DDX_Radio(pDX, IDC_RADIO_NO_NOTIFY_BUS, m_nMeans);
	//}}AFX_DATA_MAP
	UINT nIDPrompt = IDS_STRING_INVALID_NUM;
	LPCTSTR format;

	// address offset
	format = _T("0x%X");

	DDX_TextEx(pDX, IDC_EDIT_COMPUTER_OFFSET_HIGH, format, m_dwCompOffsetHi, nIDPrompt);
	DDX_TextEx(pDX, IDC_EDIT_COMPUTER_OFFSET_LOW, format, m_dwCompOffsetLo, nIDPrompt);
}


BEGIN_MESSAGE_MAP(CDlgPgAllocateAddressRange, CDialog)
	//{{AFX_MSG_MAP(CDlgPgAllocateAddressRange)
	ON_BN_CLICKED(IDC_CHECK_BROADCAST_TYPE, OnCheckBroadcastType)
	ON_BN_CLICKED(IDC_CHECK_LOCK_TYPE, OnCheckLockType)
	ON_BN_CLICKED(IDC_CHECK_READ_TYPE, OnCheckReadType)
	ON_BN_CLICKED(IDC_CHECK_WRITE_TYPE, OnCheckWriteType)
	ON_BN_CLICKED(IDC_CHECK_NO_NOTIFICATION, OnCheckNoNotification)
	ON_BN_CLICKED(IDC_CHECK_READ_NOTIFICATION, OnCheckReadNotification)
	ON_BN_CLICKED(IDC_CHECK_WRITE_NOTIFICATION, OnCheckWriteNotification)
	ON_BN_CLICKED(IDC_CHECK_LOCK_NOTIFICATION, OnCheckLockNotification)
	ON_BN_CLICKED(IDC_BUTTON_ALLOCATE_ADDRESS_RANGE, OnButtonAllocateAddressRange)
	ON_BN_CLICKED(IDC_BUTTON_FREE_ADDRESS_RANGE, OnButtonFreeAddressRange)
	ON_BN_CLICKED(IDC_RADIO_NO_NOTIFY_BUS, OnRadioNoNotifyBus)
	ON_BN_CLICKED(IDC_RADIO_NO_NOTIFY_PORT, OnRadioNoNotifyPort)
	ON_BN_CLICKED(IDC_RADIO_NOTIFY_MDL, OnRadioNotifyMdl)
	ON_BN_CLICKED(IDC_RADIO_NOTIFY_FIFO, OnRadioNotifyFifo)
	ON_BN_CLICKED(IDC_RADIO_NOTIFY_DEVICE, OnRadioNotifyDevice)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgPgAllocateAddressRange message handlers
void CDlgPgAllocateAddressRange::OnCheckBroadcastType() 
{
	if( m_bBroadcastType )//以前的值
	{
		m_bReadType = TRUE;
		m_bWriteType = TRUE;
		m_bLockType = TRUE;
		m_bBroadcastType = FALSE;
	}
	else
	{
		m_bReadType = FALSE;
		m_bWriteType = FALSE;
		m_bLockType = FALSE;
		m_bBroadcastType = TRUE;
	}
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnCheckLockType() 
{
	if( m_bWriteType == TRUE || m_bReadType == TRUE )
		m_bLockType = !m_bLockType;
	else m_bLockType = TRUE;
	if( m_bLockType == TRUE )
		m_bBroadcastType = FALSE;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnCheckReadType() 
{
	if( m_bWriteType == TRUE || m_bLockType == TRUE )
		m_bReadType = !m_bReadType;
	else m_bReadType = TRUE;
	if( m_bReadType == TRUE )
		m_bBroadcastType = FALSE;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnCheckWriteType() 
{
	if( m_bReadType == TRUE || m_bLockType == TRUE )
		m_bWriteType = !m_bWriteType;
	else m_bWriteType = TRUE;
	if( m_bWriteType == TRUE )
		m_bBroadcastType = FALSE;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnCheckNoNotification() 
{
	//状态不变
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnCheckReadNotification() 
{
	if( m_nMeans == 0 || m_nMeans == 1 || m_nMeans == 3 || m_nMeans ==4 )
	{//状态不变
		UpdateData(FALSE);
		return;
	}
	if( m_nMeans == 2 )
	{
		if( m_bWriteNotification == TRUE || m_bLockNotification == TRUE )
			m_bReadNotification = !m_bReadNotification;
		else m_bReadNotification = TRUE;
		UpdateData(FALSE);
		return;
	}	
}

void CDlgPgAllocateAddressRange::OnCheckWriteNotification() 
{
	if( m_nMeans == 0 || m_nMeans == 1 || m_nMeans ==3 || m_nMeans ==4 )
	{//状态不变
		UpdateData(FALSE);
		return;
	}
	if( m_nMeans == 2 )
	{
		if( m_bReadNotification == TRUE || m_bLockNotification == TRUE )
			m_bWriteNotification = !m_bWriteNotification;
		else m_bWriteNotification = TRUE;
		UpdateData(FALSE);
		return;
	}	
}

void CDlgPgAllocateAddressRange::OnCheckLockNotification() 
{
	if( m_nMeans == 0 || m_nMeans == 1 || m_nMeans == 3 || m_nMeans ==4 )
	{//状态不变
		UpdateData(FALSE);
		return;
	}
	if( m_nMeans == 2 )
	{
		if( m_bWriteNotification == TRUE || m_bReadNotification == TRUE )
			m_bLockNotification = !m_bLockNotification;
		else m_bLockNotification = TRUE;
		UpdateData(FALSE);
		return;
	}	
}

void CDlgPgAllocateAddressRange::OnButtonAllocateAddressRange() 
{
	/*
	typedef struct _ALLOCATE_ADDRESS_RANGE 
	{
		ULONG           fulAllocateFlags;//Means
		ULONG           fulFlags;//一个字由两个字节N,N+1组成。big-endian:N的左边为最高位,N+1的右边为最低位;little-endian:N的右边为最低位,N+1的左边为最高位
		ULONG           nLength;
		ULONG           MaxSegmentSize;
		ULONG           fulAccessType;
		ULONG           fulNotificationOptions;
		ADDRESS_OFFSET  Required1394Offset;
		HANDLE          hAddressRange;
		UCHAR           Data[1];
	} ALLOCATE_ADDRESS_RANGE, *PALLOCATE_ADDRESS_RANGE;
	*/
	ALLOCATE_ADDRESS_RANGE allocateAddressRange;
    DWORD                  Status;

//    TRACE(TL_TRACE, (hWnd, "Enter w1394_AllocateAddressRange\r\n"));
    //得到用户指定的值
	UpdateData(TRUE);
	if( m_dwCompOffsetHi < 0 || m_dwCompOffsetLo < 0 )
	{
		MessageBox("请指定适当的数据!");
		return;
	}
	allocateAddressRange.fulAllocateFlags = m_nMeans;
	allocateAddressRange.fulFlags = 0;
	if( m_bUseBigEndian )
		allocateAddressRange.fulFlags = BIG_ENDIAN_ADDRESS_RANGE;
	allocateAddressRange.nLength = m_dwLength;
	allocateAddressRange.MaxSegmentSize = m_dwMaxSegmentSize;
	if( m_bBroadcastType )
		allocateAddressRange.fulAccessType = ACCESS_FLAGS_TYPE_BROADCAST;
	else
	{
		allocateAddressRange.fulAccessType = 0;		
		if( m_bReadType )	
			allocateAddressRange.fulAccessType |= ACCESS_FLAGS_TYPE_READ;
		if( m_bWriteType )	
			allocateAddressRange.fulAccessType |= ACCESS_FLAGS_TYPE_WRITE;
		if( m_bLockType )	
			allocateAddressRange.fulAccessType |= ACCESS_FLAGS_TYPE_LOCK;
	}

	if( m_bNoNotification )
		allocateAddressRange.fulNotificationOptions = NOTIFY_FLAGS_NEVER;
	else
	{
		allocateAddressRange.fulNotificationOptions = 0;
		if( m_bReadNotification )
			allocateAddressRange.fulNotificationOptions |= NOTIFY_FLAGS_AFTER_READ;
		if( m_bWriteNotification )
			allocateAddressRange.fulNotificationOptions |= NOTIFY_FLAGS_AFTER_WRITE;
		if( m_bLockNotification )
			allocateAddressRange.fulNotificationOptions |= NOTIFY_FLAGS_AFTER_LOCK;
	}
	allocateAddressRange.Required1394Offset.Off_High = (USHORT)m_dwCompOffsetHi; 
	allocateAddressRange.Required1394Offset.Off_Low = m_dwCompOffsetLo;
	
	//开辟传给驱动的存储空间
	PALLOCATE_ADDRESS_RANGE pAllocateAddressRange;
	ULONG ulBufferSize;

	ulBufferSize = sizeof(ALLOCATE_ADDRESS_RANGE) + allocateAddressRange.nLength;//去掉应用程序开辟的数据缓冲区
//	ulBufferSize = sizeof(ALLOCATE_ADDRESS_RANGE);
    pAllocateAddressRange = (PALLOCATE_ADDRESS_RANGE)LocalAlloc(LPTR, ulBufferSize);
    FillMemory(pAllocateAddressRange, ulBufferSize, 0);
    *pAllocateAddressRange = allocateAddressRange;

	Status = g_CurrentDev.AllocateAddressRange(pAllocateAddressRange,ulBufferSize);
	if ( Status == STATUS_SUCCESS ) 
	{
		PrintOut(NL"AllocateAddressRange Success!"NL);
	} 
	else 
	{
		Status = GetLastError();
		PrintOut(NL"AllocateAddressRange failed"NL);
		PrintError(Status);
	}	
	PrintOut(NL);

	LocalFree(pAllocateAddressRange);
}

void CDlgPgAllocateAddressRange::OnButtonFreeAddressRange() 
{
	MessageBox("free addressrange!");
}

void CDlgPgAllocateAddressRange::OnRadioNoNotifyBus() 
{
	UpdateData();
	m_bReadNotification = FALSE;
	m_bWriteNotification = FALSE;
	m_bLockNotification = FALSE;
	m_bNoNotification = TRUE;
	m_nMeans = 0;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnRadioNoNotifyPort() 
{
	m_bReadNotification = FALSE;
	m_bWriteNotification = FALSE;
	m_bLockNotification = FALSE;
	m_bNoNotification = TRUE;
	m_nMeans = 1;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnRadioNotifyMdl() 
{
	m_bReadNotification = TRUE;
	m_bWriteNotification = TRUE;
	m_bLockNotification = TRUE;
	m_bNoNotification = FALSE;
	m_nMeans = 2;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnRadioNotifyFifo() 
{
	m_bReadNotification = FALSE;
	m_bWriteNotification = TRUE;
	m_bLockNotification = FALSE;
	m_bNoNotification = FALSE;
	m_nMeans = 3;
	UpdateData(FALSE);
}

void CDlgPgAllocateAddressRange::OnRadioNotifyDevice() 
{
	m_bReadNotification = FALSE;
	m_bWriteNotification = FALSE;
	m_bLockNotification = FALSE;
	m_bNoNotification = FALSE;
	m_nMeans = 4;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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