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

📄 faxrcv.cpp

📁 传真演示系统(需硬件板卡支持)
💻 CPP
字号:
#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>    
#include <wchar.h>    
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "tce1_32.h"
#include "faxapi32.h"

#define	MAX_VOC_NUM	120

struct {
	int		MemFaxChnl;
	HANDLE	FileHandle;
} VoiceWorkStr[MAX_VOC_NUM];


void InitCard(void)
{
	int Result;

	Result = DJSys_EnableCard( "", "");
	if( Result ) {
		printf ( "Load driver FAIL\n");
		exit(0);
	}

	DJSys_DisableWarn() ;
	
	Result = DJFax_DriverReady(2048);
	if ( Result ) {
		printf ( "Load Fax Driver Fail\n");
		DJSys_DisableCard();
		exit(0);
	}

	printf ( "Init D320E1 and Fax card OK\n" );

	for ( int i = 0; i < MAX_VOC_NUM; i ++ ) {
		VoiceWorkStr[i].MemFaxChnl = -1;
		VoiceWorkStr[i].FileHandle = INVALID_HANDLE_VALUE;
	}
}

void ReleaseCard(void)
{
	DJSys_DisableCard();
	DJFax_DisableCard();
}

void AnalyzeFax ( int VocChnl, char *VocFileName, char *FaxFileName );

void main(void)
{
	char VocFileName[40];
	char FaxFileName[40];

	InitCard();

	int voiceID = DJVoc_SearchFreeVoiceChannelForPlay();
	if ( voiceID == -1 )
		printf ( "No Voice Chnl for use, so do nothing\n" );
	else {
		strcpy ( VocFileName, "rcvfax.voc" );
		strcpy ( FaxFileName, "rcvfax.bfx" );
		AnalyzeFax ( voiceID, VocFileName, FaxFileName );
	}

	ReleaseCard();
}

//--------------------------------------------------------------------------------
void Fax_StopPlayFile ( int voiceID )
{
	DJVoc_VoiceStop(voiceID);
	if(VoiceWorkStr[voiceID].FileHandle != INVALID_HANDLE_VALUE) {
		CloseHandle ( VoiceWorkStr[voiceID].FileHandle );
		VoiceWorkStr[voiceID].FileHandle = INVALID_HANDLE_VALUE;
	}
}


int Fax_StartPlayFile ( int voiceID, char *FileName )
{
	HANDLE hfFile;

	Fax_StopPlayFile(voiceID);

	hfFile = CreateFile ( FileName,
                           GENERIC_READ,
                           FILE_SHARE_READ|FILE_SHARE_WRITE,
                           NULL,
                           OPEN_EXISTING,
                           FILE_ATTRIBUTE_NORMAL,
                           NULL
                           );
	if ( hfFile == INVALID_HANDLE_VALUE ) 
		return 0;

	VoiceWorkStr[voiceID].FileHandle = hfFile;
	if( DJVoc_VoiceStart(voiceID,
			   (int)hfFile,
			   GetFileSize(hfFile,NULL),	
			   0,		
			   Res_File,
			   OP_Play))
		return 0;

	return 1;
}

void ResetChnl(int voiceID)
{
	int FaxChnl = VoiceWorkStr[voiceID].MemFaxChnl;
	DJFax_ClearListenFromVoice(FaxChnl,voiceID);
		Fax_StopPlayFile ( voiceID );
}

//--------------------------------------------------------------------------------
void AnalyzeFax ( int voiceID, char *VocFileName, char *FaxFileName )
{
	int status = 0;
	int FaxChnl;
	int CurrPage;
	int CheckReturn;


	while ( 1 ) {
		if ( kbhit() )
			if ( getch() == 0x1b ) {
				ResetChnl(voiceID);
				break;
			}

		DJSys_PushPlay();
		Sleep(10);

		switch ( status ) {
		case 0:
			printf ( "Start Analyze fax, voice chnl = %d, Voice file : [%s]\n", voiceID, VocFileName ); 
			printf ( "Generate Fax file : [%s]\n", FaxFileName );

			Fax_StartPlayFile ( voiceID, VocFileName );

			FaxChnl = DJFax_GetOneFreeFaxChnl();

			if(!DJFax_ListenFromVoice(FaxChnl,voiceID)){
				printf ( "no free fax chnl, so do nothing" );
				status = 990;
				break;
			}

			if(DJFax_RcvFaxFile(FaxChnl,FaxFileName) == 1) {
				printf ( "start receive fax, use faxchnl = %d\n", FaxChnl );
				CurrPage = 0;
			}
			else {
				printf ( "Rcv FaxFile fail\n" );
				DJFax_ClearListenFromVoice(FaxChnl,voiceID);
				status = 990;
				break;
			}

			// important: you should mem the FaxChnl by yourself
			VoiceWorkStr[voiceID].MemFaxChnl = FaxChnl;
			status = 10;
			break;
		case 10:
			//FaxChnl = DJFax_GetFaxChnlOfVoiceChnl(voiceID);
			FaxChnl = VoiceWorkStr[voiceID].MemFaxChnl;
			printf( "\rNow Recive Fax Page %d %ld bytes",
						CurrPage+1,DJFax_GetRcvBytes(FaxChnl) );

			CheckReturn = DJFax_CheckTransmit(FaxChnl);
			if(CheckReturn == 1)
				status = 20;
			else if(CheckReturn == 2){
				CurrPage++;
			}
			else if ( (CheckReturn == 2) || (CheckReturn == 2) ){		// -1 or -2
				status = 30;
			}

			if(DJVoc_CheckVoiceEnd(voiceID)) {
				printf ( "Play End\n" );

				status = 990;
			}
			break;

		case 20:
			printf ( "\nRcv Fax OK\n" );
			status = 990;
			break;

		case 30:
			printf ( "\nRcv Fax Fail\n" );
			status = 990;
			break;

		case 990:
			ResetChnl(voiceID);

			printf ( "press ESC to exit\n" );
			status = 1000;										 
			break;
		}
	}
}



⌨️ 快捷键说明

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