home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / README.EXE / TELEPATH.PRG < prev    next >
Encoding:
Text File  |  1991-05-01  |  17.1 KB  |  402 lines

  1. ********************************************************************
  2. * This Progress function is a crude example of a customized
  3. * function that can be specified with any protocol file transfer.
  4. * While this simple function just outputs a status line, you could
  5. * just as easily have a custom box, a progress light bar, percent
  6. * completion indicators etc.  Whenever a file transfer function
  7. * calls a User Defined Progress Function, it passes the
  8. * standardized parameters listed below.  The nCode parameter is a
  9. * code that describes the reason for the Progress function call.  The
  10. * codes correspond to the static aCodeMsg array I have defined.
  11.  
  12.  
  13. FUNCTION PROGRESS;
  14.   (nCode,cFile,nLength,nError)
  15.   STATIC aCodeMsg := {                            ;
  16.                        "Start of transfer       ",;
  17.                        "Start of file           ",;
  18.                        "Changed file name       ",;
  19.                        "Start of file data      ",;
  20.                        "Block sent or received  ",;
  21.                        "Error                   ",;
  22.                        "Aborting file           ",;
  23.                        "Aborting transfer       ",;
  24.                        "Waiting for end of file ",;
  25.                        "End of file             ",;
  26.                        "End of transfer         " ;
  27.                      }
  28.   ? cFile+" => ",aCodeMsg[nCode],nLength,tp_errmsg(nError)
  29.   RETURN 0
  30.  
  31. * The return value of your progress function can control the action
  32. * of the file transfer function as can the tp_idle() function.
  33. * Here is a list of return values and their effect although it varies
  34. * slightly with different transfer protocols.
  35. *
  36. *   0   Resume transfer if possible, otherwise generate new name if
  37. *       file already exists
  38. *   1   Abort
  39. *   2   Resume transfer if possible, otherwise overwrite existing file
  40. *   3   Skip this file
  41. *   4   Do not resume, generate new name if file already exists
  42. *   5   Do not resume, overwrite existing file
  43. *
  44. ********************************************************************
  45. * This is a sample Idle Function.  The name of this function must
  46. * be tp_idle() since this UDF actually pre-empts the do-nothing
  47. * function that is in the Telepathy library.  This function is
  48. * called by any Telepathy function that is waiting for input. If a
  49. * .T. value is returned, it causes an abort by the calling
  50. * function.
  51.  
  52. FUNCTION TP_Idle
  53.   RETURN INKEY() = 27
  54.  
  55. * In this particular example, the user pressing Esc will
  56. * cause an abort by any waiting Telepathy function.
  57. ********************************************************************
  58. * The Telepathy Notification system can be used to request
  59. * notification whenever a specified communications event occurs.
  60. * In this example, a request is posted asking to be notified when
  61. * any input is received at the serial port.  The function
  62. * OnInput() is specified as the UDF to branch to when this
  63. * communications "event" occurs.
  64.  
  65. Procedure KeyBranch;
  66.   (nPort)
  67.   LOCAL key
  68.   tp_oninput(nPort,"OnInput") // request to be notified
  69.   WHILE (key:=tp_inkey())<>27 // tp_inkey() forces a wait state
  70.     ProcessKey(key)           // your normal program processing
  71.   END
  72.   RETURN
  73.  
  74. FUNCTION OnInput
  75.   OUTERR("Input has been received at the serial Port")
  76.   RETURN QOUT()
  77.  
  78.  
  79. * The OnInput function simply sends a message to OUTERR() in this
  80. * case, but it naturally could do anything you wanted.  We could
  81. * branch to a local office messaging system, respond to a request
  82. * for data etc...  The nice thing about Notifications is that we
  83. * can post a request, and then press on doing other things.
  84. ********************************************************************
  85. * Here is a simple example of a Terminal Routine.  It takes
  86. * any keyboard input, displays it, and sends it out the serial
  87. * port. Then it reads any received characters from the input buffer
  88. * and displays them.
  89. *
  90. * Given that the port is open and communications established...
  91.  
  92. PROCEDURE SimpleTerm;
  93.   (nPort)
  94.   LOCAL key
  95.   WHILE (key:=inkey()) <> 27  .AND. tp_error()=0
  96.     IF key <> 0                // if keyboard input
  97.       tp_send(nPort,chr(key))    // send it out the port
  98.     ENDIF
  99.     QQOUT(tp_recv(nPort))      // display received characters
  100.   END
  101.   RETURN
  102.  
  103. * Just these few lines of code would suffice to operate on most BBS
  104. * systems.  You could read messages, write messages, select options
  105. * etc.  Not very fancy, and certainly no whistles and bells, but
  106. * operational nonetheless.
  107. ********************************************************************
  108.  
  109. The following are some example functions to control the modem:
  110.  
  111. ********************************************************************
  112. function MaxBaud; // determine max baud rate for modem
  113.   (nPort)
  114.   *
  115.   *   assumes port is open
  116.   *   assumes a modem is attached to port
  117.   *   returns 0 if no response from modem at 300 baud
  118.   *   leaves baud rate at same setting before test
  119.   *
  120.   local rv:=0,nBaud:=300,oBaud
  121.   oBaud := tp_baud(nPort,nBaud)
  122.   WHILE !CommErr() .AND. ModemResponds(nPort) .AND. nBaud <= 19200
  123.     rv := tp_baud(nPort,(nBaud:=nBaud*IF(nBaud=300,4,2))) // skip 600
  124.   END
  125.   tp_baud(nPort,oBaud)
  126.   CommErr()
  127.   return rv
  128. ********************************************************************
  129. function ModemResponds; // determine if modem responds to "AT"
  130.   (nPort)
  131.   * assumes nPort is open and modem attached
  132.   RETURN SendModem(nPort, chr(13) + chr(13) + "AT" )
  133. ********************************************************************
  134. STATIC;
  135. function ModemOK; // did the modem answer a command with "OK" or "0"
  136.   (nPort)
  137.   * support function - not normally called external to Hayes routines
  138.   RETURN (tp_waitfor(nPort, 1.0, "OK" + chr(13) + chr(10), "0" + chr(13)) > 0 )
  139. ********************************************************************
  140. function PortIsOpen; // determine if Port is currently open
  141.   (nPort)
  142.   RETURN tp_baud(nPort) > 0
  143. ********************************************************************
  144. function ModemResults;
  145.   (nPort,nX)
  146.   *     [  ]
  147.   *   nCodeSet = ModemResults(nPort[,nX])
  148.   *
  149.   *   Sets the result codes for the modem to nX.
  150.   *   If nX is not passed, or the value passed is not supported
  151.   *   by the modem, then the value is set to the most
  152.   *   verbose text result code that the modem supports.
  153.   *   Returns the number of the code set used (1-4).  Returns -1 if
  154.   *   modem does not respond to basic setting of X0
  155.   *
  156.   *   Assumes Port is open, and modem is attached
  157.   *
  158.   LOCAL rv,aCodeSet := {'4','3','2','1','0'}
  159.   nX := IF(nX=NIL .or. nX > 4 .or. nX < 0, 1 , 5-nX)
  160.   SendModem(nPort, "ATQ0V1" )
  161.   rv := ASCAN(aCodeSet,{|e| SendModem(nPort,"ATX"+e) } ,nX)
  162.   RETURN IF(RV<>0,5-rv,-1)
  163. ********************************************************************
  164. function Originate; // dial another modem, connect for serial communications
  165.   (nPort,cNumber,DialPrefix,nNewDelay)
  166.   *             [                    ]
  167.   *
  168.   *  If extended result codes identify a baud mismatch,
  169.   *  then modem baud rate is adjusted to match remote
  170.   *
  171.   *  If nNewDelay is passed, then it becomes the default wait for connect time
  172.   *  If function nDelay is greater than modem register value...
  173.   *       modem will return NO ANSWER prior to function timing out
  174.   *
  175.   STATIC nDelay := 30.0
  176.   LOCAL  nModemMsg,nBaud
  177.   RESET  nDelay to nNewDelay
  178.   DIAL(nPort,cNumber,DialPrefix)
  179.   IF (nModemMsg := tp_waitfor(nPort, nDelay, ModemMsgs())) = 1
  180.     MatchBaud(nPort)
  181.   ELSE
  182.     CommErr(nModemMsg)
  183.     Hangup(nPort)
  184.   ENDIF
  185.   return tp_isdcd(nPort)
  186. ********************************************************************
  187. Procedure Dial; // dial a number, and remain off-hook
  188.   (nPort,cNumber,NewDialPrefix)
  189.   *             [              ]
  190.   *
  191.   *   Dial phone number cNumber on the modem attached to nPort.
  192.   *
  193.   STATIC DialPrefix := "ATDT"
  194.   RESET DialPrefix TO NewDialPrefix
  195.   SendModem(nPort, DialPrefix + cNumber )
  196.   return
  197. ********************************************************************
  198. FUNCTION SendModem; // send HAYES commands to modem at slow speed
  199.   (nPort, cCommand, cNewTerminator , nNewDelay )
  200.   *               [                             ]
  201.   *   Some modems cannot handle commands sent at full speed.  This
  202.   *   functions inserts a small delay between characters.
  203.   *
  204.   *   If nNewDelay is send, it becomes the new permanent delay time
  205.   *
  206.   STATIC nDelay := 0.05, cTerminator
  207.   LOCAL I
  208.   DEFAULT cTerminator to CHR(13)
  209.   RESET nDelay to nNewDelay, cTerminator to cNewTerminator
  210.   cCommand += cTerminator
  211.   tp_flowon(nPort)
  212.   IF ! CommErr()
  213.     for I = 1 to len(cCommand)
  214.       tp_flush(nPort, nDelay)
  215.       tp_delay(nDelay)
  216.       tp_sendsub(nPort, cCommand, I, 1)
  217.     next
  218.     CommErr()
  219.   ENDIF
  220.   return ModemOK(nPort)
  221. ********************************************************************
  222.  
  223.  
  224. TELEPATHY ERROR CODES
  225.  
  226.  
  227. ********************************************************************
  228.     General Errors
  229.           Name        Code        Message
  230.                          0        No error
  231.           TE_PARAM      -1        Bad function parameter
  232.           TE_NOPORT     -2        No such serial port
  233.           TE_CLOSED     -3        Serial port is not open
  234.           TE_CONFL      -4        Serial port IRQ conflict
  235.           TE_TMOUT      -5        Timeout
  236.           TE_NDCD       -6        Connection lost
  237.           TE_ESCAPE     -7        User escape
  238.           TE_LENGTH     -8        Reached length limit
  239.           TE_CANCEL     -9        Canceled
  240.     File Transfer Errors:
  241.           TE_UCANCEL   -50        Canceled by user
  242.           TE_RCANCEL   -51        Canceled by remote
  243.           TE_STARTTM   -52        Timeout waiting to start
  244.           TE_BLOCKTM   -53        Timeout waiting for packet
  245.           TE_ACKTM     -54        Timeout waiting for ACK
  246.           TE_SENDTM    -55        Timeout waiting to send
  247.           TE_CLEARTM   -56        Timeout waiting to clear
  248.           TE_NAK       -57        Negative acknowledgement
  249.           TE_BADACK    -58        Bad ACK/NAK character
  250.           TE_BADBLK    -59        Bad packet format
  251.           TE_LONGBLK   -60        Packet too long
  252.           TE_ERRMAX    -61        Too many errors
  253.           TE_DUPBLK    -62        Duplicate packet
  254.           TE_PROTO     -63        Protocol failure
  255.           TE_CKSUM     -64        Checksum error
  256.           TE_HDRTM     -65        Timeout waiting for header
  257.     DOS Errors
  258.           TE_DISKFULL -100        Disk full
  259.           TE_NOFILE   -102        File not found
  260.           TE_NOPATH   -103        Path not found
  261.           TE_MFILE    -104        Too many files open
  262.           TE_ACCESS   -105        Access denied
  263.  
  264. ********************************************************************
  265.  
  266.  
  267.  
  268. TELEPATHY FUNCTION LISTING
  269.  
  270.  
  271.  
  272. *********************************************************************
  273. FILE TRANSFER
  274. *********************************************************************
  275.                      ***********  XMODEM ****************
  276. TP_RX1K()            Receive file using Xmodem-1K
  277. TP_RXCRC()           Receive file using Xmodem-CRC
  278. TP_RXMODEM()         Receive file using Xmodem
  279. TP_SX1K()            Send file using Xmodem-1K
  280. TP_SXMODEM()         Send file using Xmodem or Xmodem-CRC
  281.                      ***********  YMODEM ****************
  282. TP_RYMODEM()         Receive files using Ymodem
  283. TP_SYMODEM()         Send files using Ymodem
  284. TP_RYG())            Receive a file using Ymodem_G
  285.                      ***********  ZMODEM ****************
  286. TP_RZMODEM()         Receive files using Zmodem
  287. TP_SZMODEM()         Send files using Zmodem
  288. TP_ZBLKLEN()         Get or set Zmodem block length
  289. TP_ZFCONV()          Get or set Zmodem file conversion opt
  290. TP_ZPARAM()          Set Zmodem parameters
  291.                      ***********  KERMIT ****************
  292. TP_RKERMIT()         Receive files using Kermit
  293. TP_SKERMIT()         Send files using Kermit
  294. TP_KPARAM()          Set Kermit parameters
  295.                      ***********   MISC  ****************
  296. TP_XDCD()            Get or set file transfer DCD flag
  297. TP_XYPARAM()         Set Xmodem/Ymodem parameters
  298. TP_XBUFSIZE()        Get or set file buffer size
  299. *********************************************************************
  300. UART STATUS / CONTROL
  301. *********************************************************************
  302. TP_CTRLCTS()         Get or set CTS handshake setting
  303. TP_CTRLDCD()         Get or set DCD handshake setting
  304. TP_CTRLDSR()         Get or set DSR handshake setting
  305. TP_CTRLDTR()         Get or set DTR handshake setting
  306. TP_CTRLRTS()         Get or set RTS handshake setting
  307. TP_CTRLX()           Get or set XON/XOFF handshake setting
  308. TP_FIFO()            Get or set 16550 FIFO state
  309. TP_FLOWON()          Override received XOFF
  310. TP_HIMARK()          Get or set XOFF high-water mark
  311. TP_HSHK()            Get or set handshake settings
  312. TP_IDLE()            Idle procedure
  313. TP_ISCTS()           Return CTS status
  314. TP_ISDCD()           Return DCD status
  315. TP_ISDSR()           Return DSR status
  316. TP_ISRI()            Return RI status
  317. TP_LOMARK()          Get or set XON low-water mark
  318. TP_LSTAT()           Return line status
  319. TP_MSTAT()           Return modem status
  320. *********************************************************************
  321. GENERAL SERIAL PORT CONTROL
  322. *********************************************************************
  323. TP_BAUD()            Get or set baud rate
  324. TP_CLOSE()           Close serial port
  325. TP_DATA()            Get or set number of data bits
  326. TP_ISPORT()          Check whether serial port exists
  327. TP_OPEN()            Open serial port
  328. TP_PARITY()          Get or set parity setting
  329. TP_REOPEN()          Reopen serial port
  330. TP_SETPORT()         Configure special port
  331. TP_STOP()            Get or set number of stop bits
  332. *********************************************************************
  333. RECEIVE DATA
  334. *********************************************************************
  335. TP_CLEARIN()         Clear input buffer
  336. TP_INCHRS()          number of characters in buffer
  337. TP_INFREE()          Get free space in input buffer
  338. TP_LOOKFOR()         Look for character in input buffer
  339. TP_RECV()            Receive string
  340. TP_RECVB()           Receive string to buffer (S87 only)
  341. TP_RECVLN()          Line input with editing
  342. TP_RECVTO()          Receive string up to delimiter
  343. TP_SETLN()           Set parameters for tp_recvln()
  344. TP_STRIPHI()         Get or set high-bit-strip flag
  345. TP_WAITFOR()         Wait for one of several strings
  346. *********************************************************************
  347. TRANSMIT DATA
  348. *********************************************************************
  349. TP_BREAK()           Send serial break
  350. TP_CLEAROUT()        Clear output buffer
  351. TP_FLOWCHK()         Check output flow control
  352. TP_FLUSH()           Flush output buffer
  353. TP_OUTCHRS()         Get number of characters in buffer
  354. TP_OUTFREE()         Get free space in output buffer
  355. TP_SEND()            Send string
  356. TP_SENDSUB()         Send part of string
  357. *********************************************************************
  358. GENERAL
  359. *********************************************************************
  360. TP_DELAY()           Pause while handling notifications
  361. TP_GMTOFF()          Get or set time zone offset
  362. *********************************************************************
  363. TERMINAL EMULATION
  364. *********************************************************************
  365. TP_ANSI()            ANSI  terminal emulation.
  366. TP_TFLAGS()          Control emulation flags
  367. TP_TPOS()            Set cursor position relative to emulator Window
  368. TP_TSEND()           Send a string to the terminal emulator port
  369. TP_TTY()             TTY terminal emulation.
  370. *********************************************************************
  371. BIT AND BYTE STUFF
  372. *********************************************************************
  373. BIN_AND()            Binary AND
  374. BIN_NOT()            Binary negation
  375. BIN_OR()             Binary OR
  376. BIN_XOR()            Binary exclusive OR
  377. TP_STRHEX()          Convert string to hexadecimal
  378. *********************************************************************
  379. EVENT NOTIFICATION
  380. *********************************************************************
  381. TP_CLRKBD()          Clear typeahead buffer
  382. TP_INKEY()           Read a key and handle notifications
  383. TP_NOTEOFF()         Disable a pending notification
  384. TP_ONCHAR()          Notify on receipt of character
  385. TP_ONEMPTY()         Notify when output buffer empty
  386. TP_ONHIMARK()        Notify on high-water mark
  387. TP_ONINPUT()         Notify on any input
  388. TP_ONMODEM()         Notify when modem status changes
  389. TP_ONTIME()          Notify after a number of seconds
  390. TP_RESUME()          Resume notifications
  391. TP_SUSPEND()         Suspend notifications
  392. TP_GETWATCH()        Report non-zero watch, and decrement
  393. TP_ISWATCH()         Report when watch string has been read
  394. TP_WATCH()           Register a watch string
  395. TP_WATCHOFF()        Unregister a watch string
  396. *********************************************************************
  397. ERROR CONTROL
  398. *********************************************************************
  399. TP_ERRCODES()        Define error codes  (not needed in 5.0)
  400. TP_ERRMSG()          Convert error code to English text
  401. TP_ERROR()           Error code from last operation
  402.