/*
*******************************************************************************
* Copyright (c) 1996-2000 Digi International Inc., All Rights Reserved        *
*                                                                             *
* This  software  contains  proprietary  and  confidential   information   of *
* Digi International  Inc.   By  accepting  transfer  of this copy, Recipient *
* agrees to retain this software in  confidence,  to  prevent  disclosure  to *
* others,  and  to make no  use of this software other than that for which it *
* was delivered.  This is an unpublished copyright work  Digi   International *
* Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is *
* strictly prohibited.                                                        *
*                                                                             *
* Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc. *
* Confidential  when   combined   with   the   aggregated  modules  for  this *
* product) OBJECT CODE ONLY SOURCE MATERIALS                                  *
*                                                                             *
* (C) COPYRIGHT Digi International Inc. 1996-97                               *
*                                                                             *
* All Rights Reserved                                                         *
*                                                                             *
* US   Government   Users   Restricted   Rights   -   Use,   duplication   or *
* disclosure  restricted by GSA ADP Schedule Contract with Digi International *
* Inc.                                                                        *
*                                                                             *
*******************************************************************************
*/
// StatView.cpp : implementation file
//

/*
	file for all statistic views. Summary windows are handled by DataSource.cpp
	all these views get their data from the a CStatDoc derived document class

*/

#include "stdafx.h"
#include "Diagnostic.h"

#include "StatDoc.h"
#include "StatView.h"

#include "MainFrm.h"
#include "DataSource.h"

#include "afxpriv.h"	// Only for #define WM_COMMANDHELP

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

#define TWO_WIRE	1
#define NRZI		2
#define SDLCCRC		4
#define TxInvert	8

/////////////////////////////////////////////////////////////////////////////
// CStatViewBase

IMPLEMENT_DYNAMIC(CStatViewBase, CFormView)

CStatViewBase::CStatViewBase(UINT passthrough)
	: CFormView(passthrough)
{
	//{{AFX_DATA_INIT(CStatViewBase)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_Highlight = (COLORREF)GetSysColor(COLOR_HIGHLIGHT);
}

CStatViewBase::~CStatViewBase()
{
}

void CStatViewBase::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStatViewBase)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStatViewBase, CFormView)
	//{{AFX_MSG_MAP(CStatViewBase)
	ON_WM_ERASEBKGND()
	ON_WM_RBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CStatViewBase::QuickDump(UINT nID, DWORD Num)
{ 
	HWND hWnd = ::GetDlgItem(m_hWnd, nID);
	if ( IsWindow( hWnd ) )
	{
		DWORD Last = 0;
		m_CtrlMap.Lookup(nID, Last);

		if (Last != Num)
		{
			m_CtrlMap.SetAt(nID, Num);
			::SetWindowText(hWnd, _ultoa(Num, m_Buf, 10));
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CStatViewBase diagnostics

#ifdef _DEBUG
void CStatViewBase::AssertValid() const
{
	CFormView::AssertValid();
}

void CStatViewBase::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CStatDoc* CStatViewBase::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStatDoc)));
	return (CStatDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CStatViewBase message handlers


void CStatViewBase::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
	if (bActivate) {
		CDataSource *pDataSource = GetDocument()->GetDataSource();

// set combo box to datasource used by this view
		CComboBox& box = static_cast<CMainFrame *>(AfxGetMainWnd())->m_DataSourceBox;

		for (short iItem = 0; iItem < box.GetCount(); iItem++)
		{
			CDataSourceControl *pControl = (CDataSourceControl *)box.GetItemDataPtr(iItem);
			ASSERT(pControl != NULL);

			if (pControl->GetDataSource() == pDataSource)
				break;
		}

		ASSERT(iItem < box.GetCount());
		box.SetCurSel(iItem);

// set title of frame so user knows what datasource we are viewing
		CString Title = pDataSource->GetName() +
										CString(" Active Statistics (") +
										GetStatName() + ')';
		
		GetDocument()->SetTitle(Title);
		}
}

void CStatViewBase::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	ClientToScreen(&point);
	GetParentFrame()->SendMessage(WM_RBUTTONUP, nFlags, (point.y << 16) + point.x);
}

void CombineRectRgn(CWnd *UpdateWnd, HWND hWnd, CRgn& UpdateRgn)
{
	CRect rct;

	GetWindowRect(hWnd, rct);
	UpdateWnd->ScreenToClient(rct);
	
	CRgn rgn;
	rgn.CreateRectRgnIndirect(rct);

	UpdateRgn.CombineRgn(&UpdateRgn, &rgn, RGN_OR);
}

void CStatViewBase::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	DWORD style = GetParentFrame()->GetStyle();
	if ((style & WS_MAXIMIZE) == 0 && (style & WS_MINIMIZE) == 0)
		ResizeParentToFit(FALSE);

	m_UpdateRgn.CreateRectRgn(0, 0, 0, 0);
	CombineRectRgn(this, ::GetDlgItem(m_hWnd, IDC_TxFrame), m_UpdateRgn);
	CombineRectRgn(this, ::GetDlgItem(m_hWnd, IDC_RxFrame), m_UpdateRgn);

	OnUpdate(NULL, uavUpdateStats, NULL);
}

void CStatViewBase::PercentFrame(HWND hFrame, DWORD data, CDC *dc)
{
	if (!IsWindow(hFrame))
		return;

	CRect rect;

	::GetWindowRect(hFrame, rect);
	ScreenToClient(rect);
	rect.DeflateRect(2, 2);

	if ((BYTE)::GetVersion() >= 4)
		rect.DeflateRect(1, 1);

	int oldright = rect.right;
	rect.right = rect.left + __min((DWORD)rect.Width(), round(rect.Width() * data / 100.0));

	dc->FillSolidRect(rect, m_Highlight);
	rect.left = rect.right;
	rect.right = oldright;
	dc->FillSolidRect(rect, RGB(255, 255, 255));
}

void CStatViewBase::DoWANStats()
{
	CStatDoc *pDoc = GetDocument();

	QuickDump(IDC_TxGood, pDoc->m_AverageFPS[0]);
	QuickDump(IDC_RxGood, pDoc->m_AverageFPS[1]);
	QuickDump(IDC_TxBytes, pDoc->m_AverageBPS[0]);
	QuickDump(IDC_RxBytes, pDoc->m_AverageBPS[1]);

	QuickDump(IDC_TxFPS, pDoc->m_FPS[0]);
	QuickDump(IDC_RxFPS, pDoc->m_FPS[1]);
	QuickDump(IDC_TxBPS, pDoc->m_BPS[0]);
	QuickDump(IDC_RxBPS, pDoc->m_BPS[1]);
	QuickDump(IDC_TxLU, pDoc->m_LU[0]);
	QuickDump(IDC_RxLU, pDoc->m_LU[1]);

	const CWAN& WanStats = pDoc->GetWAN();

	QuickDump(IDC_RxAbort, WanStats->hc_rxabort);
	QuickDump(IDC_RxCRC, WanStats->hc_rxcrc);
	QuickDump(IDC_RxBitErr, WanStats->hc_rxbiterr);
	QuickDump(IDC_RxOFlow, WanStats->hc_rxoflow);
	QuickDump(IDC_RxORun, WanStats->hc_rxorun);
	QuickDump(IDC_NoClock, WanStats->hc_noclock);

	CDC *pDC = GetDC();

	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], pDC);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], pDC);

	ReleaseDC(pDC);
}


