home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / alphapage7 < prev    next >
Text File  |  2020-01-01  |  8KB  |  213 lines

  1. #!/usr/local/bin/kermit +
  2. ;
  3. ; File APAGE.KSC
  4. ; Version 5.0
  5. ;
  6. ; TAP/IXO alphanumeric paging script for Kermit 95 and C-Kermit.
  7. ; Authors: F. da Cruz and C. Gianone, Columbia University, September 1996.
  8. ;
  9. ; For use with C-Kermit 7.0 / K95 1.1.19 or later.
  10. ; For a detailed explanation, consult "Using C-Kermit", 2nd Ed., pp.454-456.
  11.  
  12. if LLT \v(version) 700196 stop 1 C-Kermit 7.0 or K95 1.1.19 or later required.
  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. ; Version 5.0: February 2000:
  24. ;  1. Improved portability and parameterization
  25. ;
  26. ; WARNING: Automatic redialing is restricted or illegal in some
  27. ; countries.  Modify the lines marked "IF LEGAL!" if below this applies
  28. ; in your location.
  29. ;
  30. ; TAPMSG, defined below, is an alphanumeric pager dialing script that
  31. ; implements the Telocator Alphanumeric Protocol (TAP), also known as IXO,
  32. ; for sending one-line alphanumeric pages.  TAPMSG assumes the connection
  33. ; to the paging service is already made.
  34. ;
  35. ; The APAGE macro makes a connection to the paging service and then uses
  36. ; TAPMSG to send the page.  The following is a SAMPLE; you will need to adjust
  37. ; it to work with your paging service.  Hint: Some paging services are very
  38. ; picky about modem configurations.  For example, experience has shown that to
  39. ; dial a certain service successfully with a USR V.34 modem, just about all of
  40. ; the modem's features must be turned off prior to dialing.
  41. ;
  42. ; GENERAL INSTRUCTIONS
  43. ;
  44. ; Edit the APSETUP macro below to contain the device name for dialing plus any
  45. ; special communications parameters (lines marked "(*)" below).  Then whenever
  46. ; you want to send an alpha page, tell Kermit to "take" the file (which
  47. ; installs the APAGE and TAPMSG definitions) and then to send a page, just
  48. ; type:
  49. ;
  50. ;   apage pagerid { this is a message }
  51. ;
  52. ; at the K-95> prompt, for example:
  53. ;
  54. ;   apage 99997654321 { Please call the office }
  55. ;
  56. ; If you always want the APAGE macro available, add a TAKE command for this
  57. ; file to your K95CUSTOM.INI file.
  58. ;
  59. ; Note: the pager ID number should not contain any spaces or else you must
  60. ; enclose it in braces:
  61. ;
  62. ;   apage { 999 76 543 21 } { This is a message }
  63. ;
  64. ; Ditto for the message.
  65. ;
  66. ; DEBUGGING: If you want to see diagnostic and progress messages, type
  67. ; "define testing 1" at the Kermit prompt before trying to send a page.
  68. ;
  69. ; The alpha paging service phone number is taken from the Kermit variable
  70. ; APAGEPHONE.  If the Kermit variable is not defined, it is taken from the
  71. ; environment variable APAGEPHONE.  If none of these is defined, a prompt
  72. ; is given so you can enter it by hand.
  73. ;
  74. ; UNIX INSTRUCTIONS
  75. ; Change the top line to indicate the full pathname of the C-Kermit 7.0
  76. ; executable, if it is not /usr/local/bin/kermit.  Edit the APSETUP macro
  77. ; below as required, then store this file in your path with a name like
  78. ; alphapage, give it execute permission, and then you can run it by name:
  79. ;
  80. ;   alphapage pagerid message
  81. ;
  82. if not defined APAGEPHONE assign APAGEPHONE \$(APAGEPHONE)
  83. while not def APAGEPHONE {
  84.     ask APAGEPHONE { Alpha paging service phone number? } 
  85. }
  86.  
  87. local \%n                      ; (for error messages)
  88. assign \%n \fbasename(\%0)
  89.  
  90. if not def TESTING def TESTING 0 ; Set to 1 for testing / debugging
  91. if \m(TESTING) {         ; So we can watch what happens
  92.     set dial display on
  93.     set input echo on
  94.     set terminal echo local    ; So output goes in session log
  95.     log session                ; Creates session.log in current directory
  96.     log transact               ; Creates transact.log in current directory
  97. }
  98.  
  99. ; EDIT the APSETUP macro for your modem, dialout device, and
  100. ; the communication setup required by your paging service.
  101.  
  102. define APSETUP {               ; Set up the calling parameters.
  103.     if eq \v(system) WIN32 {   ; (*) In Windows use the default TAPI device.
  104.         set tapi line          
  105.         if fail end 1
  106.     } else {                   ; Elsewhere...
  107.         set modem type usr     ; (*) Specify the modem type.
  108.         set line /dev/ttyS1    ; (*) Specify dialout port.
  109.     if fail end 1
  110.     }
  111.     set speed 1200             ; (*) Speed required by paging service
  112.     set parity even            ; (*) Parity required by paging service
  113.     set flow none              ; (*) No flow control
  114.     set modem flow none        ; (*) ...
  115.     set dial retries 20        ; (*) Allow 20 redials (IF LEGAL!)
  116.     set dial interval 1        ; (*) 1 sec between redial attempts (IF LEGAL!)
  117. }
  118.  
  119. define APAGE {                 ; Call the paging service and send a page.
  120.     local rc                   ; rc = Return code for this macro
  121.     if < \v(argc) 2 end 1 Pager ID required
  122.     do apsetup
  123.     if fail end 1
  124.     set modem error-correction off
  125.     set modem data-compression off
  126.     set modem speed-matching off
  127.     set output pacing 200      ; Talk s-l-o-w-l-y to the paging service
  128.     dial \m(APAGEPHONE)        ; Call the pager service
  129.     asg rc \v(status)           ; Save DIAL status
  130.     if = \m(rc) 0 {            ; If the call is answered
  131.         tapmsg \%1 {\%2}       ; Send the page
  132.         asg rc \v(status)      ; Save the result
  133.     } else {                   ; Otherwise
  134.         echo Page failed.      ; Fail.
  135.     }
  136.     hangup                     ; Hang up the phone
  137.     ;
  138.     ; For shared in-out ports you might need to reset the port's original
  139.     ; speed here and maybe also send it some kind of reset command like ATZ0.
  140.     ;
  141.     set modem type \v(modem)   ; Restore default modem settings
  142.     end \m(rc)                 ; Return
  143. }
  144.  
  145. ; TAPMSG Telocator Alphanumeric Protocol execution.  Call with:
  146. ;   \%1 = Pager ID (PIN)
  147. ;   \%2 = Message (single line)
  148. ;  Assumes connection is made.  Uses TAP to send PIN and 1-line message.
  149. ;
  150. def TAPMSG {
  151.     local \%i \%m \%s blk        ; Local variables
  152.     asg \%m \2\%1\13\%2\13\3        ; <STX>ID<CR>msg<CR><ETX>
  153.     asg \%s \fchecksum(\%m)        ; Get checksum and make block
  154.     asg blk \%m\fchar(\fmod(\%s/256,16)+48)-
  155. \fchar(\fmod(\%s/16,16)+48)-
  156. \fchar(\fmod(\%s,16)+48)\13        ; Checksummed TAP block
  157.     if \m(TESTING) xecho WAITING FOR ID= PROMPT...
  158.     for \%i 1 6 1 {            ; Try six times to get prompt
  159.     out \13                ; Send <CR>
  160.     in 3 ID=            ; Wait for "ID="
  161.     if succ break
  162.         if \m(TESTING) xecho NO ID= PROMPT - TRYING AGAIN
  163.     }
  164.     if > \%i 6 end 1 FAILED: No "ID=" prompt after 6 tries
  165.     for \%i 1 8 1 {            ; Send <ESC>PG1, get <ACK>
  166.     msleep 500
  167.     output \{27}PG1\13
  168.         if \m(TESTING) echo SENT <ESC>PG1(\%i)...
  169.     minput 3 {\6\13} {\21\13} {ID=} {\27\4\13}
  170.         if \m(TESTING) echo RESULT=\v(minput)
  171.     switch \v(minput) {
  172.       :0, continue            ; Timeout
  173.       :1, break            ; <ACK>
  174.       :2, continue            ; <NAK>
  175.       :3, out \{27}PG1\13, continue
  176.       :4, end 1 Forced disconnect    ; Forced disconnect - fatal
  177.     }
  178.     break
  179.     }
  180.     if > \%i 8 end 1 Timeout during TAP
  181.     in 10 \27[p\13            ; Wait for go-ahead
  182.     if fail end 1 No go-ahead        ; Didn't get it
  183.     for \%i 1 8 1 {            ; Try eight times
  184.     msleep 500
  185.     output \m(blk)            ; Send block
  186.         if \m(TESTING) echo SENT BLOCK (\%i)...
  187.     minput 8 {\6\13} {\21\13} {\13\27\4\13} {\30\13}
  188.         if \m(TESTING) echo RESULT=\v(minput)
  189.     switch \v(minput) {             ; Get response
  190.       :0, continue                  ; Timeout
  191.       :1, break                     ; <ACK> - success
  192.       :2, continue                  ; <NAK>
  193.       :3, end 1 Forced Disconnect
  194.       :4, echo ERROR - RETRYING, continue
  195.     }
  196.     out \4\13                       ; Sign off with <EOT>
  197.     in 8 \27\4\13                   ; Get <ESC><EOT> back
  198.     break                           ; But ignore timeout
  199.     }
  200.     if > \%i 8 end 1 Too many retries
  201. }
  202.  
  203. ; If invoked as a "kerbang" script execute it now.
  204.  
  205. if equal "\%0" "\v(cmdfil)" {
  206.     if ( != \v(argc) 3 ) exit 1 {usage: \%n <pagerid> <message>}
  207.     apage {\%1} {\%2}
  208.     exit \v(status)
  209. }
  210.  
  211. ; (End)
  212.