home *** CD-ROM | disk | FTP | other *** search
- *.............................................................................
- *
- * Program Name: CTFUTIL Copyright: Magna Carta Software, Inc.
- * Date Created: 09-27-92 Language: FoxPro 2.0
- *.............................................................................
- * Description: Data format routines for 'CommTools -- Fox' examples.
- * Do NOT run this file directly. It is DOed by FOXCOMxx examples, starting
- * with FOXCOM04
- *.............................................................................
-
-
- * Define Pull-Down Bar and Pads
- DEFINE MENU main_menu IN SCREEN COLOR SCHEME 3
- DEFINE PAD p_ct_quit OF main_menu PROMPT "\<Quit" AT 00, 00
- ON SELECTION PAD p_ct_quit OF main_menu =ct_quit(portid)
- DEFINE PAD p_ct_online OF main_menu PROMPT "\<Go Online" AT 00, 06
- ON SELECTION PAD p_ct_online OF main_menu =ct_online(portid)
- DEFINE PAD p_ct_speed OF main_menu PROMPT "S\<peed" AT 00, 17
- ON SELECTION PAD p_ct_speed OF main_menu =do_speed(portid, 17)
- DEFINE PAD p_ct_dataform OF main_menu PROMPT "\<Data Format" AT 00, 24
- ON SELECTION PAD p_ct_dataform OF main_menu =ct_dataformat(portid, 24)
-
- * Define Windows
- DEFINE WINDOW w_term FROM 01, 00 TO SROWS()-4, SCOLS()-1;
- IN SCREEN;
- TITLE " FoxCom Terminal " DOUBLE COLOR SCHEME 7
-
- DEFINE WINDOW w_status FROM SROWS()-3, 00 TO SROWS()-1, 79;
- IN SCREEN;
- TITLE " FoxCom Status " DOUBLE COLOR SCHEME 17
-
-
-
- *
- * CT_DATAFORMAT(expN portid, expN dataparm)
- * Set the data format
- *
- FUNCTION ct_dataformat
- PARAMETER portid, col
- PRIVATE lrow
-
- lrow = WROWS() - 1
- @ lrow, 0 CLEAR TO lrow, WCOLS()-2
-
- DEFINE POPUP pop_dataform FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_dataform PROMPT " Data "
- DEFINE BAR 2 OF pop_dataform PROMPT " Parity "
- DEFINE BAR 3 OF pop_dataform PROMPT " Stop "
-
- ON SELECTION POPUP pop_dataform =_ct_dataformat(portid, BAR(), col+10)
- =display_data_format(portid)
- ACTIVATE POPUP pop_dataform
- DEACTIVATE POPUP pop_dataform
- RELEASE pop_dataform
- RETURN (0)
-
-
- FUNCTION display_data_format
- PARAMETERS portid
- PRIVATE dbits, pbits, sbits, speed, lrow
- DIMENSION a_par[8]
-
- a_par[1] = "NONE"
- a_par[2] = "ODD"
- a_par[3] = "EVEN"
- a_par[4] = "MARK"
- a_par[5] = "SPACE"
-
- ACTIVATE WINDOW w_status
- lrow = WROWS() - 1
- dbits = get_parm(portid, DATABITS)
- sbits = get_parm(portid, STOPBITS)
- pbits = get_parm(portid, PARITY)
- speed = get_speed(portid)
- @ lrow, 35 SAY "Data: " + ALLTRIM(STR(dbits))
- @ lrow, 43 SAY "Stop: " + ALLTRIM(STR(sbits))
- @ lrow, 51 SAY "Parity: " + a_par[pbits+1]
- @ lrow, 65 SAY "Speed: " + ALLTRIM(STR(speed))
- RETURN (0)
-
-
- FUNCTION _ct_dataformat
- PARAMETERS portid, dataform, col
-
- DO CASE
- CASE dataform = 1
- =do_databits(portid, col)
- CASE dataform = 2
- =do_parity(portid, col)
- CASE dataform = 3
- =do_stopbits(portid, col)
- ENDCASE
- =display_data_format(portid)
- RETURN (0)
-
-
-
- *
- * DO_DATABITS(expN portid, expN col)
- * Show a menu that allows the user to set the number of data bits.
- * Called from data_format_menu()
- *
- FUNCTION do_databits
- PARAMETERS portid, col
-
- DEFINE POPUP pop_databits FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_databits PROMPT " 5 "
- DEFINE BAR 2 OF pop_databits PROMPT " 6 "
- DEFINE BAR 3 OF pop_databits PROMPT " 7 "
- DEFINE BAR 4 OF pop_databits PROMPT " 8 "
-
- ON SELECTION POPUP pop_databits =_do_databits(portid, VAL(PROMPT()))
- ACTIVATE POPUP pop_databits
- RELEASE pop_databits
- RETURN (0)
-
-
-
- FUNCTION _do_databits
- PARAMETERS portid, dbits
- PRIVATE ret
-
- ret = set_parm(portid, DATABITS, dbits)
- DEACTIVATE POPUP pop_databits
- RETURN (ret)
-
-
-
- *
- * DO_STOPBITS(expN portid, expN col)
- * Show a menu that allows the user to set the number of stopbits
- * Called from data_format_menu()
- *
- FUNCTION do_stopbits
- PARAMETERS portid, col
- PRIVATE sbits
-
- DEFINE POPUP pop_stopbits FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_stopbits PROMPT " 1 "
- DEFINE BAR 2 OF pop_stopbits PROMPT " 2 "
-
- ON SELECTION POPUP pop_stopbits =_do_stopbits(portid, VAL(PROMPT()))
- ACTIVATE POPUP pop_stopbits
- RELEASE pop_stopbits
- RETURN (0)
-
-
-
- FUNCTION _do_stopbits
- PARAMETERS portid, sbits
- PRIVATE ret
-
- ret = set_parm(portid, STOPBITS, sbits)
- DEACTIVATE POPUP pop_stopbits
- RETURN (ret)
-
-
-
- *
- * DO_PARITY(expN portid, expN col)
- * Show a menu that allows the user to set parity.
- * Called from data_format_menu()
- *
- FUNCTION do_parity
- PARAMETERS portid, col
- PRIVATE pbits
-
- DEFINE POPUP pop_parity FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_parity PROMPT "NONE"
- DEFINE BAR 2 OF pop_parity PROMPT "ODD"
- DEFINE BAR 3 OF pop_parity PROMPT "EVEN"
- DEFINE BAR 4 OF pop_parity PROMPT "MARK"
- DEFINE BAR 5 OF pop_parity PROMPT "SPACE"
-
- ON SELECTION POPUP pop_parity =_do_parity(portid, PROMPT())
- ACTIVATE POPUP pop_parity
- RELEASE pop_parity
- RETURN (0)
-
-
-
- FUNCTION _do_parity
- PARAMETERS portid, nChoice
- PRIVATE ret
-
- nChoice = ALLTRIM(nChoice)
- DO CASE
- CASE nChoice = 'NONE'
- ret = PARITY_NONE
- CASE nChoice = 'ODD'
- ret = PARITY_ODD
- CASE nChoice = 'EVEN'
- ret = PARITY_EVEN
- CASE nChoice = 'MARK'
- ret = PARITY_MARK
- CASE nChoice = 'SPACE'
- ret = PARITY_SPACE
- OTHERWISE
- ret = -1
- ENDCASE
- IF ret >= 0
- ret = set_parm(portid, PARITY, ret)
- DEACTIVATE POPUP pop_parity
- ENDIF
- RETURN (ret)
-
-
-
- *
- * DO_SPEED(expN portid)
- * This menu allows the user to select the data transfer rate.
- *
- PROCEDURE do_speed
- PARAMETERS portid, col
- PRIVATE speed
-
- DEFINE POPUP pop_speed FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_speed PROMPT "50"
- DEFINE BAR 2 OF pop_speed PROMPT "75"
- DEFINE BAR 3 OF pop_speed PROMPT "110"
- DEFINE BAR 4 OF pop_speed PROMPT "150"
- DEFINE BAR 5 OF pop_speed PROMPT "300"
- DEFINE BAR 6 OF pop_speed PROMPT "600"
- DEFINE BAR 7 OF pop_speed PROMPT "1200"
- DEFINE BAR 8 OF pop_speed PROMPT "2400"
- DEFINE BAR 9 OF pop_speed PROMPT "4800"
- DEFINE BAR 10 OF pop_speed PROMPT "9600"
- DEFINE BAR 11 OF pop_speed PROMPT "19200"
- DEFINE BAR 12 OF pop_speed PROMPT "38400"
- DEFINE BAR 13 OF pop_speed PROMPT "57600"
- DEFINE BAR 14 OF pop_speed PROMPT "115200"
-
- ON SELECTION POPUP pop_speed =_do_speed(portid, VAL(PROMPT()))
- =display_data_format(portid)
- ACTIVATE POPUP pop_speed
- RELEASE pop_speed
- RETURN (0)
-
-
-
- FUNCTION _do_speed
- PARAMETERS portid, speed
- PRIVATE ret
-
- ret = set_speed(portid, speed)
- =display_data_format(portid)
- DEACTIVATE POPUP pop_speed
- RETURN (ret)
-
-
-
- FUNCTION clear_status_line
- PARAMETERS rstart, rend
- PRIVATE row
- ACTIVATE WINDOW w_status
- row = WROWS() - 1
- @row, rstart CLEAR TO row, rend
- RETURN
-
-
-
- FUNCTION status_msg
- PARAMETERS col, msg
- =clear_status_line(col, 78)
- @WROWS()-1, col SAY msg
- RETURN (0)
-
-
-
- FUNCTION ct_quit
- PARAMETERS portid
-
- DEACTIVATE WINDOW w_term
- DEACTIVATE WINDOW w_status
- CLEAR
- @ SROWS()/2-1, 00 SAY PADC("End of CommTools Terminal Version " + ALLTRIM(STR(version)), WCOLS())
- @ SROWS()/2, 00 SAY PADC("Thank You for Using CommTools - Fox", WCOLS())
- CLOSE PROCEDURE
- DEACTIVATE MENU main_menu
- CLEAR ALL
- EXIT
- RETURN (0)
-
-
-
- *.............................................................................
- *
- * GET_FILNAM -- Get a file name from the user.
- * Parameters:
- * status -- Flag indicating whether file is to be sent (.T.) or received (.F.)
- * Return Value:
- * The file name
- *.............................................................................
- FUNCTION get_filnam
- PARAMETERS status
- PRIVATE scr, fnam, done, direct, i
- PUBLIC getlist, def_colors
-
- done = .F.
- direct = IIF(status,"Send:","Receive:")
- SET SCOREBOARD off
-
- * Define Window for File Name
- DEFINE WINDOW w_fname FROM 10,20 TO 16,70 TITLE 'File Select Window' ;
- SHADOW
- ACTIVATE WINDOW w_fname
-
- @ 1,1 SAY "Enter name of file to"
- @ 1,23 say direct
-
- DO WHILE !DONE
- fnam = SPACE(80)
- @ 1,30 GET fnam PICTURE "@!S16"
- READ
-
- IF LASTKEY() = ESC
- fnam = ""
- done = .T.
- ELSE
- fnam = ALLTRIM(fnam)
- IF valid_nam(fnam,status)
- done = .T.
- ELSE
- @ 2,2 say "Invalid/Not Found"
- @ 3,2 say "Press ESC to abort"
- i = 0
- DO WHILE i = 0
- i = inkey()
- ENDDO
- IF i = ESC
- fnam = ""
- done = .T.
- ENDIF
- @ 2,2 say " "
- @ 3,2 say " "
- ENDIF
- ENDIF
- ENDDO
- DEACTIVATE WINDOW w_fname
- RETURN fnam
-
-
-
- *
- * VALID_NAM -- Determine whether a file exists or whether a string is a
- * valid file name.
- * Parameters:
- * nam -- file name;
- * exist -- flag, determine if the file exists;
- *
- * Return Value:
- * .T. --
- * .F. --
- *
- FUNCTION valid_nam
- PARAMETERS nam,exist
- PRIVATE e,ret,r
-
- ret = .F.
- e = FILE(nam)
- IF exist && must exist
- IF e && does exist
- ret = .t.
- ENDIF
- ELSE && just valid name
- IF e && file exists and will be overwritten
- ret = .t. && may want to ask here
- ELSE && no existing file, can we make one?
- r = FCREATE(nam, 0)
- IF r >= 0 && yes, valid name
- ret = .T.
- =FCLOSE(r)
- ERASE &nam
- ENDIF
- ENDIF
- ENDIF
- RETURN ret
-
-
-
- FUNCTION get_protocol
- PARAMETERS col
- PRIVATE protocol
-
- protocol = 0
- DEFINE POPUP pop_protocol FROM 01, col;
- IN SCREEN;
- SHADOW
- DEFINE BAR 1 OF pop_protocol PROMPT " \<ASCII "
- DEFINE BAR 2 OF pop_protocol PROMPT " \<KERMIT "
- DEFINE BAR 3 OF pop_protocol PROMPT " \<XMODEM "
- DEFINE BAR 4 OF pop_protocol PROMPT " XMODEM-\<CRC "
- DEFINE BAR 5 OF pop_protocol PROMPT " XMODEM-\<1k "
- DEFINE BAR 6 OF pop_protocol PROMPT " \<YMODEM "
- DEFINE BAR 7 OF pop_protocol PROMPT " YMODEM-\<g "
- DEFINE BAR 8 OF pop_protocol PROMPT " \<ZMODEM "
- ON SELECTION POPUP pop_protocol protocol=_protocol_menu(BAR())
- ACTIVATE POPUP pop_protocol
- RELEASE POPUP pop_protocol
- RETURN (protocol)
-
-
-
- FUNCTION _protocol_menu
- PARAMETERS nChoice
-
- DO CASE
- CASE nChoice = 1
- protocol = ASCII
- CASE nChoice = 2
- protocol = KERMIT
- CASE nChoice = 3
- protocol = XMODEM
- CASE nChoice = 4
- protocol = XMODEM_CRC
- CASE nChoice = 5
- protocol = XMODEM_1K
- CASE nChoice = 6
- protocol = YMODEM
- CASE nChoice = 7
- protocol = YMODEM_G
- CASE nChoice = 8
- protocol = ZMODEM
- OTHERWISE
- protocol = -1
- ENDCASE
- =status_msg(0, "Protocol: " + ALLTRIM(PROMPT()))
- DEACTIVATE POPUP pop_protocol
- RETURN (protocol)
-
-
-
- FUNCTION xfer_progress
- PARAMETERS status, parm
- PRIVATE parm1, str, file_size, ro, str1
- PRIVATE file_name
-
- ro = xfer_row
- str = " "
- str1 = " "
- DO CASE
- CASE status = CONNECTION_LOST
- str = "Connection lost at " + ALLTRIM(STR(parm)) + " bytes"
- CASE status = CT_CHECKSUM
- str = "Using checksum error correction"
- CASE status = CT_CRC
- str = "Using CRC error correction"
- CASE status = CT_CRC_ERROR
- str = "CRC/checksum error"
- CASE status = CT_DISK_ERROR
- str = "I/O Error Writing to Disk"
- CASE status = CT_DISK_FULL
- str = "Disk full"
- case status = CT_DOWN_RESUME_TRY
- str = "Attempting download resume at " + ALLTRIM(STR(parm)) + " bytes"
- CASE status = CT_EOT
- str = "Final ACK received!"
- CASE status = CT_FILE_DATE
- @03, 13 SAY SPACE(30)
- @03, 13 SAY parm
- str = "File Date"
- CASE status = CT_FILE_NAME
- @01, 13 SAY SPACE(30)
- @01, 13 SAY parm
- str = "File Name"
- CASE status = CT_FILE_PROTECTED
- str = "Receive file name exists - renaming received file"
- CASE status = CT_FILE_SIZE
- IF parm != -1
- @04, 13 SAY ALLTRIM(STR(parm))
- ELSE
- @04, 13 SAY "Not reported"
- ENDIF
- str = "File Size"
- CASE status = CT_FILE_SOURCE
- IF parm == 0
- str = "Sending from DISK"
- ELSE
- str = "Sending from RAM"
- ENDIF
- CASE status = CT_FILE_XFER_ENDED
- str = "End of transfer of this file"
- CASE status = CT_JUNK_RECEIVED
- str = "Junk Received"
- CASE status = CT_MAX_ERRORS_REACHED
- str = "Max. Errors Reached"
- CASE status = CT_MSG
- str = " "
- CASE status = CT_REMOTE_CANCELLED
- str = "Remote Cancelled"
- CASE status = CT_RENAMED_FILE
- str = "Renamed incoming file to " + ALLTRIM(parm)
- CASE status = CT_RX_ACK
- str1 = "ACK"
- CASE status = CT_RX_CAN
- str1 = "CAN"
- CASE status = CT_RX_ENQ
- str1 = "ENQ"
- CASE status = CT_RX_NAK
- str1 = "NAK"
- CASE status = CT_RX_SEQ
- str1 = "SEQ " + ALLTRIM(STR(parm))
- CASE status = CT_SKIP_FILE
- str = "Skipping file"
- CASE status = CT_SOH
- str = "Received Start of Header"
- CASE status = CT_STX
- str = "Received Start of Header"
- case status = CT_SYNC_END
- str = "File recovery at " + ALLTRIM(STR(parm)) + " bytes"
- case status = CT_SYNC_START
- str = "At " + ALLTRIM(STR(parm)) + " bytes. Calibrating..."
- CASE status = CT_TIMEOUT
- str = "Remote Did Not Start. Attempt " + ALLTRIM(STR(parm))
- CASE status = CT_TX_ACK
- str = "Sent ACK to remote"
- CASE status = CT_TX_BUFFER_NOT_EMPTY
- str = "Waiting for transmit buffer to empty"
- CASE status = CT_TX_CAN
- str = "Sent CAN to remote"
- CASE status = CT_TX_ENQ
- str1 = "ENQ"
- CASE status = CT_TX_NAK
- str = "Sent NAK to remote"
- CASE status = CT_TX_SEQ
- str1 = "SEQ " + ALLTRIM(STR(parm))
- str1 = "ENQ"
- CASE status = CT_UNSPECIFIED
- str = "Unspecified Error"
- CASE status = CT_XMODEM
- str = "Using XMODEM"
- CASE status = CT_XMODEM1K
- str = "Using XMODEM-1K"
- CASE status = CT_XMODEMCRC
- str = "Using XMODEM-CRC"
- CASE status = CT_YMODEM
- str = "Using YMODEM protocol"
- CASE status = CT_YMODEMG
- str = "Using YMODEM-g protocol"
- CASE status = CT_XFER_POSITION
- str = ALLTRIM(STR(parm))
- IF ro != 0
- ro = 2
- ENDIF
- * Crude method of calculating file transfer efficiency
- * Do not use this as an alternative to your grandmother's
- * atomic clock.
- PUBLIC start_time, xfer_speed, start_pos
- PRIVATE efficiency
-
- IF parm == 0
- @ro+4, 01 SAY "Efficiency: "
- @ro+4, 19 SAY "(not calculated by atomic clock)"
- start_time = SECONDS()
- xfer_speed = get_carrier_speed(portid)/10
- start_pos = parm
- ELSE
- IF xfer_row != 0 .AND. parm > 1023
- efficiency = (parm - start_pos)/(xfer_speed * (SECONDS() - start_time))
- IF efficiency > 1
- efficiency = 1
- ENDIF
- @ro+4, 13 SAY ALLTRIM(STR(efficiency*100)) + "% "
- ENDIF
- ENDIF
-
- CASE status = USER_CANCELLED
- str = "Keyboard cancel received"
-
- * Kermit-specific messages
- CASE status = K_ABORT
- str = "Abort Packet"
- CASE status = K_BREAK
- str = "Break Packet"
- CASE status = K_DATA
- str = "Data Packet"
- CASE status = K_EOF
- str = "End-of-File Packet"
- CASE status = K_ERROR
- str = "Error Packet"
- CASE status = K_FHEAD
- str = "File Header Packet"
- CASE status = K_SINIT
- str = "Send-Init Packet"
-
- * ZMODEM-specific messages
- CASE status = ZABORT
- str1 = "ZABORT"
- CASE status = ZACK
- str1 = "ZACK"
- CASE status = ZCAN
- str1 = "ZCAN"
- CASE status = ZCRC
- str1 = "ZCRC"
- CASE status = ZCHALLENGE
- str = "Remote sent ZCHALLENGE " + ALLTRIM(STR(parm))
- str1 = "ZCHALLENGE"
- CASE status = ZCOMMAND
- str = "Remote sent command " + ALLTRIM(parm)
- str1 = "ZCOMMAND"
- CASE status = ZCOMPL
- str1 = "ZCOMPL"
- CASE status = ZDATA
- str1 = "ZDATA"
- CASE status = ZEOF
- str1 = "ZEOF"
- CASE status = ZFERR
- str1 = "ZFERR"
- CASE status = ZFILE
- str1 = "ZFILE"
- CASE status = ZFIN
- str1 = "ZFIN"
- CASE status = ZFREECNT
- str = "Free space is " + ALLTRIM(STR(parm))
- str1 = "ZFREECNT"
- CASE status = ZNAK
- str1 = "ZNAK"
- CASE status = ZRINIT
- str1 = "ZRINIT"
- CASE status = ZRPOS
- str1 = "ZRPOS"
- CASE status = ZRQINIT
- str1 = "ZRQINIT"
- CASE status = ZSINIT
- str = "Receiver's ATTN sequence is '" + ALLTRIM(parm) + "'"
- str1 = "ZSINIT"
- CASE status = ZSKIP
- str1 = "ZSKIP"
- CASE status = ZSTDERR
- str1 = "ZSTDERR"
- OTHERWISE
- str = " "
- str1 = " "
- ENDCASE
- IF xfer_row != 0
- IF str != " "
- @ro, 13 SAY SPACE(36)
- @ro, 13 SAY str
- ENDIF
- IF str1 != " "
- @ro+2, 42 SAY SPACE(9)
- @ro+2, 42 SAY str1
- ENDIF
- ELSE
- =status_msg(0, str)
- ENDIF
- RETURN (NIL)
-
-
-
- FUNCTION display_xfer
- PARAMETERS row, col, fname, fsize
- PUBLIC xfer_row
-
- DEFINE WINDOW w_xfer FROM row,col TO row+10,col+52;
- TITLE 'File Transfer Progress';
- SHADOW
- ACTIVATE WINDOW w_xfer
- @01, 01 SAY "File Name : "
- @02, 01 SAY "Bytes : "
- @03, 01 SAY "Date : "
- @04, 01 SAY "File Size : "
- @05, 01 SAY "Last Msg. : "
- xfer_row = 5
- IF fname != "$"
- @01, 13 SAY fname
- ENDIF
- IF fsize != NULL
- @04, 13 SAY fsize
- ENDIF
- RETURN (0)
-