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

📄 callcontrol.oldc

📁 基于嵌入式Linux平台的网络电话设计控制部分原程序代码。
💻 OLDC
📖 第 1 页 / 共 5 页
字号:
//
// Copyright (c) Blueinfosys.  All rights reserved.
//
// Module Name: CallControl.cpp
//
// Abstract:
//
// Author: Yang Xin
// Date: Feb 12, 2004
// Ver:1.00
//
// Modified by:
// Modified Date:
// Notes:
////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include	<stdio.h>
#include	<stdarg.h>

#include	<sys/types.h> 
#include	<sys/stat.h> 
#include	<fcntl.h> 
#include	<sys/ioctl.h> 
#include	<errno.h>
#include	<time.h>
#include	<pthread.h>
#include	<string.h>
#include	<unistd.h>
#include	<stdlib.h>
#include	<signal.h>
#include	"../newpbx/commondef.h"

#include	"ccuatype.h"
#include	"queue.h"
#include	"WebSrv.h"
#include	"rtp.h"
#include	"sipmessage.h"
#include	"commtrace.h"
#include	"CallControl.h"

int	giFxsInGain = 0x20;			//话音呼入增益,缺省为0
int	giFxsOutGain = 0x20;		//话音呼出增益,缺省为0
int	giFxoInGain = 0x20;			//线路呼入增益,缺省为0
int	giFxoOutGain = 0x20;		//线路呼出增益,缺省为0

int	giAutoTalk = 0;

extern void Init_Codec(void);
extern int iInitAudioCode( void );

extern int	iInitTapi();
extern void vThreadReadFromDriver( void );
extern int iQXget( P_QUEUE_X p_pqQueue, UCHAR *p_ucMsg );
extern int iQXInit( P_QUEUE_X p_pqQueue, UCHAR *p_ucMsg, DWORD *pdwClock, int iUnitLen, int iMaxNumMsg );
extern int iQXput( P_QUEUE_X p_pqQueue, UCHAR *p_ucMsg );

extern BOOL boolStartFilePlay( DWORD dwChannel, int iFileNumber );
extern BOOL boolStopFilePlay( DWORD dwChannel );
extern void vPlayFileEnd( DWORD dwChannel );
extern void vSetCodecGain( int iTrnGain, int iRcvGain, int iFxoTrnGain, int iFxoRcvGain );

extern QUEUE_X		gqxQueueTrace;
BOOL				gboolTraceEnable;

tCC_UA_MSG		gqQueueUaMsg[ MAX_UAMSG_SAVED ]; 
DWORD			gdwQueueUaMsg[ MAX_UAMSG_SAVED ];
QUEUE_X			gqxQueueUaMsg;

extern tNetQueue	gtSendQueue;

CCallControl	goCC;

extern DWORD	gdwMix;
extern DWORD	gdwMix2;
extern BOOL gblnShutdown;

extern void	vReceiveCCMesg( ptCC_UA_MSG ptCcUaMsg );
extern void vPlayandRecordManager( void );
extern void vSignalTrace();
extern int iSetCallProgress( ptCallProgressData ptData );
extern int iGetCallProgress( ptCallProgressData ptData );

void	vRecvRtpPackage( DWORD *pdwChannel );

int		gmiLineType[MAX_LINE_NUM];

BOOL	gblnvSignalTrace = FALSE;
BOOL	gblnvPlayandRecordManager = FALSE;
BOOL	gblnvThreadSignalProc = FALSE;
BOOL	gblnvThreadReadFromDriver = FALSE;
BOOL	gblnvThreadReadDataFromDriver = FALSE;
BOOL	gblnvInitCCProc = FALSE;

int iWriteVoiceToDriver( DWORD dwChannel, char *pchBuf, DWORD dwLength );

void vGetHardwareInfo( char *pchBuf )
{
	memset( pchBuf, LINE_NULL, sizeof(gmiLineType) );
	memcpy( pchBuf, gmiLineType, sizeof(gmiLineType) );
}

