/*++
*******************************************************************************
* Copyright (c) 1998-99 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 copyrighted work of Digi International	*
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly	*
* prohibited.																						*
* 																										*
* Restricted Rights Legend																		*
*																										*
* Use, duplication, or disclosure by the Government is subject to					*
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in			*
* Technical Data and Computer Software clause at DFARS 252.227-7031 or			*
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -				*
* Restricted Rights at 48 CFR 52.227-19, as applicable.								*
*																										*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343				*
*																										*
*******************************************************************************

Module Name:

   

Abstract:

   DataFire PRIme adapter specific data source.

Author:

   Michael Zarns

--*/
#include "stdafx.h"
#include "Diagnostic.h"
#include "DataSource.h"
#include "DiagDoc.h"
#include "StatDoc.h"

#include "SessionStatView.h"
#include "FRLineStatView.h"
#include "LAPBLineView.h"
#include "X25LineStatView.h"
#include "FRVCStatView.h"
#include "X25VCStatView.h"
#include "SummaryDlg.h"
#include "filter.h"

#include "Tracer.h"
#include "IsdnTrace.h"
#include "TraceStatView.h"
#include "prime.h"
#include <typeInfo.h>


void CPrimeDataSource::LoadSummaryInfo(const CString& frmvsn)
{
	CDataSource::LoadSummaryInfo(frmvsn);
	AddDriverInfo("DigiIsdn");
	AddDriverInfo("DigiPci");
}


CPrimeDataSource::CPrimeDataSource(const HKEY hkLine, const CString& DeviceName, const CString& Protocol) : 
	CDataSource(hkLine, DeviceName),
	m_IfaceState(m_SNID - 'A'),
	m_Rfc1406(m_SNID - 'A')
{
	m_Status = dssNotAvailable;
	m_Protocol = Protocol;
	m_BaudRate = 64000;	// Baudrate is for d-channel trace.  PRI D-channel is always 64000 bps.
}


const CSXB_USER_IOCTL *CPrimeDataSource::GetStatType(const type_info& Type, int index) const
{
	const CSXB_USER_IOCTL * result;

	if ( Type == typeid(CIfaceState) )
		result = &m_IfaceState;
	else if ( Type == typeid(CRfc1406) )
		result = &m_Rfc1406;
	else
		result = NULL;

	return result;
}


BOOL CPrimeDataSource::UpdateDataSourceStats()
{
	if ( m_Status == dssRunning )
	{
		GetData(&m_IfaceState);
		if ( m_Status == dssRunning )
		{
			switch ( ALARM_CONDITION( m_IfaceState->State ) )
			{
				case RED_ALARM_CONDITION:		m_Alarms = "Red";		break;
				case YELLOW_ALARM_CONDITION:	m_Alarms = "Yellow";	break;
				case BLUE_ALARM_CONDITION:		m_Alarms = "Blue";	break;
				case NO_ALARM_CONDITION:		
				default:								m_Alarms = "None";	break;
			}
		}
		else
			m_Alarms = "N/A";

		GetData(&m_Rfc1406);
		if ( m_Status == dssRunning )
		{
			// Add up the 24hour total errors
			__int64 Error = 
				m_Rfc1406->Total.ES + m_Rfc1406->Total.SES + m_Rfc1406->Total.SEFS + 
				m_Rfc1406->Total.UAS + m_Rfc1406->Total.CSS + m_Rfc1406->Total.PCV +
				m_Rfc1406->Total.LES + m_Rfc1406->Total.BES + m_Rfc1406->Total.DM + 
				m_Rfc1406->Total.LCV;
			// Then add in the current 15-minute interval errors
			Error += 
				m_Rfc1406->Current.ES + m_Rfc1406->Current.SES + m_Rfc1406->Current.SEFS + 
				m_Rfc1406->Current.UAS + m_Rfc1406->Current.CSS + m_Rfc1406->Current.PCV +
				m_Rfc1406->Current.LES + m_Rfc1406->Current.BES + m_Rfc1406->Current.DM + 
				m_Rfc1406->Current.LCV;
			m_Err = Error;	// Don't increment because these counters are already cumulative
		}
	}
	HandleClearStats( m_Err, m_ClearErr );
	return m_Status == dssRunning;
}


CTracer *CPrimeDataSource::CreateTracer()
{ 
	return new CIsdnTracer(this); 
}


CTraceData *CPrimeDataSource::CreateTraceData(DWORD baud, CDWordArray& circuits)
{
	return new CPrimeTraceData(baud, circuits); 
}
