www.pudn.com > IEC104MasterSlave.rar > Master104.cpp, change:2013-04-16,size:3094b


#include "stdafx.h" 
#include "Master104.h" 
#include <time.h> 
#include <stdio.h> 
#include "NAIEC104MasterDlg.h" 
 
void Master104::OnRxAsduMsg(BYTE *msgbuf, unsigned int len ) 
{ 
	OnRxMsg(msgbuf, len); 
	return; 
} 
 
void Master104::OnTxMsg(BYTE *msgbuf, unsigned int len) 
{ 
	CString ch, str; 
	str="Send:"; 
	 
	for(unsigned int n = 0; n < len; n++) 
	{ 
		ch.Format(" %02x",msgbuf[n]); 
		str += ch; 
		if(n>0 && !(n%20)) 
		{ 
			str += "\n"; 
		} 
	} 
//	dlg->m_sendList.AddString(str); 
	dlg->m_revList.AddString(str); 
	 
 
	/*char buf[20]; 
	fprintf(stdout, "\n<--"); 
	TRACE("\n<--"); 
	for(unsigned int n = 0; n < len; n++) 
		{ 
		sprintf(buf, " %02x", msgbuf[n]); 
		fprintf(stdout, buf); 
		TRACE(buf); 
		if(n>0 && !(n%20)) 
			{ 
			fprintf(stdout, "\n"); 
			TRACE("\n"); 
			} 
		} 
	fprintf(stdout, "\n"); 
	TRACE("\n"); 
	fflush(stdout); 
	return;*/ 
} 
 
void Master104::OnRxMsg(BYTE *msgbuf, unsigned int len) 
{ 
	// dlg 
	CString ch, str; 
	str="Rece:"; 
 
	for(unsigned int n = 0; n < len; n++) 
	{ 
		ch.Format(" %02x",msgbuf[n]); 
		str += ch; 
		if(n>0 && !(n%10)) 
		{ 
			str += "\n"; 
		} 
	} 
	dlg->m_revList.AddString(str); 
 
	/*char buf[20]; 
	fprintf(stderr, "\n-->"); 
	TRACE("\n-->"); 
	for(unsigned int n = 0; n < len; n++) 
	{ 
		sprintf(buf, " %02x", msgbuf[n]); 
		fprintf(stderr, buf); 
		TRACE(buf); 
		if(n>0 && !(n%20)) 
		{ 
			fprintf(stderr, "\n"); 
			TRACE("\n"); 
		} 
	} 
	fprintf(stderr, "\n"); 
	TRACE("\n"); 
	fflush(stderr); 
	return;*/ 
} 
 
BOOL Master104::GetIsResponseUTest()  // T1 
{ 
	return dlg->GetUTestIsResponse(); 
} 
 
BOOL Master104::GetIsResponseS()      // K 
{ 
	return dlg->GetRevIisResponseS(); 
} 
 
BOOL Master104::GetIsResponseIFrame() // T2 
{ 
	return dlg->GetIFrameIsResponse(); 
} 
 
void Master104::onUpdateWnd() 
{ 
	dlg->SetButtonState(FALSE); 
} 
 
void Master104::onCloseLink() 
{ 
	dlg->stopLink(); 
} 
 
void Master104::OnErrorMsg(int code, char *msgbuf) 
{ 
	fprintf(stderr, "\n--> Error: "); 
	fprintf(stderr, msgbuf); 
	fprintf(stderr, "\n"); 
	return; 
} 
 
void Master104::OnRxSinglePoint(unsigned int asdu, unsigned long address, 
		bool value, bool valid, bool blocked, FILETIME time) 
{ 
	char buf[150]; 
	SYSTEMTIME stime; 
	FileTimeToSystemTime(&time, &stime); 
	sprintf(buf,"SP_%3.3d: %d\tValid: %d\tBlocked: %d\t%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d.%3.3d\n", 
		address, value, valid, blocked, stime.wDay, 
		stime.wMonth, stime.wYear, stime.wHour, stime.wMinute, 
		stime.wSecond, stime.wMilliseconds); 
	fprintf(stdout, buf); 
	fflush(stdout); 
	return; 
} 
 
void Master104::OnRxMeasuredValue(unsigned int asdu, unsigned long address, 
		float value, bool valid, bool blocked, FILETIME time) 
{ 
	char buf[150]; 
	SYSTEMTIME stime; 
	FileTimeToSystemTime(&time, &stime); 
	sprintf(buf,"MV_%d: %3.2f\tValid: %d\tBlocked: %d\t%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d.%3.3d\n", 
		address, value, valid, blocked, stime.wDay, 
		stime.wMonth, stime.wYear, stime.wHour, stime.wMinute, 
		stime.wSecond, stime.wMilliseconds); 
	fprintf(stdout, buf); 
	fflush(stdout); 
	return; 
}