home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c-kermit / ckepage.ksc < prev    next >
Text File  |  2020-01-01  |  7KB  |  199 lines

  1. #!/usr/local/bin/kermit +
  2. ;
  3. ; File APAGE.KSC
  4. ; Version 4.0
  5. ;
  6. if < \v(version) 700000 end 1 C-Kermit 7.0 or later required.
  7.  
  8. ; TAP/IXO alphanumeric paging script for Kermit 95 and C-Kermit.
  9. ; Authors: F. da Cruz and C. Gianone, Columbia University, September 1996.
  10. ;
  11. ; For use with C-Kermit 7.0 / K95 1.1.17 or later.
  12. ; For a detailed explanation, consult "Using C-Kermit", 2nd Ed., pp.454-456.
  13. ;
  14. ; Version 2.0: July 1997:
  15. ;  1. To make TAPMSG fit into 1K for small C-Kermit versions.
  16. ;  2. Change END to STOP within SWITCH to work around bug.
  17. ; Version 3.0: September 1997:
  18. ;  1. Change STOP back to END because bug is fixed.
  19. ;  2. Added robustness.
  20. ; Version 4.0: August 1998:
  21. ;  1. Additional robustness - requires 2K command buffer.
  22. ;  2. Diagnostics.
  23. ;
  24. ; WARNING: Automatic redialing is restricted or illegal in some
  25. ; countries.  Modify the lines marked "IF LEGAL!" if below this applies
  26. ; in your location.
  27. ;
  28. ; TAPMSG, defined below, is an alphanumeric pager dialing script that
  29. ; implements the Telocator Alphanumeric Protocol (TAP), also known as IXO,
  30. ; for sending one-line alphanumeric pages.  TAPMSG assumes the connection
  31. ; to the paging service is already made.
  32. ;
  33. ; The APAGE macro makes a connection to the paging service and then uses
  34. ; TAPMSG to send the page.  Here is a SAMPLE; you will need to adjust it
  35. ; to work with your paging service.  Hint: Some paging services are very
  36. ; picky about modem configurations.  For example, experience has shown
  37. ; that to dial a certain service successfully with a USR 28.8 modem, just
  38. ; about all of the modem's features must be turned off prior to dialing.
  39. ; If you have trouble connecting to your service and staying connected,
  40. ; try removing the ";" from the left margin of the commands marked
  41. ; UNCOMMENT below.
  42. ;
  43. ; Replace values in lines marked (*) with the ones appropriate for your
  44. ; computer, modem, and paging service:
  45. ;
  46. ; UNIX-SPECIFIC INSTRUCTIONS:
  47. ; 1. Make sure C-Kermit 7.0 is installed and has permission to use
  48. ;    dialout devices.
  49. ; 2. Call this file "alphapage" or other name of your choice;
  50. ; 3. Change the first line show the full pathname of the C-Kermit 7.0
  51. :    executable;
  52. ; 4. Give this file execute permission ("chmod +x alphapage");
  53. ; 5. Put this file in a directory that is in the PATH of users who need
  54. ;    to send pages;
  55. ; 6. Invoke with command-line arguments, e.g.:
  56. ;
  57. ;      alphapage "+1 (212) 555-1234" "This is a message"
  58. ;
  59. ;    Use shell quoting rules to group words into arguments.
  60. ;
  61. ; GENERAL INSTRUCTIONS (work on all platforms).
  62. ;
  63. ; To invoke the APAGE macro, put it in a file, edit it as necessary for
  64. ; your setup, tell C-Kermit to "take" the file (which installs the APAGE
  65. ; and TAPMSG definitions) and then to send a page, just type:
  66. ;
  67. ;   apage number { this is a message }
  68. ;
  69. ; at the C-Kermit> prompt, for example:
  70. ;
  71. ;   apage 99997654321 { Please call the office }
  72. ;
  73. ; Note: the pager ID number should not contain any spaces or else you must
  74. ; enclose it in braces:
  75. ;
  76. ;   apage { 999 76 543 21 } { This is a message }
  77. ;
  78. ; Ditto for the message.
  79. ;
  80. ; DEBUGGING: If you want to see diagnostic and progress messages, type
  81. ; "define testing 1" at the Kermit prompt before trying to send a page.
  82. ;
  83. local usage \%m
  84. assign \%m \fbasename(\%0)
  85.  
  86. define usage { exit 1 {usage: \%m <phonenumber> <message>} }
  87.  
  88. if not def TESTING def TESTING 0 ; Set to 1 for testing / debugging
  89. if \m(TESTING) {         ; So we can watch what happens
  90.     set dial display on
  91.     set input echo on
  92.     set terminal echo local    ; So output goes in session log
  93.     log session                ; Creates session.log in current directory
  94.     log transact               ; Creates transact.log in current directory
  95. }
  96.  
  97. define APAGE {
  98.     local rc number            ; rc = Return code for this macro
  99.     if < \v(argc) 2 end 1 PIN required
  100.     asg number 5554321         ; (*) Paging service phone number
  101.     set modem type usr         ; (*) I have a USR modem
  102.     set port /dev/tty01        ; (*) on this device
  103.     if fail end 1 SET PORT failed
  104.     set speed 1200             ; (*) Must use 1200 bps for paging
  105.     set parity even            ; (*) and even parity
  106.     set flow none              ; (*) and no flow control
  107.     set modem flow none        ; (*) ...
  108.     set modem error-correction off
  109.     set modem data-compression off
  110.     set modem speed-matching off
  111.     set output pacing 200      ; Talk s-l-o-w-l-y to the paging service
  112.     set dial retries 20        ; (*) Allow 20 redials (IF LEGAL!)
  113.     set dial interval 1        ; (*) 1 sec between redial attempts (IF LEGAL!)
  114.     dial \m(number)            ; Call the pager service
  115.     asg rc \v(status)           ; Save DIAL status
  116.     if = \m(rc) 0 {            ; If the call is answered
  117.         tapmsg \%1 {\%2}       ; Send the page
  118.         asg rc \v(status)      ; Save the result
  119.     } else {                   ; Otherwise
  120.         echo Page failed.      ; Fail.
  121.     }
  122.     hangup                     ; Hang up the phone
  123.     ;
  124.     ; For shared in-out ports you might need to reset the port's original
  125.     ; speed here and maybe also send it some kind of reset command like ATZ0.
  126.     ;
  127.     set modem type \v(modem)   ; Restore default modem settings
  128.     end \m(rc)                 ; Return
  129. }
  130.  
  131. ; TAPMSG Telocator Alphanumeric Protocol execution.  Call with:
  132. ;   \%1 = Pager ID (PIN)
  133. ;   \%2 = Message (single line)
  134. ;  Assumes connection is made.  Uses TAP to send PIN and 1-line message.
  135. ;
  136. def TAPMSG {
  137.     local \%i \%m \%s blk        ; Local variables
  138.     asg \%m \2\%1\13\%2\13\3        ; <STX>ID<CR>msg<CR><ETX>
  139.     asg \%s \fchecksum(\%m)        ; Get checksum and make block
  140.     asg blk \%m\fchar(\fmod(\%s/256,16)+48)-
  141. \fchar(\fmod(\%s/16,16)+48)-
  142. \fchar(\fmod(\%s,16)+48)\13        ; Checksummed TAP block
  143.     if \m(TESTING) xecho WAITING FOR ID= PROMPT...
  144.     for \%i 1 6 1 {            ; Try six times to get prompt
  145.     out \13                ; Send <CR>
  146.     in 3 ID=            ; Wait for "ID="
  147.     if succ break
  148.         if \m(TESTING) xecho NO ID= PROMPT - TRYING AGAIN
  149.     }
  150.     if > \%i 6 end 1 FAILED: No "ID=" prompt after 6 tries
  151.     for \%i 1 8 1 {            ; Send <ESC>PG1, get <ACK>
  152.     msleep 500
  153.     output \{27}PG1\13
  154.         if \m(TESTING) echo SENT <ESC>PG1(\%i)...
  155.     minput 3 {\6\13} {\21\13} {ID=} {\27\4\13}
  156.         if \m(TESTING) echo RESULT=\v(minput)
  157.     switch \v(minput) {
  158.       :0, continue            ; Timeout
  159.       :1, break            ; <ACK>
  160.       :2, continue            ; <NAK>
  161.       :3, out \{27}PG1\13, continue
  162.       :4, end 1 Forced disconnect    ; Forced disconnect - fatal
  163.     }
  164.     break
  165.     }
  166.     if > \%i 8 end 1 Timeout during TAP
  167.     in 10 \27[p\13            ; Wait for go-ahead
  168.     if fail end 1 No go-ahead        ; Didn't get it
  169.     for \%i 1 8 1 {            ; Try eight times
  170.     msleep 500
  171.     output \m(blk)            ; Send block
  172.         if \m(TESTING) echo SENT BLOCK (\%i)...
  173.     minput 8 {\6\13} {\21\13} {\13\27\4\13} {\30\13}
  174.         if \m(TESTING) echo RESULT=\v(minput)
  175.     switch \v(minput) {             ; Get response
  176.       :0, continue                  ; Timeout
  177.       :1, break                     ; <ACK> - success
  178.       :2, continue                  ; <NAK>
  179.       :3, end 1 Forced Disconnect
  180.       :4, echo ERROR - RETRYING, continue
  181.     }
  182.     out \4\13                       ; Sign off with <EOT>
  183.     in 8 \27\4\13                   ; Get <ESC><EOT> back
  184.     break                           ; But ignore timeout
  185.     }
  186.     if > \%i 8 end 1 Too many retries
  187. }
  188.  
  189. ; If invoked as a "kerbang" script execute it now.
  190.  
  191. if equal "\%0" "\v(cmdfil)" {
  192.     if not def \%1 usage
  193.     if not def \%2 usage
  194.     apage {\%1} {\%2}
  195.     exit \v(status)
  196. }
  197.  
  198. ; (End)
  199.