/* Copyright (C) Magna Carta Software, Inc. 1988, 1989. All Rights Reserved. CCT12.C CAPABILITY: 1) Uses interrupt driven reception; 2) Data transfer rate can be set at run time; 3) Data format can be adjusted at run time; 4) Formatted serial input is used; 5) Formatted serial output is used; 6) Direct control over the modem; NEW: KERMIT file transfer; All other options must be changed in the source code and the source recompiled to change them. COMPATIBILITY: TURBOC v1.5+, POWERC v1.2+, MSC 5.0+/QUICK C, WATCOM C; */ #include #include #include #include #include #include #include #if defined(__WATCOMC__) #include #endif /* MANIFEST CONSTANTS AND MACROS */ #define DO_MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void do_data_menu(COMM_PORT * p); short do_rxfile_menu(COMM_PORT *p); short do_txfile_menu(COMM_PORT *p); short do_modem_menu(COMM_PORT *p); long do_speed_menu(COMM_PORT * p); void term(COMM_PORT *p); short menu(COMM_PORT *p); short transfer_progress(COMM_PORT *p, short status, unsigned long parm); /* GLOBAL VARIABLES */ COMM_PORT port1; char phone_number[] = "226-8088";/* MAGNA CARTA BBS (change if nec.) */ BYTE rxbuf[2048]; /* RECEIVE BUFFER */ int vers = 12; MODEM m1; XFER x; /* MUST be initialized to 0 */ KERMIT_PARMS k; /* MUST be initialized to 0 */ #include "menus.c" #include "xfermsg.c" /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { init_port(&port1, COM1, 9600L, DATABITS8, PARITY_NONE, STOPBITS1); install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); install_isr(&port1, 4, NULL); modem_assign(&port1, &m1); printf("\nCCT-COMM Version %d: Press Alt-M for a list of commands\n", vers); term(&port1); printf("\nEnd of CCT-COMM%d\n", vers); set_dtr(&port1, LOW); set_rts(&port1, LOW); return (0); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p) { short c; /* must be int to detect a -1 return */ set_rx_xlat(p, LOCAL_ECHO, ON); for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c = c_getc(p); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != 0) { if (c == DO_MENU) { if (menu(p) == 1) break; } else c_putc(p, c); } } } #define DATA_FORMAT 'D' /* key to set data format */ #define DATA_SPEED 'S' /* key to set speed */ #define MODEM_MENU 'M' /* key to send modem commands */ #define TXFILE_MENU 'F' /* key to send files */ #define RXFILE_MENU 'R' /* key to receive files */ #define EXIT 'Q' /* key to exit from main */ short menu(COMM_PORT *p) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tD. Data Format", "\tF. File Send Commands.", "\tM. Modem Commands.", "\tR. File Receive Commands.", "\tS. Data Transfer Rate.", "\tQ. EXIT from COMM.", NULL /* null string terminates list */ }; char **p_menu; c = !EXIT; while (!DONE) { puts("\n\n"); for (p_menu = menus; *p_menu != NULL; p_menu++) printf("%s\n", *p_menu); printf("\n\t\t Enter selection (CR to quit menu) : "); c = getchar(); c = toupper(c); switch (c) { case EXIT: retval = 1; DONE = TRUE; break; case DATA_FORMAT: do_data_menu(p); break; case DATA_SPEED: do_speed_menu(p); break; case MODEM_MENU: DONE = do_modem_menu(p); break; case TXFILE_MENU: DONE = do_txfile_menu(p); break; case RXFILE_MENU: DONE = do_rxfile_menu(p); break; default: DONE = TRUE; break; } } puts("\nExiting menu"); set_tx_xlat(p, LOCAL_ECHO, FALSE); return (retval); /* will be zero except if EXIT */ } /* DO_MODEM_MENU -- Send commands to the modem. */ short do_modem_menu(COMM_PORT *p) { short key; short DONE=FALSE, ret = 0; do { puts("\nSEND COMMANDS TO THE MODEM"); puts("\nD. Dial"); puts("H. Hangup"); puts("I. Initialize"); puts("O. Go Offline"); puts("R. Reset\n"); puts("\nAny other key exits"); key = bios_key(0) & 0XFF; switch (toupper(key)) { case 'D': modem_dial(p, phone_number); ret = 1; DONE = TRUE; break; case 'H': modem_hangup(p); break; case 'I': modem_init(p, modem_type(p)); set_dtr(p, HIGH); break; case 'O': modem_go_cmd(p, (short) atoi(&((MODEM *)p->modem)->escape[3])); break; case 'R': modem_reset(p); break; default: DONE = TRUE; break; } } while (!DONE); return (ret); } /* DO_RXFILE_MENU -- Receive a file from a remote system using KERMIT */ short do_rxfile_menu(COMM_PORT *p) { short ret = 0; set_rx_xlat(p, LOCAL_ECHO, OFF); set_tx_xlat(p, LOCAL_ECHO, OFF); puts("\nRECEIVING FILE FROM REMOTE SYSTEM USING THE KERMIT PROTOCOL"); ret = freceive(p, &x, KERMIT, 4*1024, xfer_progress); return (ret); } /* DO_TXFILE_MENU -- Send a file to a remote system using KERMIT. */ short do_txfile_menu(COMM_PORT *p) { short ret = 0; char filename[80], sxlat[XLAT_SIZE]; struct ffblk fb; filename[0] = '\0'; puts("\nSEND A FILE TO A REMOTE SYSTEM USING THE KERMIT PROTOCOL"); puts("\nEnter file name (ENTER to exit):"); scanf("%s", filename); if (filename[0] == CR) return (0); ret = findfirst(filename, &fb, FA_ARCH); if (ret == 0) { save_xlat(p, sxlat); set_tx_xlat(p, LOCAL_ECHO, OFF); set_rx_xlat(p, LOCAL_ECHO, OFF); fqueue(&x, fb.ff_name); /* fqueue(&x, "CCT00.C"); */ /* could queue a second file here */ x.len = 1024*5; ret = fsend(p, &x, KERMIT, 24*1024, xfer_progress); /* send the file */ restore_xlat(p, sxlat); } return (ret); }