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

📄 netdisplay.cpp

📁 F340+CP2200的汉化版NETFINDER源代码,增加了串口设置
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	}		


	SetScrollPos(SB_VERT, nCurPos);
	
	// Call Default
	//CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CNetDisplay::Init()
{


}

void CNetDisplay::UpdateScrollbar()
{
	SCROLLINFO scroll_info = {0};
	
	// Specify the maximum number of entries for which 
	// the scroll bar should be hidden
	#define MAX_NO_SCROLL_SIZE 5	

	if(m_numcells > MAX_NO_SCROLL_SIZE){

		ShowScrollBar(SB_VERT);
		scroll_info.cbSize = sizeof(SCROLLINFO);
		scroll_info.fMask = (SIF_RANGE | SIF_PAGE);
		scroll_info.nMin = 0;
		scroll_info.nMax =  m_numcells - 1  ;
		scroll_info.nPage = 1;
		SetScrollInfo(SB_VERT, &scroll_info);

	} else {
		// Hide Scroll Bar
		ShowScrollBar(SB_VERT, FALSE);
	}
	
	// Sort and Redraw Window
	Refresh();
}



bool CNetDisplay::AddEntry(NETDISPLAY_ENTRY * pEntry)
{
	
	int i;
	NETDISPLAY_ENTRY *pNewEntry;

	// Find the next available entry
	for(i = 0; i < MAX_ENTRIES; i++)
	{
		if(m_ptr_array[i] == 0)
		{
			break;	//发现第一个空条目
		}
	}

	// If no entries could be found
	if( i == MAX_ENTRIES ){
		return FALSE;	//全满,没有空条目
	} 

	//-----------------------------
	// Add the entry at location i
	//-----------------------------
	
	// Create new entry
	pNewEntry = new NETDISPLAY_ENTRY(); //动态在堆上建立一个新NETDISPLAY_ENTRY型对象
	
	// Copy the entry data
	pNewEntry->alert_level    = pEntry->alert_level;
	
	pNewEntry->event1_days    = pEntry->event1_days;
	pNewEntry->event1_hours   = pEntry->event1_hours;
	pNewEntry->event1_minutes = pEntry->event1_minutes;

	pNewEntry->event2_days    = pEntry->event2_days;
	pNewEntry->event2_hours   = pEntry->event2_hours;
	pNewEntry->event2_minutes = pEntry->event2_minutes;
	
	pNewEntry->event1_seconds = pEntry->event1_seconds;
	pNewEntry->event2_seconds = pEntry->event2_seconds;

	CopyMemory(pNewEntry->mac,		pEntry->mac,	6);
	CopyMemory(pNewEntry->ip,		pEntry->ip,		4);

	pNewEntry->port = pEntry->port;


	CopyMemory(pNewEntry->subnet,	pEntry->subnet, 4);
	CopyMemory(pNewEntry->gateway,  pEntry->gateway,4);
	
	pNewEntry->baudrate      = pEntry->baudrate;
	pNewEntry->baudrate_mode = pEntry->baudrate_mode;
	
	pNewEntry->str_type = pEntry->str_type;

	switch(pEntry->baudrate){
		case 0: // Select 1200
			pEntry->str_description += "1200位/秒、";
			break;
		case 1: // Select 2400
			pEntry->str_description += "2400位/秒、";
			break;
		case 3: // Select 14400
			pEntry->str_description += "14400位/秒、";
			break;
		case 4: // Select 38400
			pEntry->str_description += "38400位/秒、";
			break;
		case 5: // Select 57600
			pEntry->str_description += "57600位/秒、";
			break;
		case 6: // Select 115200
			pEntry->str_description += "115200位/秒、";
			break;
		case 7: // Select 230400
			pEntry->str_description += "230400位/秒、";
			break;
		default:
			pEntry->str_description += "9600位/秒、";
			break;
	}
	if(pEntry->baudrate_mode & 0x10){
		switch(pEntry->baudrate_mode & 0x60){
		case 0x00:
			pEntry->str_description += "奇校验、";
			break;
		case 0x20:
			pEntry->str_description += "偶校验、";
			break;
		case 0x40:
			pEntry->str_description += "Mark校验、";
			break;
		default:
			pEntry->str_description += "Space校验、";
			break;
		}
	}			
	else
		pEntry->str_description += "无奇偶校验、";

	switch(pEntry->baudrate_mode & 0x0C){
		case 0x00:
			pEntry->str_description += "5位数据、";
			break;
		case 0x04:
			pEntry->str_description += "6位数据、";
			break;
		case 0x08:
			pEntry->str_description += "7位数据、";
			break;
		default:
			pEntry->str_description += "8位数据、";
			break;
		}
	if(pEntry->baudrate_mode & 0x01)
		pEntry->str_description += "2停止位";
	else
		pEntry->str_description += "1停止位";
	
	pNewEntry->str_description = pEntry->str_description;
	pNewEntry->str_ev1 = pEntry->str_ev1;
	pNewEntry->str_ev2 = pEntry->str_ev2;
	
	// Store address in global array
	m_ptr_array[i] = pNewEntry;	//保存当前条目的指针
	
	// Increment valid cell count
	m_numcells++;	//增加一个有效的单元(条目)计数
	
	// Update the scroll bar, sort, and redraw window
	UpdateScrollbar();

	return TRUE;
}	


