home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / PMPAGER.ZIP / PMPAGER.CMD < prev    next >
OS/2 REXX Batch file  |  1991-11-02  |  13KB  |  308 lines

  1. /* rexx */
  2. /* ****************************************************************** */
  3. /*                                                                    */
  4. /* PMPAGER.CMD (OS/2)                                                 */
  5. /*                                                                    */
  6. /* Version 1.0                                                        */
  7. /* Copyright (c) 1991 Robert G Gaillard.                              */
  8. /*                                                                    */
  9. /* ****************************************************************** */
  10. /*                                                                    */
  11. /* PM-Pager is a REXX add-in program for the OS/2 communications      */
  12. /* program Pmcomm, by Multi-Net Communications, and uses several      */
  13. /* specialized function calls proprietary to that product.            */
  14. /*                                                                    */
  15. /* The purpose of PM-Pager is to monitor a telephone line that is     */
  16. /* connected to both a modem and an answering machine, recognize      */
  17. /* when a sufficient number of rings have been received to trigger    */
  18. /* the answering machine, and then dial a remote beeper or pager      */
  19. /* as notification that a call was received.  Provision is made to    */
  20. /* send a (numeric) identifying message to pagers that provide a      */
  21. /* display feature.                                                   */
  22. /*                                                                    */
  23. /* Refer to the full documentation provided with the program for      */
  24. /* additional details, warnings, licensing information and            */
  25. /* disclaimers.                                                       */
  26. /*                                                                    */
  27. /* Input  (REXX Arg List):                                            */
  28. /*                           Pmcomm Standard Parameters:              */
  29. /*                               Port                                 */
  30. /*                               Portname                             */
  31. /*                               Screen_handle                        */
  32. /*                               Dde_output                           */
  33. /*                               Dde_input                            */
  34. /*                               Semaphore                            */
  35. /*                                                                    */
  36. /* Output:                                                            */
  37. /*                           None                                     */
  38. /*                                                                    */
  39. /* External Calls:                                                    */
  40. /*                           RxFuncAdd                                */
  41. /*                           Pmcomm Functions:                        */
  42. /*                               Init_dll                             */
  43. /*                               Drop_dtr                             */
  44. /*                               Get_ch                               */
  45. /*                               Put_s                                */
  46. /*                               Raise_dtr                            */
  47. /*                               Read_timeout                         */
  48. /*                               Sleep                                */
  49. /*                               Wait_for                             */
  50. /*                                                                    */
  51. /* ****************************************************************** */
  52. /*                                                                    */
  53. /*                                                                    */
  54. /* ****************************************************************** */
  55. /*                                                                    */
  56. /* Following are the variable parameters which may be modified to     */
  57. /* customize PM-Pager to individual needs.  Please refer to the       */
  58. /* documentation for a more complete description of each field.      */
  59. /*                                                                    */
  60. /* ****************************************************************** */
  61. /*                                                                    */
  62. init_string="AT"||,                /* Standard command prefix         */
  63. "&F"||,                            /* Restore factory defaults        */
  64. "&C1"||,                           /* Monitor carrier                 */
  65. "&D2"||,                           /* Monitor DTR                     */
  66. "L0"||,                            /* Lower volume                    */
  67. "M0"||,                            /* Run fully silent                */
  68. "Q0"||,                            /* Return response codes           */
  69. "S0=0"||,                          /* Do not answer                   */
  70. "S11=50"||,                        /* Speed up tone dialing           */
  71. "X4"                               /* Use full response code set      */
  72. /*                                                                    */
  73. dial_command="ATD"                 /* Standard dial command string    */
  74. dial_type="T"                      /* T=Tone or P=Pulse               */
  75. dial_prefix=""                     /* Get outside line (e.g "9,")     */
  76. area_code="1800"                   /* Pager area code (if required)   */
  77. phone_number="5551234"             /* Pager phone number              */
  78. pause_string=",,,,@"               /* Pause and Wait for quiet answer */
  79. message_dial_type=""               /* T=Tone (if normal dial was P)   */
  80. pager_message="516*555*6789"       /* Message to display on pager     */
  81. message_end="#"                    /* Terminator for pager message    */
  82. dial_suffix=",,,,;H"               /* Pause and hang up               */
  83. reset_string="ATZ0"                /* Standard Pmcomm modem setting   */
  84. ring_duration=10                   /* Max seconds between rings       */
  85. times_to_notify=1                  /* Number of times to call pager   */
  86. notify_wait=60                     /* Delay before calling pager      */
  87. primary_trigger=4                  /* Number of rings for answering   */
  88.                                    /* machine to answer normally      */
  89. secondary_trigger=2                /* Number of rings for answering   */
  90.                                    /* machine to answer in toll-saver */
  91. max_response_time=15               /* Max time to allow for callback  */
  92. log_all="NO"                       /* Set to "YES" before reporting   */
  93.                                    /* problems with PM-Pager          */
  94. /*                                                                    */
  95. /* ****************************************************************** */
  96. /*                                                                    */
  97. /* End of user-customization parameters.                              */
  98. /*                                                                    */
  99. /* ****************************************************************** */
  100.  
  101. signal on syntax name syntax_error
  102. signal on halt   name eoj_clean_up
  103.  
  104. parse arg port portname screen_handle dde_output dde_input semaphore
  105. parse source . . fn .
  106.  
  107. if semaphore=""
  108.   then
  109.     do
  110.       say "Pmpager: Input parameters invalid"
  111.       say "         Not invoked from Pmcomm"
  112.       exit(4)
  113.     end
  114. call RxFuncAdd "init_dll","RxPmcomm","init_dll"
  115. call init_dll
  116.  
  117. numeric digits 12
  118. curr_dir=directory()
  119. cr   = "0d"x
  120. crlf = "0d0a"x
  121. log_file=curr_dir"\PMPAGER.LOG"
  122. wait_time=(60*60*24*366*1000)
  123. wait_time=600000
  124. mrts=max_response_time*60
  125. nw=notify_wait*1000
  126. prev_ring=0
  127. curr_ring=0
  128. prev_series=999999999999
  129. curr_series=999999999999
  130. series_cnt=0
  131. full_string=""||,
  132. dial_command||,
  133. dial_type||,
  134. dial_prefix||,
  135. area_code||,
  136. phone_number||,
  137. pause_string||,
  138. message_dial_type||,
  139. pager_message||,
  140. message_end||,
  141. dial_suffix
  142. noring_msg=""
  143. ring_msg=""
  144. err_msg=""
  145.  
  146. call read_timeout "0",port
  147. r_c=0
  148. do until r_c=-1
  149.   call get_ch port
  150.   r_c=result
  151. end
  152. call drop_dtr port
  153. call sleep 2000
  154. call raise_dtr port
  155. do forever
  156.   call put_s 'ATZ'||cr,port
  157.   call wait_for "OK",port
  158.   call sleep "2000"
  159.   call put_s init_string||cr,port
  160.   call wait_for "OK",port
  161.   if  result=1
  162.     then
  163.       leave
  164. end
  165. call put_s "1b5b324a"x,screen_handle   /* Clear Screen Routine */
  166. call put_s "PM-Pager now active, waiting for ring..." crlf,
  167.       ,screen_handle
  168. dummy=stream(log_file,"c","open write")
  169. dummy=lineout(log_file,"PM-Pager started at "time()" on",
  170.       date(w)", "date(l))
  171. call read_timeout wait_time,port
  172. do forever
  173.   call wait_for "RING",port
  174.   r_c=result
  175.   if  r_c=1
  176.     then
  177.       do
  178.         curr_ring=(date(b)*86400)+time(s)
  179.         this_gap=curr_ring-prev_ring
  180.         prev_ring=curr_ring
  181.         if  this_gap>ring_duration
  182.           then
  183.             do
  184.               series_cnt=1
  185.               curr_series=curr_ring
  186.               s_s=" "
  187.               lm=length(noring_msg)+2
  188.             end
  189.           else
  190.             do
  191.               series_cnt=series_cnt+1
  192.               s_s="s"
  193.               lm=length(ring_msg)+2
  194.             end
  195.         if  lm=2 | log_all="YES"
  196.           then
  197.             lm=0
  198.         dummy=stream(log_file,"c","seek -"lm)
  199.         ring_msg=series_cnt" Ring"s_s" Detected at "time()" on",
  200.               date(w)", "date(l)
  201.         dummy=lineout(log_file,ring_msg)
  202.         noring_msg=""
  203.         if  series_cnt>=primary_trigger,
  204.         |   (series_cnt>=secondary_trigger,
  205.         &   (curr_series-prev_series)>mrts)
  206.           then
  207.             do
  208.               call put_s ring_msg||crlf,screen_handle
  209.               prev_series=curr_series
  210.               call sleep nw
  211.               call read_timeout 50000,port
  212.               times_notified=0
  213.               times_tried=0
  214.               response_codes="RC="
  215.               do while times_notified<times_to_notify,
  216.                     & times_tried<10
  217.                 call put_s full_string||cr,port
  218.                 call wait_for "OK","CONNECT","NO CARRIER",
  219.                       "NO DIALTONE","BUSY","ERROR","NO ANSWER",port
  220.                 r_c=result
  221.                 response_codes=response_codes||r_c
  222.                 if  r_c>0 & r_c<4
  223.                   then
  224.                     do
  225.                       times_notified=times_notified+1
  226.                       call drop_dtr port
  227.                       call sleep 3000
  228.                       call raise_dtr port
  229.                     end
  230.                   else
  231.                     do
  232.                       times_tried=times_tried+1
  233.                       call sleep 30000
  234.                     end
  235.               end
  236.               if  times_notified<times_to_notify
  237.                 then
  238.                   do
  239.                     err_msg="ERROR attempting to dial pager at",
  240.                           time()" on "date(w)", "date(l)
  241.                     dummy=lineout(log_file,err_msg)
  242.                     err_msg="      "response_codes
  243.                     dummy=lineout(log_file,err_msg)
  244.                   end
  245.                 else
  246.                   do
  247.                     if  times_notified=1
  248.                       then
  249.                         s_s=""
  250.                       else
  251.                         s_s="s"
  252.                     if  log_all\="YES"
  253.                       then
  254.                         response_codes=""
  255.                     err_msg="Pager dialed" times_notified "time"s_s,
  256.                           "at" time() "on" date(w)"," date(l),
  257.                           response_codes
  258.                     dummy=lineout(log_file,err_msg)
  259.                   end
  260.               ring_msg=""
  261.               call read_timeout wait_time,port
  262.             end
  263.           else
  264.             if  series_cnt>=secondary_trigger
  265.               then
  266.                 prev_series=999999999999
  267.       end
  268.     else
  269.       do
  270.         lm=length(noring_msg)+2
  271.         if  lm=2 | log_all="YES"
  272.           then
  273.             lm=0
  274.         dummy=stream(log_file,"c","seek -"lm)
  275.         noring_msg="No Ring, "date(l)" "time()"..."
  276.         dummy=lineout(log_file,noring_msg)
  277.       end
  278. end
  279. exit
  280. /*                                                                    */
  281. eoj_clean_up:
  282. lm=length(noring_msg)+2
  283. if  lm=2 | log_all="YES"
  284.   then
  285.     lm=0
  286. dummy=stream(log_file,"c","seek -"lm)
  287. noring_msg="No Ring, "date(l)" "time()"..."
  288. dummy=lineout(log_file,noring_msg)
  289. dummy=lineout(log_file,"PM-Pager ended at" time() "on",
  290.       date(w)", "date(l))
  291. do forever
  292.   call put_s 'ATZ'||cr,port
  293.   call wait_for "OK",port
  294.   call sleep "2000"
  295.   call put_s reset_string||cr,port
  296.   call wait_for "OK",port
  297.   if  result=1
  298.     then
  299.       leave
  300. end
  301. exit
  302. /*                                                                    */
  303. syntax_error:
  304. errormsg = "REXX error" rc "in line" sigl":" errortext(rc)
  305. rc = lineout(log_file,date() time() fn "-" errormsg)
  306. rc = lineout(log_file,date() time() fn "-" sourceline(sigl))
  307. exit
  308.