home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts310b5 / m7rec.c < prev    next >
C/C++ Source or Header  |  1991-11-28  |  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. #ifdef __TOS__
  49. /* #pragma warn -sus */
  50. #else
  51. #include <fcntl.h>
  52. #endif
  53. #include <stdio.h>
  54.  
  55. #include "bink.h"
  56. #include "msgs.h"
  57. #include "com.h"
  58. #include "sbuf.h"
  59. #include "defines.h"
  60. #include "ascii.h"
  61. #include "vfossil.h"
  62.  
  63. int cdecl MRInit (XMARGSP, int);
  64. int cdecl MREnd (XMARGSP, int);
  65. int cdecl MRSendNak (XMARGSP);
  66. int cdecl MRWaitAck (XMARGSP);
  67. int cdecl MRWaitChar (XMARGSP);
  68. int cdecl MRWaitOkCk (XMARGSP);
  69.  
  70. STATES Modem7_Receiver[] = {
  71.    { "MRInit",  MRInit },
  72.    { "MREnd",  MREnd },
  73.    { "MR0",  MRSendNak },
  74.    { "MR1",  MRWaitAck },
  75.    { "MR2",  MRWaitChar },
  76.    { "MR3",  MRWaitOkCk }
  77. };
  78.  
  79. int cdecl MRInit (args, start_state)
  80. XMARGSP args;
  81. int start_state;
  82. {
  83.    args->tries = 0;
  84.    return (start_state);
  85. }
  86.  
  87. int cdecl MREnd (args, cur_state)
  88. XMARGSP args;
  89. int cur_state;
  90. {
  91.    args->result = cur_state;
  92.    return (cur_state);
  93. }
  94.  
  95. int cdecl MRSendNak (args)
  96. XMARGSP args;
  97. {
  98.    if (args->tries >= 10)
  99.       return (FNAME_ERR);
  100.  
  101.    args->fptr = args->filename;
  102.  
  103.    SENDBYTE (NAK);
  104.    ++(args->tries);
  105.    return (MR1);
  106. }
  107.  
  108. int cdecl MRWaitAck (args)
  109. XMARGSP args;
  110. {
  111.    long MR1Timer;
  112.    int in_char;
  113.  
  114.    MR1Timer = timerset (1000);
  115.    while (!timeup (MR1Timer))
  116.       {
  117.       if ((in_char = PEEKBYTE ()) >= 0)
  118.          {
  119.          (void) TIMED_READ (0);
  120.          switch (in_char)
  121.             {
  122.             case ACK:
  123.                return (MR2);
  124.  
  125.             case EOT:
  126.                args->result = SUCCESS_EOT;
  127.                return (SUCCESS_EOT);
  128.             }
  129.          }
  130.       else
  131.          {
  132.          if (!CARRIER)
  133.             return (CARRIER_ERR);
  134.          else
  135.             time_release ();
  136.          }
  137.       }
  138.  
  139.    return (MR0);
  140. }
  141.  
  142. int cdecl MRWaitChar (args)
  143. XMARGSP args;
  144. {
  145.    int in_char;
  146.    unsigned char check;
  147.    char *p;
  148.  
  149.    in_char = TIMED_READ (10);
  150.    switch (in_char)
  151.       {
  152.       case -1:
  153.          return (MR0);
  154.  
  155.       case EOT:
  156.          return (SUCCESS);
  157.  
  158.       case SUB:
  159.          for (p = args->filename, check = SUB; p != args->fptr; p++)
  160.             check += (unsigned char) *p;
  161.          SENDBYTE (check);
  162.          return (MR3);
  163.  
  164.       case 'u':
  165.          return (MR0);
  166.  
  167.       default:
  168.          *args->fptr++ = (char) (in_char & 0xff);
  169.          SENDBYTE (ACK);
  170.          return (MR2);
  171.       }
  172.  
  173. }
  174.  
  175. int cdecl 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.