void CNetDisplay::RemoveAllEntries()
{	
	int i;

	// Delete all entries 
	for(i = 0; i < MAX_ENTRIES; i++)
	{
		if(m_ptr_array[i] != 0)
		{
			delete m_ptr_array[i];
			m_ptr_array[i] = 0;
		}
	}
	
	// Update number of cells
	m_numcells = 0;
	m_selectedcell = -1;

	// Update the scroll bar and redraw window
	UpdateScrollbar();
}

void CNetDisplay::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	// (Hidden above window     +   amount showing) / CELL_HEIGHT 
	unsigned int cell = (CELL_HEIGHT*GetScrollPos(SB_VERT) + point.y)/CELL_HEIGHT;
	
	// If the user clicks of a valid cell, select it
	// Otherwise, clear selection
	if(cell <= m_numcells){
		m_selectedcell = cell;		
	} else {
		m_selectedcell = -1;
	}
	
	// Redraw window to show selected cell
	this->RedrawWindow();

	CWnd::OnLButtonUp(nFlags, point);
}



void CNetDisplay::Refresh()
{
	
	// Sort Array
	//  
	switch(m_sortmethod){
	
		case 0: // Sort By Event 1
			SortByEvent1();
			break;
		case 1:	// Sort By Event 2
			SortByEvent2();
			break;
		case 2:	// Sort By IP Address
			SortByIP();
			break;
		default:// Not Sorted
			break;

	}

	this->RedrawWindow();
}

void CNetDisplay::SwapEntry(unsigned int index_a, unsigned int index_b)
{
	NETDISPLAY_ENTRY* pTempEntry = m_ptr_array[index_a];

	m_ptr_array[index_a] = m_ptr_array[index_b];

	m_ptr_array[index_b] = pTempEntry;

	// Check if any of the cells were selected and maintain the selected cell
	if(m_selectedcell == (signed) index_a){
		m_selectedcell =  index_b;
	} else 
	if(m_selectedcell == (signed) index_b){
		m_selectedcell = index_a;
	}  
}



// Compare by Event 1
//
//	Returns:
//		1 - Entry1 is greater than Entry 2
//		0 - Entry 2 is greater than Entry 1
//	   -1 - Entries are equal
//		 
int CNetDisplay::CMP_Event1(NETDISPLAY_ENTRY *pEntry1, NETDISPLAY_ENTRY *pEntry2)
{
	// Check Days
	if(pEntry1->event1_days > pEntry2->event1_days){
		return 1;		
	} else 
	if(pEntry1->event1_days < pEntry2->event1_days){
		return 0;		
	} else
		
		// Days are equal, check hours
		if(pEntry1->event1_hours > pEntry2->event1_hours){
			return 1;		
		} else 
		if(pEntry1->event1_hours < pEntry2->event1_hours){
			return 0;		
		} else
		
			// Hours are equal, check minutes
			if(pEntry1->event1_minutes > pEntry2->event1_minutes){
				return 1;		
			} else 
			if(pEntry1->event1_minutes < pEntry2->event1_minutes){
				return 0;		
			} else	

				// Minutes are equal, check seconds
				if(pEntry1->event1_seconds > pEntry2->event1_seconds){
					return 1;		
				} else 
				if(pEntry1->event1_seconds < pEntry2->event1_seconds){
					return 0;		
				} else 
					
					// All fields are equal
					return -1;
}