void CStatViewBase::DoWANLineStatus()
{
	CStatDoc *pDoc = GetDocument();

	const CWANLINESTATUS& LineStatus = pDoc->GetLineStatus();

	CString LineState ;
	if (LineStatus->wan_linestatus_linestatus & WAN_LINESTATUS_FLAGS)
		LineState = "Flags" ;
	else if (LineStatus->wan_linestatus_linestatus & WAN_LINESTATUS_IDLE)
		LineState = "Idle" ;
	else if (LineStatus->wan_linestatus_linestatus & WAN_LINESTATUS_AVAILABLE)
		LineState = "Not In Use" ;
	else
		LineState = "Active" ;
	QuickDumpText (IDC_LineStatus, LineState) ;

	if (!(LineStatus->wan_linestatus_linestatus & WAN_LINESTATUS_AVAILABLE))
	{
		CString LineOptions ;
		if (LineStatus->wan_linestatus_options & TWO_WIRE)
			LineOptions = "2Wire " ;
		else
			LineOptions = "4Wire " ;

		if (LineStatus->wan_linestatus_options & NRZI)
			LineOptions += "NRZI" ;
		else
			LineOptions += "NRZ" ;

		if (LineStatus->wan_linestatus_options & TxInvert)
			LineOptions += " Tx Invert" ;
		QuickDumpText (IDC_LineOptions, LineOptions) ;

		QuickDump (IDC_ConfigBaud, LineStatus->wan_linestatus_config_baud) ;
		QuickDump (IDC_MaxFrame, LineStatus->wan_linestatus_maxframe) ;
		QuickDump (IDC_LineSpeed, LineStatus->wan_linestatus_linespeed) ;

		CString Duplex ;
		if (LineStatus->wan_linestatus_hdplx)
			Duplex = "Half" ;
		else
			Duplex = "Full" ;
		QuickDumpText (IDC_HalfDuplex, Duplex) ;
	
		CString CableType ;
		switch (LineStatus->wan_linestatus_cable_id)
		{
			case WAN_X21:			CableType = "V.11" ;			break;
			case WAN_V28:			CableType = "RS-232" ;			break;
			case WAN_V35:			CableType = "V.35" ;			break;
			case WAN_V36:			CableType = "V.36" ;			break;
			case WAN_CSUDSU:		CableType = "CSU/DSU" ;			break;
			case WAN_SW56:			CableType = "SWitched56" ;		break;
			case WAN_V35RS232:		CableType = "V.35 or RS232" ;	break;
			case WAN_530:			CableType = "EIA-530" ;			break;
			case WAN_EIA530:		CableType = "EIA-530" ;			break;
			case WAN_EIA449:		CableType = "EIA-449" ;			break;
			case WAN_LOOPBACK:		CableType = "Loopback" ;		break;
			case WAN_NO_CABLE:		CableType = "None" ;			break;

			// cPCI cable types
			case WAN_CPCI_X21:		CableType = "V.11" ;			break;
			case WAN_CPCI_V28:		CableType = "RS-232" ;			break;
			case WAN_CPCI_V35:		CableType = "V.35" ;			break;
			case WAN_CPCI_V36:		CableType = "V.36" ;			break;
			case WAN_CPCI_EIA530:	CableType = "EIA-530" ;			break;
			case WAN_CPCI_EIA449:	CableType = "EIA-449" ;			break;
			case WAN_LOOPBACK_GOOD:	CableType = "Loopback Good" ;	break;
			case WAN_LOOPBACK_BAD:	CableType = "Loopback Bad" ;	break;
			default:				CableType = "Unknown" ;			break;
		}
		QuickDumpText (IDC_CableType, CableType) ;

		DWORD	mask = 1 ;
		DWORD	signals = LineStatus->wan_linestatus_modem ;
		CString Signals ;
		while (signals)
		{
			switch((signals & mask))
			{
			case W_DTR:
				Signals += "DTR" ;
				signals &= ~W_DTR;
				if (signals)
					Signals += ", " ;
				break;

			case W_RTS:
				Signals += "RTS" ;
				signals &= ~W_RTS;
				if (signals)
					Signals += ", " ;
				break;

			case W_CTS:
				Signals += "CTS" ;
				signals &= ~W_CTS;
				if (signals)
					Signals += ", " ;
				break;

			case W_DSR:
				Signals += "DSR" ;
				signals &= ~W_DSR;
				if (signals)
					Signals += ", " ;
				break;

			case W_DCD:
				Signals += "DCD" ;
				signals &= ~W_DCD;
				if (signals)
					Signals += ", " ;
				break;

			case W_MODE:
				Signals += "MODE" ;
				signals &= ~W_MODE;
				if (signals)
					Signals += ", " ;
				break;

			case W_RI:
				Signals += "RI" ;
				signals &= ~W_RI;
				if (signals)
					Signals += ", " ;
				break;

			case 0:
				break;

			default:
				Signals += "Unknown" ;
				signals = 0;
				break;
			}

			mask = mask << 1;
		}
		QuickDumpText (IDC_ModemSignals, Signals) ;

	}
	else
	{
		CString strNotApplicable = "N/A";

		QuickDump (IDC_ConfigBaud, 0) ;
		QuickDump (IDC_MaxFrame, 0) ;
		QuickDump (IDC_LineSpeed, 0) ;
		QuickDumpText (IDC_LineOptions, strNotApplicable) ;
		QuickDumpText (IDC_HalfDuplex, strNotApplicable) ;
		QuickDumpText (IDC_CableType, strNotApplicable) ;
		QuickDumpText (IDC_ModemSignals, strNotApplicable) ;
	}

}


/////////////////////////////////////////////////////////////////////////////
// CFRStatView

IMPLEMENT_DYNCREATE(CFRStatView, CStatViewBase)

CFRStatView::CFRStatView()
	: CStatViewBase(CFRStatView::IDD)
{
	//{{AFX_DATA_INIT(CFRStatView)
	//}}AFX_DATA_INIT
}

CFRStatView::~CFRStatView()
{
}

void CFRStatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFRStatView)
	DDX_Control(pDX, IDC_DLCI, m_DLCIBox);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFRStatView, CStatViewBase)
	//{{AFX_MSG_MAP(CFRStatView)
	ON_CBN_SELCHANGE(IDC_DLCI, OnSelchangeDlci)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFRStatView diagnostics

#ifdef _DEBUG
void CFRStatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CFRStatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFRStatView message handlers

void CFRStatView::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	const CDataSource *ds = GetDocument()->GetDataSource();

	m_DLCIBox.ResetContent();
	for (short i = 0; i < ds->GetNumCircuits(); i++) {
		CString txt;

		txt.Format("%lu", ds->GetCircuitNum(i));
		int index = m_DLCIBox.AddString(txt);
		m_DLCIBox.SetItemData(index, i);
		}
	m_DLCIBox.SetCurSel(0);
}

