#include #include #include "typedef.h" #include "zyascii.h" #include "zyl2.h" void main(void) { FILE *fp; int c; int nReadNum; int nResult; char szDTMF[5] = { 0,0,0,0,0}; char szVFHeader[16] = { 'Z', 'y', 'X', 'E', 'L', 0x02, 0x00, 0x00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00, 0x00, 0x00}; char szTempBuffer[512]; char szEndVoice[3] = { DLE, ETX, 0}; printf( "\r\nZyXEL Voice DEMO sample . \r\n"); printf( "You must install FOSSIL driver before run this sample. \r\n"); printf( "Use the another phone to call the modem. \r\n"); nResult = ZyOpenCommPort( COM2, 19200L, 'N', 8, 1 ); if ( nResult < IDR_SUCCESS ) { printf( "Failed to open the port. Status = %d\n", nResult ); exit( 1 ); } printf( "open the port successful. Status = %d\n", nResult); if (!initZyModem(COM2, FC_HARDWARE)) exit(1); printf( "Initialize modem successfully\r\n"); printf( "Start to DEMO \r\n"); printf( "Press the '1' phone key to record voice \n\r"); printf( "Press the '2' phone key to listen voice \n\r"); printf( "Press the '3' phone key to test DTMF generate \n\r"); startVoicePlay(COM2, IDV_ADPCM2, IDV_LINE); for(;;) { ZyWriteFileWithDtmf(COM2, "greet1.dat", 1, szDTMF); nResult = (int) szDTMF[0]; switch(nResult) { case '1': ZyWriteByteCommand(COM2, szEndVoice, ON); printf("%s DTMF code had been detected\n\r",szDTMF); ZyWriteCommand(COM2, "AT+VTS=[933,0,10]\0", ON); ZyWriteCommand(COM2, "AT+VRX\0", ON); if ((fp = fopen("test.dat", "w+b")) == NULL) exit (1); fwrite((NPSTR) szVFHeader, sizeof (char), 16, fp); /* write header */ while (0 != (nReadNum = (int) ZyReadMemoryBlock(COM2, szTempBuffer, 256))) { fwrite((NPSTR) szTempBuffer, sizeof(char), nReadNum, fp); if (nReadNum < 256) break; } /* disconnectVoice(COM2); */ fclose(fp); break; case '2': ZyWriteByteCommand(COM2, szEndVoice, ON); printf("%s DTMF code had been detected\n\r",szDTMF); ZyWriteCommand(COM2, "AT+VTS=[933,0,10]\0", ON); ZyWriteCommand(COM2, "AT+VTX\0",ON); ZyWriteFileWithDtmf(COM2, "greet.dat", 1, szDTMF); ZyWriteByteCommand(COM2, szEndVoice, ON); if (szDTMF[0] != 'c') { nResult = 0; break; } else { nResult = szDTMF[0]; /*disconnectVoice(COM2); */ break; } case '3': case 's': case 'b': case 'q': case 'c': ZyWriteByteCommand(COM2, szEndVoice, ON); printf("%s DTMF code had been detected\n\r",szDTMF); ZyWriteCommand(COM2, "AT+VTS=[933,0,10]\0", ON); break; default: nResult = 0; break; } if (nResult != 0) break; ZyWriteCommand(COM2, "AT+VTX\0",ON); } ZyWriteCommand (COM2, "AT+VBT=2", ON); printf("Generate DTMF DEMO, Press the 0-9 and * # on keyboard \n\r"); printf("to generate the DTMF code \n\r"); while ((c = getch()) != ESC) { switch(c) { case 49: ZyGenerateDtmf (COM2, '1'); printf("DTMF 1 is generating\n\r"); break; case 50: ZyGenerateDtmf (COM2, '2'); printf("DTMF 2 is generating\n\r"); break; case 51: ZyGenerateDtmf (COM2, '3'); printf("DTMF 3 is generating\n\r"); break; case 52: ZyGenerateDtmf (COM2, '4'); printf("DTMF 4 is generating\n\r"); break; case 53: ZyGenerateDtmf (COM2, '5'); printf("DTMF 5 is generating\n\r"); break; case 54: ZyGenerateDtmf (COM2, '6'); printf("DTMF 6 is generating\n\r"); break; case 55: ZyGenerateDtmf (COM2, '7'); printf("DTMF 7 is generating\n\r"); break; case 56: ZyGenerateDtmf (COM2, '8'); printf("DTMF 8 is generating\n\r"); break; case 57: ZyGenerateDtmf (COM2, '9'); printf("DTMF 9 is generating\n\r"); break; case 48: ZyGenerateDtmf (COM2, '0'); printf("DTMF 0 is generating\n\r"); break; case 42: ZyGenerateDtmf (COM2, '*'); printf("DTMF * is generating\n\r"); break; case 35: ZyGenerateDtmf (COM2, '#'); printf("DTMF # is generating\n\r"); break; default: printf("NONE DTMF generat\n\r"); break; } } c = ZyWriteVoiceFile(COM2, "test.dat", IDV_ADPCM2, IDV_SPEAKER); if (!c) printf("Play voice file successfully !\n\r"); else printf("Play voice file error !\n\r"); ZyResetModem(COM2); ZyCloseCommPort(COM2); exit(0); }