siomon - XENIX V real-time serial I/O monitor

Warren Tucker wht at tridom.uucp
Thu Nov 23 06:54:22 AEST 1989


#!/bin/sh
# This is a shell archive built by shar 3.03
# Created Wed Nov 22 14:42:58 EST 1989 by gatech!kd4nc!n4hgf!wht
# Source directory /u4/src/uusnap
#
# existing files will NOT be overwriten
#
# This shar contains:
#    README
#    siomon.c
#    termio.h.diff
#
touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
if [ -s /tmp/s3_touch$$ ]
then
	TOUCH=can
else
	TOUCH=cannot
fi
rm -f /tmp/s3_touch$$
if test -f README; then echo "File README exists"; else
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
XThis is siomon, a serial I/O monitor for XENIX V.  I know it works
Xon the 386 with 2.3.2, but it should work with any system that
X1.  has select(S) [NOTE: 2.3.1 has a broken but fixable select].
X2.  defines the serial I/O structures in the kernel with the public
X    label '_sio_tty'  (the console I/O label is '_cn_tty', BTW).
X
XSince XENIX curses.h and sys/tty.h both include termio.h (and  the
X$#@*/! termio.h fil;es doesn't handle multiple inclusions),
Xyou need to patch your sys/termio.h file by:
X    su root
X    patch /usr/sys/include/termio.h < termio.h.diff
XThis enables termio.h to be included multiple times without error
Xif and only if #define TERMIO_HACK is turned on.  The header
Xfile will behave exactly the same as it always did if
Xthis define is excluded, so you won't get lulled into thinking this
Xdesirable behavior is the same in all the termio.h's in the world
X(would that we could).
X
XTo make siomon after the patch has been done:
X1.  cc -Ox -DM_TERMCAP siomon.c -s -o siomon -lcurses -ltermcap
X    (you may have to omit -DM_TERMCAP if it is your default)
X2.  chown root siomon  -or-   chgrp sysinfo siomon
X3.  chmod 4111 siomon         chgrp 2111 siomon
X
XYou may be able to hack it for other System V type systems by
X1.  using nap() and rdchk() instead of select() (pre XENIX 2.3,
X    no hope on vanilla System V)
X2.  change xlist() against '_cn_tty' to ??list() against '_??'.
X
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
if [ $TOUCH = can ]
then
    touch -m 1122143189 README
fi
fi
if test -f siomon.c; then echo "File siomon.c exists"; else
echo "x - extracting siomon.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > siomon.c &&
X/*+-------------------------------------------------------------------------
X	siomon.c -- watch XENIX serial I/O
X	...!gatech!kd4nc!n4hgf!wht (free to do what you want with it)
X
Xcc -Ox -DM_TERMCAP siomon.c -o siomon -lcurses -ltermcap
X    (you may have to omit -DM_TERMCAP if it is your default)
Xchown root siomon  -or-   chgrp sysinfo siomon
Xchmod 4111 siomon         chgrp 2111 siomon
X
X    Sample output:
X siomon 1.1 for XENIX V                           delay:  0        14:41:31
X
X tty  raw  can   out   speed  state iflag  oflag  cflag  lflag  pgrp
X ---  ---  ---  -----  -----  ----- ------ ------ ------ ------ -----
X 1a     0    0      0   9600  OC     10045      0   6655      0     0
X 1b
X 1c
X 1d
X 1e
X 1f
X 1g
X 1h
X 2a
X 2b
X 2c
X 2d     0    0      0   9600  W          0      1   2275      0     0
X 2e
X 2f
X 2g
X 2h
X
X
XFlags: W waiting for open to complete  O open  C carrier on
X       S stopped by XOFF  D delay timeout in progress
XCommands:  + inc delay  - dec delay  ^L refresh  q quit
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:11-22-1989-12:33-wht-rehost my Pyramid itpmon.c */
X
X#include <stdio.h>
X#include <signal.h>
X#include <sys/types.h>
X#include <sys/a.out.h>
X
X#include <curses.h>
X#define TERMIO_HACK
X#include <sys/tty.h>
X#include <sys/time.h>
X#include <sys/select.h>
X
X#define HY 2	/* header line */
X#define TX 1
X#define RX 6
X#define CX 11
X#define OX 16
X#define SX 23
X#define FX 30
X
X/*global*/  void leave(void );
X/*global*/  char *B_to_baud_rate(int );
X/*global*/  void kmem_read(long ,char *,int ,char *);
X/*global*/  void utoda(char *,int ,unsigned int );
X/*global*/  void utooa(char *,int ,unsigned int );
X/*global*/  void disp_tty(int ,struct tty *);
X/*global*/  void disp_delay(void );
X/*global*/  void disp_tod(void);
X/*global*/  void draw_template(void );
X/*global*/  int main(int ,char * *,char * *);
X
Xextern char _sobuf[];
Xextern int errno;
Xextern char *sys_errlist[];
X
Xchar *xenix_file = "/xenix";
Xchar *kmem_file = "/dev/kmem";
X
Xint kmemfd;
X
Xstruct xlist xlst[] = {
X#define N_SIO_TTY	0
X	{0,0,0, "_sio_tty" },
X	{0,0,0, (char *)0 }
X};
X
X#define	SIO_NTTY	16
Xlong sio_tty;
Xlong sio_cnt;
Xlong base_sio = 0;
X
Xstruct tty sio[SIO_NTTY];
X
Xtypedef struct b_to_br
X{
X	char *baud_rate;
X	int B_code;
X} B_TO_BR;
X
XB_TO_BR speeds[] = 
X{
X	"  110",	B110,
X	"  300",	B300,
X	" 1200",	B1200,
X	" 2400",	B2400,
X	" 4800",	B4800,
X	" 9600",	B9600,
X	"19200",	EXTA,
X	"38400",	EXTB,
X	(char *)0,0
X};
X
Xint delay = 1;
X
X/*+-------------------------------------------------------------------------
X	leave()
X--------------------------------------------------------------------------*/
Xvoid
Xleave()
X{
X	refresh();
X	move(LINES - 1,0);
X	refresh();
X	endwin();
X	exit(0);
X}	/* end of leave */
X
X/*+-------------------------------------------------------------------------
X	B_to_baud_rate(code)
X--------------------------------------------------------------------------*/
Xchar *
XB_to_baud_rate(code)
X{
Xregister int n;
X
X	for(n=0; speeds[n].baud_rate; n++)
X		if(speeds[n].B_code == code)
X			return(speeds[n].baud_rate);
X	return("-----");
X}	/* end of B_to_baud_rate */
X
X/*+-------------------------------------------------------------------------
X	kmem_read(pos,buf,len,objname)
X--------------------------------------------------------------------------*/
Xvoid
Xkmem_read(pos,buf,len,objname)
Xlong pos;
Xchar *buf;
Xint len;
Xchar *objname;
X{
X	if(lseek(kmemfd,pos,0) == -1)
X	{
X		move(1,0);
X		standout();
X		printw(" %s: kmem lseek failure: %s ",objname,sys_errlist[errno]);
X		standend();
X		leave();
X	}
X	if(read(kmemfd,buf,len) == -1)
X	{
X		move(1,0);
X		standout();
X		printw(" %s: kmem read failure:  %s ",objname,sys_errlist[errno]);
X		standend();
X		leave();
X	}
X}	/* end of kmem_read */
X
X/*+-------------------------------------------------------------------------
X	utoda(buf,width,n) unsigned to decimal ascii
X--------------------------------------------------------------------------*/
Xvoid
Xutoda(buf,width,n)
Xchar *buf;
Xint width;
Xunsigned n;
X{
X	register unsigned div;
X	register char *ep = &buf[width];
X
X	*ep = '\0';
X	if(n == 0)
X		*--ep = '0';
X	while(ep-- > buf)
X	{
X		if(n <= 0)
X			*ep = ' ';
X		else
X		{
X			div = n / 10;
X			*ep = n - 10*div + '0';
X			n = div;
X		}
X	}
X}	/* end of utoda */
X
X/*+-------------------------------------------------------------------------
X	utooa(buf,width,n) unsigned to octal ascii
X--------------------------------------------------------------------------*/
Xvoid
Xutooa(buf,width,n)
Xchar *buf;
Xint width;
Xunsigned n;
X{
Xregister unsigned div;
Xregister char *ep = &buf[width];
X
X	*ep = '\0';
X	if(n == 0)
X		*--ep = '0';
X	while(ep-- > buf)
X	{
X		if(n <= 0)
X			*ep = ' ';
X		else
X		{
X			div = n >> 3;
X			*ep = n - (div << 3) + '0';
X			n = div;
X		}
X	}
X}	/* end of utooa */
X
X/*+-------------------------------------------------------------------------
X	disp_tty(ttnum,tty)
X--------------------------------------------------------------------------*/
Xvoid
Xdisp_tty(ttnum,tty)
Xint ttnum;
Xregister struct tty *tty;
X{
Xregister int xo = (ttnum > 15) ? 40 : 0;	/* x offset */
Xregister int y  = HY + 2 + (ttnum & 15);
Xregister unsigned int itmp;
Xregister opened = tty->t_state & (ISOPEN | WOPEN);
Xchar s8[8];
X
X	move(y,TX + xo);
X	addch((ttnum < 8) ? '1' : '2');
X	addch((ttnum % 8) + 'a');
X
X	if(!opened)
X	{
X		clrtoeol();
X		return;
X	}
X
X	if((itmp = (unsigned)tty->t_rawq.c_cc) > 999)
X		itmp = 999;
X	utoda(s8,3,itmp);
X	move(y,RX + xo);
X	if(itmp > 10)
X		standout();
X	addstr(s8);
X	if(itmp > 10)
X		standend();
X
X	if((itmp = (unsigned)tty->t_canq.c_cc) > 999)
X		itmp = 999;
X	utoda(s8,3,itmp);
X	move(y,CX + xo);
X	addstr(s8);
X
X	if((itmp = (unsigned)tty->t_outq.c_cc) > 99999)
X		itmp = 99999;
X	utoda(s8,5,itmp);
X	move(y,OX + xo);
X	addstr(s8);
X
X	move(y,SX + xo);
X	addstr(B_to_baud_rate(tty->t_cflag & CBAUD));
X
X	strcpy(s8,"     ");
X	if(tty->t_state & WOPEN)
X		s8[0] = 'W',opened = 1;
X	else if(tty->t_state & ISOPEN)
X		s8[0] = 'O',opened = 1;
X	if(tty->t_state & CARR_ON)
X		s8[1] = 'C';
X	if(tty->t_state & BUSY)
X		s8[2] = 'B';
X	if(tty->t_state & TTSTOP)
X		s8[3] = 'S';
X	if(tty->t_state & TIMEOUT)
X		s8[3] = 'D';
X	move(y,FX + xo);
X	addstr(s8);
X
X	utooa(s8,7,tty->t_iflag);
X	addstr(s8);
X
X	utooa(s8,7,tty->t_oflag);
X	addstr(s8);
X
X	utooa(s8,7,tty->t_cflag);
X	addstr(s8);
X
X	utooa(s8,7,tty->t_lflag);
X	addstr(s8);
X
X	utoda(s8,6,tty->t_pgrp);
X	addstr(s8);
X
X}	/* end of disp_tty */
X
X/*+-------------------------------------------------------------------------
X	disp_delay()
X--------------------------------------------------------------------------*/
Xvoid
Xdisp_delay()
X{
Xchar dmsg[12];
X
X	sprintf(dmsg,"delay: %2d",delay);
X	move(0,50);
X	addstr(dmsg);
X}	/* end of disp_delay */
X
X/*+-------------------------------------------------------------------------
X	disp_tod()
X--------------------------------------------------------------------------*/
Xvoid
Xdisp_tod()
X{
Xregister struct tm *lt;		/* local time */
Xstruct tm *localtime();
Xlong now;
Xchar buf[10];
X
X	time(&now);
X	lt = localtime(&now);
X	sprintf(buf,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
X	move(0,COLS - 13);
X	addstr(buf);
X}	/* end of disp_tod */
X
X/*+-------------------------------------------------------------------------
X	draw_template()
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_template()
X{
Xstatic char *header  = 
X	" tty  raw  can   out   speed  state iflag  oflag  cflag  lflag  pgrp";
Xstatic char *hyphens =
X	" ---  ---  ---  -----  -----  ----- ------ ------ ------ ------ -----";
X
X	clear();
X	move(0,0);
X	standout();
X	addstr(" siomon 1.1 for XENIX V");
X	standend();
X	move(HY,0);
X	addstr(header);
X	move(HY + 1,0);
X	addstr(hyphens);
X	move(LINES - 4,0);
X	addstr(
X"Flags: W waiting for open to complete  O open  C carrier on");
X	move(LINES - 3,0);
X	addstr(
X"       S stopped by XOFF  D delay timeout in progress ");
X	move(LINES - 2,0);
X	addstr(
X"Commands:  + inc delay  - dec delay  ^L refresh  q quit");
X	move(LINES - 1,0);
X	disp_delay();
X	refresh();
X}	/* end of draw_template */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
Xmain(argc,argv,envp)
Xint argc;
Xchar **argv;
Xchar **envp;
X{
Xregister struct xlist *nn = xlst;
Xregister int ttnum;
Xstruct timeval timeout;
Xint readfds;
X
X	signal(SIGINT,leave);
X	signal(SIGTERM,leave);
X
X	setbuf(stdout,_sobuf);
X	initscr();
X	crmode();
X	noecho();
X	draw_template();
X
X	move(4,0);
X	standout();
X	addstr("  initializing  ");
X	standend();
X	refresh();
X
X	if((kmemfd = open(kmem_file,0)) < 0)
X	{
X		move(8,0);
X		standout();
X		printw(" %s: %s ",kmem_file,sys_errlist[errno]);
X		standend();
X		leave();
X	}
X
X	xlist(xenix_file,xlst);
X	if(xlst[N_SIO_TTY].xl_type == 0)
X	{
X		move(8,0);
X		standout();
X		printw(" xlist failure: %s ",xenix_file);
X		standend();
X		leave();
X	}
X	sio_tty = xlst[N_SIO_TTY].xl_value;
X
X	move(4,0);
X	addstr("                ");
X
X	while(1)
X	{
X		kmem_read(sio_tty,(char *)sio,sizeof(sio),"tty struct");
X		for(ttnum = 0; ttnum < SIO_NTTY; ttnum++)
X			disp_tty(ttnum,&sio[ttnum]);
X		disp_tod();
X		move(LINES - 1,0);
X		refresh();
X		readfds = 1;			/* for standard input */
X		timeout.tv_sec  = delay;
X		timeout.tv_usec = (delay) ? 0 : 100*1000L;
X		if(select(32,&readfds,0,0,&timeout) > 0)
X		{
X		char ch;
X			read(0,&ch,1);
X			switch(ch & 0x7F)
X			{
X			case 'L' & 0x1F:		/* redraw screen */
X			case 'R' & 0x1F:		/* redraw screen */
X				draw_template();
X				continue;
X
X			case '+':
X				delay++;
X				disp_delay();
X				break;
X
X			case '-':
X				if(!delay)
X					break;
X				delay--;
X				disp_delay();
X				break;
X
X			case 'q':		/* quit */
X				leave();
X				break;
X
X			case '{':
X				if(base_sio > 0)
X					base_sio--;
X				continue;
X
X			case '}':
X				if(base_sio+2 < sio_cnt)
X					base_sio++;
X				continue;
X			}
X		}
X	}
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of siomon.c */
SHAR_EOF
chmod 0644 siomon.c || echo "restore of siomon.c fails"
if [ $TOUCH = can ]
then
    touch -m 1122144289 siomon.c
fi
fi
if test -f termio.h.diff; then echo "File termio.h.diff exists"; else
echo "x - extracting termio.h.diff (Text)"
sed 's/^X//' << 'SHAR_EOF' > termio.h.diff &&
X*** termio-orig.h	Tue Aug  8 19:13:54 1989
X--- termio.h	Wed Nov 22 12:21:17 1989
X***************
X*** 14,20
X   * AND CONFIGURATIONS. IT SHOULD NOT REQUIRE ANY
X   * MODIFICATIONS WHEN ADAPTING XENIX TO NEW HARDWARE.
X   */
X! 
X  #define	IOCTYPE	0xff00
X  
X  #define	TIOC	('T'<<8)
X
X--- 14,20 -----
X   * AND CONFIGURATIONS. IT SHOULD NOT REQUIRE ANY
X   * MODIFICATIONS WHEN ADAPTING XENIX TO NEW HARDWARE.
X   */
X! #if defined(TERMIO_HACK) && !defined(IOCTYPE)
X  #define	IOCTYPE	0xff00
X  
X  #define	TIOC	('T'<<8)
X***************
X*** 247,249
X  #ifdef M_I386
X  #pragma	pack()
X  #endif
X
X--- 247,250 -----
X  #ifdef M_I386
X  #pragma	pack()
X  #endif
X+ #endif TERMIO_HACK
SHAR_EOF
chmod 0644 termio.h.diff || echo "restore of termio.h.diff fails"
if [ $TOUCH = can ]
then
    touch -m 1122141089 termio.h.diff
fi
fi
exit 0
-- 
------------------------------------------------------------------
Warren Tucker, Tridom Corporation      ...!gatech!emory!tridom!wht
Hackre Extraordinaire de asynch PADs, pods, proteins and protocols
home address: ...!gatech!kd4nc!n4hgf!wht   <--- now finally stable



More information about the Alt.sources mailing list