void CFRStatView::OnUpdate(CView*, LPARAM lHint, CObject *pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CFRStatDoc *pDoc = dynamic_cast<CFRStatDoc *>(GetDocument());

		const CFR_LINK_STATS& LinkStats = pDoc->GetLinkStats();

		QuickDump(IDC_BECNRcv, LinkStats->rcvbecns);
		QuickDump(IDC_FECNRcv, LinkStats->rcvfecns);

		const CFR_LINK_ERRORS& LinkErrors = pDoc->GetLinkErrors();

		QuickDump(IDC_IvdFrmRvc, LinkErrors->rcvframe_inv);
		QuickDump(IDC_TooSrt2, LinkErrors->rcvinv_short);
		QuickDump(IDC_TooLong2, LinkErrors->rcvinv_long);
		QuickDump(IDC_IvdDLCI2, LinkErrors->rcvinv_dlci);
		QuickDump(IDC_UnknownDLCI2, LinkErrors->rcvunk_dlci);

		const CFR_LMI_STATS& LMIStats = pDoc->GetLMIStats();

		QuickDump(IDC_LMISETx, LMIStats->lmi_total_stat_enqs);
		QuickDump(IDC_LMISMTX, LMIStats->lmi_total_status);
		QuickDump(IDC_LMIUSTx, LMIStats->lmi_total_updates);
	
		DWORD temp =	LMIStats->lmi_inv_msg_rcvd + LMIStats->lmi_no_ie_rep_type +
									LMIStats->lmi_no_ie_keep_alive + LMIStats->lmi_lost_seq_num +
									LMIStats->lmi_stat_resp_timeout + LMIStats->lmi_unsupp_ie_msg +
									LMIStats->lmi_unexpected_pvc_num + LMIStats->lmi_unexpected_pvc_stat_msg;
		QuickDump(IDC_LMIErrors, temp);

		DoWANStats();

		DoWANLineStatus();

		int index = m_DLCIBox.GetCurSel();

		if (index > -1)
		{
			index = m_DLCIBox.GetItemData(index);

			const CFR_PROTOCOL_ERRORS& ProtocolErrors = pDoc->GetProtocolErrors(index);

			QuickDump(IDC_UnkwnProto, ProtocolErrors->rcv_unkprot);
			QuickDump(IDC_UnkwnFrm2, ProtocolErrors->rcv_unkframe);
			QuickDump(IDC_LostFrm, ProtocolErrors->rcv_lostframe);
			QuickDump(IDC_UnkwnOrgCode, ProtocolErrors->rcv_unkorg);

			const CFR_INJ_MANG& InjManager = pDoc->GetInjManager(index);
	
			QuickDump(IDC_InjDropped, InjManager->InjFramesDropped);
			QuickDump(IDC_InjExcess, InjManager->InjExcessFrames);
			QuickDump(IDC_InjHold2, InjManager->InjHoldFrames);
			QuickDump(IDC_InjNormal, InjManager->InjNormalFrames);
		}
	}

	if (lHint & uavGetUpdateCircuits)
	{
		CDWordArray *pCircuits = (CDWordArray *)pHint;

		int index = m_DLCIBox.GetCurSel();

		if (index > -1)
			pCircuits->SetAt(m_DLCIBox.GetItemData(index), 1);
	}
}

void CFRStatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CStatDoc *pDoc = GetDocument();
	
	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], &dc);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], &dc);
	// Do not call CStatViewBase::OnPaint() for painting messages
}

void CFRStatView::OnSelchangeDlci() 
{
	// TODO: Add your control notification handler code here
	((CFRStatDoc *)GetDocument())->SelChange(m_DLCIBox.GetCurSel());
}

//------------------------------------------------------------ MLZ 7/20/98 {
/////////////////////////////////////////////////////////////////////////////
// CHlcStatViewBase

IMPLEMENT_DYNAMIC(CHlcStatViewBase, CStatViewBase)

CHlcStatViewBase::CHlcStatViewBase(UINT PassThrough)
	: CStatViewBase(PassThrough)
{
	//{{AFX_DATA_INIT(CHlcStatViewBase)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CHlcStatViewBase::~CHlcStatViewBase()
{
}

void CHlcStatViewBase::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHlcStatViewBase)
	DDX_Control(pDX, IDC_Modem, m_ModemBox);
	DDX_Control(pDX, IDC_LIST_ISDN, m_ISDNList);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHlcStatViewBase, CStatViewBase)
	//{{AFX_MSG_MAP(CHlcStatViewBase)
	ON_CBN_SELCHANGE(IDC_Modem, OnSelchangeModem)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHlcStatViewBase diagnostics

#ifdef _DEBUG
void CHlcStatViewBase::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CHlcStatViewBase::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHlcStatViewBase message handlers

void CHlcStatViewBase::OnSelchangeModem() 
{
	// TODO: Add your control notification handler code here
	((CHlcStatDoc *)GetDocument())->SelChange(m_ModemBox.GetCurSel());
}

void CHlcStatViewBase::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();
	const CDataSource *ds = GetDocument()->GetDataSource();

	m_ModemBox.ResetContent();
	for (short i = 0; i < ds->GetNumCircuits(); i++) 
	{
		CString txt;
		txt.Format("%d", ds->GetCircuitNum(i) + 1);
		int index = m_ModemBox.AddString(txt);
		m_ModemBox.SetItemData(index, i);
	}
	m_ModemBox.SetCurSel(0);

	m_ISDNList.InsertColumn(0, "Index", LVCFMT_LEFT, 40, -1);
	m_ISDNList.InsertColumn(1, "Directory number", LVCFMT_LEFT, 100, -1);
	m_ISDNList.InsertColumn(2, "SubAddress", LVCFMT_LEFT, 100, -1);
	m_ISDNList.InsertColumn(3, "SPID", LVCFMT_LEFT, 110, -1);
	
	CString Index;
	for(int z = 0; z < MSN_MAX; z++){
		Index.Format(_T("%d"), (z + 1));
		m_ISDNList.InsertItem(z, (LPCTSTR)Index);
	}
}

