SERMODEM.C 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "global.h"
  16. #include <time.h>
  17. #include "serial.h"
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <bios.h>
  21. #include "port.h"
  22. #include "sermodem.h"
  23. #include "sersetup.h"
  24. char initstring[100];
  25. char dialstring[60];
  26. boolean pulse=false;
  27. char hangupstring[60];
  28. /*
  29. =================
  30. =
  31. = hangup_modem
  32. =
  33. =================
  34. */
  35. void hangup_modem ( void )
  36. {
  37. printf ("Dropping DTR\n");
  38. OUTPUT( uart + MODEM_CONTROL_REGISTER
  39. , INPUT( uart + MODEM_CONTROL_REGISTER ) & ~MCR_DTR );
  40. delay (1250);
  41. OUTPUT( uart + MODEM_CONTROL_REGISTER
  42. , INPUT( uart + MODEM_CONTROL_REGISTER ) | MCR_DTR );
  43. ModemCommand("+++");
  44. delay (1250);
  45. if (hangupstring [0] != EOS)
  46. ModemCommand(hangupstring);
  47. else
  48. {
  49. printf ("Warning: Null Hangup string. Using default.\n");
  50. ModemCommand("ATH0");
  51. }
  52. delay (1250);
  53. while (read_byte () != -1)
  54. ;
  55. }
  56. /*
  57. ==============
  58. =
  59. = ModemCommand
  60. =
  61. ==============
  62. */
  63. void ModemCommand (char *str)
  64. {
  65. int i;
  66. char *ptr;
  67. printf ("Modem command : ");
  68. ptr = str;
  69. for (i = 0; i < strlen (str); i++)
  70. {
  71. printf ("%c",*ptr);
  72. write_buffer (ptr++, 1);
  73. delay (100);
  74. }
  75. printf("\n");
  76. write_buffer ("\r",1);
  77. }
  78. /*
  79. ==============
  80. =
  81. = ModemResponse
  82. =
  83. = Waits for OK, RING, CONNECT, etc
  84. ==============
  85. */
  86. int ModemResponse (char *resp)
  87. {
  88. int c;
  89. int respptr;
  90. char response[80];
  91. do
  92. {
  93. printf ("Modem response: ");
  94. respptr=0;
  95. do
  96. {
  97. while ( bioskey(1) )
  98. {
  99. if ( (bioskey (0) & 0xff) == ESC)
  100. {
  101. printf ("\nModem response aborted.\n");
  102. return FALSE;
  103. }
  104. }
  105. c = read_byte ();
  106. if (c==-1)
  107. continue;
  108. if (c=='\n' || respptr == 79)
  109. {
  110. response[respptr] = 0;
  111. printf ("%s\n",response);
  112. break;
  113. }
  114. if (c>=' ')
  115. {
  116. response[respptr] = c;
  117. respptr++;
  118. }
  119. } while (1);
  120. } while (strncmp(response,resp,strlen(resp)));
  121. return TRUE;
  122. }
  123. /*
  124. =============
  125. =
  126. = InitModem
  127. =
  128. =============
  129. */
  130. int InitModem ( void )
  131. {
  132. if (initstring [0] != EOS)
  133. {
  134. ModemCommand (initstring);
  135. if (! ModemResponse ("OK"))
  136. return FALSE;
  137. }
  138. return TRUE;
  139. }
  140. /*
  141. =============
  142. =
  143. = Dial
  144. =
  145. =============
  146. */
  147. int Dial ( void )
  148. {
  149. char cmd[80];
  150. usemodem = true;
  151. InitModem ();
  152. printf ("Dialing %s\n", dialstring);
  153. if (pulse==true)
  154. sprintf (cmd,"ATDP%s", dialstring);
  155. else
  156. sprintf (cmd,"ATDT%s", dialstring);
  157. ModemCommand(cmd);
  158. return ModemResponse ("CONNECT");
  159. }
  160. /*
  161. =============
  162. =
  163. = Answer
  164. =
  165. =============
  166. */
  167. int Answer (void)
  168. {
  169. usemodem = true;
  170. InitModem ( );
  171. printf ("Waiting for ring...\n");
  172. if (! ModemResponse ("RING"))
  173. return FALSE;
  174. ModemCommand ("ATA");
  175. return ModemResponse ("CONNECT");
  176. }