/*
Copyright (C) Magna Carta Software, Inc. 1990,1991. All Rights Reserved
CCT05.C -- CCT04.C plus...
1) Uses transmitted data transformation. All transmitted characters are
converted to upper case before thay are sent out of the port. Furthermore,
only ASCII characters are transmitted.
*/
#include <comm.h>
#include <conio.h>
#include <dos.h>
/* MANIFEST CONSTANTS AND MACROS */
#define MENU ALT_M /* key for command summary */
/* FUNCTION PROTOTYPES */
short menu(COMM_PORT *p);
void term(COMM_PORT *p);
/* GLOBAL VARIABLES */
COMM_PORT port1;
BYTE rxbuf[2048]; /* RECEIVE BUFFER */
int vers = 5;
#include "menus.c"
/* ------------------------ PROGRAM BEGINS HERE --------------------------- */
int main(void)
{
u8250_init(&port1, COM1, 2400L, DATABITS8, PARITY_NONE, STOPBITS1);
install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf));
install_isr(&port1, 4, NULL);
printf("CCT-COMM Version %d: Press Alt-M for a list of commands\n", vers);
term(&port1);
printf("\nEnd of CCT-COMM%d\n", vers);
return (0);
}
/*
TERM -- The terminal emulation routine. Simply polls the COM port and the
keyboard alternately for characters.
*/
void term(COMM_PORT *p_port)
{
short c; /* must be signed to detect a -1 return */
/* THESE LINES CONTROL THE RECEIVED DATA TRANSLATION */
set_rx_xlat(p_port, EOL, FALSE);
set_rx_xlat(p_port, LOCAL_ECHO, ON);
/* THESE LINES CONTROL THE TRANSMITTED DATA TRANSLATION */
set_tx_xlat(p_port, ASCII_ONLY, TRUE);
set_tx_xlat(p_port, CASE, UPPER);
for (;;) {
/* CHECK SERIAL PORT FOR BYTE */
c_getc(p_port);
/* CHECK KEYBOARD FOR A KEY PRESS */
if ((c = inkey()) != 0) {
if (c == MENU) {
if (menu(p_port) == 1) break;
}
else c_putc(p_port, c);
}
}
}
#define DATA_FORMAT 'D' /* key to set speed */
#define DATA_SPEED 'S' /* key to set speed */
#define EXIT 'Q' /* key to exit from main */
short menu(COMM_PORT *p_port)
{
short c, retval = 0, DONE = FALSE;
static char *menus[] = {
"\tD. Data Format",
"\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_port);
break;
case DATA_SPEED:
do_speed_menu(p_port);
break;
case LF:
DONE = TRUE;
break;
default:
break;
}
}
puts("\nExiting menu");
return (retval); /* will be zero except if EXIT */
}