void CHlcStatViewBase::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CHlcStatDoc *pDoc = dynamic_cast<CHlcStatDoc *>(GetDocument());
		
		{
			// Ds1 Status
			const CDS1_STATUS& Ds1Status = pDoc->GetDs1Status();
			CString Signal;
			if ( Ds1Status->rx_special )
			{
				if ( Ds1Status->rx_special & DS1_LOS )
					Signal += " LOS";	// Loss Of Signal
				if ( Ds1Status->rx_special & DS1_LFA )
					Signal += " LFA";	// Loss of Framing Alarm
				if ( Ds1Status->rx_special & DS1_AIS )
					Signal += " AIS";	// All Ones
				if ( Ds1Status->rx_special & DS1_RFA )
					Signal += " RFA";	// Remote Facilities Alarm
			}
			else
				Signal = "None";
			QuickDumpText( IDC_Signal, Signal );

			CString Alarms;
			switch ( Ds1Status->alarm )
			{
				case DS1_RED_ALARM:		Alarms = "Red";		break;
				case DS1_BLUE_ALARM:		Alarms = "Blue";		break;
				case DS1_YELLOW_ALARM:	Alarms = "Yellow";	break;
				case DS1_NO_ALARM:	
				default:						Alarms = "None";		break;
			}
			QuickDumpText( IDC_Alarms, Alarms );


			CString Loopback;
			switch ( Ds1Status->loopback )
			{
				case DS1_PAYLOAD_LOOP:	Loopback = "Payload";	break;
				case DS1_LINE_LOOP:		Loopback = "Line";		break;
				case DS1_LOCAL_LOOP:		Loopback = "Local";		break;
				case DS1_NO_LOOP:	
				default:						Loopback = "None";		break;
			}
			QuickDumpText( IDC_Loopback, Loopback );
		}
		{
			// Ds1 Extended Status
			const CDS1_EXT_STATUS& Ds1ExtStatus = pDoc->GetDs1ExtStatus();
			QuickDump( IDC_line_code_violations, Ds1ExtStatus->line_code_violations );
			QuickDump( IDC_crc_error_count, Ds1ExtStatus->crc_error_count );
		}

		// BRI Status
		const CBRI_STATUS& BriStatus = pDoc->GetBriStatus();
		{
			CString Power;
			switch ( BriStatus->power )
			{
				case BRI_POWER_OFF:		Power = "Off";			break;
				case BRI_POWER_ON:   	Power = "On";			break;
				case BRI_POWER_UNKNOWN:
				default:						Power = "Unknown";	break;
			}
			QuickDumpText( IDC_power, Power );
		}
		{
			CString Activation;
			switch ( BriStatus->activation_state )
			{
				// TE states
				case BRI_ACT_F1:	Activation = "F1 (Inactive)";				break;
				case BRI_ACT_F2:	Activation = "F2 (Sensing)";				break;
				case BRI_ACT_F3:	Activation = "F3 (Deactivated)";			break;
				case BRI_ACT_F4:	Activation = "F4 (Awaiting signal)";	break;
				case BRI_ACT_F5:	Activation = "F5 (Identifying input)";	break;
				case BRI_ACT_F6:	Activation = "F6 (Synchronized)";		break;
				case BRI_ACT_F7:	Activation = "F7 (Activated)";			break;
				case BRI_ACT_F8:	Activation = "F8 (Lost Framing)";		break;

				// NT states
//					case BRI_ACT_G1:	Activation = "G1 (Deactivated)";			break;
//					case BRI_ACT_G2:	Activation = "G2 (Pending activation)";break;
//					case BRI_ACT_G3:	Activation = "G3 (Activated)";			break;
//					case BRI_ACT_G4:	Activation = "G4 (Pending deactivation)";break;

				default:				Activation = "Unknown";						break;
			}
			QuickDumpText( IDC_activation_state, Activation );
		}
		{
			CString Info;
			switch ( BriStatus->rx_info_state )
			{
				case BRI_INFO_0:	Info = "0 (No signal)";							break;
				case BRI_INFO_1:	Info = "1 (Signal with pattern)";			break;
				case BRI_INFO_2:	Info = "2 (Frame with zeroed data)";		break;
				case BRI_INFO_3:	Info = "3 (Frame with operational data)";	break;
				case BRI_INFO_4:	Info = "4 (Frame with operational data)";	break;
				case BRI_INFO_5:
				default:          Info = "Unknown";
			}
			QuickDumpText( IDC_rx_information_state, Info );
		}
		{
			CString Info;
			switch ( BriStatus->tx_info_state )
			{
				case BRI_INFO_0:	Info = "0 (No signal)";							break;
				case BRI_INFO_1:	Info = "1 (Signal with pattern)";			break;
				case BRI_INFO_2:	Info = "2 (Frame with zeroed data)";		break;
				case BRI_INFO_3:	Info = "3 (Frame with operational data)";	break;
				case BRI_INFO_4:	Info = "4 (Frame with operational data)";	break;
				case BRI_INFO_5:
				default:          Info = "Unknown";
			}
			QuickDumpText( IDC_tx_information_state, Info );
		}
		QuickDump( IDC_loss_of_sync, BriStatus->loss_of_sync );
		QuickDump( IDC_collisions, BriStatus->collisions );

		/* ISDN layer 2 info (tei states) */
		const CDCHAN_EXT_STATUS& DChanExtStatus = pDoc->GetDChanExtStatus();
		{
			CString TEIState;
			for(unsigned int i = 0; i < DChanExtStatus->tei_count; i++){
				switch(DChanExtStatus->tei_state[i]){
					case DCHAN_TEI_OFF:					TEIState = "TEI off";							break;
					case DCHAN_TEI_UNASSIGNED:			TEIState = "TEI unassigned";					break;
					case DCHAN_TEI_AWAITING_ASS:		TEIState = "TEI awaiting assignement";			break;
					case DCHAN_TEI_AWAITING_EST:		TEIState = "TEI awaiting establishment";		break;
					case DCHAN_TEI_ASSIGNED:			TEIState = "TEI assigned";						break;
					case DCHAN_MULTIFRAME_AWAITING_EST:	TEIState = "multiframe awaiting establishment";	break;
					case DCHAN_MULTIFRAME_EST:			TEIState = "multiframe establishment";			break;
					case DCHAN_MULTIFRAME_AWAITING_REL:	TEIState = "multiframe awaiting recovery";		break;
					case DCHAN_MULTIFRAME_TIMER_REC:	TEIState = "multiframe timer recovery";			break;
					default:							TEIState = "Unknown";							break;
				}
				if(i == 0)
					QuickDumpText(IDC_TEI_state_1, TEIState);
				else
					QuickDumpText(IDC_TEI_state_2, TEIState);
			}
		}

		/* ISDN layer 3 info, switch type and Directory/subaddress/spids */
		{
			CString SpidState;
			for(unsigned int i = 0; i < BriStatus->spid_count; i++){	
				switch(BriStatus->spid_state[i]){ 
					case BRI_SPID_UNUSED:             SpidState = "SPID unused";													   break;
					case BRI_SPID_IDLE:               SpidState = "Negotiation pending";											   break;
					case BRI_SPID_SENT_INFO:          SpidState = "Info Sent";														   break; 
					case BRI_SPID_RECV_INFO:          SpidState = "SPID negotiation successful";									   break;
					case BRI_SPID_BAD_INFO:           SpidState = "SPID negotiation failed due to rejected SPID";					   break;
					case BRI_SPID_WAITING_FOR_DL:     SpidState = "SPID waiting for DL";											   break;
					case BRI_SPID_NEGOTIATE:          SpidState = "SPID negotiation in progress";									   break;
					case BRI_SPID_NEGOTIATE_FAILED:	  SpidState = "SPID negotiation failed due to excessive renegotiation attempts";   break;
					default:						  SpidState = "Unknown";														   break;
				}
				if(i == 0)
					QuickDumpText(IDC_SPID_state_1, SpidState);
				else
					QuickDumpText(IDC_SPID_state_2, SpidState);
			}
		}

		const CBRI_CONFIG& BriConfig = pDoc->GetBriConfig();
		{
			CString SwitchProtocol;
			switch(BriConfig->switch_type){
				case BRI_NONE:		SwitchProtocol = "None";				break;
				case BRI_NI1:		SwitchProtocol = "NI1";					break;
				case BRI_5ESS:		SwitchProtocol = "5ESS";				break;
				case BRI_DMS100:	SwitchProtocol = "DMS100";				break;
				case BRI_ETSI:		SwitchProtocol = "ETSI (Euro ISDN)";	break;
				case BRI_JAPAN:		SwitchProtocol = "Japan (INS64)";		break;
				default:			SwitchProtocol = "Unknown";				break;
			}
			QuickDumpText(IDC_ISDN_protocol, SwitchProtocol);

			for(unsigned int i = 0; i < MSN_MAX; i++){
				m_ISDNList.SetItemText(i, idISDN_DirectoryNumber, LPCSTR(BriConfig->directory[i].number));
				m_ISDNList.SetItemText(i, idISDN_SubAddress, LPCSTR(BriConfig->directory[i].sub_address));
				m_ISDNList.SetItemText(i, idISDN_Spid, LPCSTR(BriConfig->directory[i].spid));
			}
		}
		
		// Modem stats
		if ( m_ModemBox.GetCurSel() > -1 )
		{
			// Get the selected modem
			int index = m_ModemBox.GetItemData(m_ModemBox.GetCurSel());
			
			{
				// Standard modem stuff
				const CMODEM_STATUS& ModemStatus = pDoc->GetModemStatus(index);
				QuickDump( IDC_connect_time, ModemStatus->connect_time );

				QuickDump( IDC_dte_tx_rate, ModemStatus->dte_tx_rate );
				QuickDump( IDC_dte_rx_rate, ModemStatus->dte_rx_rate );

				QuickDump( IDC_initial_tx_rate, ModemStatus->initial_tx_rate );
				QuickDump( IDC_initial_rx_rate, ModemStatus->initial_rx_rate );

				QuickDump( IDC_current_tx_rate, ModemStatus->current_tx_rate );
				QuickDump( IDC_current_rx_rate, ModemStatus->current_rx_rate );

				{
					// Modulation standard
					CString Modulation;
					switch ( ModemStatus->modulation )
					{
						case 0:	Modulation = "None";			break;
						case 1:	Modulation = "Bell 103";	break;
						case 2:	Modulation = "Bell 212A";	break;
						case 3:	Modulation = "V.21";			break;
						case 4:	Modulation = "V.22";			break;
						case 5:	Modulation = "V.22bis";		break;
						case 6:	Modulation = "V.23";			break;
						case 7:	Modulation = "V.24bis";		break;
						case 8:	Modulation = "V.32";			break;
						case 9:	Modulation = "V.32bis";		break;
						case 10:	Modulation = "V.34";			break;
						case 11:	Modulation = "V.34bis";		break;
						case 12:	Modulation = "K56Flex";		break;
						case 13:	Modulation = "V.90";			break;
						case 32:	Modulation = "V.17";			break;
						case 33:	Modulation = "V.21ch2";		break;
						case 34:	Modulation = "V.27ter";		break;
						case 35:	Modulation = "V.29";			break;
						default:
							Modulation = "Unknown";
							break;
					}
					QuickDumpText( IDC_modulation, Modulation );
				}

				{
					// Compression standard
					CString Compression;
					switch ( ModemStatus->compression )
					{
						case 1:	Compression = "None";	break;
						case 4:	Compression = "MNP5";	break;
						case 5:	Compression = "V42bis";	break;
						default:
							Compression = "Unknown";
							break;
					}
					QuickDumpText( IDC_compression, Compression );
				}

				{
					// ErrorCorrection standard
					CString ErrorCorrection;
					switch ( ModemStatus->error_correction )
					{
						case 1:	ErrorCorrection = "None";	break;
						case 2:	ErrorCorrection = "LAPM";	break;
						case 3:	ErrorCorrection = "MNP2";	break;
						case 4:	ErrorCorrection = "MNP3";	break;
						case 5:	ErrorCorrection = "MNP4";	break;
						case 6:	ErrorCorrection = "V42";	break;
						default:
							ErrorCorrection = "Unknown";
							break;
					}
					QuickDumpText( IDC_error_correction, ErrorCorrection );
				}

				{
					// LastDisconnect Reason Code
					CString Reason;
					switch ( ModemStatus->last_disconnect )
					{
						case MODEM_REASON_OMC_NORMAL_LOCAL:		Reason = "Local disconnect normal";	break;
						case MODEM_REASON_OMC_NORMAL_REMOTE:	Reason = "Remote disconnect normal";	break;
						case MODEM_REASON_OMC_INACTIVITY:		Reason = "Inactivity timeout";	break;
						case MODEM_REASON_OMC_CIRCUIT_LOSS:		Reason = "Circuit lost during connection";	break;
						case MODEM_REASON_OMC_HALTED:				Reason = "Abnormal locally initiated disconnect";	break;
						case MODEM_REASON_OMC_DM_TIMEOUT:		Reason = "Data modulation connect timeout";	break;
						case MODEM_REASON_OMC_DP_TIMEOUT:		Reason = "Data protocol connect timeout";	break;
						case MODEM_REASON_OMC_IMPROPER_CONTROL:Reason = "Illegal state change occurred";	break;
						case MODEM_REASON_OMC_FAX_DETECTED:		Reason = "Fax detected while fax not enabled";	break;
						case MODEM_REASON_OMC_DM_CLEARDOWN:		Reason = "Abnormal remote disconnect at data modulation layer";	break;
						case MODEM_REASON_OMC_CALL_FUNC_UNSUPP:Reason = "Incompatible V.8 or V.8bis call functions";	break;
						case MODEM_REASON_OMC_T30_SESSION:		Reason = "T.30 session initiated and terminated";	break;

						case MODEM_REASON_DM_CARRIER_LOSS:		Reason = "Carrier loss after call established";	break;
						case MODEM_REASON_DM_NEG_REQ_FAIL:		Reason = "Unable to negotiate required modulation feature";	break;
						case MODEM_REASON_DM_GEN_REQ_FAIL:		Reason = "Required modulation feature not maintained";	break;
						case MODEM_REASON_DM_PROTOCOL_FAIL:		Reason = "Unrecoverable modulation protocol violation";	break;
						case MODEM_REASON_DM_GENERAL:				Reason = "Generic modulation protocol disconnect";	break;

						case MODEM_REASON_DP_NEG_REQ_FAIL:		Reason = "Unable to negotiate required data protocol feature";	break;
						case MODEM_REASON_DP_GEN_REQ_FAIL:		Reason = "Required data protocol feature not maintained";	break;
						case MODEM_REASON_DP_PROTOCOL_FAIL:		Reason = "Unrecoverable data protocol violation";	break;
						case MODEM_REASON_DP_COMP_PROTOCOL_FAIL:	Reason = "Unrecoverable V.42bis protocol violation";break;
						case MODEM_REASON_DP_GENERAL:				Reason = "Generic data protocol disconnect";	break;
						case MODEM_REASON_DP_NO_RESPONSE:		Reason = "Remote protocol not responding";	break;
						case MODEM_REASON_DP_STARTUP_FAIL:		Reason = "Data protocol failed to start";	break;
						case MODEM_REASON_DP_TIMEOUT:				Reason = "Data protocol startup timeout";	break;

						case MODEM_REASON_DIAL_NO_DIALTONE:		Reason = "No dialtone";	break;
						case MODEM_REASON_DIAL_BUSY:				Reason = "Busy";			break;
						case MODEM_REASON_DIAL_NO_ANSWER:		Reason = "No answer";	break;
						case MODEM_REASON_DIAL_DELAYED:			Reason = "Delayed";		break;
						case MODEM_REASON_DIAL_BLACKLISTED:		Reason = "Blacklisted";	break;
						case MODEM_REASON_DIAL_NO_CARRIER:		Reason = "No carrier";	break;

						default:											Reason = "Unknown";		break;
					}	
					QuickDumpText( IDC_last_disconnect, Reason );
				}
			}

			{
#if 0
				// "Advanced" modem stuff
				const CMODEM_EXT_STATUS& ExtStatus = pDoc->GetModemExtStatus(index);
				QuickDump( IDC_estimated_snr, ExtStatus->estimated_snr );
				QuickDump( IDC_estimated_rtt, ExtStatus->estimated_rtt );
				QuickDump( IDC_tx_signal_level, ExtStatus->tx_signal_level );
				QuickDump( IDC_rx_signal_level, ExtStatus->rx_signal_level );
				QuickDump( IDC_local_retrains, ExtStatus->local_retrains );
				QuickDump( IDC_remote_retrains, ExtStatus->remote_retrains );
				QuickDump( IDC_manual_retrains, ExtStatus->manual_retrains );
				QuickDump( IDC_renegotiate_count, 0 );
				QuickDump( IDC_mean_square_error, 0 );
				QuickDump( IDC_trellis_size, 0 );
				QuickDump( IDC_block_errors, 0 );
				QuickDump( IDC_resends, 0 );
				QuickDump( IDC_dictionary_size, ExtStatus->dictionary_size );
				QuickDump( IDC_max_string_length, ExtStatus->max_string_length );
#endif
			}
		}
	}

	if (lHint & uavGetUpdateCircuits)
	{
		CDWordArray *pCircuits = (CDWordArray *)pHint;

		int index = m_ModemBox.GetCurSel();

		if (index > -1)
			pCircuits->SetAt(m_ModemBox.GetItemData(index), 1);
	}
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CPriStatView