// Compare by Event 2
//
//	Returns:
//		1 - Entry1 is greater than Entry 2
//		0 - Entry 2 is greater than Entry 1
//	   -1 - Entries are equal
//	
int CNetDisplay::CMP_Event2(NETDISPLAY_ENTRY *pEntry1, NETDISPLAY_ENTRY *pEntry2)
{
	// Check Days
	if(pEntry1->event2_days > pEntry2->event2_days){
		return 1;		
	} else 
	if(pEntry1->event2_days < pEntry2->event2_days){
		return 0;		
	} else
		
		// Days are equal, check hours
		if(pEntry1->event2_hours > pEntry2->event2_hours){
			return 1;		
		} else 
		if(pEntry1->event2_hours < pEntry2->event2_hours){
			return 0;		
		} else
		
			// Hours are equal, check minutes
			if(pEntry1->event2_minutes > pEntry2->event2_minutes){
				return 1;		
			} else 
			if(pEntry1->event2_minutes < pEntry2->event2_minutes){
				return 0;		
			} else	

				// Minutes are equal, check seconds
				if(pEntry1->event2_seconds > pEntry2->event2_seconds){
					return 1;		
				} else 
				if(pEntry1->event2_seconds < pEntry2->event2_seconds){
					return 0;		
				} else 
					
					// All fields are equal
					return -1;
}

// Compare by IP Address
//
//	Returns:
//		1 - Entry1 is greater than Entry 2
//		0 - Entry 2 is greater than Entry 1
//	   -1 - Entries are equal
//	

int CNetDisplay::CMP_IP(NETDISPLAY_ENTRY *pEntry1, NETDISPLAY_ENTRY *pEntry2)
{

	// Check First Octet (MSB)
	if(*((unsigned int*)pEntry1->ip) > *((unsigned int*)pEntry2->ip)){
		return 1;		
	} else 
	if(*((unsigned int*)pEntry1->ip) < *((unsigned int*)pEntry1->ip)){
		return 0;		
	} else
		
		// Entries are equal
		return -1;
}

void CNetDisplay::SortByEvent1()
{
	unsigned int i;
	
	if(m_numcells < 2){
		return;
	}

	bool unsorted = 1;
	while(unsorted){
		
		// Set unsorted flag to indicate sorted
		// If array is sorted, 
		unsorted = 0;

		// Loop through all entries 
		for(i = 0; i < (m_numcells-1); i++){
			
			// If i > i+1, swap 
			if(1 == CMP_Event1(m_ptr_array[i], m_ptr_array[i+1])){
				SwapEntry(i, i+1);
				unsorted = 1;
			}


		}
	}
}


void CNetDisplay::SortByEvent2()
{
	unsigned int i;

	if(m_numcells < 2){
		return;
	}

	bool unsorted = 1;
	while(unsorted){
		
		// Set unsorted flag to indicate sorted
		// If array is sorted, 
		unsorted = 0;

		// Loop through all entries 
		for(i = 0; i < (m_numcells-1); i++){
			
			// If i > i+1, swap 
			if(1 == CMP_Event2(m_ptr_array[i], m_ptr_array[i+1])){
				SwapEntry(i, i+1);
				unsorted = 1;
			}


		}
	}
}

void CNetDisplay::SortByIP()
{
	unsigned int i;
	
	if(m_numcells < 2){
		return;
	}

	bool unsorted = 1;
	while(unsorted){
		
		// Set unsorted flag to indicate sorted
		// If array is sorted, 
		unsorted = 0;

		// Loop through all entries 
		for(i = 0; i < (m_numcells-1); i++){
			
			// If i > i+1, swap 
			if(1 == CMP_IP(m_ptr_array[i], m_ptr_array[i+1])){
				SwapEntry(i, i+1);
				unsorted = 1;
			}


		}
	}
}

bool CNetDisplay::IsCellSelected()
{
	return (m_selectedcell != -1);//m_selectedcell=-1为FASLE;其它为TRUE
}

bool CNetDisplay::GetMACAddress(unsigned char *mac_ptr)
{
	if(!IsCellSelected()){
		return 0;
	}
	
	// Copy MAC address
	CopyMemory(mac_ptr, m_ptr_array[m_selectedcell]->mac, 6);
	return 1;

}

bool CNetDisplay::GetMACAddress(unsigned int cell_number, unsigned char *mac_ptr)
{
	if(cell_number >= m_numcells){
		return 0;
	}
	
	// Copy MAC address
	CopyMemory(mac_ptr, m_ptr_array[cell_number]->mac, 6);
	return 1;

}

bool CNetDisplay::GetIPAddress(unsigned char *ip_ptr)
{
	if(!IsCellSelected()){
		return 0;
	}
	
	// Copy IP address
	CopyMemory(ip_ptr, m_ptr_array[m_selectedcell]->ip, 4);
	return 1;

}

unsigned short CNetDisplay::GetPort()
{
	return m_ptr_array[m_selectedcell]->port;
}

int CNetDisplay::GetNumCells()
{
	return m_numcells;
}

unsigned char CNetDisplay::GetBaudrate()
{
	return m_ptr_array[m_selectedcell]->baudrate;
}

unsigned char CNetDisplay::GetBaudrateMode()
{
	return m_ptr_array[m_selectedcell]->baudrate_mode;
}

⌨️ 快捷键说明

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