home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / RMODEM.ZIP / rmodem.cmd
OS/2 REXX Batch file  |  1991-09-27  |  31KB  |  785 lines

  1. /*---------------------------------------------------------------+
  2. | RMODEM, REXX Communication Macro Processor o o o     o         |
  3. |         (see line 135 and below)            \|/     /          |
  4. |                                           o--O-----O--o        |
  5. |                                             /|\     \          |
  6. | RMODEM  .46, 1991 by Arthur F. Tyde III    o | o     O         |
  7. |          Asynchronous control program for    |      / \        |
  8. |          Hayes compatible modems.         o--O     o   o       |
  9. |                                                                |
  10. | If you find this shareware package useful, want to make        |
  11. | suggestions, send money, whatever... Mail can be sent to       |
  12. | 1020 Raleigh #2006, Carrollton TX 75007,                       |
  13. | 71660,1134, AFTYDE @ HONE9, A.TYDE1,                           |
  14. |                                                                |
  15. | RMODEM is a set of OS/2 REXX routines to control a Hayes       |
  16. | compatible modem.  This example will sign-on to your local     |
  17. | Compuserve node, save the main menu to a file and then         |
  18. | sign off.  You may need to change some of the values in the    |
  19. | Setup_Rmodem: routine to match your hardware configuration.    |
  20. |                                                                |
  21. | RMODEM change history.                                         |
  22. |                                                                |
  23. | 07/07/91 - Added tag to define MNP connect reliable message.   |
  24. +---------------------------------------------------------------*/
  25.  
  26. Address CMD
  27.  
  28. /*-----------------------------------------------+
  29. | Here we preset some RMODEM environment         |
  30. | variables.  They may be set by your program    |
  31. | or inherited from the environment of another.  |
  32. +-----------------------------------------------*/
  33. Call Value 'COMPORT','COM2','OS2ENVIRONMENT'
  34. Call Value 'PORT_PAUSE','0','OS2ENVIRONMENT'
  35. Call Value 'COMMAND_PAUSE','3','OS2ENVIRONMENT'
  36. Call Value 'MODEM_INIT','ATV1','OS2ENVIRONMENT'
  37. Call Value 'MODEM_RESET','ATZ','OS2ENVIRONMENT'
  38. Call Value 'MODEM_MNP','NO','OS2ENVIRONMENT'
  39. Call Value 'MODEM_MNP_ACK','NO','OS2ENVIRONMENT'
  40. Call Value 'MODEM_SPEED','2400','OS2ENVIRONMENT'
  41.  
  42.  
  43. parse upper arg command
  44. /*-------------------------------------+
  45. | Set up and initialize RMODEM.        |
  46. +-------------------------------------*/
  47. Call Setup_Rmodem  /* Set up RMODEM Version .45 */
  48. /*-------------------------------------+
  49. | Set up demo variables.               |
  50. +-------------------------------------*/
  51. Call Setup_CIS   /* Set Macro dependent stuff */
  52. /*--------------------+
  53. | Dial CIS.           |
  54. +--------------------*/
  55. Parse value Modem_Connect(CIS_dialup) with fatal_error
  56. /*--------------------+
  57. | Sign on to CIS.     |
  58. +--------------------*/
  59. If Fatal_Error=0 then do
  60.    Parse value CIS_signon() with fatal_error
  61.    If fatal_error=0 Then Do  /* we are on the system now */
  62.      Call Announce 'We logged on and saved menu, now signing off!'
  63.      Call Exit_From_CIS
  64.      Call Announce rmodem_service 'connection terminated.'
  65.    End
  66.    Else Do /* naaa gaaa duit */
  67.      Call Announce 'Unable to connect to CIS.'
  68.    End
  69. End
  70. Exit:
  71. '@EXIT'
  72. exit 999
  73.  
  74. SETUP_CIS:
  75. /*-----------------------------------------------+
  76. | RMODEM - Set the name & title of this program. |
  77. +-----------------------------------------------*/
  78. rmodem_program='CIS'
  79. rmodem_service='Compuserve Information Service'
  80. Call Announce 'RMODEM Demonstration Program'
  81. Say
  82. Say '-> This example signs onto CIS, captures the main menu to a file'
  83. Say '   called CISMENU.TXT, and signs off'
  84. Say
  85. Say 'Enter CIS Dialup:'
  86. parse value linein('CON') with CIS_Dialup
  87. Say crlf'Enter CIS ID'
  88. parse value linein('CON') with CIS_ID
  89. Say crlf'Enter CIS Password'
  90. parse value linein('CON') with CIS_Password
  91. Return
  92.  
  93. CIS_SIGNON:
  94. Call Announce 'Signing onto' rmodem_service
  95. Call Rxsleep 1
  96. Call Send cr,'NE'
  97. Parse value Match('Host Name:') with fatal_error
  98. If fatal_error=0 then do
  99.    Call Text_Out '-> Signing on to CIS.'crlf
  100.    Call Send 'CIS'cr,'NE'
  101.    Call Match 'User ID:'
  102.    Call Slow_Send CIS_ID''cr,'NE'
  103.    Call Match 'Password:'
  104.    Call Slow_Send CIS_Password''cr,'NE'
  105.    Call Announce 'Capturing' rmodem_service 'menu to disk'
  106.    Call Collect_lines 45 /* nab most of the signon stuff quickly */
  107.    Call Buffer 'WRITE','CISMENU.TXT'
  108.    Call Match_Keep ' !','NF' /* wait for space and exclamation point */
  109.    Call Buffer 'APPEND','CISMENU.TXT' /* finish writing file */
  110.    Call Announce 'File CISMENU.TXT written to disk.'
  111.    Return 0
  112. End
  113. Return 2
  114.  
  115. EXIT_FROM_CIS:
  116. /*-----------------------------------------------------------+
  117. | Say goodbye, and hang up the modem.                        |
  118. +-----------------------------------------------------------*/
  119. Call Announce 'Signing off' rmodem_service
  120. Call Send 'BYE'cr,'NE'
  121. Call Match 'Host Name:'
  122. Call Modem_Disconnect
  123. Return
  124.  
  125. USER_EXIT:
  126. /*-----------------------------------------------------------+
  127. | RMODEM                                                     |
  128. |                                                            |
  129. | If for some reason a match fails or we lose carrier we     |
  130. | give the user a chance to do a few things by calling this  |
  131. | routine before hanging up.                                 |
  132. |                                                            |
  133. +-----------------------------------------------------------*/
  134. Call Announce 'User_Exit was called!'
  135. Return
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. /*-------------------------------------------------------------------------+
  170. |                                                                          |
  171. | RMODEM Version .46, July 22, 1991.                                       |
  172. | by Arthur F. Tyde III.  For Authorized Use Only.                         |
  173. | Bug reports to Art at Skull & Crossbones.                                |
  174. | (C)opyright 1990, Arthur F. Tyde III, all rights reserved.               |
  175. |                                                                          |
  176. | Welcome to RMODEM.  The routines below are modem handling code.          |
  177. | There is nothing service specific below this point.  You will need       |
  178. | to set some values in your code such as program name, service title      |
  179. | and any additional parms you want to pass to disconnect processing.      |
  180. | If a match fails, it usually takes a full 60 seconds for the port        |
  181. | to timeout and Rmodem to realize that we've lost carrier or missed       |
  182. | a match.  If you are using RMODEM to wait for a call, you must turn      |
  183. | auto-answer OFF.  RMODEM will handle the pickup automatically.           |
  184. |                                                                          |
  185. +-------------------------------------------------------------------------*/
  186. SETUP_RMODEM:
  187. /*-------------------------------------------------------------------------+
  188. | Here we set the communication handler independent values                 |
  189. | for basic modem support services.  It is the responsibility of the       |
  190. | application programmer to make sure the following RMODEM values are      |
  191. | set and shared by Rmodem and the programmers application.                |
  192. |                                                                          |
  193. | Quiet 0/1      When set suppresses all screen IO.                        |
  194. | Rmodem_Service Set this variable to a description of the service being   |
  195. |                connected to.                                             |
  196. | Fatal_Error    Reserved variable, indicates success or failure of        |
  197. |                RMODEM call.  Exposed so user can play with it.           |
  198. | Scan_Limit     Number of characters to scan before aborting.             |
  199. | Line_Limit     Number of lines to read before aborting.                  |
  200. | Port           Should be set to any valid COM port.                      |
  201. | Port_Pause     On a very fast machine, port pause waits x number of      |
  202. |                seconds before continuing with a match operation.  This   |
  203. |                gives the modem time to return chars to the port.         |
  204. | Command_Pause  The amount of seconds RMODEM pauses between sending AT    |
  205. |                commands to a Hayes Compatible Modem.                     |
  206. | Modem_Reset    The command that sets you modem to it's factory default.  |
  207. |                Normally, this should be YES,ATZ.                         |
  208. | Modem_Init     Should at least contain YES,ATV1.  It's recommended you   |
  209. |                set your modem up and write the configuration to NVRAM.   |
  210. | Modem_MNP      Should be 'YES, command string to enable MNP.  Turn on    |
  211. |                extended messages for MNP, set for highest terminal       |
  212. |                speed (9600) and enable modem speed conversion.  Enable   |
  213. |                auto-reliable and XON/XOFF flow control.                  |
  214. | Modem_MNP_ACK  Return string from modem indicating a reliable connect.   |
  215. | Baud           Has been tested at 300 to 9600 BPS.  If your modem        |
  216. |                provides speed conversion we recommend using it only      |
  217. |                with MNP enabled.                                         |
  218. +-------------------------------------------------------------------------*/
  219. cr=d2c(13);crlf=d2c(13)d2c(10);bs=d2c(8);cc=d2c(3);nul=d2c(00);os2=1
  220. parse source with rmodem_program
  221. parse value reverse(rmodem_program) with rmodem_program'\' .
  222. parse value reverse(rmodem_program) with rmodem_program
  223. parse value '0 0 800 500' with fatal_error quiet scan_limit line_limit
  224. parse value '' with rmodem_hangup_parms
  225. Port         = Value('COMPORT',,'OS2ENVIRONMENT')
  226. Port_Pause   = Value('PORT_PAUSE',,'OS2ENVIRONMENT')
  227. Command_Pause= Value('COMMAND_PAUSE',,'OS2ENVIRONMENT')
  228. Modem_Init   = Value('MODEM_INIT',,'OS2ENVIRONMENT')
  229. Modem_Reset  = Value('MODEM_RESET',,'OS2ENVIRONMENT')
  230. Modem_MNP    = Value('MODEM_MNP',,'OS2ENVIRONMENT')
  231. Modem_MNP_ACK= Value('MODEM_MNP_ACK',,'OS2ENVIRONMENT')
  232. Baud         = Value('MODEM_SPEED',,'OS2ENVIRONMENT')
  233. Parse Value Stream(port,'c','OPEN') with Pstat
  234. If Modem_Reset='' then Modem_Reset='YES,ATZ'
  235. If Command_Pause='' then Command_Pause=1
  236. If Modem_Init='' then Modem_Init='YES,ATV1'
  237. Call Announce 'RMODEM Version .46, (C)opyright 1991, A. Tyde'
  238. /*------------------------------------------------------------------+
  239. | Let's init the port, then reset and init the modem.               |
  240. +------------------------------------------------------------------*/
  241. Parse value Port_baud(port,baud) with fatal_error
  242. If pos('YES',modem_reset)>0 then do
  243.    Parse Value Modem_Reset with ','Modem_reset
  244.    Parse value Modem_Command(modem_reset) with fatal_error
  245.    Call Check_Init
  246. End
  247. If pos('YES',modem_init)>0 then do
  248.    Parse Value Modem_Init with ','Modem_Init
  249.    Parse value Modem_Command(modem_init) with fatal_error
  250.    Call Check_Init
  251. End
  252. If pos('YES',modem_mnp)>0 then do
  253.    /*---------------------------------------------------------------+
  254.    | To enable MNP.  The tag MODEM_MNP should be set to             |
  255.    | whatever AT initialization string activates the auto-MNP       |
  256.    | feature on your modem.  This will insure error free            |
  257.    | high-throughput MNP synchronous connections.                   |
  258.    |                                                                |
  259.    | For example...  AT*SC1*SM3*XC1*FL1                             |
  260.    |                                                                |
  261.    | SC1 - Speed Conversion ON                                      |
  262.    | SM3 - Data Transfer Mode, auto reliable.                       |
  263.    | XC1 - Turn on extended MNP messages.                           |
  264.    | FL1 - Enable XON/XOFF flow control.                            |
  265.    +---------------------------------------------------------------*/
  266.    Parse Value Modem_Mnp with ','modem_mnp
  267.    Parse Value Modem_Command(modem_mnp) with fatal_error
  268.    If Fatal_Error>0 then do
  269.       Call Announce 'RMODEM: MNP Initialization Failed.'
  270.       Fatal_error=0
  271.       Modem_mnp='NO'
  272.    End
  273.    Else Do
  274.       Call Announce 'MNP mode enabled!'
  275.       Modem_mnp='YES'
  276.    End
  277. End
  278. If Fatal_Error\=0 then Call Exit /* We're FUBAR */
  279. Return
  280.  
  281. PORT_BAUD:
  282. /*---------------------------------------------------------------+
  283. | Syntax: Call Port_Baud port,baud                               |
  284. |                                                                |
  285. | Sets the designated port to the correct baud and parms.        |
  286. | Currently, BUFFERS=ON, and XON/XOFF=ON.  Seems to work.        |
  287. +---------------------------------------------------------------*/
  288. parse arg port, baud
  289. Call Text_Out '-> Setting port' port 'to' baud 'baud.'crlf
  290. Call Text_Out '   Stream status is' pstat'.'crlf
  291. '@MODE' port':'baud',,,,TO=OFF,XON=ON 1>nul 2>nul'
  292. return 0
  293.  
  294. MATCH_KEEP:
  295. /*---------------------------------------------------------------+
  296. | Syntax: Call Match_Keep 'string',options                       |
  297. |                                                                |
  298. | Options: NE, no echo to screen.                                |
  299. |          NF, disable failure detection.                        |
  300. |                                                                |
  301. | Scans incoming stream for a pattern match.  Returns all data   |
  302. | scanned to caller.  If scan_limit is exceeded we disconnect    |
  303. | unless NF is used.                                             |
  304. +---------------------------------------------------------------*/
  305. options=''
  306. parse arg target, options
  307. file=target
  308. if target=d2c(13) then file='[CR]'
  309. Call Text_Out '-> Buffer & Match for' file'.'crlf
  310. parse value '0' with scan_done
  311. file=''
  312. Parse Value Time_Delay(Port_Pause) with .
  313. Do i=1 by 1 until scan_done>0 | i>scan_limit
  314.    data_byte=charin(port)
  315.    file=file||data_byte
  316.    if quiet=0 & pos('NE',options)=0 then call charout ,data_byte
  317.    parse value pos(target,file) with scan_done
  318. End
  319. If pos('NF',options)=0 then do /* no process failures */
  320.    If Scan_Done=0 then Do
  321.       Call Text_Out '-> Match failed: Aborting session.'crlf
  322.       Call Modem_Disconnect
  323.       Call User_Exit '(Emergency Disconnect) Match Failure for' target'.'
  324.       Call Exit
  325.    End
  326.    Call Carrier_Detect file
  327. End
  328. options='';data_line.1=file;data_line.0=1
  329. Return file
  330.  
  331. MATCH:
  332. /*---------------------------------------------------------------------+
  333. | Syntax: Call Match_Keep 'string',options                             |
  334. |                                                                      |
  335. | Options: NE, no screen echo.                                         |
  336. |          NF, disable failure detection/processing.                   |
  337. |                                                                      |
  338. | Scans incoming stream for a pattern match.  Returns 0 if matched, if |
  339. | NF is specified a 1 is returned if a match fails, otherwise we call  |
  340. | Modem_Disconnect to abort session.                                   |
  341. +---------------------------------------------------------------------*/
  342. parse arg target, options
  343. file=target
  344. if target=d2c(13) then file='[CR]'
  345. Call Text_Out '-> Matching for' file'.'crlf
  346. parse value '0' with scan_done
  347. file=''
  348. Parse Value Time_Delay(Port_Pause) with .
  349. Do i=1 by 1 until scan_done>1 | i>scan_limit
  350.    data_byte=charin(port)
  351.    file=file||data_byte
  352.    if quiet=0 & pos('NE',options)=0 then call charout ,data_byte
  353.    parse value pos(target,file) with scan_done
  354. End
  355. If pos('NF',options)=0 then do
  356.    Call Carrier_Detect file
  357.    If Scan_Done=0 then Do
  358.       Call Text_Out '-> Match failed: Aborting session.'crlf
  359.       Call Modem_Disconnect
  360.       Call User_Exit '(Emergency Disconnect) Match Failure for' target'.'
  361.       Call Exit
  362.    End
  363. End
  364. If pos('NF',options)>0 & scan_done=0 then do
  365.    Return 1
  366. End
  367. options='';data_line.1=file;data_line.0=1
  368. Return fatal_error
  369.  
  370. SEND:
  371. /*---------------------------------------------------------------------+
  372. | Syntax: Call Send 'data to send',options                             |
  373. |                                                                      |
  374. | Sends a piece of data.  Returns that data echoed back from the port. |
  375. | The NE option suppresses the echo, and the sent data will remain out |
  376. | in limbo until it's eventually read in or scanned by.                |
  377. +---------------------------------------------------------------------*/
  378. parse arg command, options
  379. echo=''
  380. Call charout port,command
  381. if options\='NE' then do
  382.    parse value match_keep(command) with echo
  383. end
  384. Return echo
  385.  
  386. SLOW_SEND:
  387. /*---------------------------------------------------------------------+
  388. | Syntax: Call Slow_Send 'data to send',options                        |
  389. |                                                                      |
  390. | Sends a piece of data.  Returns that data echoed back from the port. |
  391. | The NE option suppresses the echo, and the sent data will remain out |
  392. | in limbo until it's eventually read in or scanned by.                |
  393. +---------------------------------------------------------------------*/
  394. parse arg command, options
  395. echo=''
  396. do i=1 to length(command)
  397.    Call charout port,substr(command,i,1)
  398.    call rxsleep 1
  399. end
  400. if options\='NE' then do
  401.    parse value match_keep(command) with echo
  402. end
  403. Return echo
  404.  
  405. TEXT_OUT:
  406. /*--------------------------------------------+
  407. | Syntax: Call Text_Out 'text to say'         |
  408. |                                             |
  409. | Sends data to a selected device.  Currently |
  410. | supports the screen.                        |
  411. +--------------------------------------------*/
  412. parse arg data
  413. if quiet=0 then call charout ,data
  414. Return
  415.  
  416. ANNOUNCE:
  417. /*--------------------------------------------+
  418. | Syntax: Call Announce 'text to say'         |
  419. |                                             |
  420. | Sends data to a selected device.  Currently |
  421. | supports the screen, boxes the text.        |
  422. +--------------------------------------------*/
  423. parse arg data
  424. top='╒'copies('═',length(data)+2)'╕'crlf
  425. string='│' data '│'crlf
  426. bottom='╘'copies('═',length(data)+2)'╛'crlf
  427. if quiet=0 then do
  428.    call charout ,crlf
  429.    call charout ,top
  430.    call charout ,string
  431.    call charout ,bottom
  432. end
  433. Return
  434.  
  435. DISCARD_LINES:
  436. /*--------------------------------------------------------+
  437. | Syntax: Call Discard_Lines 5,options                    |
  438. |                                                         |
  439. | Reads and discards a specified number of lines.         |
  440. | Option, NE - No Screen Echo, NF - No failure detection. |
  441. +--------------------------------------------------------*/
  442. options='';file=''
  443. parse arg data_lines, options
  444. Call Text_Out crlf'-> Discarding' data_lines' '
  445. if data_lines=1 then do
  446.    call Text_Out 'Line.'crlf
  447. end
  448. else do
  449.    call Text_Out 'Lines.'crlf
  450. end
  451. Parse Value Time_Delay(Port_Pause) with .
  452. do i=1 to data_lines
  453.    data=linein(port)
  454.    if pos('NF',options)=0 then Call Carrier_Detect data
  455.    if quiet=0 & options\='NE' then call lineout ,data
  456. end
  457. return fatal_error
  458.  
  459. COLLECT_LINES:
  460. /*------------------------------------------------------------------+
  461. | Syntax: Call Collect_Lines 5,'NE'                                 |
  462. |                                                                   |
  463. | Collects a specified number of lines into the DATA_LINE.x stem.   |
  464. | NE (no echo), and NF (no failure) options apply.                  |
  465. +------------------------------------------------------------------*/
  466. options='';file=''
  467. parse arg target, options
  468. Call Text_Out crlf'-> Collecting' target' '
  469. if target=1 then do
  470.    call Text_Out 'Line.'crlf
  471. end
  472. else do
  473.    call Text_Out 'Lines.'crlf
  474. end
  475. Parse Value Time_Delay(Port_Pause) with .
  476. do i=1 to target
  477.    Parse value linein(port) with data_line.i
  478.    if pos('NF',options)=0 then Call Carrier_Detect data_line.i
  479.    if quiet=0 & options\='NE' then call lineout ,i':'data_line.i
  480. end
  481. data_line.0=i-1
  482. return fatal_error
  483.  
  484. MATCH_LINES:
  485. /*------------------------------------------------------------------+
  486. | Syntax: Call Match_Lines 'line element','NFNESD',5                |
  487. |                                                  |                |
  488. | Options are, NF - No failure detection.          Max lines.       |
  489. |              NE - No echo to screen.                              |
  490. |              SD - Show a download as '.' per 10 lines captured.   |
  491. |                                                                   |
  492. | Data is captured to DATA_LINE.x                                   |
  493. +------------------------------------------------------------------*/
  494. options='';file='';limits=''
  495. parse arg target, options, limits
  496. if limits='' then limits=line_limit
  497. if target=c2d(13) then file='[CR]'
  498. if target='' then file='blank line'
  499. if pos('SD',options)=0 then Call Text_Out '-> Line matching for' file'.'crlf
  500. Parse Value Time_Delay(Port_Pause) with .
  501. do i=1 by 1 until target=data_line.i | i>limits
  502.    Parse value linein(port) with data_line.i
  503.    if pos('NF',options)=0 then Call Carrier_Detect data_line.i
  504.    if quiet=0 & pos('NE',options)=0 then call lineout ,i':'data_line.i
  505.    if pos('SD',options)>0 & i//10=0 then Call Text_Out '.'
  506. end
  507. if I>limits & pos('NF',options)=0 then do
  508.    Call modem_disconnect
  509.    Call User_Exit '(Emergency Disconnect) Match Failure for' target'.'
  510.    Call Exit
  511. end
  512. options='';file='';limits='';data_line.0=i
  513. return fatal_error
  514.  
  515. FAST_MATCH_LINES:
  516. /*------------------------------------------------------------------+
  517. | Syntax: Call Fast_Match_Lines 'line element',options,limits       |
  518. |                                                                   |
  519. | Used for capturing data as quickly as possible.  Will nab data    |
  520. | until line element is found or limits are exceeded.  Works just   |
  521. | like MATCH_LINES, however there is no carrier detect on incoming  |
  522. | data.  The routine will wait for a port timeout and call modem    |
  523. | disconnect.                                                       |
  524. |                                                                   |
  525. | Options are, NF - No failure detection.                           |
  526. |                                                                   |
  527. | Data is captured to DATA_LINE.x                                   |
  528. +------------------------------------------------------------------*/
  529. options='';file='';limits='';qqi=0
  530. parse arg target, options, limits
  531. if limits='' then limits=line_limit
  532. if target=c2d(13) then file='[CR]'
  533. if target='' then file='blank line'
  534. Parse Value Time_Delay(Port_Pause) with .
  535. do forever
  536.    qqi=qqi+1
  537.    Parse value linein(port) with data_line.qqi
  538.    if data_line.qqi = target | qqi > limits then leave
  539. end
  540. if I>limits & pos('NF',options)=0 then do
  541.    Call modem_disconnect
  542.    Call User_Exit '(Emergency Disconnect) Match Failure for' target'.'
  543.    Call exit
  544. end
  545. options='';file='';limits='';data_line.0=qqi
  546. return fatal_error
  547.  
  548. CARRIER_DETECT:
  549. /*-----------------------------------------------------------+
  550. | Syntax: Call Carrier_Detect data                           |
  551. |                                                            |
  552. | Crude, but effective.  Any additional carrier detect code  |
  553. | should go here.                                            |
  554. +-----------------------------------------------------------*/
  555. parse arg scan_data
  556. if pos('CARRIER',scan_data)>0 then do
  557.    Call Announce '-> Holy Shit!  We just lost carrier!'
  558.    Call Modem_Disconnect
  559.    Call User_Exit '(Emergency Disconnect) NO CARRIER detected.'
  560.    Call Exit
  561. End
  562. Return 0
  563.  
  564. MODEM_DISCONNECT:
  565. /*-----------------------------------------------------------+
  566. | This hangup procedure appears to work well for most modems.|
  567. | You may need to change this to suit your modem if it is    |
  568. | not Hayes compatible, or your computer is unusually fast.  |
  569. +-----------------------------------------------------------*/
  570. crlf=d2c(13)d2c(10);cr=d2c(13)
  571. Modem_Reset  = Value('MODEM_RESET',,'OS2ENVIRONMENT')
  572. Call RxSleep Command_Pause+2
  573. parse value stream(port,'c','OPEN') with pstat
  574. Call Announce 'Port is:' pstat', Attempting Disconnect!'
  575. Call Lineout Port,''
  576. Do i=1 to 5
  577.    Call Beep 2000+(i*100),25
  578.    Call Beep 2500-(i*100),25
  579. End
  580. Call Rxsleep Command_Pause
  581. Call Send '+++','NE' /* don't match for echo */
  582. Call Rxsleep Command_Pause
  583. Call Send Cr,'NE'
  584. Call Send 'ATH'cr,'NE'
  585. Call Rxsleep Command_Pause
  586. Call Send Modem_Reset''cr,'NE'
  587. return
  588.  
  589. MODEM_CONNECT:
  590. /*-----------------------------------------------------------+
  591. | Syntax: Parse Value Modem_Connect('5551212') with variable |
  592. |                                                            |
  593. | Dial a telephone number and wait for the connect message.  |
  594. | Connected: CONNECT, fatal_error is set to 1 if we fail to  |
  595. | to connect.  If MNP, we issue Connect MNP message.         |
  596. +-----------------------------------------------------------*/
  597. parse arg number
  598. Call Text_Out '-> Dialing' rmodem_service'.'crlf
  599. dial_string='ATDT'number''cr
  600. parse value Send(dial_string) with echo
  601. Call rxsleep 2
  602. Parse value Match('CONNECT','NF') with fatal_error
  603. If fatal_error=0 then do
  604.    If Modem_MNP='YES' then Do
  605.       Parse Value Match(Modem_MNP_ACK,'NF') with fatal_error
  606.       If fatal_error=0 then do
  607.          Call Announce 'MNP Connect Successful!'
  608.       End
  609.       Else do
  610.          Call Announce 'MNP Connect failure, standard connect assumed.'
  611.          modem_mnp='NO'
  612.          fatal_error=0
  613.       End
  614.    End
  615.    Else Do
  616.       Call Announce 'Connected at' baud 'BPS.'
  617.    End
  618. End
  619. Else Do
  620.    Call Announce 'Connection Failure!'
  621.    Fatal_Error=1
  622. End
  623. Return fatal_error
  624.  
  625. MODEM_COMMAND:
  626. /*-----------------------------------------------------------+
  627. | Syntax: Call Modem_Command 'ATZ'                           |
  628. |                                                            |
  629. | Send the modem an AT type command that will return a       |
  630. | expected value of OK.                                      |
  631. +-----------------------------------------------------------*/
  632. parse arg command
  633. Call Text_Out '-> Sent' command 'to' port'.'crlf
  634. Call Send command''cr,'NE' /* don't read in command echo */
  635. Parse Value Match('OK','NF') with fatal_error
  636. return fatal_error
  637.  
  638. BUFFER:
  639. /*-----------------------------------------------------------+
  640. | Write the buffer to a file.  Any match or line call will   |
  641. | reload the buffer stem.                                    |
  642. |                                                            |
  643. | Call Capture 'Command','Filename'                          |
  644. |               RESET - Resets capture, erase filename.      |
  645. |               WRITE - Write new file, reset buffer.        |
  646. |               APPEND - Append to existing file.            |
  647. |                                                            |
  648. | Buffer is DATA_LINE.x, counter is DATA_LINE.0              |
  649. +-----------------------------------------------------------*/
  650. Procedure Expose Data_Line. Os2
  651. file=''
  652. parse upper arg command, filename, file
  653. Select
  654.   When command='RESET' then do
  655.      If Exis(filename) Then Call Erase_file filename
  656.   End
  657.   When command='WRITE' then do
  658.      If Exis(filename) Then Call Erase_file filename
  659.      If file='' then do
  660.         Do qqx=1 to data_line.0
  661.            Call lineout filename,data_line.qqx
  662.         End
  663.      End
  664.      Else Do
  665.         Call lineout filename,file
  666.      End
  667.   End
  668.   When command='APPEND' then do
  669.      If file='' then do
  670.         Do qqx=1 to data_line.0
  671.            Call lineout filename,data_line.qqx
  672.         End
  673.      End
  674.      Else Do
  675.         Call lineout filename,file
  676.      End
  677.   End
  678. Otherwise
  679. End
  680. Call Lineout filename
  681. return
  682.  
  683. CHECK_INIT:
  684. /*-----------------------------------------------------------+
  685. | Called to check FATAL_ERROR after sending a command to the |
  686. | modem at startup.  If the modem command has failed we      |
  687. | assume that things are awry and exit.                      |
  688. +-----------------------------------------------------------*/
  689. If Fatal_Error\=0 then Do
  690.    Call Announce 'Modem at' port 'not responding to commands.'
  691.    Call User_Exit '(Fatal Error) Modem at' port 'not responding.'
  692.    '@EXIT'
  693.    exit 999  /* if for some reason smgenie fails to exit */
  694. End
  695. Return 0
  696.  
  697. TIME_DELAY:
  698. /*-----------------------------------------------------------+
  699. | Waits a specified amount of time.                          |
  700. +-----------------------------------------------------------*/
  701. Procedure
  702. Parse Value '0' With Command
  703. parse arg command
  704. If Command>0 then do
  705.    Call RxSleep Command
  706. End
  707. Return 0
  708.  
  709. WAIT_FOR_CALL:
  710. /*-----------------------------------------------------------+
  711. | Waits for a call from another modem.  Make sure your modem |
  712. | is NOT set for Auto Answer.  We will detect the RING       |
  713. | message and instruct the modem to answer the phone.        |
  714. +-----------------------------------------------------------*/
  715. Parse Arg Wait_Time
  716. Do until (wait_time*60)//3=1 /* number of hours to wait */
  717.    Call Send 'AT'cr
  718.    Parse Value Match_Keep('OK','NF') with Data_Line.1
  719.    If pos('RING',Data_Line.1)>0 then Do
  720.       Call Send 'ATA'cr /* pick up the phone */
  721.       Parse Value Match('CONNECT','NF') with Data_Line.2
  722.       If Modem_MNP='YES' then Do
  723.          Parse Value Match(Modem_MNP_ACK,'NF') with fatal_error
  724.          If fatal_error=0 then do
  725.             Call Announce 'MNP Connect Successful!'
  726.          End
  727.          Else do
  728.             Call Announce 'MNP Connect failure, standard connect assumed.'
  729.             modem_mnp='NO'
  730.             fatal_error=0
  731.          End
  732.       End
  733.       Else Do
  734.          Call Announce 'Connected at' baud 'BPS.'
  735.       End
  736.       If Data_Line.2=0 then Do
  737.          Return 1 /* We Connected */
  738.       End
  739.       Else Do
  740.          Return 0 /* No Connect */
  741.       End
  742.    End
  743.    Else Do
  744.       Call RxSleep 3
  745.    End
  746. End
  747. Return 0
  748.  
  749. EXIS:
  750. /*-----------------------------------------------------------+
  751. | Check for the existance of a file.                         |
  752. +-----------------------------------------------------------*/
  753. Procedure Expose os2
  754. File_exists = STREAM(ARG(1),'C','QUERY EXISTS')
  755. If file_exists='' then do
  756.    file_exists=0
  757. end
  758. else do
  759.    file_exists=1
  760. end
  761. Return File_exists
  762.  
  763. ERASE_FILE:
  764. /*-----------------------------------------------------------+
  765. | Erase a specified file.                                    |
  766. +-----------------------------------------------------------*/
  767. Procedure Expose OS2
  768. Parse Arg File_to_delete
  769. If OS2 Then Do
  770.   '@DEL' File_to_delete
  771. End
  772. Else Call DosDel File_to_delete
  773. Return
  774.  
  775. RXSLEEP:
  776. /*-----------------------------------------------------------+
  777. | Spin in a loop- there has to be a better way.              |
  778. +-----------------------------------------------------------*/
  779. Procedure Expose OS2
  780. Parse Arg count
  781. do leh=1 to count*1000
  782. end
  783. Return
  784.  
  785.