IMPLEMENT_DYNCREATE(CPriStatView, CHlcStatViewBase)

CPriStatView::CPriStatView()
	: CHlcStatViewBase(CPriStatView::IDD)
{
	//{{AFX_DATA_INIT(CPriStatView)
	//}}AFX_DATA_INIT
}

CPriStatView::~CPriStatView()
{
}

BEGIN_MESSAGE_MAP(CPriStatView, CHlcStatViewBase)
	//{{AFX_MSG_MAP(CPriStatView)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()


LRESULT CPriStatView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		lParam = HID_BASE_RESOURCE + IDD_PriStats;
	return GetParentFrame()->SendMessage(WM_COMMANDHELP, wParam, lParam);
}

/////////////////////////////////////////////////////////////////////////////
// CPriStatView diagnostics

#ifdef _DEBUG
void CPriStatView::AssertValid() const
{
	CHlcStatViewBase::AssertValid();
}

void CPriStatView::Dump(CDumpContext& dc) const
{
	CHlcStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBriStatView

IMPLEMENT_DYNCREATE(CBriStatView, CHlcStatViewBase)

CBriStatView::CBriStatView()
	: CHlcStatViewBase(CBriStatView::IDD)
{
	//{{AFX_DATA_INIT(CBriStatView)
	//}}AFX_DATA_INIT
}

CBriStatView::~CBriStatView()
{
}

BEGIN_MESSAGE_MAP(CBriStatView, CHlcStatViewBase)
	//{{AFX_MSG_MAP(CBriStatView)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()


LRESULT CBriStatView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		lParam = HID_BASE_RESOURCE + IDD_BriStats;
	
	return GetParentFrame()->SendMessage(WM_COMMANDHELP, wParam, lParam);
}

