Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 315301 Details for
Bug 445211
[RFE] DTR/DSR flow control
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
updated test case
testcase-final.c (text/x-csrc), 8.97 KB, created by
Aristeu Rozanski
on 2008-08-28 21:18:15 UTC
(
hide
)
Description:
updated test case
Filename:
MIME Type:
Creator:
Aristeu Rozanski
Created:
2008-08-28 21:18:15 UTC
Size:
8.97 KB
patch
obsolete
>#include <stdio.h> >#include <fcntl.h> >#include <unistd.h> >#include <termios.h> >#include <string.h> >#include <errno.h> >#include <stdlib.h> >#include <stdint.h> >#include <sys/ioctl.h> >#include <sys/types.h> > >#define TCGETX 0x5432 /* SYS5 TCGETX compatibility */ >#define TCSETX 0x5433 >#define TCSETXF 0x5434 >#define TCSETXW 0x5435 > >#define NFF 5 >struct termiox >{ > uint16_t x_hflag; > uint16_t x_cflag; > uint16_t x_rflag[NFF]; > uint16_t x_sflag; >}; > >#define RTSXOFF 0x0001 /* RTS flow control on input */ >#define CTSXON 0x0002 /* CTS flow control on output */ >#define DTRXOFF 0x0004 /* DTR flow control on input */ >#define DSRXON 0x0008 /* DCD flow control on output */ > > >static void show_help(FILE *out) >{ > fprintf(out, "testcase -d <device file> [-w] [-f]\n"); > fprintf(out, "\t-w\twait 1 second between each command\n"); > fprintf(out, "\t-f\tafter every command, wait until it be completely transferred\n"); >} > >static int delay; >static int flush; >#define p(x...) do { printf(x); fflush(stdout); } while(0) >static int write_to_printer(char *desc, int fd, const char *data, int size) >{ > int rc, s = size; > const char *d = data; > > p(desc); > > if (size == -1) > s = size = strlen(data); > > while(1) { > rc = write(fd, d, s); > if (rc == s) > break; > if (rc < 0) { > perror("writing to serial"); > if (errno == EAGAIN || errno == EINTR) > continue; > return 1; > } > d += rc; > s -= rc; > } > if (flush) > tcdrain(fd); > if (delay) > sleep(1); > return 0; >} > >#if 0 >PRINT #1, CHR$(&H1B);"@"; 'Initializes the printer (ESC @) >PRINT #1, CHR$(&H1B);"a";CHR$(1); 'Specifies a centered printing position (ESC a) >PRINT #1, CHR$(&H1B);"!";CHR$(0); 'Specifies font A (ESC !) >PRINT #1, "January 14, 2002 15:00"; >PRINT #1, CHR$(&H1B);"d";CHR$(3); 'Prints and 3 line feeding (ESC d) >PRINT #1, CHR$(&H1B);"a";CHR$(0); 'Selects the left print position (ESC a) >PRINT #1, CHR$(&H1B);"!";CHR$(1); 'Selects font B >PRINT #1, "TM-U210B $20.00"; CHR$(&HA); >PRINT #1, "TM-U210D $21.00"; CHR$(&HA); >PRINT #1, "PS-170 $17.00"; CHR$(&HA); >PRINT #1, CHR$(&HA); 'Line feeding (LF) >PRINT #1, CHR$(&H1B);"!";CHR$(17); 'Selects double-height mode >PRINT #1, "TOTAL $58.00"; CHR$(&HA); >PRINT #1, CHR$(&H1B);"!";CHR$(0); 'Cancels double-height mode >PRINT #1, "------------------------------"; CHR$(&HA); >PRINT #1, "PAID $60.00"; CHR$(&HA); >PRINT #1, "CHANGE $ 2.00"; CHR$(&HA); >PRINT #1, CHR$(&H1D);"V";CHR$(66);CHR$(0); 'Feeds paper & cut >' Drawer Kick (ESC p) >PRINT #1, CHR$(&H1B); CHR$(&H70); CHR$(&H0); CHR$(60); CHR$(120); >#endif > >const char ESC_init[] = { 0x1B, '@' }; >const char ESC_center[] = { 0x1B, 'a', 1 }; >const char ESC_fontA[] = { 0x1B, '!', 0 }; >const char ESC_3line[] = { 0x1B, 'd', 3 }; >const char ESC_leftal[] = { 0x1B, 'a', 0 }; >const char ESC_fontB[] = { 0x1B, '!', 1 }; >const char ESC_dheighton[] = { 0x1B, '!', 17 }; >const char ESC_feedncut[] = { 0x1B, 'V', 66, 0 }; >const char ESC_drawer[] = { 0x1B, 0x70, 0, 60, 120 }; >static void do_test(int fd) >{ > if (write_to_printer("Initializing printer\n", fd, ESC_init, 2) || > write_to_printer("Centering position\n", fd, ESC_center, 3) || > write_to_printer("Selecting font A\n", fd, ESC_fontA, 3) || > write_to_printer("Printing date\n", fd, "January 14, 2002 15:00", -1) || > write_to_printer("3 line feeding\n", fd , ESC_3line, 3) || > write_to_printer("Selects left alignment\n", fd, ESC_leftal, 3) || > write_to_printer("Selects font B\n", fd, ESC_fontB, 3) || > write_to_printer("Printing first item\n", fd, "TM-U210B $20.00\n", -1) || > write_to_printer("Printing second item\n", fd, "TM-U210D $21.00\n", -1) || > write_to_printer("Printing third item\n", fd, "PS-170 $17.00\n", -1) || > write_to_printer("Line feeding\n", fd, "\n", -1) || > write_to_printer("Selects double-height mode\n", fd, ESC_dheighton, 3) || > write_to_printer("Printing total\n", fd, "TOTAL $58.00\n", -1) || > write_to_printer("Cancels double-height mode\n", fd, ESC_fontA, 3) || > write_to_printer("Printing line\n", fd, "------------------------------\n", -1) || > write_to_printer("Printing Paid line\n", fd, "PAID $60.00\n", -1) || > write_to_printer("Printing change\n", fd, "CHANGE $ 2.00\n", -1) || > write_to_printer("Feeds paper and cut\n", fd, ESC_feedncut, 4) || > write_to_printer("Drawer\n", fd, ESC_drawer, 5)) > return; >} > >static void do_stress(int fd, int cycles) >{ > int i; > > fprintf(stdout, "doing stress test: %i cycles\n", cycles); > > if (write_to_printer("Initializing printer\n", fd, ESC_init, 2) || > write_to_printer("Selects left alignment\n", fd, ESC_leftal, 3)|| > write_to_printer("Selects font B\n", fd, ESC_fontB, 3)) > return; > for (i = 0; i < cycles; i++) { > if (!(i % 10)) { > if (write_to_printer("stress\n", fd, "== break ==\n", -1)) > break; > } > > if (write_to_printer("stress\n", fd, "All work and no play makes Edu a dull boy.\n", -1)) > break; > } >} > >static const char *options = "d:wfs:h"; >int main(int argc, char *argv[]) >{ > char *file = NULL; > int opt, fd, stress = 0; > struct termios tio; > struct termiox tiox; > > do { > opt = getopt(argc, argv, options); > switch(opt) { > case 'd': > file = strdup(optarg); > break; > case 'h': > show_help(stdout); > return 0; > case 'w': > delay = 1; > break; > case 'f': > flush = 1; > break; > case 's': > stress = atoi(optarg); > break; > case -1: > break; > default: > show_help(stderr); > return 1; > } > } while (opt >= 0); > > if (file == NULL) { > fprintf(stderr, "you must specify a device with -d\n"); > show_help(stderr); > return 1; > } > > if (delay) > fprintf(stdout, "delay is enabled\n"); > > fd = open(file, O_RDWR); > if (fd < 0) { > fprintf(stderr, "Error opening file %s: %s\n", file, > strerror(errno)); > return 1; > } > > if (tcgetattr(fd, &tio) == -1) { > perror("Error getting terminal attributes"); > close(fd); > return 1; > } > > if (ioctl(fd, TCGETX, &tiox) == -1) { > perror("Error retrieving extended attributes"); > close(fd); > return 1; > } > > printf("Original CRTSCTS: %s (%s | %s | %s | %s)\n", (tio.c_cflag & CRTSCTS)? "on":"off", > (tiox.x_cflag & DTRXOFF)? "DTRXOFF":"0", > (tiox.x_cflag & DSRXON)? "DSRXON":"0", > (tiox.x_cflag & RTSXOFF)? "RTSXOFF":"0", > (tiox.x_cflag & CTSXON)? "CTSXON":"0"); > > /* if it's not on, turn it on */ > if (!(tio.c_cflag & CRTSCTS)) { > tio.c_cflag |= CRTSCTS; > if (tcsetattr(fd, TCSANOW, &tio) == -1) { > fprintf(stderr, "Error enabling CDTRDSR (%s)\n", > strerror(errno)); > close(fd); > return 1; > } > } > > if (tcgetattr(fd, &tio) == -1) { > perror("Error getting terminal attributes"); > close(fd); > return 1; > } > > if (ioctl(fd, TCGETX, &tiox) == -1) { > perror("Error retrieving extended attributes after tcsetattr"); > close(fd); > return 1; > } > > printf("CRTSCTS: %s (%s | %s | %s | %s)\n", (tio.c_cflag & CRTSCTS)? "on":"off", > (tiox.x_cflag & DTRXOFF)? "DTRXOFF":"0", > (tiox.x_cflag & DSRXON)? "DSRXON":"0", > (tiox.x_cflag & RTSXOFF)? "RTSXOFF":"0", > (tiox.x_cflag & CTSXON)? "CTSXON":"0"); > > /* enabling the DTR/DSR mode */ > memset(&tiox, 0, sizeof(tiox)); > tiox.x_cflag |= (DTRXOFF | DSRXON); > if (ioctl(fd, TCSETX, &tiox) == -1) { > perror("Error setting extended attributes"); > close(fd); > return 1; > } > > if (tcgetattr(fd, &tio) == -1) { > perror("Error getting terminal attributes"); > close(fd); > return 1; > } > > if (ioctl(fd, TCGETX, &tiox) == -1) { > perror("Error retrieving extended attributes"); > close(fd); > return 1; > } > > printf("after setting DTR/DSR: %s (%s | %s | %s | %s)\n", (tio.c_cflag & CRTSCTS)? "on":"off", > (tiox.x_cflag & DTRXOFF)? "DTRXOFF":"0", > (tiox.x_cflag & DSRXON)? "DSRXON":"0", > (tiox.x_cflag & RTSXOFF)? "RTSXOFF":"0", > (tiox.x_cflag & CTSXON)? "CTSXON":"0"); > > > /* resetting the flags */ > tio.c_iflag &= ~(IXON | IXOFF); > if (cfsetspeed(&tio, B9600) == -1) { > perror("Error setting speed"); > close(fd); > return errno; > } > cfmakeraw(&tio); > if (tcsetattr(fd, TCSANOW, &tio) == -1) { > perror("Error resetting flags"); > close(fd); > return errno; > } > > /* enabling the DTR/DSR mode */ > memset(&tiox, 0, sizeof(tiox)); > tiox.x_cflag |= (DTRXOFF | DSRXON); > if (ioctl(fd, TCSETX, &tiox) == -1) { > perror("Error setting extended attributes"); > close(fd); > return 1; > } > > if (tcgetattr(fd, &tio) == -1) { > perror("Error getting terminal attributes"); > close(fd); > return 1; > } > > if (ioctl(fd, TCGETX, &tiox) == -1) { > perror("Error retrieving extended attributes after initialization"); > close(fd); > return 1; > } > > printf("CRTSCTS after settings: %s (%s | %s | %s | %s)\n", (tio.c_cflag & CRTSCTS)? "on":"off", > (tiox.x_cflag & DTRXOFF)? "DTRXOFF":"0", > (tiox.x_cflag & DSRXON)? "DSRXON":"0", > (tiox.x_cflag & RTSXOFF)? "RTSXOFF":"0", > (tiox.x_cflag & CTSXON)? "CTSXON":"0"); > > > if (stress) > do_stress(fd, stress); > else > do_test(fd); > > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 445211
:
308359
|
308360
|
309219
|
309849
|
315299
|
315300
| 315301