home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / M7REC.C < prev    next >
C/C++ Source or Header  |  1990-05-14  |  6KB  |  201 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                  This module was written by Bob Hartman                  */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                BinkleyTerm Modem7 Receiver State Machine                 */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n132.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46.  
  47. /* System include files */
  48. #include <fcntl.h>
  49. #include <stdio.h>
  50.  
  51. /* Local include files */
  52. #include "defines.h"
  53. #include "com.h"
  54. #include "xfer.h"
  55. #include "zmodem.h"
  56. #include "keybd.h"
  57. #include "sbuf.h"
  58. #include "sched.h"
  59. #include "externs.h"
  60. #include "prototyp.h"
  61.  
  62. int MRInit (XMARGSP, int);
  63. int MREnd (XMARGSP, int);
  64. int MRSendNak (XMARGSP);
  65. int MRWaitAck (XMARGSP);
  66. int MRWaitChar (XMARGSP);
  67. int MRWaitOkCk (XMARGSP);
  68.  
  69. STATES Modem7_Receiver[] = {
  70.    { "MRInit",  MRInit },
  71.    { "MREnd",  MREnd },
  72.    { "MR0",  MRSendNak },
  73.    { "MR1",  MRWaitAck },
  74.    { "MR2",  MRWaitChar },
  75.    { "MR3",  MRWaitOkCk }
  76. };
  77.  
  78. int MRInit (args, start_state)
  79. XMARGSP args;
  80. int start_state;
  81. {
  82.    args->tries = 0;
  83.    return (start_state);
  84. }
  85.  
  86. int MREnd (args, cur_state)
  87. XMARGSP args;
  88. int cur_state;
  89. {
  90.    args->result = cur_state;
  91.    return (cur_state);
  92. }
  93.  
  94. int MRSendNak (args)
  95. XMARGSP args;
  96. {
  97.    if (args->tries >= 10)
  98.       return (FNAME_ERR);
  99.  
  100.    args->fptr = args->filename;
  101.  
  102.    SENDBYTE (NAK);
  103.    ++(args->tries);
  104.    return (MR1);
  105. }
  106.  
  107. int MRWaitAck (args)
  108. XMARGSP args;
  109. {
  110.    long MR1Timer;
  111.    int in_char;
  112.  
  113.    MR1Timer = timerset (1000);
  114.    while (!timeup (MR1Timer))
  115.       {
  116.       if ((in_char = PEEKBYTE ()) >= 0)
  117.          {
  118.          (void) TIMED_READ (0);
  119.          switch (in_char)
  120.             {
  121.             case ACK:
  122.                return (MR2);
  123.  
  124.             case EOT:
  125.                args->result = SUCCESS_EOT;
  126.                return (SUCCESS_EOT);
  127.             }
  128.          }
  129.       else
  130.          {
  131.          if (!CARRIER)
  132.             return (CARRIER_ERR);
  133.          else
  134.             time_release ();
  135.          }
  136.       }
  137.  
  138.    return (MR0);
  139. }
  140.  
  141. int MRWaitChar (args)
  142. XMARGSP args;
  143. {
  144.    int in_char;
  145.    unsigned char check;
  146.    char *p;
  147.  
  148.    in_char = TIMED_READ (10);
  149.    switch (in_char)
  150.       {
  151.       case -1:
  152.          return (MR0);
  153.  
  154.       case EOT:
  155.          return (SUCCESS);
  156.  
  157.       case SUB:
  158.          for (p = args->filename, check = SUB; p != args->fptr; p++)
  159.             check += (unsigned char) *p;
  160.          SENDBYTE (check);
  161.          return (MR3);
  162.  
  163.       case 'u':
  164.          return (MR0);
  165.  
  166.       default:
  167.          *args->fptr++ = (char) (in_char & 0xff);
  168.          SENDBYTE (ACK);
  169.          return (MR2);
  170.       }
  171.  
  172.    return (SUCCESS);
  173. }
  174.  
  175. int MRWaitOkCk (args)
  176. XMARGSP args;
  177. {
  178.    int in_char;
  179.  
  180.    in_char = TIMED_READ (10);
  181.    if (in_char == ACK)
  182.       {
  183.       args->result = SUCCESS;
  184.       return (SUCCESS);
  185.       }
  186.    
  187.    return (MR0);
  188. }
  189.  
  190. int Modem7_Receive_File (filename)
  191. char *filename;
  192. {
  193.    XMARGS batch;
  194.    int res;
  195.  
  196.    batch.result = 0;
  197.    batch.filename = filename;
  198.    res = state_machine (Modem7_Receiver, &batch, 2);
  199.    return (res);
  200. }
  201.