void CCallControl::vFollowmeFunc( DWORD dwChannel, ptCC_UA_MSG ptCcUaMsg )
{
	tCC_UA_MSG	tCcUaMsg;

	switch( ptCcUaMsg->u.tFollowme.eType ) {
	case eF_Set:
		if ( ptCcUaMsg->u.tFollowme.iPassword == m_tModuleInfo.port.dwPwd[dwChannel] ) {
			// password is right
			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.dwChannel = dwChannel;
			tCcUaMsg.hdr.eMsgType = eFollowmeAns;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tFollowmeResult );
			tCcUaMsg.hdr.dwChannel = dwChannel;

			tCcUaMsg.u.tFollowmeResult.iSourceNumber = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			tCcUaMsg.u.tFollowmeResult.eType = eF_SetOk;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			goCC.vSendMsgToUA( &tCcUaMsg );

			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.eMsgType = eForwardMsg;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tForward );
			tCcUaMsg.hdr.dwChannel = dwChannel;
			tCcUaMsg.u.tForward.dwType = 1;
			tCcUaMsg.u.tForward.dwForwardNumber = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			tCcUaMsg.u.tForward.dwChannel = dwChannel;
			tCcUaMsg.u.tForward.dwModuleNumber = m_tModuleInfo.general.iModuleIndex;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			vSendMsgToUA( &tCcUaMsg );
			m_tModuleInfo.port.dwForwardTel[dwChannel] = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			m_tModuleInfo.port.dwDelayTime[dwChannel] = 0;
		} else {
			// password is error
			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.eMsgType = eFollowmeAns;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tFollowmeResult );
			tCcUaMsg.hdr.dwChannel = dwChannel;

			tCcUaMsg.u.tFollowmeResult.iSourceNumber = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			tCcUaMsg.u.tFollowmeResult.eType = eF_SetFail;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			vSendMsgToUA( &tCcUaMsg );
		}
		break;
	case eF_Clear:
		if ( ptCcUaMsg->u.tFollowme.iDestinationNumber == m_tModuleInfo.port.dwForwardTel[dwChannel] ) {
			// 目标分机就是前转分机
			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.eMsgType = eFollowmeAns;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tFollowmeResult );
			tCcUaMsg.hdr.dwChannel = dwChannel;

			tCcUaMsg.u.tFollowmeResult.iSourceNumber = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			tCcUaMsg.u.tFollowmeResult.eType = eF_ClearOk;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			vSendMsgToUA( &tCcUaMsg );

			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.eMsgType = eForwardMsg;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tForward );
			tCcUaMsg.hdr.dwChannel = dwChannel;

			tCcUaMsg.u.tForward.dwType = 0;
			tCcUaMsg.u.tForward.dwModuleNumber = m_tModuleInfo.general.iModuleIndex;
			tCcUaMsg.u.tForward.dwChannel = dwChannel;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			vSendMsgToUA( &tCcUaMsg );
			m_tModuleInfo.port.dwForwardTel[dwChannel] = 0;
		} else {
			// 目标分机不是前转分机
			memset( (char *)&tCcUaMsg, 0, sizeof(tCcUaMsg) );
			tCcUaMsg.hdr.eMsgType = eFollowmeAns;
			tCcUaMsg.hdr.length = sizeof( tCcUaMsg.hdr ) + sizeof( tCcUaMsg.u.tFollowmeResult );
			tCcUaMsg.hdr.dwChannel = dwChannel;

			tCcUaMsg.u.tFollowmeResult.iSourceNumber = ptCcUaMsg->u.tFollowme.iDestinationNumber;
			tCcUaMsg.u.tFollowmeResult.eType = eF_ClearFail;
			tCcUaMsg.hdr.dwCcIdx = 0;
			tCcUaMsg.hdr.dwUaIdx = 0;
			vSendMsgToUA( &tCcUaMsg );
		}
		break;
	default:
		break;
	}
}

void CCallControl::vStatusEnquiryAck( DWORD dwChannel, ptCC_UA_MSG ptCcUaMsg )
{
	// answer Fxostatusack message to the other side
	ptCcUaMsg->hdr.eMsgType = eFxoStatusAck;
	ptCcUaMsg->hdr.length = sizeof(ptCcUaMsg->hdr) + sizeof(tFxoStatusAckMessage);
	ptCcUaMsg->u.tFxoStatusAck.iFxoNumber = ptCcUaMsg->u.tFxoStatusAck.dwSendFxoNumber;
	ptCcUaMsg->u.tFxoStatusAck.dwSendFxoNumber = goCC.m_tModuleInfo.port.dwTelno[dwChannel];
	ptCcUaMsg->u.tFxoStatusAck.dwStatus = goCC.dwGetStatus( dwChannel );
	ptCcUaMsg->u.tFxoStatusAck.eCurrentSceType = eSceTypeOff;

	if ( mtFxxAttrib[dwChannel].mtCallInfo[eFirstcall].tSetup.dwCallee == ptCcUaMsg->u.tFxoStatusAck.iFxoNumber
		|| mtFxxAttrib[dwChannel].mtCallInfo[eFirstcall].tSetup.dwCaller == ptCcUaMsg->u.tFxoStatusAck.iFxoNumber
		|| mtFxxAttrib[dwChannel].mtCallInfo[eSecondcall].tSetup.dwCallee == ptCcUaMsg->u.tFxoStatusAck.iFxoNumber
		|| mtFxxAttrib[dwChannel].mtCallInfo[eSecondcall].tSetup.dwCaller == ptCcUaMsg->u.tFxoStatusAck.iFxoNumber ) {
		ptCcUaMsg->u.tFxoStatusAck.boolOppositeOk = TRUE;
	} else {
		ptCcUaMsg->u.tFxoStatusAck.boolOppositeOk = FALSE;
	}

	if ( gboolTraceEnable ) {
		ptCcUaMsg->hdr.dwDirection = 1;
		ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
		iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
	}

	// call function of HEGS
	vReceiveCCMesg( ptCcUaMsg );
}

