home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / ISC365 / MODEM.CPP < prev    next >
C/C++ Source or Header  |  1993-07-26  |  4KB  |  155 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //                                                                       //
  3. //            File: modem.cpp                                            //
  4. //                  (project version).                                   //
  5. //            started on: 24/2/92                                        //
  6. //                                                                       //
  7. ///////////////////////////////////////////////////////////////////////////
  8. //                                                                       //
  9. //                                                                       //                                                                     //
  10. ///////////////////////////////////////////////////////////////////////////
  11.  
  12. #include <bios.h>;   // biostime.
  13. #include <dos.h>;    // inportb, delay.
  14. #include "modem.h";  // MODEM.
  15.  
  16. // extending the init.
  17. //
  18. void MODEM::extended_init(void)
  19. {
  20.     // turn on DTR, RTS.
  21.     //
  22.     set_controls(0x3);
  23. }
  24.  
  25. // destructor.
  26. //
  27. MODEM::~MODEM()
  28. {
  29.     // turn off DTR, RTS.
  30.     //
  31.     set_controls(0);
  32. }
  33.  
  34. void MODEM::flow_check(void)
  35. {
  36.     // check flow control.
  37.     // if both DSR && CTS are activated:- flow is enabled.
  38.     //
  39.     flow_enabled= ((get_MSR()& 0x30)== 0x30)?TRUE: FALSE;
  40. }
  41.  
  42. void MODEM::wait(unsigned miliseconds)
  43. {
  44.     unsigned long start= biostime(0, 0L);
  45.  
  46.     do {
  47.        if (!(get_MSR()& 0x80))
  48.           return;
  49.     } while ((biostime(0, 0L)- start* 55)< miliseconds);
  50. }
  51.  
  52. void MODEM::disconnect( BOOLEAN boot_enable,
  53.                         const char *escape_sequence,
  54.                         const char *disconnect_string,
  55.                         const char *disconnect_reply_string,
  56.                         const unsigned timeout)
  57. {
  58.     INDEX i;
  59.  
  60.     empty_io_buffers();
  61.  
  62.     for (i=0; escape_sequence[i]!='\x0'; i++) {
  63.         if (escape_sequence[i]!='~')
  64.            *this<< escape_sequence[i];
  65.         else
  66.             delay (500);
  67.     }
  68.     for (i=0; disconnect_string[i]!='\x0'; i++) {
  69.         if (disconnect_string[i]!='~')
  70.            *this<< disconnect_string[i];
  71.         else
  72.             delay(500);
  73.     }
  74.  
  75.     if ((get_MSR()& 0x80)) {
  76.        set_controls(0);
  77.        wait (2000);
  78.        set_controls(0x3);
  79.     }
  80.     else { // disconnected...
  81.          empty_io_buffers();
  82.          return;
  83.     }
  84.  
  85.  
  86.     // WAIT FOR OK_STRING.
  87.     long begin_clock, timeout_begin_clock;
  88.     BYTE temp;
  89.  
  90.     i= 0;
  91.     timeout_begin_clock= begin_clock= biostime(0, 0L);
  92.  
  93.     do {
  94.        if (!disconnect_reply_string[i]) // finished receiving OK string.
  95.           break;
  96.  
  97.        if (*this>> temp) { // if a byte is available check it.
  98.           if (temp== disconnect_reply_string[i])
  99.              i++;
  100.           else {
  101.                i= 0;
  102.                if (temp== disconnect_reply_string[i]) // could be that the char was the start of the string...
  103.                   i++;
  104.           }
  105.  
  106.           begin_clock= biostime(0,0L); // a byte was received (reset pend_ticks timeout).
  107.        }
  108.     } while (((biostime(0,0L)- begin_clock)< timeout)&&
  109.              ((biostime(0,0L)- timeout_begin_clock)< timeout));
  110.  
  111.     if (disconnect_reply_string[i]) { // did not receive OK string.
  112.        // now, if line is still up, boot!
  113.        //
  114.        if ((get_MSR()& 0x80))
  115.           if (boot_enable)
  116.              ; // boot();
  117.     }
  118. }
  119.  
  120. void MODEM::msr_int(const BYTE msr)
  121. {
  122.     if ((msr& 0x44)== 0x44) // ring is up and the interrupt is because of it.
  123.        ring_int (msr);
  124.  
  125.     if (msr& 0x3)   // DSR or CTS changed!
  126.        modem_status_change (msr);
  127.  
  128.     if ((msr& 0x8)) // DCD changed.
  129.        dcd_status_change (msr);
  130. }
  131.  
  132. void MODEM::dcd_status_change(BYTE /* msr */)
  133. {
  134.     // if DCD or CTS changed...
  135.  
  136.     // to be overloaded.
  137. }
  138.  
  139. void MODEM::modem_status_change(BYTE /* msr */)
  140. {
  141.     // if DSR or CTS changed...
  142.  
  143.     // to be overloaded.
  144. }
  145.  
  146. void MODEM::ring_int(BYTE /* msr */)
  147. {
  148.     // to be overloaded.
  149. }
  150.  
  151. BYTE MODEM::get_MSR(void)
  152. {
  153.     return ((BYTE) inportb(com_port+ MSR));
  154. }
  155.