/////////////////////////////////////////////////////////////////////////////
// CBriStatView diagnostics

#ifdef _DEBUG
void CBriStatView::AssertValid() const
{
	CHlcStatViewBase::AssertValid();
}

void CBriStatView::Dump(CDumpContext& dc) const
{
	CHlcStatViewBase::Dump(dc);
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CModemStatView

IMPLEMENT_DYNCREATE(CModemStatView, CHlcStatViewBase)

CModemStatView::CModemStatView()
	: CHlcStatViewBase(CModemStatView::IDD)
{
	//{{AFX_DATA_INIT(CModemStatView)
	//}}AFX_DATA_INIT
}

CModemStatView::~CModemStatView()
{
}

BEGIN_MESSAGE_MAP(CModemStatView, CHlcStatViewBase)
	//{{AFX_MSG_MAP(CModemStatView)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()


LRESULT CModemStatView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		lParam = HID_BASE_RESOURCE + IDD_ModemStats;

	return GetParentFrame()->SendMessage(WM_COMMANDHELP, wParam, lParam);
}

/////////////////////////////////////////////////////////////////////////////
// CModemStatView diagnostics

#ifdef _DEBUG
void CModemStatView::AssertValid() const
{
	CHlcStatViewBase::AssertValid();
}

void CModemStatView::Dump(CDumpContext& dc) const
{
	CHlcStatViewBase::Dump(dc);
}
#endif //_DEBUG


//------------------------------------------------------------ MLZ 7/20/98 }

/////////////////////////////////////////////////////////////////////////////
// CSnaStatView

IMPLEMENT_DYNCREATE(CSnaStatView, CStatViewBase)

CSnaStatView::CSnaStatView()
	: CStatViewBase(CSnaStatView::IDD)
{
	//{{AFX_DATA_INIT(CSnaStatView)
	//}}AFX_DATA_INIT
}

CSnaStatView::~CSnaStatView()
{
}

void CSnaStatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSnaStatView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSnaStatView, CStatViewBase)
	//{{AFX_MSG_MAP(CSnaStatView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSnaStatView diagnostics

#ifdef _DEBUG
void CSnaStatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CSnaStatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSnaStatView message handlers

void CSnaStatView::OnUpdate(CView*, LPARAM lHint, CObject *pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CSnaStatDoc *pDoc = dynamic_cast<CSnaStatDoc *>(GetDocument());

		//  Get the standard WAN Statistics
		DoWANStats();

		DoWANLineStatus();

		const CWANLINESTATUS& LineStatus = pDoc->GetLineStatus();

		QuickDump (IDC_RxAbort, LineStatus->wan_linestatus_stats.hc_rxabort);
		QuickDump (IDC_RxCRC, LineStatus->wan_linestatus_stats.hc_rxcrc);
		QuickDump (IDC_RxBitErr, LineStatus->wan_linestatus_stats.hc_rxbiterr);
		QuickDump (IDC_RxOFlow, LineStatus->wan_linestatus_stats.hc_rxoflow);
		QuickDump (IDC_RxORun, LineStatus->wan_linestatus_stats.hc_rxorun);
		QuickDump (IDC_NoClock, LineStatus->wan_linestatus_stats.hc_noclock);

		CDC *pDC = GetDC();

		PercentFrame (::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], pDC);
		PercentFrame (::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], pDC);

		ReleaseDC(pDC);

		//
		//  Additional information displayed here
		//
		QuickDump (IDC_TxGoodFrames, LineStatus->wan_linestatus_stats.hc_txgood);
		QuickDump (IDC_RxGoodFrames, LineStatus->wan_linestatus_stats.hc_rxgood);
		QuickDump (IDC_TxGoodBytes, LineStatus->wan_linestatus_stats.hc_txgdbytes);
		QuickDump (IDC_RxGoodBytes, LineStatus->wan_linestatus_stats.hc_rxgdbytes);

		QuickDump (IDC_TxUnderrun, LineStatus->wan_linestatus_stats.hc_txurun);
		QuickDump (IDC_RxOverrun, LineStatus->wan_linestatus_stats.hc_rxorun);

		QuickDump (IDC_RxCRC, LineStatus->wan_linestatus_stats.hc_rxcrc);
		QuickDump (IDC_RxNoBuffer, LineStatus->wan_linestatus_stats.hc_rxnobuf);
		QuickDump (IDC_RxBitError, LineStatus->wan_linestatus_stats.hc_rxbiterr);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CX25StatView

IMPLEMENT_DYNCREATE(CX25StatView, CStatViewBase)

CX25StatView::CX25StatView()
	: CStatViewBase(CX25StatView::IDD)
{
	//{{AFX_DATA_INIT(CX25StatView)
	//}}AFX_DATA_INIT
}

CX25StatView::~CX25StatView()
{
}

void CX25StatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CX25StatView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CX25StatView, CStatViewBase)
	//{{AFX_MSG_MAP(CX25StatView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CX25StatView diagnostics

#ifdef _DEBUG
void CX25StatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CX25StatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CX25StatView message handlers

void CX25StatView::OnUpdate(CView*, LPARAM lHint, CObject*) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CX25StatDoc *pDoc = dynamic_cast<CX25StatDoc *>(GetDocument());

		DoWANStats();

		DoWANLineStatus();

		const CLAPB& LapbStats = pDoc->GetLAPB();

		QuickDumpText(IDC_LnkState, LapbStats.GetState());

		QuickDump(IDC_CmdTxRej, LapbStats[REJ_tx_cmd] + 
																		LapbStats[REJ_tx_rsp] +
																		LapbStats[REJ_tx_cmd_p]);

		QuickDump(IDC_CmdTxRNR, LapbStats[RNR_tx_cmd] +
																		LapbStats[RNR_tx_rsp] +
																		LapbStats[RNR_tx_cmd_p]);

		QuickDump(IDC_CmdTxRR,	LapbStats[RR_tx_cmd] +
																		LapbStats[RR_tx_rsp] +
																		LapbStats[RR_tx_cmd_p]);

		QuickDump(IDC_TxData, LapbStats[I_tx_cmd]);
		QuickDump(IDC_TxDisconnect, LapbStats[DISC_tx_cmd]);
		QuickDump(IDC_TxDM, LapbStats[DM_tx_rsp]);
		QuickDump(IDC_TxFRMR, LapbStats[FRMR_tx_rsp]);
		QuickDump(IDC_TxSABM, LapbStats[SABM_tx_cmd]);
		QuickDump(IDC_TxSABMExt, LapbStats[SABME_tx_cmd]);
		QuickDump(IDC_TxUA, LapbStats[UA_tx_rsp]);

		QuickDump(IDC_CmdRxRej, LapbStats[REJ_rx_cmd] +
																		LapbStats[REJ_rx_rsp]);

		QuickDump(IDC_CmdRxRNR, LapbStats[RNR_rx_cmd] +
																		LapbStats[RNR_rx_rsp]);

		QuickDump(IDC_CmdRxRR,	LapbStats[RR_rx_cmd] +
																		LapbStats[RR_rx_rsp]);

		QuickDump(IDC_RxData, LapbStats[I_rx_cmd]);
		QuickDump(IDC_RxDisconnect, LapbStats[DISC_rx_cmd]);
		QuickDump(IDC_RxDM, LapbStats[DM_rx_rsp]);
		QuickDump(IDC_RxFRMR, LapbStats[FRMR_rx_rsp]);
		QuickDump(IDC_RxSABM, LapbStats[SABM_rx_cmd]);
		QuickDump(IDC_RxSABMExt, LapbStats[SABME_rx_cmd]);
		QuickDump(IDC_RxUA, LapbStats[UA_rx_rsp]);

		const CX25& X25Stats = pDoc->GetX25();

		QuickDump(IDC_CallCollision, X25Stats[cll_coll]);
		QuickDump(IDC_CallAbort, X25Stats[cll_uabort]);
		QuickDump(IDC_CallRejectSent, X25Stats[rjc_buflow] +
																					X25Stats[rjc_coll] +
																					X25Stats[rjc_failNRS] +
																					X25Stats[rjc_lstate] +
																					X25Stats[rjc_nochnl] +
																					X25Stats[rjc_nouser] +
																					X25Stats[rjc_u]);
		QuickDump(IDC_CallRejectRcv, X25Stats[rjc_remote]);

		QuickDump(IDC_CallIn, X25Stats[caa_in]);
		QuickDump(IDC_CallOut, X25Stats[caa_out]);
		QuickDump(IDC_CallRcv, X25Stats[cll_in]);
		QuickDump(IDC_CallSent, X25Stats[cll_out]);
		QuickDump(IDC_DataPktRcv, X25Stats[dt_in]);
		QuickDump(IDC_DataPktSent, X25Stats[dt_out]);
		QuickDump(IDC_DiagPktRcv, X25Stats[dg_in]);
		QuickDump(IDC_DiagPktSent, X25Stats[dg_out]);

		QuickDump(IDC_X25_TxErr,	X25Stats[p4_ferr] +
															X25Stats[res_ferr]);
		QuickDump(IDC_X25_RxErr, X25Stats[rem_perr]);

		QuickDump(IDC_RcvrNotRdyRcv, X25Stats[rnr_in]);
		QuickDump(IDC_RcvrNotRdySent, X25Stats[rnr_out]);
		QuickDump(IDC_RcvrRdyRcv, X25Stats[rr_in]);
		QuickDump(IDC_RcvrRdySent, X25Stats[rr_out]);
		QuickDump(IDC_ResetRcv, X25Stats[rst_in]);
		QuickDump(IDC_ResetSent, X25Stats[rst_out]);
		QuickDump(IDC_RestartRcv, X25Stats[res_in]);
		QuickDump(IDC_RestartSent, X25Stats[res_out]);
		}
}

