?? id.c
字號:
/*=========================================================
ID.C
=========================================================*/
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include "..\\..\\..\\..\\inc\\tc08a32.h"
unsigned char IDStr[MAX_CHANNEL_NO][128];
int ChType[MAX_CHANNEL_NO];
int ChStatus[MAX_CHANNEL_NO];
long MyTimer[MAX_CHANNEL_NO];
char VocName[80];
WORD ChannelCount;
#define TEST_CLOCK 4
TC_INI_TYPE TmpIni;
int OffHookFlag = 0;
void PrintRaw ( WORD i );
int GetCallerIDDtmf (WORD ChannelNo, char far *IDStr);
/*void StartTimer(int ChannelNo)
{
struct time t;
gettime(&t);
MyTimer[ChannelNo] = (3600L*t.ti_hour + 60L*t.ti_min + t.ti_sec )*100
+ t.ti_hund;
}
long ElapseTime ( int ChannelNo)
{
struct time t;
long tmpl;
gettime(&t);
tmpl = (3600L*t.ti_hour + 60L*t.ti_min + t.ti_sec )*100
+ t.ti_hund;
return ( tmpl - MyTimer[ChannelNo] );
}
*/
void TestCallerID(void);
void TestCallerID1(void);
int main( int argc, char **argv )
{
WORD i;
FILE *fp;
long r;
if ( argc <= 1 ) {
printf ( "Usage: ID o run the ID.EXE and OffHook for play \n" );
printf ( " ID n run the ID.EXE and not OffHook \n" );
return 0;
}
if ( ( argv[1][0] == 'o') || ( argv[1][0] == 'O') )
OffHookFlag = 1;
else
OffHookFlag = 0;
r = LoadDRV();
if ( r != 0 ) {
printf ( "Load driver fail! ErrCode = %d", r);
return r;
}
if ( IsSupportCallerID() == 0 ) {
printf("This Card is not support Caller-ID !\n");
exit(0);
}
GetSysInfo( &TmpIni);
lstrcpy( VocName, TmpIni.cbDir );
lstrcat( VocName, "voc\\" );
lstrcat ( VocName, "hello.voc" );
fp = fopen ( VocName, "r" );
if ( fp == NULL ) {
printf ( "Voice File not Exist!\n", VocName );
exit(0);
}
fclose (fp);
ChannelCount = CheckValidCh();
for ( i = 0; i < ChannelCount; i ++ ) {
ChType[i] = CheckChType(i);
ChStatus[i] = 0;
}
r = EnableCard(ChannelCount, 4096*8 ); // 32 K
if ( r != 0 ) {
FreeDRV();
printf ( "Enable Card Fail! ErrCode = %d\n", r );
return 0;
}
printf ( "T5ID card Caller-ID Demo!\n" );
printf ( "Dong Jin. 1997.11\n" );
printf ( "waiting for call ......\n\n" );
while ( 1 ) {
if ( kbhit() )
if ( getch() == 0x1b )
break;
TestCallerID();
}
DisableCard();
FreeDRV();
return 1;
}
void MesgHead ( int ChannelNo )
{
if ( ChType[ChannelNo] == CHTYPE_TRUNK )
printf ( "[%02d:TRUNK] ", ChannelNo );
else
printf ( "[%02d: USER] ", ChannelNo );
}
void TestCallerID()
{
WORD i;
int r;
for ( i = 0; i < ChannelCount; i ++ ) {
switch ( ChStatus[i] ) {
case 0: // init for get Caller-ID
ResetCallerIDBuffer(i);
InitDtmfBuf(i);
ChStatus[i] = 5;
break;
case 5:
if ( RingDetect(i) ) {
if ( ChType[i] == CHTYPE_TRUNK ) {
// if get caller-id is DTMF , then start work
if ( GetCallerIDDtmf(i,IDStr[i]) != 0 ) {
printf ( "Ring [ DTMF ]. The Caller-ID is [%s]!\n", IDStr[i] );
ChStatus[i] = 15;
}
else { // suppose it is FSK
StartTimer(i,TEST_CLOCK);
//StartTimer(i);
MesgHead (i);
printf ( "Ring. Start get caller-ID!\n" );
ChStatus[i] = 10;
}
}
else {
ChStatus[i] = 20;
}
}
break;
case 10:
if ( ElapseTime(i,TEST_CLOCK) > 500 ) { // 100 is 1 second
MesgHead (i);
printf ( "Get caller-Id Time Out! start work !\n" );
ChStatus[i] = 15; // time-out
// next is to print the raw data
PrintRaw ( i );
}
r = GetCallerIDStr (i,IDStr[i]);
if ( r == 3 ) { // OK
MesgHead (i);
printf ( "[ FSK ]. The Caller-ID is [%s]!\n", IDStr[i] );
ChStatus[i] = 15; // get Caller-ID OK
// next is to print the raw data
// PrintRaw ( i );
}
break;
case 15:
if ( OffHookFlag ) {
OffHook (i);
StartSigCheck(i);
ChStatus[i] = 20;
}
else
ChStatus[i] = 40;
break;
case 20:
MesgHead (i);
printf ( "Start play file!\n" );
StartPlayFile(i, VocName,0 );
ChStatus[i] = 30;
break;
case 30:
if ( ChType[i] == CHTYPE_USER ) {
if ( !RingDetect(i) ) {
MesgHead (i);
printf ( "User on hook.!\n" );
ChStatus[i] = 40;
}
}
else {
if ( ReadCheckResult(i,PLAY_CHECK) == R_BUSY ) {
ChStatus[i] = 40;
MesgHead (i);
printf ( "Busy Tone detect.!\n" );
}
if ( CheckPlayEnd(i) ) {
ChStatus[i] = 40;
MesgHead (i);
printf ( "Trunk play end.!\n" );
}
}
break;
// hang up and stop work
case 40:
if ( OffHookFlag ) {
ChStatus[i] = 50;
}
else {
MesgHead(i);
printf ( "Delay for 5 seconds!\n" );
StartTimer(i,TEST_CLOCK);
ChStatus[i] = 45;
}
break;
case 45:
if ( ElapseTime(i,TEST_CLOCK) > 500 ) { // 100 is 1 second
ChStatus[i] = 50;
}
break;
case 50:
if ( ChType[i] == CHTYPE_TRUNK ) {
HangUp(i);
}
MesgHead (i);
printf ( "END!\n\n" );
StopPlayFile ( i );
ChStatus[i] = 0;
break;
}
}
}
int GetCallerIDDtmf (WORD ChannelNo, char far *IDStr)
{
short c;
int i;
i = 0;
c = GetDtmfCode(ChannelNo);
while ( c!= NODTMF ) {
if ( c == 10 )
IDStr[i++] = '0';
else if ( ( c > 0 ) && ( c < 10 ) )
IDStr[i++] = '0' + c;
c = GetDtmfCode(ChannelNo);
}
IDStr[i] = '\0';
return i;
}
void PrintRaw ( WORD i )
{
int r;
int j;
r = GetCallerIDStr (i,IDStr[i]);
printf ( " Caller-ID = [%s], r = %d\n", IDStr[i], r );
r = GetCallerIDRawStr (i,IDStr[i]);
printf ( " The Raw Data is [");
j = 0;
while ( (IDStr[i][j] != 0) && (j<128) ) {
printf ( "%x ", IDStr[i][j] );
j ++ ;
}
printf ( "]\n" );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -