/* DEMO8.C On PC run 7188.exe,download demo8.exe to I-7188 and run demo8.exe operation: CTRL_A: set modem to auto answer mode CTRL_B: Init modem,and set to auto answer mode CTRL_C: HandUp phone CTRL_D: Dial phone(key in phone number first) CTRL_E: Answer phone CTRL_F: Back to data transfer mode data transfer mode -----------> command mode ESC <------------ CTRL_F ESC: HandUp and quit. Before connect modem in COMMAND mode,after connect modem in data transfer mode. In COMMAND mode ,the command is send to MODEM,and modem process these command. In data transfer mode,modem will bypass all command or data out to telphone line. */ #include #include #include"..\lib\7188.h" #include"uart7.h" #include"modem.h" #define CTRL_A 1 #define CTRL_B 2 #define CTRL_C 3 #define CTRL_D 4 #define CTRL_E 5 #define CTRL_F 6 int fInitModem=0; int fConnect=0; /* 0:modem is not connected, 1:is connected */ int fMode=0; /* 0:modem in command mode, 1:modem in data mode */ char PhoneNumber[12]={0}; char DataBuf[80]; char DataBuf1[80]; int DataIdx=0; main() { int quit=0; int data; fDebugMode=1; TimerOpen(); _InstallCom1(57600L,8,0,1); while(!quit){ if(kbhit4()){ data=getch4(); if(!fMode){ /* In modem Command mode */ switch(data){ case CTRL_A: /* Set to Auto Answer mode */ if(!fInitModem){ fInitModem=!OpenModem(); } if(fInitModem){ AutoAnswer(); } break; case CTRL_B: /* Init Modem */ fInitModem=!OpenModem(); break; case CTRL_C: /* handup phone */ if(fInitModem){ HangUp(); fConnect=0; fMode=0; printf("handup phone\n"); } break; case CTRL_D: /* Dial phone */ printf("Enter the phone number:"); scanf("%s",PhoneNumber); if(0==SendTel(PhoneNumber)){ fConnect=1; fMode=1; printf("Dial:[connect] fmode=1,fConnect=1\n"); } else { fConnect=0; fMode=0; printf("Dial:[NO connect] fmode=0,fConnect=0\n"); } break; case CTRL_E: if(fInitModem){ AnswerPhone(); fConnect=1; fMode=1; } break; case CTRL_F: /* change to data mode */ if(fConnect){ SendToModem("ATO^M"); fMode=1; } break; case 27: /* ESC */ if(fConnect){ printf("handup phone\n"); HangUp(); } quit=1; break; default: _ToCom1(data); break; } } else { if(data==27){ SendToModem("~~~+++~~~"); GetModemResponse(DataBuf); fMode=0; printf("\nBack to COMMAND mode\n"); } else { _ToCom1(data); if(data=='\r' && fConnect) _ToCom1('\n'); /* for line mode test */ } } } while(_IsCom1()){ data=_ReadCom1(); putchar(data); DataBuf1[DataIdx]=data; if(data=='\n'){ DataBuf1[DataIdx]=0; DataIdx=0; /* printf("**[%s]\n",DataBuf1); */ if(!fConnect){ if(!strncmp(DataBuf1,"CONNECT",7)){ fConnect=1; fMode=1; printf("[connect] fmode=1,fConnect=1\n"); } } if(fConnect){ if(!strncmp(DataBuf1,"NO CARRIER",10)){ fConnect=0; fMode=0; printf("[was hand up] fmode=0,fConnect=0\n"); } } } else { DataIdx++; if(DataIdx>=80) DataIdx=0; } } } _RestoreCom1(); TimerClose(); }