home *** CD-ROM | disk | FTP | other *** search
- ********************************************************************
- * This Progress function is a crude example of a customized
- * function that can be specified with any protocol file transfer.
- * While this simple function just outputs a status line, you could
- * just as easily have a custom box, a progress light bar, percent
- * completion indicators etc. Whenever a file transfer function
- * calls a User Defined Progress Function, it passes the
- * standardized parameters listed below. The nCode parameter is a
- * code that describes the reason for the Progress function call. The
- * codes correspond to the static aCodeMsg array I have defined.
-
-
- FUNCTION PROGRESS;
- (nCode,cFile,nLength,nError)
- STATIC aCodeMsg := { ;
- "Start of transfer ",;
- "Start of file ",;
- "Changed file name ",;
- "Start of file data ",;
- "Block sent or received ",;
- "Error ",;
- "Aborting file ",;
- "Aborting transfer ",;
- "Waiting for end of file ",;
- "End of file ",;
- "End of transfer " ;
- }
- ? cFile+" => ",aCodeMsg[nCode],nLength,tp_errmsg(nError)
- RETURN 0
-
- * The return value of your progress function can control the action
- * of the file transfer function as can the tp_idle() function.
- * Here is a list of return values and their effect although it varies
- * slightly with different transfer protocols.
- *
- * 0 Resume transfer if possible, otherwise generate new name if
- * file already exists
- * 1 Abort
- * 2 Resume transfer if possible, otherwise overwrite existing file
- * 3 Skip this file
- * 4 Do not resume, generate new name if file already exists
- * 5 Do not resume, overwrite existing file
- *
- ********************************************************************
- * This is a sample Idle Function. The name of this function must
- * be tp_idle() since this UDF actually pre-empts the do-nothing
- * function that is in the Telepathy library. This function is
- * called by any Telepathy function that is waiting for input. If a
- * .T. value is returned, it causes an abort by the calling
- * function.
-
- FUNCTION TP_Idle
- RETURN INKEY() = 27
-
- * In this particular example, the user pressing Esc will
- * cause an abort by any waiting Telepathy function.
- ********************************************************************
- * The Telepathy Notification system can be used to request
- * notification whenever a specified communications event occurs.
- * In this example, a request is posted asking to be notified when
- * any input is received at the serial port. The function
- * OnInput() is specified as the UDF to branch to when this
- * communications "event" occurs.
-
- Procedure KeyBranch;
- (nPort)
- LOCAL key
- tp_oninput(nPort,"OnInput") // request to be notified
- WHILE (key:=tp_inkey())<>27 // tp_inkey() forces a wait state
- ProcessKey(key) // your normal program processing
- END
- RETURN
-
- FUNCTION OnInput
- OUTERR("Input has been received at the serial Port")
- RETURN QOUT()
-
-
- * The OnInput function simply sends a message to OUTERR() in this
- * case, but it naturally could do anything you wanted. We could
- * branch to a local office messaging system, respond to a request
- * for data etc... The nice thing about Notifications is that we
- * can post a request, and then press on doing other things.
- ********************************************************************
- * Here is a simple example of a Terminal Routine. It takes
- * any keyboard input, displays it, and sends it out the serial
- * port. Then it reads any received characters from the input buffer
- * and displays them.
- *
- * Given that the port is open and communications established...
-
- PROCEDURE SimpleTerm;
- (nPort)
- LOCAL key
- WHILE (key:=inkey()) <> 27 .AND. tp_error()=0
- IF key <> 0 // if keyboard input
- tp_send(nPort,chr(key)) // send it out the port
- ENDIF
- QQOUT(tp_recv(nPort)) // display received characters
- END
- RETURN
-
- * Just these few lines of code would suffice to operate on most BBS
- * systems. You could read messages, write messages, select options
- * etc. Not very fancy, and certainly no whistles and bells, but
- * operational nonetheless.
- ********************************************************************
-
- The following are some example functions to control the modem:
-
- ********************************************************************
- function MaxBaud; // determine max baud rate for modem
- (nPort)
- *
- * assumes port is open
- * assumes a modem is attached to port
- * returns 0 if no response from modem at 300 baud
- * leaves baud rate at same setting before test
- *
- local rv:=0,nBaud:=300,oBaud
- oBaud := tp_baud(nPort,nBaud)
- WHILE !CommErr() .AND. ModemResponds(nPort) .AND. nBaud <= 19200
- rv := tp_baud(nPort,(nBaud:=nBaud*IF(nBaud=300,4,2))) // skip 600
- END
- tp_baud(nPort,oBaud)
- CommErr()
- return rv
- ********************************************************************
- function ModemResponds; // determine if modem responds to "AT"
- (nPort)
- * assumes nPort is open and modem attached
- RETURN SendModem(nPort, chr(13) + chr(13) + "AT" )
- ********************************************************************
- STATIC;
- function ModemOK; // did the modem answer a command with "OK" or "0"
- (nPort)
- * support function - not normally called external to Hayes routines
- RETURN (tp_waitfor(nPort, 1.0, "OK" + chr(13) + chr(10), "0" + chr(13)) > 0 )
- ********************************************************************
- function PortIsOpen; // determine if Port is currently open
- (nPort)
- RETURN tp_baud(nPort) > 0
- ********************************************************************
- function ModemResults;
- (nPort,nX)
- * [ ]
- * nCodeSet = ModemResults(nPort[,nX])
- *
- * Sets the result codes for the modem to nX.
- * If nX is not passed, or the value passed is not supported
- * by the modem, then the value is set to the most
- * verbose text result code that the modem supports.
- * Returns the number of the code set used (1-4). Returns -1 if
- * modem does not respond to basic setting of X0
- *
- * Assumes Port is open, and modem is attached
- *
- LOCAL rv,aCodeSet := {'4','3','2','1','0'}
- nX := IF(nX=NIL .or. nX > 4 .or. nX < 0, 1 , 5-nX)
- SendModem(nPort, "ATQ0V1" )
- rv := ASCAN(aCodeSet,{|e| SendModem(nPort,"ATX"+e) } ,nX)
- RETURN IF(RV<>0,5-rv,-1)
- ********************************************************************
- function Originate; // dial another modem, connect for serial communications
- (nPort,cNumber,DialPrefix,nNewDelay)
- * [ ]
- *
- * If extended result codes identify a baud mismatch,
- * then modem baud rate is adjusted to match remote
- *
- * If nNewDelay is passed, then it becomes the default wait for connect time
- * If function nDelay is greater than modem register value...
- * modem will return NO ANSWER prior to function timing out
- *
- STATIC nDelay := 30.0
- LOCAL nModemMsg,nBaud
- RESET nDelay to nNewDelay
- DIAL(nPort,cNumber,DialPrefix)
- IF (nModemMsg := tp_waitfor(nPort, nDelay, ModemMsgs())) = 1
- MatchBaud(nPort)
- ELSE
- CommErr(nModemMsg)
- Hangup(nPort)
- ENDIF
- return tp_isdcd(nPort)
- ********************************************************************
- Procedure Dial; // dial a number, and remain off-hook
- (nPort,cNumber,NewDialPrefix)
- * [ ]
- *
- * Dial phone number cNumber on the modem attached to nPort.
- *
- STATIC DialPrefix := "ATDT"
- RESET DialPrefix TO NewDialPrefix
- SendModem(nPort, DialPrefix + cNumber )
- return
- ********************************************************************
- FUNCTION SendModem; // send HAYES commands to modem at slow speed
- (nPort, cCommand, cNewTerminator , nNewDelay )
- * [ ]
- * Some modems cannot handle commands sent at full speed. This
- * functions inserts a small delay between characters.
- *
- * If nNewDelay is send, it becomes the new permanent delay time
- *
- STATIC nDelay := 0.05, cTerminator
- LOCAL I
- DEFAULT cTerminator to CHR(13)
- RESET nDelay to nNewDelay, cTerminator to cNewTerminator
- cCommand += cTerminator
- tp_flowon(nPort)
- IF ! CommErr()
- for I = 1 to len(cCommand)
- tp_flush(nPort, nDelay)
- tp_delay(nDelay)
- tp_sendsub(nPort, cCommand, I, 1)
- next
- CommErr()
- ENDIF
- return ModemOK(nPort)
- ********************************************************************
-
-
- TELEPATHY ERROR CODES
-
-
- ********************************************************************
- General Errors
- Name Code Message
- 0 No error
- TE_PARAM -1 Bad function parameter
- TE_NOPORT -2 No such serial port
- TE_CLOSED -3 Serial port is not open
- TE_CONFL -4 Serial port IRQ conflict
- TE_TMOUT -5 Timeout
- TE_NDCD -6 Connection lost
- TE_ESCAPE -7 User escape
- TE_LENGTH -8 Reached length limit
- TE_CANCEL -9 Canceled
- File Transfer Errors:
- TE_UCANCEL -50 Canceled by user
- TE_RCANCEL -51 Canceled by remote
- TE_STARTTM -52 Timeout waiting to start
- TE_BLOCKTM -53 Timeout waiting for packet
- TE_ACKTM -54 Timeout waiting for ACK
- TE_SENDTM -55 Timeout waiting to send
- TE_CLEARTM -56 Timeout waiting to clear
- TE_NAK -57 Negative acknowledgement
- TE_BADACK -58 Bad ACK/NAK character
- TE_BADBLK -59 Bad packet format
- TE_LONGBLK -60 Packet too long
- TE_ERRMAX -61 Too many errors
- TE_DUPBLK -62 Duplicate packet
- TE_PROTO -63 Protocol failure
- TE_CKSUM -64 Checksum error
- TE_HDRTM -65 Timeout waiting for header
- DOS Errors
- TE_DISKFULL -100 Disk full
- TE_NOFILE -102 File not found
- TE_NOPATH -103 Path not found
- TE_MFILE -104 Too many files open
- TE_ACCESS -105 Access denied
-
- ********************************************************************
-
-
-
- TELEPATHY FUNCTION LISTING
-
-
-
- *********************************************************************
- FILE TRANSFER
- *********************************************************************
- *********** XMODEM ****************
- TP_RX1K() Receive file using Xmodem-1K
- TP_RXCRC() Receive file using Xmodem-CRC
- TP_RXMODEM() Receive file using Xmodem
- TP_SX1K() Send file using Xmodem-1K
- TP_SXMODEM() Send file using Xmodem or Xmodem-CRC
- *********** YMODEM ****************
- TP_RYMODEM() Receive files using Ymodem
- TP_SYMODEM() Send files using Ymodem
- TP_RYG()) Receive a file using Ymodem_G
- *********** ZMODEM ****************
- TP_RZMODEM() Receive files using Zmodem
- TP_SZMODEM() Send files using Zmodem
- TP_ZBLKLEN() Get or set Zmodem block length
- TP_ZFCONV() Get or set Zmodem file conversion opt
- TP_ZPARAM() Set Zmodem parameters
- *********** KERMIT ****************
- TP_RKERMIT() Receive files using Kermit
- TP_SKERMIT() Send files using Kermit
- TP_KPARAM() Set Kermit parameters
- *********** MISC ****************
- TP_XDCD() Get or set file transfer DCD flag
- TP_XYPARAM() Set Xmodem/Ymodem parameters
- TP_XBUFSIZE() Get or set file buffer size
- *********************************************************************
- UART STATUS / CONTROL
- *********************************************************************
- TP_CTRLCTS() Get or set CTS handshake setting
- TP_CTRLDCD() Get or set DCD handshake setting
- TP_CTRLDSR() Get or set DSR handshake setting
- TP_CTRLDTR() Get or set DTR handshake setting
- TP_CTRLRTS() Get or set RTS handshake setting
- TP_CTRLX() Get or set XON/XOFF handshake setting
- TP_FIFO() Get or set 16550 FIFO state
- TP_FLOWON() Override received XOFF
- TP_HIMARK() Get or set XOFF high-water mark
- TP_HSHK() Get or set handshake settings
- TP_IDLE() Idle procedure
- TP_ISCTS() Return CTS status
- TP_ISDCD() Return DCD status
- TP_ISDSR() Return DSR status
- TP_ISRI() Return RI status
- TP_LOMARK() Get or set XON low-water mark
- TP_LSTAT() Return line status
- TP_MSTAT() Return modem status
- *********************************************************************
- GENERAL SERIAL PORT CONTROL
- *********************************************************************
- TP_BAUD() Get or set baud rate
- TP_CLOSE() Close serial port
- TP_DATA() Get or set number of data bits
- TP_ISPORT() Check whether serial port exists
- TP_OPEN() Open serial port
- TP_PARITY() Get or set parity setting
- TP_REOPEN() Reopen serial port
- TP_SETPORT() Configure special port
- TP_STOP() Get or set number of stop bits
- *********************************************************************
- RECEIVE DATA
- *********************************************************************
- TP_CLEARIN() Clear input buffer
- TP_INCHRS() number of characters in buffer
- TP_INFREE() Get free space in input buffer
- TP_LOOKFOR() Look for character in input buffer
- TP_RECV() Receive string
- TP_RECVB() Receive string to buffer (S87 only)
- TP_RECVLN() Line input with editing
- TP_RECVTO() Receive string up to delimiter
- TP_SETLN() Set parameters for tp_recvln()
- TP_STRIPHI() Get or set high-bit-strip flag
- TP_WAITFOR() Wait for one of several strings
- *********************************************************************
- TRANSMIT DATA
- *********************************************************************
- TP_BREAK() Send serial break
- TP_CLEAROUT() Clear output buffer
- TP_FLOWCHK() Check output flow control
- TP_FLUSH() Flush output buffer
- TP_OUTCHRS() Get number of characters in buffer
- TP_OUTFREE() Get free space in output buffer
- TP_SEND() Send string
- TP_SENDSUB() Send part of string
- *********************************************************************
- GENERAL
- *********************************************************************
- TP_DELAY() Pause while handling notifications
- TP_GMTOFF() Get or set time zone offset
- *********************************************************************
- TERMINAL EMULATION
- *********************************************************************
- TP_ANSI() ANSI terminal emulation.
- TP_TFLAGS() Control emulation flags
- TP_TPOS() Set cursor position relative to emulator Window
- TP_TSEND() Send a string to the terminal emulator port
- TP_TTY() TTY terminal emulation.
- *********************************************************************
- BIT AND BYTE STUFF
- *********************************************************************
- BIN_AND() Binary AND
- BIN_NOT() Binary negation
- BIN_OR() Binary OR
- BIN_XOR() Binary exclusive OR
- TP_STRHEX() Convert string to hexadecimal
- *********************************************************************
- EVENT NOTIFICATION
- *********************************************************************
- TP_CLRKBD() Clear typeahead buffer
- TP_INKEY() Read a key and handle notifications
- TP_NOTEOFF() Disable a pending notification
- TP_ONCHAR() Notify on receipt of character
- TP_ONEMPTY() Notify when output buffer empty
- TP_ONHIMARK() Notify on high-water mark
- TP_ONINPUT() Notify on any input
- TP_ONMODEM() Notify when modem status changes
- TP_ONTIME() Notify after a number of seconds
- TP_RESUME() Resume notifications
- TP_SUSPEND() Suspend notifications
- TP_GETWATCH() Report non-zero watch, and decrement
- TP_ISWATCH() Report when watch string has been read
- TP_WATCH() Register a watch string
- TP_WATCHOFF() Unregister a watch string
- *********************************************************************
- ERROR CONTROL
- *********************************************************************
- TP_ERRCODES() Define error codes (not needed in 5.0)
- TP_ERRMSG() Convert error code to English text
- TP_ERROR() Error code from last operation
-