From e7316389e852d7ea32b836de1646fc6b87c30515 Mon Sep 17 00:00:00 2001 From: ppokorny Date: Wed, 18 Jul 2001 22:30:12 +0000 Subject: [PATCH] Fixed compile errors on FreeBSD related to cfmakeraw and friends on the serial port side. Also fixed problems with ioperm on the parallel port side. Added --waittime option to the server to specify how long the server should leave a screen up before changing to the next screen. --- configure.in | 2 +- server/drivers/CFontz.c | 24 ++++++++++++---- server/drivers/MtxOrb.c | 25 ++++++++++++---- server/drivers/bayrad.c | 25 ++++++++++++---- server/drivers/glkproto.c | 29 ++++++++++++------- server/drivers/hd44780-4bit.c | 3 +- server/drivers/hd44780-ext8bit.c | 3 +- server/drivers/hd44780-serialLpt.c | 8 ++++++ server/drivers/hd44780-winamp.c | 3 +- server/drivers/hd44780.c | 4 +-- server/drivers/lb216.c | 26 ++++++++++++----- server/drivers/port.h | 40 ++++++++++++++++++++++++-- server/drivers/wirz-sli.c | 26 +++++++++++++++-- server/main.c | 46 ++++++++++-------------------- server/screen.c | 7 +++-- server/screen.h | 3 ++ 16 files changed, 191 insertions(+), 83 deletions(-) diff --git a/configure.in b/configure.in index eaeaaa8..3866bf9 100644 --- a/configure.in +++ b/configure.in @@ -86,7 +86,7 @@ AC_TYPE_UID_T dnl Checks for library functions. AC_PROG_GCC_TRADITIONAL AC_TYPE_SIGNAL -AC_CHECK_FUNCS(select socket strdup strerror strtol uname) +AC_CHECK_FUNCS(select socket strdup strerror strtol uname cfmakeraw ioperm) dnl Check for various defines and features diff --git a/server/drivers/CFontz.c b/server/drivers/CFontz.c index 29fb5b1..30f04c4 100644 --- a/server/drivers/CFontz.c +++ b/server/drivers/CFontz.c @@ -139,14 +139,26 @@ CFontz_init (lcd_logical_driver * driver, char *args) } //else fprintf(stderr, "CFontz_init: opened device %s\n", device); tcgetattr (fd, &portset); - // This is necessary in Linux, but does not exist in irix. -#ifndef IRIX -#ifndef SOLARIS - cfmakeraw (&portset); -#endif + + // We use RAW mode +#ifdef HAVE_CFMAKERAW + // The easy way + cfmakeraw( &portset ); +#else + // The hard way + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; #endif + + // Set port speed cfsetospeed (&portset, speed); - cfsetispeed (&portset, speed); + cfsetispeed (&portset, B0); + + // Do it... tcsetattr (fd, TCSANOW, &portset); // Set display-specific stuff.. diff --git a/server/drivers/MtxOrb.c b/server/drivers/MtxOrb.c index b2bf189..d274155 100644 --- a/server/drivers/MtxOrb.c +++ b/server/drivers/MtxOrb.c @@ -84,6 +84,7 @@ MtxOrb_init (lcd_logical_driver * driver, char *args) int contrast = 140; char device[256] = "/dev/lcd"; int speed = B19200; + MtxOrb_type = MTXORB_LKD ; // Assume it's an LCD w/keypad MtxOrb = driver; @@ -170,14 +171,26 @@ MtxOrb_init (lcd_logical_driver * driver, char *args) } //else fprintf(stderr, "MtxOrb_init: opened device %s\n", device); tcgetattr (fd, &portset); - // This is necessary in Linux, but does not exist in irix. -#ifndef IRIX -#ifndef SOLARIS - cfmakeraw (&portset); -#endif + + // We use RAW mode +#ifdef HAVE_CFMAKERAW + // The easy way + cfmakeraw( &portset ); +#else + // The hard way + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; #endif + + // Set port speed cfsetospeed (&portset, speed); - cfsetispeed (&portset, speed); + cfsetispeed (&portset, B0); + + // Do it... tcsetattr (fd, TCSANOW, &portset); // Set display-specific stuff.. diff --git a/server/drivers/bayrad.c b/server/drivers/bayrad.c index e6969bf..5316202 100644 --- a/server/drivers/bayrad.c +++ b/server/drivers/bayrad.c @@ -408,15 +408,28 @@ int bayrad_init(struct lcd_logical_driver *driver, char *args) tcflush(fd, TCIOFLUSH); - // This is necessary in Linux, but does not exist in irix. - bzero(&portset, sizeof(portset)); - portset.c_iflag = IGNPAR; - portset.c_oflag = 0; - portset.c_cflag = B9600|CS8|CREAD|CLOCAL; - portset.c_lflag = 0; + // We use RAW mode +#ifdef HAVE_CFMAKERAW + // The easy way + cfmakeraw( &portset ); +#else + // The hard way + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; +#endif + portset.c_cc[VTIME] = 0; // Don't use the timer, no workee portset.c_cc[VMIN] = 1; // Need at least 1 char + // Set port speed + cfsetospeed(&portset, B9600); + cfsetispeed(&portset, B0); + + // Do it... tcsetattr(fd, TCSANOW, &portset); tcflush(fd, TCIOFLUSH); diff --git a/server/drivers/glkproto.c b/server/drivers/glkproto.c index 84b11d6..ffbb497 100644 --- a/server/drivers/glkproto.c +++ b/server/drivers/glkproto.c @@ -45,13 +45,13 @@ GLKDisplay * struct termios new ; GLKDisplay * retval ; - if( name == NULL || (speed & CBAUD) == 0 ) { + if( name == NULL || speed == 0 ) { /* Invalid arguments */ errno = EINVAL ; return( NULL ); }; - fd = open( name, O_RDWR | O_NOCTTY | O_SYNC ); + fd = open( name, O_RDWR | O_NOCTTY ); if( fd < 0 ) { return( NULL ); }; @@ -76,20 +76,29 @@ GLKDisplay * retval->flow = GLKFLOW_OK ; /* Make new settings */ - /* We use RAW mode, and select two stop bits - * to slow things down 10%. Therefore, we IGNORE - * framing errors incase the module transmits back - * to back with only one stop bit. - */ - new.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | IGNPAR | ISTRIP + + /* We use RAW mode */ +#ifdef HAVE_CFMAKERAW + /* The easy way */ + cfmakeraw( &new ); +#else + /* The hard way */ + new.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON ); new.c_oflag &= ~OPOST; new.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); - new.c_cflag &= ~( CBAUD | CSIZE | PARENB | CRTSCTS ); - new.c_cflag |= speed | CS8 | CREAD | CLOCAL | CSTOPB ; + new.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + new.c_cflag |= CS8 | CREAD | CLOCAL ; +#endif + + /* Set default MIN and TIMEOUT values */ new.c_cc[VMIN] = 0 ; new.c_cc[VTIME] = GLK_TIMEOUT ; + /* Set the out and in speeds */ + cfsetospeed( &new, speed ); + cfsetispeed( &new, B0 ); /* Input equals output speed */ + /* Configure the port */ tcflush( fd, TCIOFLUSH ); if( tcsetattr( fd, TCSANOW, &new ) < 0 ) { diff --git a/server/drivers/hd44780-4bit.c b/server/drivers/hd44780-4bit.c index bedf7e6..58c6e0a 100644 --- a/server/drivers/hd44780-4bit.c +++ b/server/drivers/hd44780-4bit.c @@ -40,7 +40,6 @@ #include "port.h" #include "shared/str.h" -#include #include #include #include @@ -83,7 +82,7 @@ hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver for (i = 0; i < argc; ++i) { if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0) { extIF = 1; - if ((ioperm (port + 2, 1, 255)) == -1) { + if (port_access (port + 2)) { fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); return -1; } diff --git a/server/drivers/hd44780-ext8bit.c b/server/drivers/hd44780-ext8bit.c index d95046b..c486263 100644 --- a/server/drivers/hd44780-ext8bit.c +++ b/server/drivers/hd44780-ext8bit.c @@ -33,7 +33,6 @@ #include "port.h" #include "lcd_sem.h" -#include #include #include #include @@ -66,7 +65,7 @@ hd_init_ext8bit (HD44780_functions * hd44780_functions, lcd_logical_driver * dri hd44780_functions->senddata = lcdtime_HD44780_senddata; - if ((ioperm (port + 2, 1, 255)) == -1) { + if (port_access (port + 2)) { fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); return -1; } diff --git a/server/drivers/hd44780-serialLpt.c b/server/drivers/hd44780-serialLpt.c index 1dff000..beacb4a 100644 --- a/server/drivers/hd44780-serialLpt.c +++ b/server/drivers/hd44780-serialLpt.c @@ -27,6 +27,10 @@ * COPYING file distributed with this package. */ +#include +#include +#include + #include "hd44780-serialLpt.h" #include "port.h" @@ -53,6 +57,10 @@ hd_init_serialLpt (HD44780_functions * hd44780_functions, lcd_logical_driver * d int displayID = EN1 | EN2; lp = port; + if (port_access (lp) || port_access (lp +1)) { + fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); + return( -1 ); + }; hd44780_functions->senddata = lcdserLpt_HD44780_senddata; diff --git a/server/drivers/hd44780-winamp.c b/server/drivers/hd44780-winamp.c index 6c4b708..cd90f4f 100644 --- a/server/drivers/hd44780-winamp.c +++ b/server/drivers/hd44780-winamp.c @@ -36,7 +36,6 @@ #include "port.h" #include "shared/str.h" -#include #include #include #include @@ -73,7 +72,7 @@ hd_init_winamp (HD44780_functions * hd44780_functions, lcd_logical_driver * driv if (strcmp (argv[i], "-e") == 0 || strcmp (argv[i], "--extended") == 0) extIF = 1; - if ((ioperm (lptPort + 2, 1, 255)) == -1) { + if (port_access (lptPort + 2) || port_access (lptPort)) { fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); return -1; } diff --git a/server/drivers/hd44780.c b/server/drivers/hd44780.c index a2203f5..7e164fb 100644 --- a/server/drivers/hd44780.c +++ b/server/drivers/hd44780.c @@ -36,10 +36,10 @@ #include #include #include -#include #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include "port.h" // Uncomment one of the lines below to select your desired delay generation // mechanism. If both defines are commented, the original I/O read timing @@ -254,7 +254,7 @@ HD44780_init (lcd_logical_driver * driver, char *args) } #endif // Set up io port correctly, and open it... - if ((ioperm (port, 1, 255)) == -1) { + if (port_access (port)) { fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); return -1; } diff --git a/server/drivers/lb216.c b/server/drivers/lb216.c index 2950752..4a58fe7 100644 --- a/server/drivers/lb216.c +++ b/server/drivers/lb216.c @@ -146,14 +146,26 @@ int LB216_init(lcd_logical_driver *driver, char *args) } //else fprintf(stderr, "LB216_init: opened device %s\n", device); tcgetattr(fd, &portset); - // This is necessary in Linux, but does not exist in irix or solaris. -#ifndef IRIX -#ifndef SOLARIS - cfmakeraw(&portset); + + // We use RAW mode +#ifdef HAVE_CFMAKERAW + // The easy way + cfmakeraw( &portset ); +#else + // The hard way + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; #endif -#endif - cfsetospeed(&portset, speed); - cfsetispeed(&portset, speed); + + // Set port speed + cfsetospeed (&portset, speed); + cfsetispeed (&portset, B0); + + // Do it... tcsetattr(fd, TCSANOW, &portset); diff --git a/server/drivers/port.h b/server/drivers/port.h index 3b85512..20b4ec8 100644 --- a/server/drivers/port.h +++ b/server/drivers/port.h @@ -1,3 +1,5 @@ +#ifndef PORT_H +#define PORT_H /*----------------------------------------------------------------------------- * port.h (by damianf@wpi.edu) * Low level I/O functions taken from led-stat.txt @@ -9,9 +11,8 @@ */ /* #define DOS */ - -#ifndef PORT_H -#define PORT_H +#ifdef HAVE_CONFIG_H +# include "config.h" #endif #ifndef DOS @@ -30,6 +31,38 @@ port_out (unsigned short int port, unsigned char val) __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port) ); } + +/*** + *** Get access to a specific port + ***/ +#ifdef HAVE_IOPERM +/* Assume this is a LINUX system with ioperm */ +#include + +static inline int +port_access (unsigned short int port) +{ + return ioperm( port, 1, 255); +} + +#else +/* Assume this is a BSD system */ +#include + +FILE * port_access_handle = NULL ; + +static inline int +port_access (unsigned short int port) +{ + if( port_access_handle + || (port_access_handle = fopen("/dev/io", "rw")) != NULL ) { + return( 0 ); /* Success */ + } else { + return( -1 ); /* Failure */ + }; +} +#endif + #else #include @@ -49,3 +82,4 @@ port_out (unsigned int port, unsigned char val) #endif /**** END OF FILE ****/ +#endif diff --git a/server/drivers/wirz-sli.c b/server/drivers/wirz-sli.c index 85513e1..6d088eb 100644 --- a/server/drivers/wirz-sli.c +++ b/server/drivers/wirz-sli.c @@ -11,6 +11,11 @@ #include #include #include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "lcd.h" #include "wirz-sli.h" #include "drv_base.h" @@ -108,11 +113,26 @@ sli_init (lcd_logical_driver * driver, char *args) } //else fprintf(stderr, "sli_init: opened device %s\n", device); tcgetattr (fd, &portset); - // This is necessary in Linux, but does not exist in irix. -#ifndef IRIX - cfmakeraw (&portset); + + // We use RAW mode +#ifdef HAVE_CFMAKERAW + // The easy way + cfmakeraw( &portset ); +#else + // The hard way + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; #endif + + // Set port speed cfsetospeed (&portset, speed); + cfsetispeed (&portset, B0); + + // Do it... tcsetattr (fd, TCSANOW, &portset); /* Initialize SLI using autobaud detection, and then turn off cursor diff --git a/server/main.c b/server/main.c index 882773a..6f69e07 100644 --- a/server/main.c +++ b/server/main.c @@ -36,18 +36,6 @@ char *version = VERSION; char *protocol_version = PROTOCOL_VERSION; char *build_date = __DATE__; -/* no longer needed -static screen_size sizes[] = -{ - {"16x2", 16, 2}, - {"16x4", 16, 4}, - {"20x2", 20, 2}, - {"20x4", 20, 4}, - {"40x2", 40, 2}, - {"40x4", 40, 4}, - {NULL , 0, 0}, -}; -*/ // This is currently only a list of available arguments, but doesn't // really *do* anything. It just helps to figure out which parameters @@ -59,6 +47,7 @@ static parameter args[] = { {"-f", "--foreground"}, {"-b", "--backlight"}, {"-i", "--serverinfo"}, + {"-w", "--waittime"}, {NULL, NULL}, }; @@ -75,7 +64,6 @@ main (int argc, char **argv) int disable_server_screen = 1; screen *s = NULL; char *str, *ing; // strings for commandline handling -// screen_size *size = &sizes[0]; // No longer needed // Ctrl-C will cause a clean exit... signal (SIGINT, exit_program); @@ -175,24 +163,6 @@ main (int argc, char **argv) lcd.hgt = hgt; } -/* no longer needed - int j=0, valid=0; - i++; - for(j=0; sizes[j].size; j++) - { - if(0 == strcmp(sizes[j].size, argv[i])) - { - valid = 1; - size = &sizes[j]; - lcd.wid = size->wid; - lcd.hgt = size->hgt; - } - } - if(!valid) - { - fprintf(stderr, "LCDd: Invalid lcd size \"%s\". Using 20x4.\n", argv[i]); - } -*/ } } else if (0 == strcmp (argv[i], "-i") || 0 == strcmp (argv[i], "--serverinfo")) { if (i + 1 > argc) @@ -204,6 +174,20 @@ main (int argc, char **argv) if (0 == strcmp (argv[i], "on")) disable_server_screen = 0; } + } else if (0 == strcmp (argv[i], "-w") || 0 == strcmp (argv[i], "--waittime")) { + if (i + 1 > argc) + HelpScreen (); + else { + int tmp ; + i++; + tmp = atoi( argv[i] ); + if ( tmp < 16 || tmp > 10000 ) { + printf ("Wait time should be between 16 and 10000 (1/8ths of second), not %s\n", argv[i]); + HelpScreen (); + } else { + default_duration = tmp ; + }; + } } else { // otherwise... Get help! printf ("Invalid parameter: %s\n", argv[i]); diff --git a/server/screen.c b/server/screen.c index 7895c31..9815d56 100644 --- a/server/screen.c +++ b/server/screen.c @@ -12,6 +12,9 @@ #include "screenlist.h" #include "screen.h" +int default_priority = 128 ; +int default_duration = 64 ; // About 8 seconds + screen * screen_create () { @@ -25,8 +28,8 @@ screen_create () s->id = NULL; s->name = NULL; - s->priority = 128; // Default priority - s->duration = 32; // Default duration (~ 8 seconds) + s->priority = default_priority ; + s->duration = default_duration ; s->heartbeat = 1; s->wid = lcd.wid; s->hgt = lcd.hgt; diff --git a/server/screen.h b/server/screen.h index d846731..4516962 100644 --- a/server/screen.h +++ b/server/screen.h @@ -16,6 +16,9 @@ typedef struct screen { client *parent; } screen; +extern int default_duration ; +extern int default_priority ; + screen *screen_create (); int screen_destroy (screen * s);