home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- These C++ classes are copyright 1990, by William Herrera.
- All those who put this code or its derivatives in a commercial product MUST
- mention this copyright in their documentation for users of the products in
- which this code or its derivative classes are used. Otherwise, this code
- may be freely distributed and freely used for any purpose.
- ***************************************************************************/
-
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <dos.h>
-
- #include "modem.hpp"
-
- static int defaultport = 1;
-
- static const long defaultspeed = 38400L;
-
- // change spped to suit your application.
-
- int xgetch(void)
- {
- // ibm pc keyboard extended getch().
- int ch;
- return ( (ch = getch()) != 0 ) ? ch : getch() + 256;
- }
-
- int main(int argc, char ** argv)
- {
- char dialstr[256];
- int port;
- long speed;
- switch(argc)
- {
- case 2:
- // one argument--dial the argument
- strcpy(dialstr, argv[1]);
- port = defaultport;
- speed = defaultspeed;
- break;
- case 3:
- // two arguments--dial the second argument using first for port
- strcpy(dialstr, argv[2]);
- port = atoi(argv[1]);
- speed = defaultspeed;
- break;
- case 4:
- // first port, then speed, then number.
- strcpy(dialstr, argv[3]);
- port = atoi(argv[1]);
- speed = atoi(argv[2]);
- break;
- default:
- port = defaultport;
- speed = defaultspeed;
- dialstr[0] = 0;
- break;
- }
- modem m(port, speed, NOPAR, 1, 8, false);
- m.RaiseDTR();
-
- if(dialstr[0] != 0)
- {
- printf("Please pick up the phone. Press a key to continue:\n");
- xgetch();
- printf("Dialing %s. . .\n", dialstr);
- m.Dial(dialstr);
- printf("Please hit a key when dialing is complete.\n");
- xgetch();
- }
- else // go into open modem mode
- {
- printf("Current baud rate is %ld\n", m.GetSpeed());
- printf("Alt-B set baud rate, Alt-D dial, Alt-H hang up, Alt-S shell, Alt-X exit\n");
- while (1)
- {
- int c;
- if (kbhit())
- {
- c = xgetch();
- if(c == 301) // Alt-X to exit
- break; // break out of while(1) loop.
- char st[212];
- switch(c)
- {
- case 304: // Alt-B to set baud rate
- printf("\nCurrent baud rate is %ld\n",
- m.GetSpeed());
- printf("New baud rate (300-19200): ");
- if(scanf("%7s", st) == 1)
- {
- int s = atoi(st);
- if(s > 299 && s < 19201)
- m.SetSpeed(s);
- }
- break;
- case 288: // Alt-D to dial
- printf("\nNumber to dial: ");
- if(scanf("%64s", st) == 1)
- m.Dial(st);
- break;
- case 287: // Alt-S to shell
- printf("\nExternal DOS command: ");
- if(scanf("%211s", st) == 1)
- system(st);
- printf("\nExiting DOS . . . You may continue.\n");
- break;
- case 291: // Alt-H to hang up
- m.Escape();
- m.HangUp();
- break;
- default:
- m.Send(char(c)); // avoid sending (int) c
- break;
- } // switch(c)
- } // if kbhit()
- if ((c = m.GetChar()) != -1)
- putchar(c);
- } // while(1)
- } // else
- // Finished. Clean up line before exiting to prevent lockups.
- m.Escape();
- m.HangUp();
- m.Pause();
- return 0;
- }
-
-