home *** CD-ROM | disk | FTP | other *** search
- /*
- This program will answer an incomming call in the background, send a brief
- message to the other caller, and then hang-up and wait for the next call.
- In order to "unload" this TSR, the user should hit ALT-U. Note that the
- different functions of this program are broken into "states" and that only
- one state is executed each time that the function is invoked by the timer
- tick.
- */
-
- #include <stdio.h>
- #include "resproto.h"
- #include "eclproto.h"
- #include "tsr.h"
- #include "xc.h"
- #include "im.h"
-
- #define SCAN_U 0X16
-
- /* Answer COMM States */
- #define COMMINIT 0 /* Initialize the serial port */
- #define OPENMODEM 1 /* Initialize the modem */
- #define WAIT_RING 2 /* Wait for the phone to ring */
- #define SETTIMER 3 /* Wait for the line to stablize after making a connection */
- #define SENDINFO 4 /* Send messag to other modem */
- #define COMMHANGUP 5 /* Hang-up the line */
- #define COMMEXIT 6 /* exit the Comm library */
- #define COMMFIN 7 /* Unload the TSR */
-
- extern int _hotkey_hit;
-
- void res_answ(void); /* TSR to answer the phone */
- void display_message(char *buffer);
-
- /* program globals */
- int comm_state = COMMINIT; /* Holds the current state of the TSR */
- char buffer[50]="";
- char sav_buf[320];
- int s_len;
- int port = COM1;
-
-
- void main(void)
-
- {
- unsigned int r_sig1 = 0X9EDC;
- int stat;
- int toggle = 0X08; /* ALT key */
- int sc_code = SCAN_U; /* U key */
- int pars = 500;
-
-
-
- stat = tsrloaded(r_sig1);
- if (stat!=1) { /* tsr not loaded */
- stat = inittsr2(toggle,sc_code,res_answ,pars,r_sig1,SIG,(void far *)NULL);
- if (stat!=0) { /* TSR not loaded */
- switch (stat) {
- case 1:
- printf("\nNot enough memory to satisfy PARS request\n");
- break;
- case 2:
- printf("\nNot compatible with MS/PC DOS system\n");
- break;
- default:
- printf("\nError installing TSR, stat = %d\n",stat);
- break;
- }
- }
- else
- printf("\nTSR ALREADY LOADED : Hit ALT-U to Unload\n");
- }
- }
-
- void res_answ()
- {
- int stat;
-
- /* Unload TSR if ALT-U hit */
- if (_hotkey_hit) {
- comm_state = COMMEXIT;
- _hotkey_hit = 0;
- }
-
- switch (comm_state) {
- case COMMINIT:
- savwindo(23,0,24,79,sav_buf);
- display_message("Initializing COMM port...");
- stat = xc_entr(4);
- if (stat == 0) {
- xc_link(port,0);
- xc_dtr(port,1);
- xc_rts(port,1);
- xc_init(port,BAUD1200,NOPAR,DATA8,STOP1);
- xct_link();
- comm_state = OPENMODEM;
- }
- else {
- printf("Error during xc_entr()");
- comm_state = COMMFIN;
- }
- break;
-
- case OPENMODEM:
- display_message("OPENING MODEM ...");
- stat = im_open(port);
- sprintf(buffer,"MODEM OPEN STATUS = %d",stat);
- display_message(buffer);
- im_spkr(port,IM_SPKR_OFF);
- xct_set(10800); /* 10 min countdown */
- display_message("WAITING FOR PHONE TO RING... HIT ALT-U TO EXIT");
- comm_state = WAIT_RING;
- break;
-
- case WAIT_RING:
- if ((xc_ri(port))&&(xct_test())) { /* phone is ringing */
- display_message("PHONE RANG! NOW WAIT IN BETWEEN RINGS...");
- while(stat=xc_ri(port))
- ;
- xct_pend(8);
- display_message("ANSWER THE PHONE...");
- if((stat = im_answ(port))>0) {
- sprintf(buffer,"CONNECTED AT BAUD RATE : %d",stat);
- display_message(buffer);
- s_len = strlen(buffer);
- comm_state = SETTIMER;
- }
- else {
- sprintf(buffer,"UNABLE TO CONNECT, stat = %d",stat);
- display_message(buffer);
- comm_state = COMMHANGUP;
- }
- }
- else {
- if (!(xct_test())) {
- display_message("TIMEOUT PERIOD HAS EXPIRED");
- comm_state = COMMEXIT;
- }
- }
- break;
-
- case SETTIMER:
- xct_set(18);
- comm_state = SENDINFO;
- break;
-
- case SENDINFO:
- if (!(xct_test())) {
- display_message("Sending Info to other PC");
- stat = xc_put(port,buffer,&s_len);
- comm_state = COMMHANGUP;
- }
- break;
-
- case COMMHANGUP:
- display_message("HANGUP THE PHONE AND WAIT FOR NEXT CALL... HIT ALT-U TO EXIT");
- im_hangu(port);
- xct_set(10800); /* 10 min countdown */
- comm_state = WAIT_RING;
- break;
-
- case COMMEXIT:
- xct_unlk();
- display_message("HANGUP THE PHONE AND EXIT...");
- im_hangu(port);
- im_close(port);
- xc_dtr(port,0);
- xc_rts(port,0);
- xc_unlk(port);
- comm_state = COMMFIN;
- break;
-
- case COMMFIN:
- xc_exit();
- stat = freetsr();
- rstwindo(23,0,24,79,sav_buf);
- break;
- }
- }
-
-
-
-
- void display_message(char *buffer)
- {
- scroll_vid(1,15,1,23,0,24,79,0); /* scroll up 1 line */
- savcur();
- loc_cur(24,0);
- printf("%s",buffer);
- rstcur();
- }