home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s4.arc / RECEIVEM.MOD < prev    next >
Text File  |  1987-12-02  |  9KB  |  250 lines

  1. (*----------------------------------------------------------------------*)
  2. (*       Receive_Modem7_File --- Download file with Modem7/Telink       *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Receive_Modem7_File( Use_CRC: BOOLEAN );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Receive_Modem7_File                                  *)
  10. (*                                                                      *)
  11. (*     Purpose:    Downloads file to PC using Modem7/Telink batch       *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Receive_Modem7_File( Use_CRC : BOOLEAN);                      *)
  16. (*                                                                      *)
  17. (*           Use_CRC --- TRUE to use CRC checking;                      *)
  18. (*                       FALSE to use checksum checking.                *)
  19. (*                                                                      *)
  20. (*     Calls:   PibTerm_KeyPressed                                              *)
  21. (*              Async_Send                                              *)
  22. (*              Async_Receive                                           *)
  23. (*              Receive_Xmodem_File                                     *)
  24. (*                                                                      *)
  25. (*      Remarks:                                                        *)
  26. (*                                                                      *)
  27. (*         This routine performs the "echo file name" function of       *)
  28. (*         Modem7, required by batch Modem7 and Telink.                 *)
  29. (*                                                                      *)
  30. (*----------------------------------------------------------------------*)
  31.  
  32. CONST
  33.    MaxTry     = 10;
  34.    MaxNoise   = 5;
  35.  
  36. VAR
  37.    RFileName   : AnyStr;
  38.    Int_Ch      : INTEGER;
  39.    Int_Ch_Save : INTEGER;
  40.    Ch          : CHAR;
  41.    CheckSum    : INTEGER;
  42.    EndFName    : BOOLEAN;
  43.    I           : INTEGER;
  44.    Tries       : INTEGER;
  45.    NTries      : INTEGER;
  46.    J           : INTEGER;
  47.  
  48. (*----------------------------------------------------------------------*)
  49. (*              Check_The_KeyBoard --- Check for keyboard input         *)
  50. (*----------------------------------------------------------------------*)
  51.  
  52. PROCEDURE Check_The_KeyBoard;
  53.  
  54. BEGIN (* Check_The_KeyBoard *)
  55.  
  56.    Check_KeyBoard;
  57.  
  58.    IF Stop_Receive THEN
  59.       BEGIN
  60.          IF ( NOT Display_Status ) THEN
  61.             Display_Batch_Window;
  62.          WRITELN('  Alt_R pressed, transfer cancelled.');
  63.       END;
  64.  
  65. END   (* Check_The_KeyBoard *);
  66.  
  67. (*----------------------------------------------------------------------*)
  68.  
  69. BEGIN (* Receive_Modem7_File *)
  70.                                    (* Open display window for transfers  *)
  71.    Display_Batch_Window;
  72.                                    (* CRC except Modem7 Checksum *)
  73.  
  74.    Use_CRC     := Use_CRC AND ( Transfer_Protocol <> Modem7_Chk );
  75.  
  76.                                    (* Flag if keyboard halt or EOT *)
  77.                                    (* encountered                  *)
  78.    Stop_Receive := FALSE;
  79.                                    (* Purge reception to remove noise  *)
  80.    Async_Purge_Buffer;
  81.                                    (* Counts initial attempts to get stuff *)
  82.    Tries := 0;
  83.                                    (* Loop over file names         *)
  84.    REPEAT
  85.                                    (* Initialize checksum          *)
  86.       CheckSum := 0;
  87.                                    (* Initialize file name         *)
  88.       RFileName := '';
  89.                                    (* Try up to MaxTry times to    *)
  90.                                    (* send NAK to say we're ready  *)
  91.                                    (* for the file name.           *)
  92.       REPEAT
  93.                                    (* Send NAK                         *)
  94.          Async_Send( CHR( NAK ) );
  95.  
  96.                                    (* Get response -- should be ACK    *)
  97.                                    (* NOTE:  skip up to MaxNoise chars *)
  98.                                    (*        that are clearly garbage  *)
  99.                                    (*        in effort to get ACK      *)
  100.          NTries := 0;
  101.  
  102.          REPEAT
  103.             Async_Receive_With_TimeOut( One_Second , Int_Ch );
  104.             NTries := NTries + 1;
  105.             Check_Keyboard;
  106.          UNTIL ( Ntries > MaxNoise ) OR
  107.                ( Int_Ch <= 127     ) OR
  108.                Stop_Receive;
  109.  
  110.          Tries := Tries + 1;
  111.  
  112.       UNTIL( Int_Ch = ACK ) OR
  113.            ( Int_Ch = CAN ) OR
  114.            ( Int_Ch = EOT ) OR
  115.            ( Tries >= MaxTry ) OR
  116.            Stop_Receive;
  117.                                    (* Only continue if ACK found      *)
  118.  
  119.       Stop_Receive := ( Int_Ch <> ACK ) OR Stop_Receive;
  120.       Int_Ch_Save  := Int_Ch;
  121.  
  122.                                    (* Pick up characters of file name *)
  123.       IF ( NOT Stop_Receive ) THEN
  124.          REPEAT
  125.  
  126.             NTries    := 0;
  127.  
  128.             REPEAT
  129.                Async_Receive_With_TimeOut( One_Second , Int_Ch );
  130.                Check_The_KeyBoard;
  131.                NTries := NTries + 1;
  132.             UNTIL ( Int_Ch <> TimeOut ) OR
  133.                   ( NTries >= MaxTry  ) OR
  134.                   Stop_Receive;
  135.  
  136.             EndFName := ( Int_Ch = CAN     ) OR
  137.                         ( Int_Ch = EOT     ) OR
  138.                         ( Int_Ch = TimeOut ) OR
  139.                         ( Int_Ch = SUB     ) OR
  140.                         Stop_Receive;
  141.  
  142.             IF ( NOT EndFname ) THEN
  143.                BEGIN
  144.                   Async_Send( CHR( ACK ) );       (* echo 1 char at a time *)
  145.                   RFileName := RFileName + CHR( Int_Ch );
  146.                   Checksum  := ( Checksum + Int_Ch ) AND 255;
  147.                END;
  148.  
  149.          UNTIL EndFname
  150.       ELSE
  151.          Int_Ch  := TimeOut;
  152.  
  153.                                    (* Finished getting filename. *)
  154.       IF ( Int_Ch = SUB ) THEN
  155.          BEGIN  (* Filename received *)
  156.  
  157.                                    (* Send checksum *)
  158.  
  159.             CheckSum := ( CheckSum + Int_Ch ) AND 255;
  160.             Async_Send( CHR( CheckSum ) );
  161.  
  162.                                    (* Get response to checksum *)
  163.             NTries := 0;
  164.  
  165.             REPEAT
  166.                Async_Receive_With_TimeOut( One_Second , Int_Ch );
  167.                Check_The_KeyBoard;
  168.                NTries := NTries + 1;
  169.             UNTIL ( Int_Ch = ACK ) OR ( NTries >= MaxTry );
  170.  
  171.                                    (* If checksum OK, do transfer *)
  172.  
  173.             IF ( Int_Ch = ACK ) AND ( NOT Stop_Receive ) THEN
  174.                BEGIN
  175.  
  176.                   FOR  I := LENGTH( RFileName ) TO 11 DO
  177.                      RFileName := RFileName + ' ';
  178.  
  179.                   FileName := Trim( COPY( RFileName, 1, 8 ) );
  180.  
  181.                   IF COPY( RfileName, 9, 3 ) <> '   ' THEN
  182.                      FileName := FileName + '.' + COPY( RFileName, 9, 3 );
  183.  
  184.                                    (* Prevent overwrite of host mode *)
  185.                                    (* files.                         *)
  186.  
  187.                   IF Host_Mode THEN
  188.                      IF ( Privilege <> 'S' ) THEN
  189.                         Stop_Receive := Stop_Receive OR
  190.                                         Check_If_File_Exists( FileName ,
  191.                                                               Download_Dir_Path );
  192.  
  193.                                     (* Get the file. *)
  194.  
  195.                   IF ( NOT Stop_Receive ) THEN
  196.                      BEGIN
  197.  
  198.                         IF Display_Status THEN
  199.                            WRITELN('   Downloading: ' + FileName );
  200.  
  201.                         Write_Log( 'Downloading: ' + FileName , FALSE , FALSE );
  202.  
  203.                         Receive_Xmodem_File( Use_CRC );
  204.  
  205.                         TextColor     ( Menu_Text_Color );
  206.                         TextBackGround( BLACK );
  207.  
  208.                      END;
  209.  
  210.                END
  211.             ELSE
  212.                Stop_Receive := TRUE;
  213.  
  214.          END  (* Filename received *)
  215.       ELSE
  216.          Stop_Receive := TRUE;
  217.  
  218.    UNTIL Stop_Receive;
  219.                                    (* Restore batch window if needed *)
  220.    IF ( NOT Display_Status ) THEN
  221.       Display_Batch_Window;
  222.  
  223.    TextColor     ( Menu_Text_Color );
  224.    TextBackGround( BLACK );
  225.                                    (* Acknowledge EOT if received *)
  226.    IF ( Int_Ch_Save = EOT ) THEN
  227.       BEGIN
  228.  
  229.          Async_Send( CHR( ACK ) );
  230.  
  231.          Write_Log( 'Received EOT from host.' , FALSE , FALSE );
  232.  
  233.          WRITELN( ' ' );
  234.          WRITELN( '  Received EOT from host.' );
  235.  
  236.       END
  237.    ELSE
  238.       BEGIN
  239.  
  240.          Write_Log( 'Transfer cancelled.' , FALSE , FALSE );
  241.  
  242.          WRITELN( ' ' );
  243.          WRITELN( '  Transfer cancelled.' );
  244.  
  245.       END;
  246.  
  247.    End_Batch_Transfer;
  248.  
  249. END   (* Receive_Modem7_File *);
  250.