void vReceiveUaMsg( ptCC_UA_MSG ptCcUaMsg )
{
	DWORD				dwTmp;
	tCallProgressData	tCallData;

	if ( ptCcUaMsg->hdr.dwChannel < 0 || ptCcUaMsg->hdr.dwChannel >= MAX_LINE_NUM ) {
		return;
	}

	if ( ptCcUaMsg->hdr.eMsgType == eGlobalMsg ) {
		memcpy( &(goCC.m_tGlobalInfo), ptCcUaMsg->u.tGlobalInfo.pchMsg, sizeof(goCC.m_tGlobalInfo) );
		if ( gboolTraceEnable ) {
			ptCcUaMsg->hdr.dwDirection = 0;
			ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
			iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
		}

		goCC.m_blnUpdateTimeformcallid = goCC.m_tGlobalInfo.general.isTimeChangedByCallid;

		iGetCallProgress( &tCallData );

		tCallData.dwNumberofFrequencies = goCC.m_tGlobalInfo.signal.iFreqNum;
		tCallData.dwNumberofSignals = goCC.m_tGlobalInfo.signal.iSignalNum;

		for( dwTmp = 0; dwTmp < tCallData.dwNumberofFrequencies; dwTmp ++ ) {
			tCallData.mulFreq[dwTmp] = goCC.m_tGlobalInfo.frequence.frequence[dwTmp];
		}

		for( dwTmp = 0; dwTmp < tCallData.dwNumberofSignals; dwTmp ++ ) {
			tCallData.mtSignal[dwTmp].ulHighFreqIndex = goCC.m_tGlobalInfo.signaltone.iHighFreqIndex[dwTmp];
			tCallData.mtSignal[dwTmp].ulHighFreqLevel = goCC.m_tGlobalInfo.signaltone.iHighFreqLevel[dwTmp];
			tCallData.mtSignal[dwTmp].ulLowFreqIndex = goCC.m_tGlobalInfo.signaltone.iLowFreqIndex[dwTmp];
			tCallData.mtSignal[dwTmp].ulLowFreqLevel = goCC.m_tGlobalInfo.signaltone.iLowFreqLevel[dwTmp];
			tCallData.mtSignal[dwTmp].ulTOFF1 = goCC.m_tGlobalInfo.signaltone.iToff1[dwTmp];
			tCallData.mtSignal[dwTmp].ulTOFF2 = goCC.m_tGlobalInfo.signaltone.iToff2[dwTmp];
			tCallData.mtSignal[dwTmp].ulTON1 = goCC.m_tGlobalInfo.signaltone.iTon1[dwTmp];
			tCallData.mtSignal[dwTmp].ulTON2 = goCC.m_tGlobalInfo.signaltone.iTon2[dwTmp];
		}

		tCallData.tFxsSignalsData.ulDialToneIndex = goCC.m_tGlobalInfo.dialtone.iSignalIndex;
		tCallData.tFxsSignalsData.ulDialToneGain = goCC.m_tGlobalInfo.dialtone.iGain & 0x1f;
		tCallData.tFxsSignalsData.ulRingBackIndex = goCC.m_tGlobalInfo.ringbacktone.iSignalIndex;
		tCallData.tFxsSignalsData.ulRingBackLevel = goCC.m_tGlobalInfo.ringbacktone.iGain & 0x1f;
		tCallData.tFxsSignalsData.ulBusyToneIndex = goCC.m_tGlobalInfo.busytone.iSignalIndex;
		tCallData.tFxsSignalsData.ulBusyToneLevel = goCC.m_tGlobalInfo.busytone.iGain & 0x1f;

		tCallData.tFxoBusyToneSet.dwCounter = goCC.m_tGlobalInfo.fxobusytoneidentify.iSignalCount;
		for( dwTmp = 0; dwTmp < tCallData.tFxoBusyToneSet.dwCounter; dwTmp ++ ) {
			tCallData.tFxoBusyToneSet.mulIdx[dwTmp] = goCC.m_tGlobalInfo.fxobusytoneidentify.iSignalIndex[dwTmp];
		}
		tCallData.tFxoDialToneSet.dwCounter = goCC.m_tGlobalInfo.fxodialtoneidentify.iSignalCount;
		for( dwTmp = 0; dwTmp < tCallData.tFxoDialToneSet.dwCounter; dwTmp ++ ) {
			tCallData.tFxoDialToneSet.mulIdx[dwTmp] = goCC.m_tGlobalInfo.fxodialtoneidentify.iSignalIndex[dwTmp];
		}

		iSetCallProgress( &tCallData );

		vSetCodecGain( goCC.m_tModuleInfo.voice.iFxsTrnGain, goCC.m_tModuleInfo.voice.iFxsRcvGain,
			goCC.m_tModuleInfo.voice.iFxoTrnGain, goCC.m_tModuleInfo.voice.iFxoRcvGain );

		return;
	}
	
//yy	if ( ptCcUaMsg->hdr.eMsgType == eCallmgrStatus ) {
//yy		ptIppbxFXInfo->dwMaxLEDCounter = 64;
//yy		if ( ptCcUaMsg->u.tCallmgrStatus.boolConnectStatus ) {
//yy			ptIppbxFXInfo->dwMaxLEDCounter /= 4;
//yy		}
//yy		if ( ptCcUaMsg->u.tCallmgrStatus.boolCenter ) {
//yy			ptIppbxFXInfo->dwMaxLEDCounter /= 2;
//yy		}
//yy		return;
//yy	}

	if ( ptCcUaMsg->hdr.eMsgType == eModuleMsg ) {
		memcpy( &(goCC.m_tModuleInfo), ptCcUaMsg->u.tModuleInfo.pchMsg, sizeof(goCC.m_tModuleInfo) );

		goCC.vUpdateLineSet();

		if ( gboolTraceEnable ) {
			ptCcUaMsg->hdr.dwDirection = 0;
			ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
			iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
		}

//yy		goIppbxfx.vSetBufferedVoiceType( goCC.m_tModuleInfo.voice.iRxBuffer );

		iGetCallProgress( &tCallData );

		tCallData.dwFxoSendDtmfGain = goCC.m_tModuleInfo.voice.iDtmfGain;
		tCallData.dwFxoSendDtmfGain %= 32;

		iSetCallProgress( &tCallData );

		giFxsInGain = goCC.m_tModuleInfo.voice.iFxsTrnPacketGain;
		giFxsOutGain = goCC.m_tModuleInfo.voice.iFxsRcvPacketGain;
		giFxoInGain = goCC.m_tModuleInfo.voice.iFxoTrnPacketGain;
		giFxoOutGain = goCC.m_tModuleInfo.voice.iFxoRcvPacketGain;

		vSetCodecGain( goCC.m_tModuleInfo.voice.iFxsTrnGain, goCC.m_tModuleInfo.voice.iFxsRcvGain,
			goCC.m_tModuleInfo.voice.iFxoTrnGain, goCC.m_tModuleInfo.voice.iFxoRcvGain );

		return;
	}

	if ( ptCcUaMsg->hdr.eMsgType == eCMConnect ) {
		goCC.vReportAll();
		if ( gboolTraceEnable ) {
			ptCcUaMsg->hdr.dwDirection = 0;
			ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
			iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
		}
		return;
	}

	if ( ptCcUaMsg->hdr.eMsgType == eAudioData ) {

		// 语音信息直接传递给DRIVER
		iWriteVoiceToDriver( ptCcUaMsg->hdr.dwChannel, ptCcUaMsg->u.tVoiceMsg.pVoiceMessage,
			ptCcUaMsg->u.tVoiceMsg.dwLength );

		return;
	}

	if ( ptCcUaMsg->hdr.eMsgType == eGetFxsInfoAns ) {
		for( dwTmp = 0; dwTmp < MAX_LINE_NUM; dwTmp ++ ) {
			if ( goCC.m_tModuleInfo.port.dwTelno[dwTmp] == ptCcUaMsg->u.tGetFxsInfo.iDestChannel ) {
				ptCcUaMsg->hdr.dwChannel = dwTmp;
				break;
			}
		}
	}

#if	0
	if ( ptCcUaMsg->hdr.eMsgType == eRtpSessionInit ) {
		if ( gboolTraceEnable ) {
			ptCcUaMsg->hdr.dwDirection = 0;
			ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
			iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
		}
		goCC.vInitSession( ptCcUaMsg );
		return;
	}
#endif
	
	if ( ptCcUaMsg->hdr.eMsgType == eSetSystemTime ) {
		// modify system time
		if ( gboolTraceEnable ) {
			ptCcUaMsg->hdr.dwDirection = 0;
			ptCcUaMsg->hdr.dwStatus = (DWORD)-1;
			iQXput( &gqxQueueTrace, (UCHAR *)ptCcUaMsg );
		}

⌨️ 快捷键说明

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