void CX25StatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CStatDoc *pDoc = GetDocument();
	
	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], &dc);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], &dc);	
	// Do not call CStatViewBase::OnPaint() for painting messages
}

void CSnaStatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CStatDoc *pDoc = GetDocument();
	
	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], &dc);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], &dc);
	
	// Do not call CStatViewBase::OnPaint() for painting messages
}

void CSnaStatView::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();

	// TODO: Add your specialized code here and/or call the base class
	
}


/////////////////////////////////////////////////////////////////////////////
// CPPPStatView

IMPLEMENT_DYNCREATE(CPPPStatView, CStatViewBase)

CPPPStatView::CPPPStatView()
	: CStatViewBase(CPPPStatView::IDD)
{
	//{{AFX_DATA_INIT(CPPPStatView)
	//}}AFX_DATA_INIT
}

CPPPStatView::~CPPPStatView()
{
}

void CPPPStatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPPPStatView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPPPStatView, CStatViewBase)
	//{{AFX_MSG_MAP(CPPPStatView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPPPStatView diagnostics

#ifdef _DEBUG
void CPPPStatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CPPPStatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPPPStatView message handlers

void CPPPStatView::OnUpdate(CView*, LPARAM lHint, CObject *pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CPPPStatDoc *pDoc = dynamic_cast<CPPPStatDoc *>(GetDocument());

		//  Get the standard WAN Statistics
		DoWANStats();

		DoWANLineStatus();

		const CWANLINESTATUS& LineStatus = pDoc->GetLineStatus();

		QuickDump(IDC_RxAbort, LineStatus->wan_linestatus_stats.hc_rxabort);
		QuickDump(IDC_RxCRC, LineStatus->wan_linestatus_stats.hc_rxcrc);
		QuickDump(IDC_RxBitErr, LineStatus->wan_linestatus_stats.hc_rxbiterr);
		QuickDump(IDC_RxOFlow, LineStatus->wan_linestatus_stats.hc_rxoflow);
		QuickDump(IDC_RxORun, LineStatus->wan_linestatus_stats.hc_rxorun);
		QuickDump(IDC_NoClock, LineStatus->wan_linestatus_stats.hc_noclock);

		CDC *pDC = GetDC();

		PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], pDC);
		PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], pDC);

		ReleaseDC(pDC);

		//
		//  Additional information displayed here
		//
		QuickDump (IDC_TxGoodFrames, LineStatus->wan_linestatus_stats.hc_txgood);
		QuickDump (IDC_RxGoodFrames, LineStatus->wan_linestatus_stats.hc_rxgood);
		QuickDump (IDC_TxGoodBytes, LineStatus->wan_linestatus_stats.hc_txgdbytes);
		QuickDump (IDC_RxGoodBytes, LineStatus->wan_linestatus_stats.hc_rxgdbytes);

		QuickDump (IDC_TxUnderrun, LineStatus->wan_linestatus_stats.hc_txurun);
		QuickDump (IDC_RxOverrun, LineStatus->wan_linestatus_stats.hc_rxorun);

		QuickDump (IDC_RxCRC, LineStatus->wan_linestatus_stats.hc_rxcrc);
		QuickDump (IDC_RxNoBuffer, LineStatus->wan_linestatus_stats.hc_rxnobuf);
		QuickDump (IDC_RxBitError, LineStatus->wan_linestatus_stats.hc_rxbiterr);
	}
}

void CPPPStatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CStatDoc *pDoc = GetDocument();
	
	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], &dc);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], &dc);
	
	// Do not call CStatViewBase::OnPaint() for painting messages
}

void CPPPStatView::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();

	// TODO: Add your specialized code here and/or call the base class
	
}


/////////////////////////////////////////////////////////////////////////////
// CPPPCsuStatView
/////////////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE(CPPPCsuStatView, CStatViewBase)

CPPPCsuStatView::CPPPCsuStatView()
	: CStatViewBase(CPPPCsuStatView::IDD)
{
	//{{AFX_DATA_INIT(CPPPCsuStatView)
	//}}AFX_DATA_INIT
}

CPPPCsuStatView::~CPPPCsuStatView()
{
}

void CPPPCsuStatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPPPCsuStatView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPPPCsuStatView, CStatViewBase)
	//{{AFX_MSG_MAP(CPPPCsuStatView)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()

// CPPPCsuStatView diagnostics

#ifdef _DEBUG
void CPPPCsuStatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CPPPCsuStatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

// CPPPCsuStatView message handlers

void CPPPCsuStatView::OnUpdate(CView*, LPARAM lHint, CObject *pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CPPPCsuStatDoc *pDoc = dynamic_cast<CPPPCsuStatDoc *>(GetDocument());

		{
			const CIfaceState Iface = pDoc->GetIfaceState();
			CString Signal;
			switch ( LOS_STATE(Iface->State) )
			{
				case SIGNAL_PRESENT:	Signal = "None";	break;
				case SIGNAL_LOST:		Signal = "LOS";	break;
			}
			QuickDumpText( IDC_Signal, Signal );

			CString Alarms;
			switch ( ALARM_CONDITION(Iface->State) )
			{
				case RED_ALARM_CONDITION:		Alarms = "Red";		break;
				case BLUE_ALARM_CONDITION:		Alarms = "Blue";		break;
				case YELLOW_ALARM_CONDITION:	Alarms = "Yellow";	break;
				case NO_ALARM_CONDITION:	
				default:								Alarms = "None";		break;
			}
			QuickDumpText( IDC_Alarms, Alarms );

			CString Loopback;
			switch ( LOOPBACK_STATE(Iface->State) )
			{
				case PAYLOAD_LOOPBACK:	Loopback = "Payload";	break;
				case LINE_LOOPBACK:		Loopback = "Line";		break;
				case NO_LOOPBACK:	
				default:						Loopback = "None";		break;
			}
			QuickDumpText( IDC_Loopback, Loopback );
		}
	}
}

void CPPPCsuStatView::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();

	// TODO: Add your specialized code here and/or call the base class
	
}


LRESULT CPPPCsuStatView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		lParam = HID_BASE_RESOURCE + IDD_CsuLine;

	return GetParentFrame()->SendMessage(WM_COMMANDHELP, wParam, lParam);
}


/////////////////////////////////////////////////////////////////////////////
// CFRCsuStatView
/////////////////////////////////////////////////////////////////////////////

IMPLEMENT_DYNCREATE(CFRCsuStatView, CStatViewBase)

CFRCsuStatView::CFRCsuStatView()
	: CStatViewBase(CFRCsuStatView::IDD)
{
	//{{AFX_DATA_INIT(CFRCsuStatView)
	//}}AFX_DATA_INIT
}

CFRCsuStatView::~CFRCsuStatView()
{
}

void CFRCsuStatView::DoDataExchange(CDataExchange* pDX)
{
	CStatViewBase::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFRCsuStatView)
	DDX_Control(pDX, IDC_DLCI, m_DLCIBox);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFRCsuStatView, CStatViewBase)
	//{{AFX_MSG_MAP(CFRCsuStatView)
	ON_CBN_SELCHANGE(IDC_DLCI, OnSelchangeDlci)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
END_MESSAGE_MAP()

// CFRCsuStatView diagnostics

#ifdef _DEBUG
void CFRCsuStatView::AssertValid() const
{
	CStatViewBase::AssertValid();
}

void CFRCsuStatView::Dump(CDumpContext& dc) const
{
	CStatViewBase::Dump(dc);
}
#endif //_DEBUG

// CFRCsuStatView message handlers

void CFRCsuStatView::OnInitialUpdate() 
{
	CStatViewBase::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	const CDataSource *ds = GetDocument()->GetDataSource();

	m_DLCIBox.ResetContent();
	for (short i = 0; i < ds->GetNumCircuits(); i++) {
		CString txt;

		txt.Format("%lu", ds->GetCircuitNum(i));
		int index = m_DLCIBox.AddString(txt);
		m_DLCIBox.SetItemData(index, i);
		}
	m_DLCIBox.SetCurSel(0);
}

void CFRCsuStatView::OnUpdate(CView*, LPARAM lHint, CObject *pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (lHint & uavUpdateStats)
	{
		CFRCsuStatDoc *pDoc = dynamic_cast<CFRCsuStatDoc *>(GetDocument());

		const CFR_LINK_STATS& LinkStats = pDoc->GetLinkStats();

		QuickDump(IDC_BECNRcv, LinkStats->rcvbecns);
		QuickDump(IDC_FECNRcv, LinkStats->rcvfecns);

		const CFR_LINK_ERRORS& LinkErrors = pDoc->GetLinkErrors();

		QuickDump(IDC_IvdFrmRvc, LinkErrors->rcvframe_inv);
		QuickDump(IDC_TooSrt2, LinkErrors->rcvinv_short);
		QuickDump(IDC_TooLong2, LinkErrors->rcvinv_long);
		QuickDump(IDC_IvdDLCI2, LinkErrors->rcvinv_dlci);
		QuickDump(IDC_UnknownDLCI2, LinkErrors->rcvunk_dlci);

		const CFR_LMI_STATS& LMIStats = pDoc->GetLMIStats();

		QuickDump(IDC_LMISETx, LMIStats->lmi_total_stat_enqs);
		QuickDump(IDC_LMISMTX, LMIStats->lmi_total_status);
		QuickDump(IDC_LMIUSTx, LMIStats->lmi_total_updates);
	
		DWORD temp =	LMIStats->lmi_inv_msg_rcvd + LMIStats->lmi_no_ie_rep_type +
									LMIStats->lmi_no_ie_keep_alive + LMIStats->lmi_lost_seq_num +
									LMIStats->lmi_stat_resp_timeout + LMIStats->lmi_unsupp_ie_msg +
									LMIStats->lmi_unexpected_pvc_num + LMIStats->lmi_unexpected_pvc_stat_msg;
		QuickDump(IDC_LMIErrors, temp);

		int index = m_DLCIBox.GetCurSel();

		if (index > -1)
		{
			index = m_DLCIBox.GetItemData(index);

			const CFR_PROTOCOL_ERRORS& ProtocolErrors = pDoc->GetProtocolErrors(index);

			QuickDump(IDC_UnkwnProto, ProtocolErrors->rcv_unkprot);
			QuickDump(IDC_UnkwnFrm2, ProtocolErrors->rcv_unkframe);
			QuickDump(IDC_LostFrm, ProtocolErrors->rcv_lostframe);
			QuickDump(IDC_UnkwnOrgCode, ProtocolErrors->rcv_unkorg);

			const CFR_INJ_MANG& InjManager = pDoc->GetInjManager(index);
	
			QuickDump(IDC_InjDropped, InjManager->InjFramesDropped);
			QuickDump(IDC_InjExcess, InjManager->InjExcessFrames);
			QuickDump(IDC_InjHold2, InjManager->InjHoldFrames);
			QuickDump(IDC_InjNormal, InjManager->InjNormalFrames);
		}

		{
			const CIfaceState Iface = pDoc->GetIfaceState();
			CString Signal;
			switch ( LOS_STATE(Iface->State) )
			{
				case SIGNAL_PRESENT:	Signal = "None";	break;
				case SIGNAL_LOST:		Signal = "LOS";	break;
			}
			QuickDumpText( IDC_Signal, Signal );

			CString Alarms;
			switch ( ALARM_CONDITION(Iface->State) )
			{
				case RED_ALARM_CONDITION:		Alarms = "Red";		break;
				case BLUE_ALARM_CONDITION:		Alarms = "Blue";		break;
				case YELLOW_ALARM_CONDITION:	Alarms = "Yellow";	break;
				case NO_ALARM_CONDITION:	
				default:								Alarms = "None";		break;
			}
			QuickDumpText( IDC_Alarms, Alarms );

			CString Loopback;
			switch ( LOOPBACK_STATE(Iface->State) )
			{
				case PAYLOAD_LOOPBACK:	Loopback = "Payload";	break;
				case LINE_LOOPBACK:		Loopback = "Line";		break;
				case NO_LOOPBACK:	
				default:						Loopback = "None";		break;
			}
			QuickDumpText( IDC_Loopback, Loopback );
		}
	}

	if (lHint & uavGetUpdateCircuits)
	{
		CDWordArray *pCircuits = (CDWordArray *)pHint;

		int index = m_DLCIBox.GetCurSel();

		if (index > -1)
			pCircuits->SetAt(m_DLCIBox.GetItemData(index), 1);
	}
}

void CFRCsuStatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CStatDoc *pDoc = GetDocument();
	
	PercentFrame(::GetDlgItem(m_hWnd, IDC_TxFrame), pDoc->m_LU[0], &dc);
	PercentFrame(::GetDlgItem(m_hWnd, IDC_RxFrame), pDoc->m_LU[1], &dc);
	// Do not call CStatViewBase::OnPaint() for painting messages
}

void CFRCsuStatView::OnSelchangeDlci() 
{
	// TODO: Add your control notification handler code here
	((CFRCsuStatDoc *)GetDocument())->SelChange(m_DLCIBox.GetCurSel());
}


LRESULT CFRCsuStatView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
	if (lParam == 0)
		lParam = HID_BASE_RESOURCE + IDD_FRCsuStats;

	return GetParentFrame()->SendMessage(WM_COMMANDHELP, wParam, lParam);
}
